super.c (ad2e6329666650d9cafcae9ef53fbe09ea759ae2) | super.c (6e6093a8f144414d904575da5fdea40cf14fb63e) |
---|---|
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 --- 39 unchanged lines hidden (view full) --- 48 {Opt_noheap, "no_heap"}, 49 {Opt_nouser_xattr, "nouser_xattr"}, 50 {Opt_noacl, "noacl"}, 51 {Opt_active_logs, "active_logs=%u"}, 52 {Opt_disable_ext_identify, "disable_ext_identify"}, 53 {Opt_err, NULL}, 54}; 55 | 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 --- 39 unchanged lines hidden (view full) --- 48 {Opt_noheap, "no_heap"}, 49 {Opt_nouser_xattr, "nouser_xattr"}, 50 {Opt_noacl, "noacl"}, 51 {Opt_active_logs, "active_logs=%u"}, 52 {Opt_disable_ext_identify, "disable_ext_identify"}, 53 {Opt_err, NULL}, 54}; 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) 57{ 58 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; 59 60 inode_init_once(&fi->vfs_inode); 61} 62 63static struct inode *f2fs_alloc_inode(struct super_block *sb) --- 56 unchanged lines hidden (view full) --- 120{ 121 struct f2fs_sb_info *sbi = F2FS_SB(sb); 122 123 if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) 124 return 0; 125 126 if (sync) 127 write_checkpoint(sbi, false, false); | 68static void init_once(void *foo) 69{ 70 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; 71 72 inode_init_once(&fi->vfs_inode); 73} 74 75static struct inode *f2fs_alloc_inode(struct super_block *sb) --- 56 unchanged lines hidden (view full) --- 132{ 133 struct f2fs_sb_info *sbi = F2FS_SB(sb); 134 135 if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) 136 return 0; 137 138 if (sync) 139 write_checkpoint(sbi, false, false); |
140 else 141 f2fs_balance_fs(sbi); |
|
128 129 return 0; 130} 131 132static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) 133{ 134 struct super_block *sb = dentry->d_sb; 135 struct f2fs_sb_info *sbi = F2FS_SB(sb); --- 106 unchanged lines hidden (view full) --- 242} 243 244static const struct export_operations f2fs_export_ops = { 245 .fh_to_dentry = f2fs_fh_to_dentry, 246 .fh_to_parent = f2fs_fh_to_parent, 247 .get_parent = f2fs_get_parent, 248}; 249 | 142 143 return 0; 144} 145 146static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) 147{ 148 struct super_block *sb = dentry->d_sb; 149 struct f2fs_sb_info *sbi = F2FS_SB(sb); --- 106 unchanged lines hidden (view full) --- 256} 257 258static const struct export_operations f2fs_export_ops = { 259 .fh_to_dentry = f2fs_fh_to_dentry, 260 .fh_to_parent = f2fs_fh_to_parent, 261 .get_parent = f2fs_get_parent, 262}; 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{ 252 substring_t args[MAX_OPT_ARGS]; 253 char *p; 254 int arg = 0; 255 256 if (!options) 257 return 0; 258 --- 22 unchanged lines hidden (view full) --- 281 set_opt(sbi, NOHEAP); 282 break; 283#ifdef CONFIG_F2FS_FS_XATTR 284 case Opt_nouser_xattr: 285 clear_opt(sbi, XATTR_USER); 286 break; 287#else 288 case Opt_nouser_xattr: | 266{ 267 substring_t args[MAX_OPT_ARGS]; 268 char *p; 269 int arg = 0; 270 271 if (!options) 272 return 0; 273 --- 22 unchanged lines hidden (view full) --- 296 set_opt(sbi, NOHEAP); 297 break; 298#ifdef CONFIG_F2FS_FS_XATTR 299 case Opt_nouser_xattr: 300 clear_opt(sbi, XATTR_USER); 301 break; 302#else 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; 291#endif 292#ifdef CONFIG_F2FS_FS_POSIX_ACL 293 case Opt_noacl: 294 clear_opt(sbi, POSIX_ACL); 295 break; 296#else 297 case Opt_noacl: | 306 break; 307#endif 308#ifdef CONFIG_F2FS_FS_POSIX_ACL 309 case Opt_noacl: 310 clear_opt(sbi, POSIX_ACL); 311 break; 312#else 313 case Opt_noacl: |
298 pr_info("noacl options not supported\n"); | 314 f2fs_msg(sb, KERN_INFO, "noacl options not supported"); |
299 break; 300#endif 301 case Opt_active_logs: 302 if (args->from && match_int(args, &arg)) 303 return -EINVAL; 304 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE) 305 return -EINVAL; 306 sbi->active_logs = arg; 307 break; 308 case Opt_disable_ext_identify: 309 set_opt(sbi, DISABLE_EXT_IDENTIFY); 310 break; 311 default: | 315 break; 316#endif 317 case Opt_active_logs: 318 if (args->from && match_int(args, &arg)) 319 return -EINVAL; 320 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE) 321 return -EINVAL; 322 sbi->active_logs = arg; 323 break; 324 case Opt_disable_ext_identify: 325 set_opt(sbi, DISABLE_EXT_IDENTIFY); 326 break; 327 default: |
312 pr_err("Unrecognized mount option \"%s\" or missing value\n", 313 p); | 328 f2fs_msg(sb, KERN_ERR, 329 "Unrecognized mount option \"%s\" or missing value", 330 p); |
314 return -EINVAL; 315 } 316 } 317 return 0; 318} 319 320static loff_t max_file_size(unsigned bits) 321{ --- 10 unchanged lines hidden (view full) --- 332 /* one double indirect node block */ 333 leaf_count *= NIDS_PER_BLOCK; 334 result += leaf_count; 335 336 result <<= bits; 337 return result; 338} 339 | 331 return -EINVAL; 332 } 333 } 334 return 0; 335} 336 337static loff_t max_file_size(unsigned bits) 338{ --- 10 unchanged lines hidden (view full) --- 349 /* one double indirect node block */ 350 leaf_count *= NIDS_PER_BLOCK; 351 result += leaf_count; 352 353 result <<= bits; 354 return result; 355} 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{ 342 unsigned int blocksize; 343 | 359{ 360 unsigned int blocksize; 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 347 /* Currently, support only 4KB block size */ 348 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); | 368 369 /* Currently, support only 4KB block size */ 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; 358} 359 360static int sanity_check_ckpt(struct f2fs_super_block *raw_super, 361 struct f2fs_checkpoint *ckpt) 362{ 363 unsigned int total, fsmeta; 364 --- 43 unchanged lines hidden (view full) --- 408 long err = -EINVAL; 409 int i; 410 411 /* allocate memory for f2fs-specific super block info */ 412 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); 413 if (!sbi) 414 return -ENOMEM; 415 | 387 return 0; 388} 389 390static int sanity_check_ckpt(struct f2fs_super_block *raw_super, 391 struct f2fs_checkpoint *ckpt) 392{ 393 unsigned int total, fsmeta; 394 --- 43 unchanged lines hidden (view full) --- 438 long err = -EINVAL; 439 int i; 440 441 /* allocate memory for f2fs-specific super block info */ 442 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); 443 if (!sbi) 444 return -ENOMEM; 445 |
416 /* set a temporary block size */ 417 if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) | 446 /* set a block size */ 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 420 /* read f2fs raw super block */ 421 raw_super_buf = sb_bread(sb, 0); 422 if (!raw_super_buf) { 423 err = -EIO; | 451 452 /* read f2fs raw super block */ 453 raw_super_buf = sb_bread(sb, 0); 454 if (!raw_super_buf) { 455 err = -EIO; |
456 f2fs_msg(sb, KERN_ERR, "unable to read superblock"); |
|
424 goto free_sbi; 425 } 426 raw_super = (struct f2fs_super_block *) 427 ((char *)raw_super_buf->b_data + F2FS_SUPER_OFFSET); 428 429 /* init some FS parameters */ 430 sbi->active_logs = NR_CURSEG_TYPE; 431 432 set_opt(sbi, BG_GC); 433 434#ifdef CONFIG_F2FS_FS_XATTR 435 set_opt(sbi, XATTR_USER); 436#endif 437#ifdef CONFIG_F2FS_FS_POSIX_ACL 438 set_opt(sbi, POSIX_ACL); 439#endif 440 /* parse mount options */ | 457 goto free_sbi; 458 } 459 raw_super = (struct f2fs_super_block *) 460 ((char *)raw_super_buf->b_data + F2FS_SUPER_OFFSET); 461 462 /* init some FS parameters */ 463 sbi->active_logs = NR_CURSEG_TYPE; 464 465 set_opt(sbi, BG_GC); 466 467#ifdef CONFIG_F2FS_FS_XATTR 468 set_opt(sbi, XATTR_USER); 469#endif 470#ifdef CONFIG_F2FS_FS_POSIX_ACL 471 set_opt(sbi, POSIX_ACL); 472#endif 473 /* parse mount options */ |
441 if (parse_options(sbi, (char *)data)) | 474 if (parse_options(sb, sbi, (char *)data)) |
442 goto free_sb_buf; 443 444 /* sanity checking of raw super */ | 475 goto free_sb_buf; 476 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 448 sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); 449 sb->s_max_links = F2FS_LINK_MAX; 450 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 451 452 sb->s_op = &f2fs_sops; 453 sb->s_xattr = f2fs_xattr_handlers; 454 sb->s_export_op = &f2fs_export_ops; --- 17 unchanged lines hidden (view full) --- 472 sbi->por_doing = 0; 473 spin_lock_init(&sbi->stat_lock); 474 init_rwsem(&sbi->bio_sem); 475 init_sb_info(sbi); 476 477 /* get an inode for meta space */ 478 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); 479 if (IS_ERR(sbi->meta_inode)) { | 482 483 sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); 484 sb->s_max_links = F2FS_LINK_MAX; 485 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 486 487 sb->s_op = &f2fs_sops; 488 sb->s_xattr = f2fs_xattr_handlers; 489 sb->s_export_op = &f2fs_export_ops; --- 17 unchanged lines hidden (view full) --- 507 sbi->por_doing = 0; 508 spin_lock_init(&sbi->stat_lock); 509 init_rwsem(&sbi->bio_sem); 510 init_sb_info(sbi); 511 512 /* get an inode for meta space */ 513 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); 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); 481 goto free_sb_buf; 482 } 483 484 err = get_valid_checkpoint(sbi); | 516 err = PTR_ERR(sbi->meta_inode); 517 goto free_sb_buf; 518 } 519 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 488 /* sanity checking of checkpoint */ 489 err = -EINVAL; | 525 526 /* sanity checking of checkpoint */ 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 493 sbi->total_valid_node_count = 494 le32_to_cpu(sbi->ckpt->valid_node_count); 495 sbi->total_valid_inode_count = 496 le32_to_cpu(sbi->ckpt->valid_inode_count); 497 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); 498 sbi->total_valid_block_count = 499 le64_to_cpu(sbi->ckpt->valid_block_count); 500 sbi->last_valid_block_count = sbi->total_valid_block_count; 501 sbi->alloc_valid_block_count = 0; 502 INIT_LIST_HEAD(&sbi->dir_inode_list); 503 spin_lock_init(&sbi->dir_inode_lock); 504 | 532 533 sbi->total_valid_node_count = 534 le32_to_cpu(sbi->ckpt->valid_node_count); 535 sbi->total_valid_inode_count = 536 le32_to_cpu(sbi->ckpt->valid_inode_count); 537 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); 538 sbi->total_valid_block_count = 539 le64_to_cpu(sbi->ckpt->valid_block_count); 540 sbi->last_valid_block_count = sbi->total_valid_block_count; 541 sbi->alloc_valid_block_count = 0; 542 INIT_LIST_HEAD(&sbi->dir_inode_list); 543 spin_lock_init(&sbi->dir_inode_lock); 544 |
505 /* init super block */ 506 if (!sb_set_blocksize(sb, sbi->blocksize)) 507 goto free_cp; 508 | |
509 init_orphan_info(sbi); 510 511 /* setup f2fs internal modules */ 512 err = build_segment_manager(sbi); | 545 init_orphan_info(sbi); 546 547 /* setup f2fs internal modules */ 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 519 build_gc_manager(sbi); 520 521 /* get an inode for node space */ 522 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); 523 if (IS_ERR(sbi->node_inode)) { | 560 561 build_gc_manager(sbi); 562 563 /* get an inode for node space */ 564 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); 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); 525 goto free_nm; 526 } 527 528 /* if there are nt orphan nodes free them */ 529 err = -EINVAL; 530 if (recover_orphan_inodes(sbi)) 531 goto free_node_inode; 532 533 /* read root inode and dentry */ 534 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); 535 if (IS_ERR(root)) { | 567 err = PTR_ERR(sbi->node_inode); 568 goto free_nm; 569 } 570 571 /* if there are nt orphan nodes free them */ 572 err = -EINVAL; 573 if (recover_orphan_inodes(sbi)) 574 goto free_node_inode; 575 576 /* read root inode and dentry */ 577 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); 578 if (IS_ERR(root)) { |
579 f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); |
|
536 err = PTR_ERR(root); 537 goto free_node_inode; 538 } 539 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) 540 goto free_root_inode; 541 542 sb->s_root = d_make_root(root); /* allocate root dentry */ 543 if (!sb->s_root) { --- 47 unchanged lines hidden (view full) --- 591static struct file_system_type f2fs_fs_type = { 592 .owner = THIS_MODULE, 593 .name = "f2fs", 594 .mount = f2fs_mount, 595 .kill_sb = kill_block_super, 596 .fs_flags = FS_REQUIRES_DEV, 597}; 598 | 580 err = PTR_ERR(root); 581 goto free_node_inode; 582 } 583 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) 584 goto free_root_inode; 585 586 sb->s_root = d_make_root(root); /* allocate root dentry */ 587 if (!sb->s_root) { --- 47 unchanged lines hidden (view full) --- 635static struct file_system_type f2fs_fs_type = { 636 .owner = THIS_MODULE, 637 .name = "f2fs", 638 .mount = f2fs_mount, 639 .kill_sb = kill_block_super, 640 .fs_flags = FS_REQUIRES_DEV, 641}; 642 |
599static int init_inodecache(void) | 643static int __init init_inodecache(void) |
600{ 601 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", 602 sizeof(struct f2fs_inode_info), NULL); 603 if (f2fs_inode_cachep == NULL) 604 return -ENOMEM; 605 return 0; 606} 607 --- 18 unchanged lines hidden (view full) --- 626 if (err) 627 goto fail; 628 err = create_gc_caches(); 629 if (err) 630 goto fail; 631 err = create_checkpoint_caches(); 632 if (err) 633 goto fail; | 644{ 645 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", 646 sizeof(struct f2fs_inode_info), NULL); 647 if (f2fs_inode_cachep == NULL) 648 return -ENOMEM; 649 return 0; 650} 651 --- 18 unchanged lines hidden (view full) --- 670 if (err) 671 goto fail; 672 err = create_gc_caches(); 673 if (err) 674 goto fail; 675 err = create_checkpoint_caches(); 676 if (err) 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: 636 return err; 637} 638 639static void __exit exit_f2fs_fs(void) 640{ | 682fail: 683 return err; 684} 685 686static void __exit exit_f2fs_fs(void) 687{ |
641 destroy_root_stats(); | 688 f2fs_destroy_root_stats(); |
642 unregister_filesystem(&f2fs_fs_type); 643 destroy_checkpoint_caches(); 644 destroy_gc_caches(); 645 destroy_node_manager_caches(); 646 destroy_inodecache(); 647} 648 649module_init(init_f2fs_fs) 650module_exit(exit_f2fs_fs) 651 652MODULE_AUTHOR("Samsung Electronics's Praesto Team"); 653MODULE_DESCRIPTION("Flash Friendly File System"); 654MODULE_LICENSE("GPL"); | 689 unregister_filesystem(&f2fs_fs_type); 690 destroy_checkpoint_caches(); 691 destroy_gc_caches(); 692 destroy_node_manager_caches(); 693 destroy_inodecache(); 694} 695 696module_init(init_f2fs_fs) 697module_exit(exit_f2fs_fs) 698 699MODULE_AUTHOR("Samsung Electronics's Praesto Team"); 700MODULE_DESCRIPTION("Flash Friendly File System"); 701MODULE_LICENSE("GPL"); |