super.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247
  1. /*
  2. * fs/f2fs/super.c
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/fs.h>
  14. #include <linux/statfs.h>
  15. #include <linux/buffer_head.h>
  16. #include <linux/backing-dev.h>
  17. #include <linux/kthread.h>
  18. #include <linux/parser.h>
  19. #include <linux/mount.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/random.h>
  23. #include <linux/exportfs.h>
  24. #include <linux/blkdev.h>
  25. #include <linux/f2fs_fs.h>
  26. #include <linux/sysfs.h>
  27. #include "f2fs.h"
  28. #include "node.h"
  29. #include "segment.h"
  30. #include "xattr.h"
  31. #include "gc.h"
  32. #include "trace.h"
  33. #define CREATE_TRACE_POINTS
  34. #include <trace/events/f2fs.h>
  35. static struct proc_dir_entry *f2fs_proc_root;
  36. static struct kmem_cache *f2fs_inode_cachep;
  37. static struct kset *f2fs_kset;
  38. #ifdef CONFIG_F2FS_FAULT_INJECTION
  39. char *fault_name[FAULT_MAX] = {
  40. [FAULT_KMALLOC] = "kmalloc",
  41. [FAULT_PAGE_ALLOC] = "page alloc",
  42. [FAULT_ALLOC_NID] = "alloc nid",
  43. [FAULT_ORPHAN] = "orphan",
  44. [FAULT_BLOCK] = "no more block",
  45. [FAULT_DIR_DEPTH] = "too big dir depth",
  46. [FAULT_EVICT_INODE] = "evict_inode fail",
  47. [FAULT_IO] = "IO error",
  48. [FAULT_CHECKPOINT] = "checkpoint error",
  49. };
  50. static void f2fs_build_fault_attr(struct f2fs_sb_info *sbi,
  51. unsigned int rate)
  52. {
  53. struct f2fs_fault_info *ffi = &sbi->fault_info;
  54. if (rate) {
  55. atomic_set(&ffi->inject_ops, 0);
  56. ffi->inject_rate = rate;
  57. ffi->inject_type = (1 << FAULT_MAX) - 1;
  58. } else {
  59. memset(ffi, 0, sizeof(struct f2fs_fault_info));
  60. }
  61. }
  62. #endif
  63. /* f2fs-wide shrinker description */
  64. static struct shrinker f2fs_shrinker_info = {
  65. .scan_objects = f2fs_shrink_scan,
  66. .count_objects = f2fs_shrink_count,
  67. .seeks = DEFAULT_SEEKS,
  68. };
  69. enum {
  70. Opt_gc_background,
  71. Opt_disable_roll_forward,
  72. Opt_norecovery,
  73. Opt_discard,
  74. Opt_nodiscard,
  75. Opt_noheap,
  76. Opt_user_xattr,
  77. Opt_nouser_xattr,
  78. Opt_acl,
  79. Opt_noacl,
  80. Opt_active_logs,
  81. Opt_disable_ext_identify,
  82. Opt_inline_xattr,
  83. Opt_inline_data,
  84. Opt_inline_dentry,
  85. Opt_noinline_dentry,
  86. Opt_flush_merge,
  87. Opt_noflush_merge,
  88. Opt_nobarrier,
  89. Opt_fastboot,
  90. Opt_extent_cache,
  91. Opt_noextent_cache,
  92. Opt_noinline_data,
  93. Opt_data_flush,
  94. Opt_mode,
  95. Opt_fault_injection,
  96. Opt_lazytime,
  97. Opt_nolazytime,
  98. Opt_err,
  99. };
  100. static match_table_t f2fs_tokens = {
  101. {Opt_gc_background, "background_gc=%s"},
  102. {Opt_disable_roll_forward, "disable_roll_forward"},
  103. {Opt_norecovery, "norecovery"},
  104. {Opt_discard, "discard"},
  105. {Opt_nodiscard, "nodiscard"},
  106. {Opt_noheap, "no_heap"},
  107. {Opt_user_xattr, "user_xattr"},
  108. {Opt_nouser_xattr, "nouser_xattr"},
  109. {Opt_acl, "acl"},
  110. {Opt_noacl, "noacl"},
  111. {Opt_active_logs, "active_logs=%u"},
  112. {Opt_disable_ext_identify, "disable_ext_identify"},
  113. {Opt_inline_xattr, "inline_xattr"},
  114. {Opt_inline_data, "inline_data"},
  115. {Opt_inline_dentry, "inline_dentry"},
  116. {Opt_noinline_dentry, "noinline_dentry"},
  117. {Opt_flush_merge, "flush_merge"},
  118. {Opt_noflush_merge, "noflush_merge"},
  119. {Opt_nobarrier, "nobarrier"},
  120. {Opt_fastboot, "fastboot"},
  121. {Opt_extent_cache, "extent_cache"},
  122. {Opt_noextent_cache, "noextent_cache"},
  123. {Opt_noinline_data, "noinline_data"},
  124. {Opt_data_flush, "data_flush"},
  125. {Opt_mode, "mode=%s"},
  126. {Opt_fault_injection, "fault_injection=%u"},
  127. {Opt_lazytime, "lazytime"},
  128. {Opt_nolazytime, "nolazytime"},
  129. {Opt_err, NULL},
  130. };
  131. /* Sysfs support for f2fs */
  132. enum {
  133. GC_THREAD, /* struct f2fs_gc_thread */
  134. SM_INFO, /* struct f2fs_sm_info */
  135. NM_INFO, /* struct f2fs_nm_info */
  136. F2FS_SBI, /* struct f2fs_sb_info */
  137. #ifdef CONFIG_F2FS_FAULT_INJECTION
  138. FAULT_INFO_RATE, /* struct f2fs_fault_info */
  139. FAULT_INFO_TYPE, /* struct f2fs_fault_info */
  140. #endif
  141. };
  142. struct f2fs_attr {
  143. struct attribute attr;
  144. ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
  145. ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
  146. const char *, size_t);
  147. int struct_type;
  148. int offset;
  149. };
  150. static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
  151. {
  152. if (struct_type == GC_THREAD)
  153. return (unsigned char *)sbi->gc_thread;
  154. else if (struct_type == SM_INFO)
  155. return (unsigned char *)SM_I(sbi);
  156. else if (struct_type == NM_INFO)
  157. return (unsigned char *)NM_I(sbi);
  158. else if (struct_type == F2FS_SBI)
  159. return (unsigned char *)sbi;
  160. #ifdef CONFIG_F2FS_FAULT_INJECTION
  161. else if (struct_type == FAULT_INFO_RATE ||
  162. struct_type == FAULT_INFO_TYPE)
  163. return (unsigned char *)&sbi->fault_info;
  164. #endif
  165. return NULL;
  166. }
  167. static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
  168. struct f2fs_sb_info *sbi, char *buf)
  169. {
  170. struct super_block *sb = sbi->sb;
  171. if (!sb->s_bdev->bd_part)
  172. return snprintf(buf, PAGE_SIZE, "0\n");
  173. return snprintf(buf, PAGE_SIZE, "%llu\n",
  174. (unsigned long long)(sbi->kbytes_written +
  175. BD_PART_WRITTEN(sbi)));
  176. }
  177. static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
  178. struct f2fs_sb_info *sbi, char *buf)
  179. {
  180. unsigned char *ptr = NULL;
  181. unsigned int *ui;
  182. ptr = __struct_ptr(sbi, a->struct_type);
  183. if (!ptr)
  184. return -EINVAL;
  185. ui = (unsigned int *)(ptr + a->offset);
  186. return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
  187. }
  188. static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
  189. struct f2fs_sb_info *sbi,
  190. const char *buf, size_t count)
  191. {
  192. unsigned char *ptr;
  193. unsigned long t;
  194. unsigned int *ui;
  195. ssize_t ret;
  196. ptr = __struct_ptr(sbi, a->struct_type);
  197. if (!ptr)
  198. return -EINVAL;
  199. ui = (unsigned int *)(ptr + a->offset);
  200. ret = kstrtoul(skip_spaces(buf), 0, &t);
  201. if (ret < 0)
  202. return ret;
  203. #ifdef CONFIG_F2FS_FAULT_INJECTION
  204. if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
  205. return -EINVAL;
  206. #endif
  207. *ui = t;
  208. return count;
  209. }
  210. static ssize_t f2fs_attr_show(struct kobject *kobj,
  211. struct attribute *attr, char *buf)
  212. {
  213. struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
  214. s_kobj);
  215. struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
  216. return a->show ? a->show(a, sbi, buf) : 0;
  217. }
  218. static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
  219. const char *buf, size_t len)
  220. {
  221. struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
  222. s_kobj);
  223. struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
  224. return a->store ? a->store(a, sbi, buf, len) : 0;
  225. }
  226. static void f2fs_sb_release(struct kobject *kobj)
  227. {
  228. struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
  229. s_kobj);
  230. complete(&sbi->s_kobj_unregister);
  231. }
  232. #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
  233. static struct f2fs_attr f2fs_attr_##_name = { \
  234. .attr = {.name = __stringify(_name), .mode = _mode }, \
  235. .show = _show, \
  236. .store = _store, \
  237. .struct_type = _struct_type, \
  238. .offset = _offset \
  239. }
  240. #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
  241. F2FS_ATTR_OFFSET(struct_type, name, 0644, \
  242. f2fs_sbi_show, f2fs_sbi_store, \
  243. offsetof(struct struct_name, elname))
  244. #define F2FS_GENERAL_RO_ATTR(name) \
  245. static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
  246. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
  247. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
  248. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
  249. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
  250. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
  251. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards);
  252. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
  253. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
  254. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
  255. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
  256. F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
  257. F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
  258. F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
  259. F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
  260. F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
  261. F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
  262. F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
  263. #ifdef CONFIG_F2FS_FAULT_INJECTION
  264. F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
  265. F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
  266. #endif
  267. F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
  268. #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
  269. static struct attribute *f2fs_attrs[] = {
  270. ATTR_LIST(gc_min_sleep_time),
  271. ATTR_LIST(gc_max_sleep_time),
  272. ATTR_LIST(gc_no_gc_sleep_time),
  273. ATTR_LIST(gc_idle),
  274. ATTR_LIST(reclaim_segments),
  275. ATTR_LIST(max_small_discards),
  276. ATTR_LIST(batched_trim_sections),
  277. ATTR_LIST(ipu_policy),
  278. ATTR_LIST(min_ipu_util),
  279. ATTR_LIST(min_fsync_blocks),
  280. ATTR_LIST(max_victim_search),
  281. ATTR_LIST(dir_level),
  282. ATTR_LIST(ram_thresh),
  283. ATTR_LIST(ra_nid_pages),
  284. ATTR_LIST(dirty_nats_ratio),
  285. ATTR_LIST(cp_interval),
  286. ATTR_LIST(idle_interval),
  287. #ifdef CONFIG_F2FS_FAULT_INJECTION
  288. ATTR_LIST(inject_rate),
  289. ATTR_LIST(inject_type),
  290. #endif
  291. ATTR_LIST(lifetime_write_kbytes),
  292. NULL,
  293. };
  294. static const struct sysfs_ops f2fs_attr_ops = {
  295. .show = f2fs_attr_show,
  296. .store = f2fs_attr_store,
  297. };
  298. static struct kobj_type f2fs_ktype = {
  299. .default_attrs = f2fs_attrs,
  300. .sysfs_ops = &f2fs_attr_ops,
  301. .release = f2fs_sb_release,
  302. };
  303. void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
  304. {
  305. struct va_format vaf;
  306. va_list args;
  307. va_start(args, fmt);
  308. vaf.fmt = fmt;
  309. vaf.va = &args;
  310. printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf);
  311. va_end(args);
  312. }
  313. static void init_once(void *foo)
  314. {
  315. struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
  316. inode_init_once(&fi->vfs_inode);
  317. }
  318. static int parse_options(struct super_block *sb, char *options)
  319. {
  320. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  321. struct request_queue *q;
  322. substring_t args[MAX_OPT_ARGS];
  323. char *p, *name;
  324. int arg = 0;
  325. if (!options)
  326. return 0;
  327. while ((p = strsep(&options, ",")) != NULL) {
  328. int token;
  329. if (!*p)
  330. continue;
  331. /*
  332. * Initialize args struct so we know whether arg was
  333. * found; some options take optional arguments.
  334. */
  335. args[0].to = args[0].from = NULL;
  336. token = match_token(p, f2fs_tokens, args);
  337. switch (token) {
  338. case Opt_gc_background:
  339. name = match_strdup(&args[0]);
  340. if (!name)
  341. return -ENOMEM;
  342. if (strlen(name) == 2 && !strncmp(name, "on", 2)) {
  343. set_opt(sbi, BG_GC);
  344. clear_opt(sbi, FORCE_FG_GC);
  345. } else if (strlen(name) == 3 && !strncmp(name, "off", 3)) {
  346. clear_opt(sbi, BG_GC);
  347. clear_opt(sbi, FORCE_FG_GC);
  348. } else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) {
  349. set_opt(sbi, BG_GC);
  350. set_opt(sbi, FORCE_FG_GC);
  351. } else {
  352. kfree(name);
  353. return -EINVAL;
  354. }
  355. kfree(name);
  356. break;
  357. case Opt_disable_roll_forward:
  358. set_opt(sbi, DISABLE_ROLL_FORWARD);
  359. break;
  360. case Opt_norecovery:
  361. /* this option mounts f2fs with ro */
  362. set_opt(sbi, DISABLE_ROLL_FORWARD);
  363. if (!f2fs_readonly(sb))
  364. return -EINVAL;
  365. break;
  366. case Opt_discard:
  367. q = bdev_get_queue(sb->s_bdev);
  368. if (blk_queue_discard(q)) {
  369. set_opt(sbi, DISCARD);
  370. } else if (!f2fs_sb_mounted_blkzoned(sb)) {
  371. f2fs_msg(sb, KERN_WARNING,
  372. "mounting with \"discard\" option, but "
  373. "the device does not support discard");
  374. }
  375. break;
  376. case Opt_nodiscard:
  377. if (f2fs_sb_mounted_blkzoned(sb)) {
  378. f2fs_msg(sb, KERN_WARNING,
  379. "discard is required for zoned block devices");
  380. return -EINVAL;
  381. }
  382. clear_opt(sbi, DISCARD);
  383. break;
  384. case Opt_noheap:
  385. set_opt(sbi, NOHEAP);
  386. break;
  387. #ifdef CONFIG_F2FS_FS_XATTR
  388. case Opt_user_xattr:
  389. set_opt(sbi, XATTR_USER);
  390. break;
  391. case Opt_nouser_xattr:
  392. clear_opt(sbi, XATTR_USER);
  393. break;
  394. case Opt_inline_xattr:
  395. set_opt(sbi, INLINE_XATTR);
  396. break;
  397. #else
  398. case Opt_user_xattr:
  399. f2fs_msg(sb, KERN_INFO,
  400. "user_xattr options not supported");
  401. break;
  402. case Opt_nouser_xattr:
  403. f2fs_msg(sb, KERN_INFO,
  404. "nouser_xattr options not supported");
  405. break;
  406. case Opt_inline_xattr:
  407. f2fs_msg(sb, KERN_INFO,
  408. "inline_xattr options not supported");
  409. break;
  410. #endif
  411. #ifdef CONFIG_F2FS_FS_POSIX_ACL
  412. case Opt_acl:
  413. set_opt(sbi, POSIX_ACL);
  414. break;
  415. case Opt_noacl:
  416. clear_opt(sbi, POSIX_ACL);
  417. break;
  418. #else
  419. case Opt_acl:
  420. f2fs_msg(sb, KERN_INFO, "acl options not supported");
  421. break;
  422. case Opt_noacl:
  423. f2fs_msg(sb, KERN_INFO, "noacl options not supported");
  424. break;
  425. #endif
  426. case Opt_active_logs:
  427. if (args->from && match_int(args, &arg))
  428. return -EINVAL;
  429. if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
  430. return -EINVAL;
  431. sbi->active_logs = arg;
  432. break;
  433. case Opt_disable_ext_identify:
  434. set_opt(sbi, DISABLE_EXT_IDENTIFY);
  435. break;
  436. case Opt_inline_data:
  437. set_opt(sbi, INLINE_DATA);
  438. break;
  439. case Opt_inline_dentry:
  440. set_opt(sbi, INLINE_DENTRY);
  441. break;
  442. case Opt_noinline_dentry:
  443. clear_opt(sbi, INLINE_DENTRY);
  444. break;
  445. case Opt_flush_merge:
  446. set_opt(sbi, FLUSH_MERGE);
  447. break;
  448. case Opt_noflush_merge:
  449. clear_opt(sbi, FLUSH_MERGE);
  450. break;
  451. case Opt_nobarrier:
  452. set_opt(sbi, NOBARRIER);
  453. break;
  454. case Opt_fastboot:
  455. set_opt(sbi, FASTBOOT);
  456. break;
  457. case Opt_extent_cache:
  458. set_opt(sbi, EXTENT_CACHE);
  459. break;
  460. case Opt_noextent_cache:
  461. clear_opt(sbi, EXTENT_CACHE);
  462. break;
  463. case Opt_noinline_data:
  464. clear_opt(sbi, INLINE_DATA);
  465. break;
  466. case Opt_data_flush:
  467. set_opt(sbi, DATA_FLUSH);
  468. break;
  469. case Opt_mode:
  470. name = match_strdup(&args[0]);
  471. if (!name)
  472. return -ENOMEM;
  473. if (strlen(name) == 8 &&
  474. !strncmp(name, "adaptive", 8)) {
  475. if (f2fs_sb_mounted_blkzoned(sb)) {
  476. f2fs_msg(sb, KERN_WARNING,
  477. "adaptive mode is not allowed with "
  478. "zoned block device feature");
  479. kfree(name);
  480. return -EINVAL;
  481. }
  482. set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
  483. } else if (strlen(name) == 3 &&
  484. !strncmp(name, "lfs", 3)) {
  485. set_opt_mode(sbi, F2FS_MOUNT_LFS);
  486. } else {
  487. kfree(name);
  488. return -EINVAL;
  489. }
  490. kfree(name);
  491. break;
  492. case Opt_fault_injection:
  493. if (args->from && match_int(args, &arg))
  494. return -EINVAL;
  495. #ifdef CONFIG_F2FS_FAULT_INJECTION
  496. f2fs_build_fault_attr(sbi, arg);
  497. #else
  498. f2fs_msg(sb, KERN_INFO,
  499. "FAULT_INJECTION was not selected");
  500. #endif
  501. break;
  502. case Opt_lazytime:
  503. sb->s_flags |= MS_LAZYTIME;
  504. break;
  505. case Opt_nolazytime:
  506. sb->s_flags &= ~MS_LAZYTIME;
  507. break;
  508. default:
  509. f2fs_msg(sb, KERN_ERR,
  510. "Unrecognized mount option \"%s\" or missing value",
  511. p);
  512. return -EINVAL;
  513. }
  514. }
  515. return 0;
  516. }
  517. static struct inode *f2fs_alloc_inode(struct super_block *sb)
  518. {
  519. struct f2fs_inode_info *fi;
  520. fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO);
  521. if (!fi)
  522. return NULL;
  523. init_once((void *) fi);
  524. /* Initialize f2fs-specific inode info */
  525. fi->vfs_inode.i_version = 1;
  526. atomic_set(&fi->dirty_pages, 0);
  527. fi->i_current_depth = 1;
  528. fi->i_advise = 0;
  529. init_rwsem(&fi->i_sem);
  530. INIT_LIST_HEAD(&fi->dirty_list);
  531. INIT_LIST_HEAD(&fi->gdirty_list);
  532. INIT_LIST_HEAD(&fi->inmem_pages);
  533. mutex_init(&fi->inmem_lock);
  534. init_rwsem(&fi->dio_rwsem[READ]);
  535. init_rwsem(&fi->dio_rwsem[WRITE]);
  536. /* Will be used by directory only */
  537. fi->i_dir_level = F2FS_SB(sb)->dir_level;
  538. return &fi->vfs_inode;
  539. }
  540. static int f2fs_drop_inode(struct inode *inode)
  541. {
  542. /*
  543. * This is to avoid a deadlock condition like below.
  544. * writeback_single_inode(inode)
  545. * - f2fs_write_data_page
  546. * - f2fs_gc -> iput -> evict
  547. * - inode_wait_for_writeback(inode)
  548. */
  549. if ((!inode_unhashed(inode) && inode->i_state & I_SYNC)) {
  550. if (!inode->i_nlink && !is_bad_inode(inode)) {
  551. /* to avoid evict_inode call simultaneously */
  552. atomic_inc(&inode->i_count);
  553. spin_unlock(&inode->i_lock);
  554. /* some remained atomic pages should discarded */
  555. if (f2fs_is_atomic_file(inode))
  556. drop_inmem_pages(inode);
  557. /* should remain fi->extent_tree for writepage */
  558. f2fs_destroy_extent_node(inode);
  559. sb_start_intwrite(inode->i_sb);
  560. f2fs_i_size_write(inode, 0);
  561. if (F2FS_HAS_BLOCKS(inode))
  562. f2fs_truncate(inode);
  563. sb_end_intwrite(inode->i_sb);
  564. fscrypt_put_encryption_info(inode, NULL);
  565. spin_lock(&inode->i_lock);
  566. atomic_dec(&inode->i_count);
  567. }
  568. return 0;
  569. }
  570. return generic_drop_inode(inode);
  571. }
  572. int f2fs_inode_dirtied(struct inode *inode, bool sync)
  573. {
  574. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  575. int ret = 0;
  576. spin_lock(&sbi->inode_lock[DIRTY_META]);
  577. if (is_inode_flag_set(inode, FI_DIRTY_INODE)) {
  578. ret = 1;
  579. } else {
  580. set_inode_flag(inode, FI_DIRTY_INODE);
  581. stat_inc_dirty_inode(sbi, DIRTY_META);
  582. }
  583. if (sync && list_empty(&F2FS_I(inode)->gdirty_list)) {
  584. list_add_tail(&F2FS_I(inode)->gdirty_list,
  585. &sbi->inode_list[DIRTY_META]);
  586. inc_page_count(sbi, F2FS_DIRTY_IMETA);
  587. }
  588. spin_unlock(&sbi->inode_lock[DIRTY_META]);
  589. return ret;
  590. }
  591. void f2fs_inode_synced(struct inode *inode)
  592. {
  593. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  594. spin_lock(&sbi->inode_lock[DIRTY_META]);
  595. if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) {
  596. spin_unlock(&sbi->inode_lock[DIRTY_META]);
  597. return;
  598. }
  599. if (!list_empty(&F2FS_I(inode)->gdirty_list)) {
  600. list_del_init(&F2FS_I(inode)->gdirty_list);
  601. dec_page_count(sbi, F2FS_DIRTY_IMETA);
  602. }
  603. clear_inode_flag(inode, FI_DIRTY_INODE);
  604. clear_inode_flag(inode, FI_AUTO_RECOVER);
  605. stat_dec_dirty_inode(F2FS_I_SB(inode), DIRTY_META);
  606. spin_unlock(&sbi->inode_lock[DIRTY_META]);
  607. }
  608. /*
  609. * f2fs_dirty_inode() is called from __mark_inode_dirty()
  610. *
  611. * We should call set_dirty_inode to write the dirty inode through write_inode.
  612. */
  613. static void f2fs_dirty_inode(struct inode *inode, int flags)
  614. {
  615. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  616. if (inode->i_ino == F2FS_NODE_INO(sbi) ||
  617. inode->i_ino == F2FS_META_INO(sbi))
  618. return;
  619. if (flags == I_DIRTY_TIME)
  620. return;
  621. if (is_inode_flag_set(inode, FI_AUTO_RECOVER))
  622. clear_inode_flag(inode, FI_AUTO_RECOVER);
  623. f2fs_inode_dirtied(inode, false);
  624. }
  625. static void f2fs_i_callback(struct rcu_head *head)
  626. {
  627. struct inode *inode = container_of(head, struct inode, i_rcu);
  628. kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode));
  629. }
  630. static void f2fs_destroy_inode(struct inode *inode)
  631. {
  632. call_rcu(&inode->i_rcu, f2fs_i_callback);
  633. }
  634. static void destroy_percpu_info(struct f2fs_sb_info *sbi)
  635. {
  636. percpu_counter_destroy(&sbi->alloc_valid_block_count);
  637. percpu_counter_destroy(&sbi->total_valid_inode_count);
  638. }
  639. static void destroy_device_list(struct f2fs_sb_info *sbi)
  640. {
  641. int i;
  642. for (i = 0; i < sbi->s_ndevs; i++) {
  643. blkdev_put(FDEV(i).bdev, FMODE_EXCL);
  644. #ifdef CONFIG_BLK_DEV_ZONED
  645. kfree(FDEV(i).blkz_type);
  646. #endif
  647. }
  648. kfree(sbi->devs);
  649. }
  650. static void f2fs_put_super(struct super_block *sb)
  651. {
  652. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  653. if (sbi->s_proc) {
  654. remove_proc_entry("segment_info", sbi->s_proc);
  655. remove_proc_entry("segment_bits", sbi->s_proc);
  656. remove_proc_entry(sb->s_id, f2fs_proc_root);
  657. }
  658. kobject_del(&sbi->s_kobj);
  659. stop_gc_thread(sbi);
  660. /* prevent remaining shrinker jobs */
  661. mutex_lock(&sbi->umount_mutex);
  662. /*
  663. * We don't need to do checkpoint when superblock is clean.
  664. * But, the previous checkpoint was not done by umount, it needs to do
  665. * clean checkpoint again.
  666. */
  667. if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
  668. !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
  669. struct cp_control cpc = {
  670. .reason = CP_UMOUNT,
  671. };
  672. write_checkpoint(sbi, &cpc);
  673. }
  674. /* write_checkpoint can update stat informaion */
  675. f2fs_destroy_stats(sbi);
  676. /*
  677. * normally superblock is clean, so we need to release this.
  678. * In addition, EIO will skip do checkpoint, we need this as well.
  679. */
  680. release_ino_entry(sbi, true);
  681. f2fs_leave_shrinker(sbi);
  682. mutex_unlock(&sbi->umount_mutex);
  683. /* our cp_error case, we can wait for any writeback page */
  684. f2fs_flush_merged_bios(sbi);
  685. iput(sbi->node_inode);
  686. iput(sbi->meta_inode);
  687. /* destroy f2fs internal modules */
  688. destroy_node_manager(sbi);
  689. destroy_segment_manager(sbi);
  690. kfree(sbi->ckpt);
  691. kobject_put(&sbi->s_kobj);
  692. wait_for_completion(&sbi->s_kobj_unregister);
  693. sb->s_fs_info = NULL;
  694. if (sbi->s_chksum_driver)
  695. crypto_free_shash(sbi->s_chksum_driver);
  696. kfree(sbi->raw_super);
  697. destroy_device_list(sbi);
  698. destroy_percpu_info(sbi);
  699. kfree(sbi);
  700. }
  701. int f2fs_sync_fs(struct super_block *sb, int sync)
  702. {
  703. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  704. int err = 0;
  705. trace_f2fs_sync_fs(sb, sync);
  706. if (sync) {
  707. struct cp_control cpc;
  708. cpc.reason = __get_cp_reason(sbi);
  709. mutex_lock(&sbi->gc_mutex);
  710. err = write_checkpoint(sbi, &cpc);
  711. mutex_unlock(&sbi->gc_mutex);
  712. }
  713. f2fs_trace_ios(NULL, 1);
  714. return err;
  715. }
  716. static int f2fs_freeze(struct super_block *sb)
  717. {
  718. if (f2fs_readonly(sb))
  719. return 0;
  720. /* IO error happened before */
  721. if (unlikely(f2fs_cp_error(F2FS_SB(sb))))
  722. return -EIO;
  723. /* must be clean, since sync_filesystem() was already called */
  724. if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY))
  725. return -EINVAL;
  726. return 0;
  727. }
  728. static int f2fs_unfreeze(struct super_block *sb)
  729. {
  730. return 0;
  731. }
  732. static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
  733. {
  734. struct super_block *sb = dentry->d_sb;
  735. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  736. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  737. block_t total_count, user_block_count, start_count, ovp_count;
  738. total_count = le64_to_cpu(sbi->raw_super->block_count);
  739. user_block_count = sbi->user_block_count;
  740. start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
  741. ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg;
  742. buf->f_type = F2FS_SUPER_MAGIC;
  743. buf->f_bsize = sbi->blocksize;
  744. buf->f_blocks = total_count - start_count;
  745. buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
  746. buf->f_bavail = user_block_count - valid_user_blocks(sbi);
  747. buf->f_files = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
  748. buf->f_ffree = min(buf->f_files - valid_node_count(sbi),
  749. buf->f_bavail);
  750. buf->f_namelen = F2FS_NAME_LEN;
  751. buf->f_fsid.val[0] = (u32)id;
  752. buf->f_fsid.val[1] = (u32)(id >> 32);
  753. return 0;
  754. }
  755. static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  756. {
  757. struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
  758. if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC)) {
  759. if (test_opt(sbi, FORCE_FG_GC))
  760. seq_printf(seq, ",background_gc=%s", "sync");
  761. else
  762. seq_printf(seq, ",background_gc=%s", "on");
  763. } else {
  764. seq_printf(seq, ",background_gc=%s", "off");
  765. }
  766. if (test_opt(sbi, DISABLE_ROLL_FORWARD))
  767. seq_puts(seq, ",disable_roll_forward");
  768. if (test_opt(sbi, DISCARD))
  769. seq_puts(seq, ",discard");
  770. if (test_opt(sbi, NOHEAP))
  771. seq_puts(seq, ",no_heap_alloc");
  772. #ifdef CONFIG_F2FS_FS_XATTR
  773. if (test_opt(sbi, XATTR_USER))
  774. seq_puts(seq, ",user_xattr");
  775. else
  776. seq_puts(seq, ",nouser_xattr");
  777. if (test_opt(sbi, INLINE_XATTR))
  778. seq_puts(seq, ",inline_xattr");
  779. #endif
  780. #ifdef CONFIG_F2FS_FS_POSIX_ACL
  781. if (test_opt(sbi, POSIX_ACL))
  782. seq_puts(seq, ",acl");
  783. else
  784. seq_puts(seq, ",noacl");
  785. #endif
  786. if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
  787. seq_puts(seq, ",disable_ext_identify");
  788. if (test_opt(sbi, INLINE_DATA))
  789. seq_puts(seq, ",inline_data");
  790. else
  791. seq_puts(seq, ",noinline_data");
  792. if (test_opt(sbi, INLINE_DENTRY))
  793. seq_puts(seq, ",inline_dentry");
  794. else
  795. seq_puts(seq, ",noinline_dentry");
  796. if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE))
  797. seq_puts(seq, ",flush_merge");
  798. if (test_opt(sbi, NOBARRIER))
  799. seq_puts(seq, ",nobarrier");
  800. if (test_opt(sbi, FASTBOOT))
  801. seq_puts(seq, ",fastboot");
  802. if (test_opt(sbi, EXTENT_CACHE))
  803. seq_puts(seq, ",extent_cache");
  804. else
  805. seq_puts(seq, ",noextent_cache");
  806. if (test_opt(sbi, DATA_FLUSH))
  807. seq_puts(seq, ",data_flush");
  808. seq_puts(seq, ",mode=");
  809. if (test_opt(sbi, ADAPTIVE))
  810. seq_puts(seq, "adaptive");
  811. else if (test_opt(sbi, LFS))
  812. seq_puts(seq, "lfs");
  813. seq_printf(seq, ",active_logs=%u", sbi->active_logs);
  814. return 0;
  815. }
  816. static int segment_info_seq_show(struct seq_file *seq, void *offset)
  817. {
  818. struct super_block *sb = seq->private;
  819. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  820. unsigned int total_segs =
  821. le32_to_cpu(sbi->raw_super->segment_count_main);
  822. int i;
  823. seq_puts(seq, "format: segment_type|valid_blocks\n"
  824. "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
  825. for (i = 0; i < total_segs; i++) {
  826. struct seg_entry *se = get_seg_entry(sbi, i);
  827. if ((i % 10) == 0)
  828. seq_printf(seq, "%-10d", i);
  829. seq_printf(seq, "%d|%-3u", se->type,
  830. get_valid_blocks(sbi, i, 1));
  831. if ((i % 10) == 9 || i == (total_segs - 1))
  832. seq_putc(seq, '\n');
  833. else
  834. seq_putc(seq, ' ');
  835. }
  836. return 0;
  837. }
  838. static int segment_bits_seq_show(struct seq_file *seq, void *offset)
  839. {
  840. struct super_block *sb = seq->private;
  841. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  842. unsigned int total_segs =
  843. le32_to_cpu(sbi->raw_super->segment_count_main);
  844. int i, j;
  845. seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
  846. "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
  847. for (i = 0; i < total_segs; i++) {
  848. struct seg_entry *se = get_seg_entry(sbi, i);
  849. seq_printf(seq, "%-10d", i);
  850. seq_printf(seq, "%d|%-3u|", se->type,
  851. get_valid_blocks(sbi, i, 1));
  852. for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
  853. seq_printf(seq, " %.2x", se->cur_valid_map[j]);
  854. seq_putc(seq, '\n');
  855. }
  856. return 0;
  857. }
  858. #define F2FS_PROC_FILE_DEF(_name) \
  859. static int _name##_open_fs(struct inode *inode, struct file *file) \
  860. { \
  861. return single_open(file, _name##_seq_show, PDE_DATA(inode)); \
  862. } \
  863. \
  864. static const struct file_operations f2fs_seq_##_name##_fops = { \
  865. .open = _name##_open_fs, \
  866. .read = seq_read, \
  867. .llseek = seq_lseek, \
  868. .release = single_release, \
  869. };
  870. F2FS_PROC_FILE_DEF(segment_info);
  871. F2FS_PROC_FILE_DEF(segment_bits);
  872. static void default_options(struct f2fs_sb_info *sbi)
  873. {
  874. /* init some FS parameters */
  875. sbi->active_logs = NR_CURSEG_TYPE;
  876. set_opt(sbi, BG_GC);
  877. set_opt(sbi, INLINE_DATA);
  878. set_opt(sbi, INLINE_DENTRY);
  879. set_opt(sbi, EXTENT_CACHE);
  880. sbi->sb->s_flags |= MS_LAZYTIME;
  881. set_opt(sbi, FLUSH_MERGE);
  882. if (f2fs_sb_mounted_blkzoned(sbi->sb)) {
  883. set_opt_mode(sbi, F2FS_MOUNT_LFS);
  884. set_opt(sbi, DISCARD);
  885. } else {
  886. set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
  887. }
  888. #ifdef CONFIG_F2FS_FS_XATTR
  889. set_opt(sbi, XATTR_USER);
  890. #endif
  891. #ifdef CONFIG_F2FS_FS_POSIX_ACL
  892. set_opt(sbi, POSIX_ACL);
  893. #endif
  894. #ifdef CONFIG_F2FS_FAULT_INJECTION
  895. f2fs_build_fault_attr(sbi, 0);
  896. #endif
  897. }
  898. static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  899. {
  900. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  901. struct f2fs_mount_info org_mount_opt;
  902. int err, active_logs;
  903. bool need_restart_gc = false;
  904. bool need_stop_gc = false;
  905. bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
  906. #ifdef CONFIG_F2FS_FAULT_INJECTION
  907. struct f2fs_fault_info ffi = sbi->fault_info;
  908. #endif
  909. /*
  910. * Save the old mount options in case we
  911. * need to restore them.
  912. */
  913. org_mount_opt = sbi->mount_opt;
  914. active_logs = sbi->active_logs;
  915. /* recover superblocks we couldn't write due to previous RO mount */
  916. if (!(*flags & MS_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
  917. err = f2fs_commit_super(sbi, false);
  918. f2fs_msg(sb, KERN_INFO,
  919. "Try to recover all the superblocks, ret: %d", err);
  920. if (!err)
  921. clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
  922. }
  923. sbi->mount_opt.opt = 0;
  924. default_options(sbi);
  925. /* parse mount options */
  926. err = parse_options(sb, data);
  927. if (err)
  928. goto restore_opts;
  929. /*
  930. * Previous and new state of filesystem is RO,
  931. * so skip checking GC and FLUSH_MERGE conditions.
  932. */
  933. if (f2fs_readonly(sb) && (*flags & MS_RDONLY))
  934. goto skip;
  935. /* disallow enable/disable extent_cache dynamically */
  936. if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
  937. err = -EINVAL;
  938. f2fs_msg(sbi->sb, KERN_WARNING,
  939. "switch extent_cache option is not allowed");
  940. goto restore_opts;
  941. }
  942. /*
  943. * We stop the GC thread if FS is mounted as RO
  944. * or if background_gc = off is passed in mount
  945. * option. Also sync the filesystem.
  946. */
  947. if ((*flags & MS_RDONLY) || !test_opt(sbi, BG_GC)) {
  948. if (sbi->gc_thread) {
  949. stop_gc_thread(sbi);
  950. need_restart_gc = true;
  951. }
  952. } else if (!sbi->gc_thread) {
  953. err = start_gc_thread(sbi);
  954. if (err)
  955. goto restore_opts;
  956. need_stop_gc = true;
  957. }
  958. if (*flags & MS_RDONLY) {
  959. writeback_inodes_sb(sb, WB_REASON_SYNC);
  960. sync_inodes_sb(sb);
  961. set_sbi_flag(sbi, SBI_IS_DIRTY);
  962. set_sbi_flag(sbi, SBI_IS_CLOSE);
  963. f2fs_sync_fs(sb, 1);
  964. clear_sbi_flag(sbi, SBI_IS_CLOSE);
  965. }
  966. /*
  967. * We stop issue flush thread if FS is mounted as RO
  968. * or if flush_merge is not passed in mount option.
  969. */
  970. if ((*flags & MS_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
  971. clear_opt(sbi, FLUSH_MERGE);
  972. destroy_flush_cmd_control(sbi, false);
  973. } else {
  974. err = create_flush_cmd_control(sbi);
  975. if (err)
  976. goto restore_gc;
  977. }
  978. skip:
  979. /* Update the POSIXACL Flag */
  980. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  981. (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
  982. return 0;
  983. restore_gc:
  984. if (need_restart_gc) {
  985. if (start_gc_thread(sbi))
  986. f2fs_msg(sbi->sb, KERN_WARNING,
  987. "background gc thread has stopped");
  988. } else if (need_stop_gc) {
  989. stop_gc_thread(sbi);
  990. }
  991. restore_opts:
  992. sbi->mount_opt = org_mount_opt;
  993. sbi->active_logs = active_logs;
  994. #ifdef CONFIG_F2FS_FAULT_INJECTION
  995. sbi->fault_info = ffi;
  996. #endif
  997. return err;
  998. }
  999. static struct super_operations f2fs_sops = {
  1000. .alloc_inode = f2fs_alloc_inode,
  1001. .drop_inode = f2fs_drop_inode,
  1002. .destroy_inode = f2fs_destroy_inode,
  1003. .write_inode = f2fs_write_inode,
  1004. .dirty_inode = f2fs_dirty_inode,
  1005. .show_options = f2fs_show_options,
  1006. .evict_inode = f2fs_evict_inode,
  1007. .put_super = f2fs_put_super,
  1008. .sync_fs = f2fs_sync_fs,
  1009. .freeze_fs = f2fs_freeze,
  1010. .unfreeze_fs = f2fs_unfreeze,
  1011. .statfs = f2fs_statfs,
  1012. .remount_fs = f2fs_remount,
  1013. };
  1014. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1015. static int f2fs_get_context(struct inode *inode, void *ctx, size_t len)
  1016. {
  1017. return f2fs_getxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
  1018. F2FS_XATTR_NAME_ENCRYPTION_CONTEXT,
  1019. ctx, len, NULL);
  1020. }
  1021. static int f2fs_key_prefix(struct inode *inode, u8 **key)
  1022. {
  1023. *key = F2FS_I_SB(inode)->key_prefix;
  1024. return F2FS_I_SB(inode)->key_prefix_size;
  1025. }
  1026. static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len,
  1027. void *fs_data)
  1028. {
  1029. return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
  1030. F2FS_XATTR_NAME_ENCRYPTION_CONTEXT,
  1031. ctx, len, fs_data, XATTR_CREATE);
  1032. }
  1033. static unsigned f2fs_max_namelen(struct inode *inode)
  1034. {
  1035. return S_ISLNK(inode->i_mode) ?
  1036. inode->i_sb->s_blocksize : F2FS_NAME_LEN;
  1037. }
  1038. static struct fscrypt_operations f2fs_cryptops = {
  1039. .get_context = f2fs_get_context,
  1040. .key_prefix = f2fs_key_prefix,
  1041. .set_context = f2fs_set_context,
  1042. .is_encrypted = f2fs_encrypted_inode,
  1043. .empty_dir = f2fs_empty_dir,
  1044. .max_namelen = f2fs_max_namelen,
  1045. };
  1046. #else
  1047. static struct fscrypt_operations f2fs_cryptops = {
  1048. .is_encrypted = f2fs_encrypted_inode,
  1049. };
  1050. #endif
  1051. static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
  1052. u64 ino, u32 generation)
  1053. {
  1054. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  1055. struct inode *inode;
  1056. if (check_nid_range(sbi, ino))
  1057. return ERR_PTR(-ESTALE);
  1058. /*
  1059. * f2fs_iget isn't quite right if the inode is currently unallocated!
  1060. * However f2fs_iget currently does appropriate checks to handle stale
  1061. * inodes so everything is OK.
  1062. */
  1063. inode = f2fs_iget(sb, ino);
  1064. if (IS_ERR(inode))
  1065. return ERR_CAST(inode);
  1066. if (unlikely(generation && inode->i_generation != generation)) {
  1067. /* we didn't find the right inode.. */
  1068. iput(inode);
  1069. return ERR_PTR(-ESTALE);
  1070. }
  1071. return inode;
  1072. }
  1073. static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
  1074. int fh_len, int fh_type)
  1075. {
  1076. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  1077. f2fs_nfs_get_inode);
  1078. }
  1079. static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid,
  1080. int fh_len, int fh_type)
  1081. {
  1082. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  1083. f2fs_nfs_get_inode);
  1084. }
  1085. static const struct export_operations f2fs_export_ops = {
  1086. .fh_to_dentry = f2fs_fh_to_dentry,
  1087. .fh_to_parent = f2fs_fh_to_parent,
  1088. .get_parent = f2fs_get_parent,
  1089. };
  1090. static loff_t max_file_blocks(void)
  1091. {
  1092. loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
  1093. loff_t leaf_count = ADDRS_PER_BLOCK;
  1094. /* two direct node blocks */
  1095. result += (leaf_count * 2);
  1096. /* two indirect node blocks */
  1097. leaf_count *= NIDS_PER_BLOCK;
  1098. result += (leaf_count * 2);
  1099. /* one double indirect node block */
  1100. leaf_count *= NIDS_PER_BLOCK;
  1101. result += leaf_count;
  1102. return result;
  1103. }
  1104. static int __f2fs_commit_super(struct buffer_head *bh,
  1105. struct f2fs_super_block *super)
  1106. {
  1107. lock_buffer(bh);
  1108. if (super)
  1109. memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
  1110. set_buffer_uptodate(bh);
  1111. set_buffer_dirty(bh);
  1112. unlock_buffer(bh);
  1113. /* it's rare case, we can do fua all the time */
  1114. return __sync_dirty_buffer(bh, REQ_PREFLUSH | REQ_FUA);
  1115. }
  1116. static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
  1117. struct buffer_head *bh)
  1118. {
  1119. struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
  1120. (bh->b_data + F2FS_SUPER_OFFSET);
  1121. struct super_block *sb = sbi->sb;
  1122. u32 segment0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr);
  1123. u32 cp_blkaddr = le32_to_cpu(raw_super->cp_blkaddr);
  1124. u32 sit_blkaddr = le32_to_cpu(raw_super->sit_blkaddr);
  1125. u32 nat_blkaddr = le32_to_cpu(raw_super->nat_blkaddr);
  1126. u32 ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr);
  1127. u32 main_blkaddr = le32_to_cpu(raw_super->main_blkaddr);
  1128. u32 segment_count_ckpt = le32_to_cpu(raw_super->segment_count_ckpt);
  1129. u32 segment_count_sit = le32_to_cpu(raw_super->segment_count_sit);
  1130. u32 segment_count_nat = le32_to_cpu(raw_super->segment_count_nat);
  1131. u32 segment_count_ssa = le32_to_cpu(raw_super->segment_count_ssa);
  1132. u32 segment_count_main = le32_to_cpu(raw_super->segment_count_main);
  1133. u32 segment_count = le32_to_cpu(raw_super->segment_count);
  1134. u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  1135. u64 main_end_blkaddr = main_blkaddr +
  1136. (segment_count_main << log_blocks_per_seg);
  1137. u64 seg_end_blkaddr = segment0_blkaddr +
  1138. (segment_count << log_blocks_per_seg);
  1139. if (segment0_blkaddr != cp_blkaddr) {
  1140. f2fs_msg(sb, KERN_INFO,
  1141. "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
  1142. segment0_blkaddr, cp_blkaddr);
  1143. return true;
  1144. }
  1145. if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) !=
  1146. sit_blkaddr) {
  1147. f2fs_msg(sb, KERN_INFO,
  1148. "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
  1149. cp_blkaddr, sit_blkaddr,
  1150. segment_count_ckpt << log_blocks_per_seg);
  1151. return true;
  1152. }
  1153. if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) !=
  1154. nat_blkaddr) {
  1155. f2fs_msg(sb, KERN_INFO,
  1156. "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
  1157. sit_blkaddr, nat_blkaddr,
  1158. segment_count_sit << log_blocks_per_seg);
  1159. return true;
  1160. }
  1161. if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) !=
  1162. ssa_blkaddr) {
  1163. f2fs_msg(sb, KERN_INFO,
  1164. "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
  1165. nat_blkaddr, ssa_blkaddr,
  1166. segment_count_nat << log_blocks_per_seg);
  1167. return true;
  1168. }
  1169. if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) !=
  1170. main_blkaddr) {
  1171. f2fs_msg(sb, KERN_INFO,
  1172. "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
  1173. ssa_blkaddr, main_blkaddr,
  1174. segment_count_ssa << log_blocks_per_seg);
  1175. return true;
  1176. }
  1177. if (main_end_blkaddr > seg_end_blkaddr) {
  1178. f2fs_msg(sb, KERN_INFO,
  1179. "Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)",
  1180. main_blkaddr,
  1181. segment0_blkaddr +
  1182. (segment_count << log_blocks_per_seg),
  1183. segment_count_main << log_blocks_per_seg);
  1184. return true;
  1185. } else if (main_end_blkaddr < seg_end_blkaddr) {
  1186. int err = 0;
  1187. char *res;
  1188. /* fix in-memory information all the time */
  1189. raw_super->segment_count = cpu_to_le32((main_end_blkaddr -
  1190. segment0_blkaddr) >> log_blocks_per_seg);
  1191. if (f2fs_readonly(sb) || bdev_read_only(sb->s_bdev)) {
  1192. set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
  1193. res = "internally";
  1194. } else {
  1195. err = __f2fs_commit_super(bh, NULL);
  1196. res = err ? "failed" : "done";
  1197. }
  1198. f2fs_msg(sb, KERN_INFO,
  1199. "Fix alignment : %s, start(%u) end(%u) block(%u)",
  1200. res, main_blkaddr,
  1201. segment0_blkaddr +
  1202. (segment_count << log_blocks_per_seg),
  1203. segment_count_main << log_blocks_per_seg);
  1204. if (err)
  1205. return true;
  1206. }
  1207. return false;
  1208. }
  1209. static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
  1210. struct buffer_head *bh)
  1211. {
  1212. struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
  1213. (bh->b_data + F2FS_SUPER_OFFSET);
  1214. struct super_block *sb = sbi->sb;
  1215. unsigned int blocksize;
  1216. if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
  1217. f2fs_msg(sb, KERN_INFO,
  1218. "Magic Mismatch, valid(0x%x) - read(0x%x)",
  1219. F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
  1220. return 1;
  1221. }
  1222. /* Currently, support only 4KB page cache size */
  1223. if (F2FS_BLKSIZE != PAGE_SIZE) {
  1224. f2fs_msg(sb, KERN_INFO,
  1225. "Invalid page_cache_size (%lu), supports only 4KB\n",
  1226. PAGE_SIZE);
  1227. return 1;
  1228. }
  1229. /* Currently, support only 4KB block size */
  1230. blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
  1231. if (blocksize != F2FS_BLKSIZE) {
  1232. f2fs_msg(sb, KERN_INFO,
  1233. "Invalid blocksize (%u), supports only 4KB\n",
  1234. blocksize);
  1235. return 1;
  1236. }
  1237. /* check log blocks per segment */
  1238. if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
  1239. f2fs_msg(sb, KERN_INFO,
  1240. "Invalid log blocks per segment (%u)\n",
  1241. le32_to_cpu(raw_super->log_blocks_per_seg));
  1242. return 1;
  1243. }
  1244. /* Currently, support 512/1024/2048/4096 bytes sector size */
  1245. if (le32_to_cpu(raw_super->log_sectorsize) >
  1246. F2FS_MAX_LOG_SECTOR_SIZE ||
  1247. le32_to_cpu(raw_super->log_sectorsize) <
  1248. F2FS_MIN_LOG_SECTOR_SIZE) {
  1249. f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize (%u)",
  1250. le32_to_cpu(raw_super->log_sectorsize));
  1251. return 1;
  1252. }
  1253. if (le32_to_cpu(raw_super->log_sectors_per_block) +
  1254. le32_to_cpu(raw_super->log_sectorsize) !=
  1255. F2FS_MAX_LOG_SECTOR_SIZE) {
  1256. f2fs_msg(sb, KERN_INFO,
  1257. "Invalid log sectors per block(%u) log sectorsize(%u)",
  1258. le32_to_cpu(raw_super->log_sectors_per_block),
  1259. le32_to_cpu(raw_super->log_sectorsize));
  1260. return 1;
  1261. }
  1262. /* check reserved ino info */
  1263. if (le32_to_cpu(raw_super->node_ino) != 1 ||
  1264. le32_to_cpu(raw_super->meta_ino) != 2 ||
  1265. le32_to_cpu(raw_super->root_ino) != 3) {
  1266. f2fs_msg(sb, KERN_INFO,
  1267. "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
  1268. le32_to_cpu(raw_super->node_ino),
  1269. le32_to_cpu(raw_super->meta_ino),
  1270. le32_to_cpu(raw_super->root_ino));
  1271. return 1;
  1272. }
  1273. /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
  1274. if (sanity_check_area_boundary(sbi, bh))
  1275. return 1;
  1276. return 0;
  1277. }
  1278. int sanity_check_ckpt(struct f2fs_sb_info *sbi)
  1279. {
  1280. unsigned int total, fsmeta;
  1281. struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
  1282. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  1283. unsigned int ovp_segments, reserved_segments;
  1284. total = le32_to_cpu(raw_super->segment_count);
  1285. fsmeta = le32_to_cpu(raw_super->segment_count_ckpt);
  1286. fsmeta += le32_to_cpu(raw_super->segment_count_sit);
  1287. fsmeta += le32_to_cpu(raw_super->segment_count_nat);
  1288. fsmeta += le32_to_cpu(ckpt->rsvd_segment_count);
  1289. fsmeta += le32_to_cpu(raw_super->segment_count_ssa);
  1290. if (unlikely(fsmeta >= total))
  1291. return 1;
  1292. ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  1293. reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
  1294. if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||
  1295. ovp_segments == 0 || reserved_segments == 0)) {
  1296. f2fs_msg(sbi->sb, KERN_ERR,
  1297. "Wrong layout: check mkfs.f2fs version");
  1298. return 1;
  1299. }
  1300. if (unlikely(f2fs_cp_error(sbi))) {
  1301. f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
  1302. return 1;
  1303. }
  1304. return 0;
  1305. }
  1306. static void init_sb_info(struct f2fs_sb_info *sbi)
  1307. {
  1308. struct f2fs_super_block *raw_super = sbi->raw_super;
  1309. int i;
  1310. sbi->log_sectors_per_block =
  1311. le32_to_cpu(raw_super->log_sectors_per_block);
  1312. sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
  1313. sbi->blocksize = 1 << sbi->log_blocksize;
  1314. sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  1315. sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg;
  1316. sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
  1317. sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
  1318. sbi->total_sections = le32_to_cpu(raw_super->section_count);
  1319. sbi->total_node_count =
  1320. (le32_to_cpu(raw_super->segment_count_nat) / 2)
  1321. * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK;
  1322. sbi->root_ino_num = le32_to_cpu(raw_super->root_ino);
  1323. sbi->node_ino_num = le32_to_cpu(raw_super->node_ino);
  1324. sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino);
  1325. sbi->cur_victim_sec = NULL_SECNO;
  1326. sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
  1327. sbi->dir_level = DEF_DIR_LEVEL;
  1328. sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
  1329. sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
  1330. clear_sbi_flag(sbi, SBI_NEED_FSCK);
  1331. for (i = 0; i < NR_COUNT_TYPE; i++)
  1332. atomic_set(&sbi->nr_pages[i], 0);
  1333. INIT_LIST_HEAD(&sbi->s_list);
  1334. mutex_init(&sbi->umount_mutex);
  1335. mutex_init(&sbi->wio_mutex[NODE]);
  1336. mutex_init(&sbi->wio_mutex[DATA]);
  1337. spin_lock_init(&sbi->cp_lock);
  1338. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1339. memcpy(sbi->key_prefix, F2FS_KEY_DESC_PREFIX,
  1340. F2FS_KEY_DESC_PREFIX_SIZE);
  1341. sbi->key_prefix_size = F2FS_KEY_DESC_PREFIX_SIZE;
  1342. #endif
  1343. }
  1344. static int init_percpu_info(struct f2fs_sb_info *sbi)
  1345. {
  1346. int err;
  1347. err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL);
  1348. if (err)
  1349. return err;
  1350. return percpu_counter_init(&sbi->total_valid_inode_count, 0,
  1351. GFP_KERNEL);
  1352. }
  1353. #ifdef CONFIG_BLK_DEV_ZONED
  1354. static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
  1355. {
  1356. struct block_device *bdev = FDEV(devi).bdev;
  1357. sector_t nr_sectors = bdev->bd_part->nr_sects;
  1358. sector_t sector = 0;
  1359. struct blk_zone *zones;
  1360. unsigned int i, nr_zones;
  1361. unsigned int n = 0;
  1362. int err = -EIO;
  1363. if (!f2fs_sb_mounted_blkzoned(sbi->sb))
  1364. return 0;
  1365. if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
  1366. SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)))
  1367. return -EINVAL;
  1368. sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev));
  1369. if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz !=
  1370. __ilog2_u32(sbi->blocks_per_blkz))
  1371. return -EINVAL;
  1372. sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
  1373. FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
  1374. sbi->log_blocks_per_blkz;
  1375. if (nr_sectors & (bdev_zone_sectors(bdev) - 1))
  1376. FDEV(devi).nr_blkz++;
  1377. FDEV(devi).blkz_type = kmalloc(FDEV(devi).nr_blkz, GFP_KERNEL);
  1378. if (!FDEV(devi).blkz_type)
  1379. return -ENOMEM;
  1380. #define F2FS_REPORT_NR_ZONES 4096
  1381. zones = kcalloc(F2FS_REPORT_NR_ZONES, sizeof(struct blk_zone),
  1382. GFP_KERNEL);
  1383. if (!zones)
  1384. return -ENOMEM;
  1385. /* Get block zones type */
  1386. while (zones && sector < nr_sectors) {
  1387. nr_zones = F2FS_REPORT_NR_ZONES;
  1388. err = blkdev_report_zones(bdev, sector,
  1389. zones, &nr_zones,
  1390. GFP_KERNEL);
  1391. if (err)
  1392. break;
  1393. if (!nr_zones) {
  1394. err = -EIO;
  1395. break;
  1396. }
  1397. for (i = 0; i < nr_zones; i++) {
  1398. FDEV(devi).blkz_type[n] = zones[i].type;
  1399. sector += zones[i].len;
  1400. n++;
  1401. }
  1402. }
  1403. kfree(zones);
  1404. return err;
  1405. }
  1406. #endif
  1407. /*
  1408. * Read f2fs raw super block.
  1409. * Because we have two copies of super block, so read both of them
  1410. * to get the first valid one. If any one of them is broken, we pass
  1411. * them recovery flag back to the caller.
  1412. */
  1413. static int read_raw_super_block(struct f2fs_sb_info *sbi,
  1414. struct f2fs_super_block **raw_super,
  1415. int *valid_super_block, int *recovery)
  1416. {
  1417. struct super_block *sb = sbi->sb;
  1418. int block;
  1419. struct buffer_head *bh;
  1420. struct f2fs_super_block *super;
  1421. int err = 0;
  1422. super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
  1423. if (!super)
  1424. return -ENOMEM;
  1425. for (block = 0; block < 2; block++) {
  1426. bh = sb_bread(sb, block);
  1427. if (!bh) {
  1428. f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock",
  1429. block + 1);
  1430. err = -EIO;
  1431. continue;
  1432. }
  1433. /* sanity checking of raw super */
  1434. if (sanity_check_raw_super(sbi, bh)) {
  1435. f2fs_msg(sb, KERN_ERR,
  1436. "Can't find valid F2FS filesystem in %dth superblock",
  1437. block + 1);
  1438. err = -EINVAL;
  1439. brelse(bh);
  1440. continue;
  1441. }
  1442. if (!*raw_super) {
  1443. memcpy(super, bh->b_data + F2FS_SUPER_OFFSET,
  1444. sizeof(*super));
  1445. *valid_super_block = block;
  1446. *raw_super = super;
  1447. }
  1448. brelse(bh);
  1449. }
  1450. /* Fail to read any one of the superblocks*/
  1451. if (err < 0)
  1452. *recovery = 1;
  1453. /* No valid superblock */
  1454. if (!*raw_super)
  1455. kfree(super);
  1456. else
  1457. err = 0;
  1458. return err;
  1459. }
  1460. int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
  1461. {
  1462. struct buffer_head *bh;
  1463. int err;
  1464. if ((recover && f2fs_readonly(sbi->sb)) ||
  1465. bdev_read_only(sbi->sb->s_bdev)) {
  1466. set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
  1467. return -EROFS;
  1468. }
  1469. /* write back-up superblock first */
  1470. bh = sb_getblk(sbi->sb, sbi->valid_super_block ? 0: 1);
  1471. if (!bh)
  1472. return -EIO;
  1473. err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
  1474. brelse(bh);
  1475. /* if we are in recovery path, skip writing valid superblock */
  1476. if (recover || err)
  1477. return err;
  1478. /* write current valid superblock */
  1479. bh = sb_getblk(sbi->sb, sbi->valid_super_block);
  1480. if (!bh)
  1481. return -EIO;
  1482. err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
  1483. brelse(bh);
  1484. return err;
  1485. }
  1486. static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
  1487. {
  1488. struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
  1489. int i;
  1490. for (i = 0; i < MAX_DEVICES; i++) {
  1491. if (!RDEV(i).path[0])
  1492. return 0;
  1493. if (i == 0) {
  1494. sbi->devs = kzalloc(sizeof(struct f2fs_dev_info) *
  1495. MAX_DEVICES, GFP_KERNEL);
  1496. if (!sbi->devs)
  1497. return -ENOMEM;
  1498. }
  1499. memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN);
  1500. FDEV(i).total_segments = le32_to_cpu(RDEV(i).total_segments);
  1501. if (i == 0) {
  1502. FDEV(i).start_blk = 0;
  1503. FDEV(i).end_blk = FDEV(i).start_blk +
  1504. (FDEV(i).total_segments <<
  1505. sbi->log_blocks_per_seg) - 1 +
  1506. le32_to_cpu(raw_super->segment0_blkaddr);
  1507. } else {
  1508. FDEV(i).start_blk = FDEV(i - 1).end_blk + 1;
  1509. FDEV(i).end_blk = FDEV(i).start_blk +
  1510. (FDEV(i).total_segments <<
  1511. sbi->log_blocks_per_seg) - 1;
  1512. }
  1513. FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path,
  1514. sbi->sb->s_mode, sbi->sb->s_type);
  1515. if (IS_ERR(FDEV(i).bdev))
  1516. return PTR_ERR(FDEV(i).bdev);
  1517. /* to release errored devices */
  1518. sbi->s_ndevs = i + 1;
  1519. #ifdef CONFIG_BLK_DEV_ZONED
  1520. if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
  1521. !f2fs_sb_mounted_blkzoned(sbi->sb)) {
  1522. f2fs_msg(sbi->sb, KERN_ERR,
  1523. "Zoned block device feature not enabled\n");
  1524. return -EINVAL;
  1525. }
  1526. if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) {
  1527. if (init_blkz_info(sbi, i)) {
  1528. f2fs_msg(sbi->sb, KERN_ERR,
  1529. "Failed to initialize F2FS blkzone information");
  1530. return -EINVAL;
  1531. }
  1532. f2fs_msg(sbi->sb, KERN_INFO,
  1533. "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
  1534. i, FDEV(i).path,
  1535. FDEV(i).total_segments,
  1536. FDEV(i).start_blk, FDEV(i).end_blk,
  1537. bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
  1538. "Host-aware" : "Host-managed");
  1539. continue;
  1540. }
  1541. #endif
  1542. f2fs_msg(sbi->sb, KERN_INFO,
  1543. "Mount Device [%2d]: %20s, %8u, %8x - %8x",
  1544. i, FDEV(i).path,
  1545. FDEV(i).total_segments,
  1546. FDEV(i).start_blk, FDEV(i).end_blk);
  1547. }
  1548. return 0;
  1549. }
  1550. static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  1551. {
  1552. struct f2fs_sb_info *sbi;
  1553. struct f2fs_super_block *raw_super;
  1554. struct inode *root;
  1555. int err;
  1556. bool retry = true, need_fsck = false;
  1557. char *options = NULL;
  1558. int recovery, i, valid_super_block;
  1559. struct curseg_info *seg_i;
  1560. try_onemore:
  1561. err = -EINVAL;
  1562. raw_super = NULL;
  1563. valid_super_block = -1;
  1564. recovery = 0;
  1565. /* allocate memory for f2fs-specific super block info */
  1566. sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
  1567. if (!sbi)
  1568. return -ENOMEM;
  1569. sbi->sb = sb;
  1570. /* Load the checksum driver */
  1571. sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
  1572. if (IS_ERR(sbi->s_chksum_driver)) {
  1573. f2fs_msg(sb, KERN_ERR, "Cannot load crc32 driver.");
  1574. err = PTR_ERR(sbi->s_chksum_driver);
  1575. sbi->s_chksum_driver = NULL;
  1576. goto free_sbi;
  1577. }
  1578. /* set a block size */
  1579. if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
  1580. f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
  1581. goto free_sbi;
  1582. }
  1583. err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
  1584. &recovery);
  1585. if (err)
  1586. goto free_sbi;
  1587. sb->s_fs_info = sbi;
  1588. sbi->raw_super = raw_super;
  1589. /*
  1590. * The BLKZONED feature indicates that the drive was formatted with
  1591. * zone alignment optimization. This is optional for host-aware
  1592. * devices, but mandatory for host-managed zoned block devices.
  1593. */
  1594. #ifndef CONFIG_BLK_DEV_ZONED
  1595. if (f2fs_sb_mounted_blkzoned(sb)) {
  1596. f2fs_msg(sb, KERN_ERR,
  1597. "Zoned block device support is not enabled\n");
  1598. goto free_sb_buf;
  1599. }
  1600. #endif
  1601. default_options(sbi);
  1602. /* parse mount options */
  1603. options = kstrdup((const char *)data, GFP_KERNEL);
  1604. if (data && !options) {
  1605. err = -ENOMEM;
  1606. goto free_sb_buf;
  1607. }
  1608. err = parse_options(sb, options);
  1609. if (err)
  1610. goto free_options;
  1611. sbi->max_file_blocks = max_file_blocks();
  1612. sb->s_maxbytes = sbi->max_file_blocks <<
  1613. le32_to_cpu(raw_super->log_blocksize);
  1614. sb->s_max_links = F2FS_LINK_MAX;
  1615. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  1616. sb->s_op = &f2fs_sops;
  1617. sb->s_cop = &f2fs_cryptops;
  1618. sb->s_xattr = f2fs_xattr_handlers;
  1619. sb->s_export_op = &f2fs_export_ops;
  1620. sb->s_magic = F2FS_SUPER_MAGIC;
  1621. sb->s_time_gran = 1;
  1622. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  1623. (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
  1624. memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
  1625. /* init f2fs-specific super block info */
  1626. sbi->valid_super_block = valid_super_block;
  1627. mutex_init(&sbi->gc_mutex);
  1628. mutex_init(&sbi->cp_mutex);
  1629. init_rwsem(&sbi->node_write);
  1630. /* disallow all the data/node/meta page writes */
  1631. set_sbi_flag(sbi, SBI_POR_DOING);
  1632. spin_lock_init(&sbi->stat_lock);
  1633. init_rwsem(&sbi->read_io.io_rwsem);
  1634. sbi->read_io.sbi = sbi;
  1635. sbi->read_io.bio = NULL;
  1636. for (i = 0; i < NR_PAGE_TYPE; i++) {
  1637. init_rwsem(&sbi->write_io[i].io_rwsem);
  1638. sbi->write_io[i].sbi = sbi;
  1639. sbi->write_io[i].bio = NULL;
  1640. }
  1641. init_rwsem(&sbi->cp_rwsem);
  1642. init_waitqueue_head(&sbi->cp_wait);
  1643. init_sb_info(sbi);
  1644. err = init_percpu_info(sbi);
  1645. if (err)
  1646. goto free_options;
  1647. /* get an inode for meta space */
  1648. sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
  1649. if (IS_ERR(sbi->meta_inode)) {
  1650. f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode");
  1651. err = PTR_ERR(sbi->meta_inode);
  1652. goto free_options;
  1653. }
  1654. err = get_valid_checkpoint(sbi);
  1655. if (err) {
  1656. f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
  1657. goto free_meta_inode;
  1658. }
  1659. /* Initialize device list */
  1660. err = f2fs_scan_devices(sbi);
  1661. if (err) {
  1662. f2fs_msg(sb, KERN_ERR, "Failed to find devices");
  1663. goto free_devices;
  1664. }
  1665. sbi->total_valid_node_count =
  1666. le32_to_cpu(sbi->ckpt->valid_node_count);
  1667. percpu_counter_set(&sbi->total_valid_inode_count,
  1668. le32_to_cpu(sbi->ckpt->valid_inode_count));
  1669. sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
  1670. sbi->total_valid_block_count =
  1671. le64_to_cpu(sbi->ckpt->valid_block_count);
  1672. sbi->last_valid_block_count = sbi->total_valid_block_count;
  1673. for (i = 0; i < NR_INODE_TYPE; i++) {
  1674. INIT_LIST_HEAD(&sbi->inode_list[i]);
  1675. spin_lock_init(&sbi->inode_lock[i]);
  1676. }
  1677. init_extent_cache_info(sbi);
  1678. init_ino_entry_info(sbi);
  1679. /* setup f2fs internal modules */
  1680. err = build_segment_manager(sbi);
  1681. if (err) {
  1682. f2fs_msg(sb, KERN_ERR,
  1683. "Failed to initialize F2FS segment manager");
  1684. goto free_sm;
  1685. }
  1686. err = build_node_manager(sbi);
  1687. if (err) {
  1688. f2fs_msg(sb, KERN_ERR,
  1689. "Failed to initialize F2FS node manager");
  1690. goto free_nm;
  1691. }
  1692. /* For write statistics */
  1693. if (sb->s_bdev->bd_part)
  1694. sbi->sectors_written_start =
  1695. (u64)part_stat_read(sb->s_bdev->bd_part, sectors[1]);
  1696. /* Read accumulated write IO statistics if exists */
  1697. seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
  1698. if (__exist_node_summaries(sbi))
  1699. sbi->kbytes_written =
  1700. le64_to_cpu(seg_i->journal->info.kbytes_written);
  1701. build_gc_manager(sbi);
  1702. /* get an inode for node space */
  1703. sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
  1704. if (IS_ERR(sbi->node_inode)) {
  1705. f2fs_msg(sb, KERN_ERR, "Failed to read node inode");
  1706. err = PTR_ERR(sbi->node_inode);
  1707. goto free_nm;
  1708. }
  1709. f2fs_join_shrinker(sbi);
  1710. /* if there are nt orphan nodes free them */
  1711. err = recover_orphan_inodes(sbi);
  1712. if (err)
  1713. goto free_node_inode;
  1714. /* read root inode and dentry */
  1715. root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
  1716. if (IS_ERR(root)) {
  1717. f2fs_msg(sb, KERN_ERR, "Failed to read root inode");
  1718. err = PTR_ERR(root);
  1719. goto free_node_inode;
  1720. }
  1721. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  1722. iput(root);
  1723. err = -EINVAL;
  1724. goto free_node_inode;
  1725. }
  1726. sb->s_root = d_make_root(root); /* allocate root dentry */
  1727. if (!sb->s_root) {
  1728. err = -ENOMEM;
  1729. goto free_root_inode;
  1730. }
  1731. err = f2fs_build_stats(sbi);
  1732. if (err)
  1733. goto free_root_inode;
  1734. if (f2fs_proc_root)
  1735. sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
  1736. if (sbi->s_proc) {
  1737. proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
  1738. &f2fs_seq_segment_info_fops, sb);
  1739. proc_create_data("segment_bits", S_IRUGO, sbi->s_proc,
  1740. &f2fs_seq_segment_bits_fops, sb);
  1741. }
  1742. sbi->s_kobj.kset = f2fs_kset;
  1743. init_completion(&sbi->s_kobj_unregister);
  1744. err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL,
  1745. "%s", sb->s_id);
  1746. if (err)
  1747. goto free_proc;
  1748. /* recover fsynced data */
  1749. if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
  1750. /*
  1751. * mount should be failed, when device has readonly mode, and
  1752. * previous checkpoint was not done by clean system shutdown.
  1753. */
  1754. if (bdev_read_only(sb->s_bdev) &&
  1755. !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
  1756. err = -EROFS;
  1757. goto free_kobj;
  1758. }
  1759. if (need_fsck)
  1760. set_sbi_flag(sbi, SBI_NEED_FSCK);
  1761. if (!retry)
  1762. goto skip_recovery;
  1763. err = recover_fsync_data(sbi, false);
  1764. if (err < 0) {
  1765. need_fsck = true;
  1766. f2fs_msg(sb, KERN_ERR,
  1767. "Cannot recover all fsync data errno=%d", err);
  1768. goto free_kobj;
  1769. }
  1770. } else {
  1771. err = recover_fsync_data(sbi, true);
  1772. if (!f2fs_readonly(sb) && err > 0) {
  1773. err = -EINVAL;
  1774. f2fs_msg(sb, KERN_ERR,
  1775. "Need to recover fsync data");
  1776. goto free_kobj;
  1777. }
  1778. }
  1779. skip_recovery:
  1780. /* recover_fsync_data() cleared this already */
  1781. clear_sbi_flag(sbi, SBI_POR_DOING);
  1782. /*
  1783. * If filesystem is not mounted as read-only then
  1784. * do start the gc_thread.
  1785. */
  1786. if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) {
  1787. /* After POR, we can run background GC thread.*/
  1788. err = start_gc_thread(sbi);
  1789. if (err)
  1790. goto free_kobj;
  1791. }
  1792. kfree(options);
  1793. /* recover broken superblock */
  1794. if (recovery) {
  1795. err = f2fs_commit_super(sbi, true);
  1796. f2fs_msg(sb, KERN_INFO,
  1797. "Try to recover %dth superblock, ret: %d",
  1798. sbi->valid_super_block ? 1 : 2, err);
  1799. }
  1800. f2fs_update_time(sbi, CP_TIME);
  1801. f2fs_update_time(sbi, REQ_TIME);
  1802. return 0;
  1803. free_kobj:
  1804. f2fs_sync_inode_meta(sbi);
  1805. kobject_del(&sbi->s_kobj);
  1806. kobject_put(&sbi->s_kobj);
  1807. wait_for_completion(&sbi->s_kobj_unregister);
  1808. free_proc:
  1809. if (sbi->s_proc) {
  1810. remove_proc_entry("segment_info", sbi->s_proc);
  1811. remove_proc_entry("segment_bits", sbi->s_proc);
  1812. remove_proc_entry(sb->s_id, f2fs_proc_root);
  1813. }
  1814. f2fs_destroy_stats(sbi);
  1815. free_root_inode:
  1816. dput(sb->s_root);
  1817. sb->s_root = NULL;
  1818. free_node_inode:
  1819. truncate_inode_pages_final(NODE_MAPPING(sbi));
  1820. mutex_lock(&sbi->umount_mutex);
  1821. release_ino_entry(sbi, true);
  1822. f2fs_leave_shrinker(sbi);
  1823. /*
  1824. * Some dirty meta pages can be produced by recover_orphan_inodes()
  1825. * failed by EIO. Then, iput(node_inode) can trigger balance_fs_bg()
  1826. * followed by write_checkpoint() through f2fs_write_node_pages(), which
  1827. * falls into an infinite loop in sync_meta_pages().
  1828. */
  1829. truncate_inode_pages_final(META_MAPPING(sbi));
  1830. iput(sbi->node_inode);
  1831. mutex_unlock(&sbi->umount_mutex);
  1832. free_nm:
  1833. destroy_node_manager(sbi);
  1834. free_sm:
  1835. destroy_segment_manager(sbi);
  1836. free_devices:
  1837. destroy_device_list(sbi);
  1838. kfree(sbi->ckpt);
  1839. free_meta_inode:
  1840. make_bad_inode(sbi->meta_inode);
  1841. iput(sbi->meta_inode);
  1842. free_options:
  1843. destroy_percpu_info(sbi);
  1844. kfree(options);
  1845. free_sb_buf:
  1846. kfree(raw_super);
  1847. free_sbi:
  1848. if (sbi->s_chksum_driver)
  1849. crypto_free_shash(sbi->s_chksum_driver);
  1850. kfree(sbi);
  1851. /* give only one another chance */
  1852. if (retry) {
  1853. retry = false;
  1854. shrink_dcache_sb(sb);
  1855. goto try_onemore;
  1856. }
  1857. return err;
  1858. }
  1859. static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
  1860. const char *dev_name, void *data)
  1861. {
  1862. return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super);
  1863. }
  1864. static void kill_f2fs_super(struct super_block *sb)
  1865. {
  1866. if (sb->s_root)
  1867. set_sbi_flag(F2FS_SB(sb), SBI_IS_CLOSE);
  1868. kill_block_super(sb);
  1869. }
  1870. static struct file_system_type f2fs_fs_type = {
  1871. .owner = THIS_MODULE,
  1872. .name = "f2fs",
  1873. .mount = f2fs_mount,
  1874. .kill_sb = kill_f2fs_super,
  1875. .fs_flags = FS_REQUIRES_DEV,
  1876. };
  1877. MODULE_ALIAS_FS("f2fs");
  1878. static int __init init_inodecache(void)
  1879. {
  1880. f2fs_inode_cachep = kmem_cache_create("f2fs_inode_cache",
  1881. sizeof(struct f2fs_inode_info), 0,
  1882. SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT, NULL);
  1883. if (!f2fs_inode_cachep)
  1884. return -ENOMEM;
  1885. return 0;
  1886. }
  1887. static void destroy_inodecache(void)
  1888. {
  1889. /*
  1890. * Make sure all delayed rcu free inodes are flushed before we
  1891. * destroy cache.
  1892. */
  1893. rcu_barrier();
  1894. kmem_cache_destroy(f2fs_inode_cachep);
  1895. }
  1896. static int __init init_f2fs_fs(void)
  1897. {
  1898. int err;
  1899. f2fs_build_trace_ios();
  1900. err = init_inodecache();
  1901. if (err)
  1902. goto fail;
  1903. err = create_node_manager_caches();
  1904. if (err)
  1905. goto free_inodecache;
  1906. err = create_segment_manager_caches();
  1907. if (err)
  1908. goto free_node_manager_caches;
  1909. err = create_checkpoint_caches();
  1910. if (err)
  1911. goto free_segment_manager_caches;
  1912. err = create_extent_cache();
  1913. if (err)
  1914. goto free_checkpoint_caches;
  1915. f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj);
  1916. if (!f2fs_kset) {
  1917. err = -ENOMEM;
  1918. goto free_extent_cache;
  1919. }
  1920. err = register_shrinker(&f2fs_shrinker_info);
  1921. if (err)
  1922. goto free_kset;
  1923. err = register_filesystem(&f2fs_fs_type);
  1924. if (err)
  1925. goto free_shrinker;
  1926. err = f2fs_create_root_stats();
  1927. if (err)
  1928. goto free_filesystem;
  1929. f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
  1930. return 0;
  1931. free_filesystem:
  1932. unregister_filesystem(&f2fs_fs_type);
  1933. free_shrinker:
  1934. unregister_shrinker(&f2fs_shrinker_info);
  1935. free_kset:
  1936. kset_unregister(f2fs_kset);
  1937. free_extent_cache:
  1938. destroy_extent_cache();
  1939. free_checkpoint_caches:
  1940. destroy_checkpoint_caches();
  1941. free_segment_manager_caches:
  1942. destroy_segment_manager_caches();
  1943. free_node_manager_caches:
  1944. destroy_node_manager_caches();
  1945. free_inodecache:
  1946. destroy_inodecache();
  1947. fail:
  1948. return err;
  1949. }
  1950. static void __exit exit_f2fs_fs(void)
  1951. {
  1952. remove_proc_entry("fs/f2fs", NULL);
  1953. f2fs_destroy_root_stats();
  1954. unregister_filesystem(&f2fs_fs_type);
  1955. unregister_shrinker(&f2fs_shrinker_info);
  1956. kset_unregister(f2fs_kset);
  1957. destroy_extent_cache();
  1958. destroy_checkpoint_caches();
  1959. destroy_segment_manager_caches();
  1960. destroy_node_manager_caches();
  1961. destroy_inodecache();
  1962. f2fs_destroy_trace_ios();
  1963. }
  1964. module_init(init_f2fs_fs)
  1965. module_exit(exit_f2fs_fs)
  1966. MODULE_AUTHOR("Samsung Electronics's Praesto Team");
  1967. MODULE_DESCRIPTION("Flash Friendly File System");
  1968. MODULE_LICENSE("GPL");