aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/f2fs/super.c')
-rw-r--r--fs/f2fs/super.c97
1 files changed, 72 insertions, 25 deletions
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 08a94c814bdc..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
56void 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
56static void init_once(void *foo) 68static 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;
@@ -125,6 +137,8 @@ int f2fs_sync_fs(struct super_block *sb, int sync)
125 137
126 if (sync) 138 if (sync)
127 write_checkpoint(sbi, false, false); 139 write_checkpoint(sbi, false, false);
140 else
141 f2fs_balance_fs(sbi);
128 142
129 return 0; 143 return 0;
130} 144}
@@ -247,7 +261,8 @@ static const struct export_operations f2fs_export_ops = {
247 .get_parent = f2fs_get_parent, 261 .get_parent = f2fs_get_parent,
248}; 262};
249 263
250static int parse_options(struct f2fs_sb_info *sbi, char *options) 264static int parse_options(struct super_block *sb, struct f2fs_sb_info *sbi,
265 char *options)
251{ 266{
252 substring_t args[MAX_OPT_ARGS]; 267 substring_t args[MAX_OPT_ARGS];
253 char *p; 268 char *p;
@@ -286,7 +301,8 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options)
286 break; 301 break;
287#else 302#else
288 case Opt_nouser_xattr: 303 case Opt_nouser_xattr:
289 pr_info("nouser_xattr options not supported\n"); 304 f2fs_msg(sb, KERN_INFO,
305 "nouser_xattr options not supported");
290 break; 306 break;
291#endif 307#endif
292#ifdef CONFIG_F2FS_FS_POSIX_ACL 308#ifdef CONFIG_F2FS_FS_POSIX_ACL
@@ -295,7 +311,7 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options)
295 break; 311 break;
296#else 312#else
297 case Opt_noacl: 313 case Opt_noacl:
298 pr_info("noacl options not supported\n"); 314 f2fs_msg(sb, KERN_INFO, "noacl options not supported");
299 break; 315 break;
300#endif 316#endif
301 case Opt_active_logs: 317 case Opt_active_logs:
@@ -309,8 +325,9 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options)
309 set_opt(sbi, DISABLE_EXT_IDENTIFY); 325 set_opt(sbi, DISABLE_EXT_IDENTIFY);
310 break; 326 break;
311 default: 327 default:
312 pr_err("Unrecognized mount option \"%s\" or missing value\n", 328 f2fs_msg(sb, KERN_ERR,
313 p); 329 "Unrecognized mount option \"%s\" or missing value",
330 p);
314 return -EINVAL; 331 return -EINVAL;
315 } 332 }
316 } 333 }
@@ -337,23 +354,36 @@ static loff_t max_file_size(unsigned bits)
337 return result; 354 return result;
338} 355}
339 356
340static int sanity_check_raw_super(struct f2fs_super_block *raw_super) 357static int sanity_check_raw_super(struct super_block *sb,
358 struct f2fs_super_block *raw_super)
341{ 359{
342 unsigned int blocksize; 360 unsigned int blocksize;
343 361
344 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));
345 return 1; 366 return 1;
367 }
346 368
347 /* Currently, support only 4KB block size */ 369 /* Currently, support only 4KB block size */
348 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); 370 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
349 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);
350 return 1; 375 return 1;
376 }
351 if (le32_to_cpu(raw_super->log_sectorsize) != 377 if (le32_to_cpu(raw_super->log_sectorsize) !=
352 F2FS_LOG_SECTOR_SIZE) 378 F2FS_LOG_SECTOR_SIZE) {
379 f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize");
353 return 1; 380 return 1;
381 }
354 if (le32_to_cpu(raw_super->log_sectors_per_block) != 382 if (le32_to_cpu(raw_super->log_sectors_per_block) !=
355 F2FS_LOG_SECTORS_PER_BLOCK) 383 F2FS_LOG_SECTORS_PER_BLOCK) {
384 f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block");
356 return 1; 385 return 1;
386 }
357 return 0; 387 return 0;
358} 388}
359 389
@@ -413,14 +443,17 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
413 if (!sbi) 443 if (!sbi)
414 return -ENOMEM; 444 return -ENOMEM;
415 445
416 /* set a temporary block size */ 446 /* set a block size */
417 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");
418 goto free_sbi; 449 goto free_sbi;
450 }
419 451
420 /* read f2fs raw super block */ 452 /* read f2fs raw super block */
421 raw_super_buf = sb_bread(sb, 0); 453 raw_super_buf = sb_bread(sb, 0);
422 if (!raw_super_buf) { 454 if (!raw_super_buf) {
423 err = -EIO; 455 err = -EIO;
456 f2fs_msg(sb, KERN_ERR, "unable to read superblock");
424 goto free_sbi; 457 goto free_sbi;
425 } 458 }
426 raw_super = (struct f2fs_super_block *) 459 raw_super = (struct f2fs_super_block *)
@@ -438,12 +471,14 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
438 set_opt(sbi, POSIX_ACL); 471 set_opt(sbi, POSIX_ACL);
439#endif 472#endif
440 /* parse mount options */ 473 /* parse mount options */
441 if (parse_options(sbi, (char *)data)) 474 if (parse_options(sb, sbi, (char *)data))
442 goto free_sb_buf; 475 goto free_sb_buf;
443 476
444 /* sanity checking of raw super */ 477 /* sanity checking of raw super */
445 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");
446 goto free_sb_buf; 480 goto free_sb_buf;
481 }
447 482
448 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));
449 sb->s_max_links = F2FS_LINK_MAX; 484 sb->s_max_links = F2FS_LINK_MAX;
@@ -477,18 +512,23 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
477 /* get an inode for meta space */ 512 /* get an inode for meta space */
478 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); 513 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
479 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");
480 err = PTR_ERR(sbi->meta_inode); 516 err = PTR_ERR(sbi->meta_inode);
481 goto free_sb_buf; 517 goto free_sb_buf;
482 } 518 }
483 519
484 err = get_valid_checkpoint(sbi); 520 err = get_valid_checkpoint(sbi);
485 if (err) 521 if (err) {
522 f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
486 goto free_meta_inode; 523 goto free_meta_inode;
524 }
487 525
488 /* sanity checking of checkpoint */ 526 /* sanity checking of checkpoint */
489 err = -EINVAL; 527 err = -EINVAL;
490 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");
491 goto free_cp; 530 goto free_cp;
531 }
492 532
493 sbi->total_valid_node_count = 533 sbi->total_valid_node_count =
494 le32_to_cpu(sbi->ckpt->valid_node_count); 534 le32_to_cpu(sbi->ckpt->valid_node_count);
@@ -502,25 +542,28 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
502 INIT_LIST_HEAD(&sbi->dir_inode_list); 542 INIT_LIST_HEAD(&sbi->dir_inode_list);
503 spin_lock_init(&sbi->dir_inode_lock); 543 spin_lock_init(&sbi->dir_inode_lock);
504 544
505 /* init super block */
506 if (!sb_set_blocksize(sb, sbi->blocksize))
507 goto free_cp;
508
509 init_orphan_info(sbi); 545 init_orphan_info(sbi);
510 546
511 /* setup f2fs internal modules */ 547 /* setup f2fs internal modules */
512 err = build_segment_manager(sbi); 548 err = build_segment_manager(sbi);
513 if (err) 549 if (err) {
550 f2fs_msg(sb, KERN_ERR,
551 "Failed to initialize F2FS segment manager");
514 goto free_sm; 552 goto free_sm;
553 }
515 err = build_node_manager(sbi); 554 err = build_node_manager(sbi);
516 if (err) 555 if (err) {
556 f2fs_msg(sb, KERN_ERR,
557 "Failed to initialize F2FS node manager");
517 goto free_nm; 558 goto free_nm;
559 }
518 560
519 build_gc_manager(sbi); 561 build_gc_manager(sbi);
520 562
521 /* get an inode for node space */ 563 /* get an inode for node space */
522 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); 564 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
523 if (IS_ERR(sbi->node_inode)) { 565 if (IS_ERR(sbi->node_inode)) {
566 f2fs_msg(sb, KERN_ERR, "Failed to read node inode");
524 err = PTR_ERR(sbi->node_inode); 567 err = PTR_ERR(sbi->node_inode);
525 goto free_nm; 568 goto free_nm;
526 } 569 }
@@ -533,6 +576,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
533 /* read root inode and dentry */ 576 /* read root inode and dentry */
534 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); 577 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
535 if (IS_ERR(root)) { 578 if (IS_ERR(root)) {
579 f2fs_msg(sb, KERN_ERR, "Failed to read root inode");
536 err = PTR_ERR(root); 580 err = PTR_ERR(root);
537 goto free_node_inode; 581 goto free_node_inode;
538 } 582 }
@@ -596,7 +640,7 @@ static struct file_system_type f2fs_fs_type = {
596 .fs_flags = FS_REQUIRES_DEV, 640 .fs_flags = FS_REQUIRES_DEV,
597}; 641};
598 642
599static int init_inodecache(void) 643static int __init init_inodecache(void)
600{ 644{
601 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", 645 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache",
602 sizeof(struct f2fs_inode_info), NULL); 646 sizeof(struct f2fs_inode_info), NULL);
@@ -631,14 +675,17 @@ static int __init init_f2fs_fs(void)
631 err = create_checkpoint_caches(); 675 err = create_checkpoint_caches();
632 if (err) 676 if (err)
633 goto fail; 677 goto fail;
634 return register_filesystem(&f2fs_fs_type); 678 err = register_filesystem(&f2fs_fs_type);
679 if (err)
680 goto fail;
681 f2fs_create_root_stats();
635fail: 682fail:
636 return err; 683 return err;
637} 684}
638 685
639static void __exit exit_f2fs_fs(void) 686static void __exit exit_f2fs_fs(void)
640{ 687{
641 destroy_root_stats(); 688 f2fs_destroy_root_stats();
642 unregister_filesystem(&f2fs_fs_type); 689 unregister_filesystem(&f2fs_fs_type);
643 destroy_checkpoint_caches(); 690 destroy_checkpoint_caches();
644 destroy_gc_caches(); 691 destroy_gc_caches();