super.c (e19b9137142988bec5a76c5f8bdf12a77ea802b0) | super.c (cdfc41c134d48c1923066bcfa6630b94588ad6bc) |
---|---|
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 --- 60 unchanged lines hidden (view full) --- 69 {Opt_inline_data, "inline_data"}, 70 {Opt_err, NULL}, 71}; 72 73/* Sysfs support for f2fs */ 74enum { 75 GC_THREAD, /* struct f2fs_gc_thread */ 76 SM_INFO, /* struct f2fs_sm_info */ | 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 --- 60 unchanged lines hidden (view full) --- 69 {Opt_inline_data, "inline_data"}, 70 {Opt_err, NULL}, 71}; 72 73/* Sysfs support for f2fs */ 74enum { 75 GC_THREAD, /* struct f2fs_gc_thread */ 76 SM_INFO, /* struct f2fs_sm_info */ |
77 NM_INFO, /* struct f2fs_nm_info */ |
|
77 F2FS_SBI, /* struct f2fs_sb_info */ 78}; 79 80struct f2fs_attr { 81 struct attribute attr; 82 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *); 83 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *, 84 const char *, size_t); 85 int struct_type; 86 int offset; 87}; 88 89static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) 90{ 91 if (struct_type == GC_THREAD) 92 return (unsigned char *)sbi->gc_thread; 93 else if (struct_type == SM_INFO) 94 return (unsigned char *)SM_I(sbi); | 78 F2FS_SBI, /* struct f2fs_sb_info */ 79}; 80 81struct f2fs_attr { 82 struct attribute attr; 83 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *); 84 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *, 85 const char *, size_t); 86 int struct_type; 87 int offset; 88}; 89 90static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) 91{ 92 if (struct_type == GC_THREAD) 93 return (unsigned char *)sbi->gc_thread; 94 else if (struct_type == SM_INFO) 95 return (unsigned char *)SM_I(sbi); |
96 else if (struct_type == NM_INFO) 97 return (unsigned char *)NM_I(sbi); |
|
95 else if (struct_type == F2FS_SBI) 96 return (unsigned char *)sbi; 97 return NULL; 98} 99 100static ssize_t f2fs_sbi_show(struct f2fs_attr *a, 101 struct f2fs_sb_info *sbi, char *buf) 102{ --- 75 unchanged lines hidden (view full) --- 178F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 179F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 180F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 181F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 182F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 183F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards); 184F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 185F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); | 98 else if (struct_type == F2FS_SBI) 99 return (unsigned char *)sbi; 100 return NULL; 101} 102 103static ssize_t f2fs_sbi_show(struct f2fs_attr *a, 104 struct f2fs_sb_info *sbi, char *buf) 105{ --- 75 unchanged lines hidden (view full) --- 181F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 182F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 183F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 184F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 185F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 186F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards); 187F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 188F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); |
189F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); |
|
186F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); | 190F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); |
191F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); |
|
187 188#define ATTR_LIST(name) (&f2fs_attr_##name.attr) 189static struct attribute *f2fs_attrs[] = { 190 ATTR_LIST(gc_min_sleep_time), 191 ATTR_LIST(gc_max_sleep_time), 192 ATTR_LIST(gc_no_gc_sleep_time), 193 ATTR_LIST(gc_idle), 194 ATTR_LIST(reclaim_segments), 195 ATTR_LIST(max_small_discards), 196 ATTR_LIST(ipu_policy), 197 ATTR_LIST(min_ipu_util), 198 ATTR_LIST(max_victim_search), | 192 193#define ATTR_LIST(name) (&f2fs_attr_##name.attr) 194static struct attribute *f2fs_attrs[] = { 195 ATTR_LIST(gc_min_sleep_time), 196 ATTR_LIST(gc_max_sleep_time), 197 ATTR_LIST(gc_no_gc_sleep_time), 198 ATTR_LIST(gc_idle), 199 ATTR_LIST(reclaim_segments), 200 ATTR_LIST(max_small_discards), 201 ATTR_LIST(ipu_policy), 202 ATTR_LIST(min_ipu_util), 203 ATTR_LIST(max_victim_search), |
204 ATTR_LIST(dir_level), 205 ATTR_LIST(ram_thresh), |
|
199 NULL, 200}; 201 202static const struct sysfs_ops f2fs_attr_ops = { 203 .show = f2fs_attr_show, 204 .store = f2fs_attr_store, 205}; 206 --- 44 unchanged lines hidden (view full) --- 251 token = match_token(p, f2fs_tokens, args); 252 253 switch (token) { 254 case Opt_gc_background: 255 name = match_strdup(&args[0]); 256 257 if (!name) 258 return -ENOMEM; | 206 NULL, 207}; 208 209static const struct sysfs_ops f2fs_attr_ops = { 210 .show = f2fs_attr_show, 211 .store = f2fs_attr_store, 212}; 213 --- 44 unchanged lines hidden (view full) --- 258 token = match_token(p, f2fs_tokens, args); 259 260 switch (token) { 261 case Opt_gc_background: 262 name = match_strdup(&args[0]); 263 264 if (!name) 265 return -ENOMEM; |
259 if (!strncmp(name, "on", 2)) | 266 if (strlen(name) == 2 && !strncmp(name, "on", 2)) |
260 set_opt(sbi, BG_GC); | 267 set_opt(sbi, BG_GC); |
261 else if (!strncmp(name, "off", 3)) | 268 else if (strlen(name) == 3 && !strncmp(name, "off", 3)) |
262 clear_opt(sbi, BG_GC); 263 else { 264 kfree(name); 265 return -EINVAL; 266 } 267 kfree(name); 268 break; 269 case Opt_disable_roll_forward: --- 84 unchanged lines hidden (view full) --- 354 fi->i_advise = 0; 355 rwlock_init(&fi->ext.ext_lock); 356 357 set_inode_flag(fi, FI_NEW_INODE); 358 359 if (test_opt(F2FS_SB(sb), INLINE_XATTR)) 360 set_inode_flag(fi, FI_INLINE_XATTR); 361 | 269 clear_opt(sbi, BG_GC); 270 else { 271 kfree(name); 272 return -EINVAL; 273 } 274 kfree(name); 275 break; 276 case Opt_disable_roll_forward: --- 84 unchanged lines hidden (view full) --- 361 fi->i_advise = 0; 362 rwlock_init(&fi->ext.ext_lock); 363 364 set_inode_flag(fi, FI_NEW_INODE); 365 366 if (test_opt(F2FS_SB(sb), INLINE_XATTR)) 367 set_inode_flag(fi, FI_INLINE_XATTR); 368 |
369 /* Will be used by directory only */ 370 fi->i_dir_level = F2FS_SB(sb)->dir_level; 371 |
|
362 return &fi->vfs_inode; 363} 364 365static int f2fs_drop_inode(struct inode *inode) 366{ 367 /* 368 * This is to avoid a deadlock condition like below. 369 * writeback_single_inode(inode) --- 164 unchanged lines hidden (view full) --- 534static int segment_info_seq_show(struct seq_file *seq, void *offset) 535{ 536 struct super_block *sb = seq->private; 537 struct f2fs_sb_info *sbi = F2FS_SB(sb); 538 unsigned int total_segs = 539 le32_to_cpu(sbi->raw_super->segment_count_main); 540 int i; 541 | 372 return &fi->vfs_inode; 373} 374 375static int f2fs_drop_inode(struct inode *inode) 376{ 377 /* 378 * This is to avoid a deadlock condition like below. 379 * writeback_single_inode(inode) --- 164 unchanged lines hidden (view full) --- 544static int segment_info_seq_show(struct seq_file *seq, void *offset) 545{ 546 struct super_block *sb = seq->private; 547 struct f2fs_sb_info *sbi = F2FS_SB(sb); 548 unsigned int total_segs = 549 le32_to_cpu(sbi->raw_super->segment_count_main); 550 int i; 551 |
552 seq_puts(seq, "format: segment_type|valid_blocks\n" 553 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 554 |
|
542 for (i = 0; i < total_segs; i++) { | 555 for (i = 0; i < total_segs; i++) { |
543 seq_printf(seq, "%u", get_valid_blocks(sbi, i, 1)); 544 if (i != 0 && (i % 10) == 0) 545 seq_puts(seq, "\n"); | 556 struct seg_entry *se = get_seg_entry(sbi, i); 557 558 if ((i % 10) == 0) 559 seq_printf(seq, "%-5d", i); 560 seq_printf(seq, "%d|%-3u", se->type, 561 get_valid_blocks(sbi, i, 1)); 562 if ((i % 10) == 9 || i == (total_segs - 1)) 563 seq_putc(seq, '\n'); |
546 else | 564 else |
547 seq_puts(seq, " "); | 565 seq_putc(seq, ' '); |
548 } | 566 } |
567 |
|
549 return 0; 550} 551 552static int segment_info_open_fs(struct inode *inode, struct file *file) 553{ 554 return single_open(file, segment_info_seq_show, PDE_DATA(inode)); 555} 556 --- 76 unchanged lines hidden (view full) --- 633static struct inode *f2fs_nfs_get_inode(struct super_block *sb, 634 u64 ino, u32 generation) 635{ 636 struct f2fs_sb_info *sbi = F2FS_SB(sb); 637 struct inode *inode; 638 639 if (unlikely(ino < F2FS_ROOT_INO(sbi))) 640 return ERR_PTR(-ESTALE); | 568 return 0; 569} 570 571static int segment_info_open_fs(struct inode *inode, struct file *file) 572{ 573 return single_open(file, segment_info_seq_show, PDE_DATA(inode)); 574} 575 --- 76 unchanged lines hidden (view full) --- 652static struct inode *f2fs_nfs_get_inode(struct super_block *sb, 653 u64 ino, u32 generation) 654{ 655 struct f2fs_sb_info *sbi = F2FS_SB(sb); 656 struct inode *inode; 657 658 if (unlikely(ino < F2FS_ROOT_INO(sbi))) 659 return ERR_PTR(-ESTALE); |
660 if (unlikely(ino >= NM_I(sbi)->max_nid)) 661 return ERR_PTR(-ESTALE); |
|
641 642 /* 643 * f2fs_iget isn't quite right if the inode is currently unallocated! 644 * However f2fs_iget currently does appropriate checks to handle stale 645 * inodes so everything is OK. 646 */ 647 inode = f2fs_iget(sb, ino); 648 if (IS_ERR(inode)) --- 131 unchanged lines hidden (view full) --- 780 sbi->root_ino_num = le32_to_cpu(raw_super->root_ino); 781 sbi->node_ino_num = le32_to_cpu(raw_super->node_ino); 782 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); 783 sbi->cur_victim_sec = NULL_SECNO; 784 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; 785 786 for (i = 0; i < NR_COUNT_TYPE; i++) 787 atomic_set(&sbi->nr_pages[i], 0); | 662 663 /* 664 * f2fs_iget isn't quite right if the inode is currently unallocated! 665 * However f2fs_iget currently does appropriate checks to handle stale 666 * inodes so everything is OK. 667 */ 668 inode = f2fs_iget(sb, ino); 669 if (IS_ERR(inode)) --- 131 unchanged lines hidden (view full) --- 801 sbi->root_ino_num = le32_to_cpu(raw_super->root_ino); 802 sbi->node_ino_num = le32_to_cpu(raw_super->node_ino); 803 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); 804 sbi->cur_victim_sec = NULL_SECNO; 805 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; 806 807 for (i = 0; i < NR_COUNT_TYPE; i++) 808 atomic_set(&sbi->nr_pages[i], 0); |
809 810 sbi->dir_level = DEF_DIR_LEVEL; |
|
788} 789 790/* 791 * Read f2fs raw super block. 792 * Because we have two copies of super block, so read the first one at first, 793 * if the first one is invalid, move to read the second one. 794 */ 795static int read_raw_super_block(struct super_block *sb, --- 188 unchanged lines hidden (view full) --- 984 } 985 986 sb->s_root = d_make_root(root); /* allocate root dentry */ 987 if (!sb->s_root) { 988 err = -ENOMEM; 989 goto free_root_inode; 990 } 991 | 811} 812 813/* 814 * Read f2fs raw super block. 815 * Because we have two copies of super block, so read the first one at first, 816 * if the first one is invalid, move to read the second one. 817 */ 818static int read_raw_super_block(struct super_block *sb, --- 188 unchanged lines hidden (view full) --- 1007 } 1008 1009 sb->s_root = d_make_root(root); /* allocate root dentry */ 1010 if (!sb->s_root) { 1011 err = -ENOMEM; 1012 goto free_root_inode; 1013 } 1014 |
992 /* recover fsynced data */ 993 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 994 err = recover_fsync_data(sbi); 995 if (err) 996 f2fs_msg(sb, KERN_ERR, 997 "Cannot recover all fsync data errno=%ld", err); 998 } 999 1000 /* 1001 * If filesystem is not mounted as read-only then 1002 * do start the gc_thread. 1003 */ 1004 if (!(sb->s_flags & MS_RDONLY)) { 1005 /* After POR, we can run background GC thread.*/ 1006 err = start_gc_thread(sbi); 1007 if (err) 1008 goto free_gc; 1009 } 1010 | |
1011 err = f2fs_build_stats(sbi); 1012 if (err) | 1015 err = f2fs_build_stats(sbi); 1016 if (err) |
1013 goto free_gc; | 1017 goto free_root_inode; |
1014 1015 if (f2fs_proc_root) 1016 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 1017 1018 if (sbi->s_proc) 1019 proc_create_data("segment_info", S_IRUGO, sbi->s_proc, 1020 &f2fs_seq_segment_info_fops, sb); 1021 --- 5 unchanged lines hidden (view full) --- 1027 "the device does not support discard"); 1028 } 1029 1030 sbi->s_kobj.kset = f2fs_kset; 1031 init_completion(&sbi->s_kobj_unregister); 1032 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, 1033 "%s", sb->s_id); 1034 if (err) | 1018 1019 if (f2fs_proc_root) 1020 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 1021 1022 if (sbi->s_proc) 1023 proc_create_data("segment_info", S_IRUGO, sbi->s_proc, 1024 &f2fs_seq_segment_info_fops, sb); 1025 --- 5 unchanged lines hidden (view full) --- 1031 "the device does not support discard"); 1032 } 1033 1034 sbi->s_kobj.kset = f2fs_kset; 1035 init_completion(&sbi->s_kobj_unregister); 1036 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, 1037 "%s", sb->s_id); 1038 if (err) |
1035 goto fail; | 1039 goto free_proc; |
1036 | 1040 |
1041 /* recover fsynced data */ 1042 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 1043 err = recover_fsync_data(sbi); 1044 if (err) 1045 f2fs_msg(sb, KERN_ERR, 1046 "Cannot recover all fsync data errno=%ld", err); 1047 } 1048 1049 /* 1050 * If filesystem is not mounted as read-only then 1051 * do start the gc_thread. 1052 */ 1053 if (!(sb->s_flags & MS_RDONLY)) { 1054 /* After POR, we can run background GC thread.*/ 1055 err = start_gc_thread(sbi); 1056 if (err) 1057 goto free_kobj; 1058 } |
|
1037 return 0; | 1059 return 0; |
1038fail: | 1060 1061free_kobj: 1062 kobject_del(&sbi->s_kobj); 1063free_proc: |
1039 if (sbi->s_proc) { 1040 remove_proc_entry("segment_info", sbi->s_proc); 1041 remove_proc_entry(sb->s_id, f2fs_proc_root); 1042 } 1043 f2fs_destroy_stats(sbi); | 1064 if (sbi->s_proc) { 1065 remove_proc_entry("segment_info", sbi->s_proc); 1066 remove_proc_entry(sb->s_id, f2fs_proc_root); 1067 } 1068 f2fs_destroy_stats(sbi); |
1044free_gc: 1045 stop_gc_thread(sbi); | |
1046free_root_inode: 1047 dput(sb->s_root); 1048 sb->s_root = NULL; 1049free_node_inode: 1050 iput(sbi->node_inode); 1051free_nm: 1052 destroy_node_manager(sbi); 1053free_sm: --- 23 unchanged lines hidden (view full) --- 1077 .kill_sb = kill_block_super, 1078 .fs_flags = FS_REQUIRES_DEV, 1079}; 1080MODULE_ALIAS_FS("f2fs"); 1081 1082static int __init init_inodecache(void) 1083{ 1084 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", | 1069free_root_inode: 1070 dput(sb->s_root); 1071 sb->s_root = NULL; 1072free_node_inode: 1073 iput(sbi->node_inode); 1074free_nm: 1075 destroy_node_manager(sbi); 1076free_sm: --- 23 unchanged lines hidden (view full) --- 1100 .kill_sb = kill_block_super, 1101 .fs_flags = FS_REQUIRES_DEV, 1102}; 1103MODULE_ALIAS_FS("f2fs"); 1104 1105static int __init init_inodecache(void) 1106{ 1107 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", |
1085 sizeof(struct f2fs_inode_info), NULL); | 1108 sizeof(struct f2fs_inode_info)); |
1086 if (!f2fs_inode_cachep) 1087 return -ENOMEM; 1088 return 0; 1089} 1090 1091static void destroy_inodecache(void) 1092{ 1093 /* --- 73 unchanged lines hidden --- | 1109 if (!f2fs_inode_cachep) 1110 return -ENOMEM; 1111 return 0; 1112} 1113 1114static void destroy_inodecache(void) 1115{ 1116 /* --- 73 unchanged lines hidden --- |