4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
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.
11 #include <linux/module.h>
12 #include <linux/init.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/random.h>
22 #include <linux/exportfs.h>
23 #include <linux/blkdev.h>
24 #include <linux/f2fs_fs.h>
31 #define CREATE_TRACE_POINTS
32 #include <trace/events/f2fs.h>
34 static struct kmem_cache
*f2fs_inode_cachep
;
38 Opt_disable_roll_forward
,
44 Opt_disable_ext_identify
,
48 static match_table_t f2fs_tokens
= {
49 {Opt_gc_background
, "background_gc=%s"},
50 {Opt_disable_roll_forward
, "disable_roll_forward"},
51 {Opt_discard
, "discard"},
52 {Opt_noheap
, "no_heap"},
53 {Opt_nouser_xattr
, "nouser_xattr"},
55 {Opt_active_logs
, "active_logs=%u"},
56 {Opt_disable_ext_identify
, "disable_ext_identify"},
60 void f2fs_msg(struct super_block
*sb
, const char *level
, const char *fmt
, ...)
68 printk("%sF2FS-fs (%s): %pV\n", level
, sb
->s_id
, &vaf
);
72 static void init_once(void *foo
)
74 struct f2fs_inode_info
*fi
= (struct f2fs_inode_info
*) foo
;
76 inode_init_once(&fi
->vfs_inode
);
79 static int parse_options(struct super_block
*sb
, char *options
)
81 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
82 substring_t args
[MAX_OPT_ARGS
];
89 while ((p
= strsep(&options
, ",")) != NULL
) {
94 * Initialize args struct so we know whether arg was
95 * found; some options take optional arguments.
97 args
[0].to
= args
[0].from
= NULL
;
98 token
= match_token(p
, f2fs_tokens
, args
);
101 case Opt_gc_background
:
102 name
= match_strdup(&args
[0]);
106 if (!strncmp(name
, "on", 2))
108 else if (!strncmp(name
, "off", 3))
109 clear_opt(sbi
, BG_GC
);
116 case Opt_disable_roll_forward
:
117 set_opt(sbi
, DISABLE_ROLL_FORWARD
);
120 set_opt(sbi
, DISCARD
);
123 set_opt(sbi
, NOHEAP
);
125 #ifdef CONFIG_F2FS_FS_XATTR
126 case Opt_nouser_xattr
:
127 clear_opt(sbi
, XATTR_USER
);
130 case Opt_nouser_xattr
:
131 f2fs_msg(sb
, KERN_INFO
,
132 "nouser_xattr options not supported");
135 #ifdef CONFIG_F2FS_FS_POSIX_ACL
137 clear_opt(sbi
, POSIX_ACL
);
141 f2fs_msg(sb
, KERN_INFO
, "noacl options not supported");
144 case Opt_active_logs
:
145 if (args
->from
&& match_int(args
, &arg
))
147 if (arg
!= 2 && arg
!= 4 && arg
!= NR_CURSEG_TYPE
)
149 sbi
->active_logs
= arg
;
151 case Opt_disable_ext_identify
:
152 set_opt(sbi
, DISABLE_EXT_IDENTIFY
);
155 f2fs_msg(sb
, KERN_ERR
,
156 "Unrecognized mount option \"%s\" or missing value",
164 static struct inode
*f2fs_alloc_inode(struct super_block
*sb
)
166 struct f2fs_inode_info
*fi
;
168 fi
= kmem_cache_alloc(f2fs_inode_cachep
, GFP_NOFS
| __GFP_ZERO
);
172 init_once((void *) fi
);
174 /* Initialize f2fs-specific inode info */
175 fi
->vfs_inode
.i_version
= 1;
176 atomic_set(&fi
->dirty_dents
, 0);
177 fi
->i_current_depth
= 1;
179 rwlock_init(&fi
->ext
.ext_lock
);
181 set_inode_flag(fi
, FI_NEW_INODE
);
183 return &fi
->vfs_inode
;
186 static int f2fs_drop_inode(struct inode
*inode
)
189 * This is to avoid a deadlock condition like below.
190 * writeback_single_inode(inode)
191 * - f2fs_write_data_page
192 * - f2fs_gc -> iput -> evict
193 * - inode_wait_for_writeback(inode)
195 if (!inode_unhashed(inode
) && inode
->i_state
& I_SYNC
)
197 return generic_drop_inode(inode
);
201 * f2fs_dirty_inode() is called from __mark_inode_dirty()
203 * We should call set_dirty_inode to write the dirty inode through write_inode.
205 static void f2fs_dirty_inode(struct inode
*inode
, int flags
)
207 set_inode_flag(F2FS_I(inode
), FI_DIRTY_INODE
);
211 static void f2fs_i_callback(struct rcu_head
*head
)
213 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
214 kmem_cache_free(f2fs_inode_cachep
, F2FS_I(inode
));
217 static void f2fs_destroy_inode(struct inode
*inode
)
219 call_rcu(&inode
->i_rcu
, f2fs_i_callback
);
222 static void f2fs_put_super(struct super_block
*sb
)
224 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
226 f2fs_destroy_stats(sbi
);
229 write_checkpoint(sbi
, true);
231 iput(sbi
->node_inode
);
232 iput(sbi
->meta_inode
);
234 /* destroy f2fs internal modules */
235 destroy_node_manager(sbi
);
236 destroy_segment_manager(sbi
);
240 sb
->s_fs_info
= NULL
;
241 brelse(sbi
->raw_super_buf
);
245 int f2fs_sync_fs(struct super_block
*sb
, int sync
)
247 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
249 trace_f2fs_sync_fs(sb
, sync
);
251 if (!sbi
->s_dirty
&& !get_pages(sbi
, F2FS_DIRTY_NODES
))
255 mutex_lock(&sbi
->gc_mutex
);
256 write_checkpoint(sbi
, false);
257 mutex_unlock(&sbi
->gc_mutex
);
259 f2fs_balance_fs(sbi
);
265 static int f2fs_freeze(struct super_block
*sb
)
269 if (f2fs_readonly(sb
))
272 err
= f2fs_sync_fs(sb
, 1);
276 static int f2fs_unfreeze(struct super_block
*sb
)
281 static int f2fs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
283 struct super_block
*sb
= dentry
->d_sb
;
284 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
285 u64 id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
286 block_t total_count
, user_block_count
, start_count
, ovp_count
;
288 total_count
= le64_to_cpu(sbi
->raw_super
->block_count
);
289 user_block_count
= sbi
->user_block_count
;
290 start_count
= le32_to_cpu(sbi
->raw_super
->segment0_blkaddr
);
291 ovp_count
= SM_I(sbi
)->ovp_segments
<< sbi
->log_blocks_per_seg
;
292 buf
->f_type
= F2FS_SUPER_MAGIC
;
293 buf
->f_bsize
= sbi
->blocksize
;
295 buf
->f_blocks
= total_count
- start_count
;
296 buf
->f_bfree
= buf
->f_blocks
- valid_user_blocks(sbi
) - ovp_count
;
297 buf
->f_bavail
= user_block_count
- valid_user_blocks(sbi
);
299 buf
->f_files
= sbi
->total_node_count
;
300 buf
->f_ffree
= sbi
->total_node_count
- valid_inode_count(sbi
);
302 buf
->f_namelen
= F2FS_NAME_LEN
;
303 buf
->f_fsid
.val
[0] = (u32
)id
;
304 buf
->f_fsid
.val
[1] = (u32
)(id
>> 32);
309 static int f2fs_show_options(struct seq_file
*seq
, struct dentry
*root
)
311 struct f2fs_sb_info
*sbi
= F2FS_SB(root
->d_sb
);
313 if (!(root
->d_sb
->s_flags
& MS_RDONLY
) && test_opt(sbi
, BG_GC
))
314 seq_printf(seq
, ",background_gc=%s", "on");
316 seq_printf(seq
, ",background_gc=%s", "off");
317 if (test_opt(sbi
, DISABLE_ROLL_FORWARD
))
318 seq_puts(seq
, ",disable_roll_forward");
319 if (test_opt(sbi
, DISCARD
))
320 seq_puts(seq
, ",discard");
321 if (test_opt(sbi
, NOHEAP
))
322 seq_puts(seq
, ",no_heap_alloc");
323 #ifdef CONFIG_F2FS_FS_XATTR
324 if (test_opt(sbi
, XATTR_USER
))
325 seq_puts(seq
, ",user_xattr");
327 seq_puts(seq
, ",nouser_xattr");
329 #ifdef CONFIG_F2FS_FS_POSIX_ACL
330 if (test_opt(sbi
, POSIX_ACL
))
331 seq_puts(seq
, ",acl");
333 seq_puts(seq
, ",noacl");
335 if (test_opt(sbi
, DISABLE_EXT_IDENTIFY
))
336 seq_puts(seq
, ",disable_ext_identify");
338 seq_printf(seq
, ",active_logs=%u", sbi
->active_logs
);
343 static int f2fs_remount(struct super_block
*sb
, int *flags
, char *data
)
345 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
346 struct f2fs_mount_info org_mount_opt
;
347 int err
, active_logs
;
350 * Save the old mount options in case we
351 * need to restore them.
353 org_mount_opt
= sbi
->mount_opt
;
354 active_logs
= sbi
->active_logs
;
356 /* parse mount options */
357 err
= parse_options(sb
, data
);
362 * Previous and new state of filesystem is RO,
363 * so no point in checking GC conditions.
365 if ((sb
->s_flags
& MS_RDONLY
) && (*flags
& MS_RDONLY
))
369 * We stop the GC thread if FS is mounted as RO
370 * or if background_gc = off is passed in mount
371 * option. Also sync the filesystem.
373 if ((*flags
& MS_RDONLY
) || !test_opt(sbi
, BG_GC
)) {
374 if (sbi
->gc_thread
) {
378 } else if (test_opt(sbi
, BG_GC
) && !sbi
->gc_thread
) {
379 err
= start_gc_thread(sbi
);
384 /* Update the POSIXACL Flag */
385 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
386 (test_opt(sbi
, POSIX_ACL
) ? MS_POSIXACL
: 0);
390 sbi
->mount_opt
= org_mount_opt
;
391 sbi
->active_logs
= active_logs
;
395 static struct super_operations f2fs_sops
= {
396 .alloc_inode
= f2fs_alloc_inode
,
397 .drop_inode
= f2fs_drop_inode
,
398 .destroy_inode
= f2fs_destroy_inode
,
399 .write_inode
= f2fs_write_inode
,
400 .dirty_inode
= f2fs_dirty_inode
,
401 .show_options
= f2fs_show_options
,
402 .evict_inode
= f2fs_evict_inode
,
403 .put_super
= f2fs_put_super
,
404 .sync_fs
= f2fs_sync_fs
,
405 .freeze_fs
= f2fs_freeze
,
406 .unfreeze_fs
= f2fs_unfreeze
,
407 .statfs
= f2fs_statfs
,
408 .remount_fs
= f2fs_remount
,
411 static struct inode
*f2fs_nfs_get_inode(struct super_block
*sb
,
412 u64 ino
, u32 generation
)
414 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
417 if (ino
< F2FS_ROOT_INO(sbi
))
418 return ERR_PTR(-ESTALE
);
421 * f2fs_iget isn't quite right if the inode is currently unallocated!
422 * However f2fs_iget currently does appropriate checks to handle stale
423 * inodes so everything is OK.
425 inode
= f2fs_iget(sb
, ino
);
427 return ERR_CAST(inode
);
428 if (generation
&& inode
->i_generation
!= generation
) {
429 /* we didn't find the right inode.. */
431 return ERR_PTR(-ESTALE
);
436 static struct dentry
*f2fs_fh_to_dentry(struct super_block
*sb
, struct fid
*fid
,
437 int fh_len
, int fh_type
)
439 return generic_fh_to_dentry(sb
, fid
, fh_len
, fh_type
,
443 static struct dentry
*f2fs_fh_to_parent(struct super_block
*sb
, struct fid
*fid
,
444 int fh_len
, int fh_type
)
446 return generic_fh_to_parent(sb
, fid
, fh_len
, fh_type
,
450 static const struct export_operations f2fs_export_ops
= {
451 .fh_to_dentry
= f2fs_fh_to_dentry
,
452 .fh_to_parent
= f2fs_fh_to_parent
,
453 .get_parent
= f2fs_get_parent
,
456 static loff_t
max_file_size(unsigned bits
)
458 loff_t result
= ADDRS_PER_INODE
;
459 loff_t leaf_count
= ADDRS_PER_BLOCK
;
461 /* two direct node blocks */
462 result
+= (leaf_count
* 2);
464 /* two indirect node blocks */
465 leaf_count
*= NIDS_PER_BLOCK
;
466 result
+= (leaf_count
* 2);
468 /* one double indirect node block */
469 leaf_count
*= NIDS_PER_BLOCK
;
470 result
+= leaf_count
;
476 static int sanity_check_raw_super(struct super_block
*sb
,
477 struct f2fs_super_block
*raw_super
)
479 unsigned int blocksize
;
481 if (F2FS_SUPER_MAGIC
!= le32_to_cpu(raw_super
->magic
)) {
482 f2fs_msg(sb
, KERN_INFO
,
483 "Magic Mismatch, valid(0x%x) - read(0x%x)",
484 F2FS_SUPER_MAGIC
, le32_to_cpu(raw_super
->magic
));
488 /* Currently, support only 4KB page cache size */
489 if (F2FS_BLKSIZE
!= PAGE_CACHE_SIZE
) {
490 f2fs_msg(sb
, KERN_INFO
,
491 "Invalid page_cache_size (%lu), supports only 4KB\n",
496 /* Currently, support only 4KB block size */
497 blocksize
= 1 << le32_to_cpu(raw_super
->log_blocksize
);
498 if (blocksize
!= F2FS_BLKSIZE
) {
499 f2fs_msg(sb
, KERN_INFO
,
500 "Invalid blocksize (%u), supports only 4KB\n",
505 if (le32_to_cpu(raw_super
->log_sectorsize
) !=
506 F2FS_LOG_SECTOR_SIZE
) {
507 f2fs_msg(sb
, KERN_INFO
, "Invalid log sectorsize");
510 if (le32_to_cpu(raw_super
->log_sectors_per_block
) !=
511 F2FS_LOG_SECTORS_PER_BLOCK
) {
512 f2fs_msg(sb
, KERN_INFO
, "Invalid log sectors per block");
518 static int sanity_check_ckpt(struct f2fs_sb_info
*sbi
)
520 unsigned int total
, fsmeta
;
521 struct f2fs_super_block
*raw_super
= F2FS_RAW_SUPER(sbi
);
522 struct f2fs_checkpoint
*ckpt
= F2FS_CKPT(sbi
);
524 total
= le32_to_cpu(raw_super
->segment_count
);
525 fsmeta
= le32_to_cpu(raw_super
->segment_count_ckpt
);
526 fsmeta
+= le32_to_cpu(raw_super
->segment_count_sit
);
527 fsmeta
+= le32_to_cpu(raw_super
->segment_count_nat
);
528 fsmeta
+= le32_to_cpu(ckpt
->rsvd_segment_count
);
529 fsmeta
+= le32_to_cpu(raw_super
->segment_count_ssa
);
534 if (is_set_ckpt_flags(ckpt
, CP_ERROR_FLAG
)) {
535 f2fs_msg(sbi
->sb
, KERN_ERR
, "A bug case: need to run fsck");
541 static void init_sb_info(struct f2fs_sb_info
*sbi
)
543 struct f2fs_super_block
*raw_super
= sbi
->raw_super
;
546 sbi
->log_sectors_per_block
=
547 le32_to_cpu(raw_super
->log_sectors_per_block
);
548 sbi
->log_blocksize
= le32_to_cpu(raw_super
->log_blocksize
);
549 sbi
->blocksize
= 1 << sbi
->log_blocksize
;
550 sbi
->log_blocks_per_seg
= le32_to_cpu(raw_super
->log_blocks_per_seg
);
551 sbi
->blocks_per_seg
= 1 << sbi
->log_blocks_per_seg
;
552 sbi
->segs_per_sec
= le32_to_cpu(raw_super
->segs_per_sec
);
553 sbi
->secs_per_zone
= le32_to_cpu(raw_super
->secs_per_zone
);
554 sbi
->total_sections
= le32_to_cpu(raw_super
->section_count
);
555 sbi
->total_node_count
=
556 (le32_to_cpu(raw_super
->segment_count_nat
) / 2)
557 * sbi
->blocks_per_seg
* NAT_ENTRY_PER_BLOCK
;
558 sbi
->root_ino_num
= le32_to_cpu(raw_super
->root_ino
);
559 sbi
->node_ino_num
= le32_to_cpu(raw_super
->node_ino
);
560 sbi
->meta_ino_num
= le32_to_cpu(raw_super
->meta_ino
);
561 sbi
->cur_victim_sec
= NULL_SECNO
;
563 for (i
= 0; i
< NR_COUNT_TYPE
; i
++)
564 atomic_set(&sbi
->nr_pages
[i
], 0);
567 static int validate_superblock(struct super_block
*sb
,
568 struct f2fs_super_block
**raw_super
,
569 struct buffer_head
**raw_super_buf
, sector_t block
)
571 const char *super
= (block
== 0 ? "first" : "second");
573 /* read f2fs raw super block */
574 *raw_super_buf
= sb_bread(sb
, block
);
575 if (!*raw_super_buf
) {
576 f2fs_msg(sb
, KERN_ERR
, "unable to read %s superblock",
581 *raw_super
= (struct f2fs_super_block
*)
582 ((char *)(*raw_super_buf
)->b_data
+ F2FS_SUPER_OFFSET
);
584 /* sanity checking of raw super */
585 if (!sanity_check_raw_super(sb
, *raw_super
))
588 f2fs_msg(sb
, KERN_ERR
, "Can't find a valid F2FS filesystem "
589 "in %s superblock", super
);
593 static int f2fs_fill_super(struct super_block
*sb
, void *data
, int silent
)
595 struct f2fs_sb_info
*sbi
;
596 struct f2fs_super_block
*raw_super
;
597 struct buffer_head
*raw_super_buf
;
602 /* allocate memory for f2fs-specific super block info */
603 sbi
= kzalloc(sizeof(struct f2fs_sb_info
), GFP_KERNEL
);
607 /* set a block size */
608 if (!sb_set_blocksize(sb
, F2FS_BLKSIZE
)) {
609 f2fs_msg(sb
, KERN_ERR
, "unable to set blocksize");
613 err
= validate_superblock(sb
, &raw_super
, &raw_super_buf
, 0);
615 brelse(raw_super_buf
);
616 /* check secondary superblock when primary failed */
617 err
= validate_superblock(sb
, &raw_super
, &raw_super_buf
, 1);
622 /* init some FS parameters */
623 sbi
->active_logs
= NR_CURSEG_TYPE
;
627 #ifdef CONFIG_F2FS_FS_XATTR
628 set_opt(sbi
, XATTR_USER
);
630 #ifdef CONFIG_F2FS_FS_POSIX_ACL
631 set_opt(sbi
, POSIX_ACL
);
633 /* parse mount options */
634 err
= parse_options(sb
, (char *)data
);
638 sb
->s_maxbytes
= max_file_size(le32_to_cpu(raw_super
->log_blocksize
));
639 sb
->s_max_links
= F2FS_LINK_MAX
;
640 get_random_bytes(&sbi
->s_next_generation
, sizeof(u32
));
642 sb
->s_op
= &f2fs_sops
;
643 sb
->s_xattr
= f2fs_xattr_handlers
;
644 sb
->s_export_op
= &f2fs_export_ops
;
645 sb
->s_magic
= F2FS_SUPER_MAGIC
;
647 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
648 (test_opt(sbi
, POSIX_ACL
) ? MS_POSIXACL
: 0);
649 memcpy(sb
->s_uuid
, raw_super
->uuid
, sizeof(raw_super
->uuid
));
651 /* init f2fs-specific super block info */
653 sbi
->raw_super
= raw_super
;
654 sbi
->raw_super_buf
= raw_super_buf
;
655 mutex_init(&sbi
->gc_mutex
);
656 mutex_init(&sbi
->writepages
);
657 mutex_init(&sbi
->cp_mutex
);
658 for (i
= 0; i
< NR_GLOBAL_LOCKS
; i
++)
659 mutex_init(&sbi
->fs_lock
[i
]);
660 mutex_init(&sbi
->node_write
);
662 spin_lock_init(&sbi
->stat_lock
);
663 init_rwsem(&sbi
->bio_sem
);
666 /* get an inode for meta space */
667 sbi
->meta_inode
= f2fs_iget(sb
, F2FS_META_INO(sbi
));
668 if (IS_ERR(sbi
->meta_inode
)) {
669 f2fs_msg(sb
, KERN_ERR
, "Failed to read F2FS meta data inode");
670 err
= PTR_ERR(sbi
->meta_inode
);
674 err
= get_valid_checkpoint(sbi
);
676 f2fs_msg(sb
, KERN_ERR
, "Failed to get valid F2FS checkpoint");
677 goto free_meta_inode
;
680 /* sanity checking of checkpoint */
682 if (sanity_check_ckpt(sbi
)) {
683 f2fs_msg(sb
, KERN_ERR
, "Invalid F2FS checkpoint");
687 sbi
->total_valid_node_count
=
688 le32_to_cpu(sbi
->ckpt
->valid_node_count
);
689 sbi
->total_valid_inode_count
=
690 le32_to_cpu(sbi
->ckpt
->valid_inode_count
);
691 sbi
->user_block_count
= le64_to_cpu(sbi
->ckpt
->user_block_count
);
692 sbi
->total_valid_block_count
=
693 le64_to_cpu(sbi
->ckpt
->valid_block_count
);
694 sbi
->last_valid_block_count
= sbi
->total_valid_block_count
;
695 sbi
->alloc_valid_block_count
= 0;
696 INIT_LIST_HEAD(&sbi
->dir_inode_list
);
697 spin_lock_init(&sbi
->dir_inode_lock
);
699 init_orphan_info(sbi
);
701 /* setup f2fs internal modules */
702 err
= build_segment_manager(sbi
);
704 f2fs_msg(sb
, KERN_ERR
,
705 "Failed to initialize F2FS segment manager");
708 err
= build_node_manager(sbi
);
710 f2fs_msg(sb
, KERN_ERR
,
711 "Failed to initialize F2FS node manager");
715 build_gc_manager(sbi
);
717 /* get an inode for node space */
718 sbi
->node_inode
= f2fs_iget(sb
, F2FS_NODE_INO(sbi
));
719 if (IS_ERR(sbi
->node_inode
)) {
720 f2fs_msg(sb
, KERN_ERR
, "Failed to read node inode");
721 err
= PTR_ERR(sbi
->node_inode
);
725 /* if there are nt orphan nodes free them */
727 if (recover_orphan_inodes(sbi
))
728 goto free_node_inode
;
730 /* read root inode and dentry */
731 root
= f2fs_iget(sb
, F2FS_ROOT_INO(sbi
));
733 f2fs_msg(sb
, KERN_ERR
, "Failed to read root inode");
735 goto free_node_inode
;
737 if (!S_ISDIR(root
->i_mode
) || !root
->i_blocks
|| !root
->i_size
)
738 goto free_root_inode
;
740 sb
->s_root
= d_make_root(root
); /* allocate root dentry */
743 goto free_root_inode
;
746 /* recover fsynced data */
747 if (!test_opt(sbi
, DISABLE_ROLL_FORWARD
)) {
748 err
= recover_fsync_data(sbi
);
750 f2fs_msg(sb
, KERN_ERR
,
751 "Cannot recover all fsync data errno=%ld", err
);
755 * If filesystem is not mounted as read-only then
756 * do start the gc_thread.
758 if (!(sb
->s_flags
& MS_RDONLY
)) {
759 /* After POR, we can run background GC thread.*/
760 err
= start_gc_thread(sbi
);
765 err
= f2fs_build_stats(sbi
);
769 if (test_opt(sbi
, DISCARD
)) {
770 struct request_queue
*q
= bdev_get_queue(sb
->s_bdev
);
771 if (!blk_queue_discard(q
))
772 f2fs_msg(sb
, KERN_WARNING
,
773 "mounting with \"discard\" option, but "
774 "the device does not support discard");
784 iput(sbi
->node_inode
);
786 destroy_node_manager(sbi
);
788 destroy_segment_manager(sbi
);
792 make_bad_inode(sbi
->meta_inode
);
793 iput(sbi
->meta_inode
);
795 brelse(raw_super_buf
);
801 static struct dentry
*f2fs_mount(struct file_system_type
*fs_type
, int flags
,
802 const char *dev_name
, void *data
)
804 return mount_bdev(fs_type
, flags
, dev_name
, data
, f2fs_fill_super
);
807 static struct file_system_type f2fs_fs_type
= {
808 .owner
= THIS_MODULE
,
811 .kill_sb
= kill_block_super
,
812 .fs_flags
= FS_REQUIRES_DEV
,
814 MODULE_ALIAS_FS("f2fs");
816 static int __init
init_inodecache(void)
818 f2fs_inode_cachep
= f2fs_kmem_cache_create("f2fs_inode_cache",
819 sizeof(struct f2fs_inode_info
), NULL
);
820 if (f2fs_inode_cachep
== NULL
)
825 static void destroy_inodecache(void)
828 * Make sure all delayed rcu free inodes are flushed before we
832 kmem_cache_destroy(f2fs_inode_cachep
);
835 static int __init
init_f2fs_fs(void)
839 err
= init_inodecache();
842 err
= create_node_manager_caches();
845 err
= create_gc_caches();
848 err
= create_checkpoint_caches();
851 err
= register_filesystem(&f2fs_fs_type
);
854 f2fs_create_root_stats();
859 static void __exit
exit_f2fs_fs(void)
861 f2fs_destroy_root_stats();
862 unregister_filesystem(&f2fs_fs_type
);
863 destroy_checkpoint_caches();
865 destroy_node_manager_caches();
866 destroy_inodecache();
869 module_init(init_f2fs_fs
)
870 module_exit(exit_f2fs_fs
)
872 MODULE_AUTHOR("Samsung Electronics's Praesto Team");
873 MODULE_DESCRIPTION("Flash Friendly File System");
874 MODULE_LICENSE("GPL");