diff options
Diffstat (limited to 'fs/f2fs/super.c')
-rw-r--r-- | fs/f2fs/super.c | 112 |
1 files changed, 78 insertions, 34 deletions
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 13867322cf5a..37fad04c8669 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -53,6 +53,18 @@ static match_table_t f2fs_tokens = { | |||
53 | {Opt_err, NULL}, | 53 | {Opt_err, NULL}, |
54 | }; | 54 | }; |
55 | 55 | ||
56 | void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) | ||
57 | { | ||
58 | struct va_format vaf; | ||
59 | va_list args; | ||
60 | |||
61 | va_start(args, fmt); | ||
62 | vaf.fmt = fmt; | ||
63 | vaf.va = &args; | ||
64 | printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf); | ||
65 | va_end(args); | ||
66 | } | ||
67 | |||
56 | static void init_once(void *foo) | 68 | static void init_once(void *foo) |
57 | { | 69 | { |
58 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; | 70 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; |
@@ -119,15 +131,16 @@ static void f2fs_put_super(struct super_block *sb) | |||
119 | int f2fs_sync_fs(struct super_block *sb, int sync) | 131 | int f2fs_sync_fs(struct super_block *sb, int sync) |
120 | { | 132 | { |
121 | struct f2fs_sb_info *sbi = F2FS_SB(sb); | 133 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
122 | int ret = 0; | ||
123 | 134 | ||
124 | if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) | 135 | if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) |
125 | return 0; | 136 | return 0; |
126 | 137 | ||
127 | if (sync) | 138 | if (sync) |
128 | write_checkpoint(sbi, false, false); | 139 | write_checkpoint(sbi, false, false); |
140 | else | ||
141 | f2fs_balance_fs(sbi); | ||
129 | 142 | ||
130 | return ret; | 143 | return 0; |
131 | } | 144 | } |
132 | 145 | ||
133 | static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) | 146 | static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) |
@@ -148,8 +161,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
148 | buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count; | 161 | buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count; |
149 | buf->f_bavail = user_block_count - valid_user_blocks(sbi); | 162 | buf->f_bavail = user_block_count - valid_user_blocks(sbi); |
150 | 163 | ||
151 | buf->f_files = valid_inode_count(sbi); | 164 | buf->f_files = sbi->total_node_count; |
152 | buf->f_ffree = sbi->total_node_count - valid_node_count(sbi); | 165 | buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi); |
153 | 166 | ||
154 | buf->f_namelen = F2FS_MAX_NAME_LEN; | 167 | buf->f_namelen = F2FS_MAX_NAME_LEN; |
155 | buf->f_fsid.val[0] = (u32)id; | 168 | buf->f_fsid.val[0] = (u32)id; |
@@ -248,7 +261,8 @@ static const struct export_operations f2fs_export_ops = { | |||
248 | .get_parent = f2fs_get_parent, | 261 | .get_parent = f2fs_get_parent, |
249 | }; | 262 | }; |
250 | 263 | ||
251 | static int parse_options(struct f2fs_sb_info *sbi, char *options) | 264 | static int parse_options(struct super_block *sb, struct f2fs_sb_info *sbi, |
265 | char *options) | ||
252 | { | 266 | { |
253 | substring_t args[MAX_OPT_ARGS]; | 267 | substring_t args[MAX_OPT_ARGS]; |
254 | char *p; | 268 | char *p; |
@@ -287,7 +301,8 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options) | |||
287 | break; | 301 | break; |
288 | #else | 302 | #else |
289 | case Opt_nouser_xattr: | 303 | case Opt_nouser_xattr: |
290 | pr_info("nouser_xattr options not supported\n"); | 304 | f2fs_msg(sb, KERN_INFO, |
305 | "nouser_xattr options not supported"); | ||
291 | break; | 306 | break; |
292 | #endif | 307 | #endif |
293 | #ifdef CONFIG_F2FS_FS_POSIX_ACL | 308 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
@@ -296,13 +311,13 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options) | |||
296 | break; | 311 | break; |
297 | #else | 312 | #else |
298 | case Opt_noacl: | 313 | case Opt_noacl: |
299 | pr_info("noacl options not supported\n"); | 314 | f2fs_msg(sb, KERN_INFO, "noacl options not supported"); |
300 | break; | 315 | break; |
301 | #endif | 316 | #endif |
302 | case Opt_active_logs: | 317 | case Opt_active_logs: |
303 | if (args->from && match_int(args, &arg)) | 318 | if (args->from && match_int(args, &arg)) |
304 | return -EINVAL; | 319 | return -EINVAL; |
305 | if (arg != 2 && arg != 4 && arg != 6) | 320 | if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE) |
306 | return -EINVAL; | 321 | return -EINVAL; |
307 | sbi->active_logs = arg; | 322 | sbi->active_logs = arg; |
308 | break; | 323 | break; |
@@ -310,8 +325,9 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options) | |||
310 | set_opt(sbi, DISABLE_EXT_IDENTIFY); | 325 | set_opt(sbi, DISABLE_EXT_IDENTIFY); |
311 | break; | 326 | break; |
312 | default: | 327 | default: |
313 | pr_err("Unrecognized mount option \"%s\" or missing value\n", | 328 | f2fs_msg(sb, KERN_ERR, |
314 | p); | 329 | "Unrecognized mount option \"%s\" or missing value", |
330 | p); | ||
315 | return -EINVAL; | 331 | return -EINVAL; |
316 | } | 332 | } |
317 | } | 333 | } |
@@ -338,23 +354,36 @@ static loff_t max_file_size(unsigned bits) | |||
338 | return result; | 354 | return result; |
339 | } | 355 | } |
340 | 356 | ||
341 | static int sanity_check_raw_super(struct f2fs_super_block *raw_super) | 357 | static int sanity_check_raw_super(struct super_block *sb, |
358 | struct f2fs_super_block *raw_super) | ||
342 | { | 359 | { |
343 | unsigned int blocksize; | 360 | unsigned int blocksize; |
344 | 361 | ||
345 | if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) | 362 | if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) { |
363 | f2fs_msg(sb, KERN_INFO, | ||
364 | "Magic Mismatch, valid(0x%x) - read(0x%x)", | ||
365 | F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); | ||
346 | return 1; | 366 | return 1; |
367 | } | ||
347 | 368 | ||
348 | /* Currently, support only 4KB block size */ | 369 | /* Currently, support only 4KB block size */ |
349 | blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); | 370 | blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); |
350 | if (blocksize != PAGE_CACHE_SIZE) | 371 | if (blocksize != PAGE_CACHE_SIZE) { |
372 | f2fs_msg(sb, KERN_INFO, | ||
373 | "Invalid blocksize (%u), supports only 4KB\n", | ||
374 | blocksize); | ||
351 | return 1; | 375 | return 1; |
376 | } | ||
352 | if (le32_to_cpu(raw_super->log_sectorsize) != | 377 | if (le32_to_cpu(raw_super->log_sectorsize) != |
353 | F2FS_LOG_SECTOR_SIZE) | 378 | F2FS_LOG_SECTOR_SIZE) { |
379 | f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize"); | ||
354 | return 1; | 380 | return 1; |
381 | } | ||
355 | if (le32_to_cpu(raw_super->log_sectors_per_block) != | 382 | if (le32_to_cpu(raw_super->log_sectors_per_block) != |
356 | F2FS_LOG_SECTORS_PER_BLOCK) | 383 | F2FS_LOG_SECTORS_PER_BLOCK) { |
384 | f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block"); | ||
357 | return 1; | 385 | return 1; |
386 | } | ||
358 | return 0; | 387 | return 0; |
359 | } | 388 | } |
360 | 389 | ||
@@ -414,14 +443,17 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
414 | if (!sbi) | 443 | if (!sbi) |
415 | return -ENOMEM; | 444 | return -ENOMEM; |
416 | 445 | ||
417 | /* set a temporary block size */ | 446 | /* set a block size */ |
418 | if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) | 447 | if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) { |
448 | f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); | ||
419 | goto free_sbi; | 449 | goto free_sbi; |
450 | } | ||
420 | 451 | ||
421 | /* read f2fs raw super block */ | 452 | /* read f2fs raw super block */ |
422 | raw_super_buf = sb_bread(sb, 0); | 453 | raw_super_buf = sb_bread(sb, 0); |
423 | if (!raw_super_buf) { | 454 | if (!raw_super_buf) { |
424 | err = -EIO; | 455 | err = -EIO; |
456 | f2fs_msg(sb, KERN_ERR, "unable to read superblock"); | ||
425 | goto free_sbi; | 457 | goto free_sbi; |
426 | } | 458 | } |
427 | raw_super = (struct f2fs_super_block *) | 459 | raw_super = (struct f2fs_super_block *) |
@@ -439,12 +471,14 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
439 | set_opt(sbi, POSIX_ACL); | 471 | set_opt(sbi, POSIX_ACL); |
440 | #endif | 472 | #endif |
441 | /* parse mount options */ | 473 | /* parse mount options */ |
442 | if (parse_options(sbi, (char *)data)) | 474 | if (parse_options(sb, sbi, (char *)data)) |
443 | goto free_sb_buf; | 475 | goto free_sb_buf; |
444 | 476 | ||
445 | /* sanity checking of raw super */ | 477 | /* sanity checking of raw super */ |
446 | if (sanity_check_raw_super(raw_super)) | 478 | if (sanity_check_raw_super(sb, raw_super)) { |
479 | f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem"); | ||
447 | goto free_sb_buf; | 480 | goto free_sb_buf; |
481 | } | ||
448 | 482 | ||
449 | sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); | 483 | sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); |
450 | sb->s_max_links = F2FS_LINK_MAX; | 484 | sb->s_max_links = F2FS_LINK_MAX; |
@@ -478,18 +512,23 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
478 | /* get an inode for meta space */ | 512 | /* get an inode for meta space */ |
479 | sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); | 513 | sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); |
480 | if (IS_ERR(sbi->meta_inode)) { | 514 | if (IS_ERR(sbi->meta_inode)) { |
515 | f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); | ||
481 | err = PTR_ERR(sbi->meta_inode); | 516 | err = PTR_ERR(sbi->meta_inode); |
482 | goto free_sb_buf; | 517 | goto free_sb_buf; |
483 | } | 518 | } |
484 | 519 | ||
485 | err = get_valid_checkpoint(sbi); | 520 | err = get_valid_checkpoint(sbi); |
486 | if (err) | 521 | if (err) { |
522 | f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint"); | ||
487 | goto free_meta_inode; | 523 | goto free_meta_inode; |
524 | } | ||
488 | 525 | ||
489 | /* sanity checking of checkpoint */ | 526 | /* sanity checking of checkpoint */ |
490 | err = -EINVAL; | 527 | err = -EINVAL; |
491 | if (sanity_check_ckpt(raw_super, sbi->ckpt)) | 528 | if (sanity_check_ckpt(raw_super, sbi->ckpt)) { |
529 | f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint"); | ||
492 | goto free_cp; | 530 | goto free_cp; |
531 | } | ||
493 | 532 | ||
494 | sbi->total_valid_node_count = | 533 | sbi->total_valid_node_count = |
495 | le32_to_cpu(sbi->ckpt->valid_node_count); | 534 | le32_to_cpu(sbi->ckpt->valid_node_count); |
@@ -503,38 +542,41 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
503 | INIT_LIST_HEAD(&sbi->dir_inode_list); | 542 | INIT_LIST_HEAD(&sbi->dir_inode_list); |
504 | spin_lock_init(&sbi->dir_inode_lock); | 543 | spin_lock_init(&sbi->dir_inode_lock); |
505 | 544 | ||
506 | /* init super block */ | ||
507 | if (!sb_set_blocksize(sb, sbi->blocksize)) | ||
508 | goto free_cp; | ||
509 | |||
510 | init_orphan_info(sbi); | 545 | init_orphan_info(sbi); |
511 | 546 | ||
512 | /* setup f2fs internal modules */ | 547 | /* setup f2fs internal modules */ |
513 | err = build_segment_manager(sbi); | 548 | err = build_segment_manager(sbi); |
514 | if (err) | 549 | if (err) { |
550 | f2fs_msg(sb, KERN_ERR, | ||
551 | "Failed to initialize F2FS segment manager"); | ||
515 | goto free_sm; | 552 | goto free_sm; |
553 | } | ||
516 | err = build_node_manager(sbi); | 554 | err = build_node_manager(sbi); |
517 | if (err) | 555 | if (err) { |
556 | f2fs_msg(sb, KERN_ERR, | ||
557 | "Failed to initialize F2FS node manager"); | ||
518 | goto free_nm; | 558 | goto free_nm; |
559 | } | ||
519 | 560 | ||
520 | build_gc_manager(sbi); | 561 | build_gc_manager(sbi); |
521 | 562 | ||
522 | /* get an inode for node space */ | 563 | /* get an inode for node space */ |
523 | sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); | 564 | sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); |
524 | if (IS_ERR(sbi->node_inode)) { | 565 | if (IS_ERR(sbi->node_inode)) { |
566 | f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); | ||
525 | err = PTR_ERR(sbi->node_inode); | 567 | err = PTR_ERR(sbi->node_inode); |
526 | goto free_nm; | 568 | goto free_nm; |
527 | } | 569 | } |
528 | 570 | ||
529 | /* if there are nt orphan nodes free them */ | 571 | /* if there are nt orphan nodes free them */ |
530 | err = -EINVAL; | 572 | err = -EINVAL; |
531 | if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) && | 573 | if (recover_orphan_inodes(sbi)) |
532 | recover_orphan_inodes(sbi)) | ||
533 | goto free_node_inode; | 574 | goto free_node_inode; |
534 | 575 | ||
535 | /* read root inode and dentry */ | 576 | /* read root inode and dentry */ |
536 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); | 577 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); |
537 | if (IS_ERR(root)) { | 578 | if (IS_ERR(root)) { |
579 | f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); | ||
538 | err = PTR_ERR(root); | 580 | err = PTR_ERR(root); |
539 | goto free_node_inode; | 581 | goto free_node_inode; |
540 | } | 582 | } |
@@ -548,8 +590,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
548 | } | 590 | } |
549 | 591 | ||
550 | /* recover fsynced data */ | 592 | /* recover fsynced data */ |
551 | if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) && | 593 | if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) |
552 | !test_opt(sbi, DISABLE_ROLL_FORWARD)) | ||
553 | recover_fsync_data(sbi); | 594 | recover_fsync_data(sbi); |
554 | 595 | ||
555 | /* After POR, we can run background GC thread */ | 596 | /* After POR, we can run background GC thread */ |
@@ -599,7 +640,7 @@ static struct file_system_type f2fs_fs_type = { | |||
599 | .fs_flags = FS_REQUIRES_DEV, | 640 | .fs_flags = FS_REQUIRES_DEV, |
600 | }; | 641 | }; |
601 | 642 | ||
602 | static int init_inodecache(void) | 643 | static int __init init_inodecache(void) |
603 | { | 644 | { |
604 | f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", | 645 | f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", |
605 | sizeof(struct f2fs_inode_info), NULL); | 646 | sizeof(struct f2fs_inode_info), NULL); |
@@ -634,14 +675,17 @@ static int __init init_f2fs_fs(void) | |||
634 | err = create_checkpoint_caches(); | 675 | err = create_checkpoint_caches(); |
635 | if (err) | 676 | if (err) |
636 | goto fail; | 677 | goto fail; |
637 | return register_filesystem(&f2fs_fs_type); | 678 | err = register_filesystem(&f2fs_fs_type); |
679 | if (err) | ||
680 | goto fail; | ||
681 | f2fs_create_root_stats(); | ||
638 | fail: | 682 | fail: |
639 | return err; | 683 | return err; |
640 | } | 684 | } |
641 | 685 | ||
642 | static void __exit exit_f2fs_fs(void) | 686 | static void __exit exit_f2fs_fs(void) |
643 | { | 687 | { |
644 | destroy_root_stats(); | 688 | f2fs_destroy_root_stats(); |
645 | unregister_filesystem(&f2fs_fs_type); | 689 | unregister_filesystem(&f2fs_fs_type); |
646 | destroy_checkpoint_caches(); | 690 | destroy_checkpoint_caches(); |
647 | destroy_gc_caches(); | 691 | destroy_gc_caches(); |