Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 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> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 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> |
Namjae Jeon | d3ee456 | 2013-03-17 17:26:14 +0900 | [diff] [blame] | 23 | #include <linux/blkdev.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 24 | #include <linux/f2fs_fs.h> |
| 25 | |
| 26 | #include "f2fs.h" |
| 27 | #include "node.h" |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 28 | #include "segment.h" |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 29 | #include "xattr.h" |
| 30 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 31 | #define CREATE_TRACE_POINTS |
| 32 | #include <trace/events/f2fs.h> |
| 33 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 34 | static struct kmem_cache *f2fs_inode_cachep; |
| 35 | |
| 36 | enum { |
| 37 | Opt_gc_background_off, |
| 38 | Opt_disable_roll_forward, |
| 39 | Opt_discard, |
| 40 | Opt_noheap, |
| 41 | Opt_nouser_xattr, |
| 42 | Opt_noacl, |
| 43 | Opt_active_logs, |
| 44 | Opt_disable_ext_identify, |
| 45 | Opt_err, |
| 46 | }; |
| 47 | |
| 48 | static match_table_t f2fs_tokens = { |
| 49 | {Opt_gc_background_off, "background_gc_off"}, |
| 50 | {Opt_disable_roll_forward, "disable_roll_forward"}, |
| 51 | {Opt_discard, "discard"}, |
| 52 | {Opt_noheap, "no_heap"}, |
| 53 | {Opt_nouser_xattr, "nouser_xattr"}, |
| 54 | {Opt_noacl, "noacl"}, |
| 55 | {Opt_active_logs, "active_logs=%u"}, |
| 56 | {Opt_disable_ext_identify, "disable_ext_identify"}, |
| 57 | {Opt_err, NULL}, |
| 58 | }; |
| 59 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 60 | void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) |
| 61 | { |
| 62 | struct va_format vaf; |
| 63 | va_list args; |
| 64 | |
| 65 | va_start(args, fmt); |
| 66 | vaf.fmt = fmt; |
| 67 | vaf.va = &args; |
| 68 | printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf); |
| 69 | va_end(args); |
| 70 | } |
| 71 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 72 | static void init_once(void *foo) |
| 73 | { |
| 74 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; |
| 75 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 76 | inode_init_once(&fi->vfs_inode); |
| 77 | } |
| 78 | |
| 79 | static struct inode *f2fs_alloc_inode(struct super_block *sb) |
| 80 | { |
| 81 | struct f2fs_inode_info *fi; |
| 82 | |
| 83 | fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_NOFS | __GFP_ZERO); |
| 84 | if (!fi) |
| 85 | return NULL; |
| 86 | |
| 87 | init_once((void *) fi); |
| 88 | |
Masanari Iida | 434720f | 2013-03-19 08:03:35 +0900 | [diff] [blame] | 89 | /* Initialize f2fs-specific inode info */ |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 90 | fi->vfs_inode.i_version = 1; |
| 91 | atomic_set(&fi->dirty_dents, 0); |
| 92 | fi->i_current_depth = 1; |
| 93 | fi->i_advise = 0; |
| 94 | rwlock_init(&fi->ext.ext_lock); |
| 95 | |
| 96 | set_inode_flag(fi, FI_NEW_INODE); |
| 97 | |
| 98 | return &fi->vfs_inode; |
| 99 | } |
| 100 | |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 101 | static int f2fs_drop_inode(struct inode *inode) |
| 102 | { |
| 103 | /* |
| 104 | * This is to avoid a deadlock condition like below. |
| 105 | * writeback_single_inode(inode) |
| 106 | * - f2fs_write_data_page |
| 107 | * - f2fs_gc -> iput -> evict |
| 108 | * - inode_wait_for_writeback(inode) |
| 109 | */ |
| 110 | if (!inode_unhashed(inode) && inode->i_state & I_SYNC) |
| 111 | return 0; |
| 112 | return generic_drop_inode(inode); |
| 113 | } |
| 114 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 115 | static void f2fs_i_callback(struct rcu_head *head) |
| 116 | { |
| 117 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 118 | kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode)); |
| 119 | } |
| 120 | |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 121 | static void f2fs_destroy_inode(struct inode *inode) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 122 | { |
| 123 | call_rcu(&inode->i_rcu, f2fs_i_callback); |
| 124 | } |
| 125 | |
| 126 | static void f2fs_put_super(struct super_block *sb) |
| 127 | { |
| 128 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 129 | |
| 130 | f2fs_destroy_stats(sbi); |
| 131 | stop_gc_thread(sbi); |
| 132 | |
Jaegeuk Kim | 4372752 | 2013-02-04 15:11:17 +0900 | [diff] [blame] | 133 | write_checkpoint(sbi, true); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 134 | |
| 135 | iput(sbi->node_inode); |
| 136 | iput(sbi->meta_inode); |
| 137 | |
| 138 | /* destroy f2fs internal modules */ |
| 139 | destroy_node_manager(sbi); |
| 140 | destroy_segment_manager(sbi); |
| 141 | |
| 142 | kfree(sbi->ckpt); |
| 143 | |
| 144 | sb->s_fs_info = NULL; |
| 145 | brelse(sbi->raw_super_buf); |
| 146 | kfree(sbi); |
| 147 | } |
| 148 | |
| 149 | int f2fs_sync_fs(struct super_block *sb, int sync) |
| 150 | { |
| 151 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 152 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 153 | trace_f2fs_sync_fs(sb, sync); |
| 154 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 155 | if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) |
| 156 | return 0; |
| 157 | |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 158 | if (sync) { |
| 159 | mutex_lock(&sbi->gc_mutex); |
Jaegeuk Kim | 4372752 | 2013-02-04 15:11:17 +0900 | [diff] [blame] | 160 | write_checkpoint(sbi, false); |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 161 | mutex_unlock(&sbi->gc_mutex); |
| 162 | } else { |
Jaegeuk Kim | 7d82db8 | 2013-01-11 13:10:49 +0900 | [diff] [blame] | 163 | f2fs_balance_fs(sbi); |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 164 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 165 | |
Namjae Jeon | 64c576f | 2012-12-22 12:10:27 +0900 | [diff] [blame] | 166 | return 0; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 167 | } |
| 168 | |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 169 | static int f2fs_freeze(struct super_block *sb) |
| 170 | { |
| 171 | int err; |
| 172 | |
Jaegeuk Kim | 77888c1 | 2013-05-20 20:28:47 +0900 | [diff] [blame^] | 173 | if (f2fs_readonly(sb)) |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 174 | return 0; |
| 175 | |
| 176 | err = f2fs_sync_fs(sb, 1); |
| 177 | return err; |
| 178 | } |
| 179 | |
| 180 | static int f2fs_unfreeze(struct super_block *sb) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 185 | static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 186 | { |
| 187 | struct super_block *sb = dentry->d_sb; |
| 188 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 189 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 190 | block_t total_count, user_block_count, start_count, ovp_count; |
| 191 | |
| 192 | total_count = le64_to_cpu(sbi->raw_super->block_count); |
| 193 | user_block_count = sbi->user_block_count; |
| 194 | start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); |
| 195 | ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg; |
| 196 | buf->f_type = F2FS_SUPER_MAGIC; |
| 197 | buf->f_bsize = sbi->blocksize; |
| 198 | |
| 199 | buf->f_blocks = total_count - start_count; |
| 200 | buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count; |
| 201 | buf->f_bavail = user_block_count - valid_user_blocks(sbi); |
| 202 | |
Jaegeuk Kim | 1362b5e | 2012-12-12 19:45:49 +0900 | [diff] [blame] | 203 | buf->f_files = sbi->total_node_count; |
| 204 | buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 205 | |
Jaegeuk Kim | 5a20d33 | 2013-03-03 13:58:05 +0900 | [diff] [blame] | 206 | buf->f_namelen = F2FS_NAME_LEN; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 207 | buf->f_fsid.val[0] = (u32)id; |
| 208 | buf->f_fsid.val[1] = (u32)(id >> 32); |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static int f2fs_show_options(struct seq_file *seq, struct dentry *root) |
| 214 | { |
| 215 | struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); |
| 216 | |
| 217 | if (test_opt(sbi, BG_GC)) |
| 218 | seq_puts(seq, ",background_gc_on"); |
| 219 | else |
| 220 | seq_puts(seq, ",background_gc_off"); |
| 221 | if (test_opt(sbi, DISABLE_ROLL_FORWARD)) |
| 222 | seq_puts(seq, ",disable_roll_forward"); |
| 223 | if (test_opt(sbi, DISCARD)) |
| 224 | seq_puts(seq, ",discard"); |
| 225 | if (test_opt(sbi, NOHEAP)) |
| 226 | seq_puts(seq, ",no_heap_alloc"); |
| 227 | #ifdef CONFIG_F2FS_FS_XATTR |
| 228 | if (test_opt(sbi, XATTR_USER)) |
| 229 | seq_puts(seq, ",user_xattr"); |
| 230 | else |
| 231 | seq_puts(seq, ",nouser_xattr"); |
| 232 | #endif |
| 233 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 234 | if (test_opt(sbi, POSIX_ACL)) |
| 235 | seq_puts(seq, ",acl"); |
| 236 | else |
| 237 | seq_puts(seq, ",noacl"); |
| 238 | #endif |
| 239 | if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) |
Alejandro Martinez Ruiz | aa43507 | 2013-01-25 19:08:59 +0100 | [diff] [blame] | 240 | seq_puts(seq, ",disable_ext_identify"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 241 | |
| 242 | seq_printf(seq, ",active_logs=%u", sbi->active_logs); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static struct super_operations f2fs_sops = { |
| 248 | .alloc_inode = f2fs_alloc_inode, |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 249 | .drop_inode = f2fs_drop_inode, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 250 | .destroy_inode = f2fs_destroy_inode, |
| 251 | .write_inode = f2fs_write_inode, |
| 252 | .show_options = f2fs_show_options, |
| 253 | .evict_inode = f2fs_evict_inode, |
| 254 | .put_super = f2fs_put_super, |
| 255 | .sync_fs = f2fs_sync_fs, |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 256 | .freeze_fs = f2fs_freeze, |
| 257 | .unfreeze_fs = f2fs_unfreeze, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 258 | .statfs = f2fs_statfs, |
| 259 | }; |
| 260 | |
| 261 | static struct inode *f2fs_nfs_get_inode(struct super_block *sb, |
| 262 | u64 ino, u32 generation) |
| 263 | { |
| 264 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 265 | struct inode *inode; |
| 266 | |
| 267 | if (ino < F2FS_ROOT_INO(sbi)) |
| 268 | return ERR_PTR(-ESTALE); |
| 269 | |
| 270 | /* |
| 271 | * f2fs_iget isn't quite right if the inode is currently unallocated! |
| 272 | * However f2fs_iget currently does appropriate checks to handle stale |
| 273 | * inodes so everything is OK. |
| 274 | */ |
| 275 | inode = f2fs_iget(sb, ino); |
| 276 | if (IS_ERR(inode)) |
| 277 | return ERR_CAST(inode); |
| 278 | if (generation && inode->i_generation != generation) { |
| 279 | /* we didn't find the right inode.. */ |
| 280 | iput(inode); |
| 281 | return ERR_PTR(-ESTALE); |
| 282 | } |
| 283 | return inode; |
| 284 | } |
| 285 | |
| 286 | static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid, |
| 287 | int fh_len, int fh_type) |
| 288 | { |
| 289 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 290 | f2fs_nfs_get_inode); |
| 291 | } |
| 292 | |
| 293 | static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid, |
| 294 | int fh_len, int fh_type) |
| 295 | { |
| 296 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 297 | f2fs_nfs_get_inode); |
| 298 | } |
| 299 | |
| 300 | static const struct export_operations f2fs_export_ops = { |
| 301 | .fh_to_dentry = f2fs_fh_to_dentry, |
| 302 | .fh_to_parent = f2fs_fh_to_parent, |
| 303 | .get_parent = f2fs_get_parent, |
| 304 | }; |
| 305 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 306 | static int parse_options(struct super_block *sb, struct f2fs_sb_info *sbi, |
| 307 | char *options) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 308 | { |
| 309 | substring_t args[MAX_OPT_ARGS]; |
| 310 | char *p; |
| 311 | int arg = 0; |
| 312 | |
| 313 | if (!options) |
| 314 | return 0; |
| 315 | |
| 316 | while ((p = strsep(&options, ",")) != NULL) { |
| 317 | int token; |
| 318 | if (!*p) |
| 319 | continue; |
| 320 | /* |
| 321 | * Initialize args struct so we know whether arg was |
| 322 | * found; some options take optional arguments. |
| 323 | */ |
| 324 | args[0].to = args[0].from = NULL; |
| 325 | token = match_token(p, f2fs_tokens, args); |
| 326 | |
| 327 | switch (token) { |
| 328 | case Opt_gc_background_off: |
| 329 | clear_opt(sbi, BG_GC); |
| 330 | break; |
| 331 | case Opt_disable_roll_forward: |
| 332 | set_opt(sbi, DISABLE_ROLL_FORWARD); |
| 333 | break; |
| 334 | case Opt_discard: |
| 335 | set_opt(sbi, DISCARD); |
| 336 | break; |
| 337 | case Opt_noheap: |
| 338 | set_opt(sbi, NOHEAP); |
| 339 | break; |
| 340 | #ifdef CONFIG_F2FS_FS_XATTR |
| 341 | case Opt_nouser_xattr: |
| 342 | clear_opt(sbi, XATTR_USER); |
| 343 | break; |
| 344 | #else |
| 345 | case Opt_nouser_xattr: |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 346 | f2fs_msg(sb, KERN_INFO, |
| 347 | "nouser_xattr options not supported"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 348 | break; |
| 349 | #endif |
| 350 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 351 | case Opt_noacl: |
| 352 | clear_opt(sbi, POSIX_ACL); |
| 353 | break; |
| 354 | #else |
| 355 | case Opt_noacl: |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 356 | f2fs_msg(sb, KERN_INFO, "noacl options not supported"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 357 | break; |
| 358 | #endif |
| 359 | case Opt_active_logs: |
| 360 | if (args->from && match_int(args, &arg)) |
| 361 | return -EINVAL; |
Jaegeuk Kim | 12a6714 | 2012-12-21 11:47:05 +0900 | [diff] [blame] | 362 | if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 363 | return -EINVAL; |
| 364 | sbi->active_logs = arg; |
| 365 | break; |
| 366 | case Opt_disable_ext_identify: |
| 367 | set_opt(sbi, DISABLE_EXT_IDENTIFY); |
| 368 | break; |
| 369 | default: |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 370 | f2fs_msg(sb, KERN_ERR, |
| 371 | "Unrecognized mount option \"%s\" or missing value", |
| 372 | p); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 373 | return -EINVAL; |
| 374 | } |
| 375 | } |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static loff_t max_file_size(unsigned bits) |
| 380 | { |
| 381 | loff_t result = ADDRS_PER_INODE; |
| 382 | loff_t leaf_count = ADDRS_PER_BLOCK; |
| 383 | |
| 384 | /* two direct node blocks */ |
| 385 | result += (leaf_count * 2); |
| 386 | |
| 387 | /* two indirect node blocks */ |
| 388 | leaf_count *= NIDS_PER_BLOCK; |
| 389 | result += (leaf_count * 2); |
| 390 | |
| 391 | /* one double indirect node block */ |
| 392 | leaf_count *= NIDS_PER_BLOCK; |
| 393 | result += leaf_count; |
| 394 | |
| 395 | result <<= bits; |
| 396 | return result; |
| 397 | } |
| 398 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 399 | static int sanity_check_raw_super(struct super_block *sb, |
| 400 | struct f2fs_super_block *raw_super) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 401 | { |
| 402 | unsigned int blocksize; |
| 403 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 404 | if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) { |
| 405 | f2fs_msg(sb, KERN_INFO, |
| 406 | "Magic Mismatch, valid(0x%x) - read(0x%x)", |
| 407 | F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 408 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 409 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 410 | |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 411 | /* Currently, support only 4KB page cache size */ |
| 412 | if (F2FS_BLKSIZE != PAGE_CACHE_SIZE) { |
| 413 | f2fs_msg(sb, KERN_INFO, |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 414 | "Invalid page_cache_size (%lu), supports only 4KB\n", |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 415 | PAGE_CACHE_SIZE); |
| 416 | return 1; |
| 417 | } |
| 418 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 419 | /* Currently, support only 4KB block size */ |
| 420 | blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 421 | if (blocksize != F2FS_BLKSIZE) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 422 | f2fs_msg(sb, KERN_INFO, |
| 423 | "Invalid blocksize (%u), supports only 4KB\n", |
| 424 | blocksize); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 425 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 426 | } |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 427 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 428 | if (le32_to_cpu(raw_super->log_sectorsize) != |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 429 | F2FS_LOG_SECTOR_SIZE) { |
| 430 | f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 431 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 432 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 433 | if (le32_to_cpu(raw_super->log_sectors_per_block) != |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 434 | F2FS_LOG_SECTORS_PER_BLOCK) { |
| 435 | f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 436 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 437 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 438 | return 0; |
| 439 | } |
| 440 | |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 441 | static int sanity_check_ckpt(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 442 | { |
| 443 | unsigned int total, fsmeta; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 444 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
| 445 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 446 | |
| 447 | total = le32_to_cpu(raw_super->segment_count); |
| 448 | fsmeta = le32_to_cpu(raw_super->segment_count_ckpt); |
| 449 | fsmeta += le32_to_cpu(raw_super->segment_count_sit); |
| 450 | fsmeta += le32_to_cpu(raw_super->segment_count_nat); |
| 451 | fsmeta += le32_to_cpu(ckpt->rsvd_segment_count); |
| 452 | fsmeta += le32_to_cpu(raw_super->segment_count_ssa); |
| 453 | |
| 454 | if (fsmeta >= total) |
| 455 | return 1; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 456 | |
| 457 | if (is_set_ckpt_flags(ckpt, CP_ERROR_FLAG)) { |
| 458 | f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); |
| 459 | return 1; |
| 460 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | static void init_sb_info(struct f2fs_sb_info *sbi) |
| 465 | { |
| 466 | struct f2fs_super_block *raw_super = sbi->raw_super; |
| 467 | int i; |
| 468 | |
| 469 | sbi->log_sectors_per_block = |
| 470 | le32_to_cpu(raw_super->log_sectors_per_block); |
| 471 | sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); |
| 472 | sbi->blocksize = 1 << sbi->log_blocksize; |
| 473 | sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); |
| 474 | sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg; |
| 475 | sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); |
| 476 | sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); |
| 477 | sbi->total_sections = le32_to_cpu(raw_super->section_count); |
| 478 | sbi->total_node_count = |
| 479 | (le32_to_cpu(raw_super->segment_count_nat) / 2) |
| 480 | * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; |
| 481 | sbi->root_ino_num = le32_to_cpu(raw_super->root_ino); |
| 482 | sbi->node_ino_num = le32_to_cpu(raw_super->node_ino); |
| 483 | sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 484 | sbi->cur_victim_sec = NULL_SECNO; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 485 | |
| 486 | for (i = 0; i < NR_COUNT_TYPE; i++) |
| 487 | atomic_set(&sbi->nr_pages[i], 0); |
| 488 | } |
| 489 | |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 490 | static int validate_superblock(struct super_block *sb, |
| 491 | struct f2fs_super_block **raw_super, |
| 492 | struct buffer_head **raw_super_buf, sector_t block) |
| 493 | { |
| 494 | const char *super = (block == 0 ? "first" : "second"); |
| 495 | |
| 496 | /* read f2fs raw super block */ |
| 497 | *raw_super_buf = sb_bread(sb, block); |
| 498 | if (!*raw_super_buf) { |
| 499 | f2fs_msg(sb, KERN_ERR, "unable to read %s superblock", |
| 500 | super); |
Namjae Jeon | c0d39e6 | 2013-03-17 17:26:53 +0900 | [diff] [blame] | 501 | return -EIO; |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | *raw_super = (struct f2fs_super_block *) |
| 505 | ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET); |
| 506 | |
| 507 | /* sanity checking of raw super */ |
| 508 | if (!sanity_check_raw_super(sb, *raw_super)) |
| 509 | return 0; |
| 510 | |
| 511 | f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem " |
| 512 | "in %s superblock", super); |
Namjae Jeon | c0d39e6 | 2013-03-17 17:26:53 +0900 | [diff] [blame] | 513 | return -EINVAL; |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 514 | } |
| 515 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 516 | static int f2fs_fill_super(struct super_block *sb, void *data, int silent) |
| 517 | { |
| 518 | struct f2fs_sb_info *sbi; |
| 519 | struct f2fs_super_block *raw_super; |
| 520 | struct buffer_head *raw_super_buf; |
| 521 | struct inode *root; |
| 522 | long err = -EINVAL; |
| 523 | int i; |
| 524 | |
| 525 | /* allocate memory for f2fs-specific super block info */ |
| 526 | sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); |
| 527 | if (!sbi) |
| 528 | return -ENOMEM; |
| 529 | |
Namjae Jeon | ff9234a | 2013-01-12 14:41:13 +0900 | [diff] [blame] | 530 | /* set a block size */ |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 531 | if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) { |
| 532 | f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 533 | goto free_sbi; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 534 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 535 | |
Namjae Jeon | c0d39e6 | 2013-03-17 17:26:53 +0900 | [diff] [blame] | 536 | err = validate_superblock(sb, &raw_super, &raw_super_buf, 0); |
| 537 | if (err) { |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 538 | brelse(raw_super_buf); |
Namjae Jeon | c0d39e6 | 2013-03-17 17:26:53 +0900 | [diff] [blame] | 539 | /* check secondary superblock when primary failed */ |
| 540 | err = validate_superblock(sb, &raw_super, &raw_super_buf, 1); |
| 541 | if (err) |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 542 | goto free_sb_buf; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 543 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 544 | /* init some FS parameters */ |
| 545 | sbi->active_logs = NR_CURSEG_TYPE; |
| 546 | |
| 547 | set_opt(sbi, BG_GC); |
| 548 | |
| 549 | #ifdef CONFIG_F2FS_FS_XATTR |
| 550 | set_opt(sbi, XATTR_USER); |
| 551 | #endif |
| 552 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 553 | set_opt(sbi, POSIX_ACL); |
| 554 | #endif |
| 555 | /* parse mount options */ |
Wei Yongjun | 66348b7 | 2013-04-12 10:23:18 +0800 | [diff] [blame] | 556 | err = parse_options(sb, sbi, (char *)data); |
| 557 | if (err) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 558 | goto free_sb_buf; |
| 559 | |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 560 | sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 561 | sb->s_max_links = F2FS_LINK_MAX; |
| 562 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
| 563 | |
| 564 | sb->s_op = &f2fs_sops; |
| 565 | sb->s_xattr = f2fs_xattr_handlers; |
| 566 | sb->s_export_op = &f2fs_export_ops; |
| 567 | sb->s_magic = F2FS_SUPER_MAGIC; |
| 568 | sb->s_fs_info = sbi; |
| 569 | sb->s_time_gran = 1; |
| 570 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
| 571 | (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0); |
| 572 | memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); |
| 573 | |
| 574 | /* init f2fs-specific super block info */ |
| 575 | sbi->sb = sb; |
| 576 | sbi->raw_super = raw_super; |
| 577 | sbi->raw_super_buf = raw_super_buf; |
| 578 | mutex_init(&sbi->gc_mutex); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 579 | mutex_init(&sbi->writepages); |
| 580 | mutex_init(&sbi->cp_mutex); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 581 | for (i = 0; i < NR_GLOBAL_LOCKS; i++) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 582 | mutex_init(&sbi->fs_lock[i]); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 583 | mutex_init(&sbi->node_write); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 584 | sbi->por_doing = 0; |
| 585 | spin_lock_init(&sbi->stat_lock); |
| 586 | init_rwsem(&sbi->bio_sem); |
| 587 | init_sb_info(sbi); |
| 588 | |
| 589 | /* get an inode for meta space */ |
| 590 | sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); |
| 591 | if (IS_ERR(sbi->meta_inode)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 592 | f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 593 | err = PTR_ERR(sbi->meta_inode); |
| 594 | goto free_sb_buf; |
| 595 | } |
| 596 | |
| 597 | err = get_valid_checkpoint(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 598 | if (err) { |
| 599 | f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 600 | goto free_meta_inode; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 601 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 602 | |
| 603 | /* sanity checking of checkpoint */ |
| 604 | err = -EINVAL; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 605 | if (sanity_check_ckpt(sbi)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 606 | f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 607 | goto free_cp; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 608 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 609 | |
| 610 | sbi->total_valid_node_count = |
| 611 | le32_to_cpu(sbi->ckpt->valid_node_count); |
| 612 | sbi->total_valid_inode_count = |
| 613 | le32_to_cpu(sbi->ckpt->valid_inode_count); |
| 614 | sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); |
| 615 | sbi->total_valid_block_count = |
| 616 | le64_to_cpu(sbi->ckpt->valid_block_count); |
| 617 | sbi->last_valid_block_count = sbi->total_valid_block_count; |
| 618 | sbi->alloc_valid_block_count = 0; |
| 619 | INIT_LIST_HEAD(&sbi->dir_inode_list); |
| 620 | spin_lock_init(&sbi->dir_inode_lock); |
| 621 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 622 | init_orphan_info(sbi); |
| 623 | |
| 624 | /* setup f2fs internal modules */ |
| 625 | err = build_segment_manager(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 626 | if (err) { |
| 627 | f2fs_msg(sb, KERN_ERR, |
| 628 | "Failed to initialize F2FS segment manager"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 629 | goto free_sm; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 630 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 631 | err = build_node_manager(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 632 | if (err) { |
| 633 | f2fs_msg(sb, KERN_ERR, |
| 634 | "Failed to initialize F2FS node manager"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 635 | goto free_nm; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 636 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 637 | |
| 638 | build_gc_manager(sbi); |
| 639 | |
| 640 | /* get an inode for node space */ |
| 641 | sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); |
| 642 | if (IS_ERR(sbi->node_inode)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 643 | f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 644 | err = PTR_ERR(sbi->node_inode); |
| 645 | goto free_nm; |
| 646 | } |
| 647 | |
| 648 | /* if there are nt orphan nodes free them */ |
| 649 | err = -EINVAL; |
Jaegeuk Kim | 30f0c75 | 2012-12-19 16:09:19 +0900 | [diff] [blame] | 650 | if (recover_orphan_inodes(sbi)) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 651 | goto free_node_inode; |
| 652 | |
| 653 | /* read root inode and dentry */ |
| 654 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); |
| 655 | if (IS_ERR(root)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 656 | f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 657 | err = PTR_ERR(root); |
| 658 | goto free_node_inode; |
| 659 | } |
| 660 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) |
| 661 | goto free_root_inode; |
| 662 | |
| 663 | sb->s_root = d_make_root(root); /* allocate root dentry */ |
| 664 | if (!sb->s_root) { |
| 665 | err = -ENOMEM; |
| 666 | goto free_root_inode; |
| 667 | } |
| 668 | |
| 669 | /* recover fsynced data */ |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 670 | if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { |
| 671 | err = recover_fsync_data(sbi); |
Chris Fries | bde582b | 2013-05-02 16:07:34 -0500 | [diff] [blame] | 672 | if (err) |
| 673 | f2fs_msg(sb, KERN_ERR, |
| 674 | "Cannot recover all fsync data errno=%ld", err); |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 675 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 676 | |
| 677 | /* After POR, we can run background GC thread */ |
| 678 | err = start_gc_thread(sbi); |
| 679 | if (err) |
| 680 | goto fail; |
| 681 | |
| 682 | err = f2fs_build_stats(sbi); |
| 683 | if (err) |
| 684 | goto fail; |
| 685 | |
Namjae Jeon | d3ee456 | 2013-03-17 17:26:14 +0900 | [diff] [blame] | 686 | if (test_opt(sbi, DISCARD)) { |
| 687 | struct request_queue *q = bdev_get_queue(sb->s_bdev); |
| 688 | if (!blk_queue_discard(q)) |
| 689 | f2fs_msg(sb, KERN_WARNING, |
| 690 | "mounting with \"discard\" option, but " |
| 691 | "the device does not support discard"); |
| 692 | } |
| 693 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 694 | return 0; |
| 695 | fail: |
| 696 | stop_gc_thread(sbi); |
| 697 | free_root_inode: |
| 698 | dput(sb->s_root); |
| 699 | sb->s_root = NULL; |
| 700 | free_node_inode: |
| 701 | iput(sbi->node_inode); |
| 702 | free_nm: |
| 703 | destroy_node_manager(sbi); |
| 704 | free_sm: |
| 705 | destroy_segment_manager(sbi); |
| 706 | free_cp: |
| 707 | kfree(sbi->ckpt); |
| 708 | free_meta_inode: |
| 709 | make_bad_inode(sbi->meta_inode); |
| 710 | iput(sbi->meta_inode); |
| 711 | free_sb_buf: |
| 712 | brelse(raw_super_buf); |
| 713 | free_sbi: |
| 714 | kfree(sbi); |
| 715 | return err; |
| 716 | } |
| 717 | |
| 718 | static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags, |
| 719 | const char *dev_name, void *data) |
| 720 | { |
| 721 | return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super); |
| 722 | } |
| 723 | |
| 724 | static struct file_system_type f2fs_fs_type = { |
| 725 | .owner = THIS_MODULE, |
| 726 | .name = "f2fs", |
| 727 | .mount = f2fs_mount, |
| 728 | .kill_sb = kill_block_super, |
| 729 | .fs_flags = FS_REQUIRES_DEV, |
| 730 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 731 | MODULE_ALIAS_FS("f2fs"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 732 | |
Namjae Jeon | 6e6093a | 2013-01-17 00:08:30 +0900 | [diff] [blame] | 733 | static int __init init_inodecache(void) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 734 | { |
| 735 | f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", |
| 736 | sizeof(struct f2fs_inode_info), NULL); |
| 737 | if (f2fs_inode_cachep == NULL) |
| 738 | return -ENOMEM; |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | static void destroy_inodecache(void) |
| 743 | { |
| 744 | /* |
| 745 | * Make sure all delayed rcu free inodes are flushed before we |
| 746 | * destroy cache. |
| 747 | */ |
| 748 | rcu_barrier(); |
| 749 | kmem_cache_destroy(f2fs_inode_cachep); |
| 750 | } |
| 751 | |
| 752 | static int __init init_f2fs_fs(void) |
| 753 | { |
| 754 | int err; |
| 755 | |
| 756 | err = init_inodecache(); |
| 757 | if (err) |
| 758 | goto fail; |
| 759 | err = create_node_manager_caches(); |
| 760 | if (err) |
| 761 | goto fail; |
| 762 | err = create_gc_caches(); |
| 763 | if (err) |
| 764 | goto fail; |
| 765 | err = create_checkpoint_caches(); |
| 766 | if (err) |
| 767 | goto fail; |
Namjae Jeon | 4589d25 | 2013-01-15 19:58:47 +0900 | [diff] [blame] | 768 | err = register_filesystem(&f2fs_fs_type); |
| 769 | if (err) |
| 770 | goto fail; |
| 771 | f2fs_create_root_stats(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 772 | fail: |
| 773 | return err; |
| 774 | } |
| 775 | |
| 776 | static void __exit exit_f2fs_fs(void) |
| 777 | { |
Namjae Jeon | 4589d25 | 2013-01-15 19:58:47 +0900 | [diff] [blame] | 778 | f2fs_destroy_root_stats(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 779 | unregister_filesystem(&f2fs_fs_type); |
| 780 | destroy_checkpoint_caches(); |
| 781 | destroy_gc_caches(); |
| 782 | destroy_node_manager_caches(); |
| 783 | destroy_inodecache(); |
| 784 | } |
| 785 | |
| 786 | module_init(init_f2fs_fs) |
| 787 | module_exit(exit_f2fs_fs) |
| 788 | |
| 789 | MODULE_AUTHOR("Samsung Electronics's Praesto Team"); |
| 790 | MODULE_DESCRIPTION("Flash Friendly File System"); |
| 791 | MODULE_LICENSE("GPL"); |