super.c (8df22a4d6f5b81c9c1703579d4907b57002689ed) | super.c (88b88a66797159949cec32eaab12b4968f6fae2d) |
---|---|
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 --- 176 unchanged lines hidden (view full) --- 185F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 186F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 187F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 188F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 189F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 190F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards); 191F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 192F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); | 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 --- 176 unchanged lines hidden (view full) --- 185F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 186F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 187F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 188F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 189F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 190F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards); 191F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 192F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); |
193F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks); |
|
193F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); 194F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 195F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 196 197#define ATTR_LIST(name) (&f2fs_attr_##name.attr) 198static struct attribute *f2fs_attrs[] = { 199 ATTR_LIST(gc_min_sleep_time), 200 ATTR_LIST(gc_max_sleep_time), 201 ATTR_LIST(gc_no_gc_sleep_time), 202 ATTR_LIST(gc_idle), 203 ATTR_LIST(reclaim_segments), 204 ATTR_LIST(max_small_discards), 205 ATTR_LIST(ipu_policy), 206 ATTR_LIST(min_ipu_util), | 194F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); 195F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 196F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 197 198#define ATTR_LIST(name) (&f2fs_attr_##name.attr) 199static struct attribute *f2fs_attrs[] = { 200 ATTR_LIST(gc_min_sleep_time), 201 ATTR_LIST(gc_max_sleep_time), 202 ATTR_LIST(gc_no_gc_sleep_time), 203 ATTR_LIST(gc_idle), 204 ATTR_LIST(reclaim_segments), 205 ATTR_LIST(max_small_discards), 206 ATTR_LIST(ipu_policy), 207 ATTR_LIST(min_ipu_util), |
208 ATTR_LIST(min_fsync_blocks), |
|
207 ATTR_LIST(max_victim_search), 208 ATTR_LIST(dir_level), 209 ATTR_LIST(ram_thresh), 210 NULL, 211}; 212 213static const struct sysfs_ops f2fs_attr_ops = { 214 .show = f2fs_attr_show, --- 146 unchanged lines hidden (view full) --- 361 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO); 362 if (!fi) 363 return NULL; 364 365 init_once((void *) fi); 366 367 /* Initialize f2fs-specific inode info */ 368 fi->vfs_inode.i_version = 1; | 209 ATTR_LIST(max_victim_search), 210 ATTR_LIST(dir_level), 211 ATTR_LIST(ram_thresh), 212 NULL, 213}; 214 215static const struct sysfs_ops f2fs_attr_ops = { 216 .show = f2fs_attr_show, --- 146 unchanged lines hidden (view full) --- 363 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO); 364 if (!fi) 365 return NULL; 366 367 init_once((void *) fi); 368 369 /* Initialize f2fs-specific inode info */ 370 fi->vfs_inode.i_version = 1; |
369 atomic_set(&fi->dirty_dents, 0); | 371 atomic_set(&fi->dirty_pages, 0); |
370 fi->i_current_depth = 1; 371 fi->i_advise = 0; 372 rwlock_init(&fi->ext.ext_lock); 373 init_rwsem(&fi->i_sem); | 372 fi->i_current_depth = 1; 373 fi->i_advise = 0; 374 rwlock_init(&fi->ext.ext_lock); 375 init_rwsem(&fi->i_sem); |
376 INIT_LIST_HEAD(&fi->inmem_pages); 377 mutex_init(&fi->inmem_lock); |
|
374 375 set_inode_flag(fi, FI_NEW_INODE); 376 377 if (test_opt(F2FS_SB(sb), INLINE_XATTR)) 378 set_inode_flag(fi, FI_INLINE_XATTR); 379 380 /* Will be used by directory only */ 381 fi->i_dir_level = F2FS_SB(sb)->dir_level; --- 45 unchanged lines hidden (view full) --- 427 remove_proc_entry(sb->s_id, f2fs_proc_root); 428 } 429 kobject_del(&sbi->s_kobj); 430 431 f2fs_destroy_stats(sbi); 432 stop_gc_thread(sbi); 433 434 /* We don't need to do checkpoint when it's clean */ | 378 379 set_inode_flag(fi, FI_NEW_INODE); 380 381 if (test_opt(F2FS_SB(sb), INLINE_XATTR)) 382 set_inode_flag(fi, FI_INLINE_XATTR); 383 384 /* Will be used by directory only */ 385 fi->i_dir_level = F2FS_SB(sb)->dir_level; --- 45 unchanged lines hidden (view full) --- 431 remove_proc_entry(sb->s_id, f2fs_proc_root); 432 } 433 kobject_del(&sbi->s_kobj); 434 435 f2fs_destroy_stats(sbi); 436 stop_gc_thread(sbi); 437 438 /* We don't need to do checkpoint when it's clean */ |
435 if (sbi->s_dirty) 436 write_checkpoint(sbi, true); | 439 if (sbi->s_dirty) { 440 struct cp_control cpc = { 441 .reason = CP_UMOUNT, 442 }; 443 write_checkpoint(sbi, &cpc); 444 } |
437 438 /* 439 * normally superblock is clean, so we need to release this. 440 * In addition, EIO will skip do checkpoint, we need this as well. 441 */ 442 release_dirty_inode(sbi); | 445 446 /* 447 * normally superblock is clean, so we need to release this. 448 * In addition, EIO will skip do checkpoint, we need this as well. 449 */ 450 release_dirty_inode(sbi); |
451 release_discard_addrs(sbi); |
|
443 444 iput(sbi->node_inode); 445 iput(sbi->meta_inode); 446 447 /* destroy f2fs internal modules */ 448 destroy_node_manager(sbi); 449 destroy_segment_manager(sbi); 450 --- 8 unchanged lines hidden (view full) --- 459 460int f2fs_sync_fs(struct super_block *sb, int sync) 461{ 462 struct f2fs_sb_info *sbi = F2FS_SB(sb); 463 464 trace_f2fs_sync_fs(sb, sync); 465 466 if (sync) { | 452 453 iput(sbi->node_inode); 454 iput(sbi->meta_inode); 455 456 /* destroy f2fs internal modules */ 457 destroy_node_manager(sbi); 458 destroy_segment_manager(sbi); 459 --- 8 unchanged lines hidden (view full) --- 468 469int f2fs_sync_fs(struct super_block *sb, int sync) 470{ 471 struct f2fs_sb_info *sbi = F2FS_SB(sb); 472 473 trace_f2fs_sync_fs(sb, sync); 474 475 if (sync) { |
476 struct cp_control cpc = { 477 .reason = CP_SYNC, 478 }; |
|
467 mutex_lock(&sbi->gc_mutex); | 479 mutex_lock(&sbi->gc_mutex); |
468 write_checkpoint(sbi, false); | 480 write_checkpoint(sbi, &cpc); |
469 mutex_unlock(&sbi->gc_mutex); 470 } else { 471 f2fs_balance_fs(sbi); 472 } 473 474 return 0; 475} 476 --- 134 unchanged lines hidden (view full) --- 611 612 /* 613 * Save the old mount options in case we 614 * need to restore them. 615 */ 616 org_mount_opt = sbi->mount_opt; 617 active_logs = sbi->active_logs; 618 | 481 mutex_unlock(&sbi->gc_mutex); 482 } else { 483 f2fs_balance_fs(sbi); 484 } 485 486 return 0; 487} 488 --- 134 unchanged lines hidden (view full) --- 623 624 /* 625 * Save the old mount options in case we 626 * need to restore them. 627 */ 628 org_mount_opt = sbi->mount_opt; 629 active_logs = sbi->active_logs; 630 |
631 sbi->mount_opt.opt = 0; 632 sbi->active_logs = NR_CURSEG_TYPE; 633 |
|
619 /* parse mount options */ 620 err = parse_options(sb, data); 621 if (err) 622 goto restore_opts; 623 624 /* 625 * Previous and new state of filesystem is RO, 626 * so skip checking GC and FLUSH_MERGE conditions. --- 154 unchanged lines hidden (view full) --- 781 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); 782 if (blocksize != F2FS_BLKSIZE) { 783 f2fs_msg(sb, KERN_INFO, 784 "Invalid blocksize (%u), supports only 4KB\n", 785 blocksize); 786 return 1; 787 } 788 | 634 /* parse mount options */ 635 err = parse_options(sb, data); 636 if (err) 637 goto restore_opts; 638 639 /* 640 * Previous and new state of filesystem is RO, 641 * so skip checking GC and FLUSH_MERGE conditions. --- 154 unchanged lines hidden (view full) --- 796 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); 797 if (blocksize != F2FS_BLKSIZE) { 798 f2fs_msg(sb, KERN_INFO, 799 "Invalid blocksize (%u), supports only 4KB\n", 800 blocksize); 801 return 1; 802 } 803 |
789 if (le32_to_cpu(raw_super->log_sectorsize) != 790 F2FS_LOG_SECTOR_SIZE) { 791 f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize"); | 804 /* Currently, support 512/1024/2048/4096 bytes sector size */ 805 if (le32_to_cpu(raw_super->log_sectorsize) > 806 F2FS_MAX_LOG_SECTOR_SIZE || 807 le32_to_cpu(raw_super->log_sectorsize) < 808 F2FS_MIN_LOG_SECTOR_SIZE) { 809 f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize (%u)", 810 le32_to_cpu(raw_super->log_sectorsize)); |
792 return 1; 793 } | 811 return 1; 812 } |
794 if (le32_to_cpu(raw_super->log_sectors_per_block) != 795 F2FS_LOG_SECTORS_PER_BLOCK) { 796 f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block"); | 813 if (le32_to_cpu(raw_super->log_sectors_per_block) + 814 le32_to_cpu(raw_super->log_sectorsize) != 815 F2FS_MAX_LOG_SECTOR_SIZE) { 816 f2fs_msg(sb, KERN_INFO, 817 "Invalid log sectors per block(%u) log sectorsize(%u)", 818 le32_to_cpu(raw_super->log_sectors_per_block), 819 le32_to_cpu(raw_super->log_sectorsize)); |
797 return 1; 798 } 799 return 0; 800} 801 802static int sanity_check_ckpt(struct f2fs_sb_info *sbi) 803{ 804 unsigned int total, fsmeta; --- 39 unchanged lines hidden (view full) --- 844 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); 845 sbi->cur_victim_sec = NULL_SECNO; 846 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; 847 848 for (i = 0; i < NR_COUNT_TYPE; i++) 849 atomic_set(&sbi->nr_pages[i], 0); 850 851 sbi->dir_level = DEF_DIR_LEVEL; | 820 return 1; 821 } 822 return 0; 823} 824 825static int sanity_check_ckpt(struct f2fs_sb_info *sbi) 826{ 827 unsigned int total, fsmeta; --- 39 unchanged lines hidden (view full) --- 867 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); 868 sbi->cur_victim_sec = NULL_SECNO; 869 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; 870 871 for (i = 0; i < NR_COUNT_TYPE; i++) 872 atomic_set(&sbi->nr_pages[i], 0); 873 874 sbi->dir_level = DEF_DIR_LEVEL; |
875 sbi->need_fsck = false; |
|
852} 853 854/* 855 * Read f2fs raw super block. 856 * Because we have two copies of super block, so read the first one at first, 857 * if the first one is invalid, move to read the second one. 858 */ 859static int read_raw_super_block(struct super_block *sb, --- 217 unchanged lines hidden (view full) --- 1077 1078 sbi->s_kobj.kset = f2fs_kset; 1079 init_completion(&sbi->s_kobj_unregister); 1080 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, 1081 "%s", sb->s_id); 1082 if (err) 1083 goto free_proc; 1084 | 876} 877 878/* 879 * Read f2fs raw super block. 880 * Because we have two copies of super block, so read the first one at first, 881 * if the first one is invalid, move to read the second one. 882 */ 883static int read_raw_super_block(struct super_block *sb, --- 217 unchanged lines hidden (view full) --- 1101 1102 sbi->s_kobj.kset = f2fs_kset; 1103 init_completion(&sbi->s_kobj_unregister); 1104 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, 1105 "%s", sb->s_id); 1106 if (err) 1107 goto free_proc; 1108 |
1109 if (!retry) 1110 sbi->need_fsck = true; 1111 |
|
1085 /* recover fsynced data */ 1086 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 1087 err = recover_fsync_data(sbi); 1088 if (err) { 1089 f2fs_msg(sb, KERN_ERR, 1090 "Cannot recover all fsync data errno=%ld", err); 1091 goto free_kobj; 1092 } --- 150 unchanged lines hidden --- | 1112 /* recover fsynced data */ 1113 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 1114 err = recover_fsync_data(sbi); 1115 if (err) { 1116 f2fs_msg(sb, KERN_ERR, 1117 "Cannot recover all fsync data errno=%ld", err); 1118 goto free_kobj; 1119 } --- 150 unchanged lines hidden --- |