super.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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. #define CREATE_TRACE_POINTS
  33. #include <trace/events/f2fs.h>
  34. static struct proc_dir_entry *f2fs_proc_root;
  35. static struct kmem_cache *f2fs_inode_cachep;
  36. static struct kset *f2fs_kset;
  37. enum {
  38. Opt_gc_background,
  39. Opt_disable_roll_forward,
  40. Opt_discard,
  41. Opt_noheap,
  42. Opt_user_xattr,
  43. Opt_nouser_xattr,
  44. Opt_acl,
  45. Opt_noacl,
  46. Opt_active_logs,
  47. Opt_disable_ext_identify,
  48. Opt_inline_xattr,
  49. Opt_inline_data,
  50. Opt_flush_merge,
  51. Opt_nobarrier,
  52. Opt_err,
  53. };
  54. static match_table_t f2fs_tokens = {
  55. {Opt_gc_background, "background_gc=%s"},
  56. {Opt_disable_roll_forward, "disable_roll_forward"},
  57. {Opt_discard, "discard"},
  58. {Opt_noheap, "no_heap"},
  59. {Opt_user_xattr, "user_xattr"},
  60. {Opt_nouser_xattr, "nouser_xattr"},
  61. {Opt_acl, "acl"},
  62. {Opt_noacl, "noacl"},
  63. {Opt_active_logs, "active_logs=%u"},
  64. {Opt_disable_ext_identify, "disable_ext_identify"},
  65. {Opt_inline_xattr, "inline_xattr"},
  66. {Opt_inline_data, "inline_data"},
  67. {Opt_flush_merge, "flush_merge"},
  68. {Opt_nobarrier, "nobarrier"},
  69. {Opt_err, NULL},
  70. };
  71. /* Sysfs support for f2fs */
  72. enum {
  73. GC_THREAD, /* struct f2fs_gc_thread */
  74. SM_INFO, /* struct f2fs_sm_info */
  75. NM_INFO, /* struct f2fs_nm_info */
  76. F2FS_SBI, /* struct f2fs_sb_info */
  77. };
  78. struct f2fs_attr {
  79. struct attribute attr;
  80. ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
  81. ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
  82. const char *, size_t);
  83. int struct_type;
  84. int offset;
  85. };
  86. static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
  87. {
  88. if (struct_type == GC_THREAD)
  89. return (unsigned char *)sbi->gc_thread;
  90. else if (struct_type == SM_INFO)
  91. return (unsigned char *)SM_I(sbi);
  92. else if (struct_type == NM_INFO)
  93. return (unsigned char *)NM_I(sbi);
  94. else if (struct_type == F2FS_SBI)
  95. return (unsigned char *)sbi;
  96. return NULL;
  97. }
  98. static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
  99. struct f2fs_sb_info *sbi, char *buf)
  100. {
  101. unsigned char *ptr = NULL;
  102. unsigned int *ui;
  103. ptr = __struct_ptr(sbi, a->struct_type);
  104. if (!ptr)
  105. return -EINVAL;
  106. ui = (unsigned int *)(ptr + a->offset);
  107. return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
  108. }
  109. static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
  110. struct f2fs_sb_info *sbi,
  111. const char *buf, size_t count)
  112. {
  113. unsigned char *ptr;
  114. unsigned long t;
  115. unsigned int *ui;
  116. ssize_t ret;
  117. ptr = __struct_ptr(sbi, a->struct_type);
  118. if (!ptr)
  119. return -EINVAL;
  120. ui = (unsigned int *)(ptr + a->offset);
  121. ret = kstrtoul(skip_spaces(buf), 0, &t);
  122. if (ret < 0)
  123. return ret;
  124. *ui = t;
  125. return count;
  126. }
  127. static ssize_t f2fs_attr_show(struct kobject *kobj,
  128. struct attribute *attr, char *buf)
  129. {
  130. struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
  131. s_kobj);
  132. struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
  133. return a->show ? a->show(a, sbi, buf) : 0;
  134. }
  135. static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
  136. const char *buf, size_t len)
  137. {
  138. struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
  139. s_kobj);
  140. struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
  141. return a->store ? a->store(a, sbi, buf, len) : 0;
  142. }
  143. static void f2fs_sb_release(struct kobject *kobj)
  144. {
  145. struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
  146. s_kobj);
  147. complete(&sbi->s_kobj_unregister);
  148. }
  149. #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
  150. static struct f2fs_attr f2fs_attr_##_name = { \
  151. .attr = {.name = __stringify(_name), .mode = _mode }, \
  152. .show = _show, \
  153. .store = _store, \
  154. .struct_type = _struct_type, \
  155. .offset = _offset \
  156. }
  157. #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
  158. F2FS_ATTR_OFFSET(struct_type, name, 0644, \
  159. f2fs_sbi_show, f2fs_sbi_store, \
  160. offsetof(struct struct_name, elname))
  161. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
  162. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
  163. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
  164. F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
  165. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
  166. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards);
  167. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
  168. F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
  169. F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
  170. F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
  171. F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
  172. #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
  173. static struct attribute *f2fs_attrs[] = {
  174. ATTR_LIST(gc_min_sleep_time),
  175. ATTR_LIST(gc_max_sleep_time),
  176. ATTR_LIST(gc_no_gc_sleep_time),
  177. ATTR_LIST(gc_idle),
  178. ATTR_LIST(reclaim_segments),
  179. ATTR_LIST(max_small_discards),
  180. ATTR_LIST(ipu_policy),
  181. ATTR_LIST(min_ipu_util),
  182. ATTR_LIST(max_victim_search),
  183. ATTR_LIST(dir_level),
  184. ATTR_LIST(ram_thresh),
  185. NULL,
  186. };
  187. static const struct sysfs_ops f2fs_attr_ops = {
  188. .show = f2fs_attr_show,
  189. .store = f2fs_attr_store,
  190. };
  191. static struct kobj_type f2fs_ktype = {
  192. .default_attrs = f2fs_attrs,
  193. .sysfs_ops = &f2fs_attr_ops,
  194. .release = f2fs_sb_release,
  195. };
  196. void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
  197. {
  198. struct va_format vaf;
  199. va_list args;
  200. va_start(args, fmt);
  201. vaf.fmt = fmt;
  202. vaf.va = &args;
  203. printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf);
  204. va_end(args);
  205. }
  206. static void init_once(void *foo)
  207. {
  208. struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
  209. inode_init_once(&fi->vfs_inode);
  210. }
  211. static int parse_options(struct super_block *sb, char *options)
  212. {
  213. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  214. substring_t args[MAX_OPT_ARGS];
  215. char *p, *name;
  216. int arg = 0;
  217. if (!options)
  218. return 0;
  219. while ((p = strsep(&options, ",")) != NULL) {
  220. int token;
  221. if (!*p)
  222. continue;
  223. /*
  224. * Initialize args struct so we know whether arg was
  225. * found; some options take optional arguments.
  226. */
  227. args[0].to = args[0].from = NULL;
  228. token = match_token(p, f2fs_tokens, args);
  229. switch (token) {
  230. case Opt_gc_background:
  231. name = match_strdup(&args[0]);
  232. if (!name)
  233. return -ENOMEM;
  234. if (strlen(name) == 2 && !strncmp(name, "on", 2))
  235. set_opt(sbi, BG_GC);
  236. else if (strlen(name) == 3 && !strncmp(name, "off", 3))
  237. clear_opt(sbi, BG_GC);
  238. else {
  239. kfree(name);
  240. return -EINVAL;
  241. }
  242. kfree(name);
  243. break;
  244. case Opt_disable_roll_forward:
  245. set_opt(sbi, DISABLE_ROLL_FORWARD);
  246. break;
  247. case Opt_discard:
  248. set_opt(sbi, DISCARD);
  249. break;
  250. case Opt_noheap:
  251. set_opt(sbi, NOHEAP);
  252. break;
  253. #ifdef CONFIG_F2FS_FS_XATTR
  254. case Opt_user_xattr:
  255. set_opt(sbi, XATTR_USER);
  256. break;
  257. case Opt_nouser_xattr:
  258. clear_opt(sbi, XATTR_USER);
  259. break;
  260. case Opt_inline_xattr:
  261. set_opt(sbi, INLINE_XATTR);
  262. break;
  263. #else
  264. case Opt_user_xattr:
  265. f2fs_msg(sb, KERN_INFO,
  266. "user_xattr options not supported");
  267. break;
  268. case Opt_nouser_xattr:
  269. f2fs_msg(sb, KERN_INFO,
  270. "nouser_xattr options not supported");
  271. break;
  272. case Opt_inline_xattr:
  273. f2fs_msg(sb, KERN_INFO,
  274. "inline_xattr options not supported");
  275. break;
  276. #endif
  277. #ifdef CONFIG_F2FS_FS_POSIX_ACL
  278. case Opt_acl:
  279. set_opt(sbi, POSIX_ACL);
  280. break;
  281. case Opt_noacl:
  282. clear_opt(sbi, POSIX_ACL);
  283. break;
  284. #else
  285. case Opt_acl:
  286. f2fs_msg(sb, KERN_INFO, "acl options not supported");
  287. break;
  288. case Opt_noacl:
  289. f2fs_msg(sb, KERN_INFO, "noacl options not supported");
  290. break;
  291. #endif
  292. case Opt_active_logs:
  293. if (args->from && match_int(args, &arg))
  294. return -EINVAL;
  295. if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
  296. return -EINVAL;
  297. sbi->active_logs = arg;
  298. break;
  299. case Opt_disable_ext_identify:
  300. set_opt(sbi, DISABLE_EXT_IDENTIFY);
  301. break;
  302. case Opt_inline_data:
  303. set_opt(sbi, INLINE_DATA);
  304. break;
  305. case Opt_flush_merge:
  306. set_opt(sbi, FLUSH_MERGE);
  307. break;
  308. case Opt_nobarrier:
  309. set_opt(sbi, NOBARRIER);
  310. break;
  311. default:
  312. f2fs_msg(sb, KERN_ERR,
  313. "Unrecognized mount option \"%s\" or missing value",
  314. p);
  315. return -EINVAL;
  316. }
  317. }
  318. return 0;
  319. }
  320. static struct inode *f2fs_alloc_inode(struct super_block *sb)
  321. {
  322. struct f2fs_inode_info *fi;
  323. fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO);
  324. if (!fi)
  325. return NULL;
  326. init_once((void *) fi);
  327. /* Initialize f2fs-specific inode info */
  328. fi->vfs_inode.i_version = 1;
  329. atomic_set(&fi->dirty_dents, 0);
  330. fi->i_current_depth = 1;
  331. fi->i_advise = 0;
  332. rwlock_init(&fi->ext.ext_lock);
  333. init_rwsem(&fi->i_sem);
  334. set_inode_flag(fi, FI_NEW_INODE);
  335. if (test_opt(F2FS_SB(sb), INLINE_XATTR))
  336. set_inode_flag(fi, FI_INLINE_XATTR);
  337. /* Will be used by directory only */
  338. fi->i_dir_level = F2FS_SB(sb)->dir_level;
  339. return &fi->vfs_inode;
  340. }
  341. static int f2fs_drop_inode(struct inode *inode)
  342. {
  343. /*
  344. * This is to avoid a deadlock condition like below.
  345. * writeback_single_inode(inode)
  346. * - f2fs_write_data_page
  347. * - f2fs_gc -> iput -> evict
  348. * - inode_wait_for_writeback(inode)
  349. */
  350. if (!inode_unhashed(inode) && inode->i_state & I_SYNC)
  351. return 0;
  352. return generic_drop_inode(inode);
  353. }
  354. /*
  355. * f2fs_dirty_inode() is called from __mark_inode_dirty()
  356. *
  357. * We should call set_dirty_inode to write the dirty inode through write_inode.
  358. */
  359. static void f2fs_dirty_inode(struct inode *inode, int flags)
  360. {
  361. set_inode_flag(F2FS_I(inode), FI_DIRTY_INODE);
  362. }
  363. static void f2fs_i_callback(struct rcu_head *head)
  364. {
  365. struct inode *inode = container_of(head, struct inode, i_rcu);
  366. kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode));
  367. }
  368. static void f2fs_destroy_inode(struct inode *inode)
  369. {
  370. call_rcu(&inode->i_rcu, f2fs_i_callback);
  371. }
  372. static void f2fs_put_super(struct super_block *sb)
  373. {
  374. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  375. if (sbi->s_proc) {
  376. remove_proc_entry("segment_info", sbi->s_proc);
  377. remove_proc_entry(sb->s_id, f2fs_proc_root);
  378. }
  379. kobject_del(&sbi->s_kobj);
  380. f2fs_destroy_stats(sbi);
  381. stop_gc_thread(sbi);
  382. /* We don't need to do checkpoint when it's clean */
  383. if (sbi->s_dirty)
  384. write_checkpoint(sbi, true);
  385. /* normally superblock is clean, so we need to release this */
  386. release_dirty_inode(sbi);
  387. iput(sbi->node_inode);
  388. iput(sbi->meta_inode);
  389. /* destroy f2fs internal modules */
  390. destroy_node_manager(sbi);
  391. destroy_segment_manager(sbi);
  392. kfree(sbi->ckpt);
  393. kobject_put(&sbi->s_kobj);
  394. wait_for_completion(&sbi->s_kobj_unregister);
  395. sb->s_fs_info = NULL;
  396. brelse(sbi->raw_super_buf);
  397. kfree(sbi);
  398. }
  399. int f2fs_sync_fs(struct super_block *sb, int sync)
  400. {
  401. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  402. trace_f2fs_sync_fs(sb, sync);
  403. if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES))
  404. return 0;
  405. if (sync) {
  406. mutex_lock(&sbi->gc_mutex);
  407. write_checkpoint(sbi, false);
  408. mutex_unlock(&sbi->gc_mutex);
  409. } else {
  410. f2fs_balance_fs(sbi);
  411. }
  412. return 0;
  413. }
  414. static int f2fs_freeze(struct super_block *sb)
  415. {
  416. int err;
  417. if (f2fs_readonly(sb))
  418. return 0;
  419. err = f2fs_sync_fs(sb, 1);
  420. return err;
  421. }
  422. static int f2fs_unfreeze(struct super_block *sb)
  423. {
  424. return 0;
  425. }
  426. static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
  427. {
  428. struct super_block *sb = dentry->d_sb;
  429. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  430. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  431. block_t total_count, user_block_count, start_count, ovp_count;
  432. total_count = le64_to_cpu(sbi->raw_super->block_count);
  433. user_block_count = sbi->user_block_count;
  434. start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
  435. ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg;
  436. buf->f_type = F2FS_SUPER_MAGIC;
  437. buf->f_bsize = sbi->blocksize;
  438. buf->f_blocks = total_count - start_count;
  439. buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count;
  440. buf->f_bavail = user_block_count - valid_user_blocks(sbi);
  441. buf->f_files = sbi->total_node_count;
  442. buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi);
  443. buf->f_namelen = F2FS_NAME_LEN;
  444. buf->f_fsid.val[0] = (u32)id;
  445. buf->f_fsid.val[1] = (u32)(id >> 32);
  446. return 0;
  447. }
  448. static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  449. {
  450. struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
  451. if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC))
  452. seq_printf(seq, ",background_gc=%s", "on");
  453. else
  454. seq_printf(seq, ",background_gc=%s", "off");
  455. if (test_opt(sbi, DISABLE_ROLL_FORWARD))
  456. seq_puts(seq, ",disable_roll_forward");
  457. if (test_opt(sbi, DISCARD))
  458. seq_puts(seq, ",discard");
  459. if (test_opt(sbi, NOHEAP))
  460. seq_puts(seq, ",no_heap_alloc");
  461. #ifdef CONFIG_F2FS_FS_XATTR
  462. if (test_opt(sbi, XATTR_USER))
  463. seq_puts(seq, ",user_xattr");
  464. else
  465. seq_puts(seq, ",nouser_xattr");
  466. if (test_opt(sbi, INLINE_XATTR))
  467. seq_puts(seq, ",inline_xattr");
  468. #endif
  469. #ifdef CONFIG_F2FS_FS_POSIX_ACL
  470. if (test_opt(sbi, POSIX_ACL))
  471. seq_puts(seq, ",acl");
  472. else
  473. seq_puts(seq, ",noacl");
  474. #endif
  475. if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
  476. seq_puts(seq, ",disable_ext_identify");
  477. if (test_opt(sbi, INLINE_DATA))
  478. seq_puts(seq, ",inline_data");
  479. if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE))
  480. seq_puts(seq, ",flush_merge");
  481. if (test_opt(sbi, NOBARRIER))
  482. seq_puts(seq, ",nobarrier");
  483. seq_printf(seq, ",active_logs=%u", sbi->active_logs);
  484. return 0;
  485. }
  486. static int segment_info_seq_show(struct seq_file *seq, void *offset)
  487. {
  488. struct super_block *sb = seq->private;
  489. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  490. unsigned int total_segs =
  491. le32_to_cpu(sbi->raw_super->segment_count_main);
  492. int i;
  493. seq_puts(seq, "format: segment_type|valid_blocks\n"
  494. "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
  495. for (i = 0; i < total_segs; i++) {
  496. struct seg_entry *se = get_seg_entry(sbi, i);
  497. if ((i % 10) == 0)
  498. seq_printf(seq, "%-5d", i);
  499. seq_printf(seq, "%d|%-3u", se->type,
  500. get_valid_blocks(sbi, i, 1));
  501. if ((i % 10) == 9 || i == (total_segs - 1))
  502. seq_putc(seq, '\n');
  503. else
  504. seq_putc(seq, ' ');
  505. }
  506. return 0;
  507. }
  508. static int segment_info_open_fs(struct inode *inode, struct file *file)
  509. {
  510. return single_open(file, segment_info_seq_show, PDE_DATA(inode));
  511. }
  512. static const struct file_operations f2fs_seq_segment_info_fops = {
  513. .owner = THIS_MODULE,
  514. .open = segment_info_open_fs,
  515. .read = seq_read,
  516. .llseek = seq_lseek,
  517. .release = single_release,
  518. };
  519. static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  520. {
  521. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  522. struct f2fs_mount_info org_mount_opt;
  523. int err, active_logs;
  524. bool need_restart_gc = false;
  525. bool need_stop_gc = false;
  526. sync_filesystem(sb);
  527. /*
  528. * Save the old mount options in case we
  529. * need to restore them.
  530. */
  531. org_mount_opt = sbi->mount_opt;
  532. active_logs = sbi->active_logs;
  533. /* parse mount options */
  534. err = parse_options(sb, data);
  535. if (err)
  536. goto restore_opts;
  537. /*
  538. * Previous and new state of filesystem is RO,
  539. * so skip checking GC and FLUSH_MERGE conditions.
  540. */
  541. if (f2fs_readonly(sb) && (*flags & MS_RDONLY))
  542. goto skip;
  543. /*
  544. * We stop the GC thread if FS is mounted as RO
  545. * or if background_gc = off is passed in mount
  546. * option. Also sync the filesystem.
  547. */
  548. if ((*flags & MS_RDONLY) || !test_opt(sbi, BG_GC)) {
  549. if (sbi->gc_thread) {
  550. stop_gc_thread(sbi);
  551. f2fs_sync_fs(sb, 1);
  552. need_restart_gc = true;
  553. }
  554. } else if (test_opt(sbi, BG_GC) && !sbi->gc_thread) {
  555. err = start_gc_thread(sbi);
  556. if (err)
  557. goto restore_opts;
  558. need_stop_gc = true;
  559. }
  560. /*
  561. * We stop issue flush thread if FS is mounted as RO
  562. * or if flush_merge is not passed in mount option.
  563. */
  564. if ((*flags & MS_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
  565. destroy_flush_cmd_control(sbi);
  566. } else if (test_opt(sbi, FLUSH_MERGE) && !SM_I(sbi)->cmd_control_info) {
  567. err = create_flush_cmd_control(sbi);
  568. if (err)
  569. goto restore_gc;
  570. }
  571. skip:
  572. /* Update the POSIXACL Flag */
  573. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  574. (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
  575. return 0;
  576. restore_gc:
  577. if (need_restart_gc) {
  578. if (start_gc_thread(sbi))
  579. f2fs_msg(sbi->sb, KERN_WARNING,
  580. "background gc thread has stopped");
  581. } else if (need_stop_gc) {
  582. stop_gc_thread(sbi);
  583. }
  584. restore_opts:
  585. sbi->mount_opt = org_mount_opt;
  586. sbi->active_logs = active_logs;
  587. return err;
  588. }
  589. static struct super_operations f2fs_sops = {
  590. .alloc_inode = f2fs_alloc_inode,
  591. .drop_inode = f2fs_drop_inode,
  592. .destroy_inode = f2fs_destroy_inode,
  593. .write_inode = f2fs_write_inode,
  594. .dirty_inode = f2fs_dirty_inode,
  595. .show_options = f2fs_show_options,
  596. .evict_inode = f2fs_evict_inode,
  597. .put_super = f2fs_put_super,
  598. .sync_fs = f2fs_sync_fs,
  599. .freeze_fs = f2fs_freeze,
  600. .unfreeze_fs = f2fs_unfreeze,
  601. .statfs = f2fs_statfs,
  602. .remount_fs = f2fs_remount,
  603. };
  604. static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
  605. u64 ino, u32 generation)
  606. {
  607. struct f2fs_sb_info *sbi = F2FS_SB(sb);
  608. struct inode *inode;
  609. if (check_nid_range(sbi, ino))
  610. return ERR_PTR(-ESTALE);
  611. /*
  612. * f2fs_iget isn't quite right if the inode is currently unallocated!
  613. * However f2fs_iget currently does appropriate checks to handle stale
  614. * inodes so everything is OK.
  615. */
  616. inode = f2fs_iget(sb, ino);
  617. if (IS_ERR(inode))
  618. return ERR_CAST(inode);
  619. if (unlikely(generation && inode->i_generation != generation)) {
  620. /* we didn't find the right inode.. */
  621. iput(inode);
  622. return ERR_PTR(-ESTALE);
  623. }
  624. return inode;
  625. }
  626. static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
  627. int fh_len, int fh_type)
  628. {
  629. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  630. f2fs_nfs_get_inode);
  631. }
  632. static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid,
  633. int fh_len, int fh_type)
  634. {
  635. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  636. f2fs_nfs_get_inode);
  637. }
  638. static const struct export_operations f2fs_export_ops = {
  639. .fh_to_dentry = f2fs_fh_to_dentry,
  640. .fh_to_parent = f2fs_fh_to_parent,
  641. .get_parent = f2fs_get_parent,
  642. };
  643. static loff_t max_file_size(unsigned bits)
  644. {
  645. loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
  646. loff_t leaf_count = ADDRS_PER_BLOCK;
  647. /* two direct node blocks */
  648. result += (leaf_count * 2);
  649. /* two indirect node blocks */
  650. leaf_count *= NIDS_PER_BLOCK;
  651. result += (leaf_count * 2);
  652. /* one double indirect node block */
  653. leaf_count *= NIDS_PER_BLOCK;
  654. result += leaf_count;
  655. result <<= bits;
  656. return result;
  657. }
  658. static int sanity_check_raw_super(struct super_block *sb,
  659. struct f2fs_super_block *raw_super)
  660. {
  661. unsigned int blocksize;
  662. if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
  663. f2fs_msg(sb, KERN_INFO,
  664. "Magic Mismatch, valid(0x%x) - read(0x%x)",
  665. F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
  666. return 1;
  667. }
  668. /* Currently, support only 4KB page cache size */
  669. if (F2FS_BLKSIZE != PAGE_CACHE_SIZE) {
  670. f2fs_msg(sb, KERN_INFO,
  671. "Invalid page_cache_size (%lu), supports only 4KB\n",
  672. PAGE_CACHE_SIZE);
  673. return 1;
  674. }
  675. /* Currently, support only 4KB block size */
  676. blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
  677. if (blocksize != F2FS_BLKSIZE) {
  678. f2fs_msg(sb, KERN_INFO,
  679. "Invalid blocksize (%u), supports only 4KB\n",
  680. blocksize);
  681. return 1;
  682. }
  683. if (le32_to_cpu(raw_super->log_sectorsize) !=
  684. F2FS_LOG_SECTOR_SIZE) {
  685. f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize");
  686. return 1;
  687. }
  688. if (le32_to_cpu(raw_super->log_sectors_per_block) !=
  689. F2FS_LOG_SECTORS_PER_BLOCK) {
  690. f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block");
  691. return 1;
  692. }
  693. return 0;
  694. }
  695. static int sanity_check_ckpt(struct f2fs_sb_info *sbi)
  696. {
  697. unsigned int total, fsmeta;
  698. struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
  699. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  700. total = le32_to_cpu(raw_super->segment_count);
  701. fsmeta = le32_to_cpu(raw_super->segment_count_ckpt);
  702. fsmeta += le32_to_cpu(raw_super->segment_count_sit);
  703. fsmeta += le32_to_cpu(raw_super->segment_count_nat);
  704. fsmeta += le32_to_cpu(ckpt->rsvd_segment_count);
  705. fsmeta += le32_to_cpu(raw_super->segment_count_ssa);
  706. if (unlikely(fsmeta >= total))
  707. return 1;
  708. if (unlikely(is_set_ckpt_flags(ckpt, CP_ERROR_FLAG))) {
  709. f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
  710. return 1;
  711. }
  712. return 0;
  713. }
  714. static void init_sb_info(struct f2fs_sb_info *sbi)
  715. {
  716. struct f2fs_super_block *raw_super = sbi->raw_super;
  717. int i;
  718. sbi->log_sectors_per_block =
  719. le32_to_cpu(raw_super->log_sectors_per_block);
  720. sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
  721. sbi->blocksize = 1 << sbi->log_blocksize;
  722. sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  723. sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg;
  724. sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
  725. sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
  726. sbi->total_sections = le32_to_cpu(raw_super->section_count);
  727. sbi->total_node_count =
  728. (le32_to_cpu(raw_super->segment_count_nat) / 2)
  729. * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK;
  730. sbi->root_ino_num = le32_to_cpu(raw_super->root_ino);
  731. sbi->node_ino_num = le32_to_cpu(raw_super->node_ino);
  732. sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino);
  733. sbi->cur_victim_sec = NULL_SECNO;
  734. sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
  735. for (i = 0; i < NR_COUNT_TYPE; i++)
  736. atomic_set(&sbi->nr_pages[i], 0);
  737. sbi->dir_level = DEF_DIR_LEVEL;
  738. }
  739. /*
  740. * Read f2fs raw super block.
  741. * Because we have two copies of super block, so read the first one at first,
  742. * if the first one is invalid, move to read the second one.
  743. */
  744. static int read_raw_super_block(struct super_block *sb,
  745. struct f2fs_super_block **raw_super,
  746. struct buffer_head **raw_super_buf)
  747. {
  748. int block = 0;
  749. retry:
  750. *raw_super_buf = sb_bread(sb, block);
  751. if (!*raw_super_buf) {
  752. f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock",
  753. block + 1);
  754. if (block == 0) {
  755. block++;
  756. goto retry;
  757. } else {
  758. return -EIO;
  759. }
  760. }
  761. *raw_super = (struct f2fs_super_block *)
  762. ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET);
  763. /* sanity checking of raw super */
  764. if (sanity_check_raw_super(sb, *raw_super)) {
  765. brelse(*raw_super_buf);
  766. f2fs_msg(sb, KERN_ERR,
  767. "Can't find valid F2FS filesystem in %dth superblock",
  768. block + 1);
  769. if (block == 0) {
  770. block++;
  771. goto retry;
  772. } else {
  773. return -EINVAL;
  774. }
  775. }
  776. return 0;
  777. }
  778. static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  779. {
  780. struct f2fs_sb_info *sbi;
  781. struct f2fs_super_block *raw_super;
  782. struct buffer_head *raw_super_buf;
  783. struct inode *root;
  784. long err = -EINVAL;
  785. int i;
  786. /* allocate memory for f2fs-specific super block info */
  787. sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
  788. if (!sbi)
  789. return -ENOMEM;
  790. /* set a block size */
  791. if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
  792. f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
  793. goto free_sbi;
  794. }
  795. err = read_raw_super_block(sb, &raw_super, &raw_super_buf);
  796. if (err)
  797. goto free_sbi;
  798. sb->s_fs_info = sbi;
  799. /* init some FS parameters */
  800. sbi->active_logs = NR_CURSEG_TYPE;
  801. set_opt(sbi, BG_GC);
  802. #ifdef CONFIG_F2FS_FS_XATTR
  803. set_opt(sbi, XATTR_USER);
  804. #endif
  805. #ifdef CONFIG_F2FS_FS_POSIX_ACL
  806. set_opt(sbi, POSIX_ACL);
  807. #endif
  808. /* parse mount options */
  809. err = parse_options(sb, (char *)data);
  810. if (err)
  811. goto free_sb_buf;
  812. sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize));
  813. sb->s_max_links = F2FS_LINK_MAX;
  814. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  815. sb->s_op = &f2fs_sops;
  816. sb->s_xattr = f2fs_xattr_handlers;
  817. sb->s_export_op = &f2fs_export_ops;
  818. sb->s_magic = F2FS_SUPER_MAGIC;
  819. sb->s_time_gran = 1;
  820. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  821. (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
  822. memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
  823. /* init f2fs-specific super block info */
  824. sbi->sb = sb;
  825. sbi->raw_super = raw_super;
  826. sbi->raw_super_buf = raw_super_buf;
  827. mutex_init(&sbi->gc_mutex);
  828. mutex_init(&sbi->writepages);
  829. mutex_init(&sbi->cp_mutex);
  830. init_rwsem(&sbi->node_write);
  831. sbi->por_doing = false;
  832. spin_lock_init(&sbi->stat_lock);
  833. init_rwsem(&sbi->read_io.io_rwsem);
  834. sbi->read_io.sbi = sbi;
  835. sbi->read_io.bio = NULL;
  836. for (i = 0; i < NR_PAGE_TYPE; i++) {
  837. init_rwsem(&sbi->write_io[i].io_rwsem);
  838. sbi->write_io[i].sbi = sbi;
  839. sbi->write_io[i].bio = NULL;
  840. }
  841. init_rwsem(&sbi->cp_rwsem);
  842. init_waitqueue_head(&sbi->cp_wait);
  843. init_sb_info(sbi);
  844. /* get an inode for meta space */
  845. sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
  846. if (IS_ERR(sbi->meta_inode)) {
  847. f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode");
  848. err = PTR_ERR(sbi->meta_inode);
  849. goto free_sb_buf;
  850. }
  851. err = get_valid_checkpoint(sbi);
  852. if (err) {
  853. f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
  854. goto free_meta_inode;
  855. }
  856. /* sanity checking of checkpoint */
  857. err = -EINVAL;
  858. if (sanity_check_ckpt(sbi)) {
  859. f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint");
  860. goto free_cp;
  861. }
  862. sbi->total_valid_node_count =
  863. le32_to_cpu(sbi->ckpt->valid_node_count);
  864. sbi->total_valid_inode_count =
  865. le32_to_cpu(sbi->ckpt->valid_inode_count);
  866. sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
  867. sbi->total_valid_block_count =
  868. le64_to_cpu(sbi->ckpt->valid_block_count);
  869. sbi->last_valid_block_count = sbi->total_valid_block_count;
  870. sbi->alloc_valid_block_count = 0;
  871. INIT_LIST_HEAD(&sbi->dir_inode_list);
  872. spin_lock_init(&sbi->dir_inode_lock);
  873. init_ino_entry_info(sbi);
  874. /* setup f2fs internal modules */
  875. err = build_segment_manager(sbi);
  876. if (err) {
  877. f2fs_msg(sb, KERN_ERR,
  878. "Failed to initialize F2FS segment manager");
  879. goto free_sm;
  880. }
  881. err = build_node_manager(sbi);
  882. if (err) {
  883. f2fs_msg(sb, KERN_ERR,
  884. "Failed to initialize F2FS node manager");
  885. goto free_nm;
  886. }
  887. build_gc_manager(sbi);
  888. /* get an inode for node space */
  889. sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
  890. if (IS_ERR(sbi->node_inode)) {
  891. f2fs_msg(sb, KERN_ERR, "Failed to read node inode");
  892. err = PTR_ERR(sbi->node_inode);
  893. goto free_nm;
  894. }
  895. /* if there are nt orphan nodes free them */
  896. recover_orphan_inodes(sbi);
  897. /* read root inode and dentry */
  898. root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
  899. if (IS_ERR(root)) {
  900. f2fs_msg(sb, KERN_ERR, "Failed to read root inode");
  901. err = PTR_ERR(root);
  902. goto free_node_inode;
  903. }
  904. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  905. iput(root);
  906. err = -EINVAL;
  907. goto free_node_inode;
  908. }
  909. sb->s_root = d_make_root(root); /* allocate root dentry */
  910. if (!sb->s_root) {
  911. err = -ENOMEM;
  912. goto free_root_inode;
  913. }
  914. err = f2fs_build_stats(sbi);
  915. if (err)
  916. goto free_root_inode;
  917. if (f2fs_proc_root)
  918. sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
  919. if (sbi->s_proc)
  920. proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
  921. &f2fs_seq_segment_info_fops, sb);
  922. if (test_opt(sbi, DISCARD)) {
  923. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  924. if (!blk_queue_discard(q))
  925. f2fs_msg(sb, KERN_WARNING,
  926. "mounting with \"discard\" option, but "
  927. "the device does not support discard");
  928. }
  929. sbi->s_kobj.kset = f2fs_kset;
  930. init_completion(&sbi->s_kobj_unregister);
  931. err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL,
  932. "%s", sb->s_id);
  933. if (err)
  934. goto free_proc;
  935. /* recover fsynced data */
  936. if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
  937. err = recover_fsync_data(sbi);
  938. if (err)
  939. f2fs_msg(sb, KERN_ERR,
  940. "Cannot recover all fsync data errno=%ld", err);
  941. }
  942. /*
  943. * If filesystem is not mounted as read-only then
  944. * do start the gc_thread.
  945. */
  946. if (!f2fs_readonly(sb)) {
  947. /* After POR, we can run background GC thread.*/
  948. err = start_gc_thread(sbi);
  949. if (err)
  950. goto free_kobj;
  951. }
  952. return 0;
  953. free_kobj:
  954. kobject_del(&sbi->s_kobj);
  955. free_proc:
  956. if (sbi->s_proc) {
  957. remove_proc_entry("segment_info", sbi->s_proc);
  958. remove_proc_entry(sb->s_id, f2fs_proc_root);
  959. }
  960. f2fs_destroy_stats(sbi);
  961. free_root_inode:
  962. dput(sb->s_root);
  963. sb->s_root = NULL;
  964. free_node_inode:
  965. iput(sbi->node_inode);
  966. free_nm:
  967. destroy_node_manager(sbi);
  968. free_sm:
  969. destroy_segment_manager(sbi);
  970. free_cp:
  971. kfree(sbi->ckpt);
  972. free_meta_inode:
  973. make_bad_inode(sbi->meta_inode);
  974. iput(sbi->meta_inode);
  975. free_sb_buf:
  976. brelse(raw_super_buf);
  977. free_sbi:
  978. kfree(sbi);
  979. return err;
  980. }
  981. static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
  982. const char *dev_name, void *data)
  983. {
  984. return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super);
  985. }
  986. static struct file_system_type f2fs_fs_type = {
  987. .owner = THIS_MODULE,
  988. .name = "f2fs",
  989. .mount = f2fs_mount,
  990. .kill_sb = kill_block_super,
  991. .fs_flags = FS_REQUIRES_DEV,
  992. };
  993. MODULE_ALIAS_FS("f2fs");
  994. static int __init init_inodecache(void)
  995. {
  996. f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache",
  997. sizeof(struct f2fs_inode_info));
  998. if (!f2fs_inode_cachep)
  999. return -ENOMEM;
  1000. return 0;
  1001. }
  1002. static void destroy_inodecache(void)
  1003. {
  1004. /*
  1005. * Make sure all delayed rcu free inodes are flushed before we
  1006. * destroy cache.
  1007. */
  1008. rcu_barrier();
  1009. kmem_cache_destroy(f2fs_inode_cachep);
  1010. }
  1011. static int __init init_f2fs_fs(void)
  1012. {
  1013. int err;
  1014. err = init_inodecache();
  1015. if (err)
  1016. goto fail;
  1017. err = create_node_manager_caches();
  1018. if (err)
  1019. goto free_inodecache;
  1020. err = create_segment_manager_caches();
  1021. if (err)
  1022. goto free_node_manager_caches;
  1023. err = create_gc_caches();
  1024. if (err)
  1025. goto free_segment_manager_caches;
  1026. err = create_checkpoint_caches();
  1027. if (err)
  1028. goto free_gc_caches;
  1029. f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj);
  1030. if (!f2fs_kset) {
  1031. err = -ENOMEM;
  1032. goto free_checkpoint_caches;
  1033. }
  1034. err = register_filesystem(&f2fs_fs_type);
  1035. if (err)
  1036. goto free_kset;
  1037. f2fs_create_root_stats();
  1038. f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
  1039. return 0;
  1040. free_kset:
  1041. kset_unregister(f2fs_kset);
  1042. free_checkpoint_caches:
  1043. destroy_checkpoint_caches();
  1044. free_gc_caches:
  1045. destroy_gc_caches();
  1046. free_segment_manager_caches:
  1047. destroy_segment_manager_caches();
  1048. free_node_manager_caches:
  1049. destroy_node_manager_caches();
  1050. free_inodecache:
  1051. destroy_inodecache();
  1052. fail:
  1053. return err;
  1054. }
  1055. static void __exit exit_f2fs_fs(void)
  1056. {
  1057. remove_proc_entry("fs/f2fs", NULL);
  1058. f2fs_destroy_root_stats();
  1059. unregister_filesystem(&f2fs_fs_type);
  1060. destroy_checkpoint_caches();
  1061. destroy_gc_caches();
  1062. destroy_segment_manager_caches();
  1063. destroy_node_manager_caches();
  1064. destroy_inodecache();
  1065. kset_unregister(f2fs_kset);
  1066. }
  1067. module_init(init_f2fs_fs)
  1068. module_exit(exit_f2fs_fs)
  1069. MODULE_AUTHOR("Samsung Electronics's Praesto Team");
  1070. MODULE_DESCRIPTION("Flash Friendly File System");
  1071. MODULE_LICENSE("GPL");