super.c (833dcd35453713ced96e086daecf7f023709e6a4) | super.c (a7d9fe3c33887085a2e10c085d378126314dc222) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * fs/f2fs/super.c 4 * 5 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 6 * http://www.samsung.com/ 7 */ 8#include <linux/module.h> --- 541 unchanged lines hidden (view full) --- 550#endif 551 char *p, *name; 552 int arg = 0; 553 kuid_t uid; 554 kgid_t gid; 555 int ret; 556 557 if (!options) | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * fs/f2fs/super.c 4 * 5 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 6 * http://www.samsung.com/ 7 */ 8#include <linux/module.h> --- 541 unchanged lines hidden (view full) --- 550#endif 551 char *p, *name; 552 int arg = 0; 553 kuid_t uid; 554 kgid_t gid; 555 int ret; 556 557 if (!options) |
558 return 0; | 558 goto default_check; |
559 560 while ((p = strsep(&options, ",")) != NULL) { 561 int token; 562 563 if (!*p) 564 continue; 565 /* 566 * Initialize args struct so we know whether arg was --- 518 unchanged lines hidden (view full) --- 1085 clear_opt(sbi, GC_MERGE); 1086 break; 1087 default: 1088 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", 1089 p); 1090 return -EINVAL; 1091 } 1092 } | 559 560 while ((p = strsep(&options, ",")) != NULL) { 561 int token; 562 563 if (!*p) 564 continue; 565 /* 566 * Initialize args struct so we know whether arg was --- 518 unchanged lines hidden (view full) --- 1085 clear_opt(sbi, GC_MERGE); 1086 break; 1087 default: 1088 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", 1089 p); 1090 return -EINVAL; 1091 } 1092 } |
1093default_check: |
|
1093#ifdef CONFIG_QUOTA 1094 if (f2fs_check_quota_options(sbi)) 1095 return -EINVAL; 1096#else 1097 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { 1098 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); 1099 return -EINVAL; 1100 } --- 56 unchanged lines hidden (view full) --- 1157 return -EINVAL; 1158 } 1159 1160 /* Not pass down write hints if the number of active logs is lesser 1161 * than NR_CURSEG_PERSIST_TYPE. 1162 */ 1163 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE) 1164 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; | 1094#ifdef CONFIG_QUOTA 1095 if (f2fs_check_quota_options(sbi)) 1096 return -EINVAL; 1097#else 1098 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { 1099 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); 1100 return -EINVAL; 1101 } --- 56 unchanged lines hidden (view full) --- 1158 return -EINVAL; 1159 } 1160 1161 /* Not pass down write hints if the number of active logs is lesser 1162 * than NR_CURSEG_PERSIST_TYPE. 1163 */ 1164 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE) 1165 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; |
1166 1167 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { 1168 f2fs_err(sbi, "Allow to mount readonly mode only"); 1169 return -EROFS; 1170 } |
|
1165 return 0; 1166} 1167 1168static struct inode *f2fs_alloc_inode(struct super_block *sb) 1169{ 1170 struct f2fs_inode_info *fi; 1171 1172 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO); --- 641 unchanged lines hidden (view full) --- 1814 if (test_opt(sbi, ATGC)) 1815 seq_puts(seq, ",atgc"); 1816 return 0; 1817} 1818 1819static void default_options(struct f2fs_sb_info *sbi) 1820{ 1821 /* init some FS parameters */ | 1171 return 0; 1172} 1173 1174static struct inode *f2fs_alloc_inode(struct super_block *sb) 1175{ 1176 struct f2fs_inode_info *fi; 1177 1178 fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO); --- 641 unchanged lines hidden (view full) --- 1820 if (test_opt(sbi, ATGC)) 1821 seq_puts(seq, ",atgc"); 1822 return 0; 1823} 1824 1825static void default_options(struct f2fs_sb_info *sbi) 1826{ 1827 /* init some FS parameters */ |
1822 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; | 1828 if (f2fs_sb_has_readonly(sbi)) 1829 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; 1830 else 1831 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; 1832 |
1823 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; 1824 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; 1825 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; 1826 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; 1827 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); 1828 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); 1829 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; 1830 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; --- 168 unchanged lines hidden (view full) --- 1999 2000 /* 2001 * Previous and new state of filesystem is RO, 2002 * so skip checking GC and FLUSH_MERGE conditions. 2003 */ 2004 if (f2fs_readonly(sb) && (*flags & SB_RDONLY)) 2005 goto skip; 2006 | 1833 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; 1834 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; 1835 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; 1836 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; 1837 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); 1838 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); 1839 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; 1840 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; --- 168 unchanged lines hidden (view full) --- 2009 2010 /* 2011 * Previous and new state of filesystem is RO, 2012 * so skip checking GC and FLUSH_MERGE conditions. 2013 */ 2014 if (f2fs_readonly(sb) && (*flags & SB_RDONLY)) 2015 goto skip; 2016 |
2017 if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) { 2018 err = -EROFS; 2019 goto restore_opts; 2020 } 2021 |
|
2007#ifdef CONFIG_QUOTA 2008 if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) { 2009 err = dquot_suspend(sb, -1); 2010 if (err < 0) 2011 goto restore_opts; 2012 } else if (f2fs_readonly(sb) && !(*flags & SB_RDONLY)) { 2013 /* dquot_resume needs RW */ 2014 sb->s_flags &= ~SB_RDONLY; --- 1117 unchanged lines hidden (view full) --- 3132 fsmeta += le32_to_cpu(raw_super->segment_count_ssa); 3133 3134 if (unlikely(fsmeta >= total)) 3135 return 1; 3136 3137 ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); 3138 reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); 3139 | 2022#ifdef CONFIG_QUOTA 2023 if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) { 2024 err = dquot_suspend(sb, -1); 2025 if (err < 0) 2026 goto restore_opts; 2027 } else if (f2fs_readonly(sb) && !(*flags & SB_RDONLY)) { 2028 /* dquot_resume needs RW */ 2029 sb->s_flags &= ~SB_RDONLY; --- 1117 unchanged lines hidden (view full) --- 3147 fsmeta += le32_to_cpu(raw_super->segment_count_ssa); 3148 3149 if (unlikely(fsmeta >= total)) 3150 return 1; 3151 3152 ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); 3153 reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); 3154 |
3140 if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS || | 3155 if (!f2fs_sb_has_readonly(sbi) && 3156 unlikely(fsmeta < F2FS_MIN_META_SEGMENTS || |
3141 ovp_segments == 0 || reserved_segments == 0)) { 3142 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); 3143 return 1; 3144 } | 3157 ovp_segments == 0 || reserved_segments == 0)) { 3158 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); 3159 return 1; 3160 } |
3145 | |
3146 user_block_count = le64_to_cpu(ckpt->user_block_count); | 3161 user_block_count = le64_to_cpu(ckpt->user_block_count); |
3147 segment_count_main = le32_to_cpu(raw_super->segment_count_main); | 3162 segment_count_main = le32_to_cpu(raw_super->segment_count_main) + 3163 (f2fs_sb_has_readonly(sbi) ? 1 : 0); |
3148 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); 3149 if (!user_block_count || user_block_count >= 3150 segment_count_main << log_blocks_per_seg) { 3151 f2fs_err(sbi, "Wrong user_block_count: %u", 3152 user_block_count); 3153 return 1; 3154 } 3155 --- 14 unchanged lines hidden (view full) --- 3170 3171 main_segs = le32_to_cpu(raw_super->segment_count_main); 3172 blocks_per_seg = sbi->blocks_per_seg; 3173 3174 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { 3175 if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || 3176 le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) 3177 return 1; | 3164 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); 3165 if (!user_block_count || user_block_count >= 3166 segment_count_main << log_blocks_per_seg) { 3167 f2fs_err(sbi, "Wrong user_block_count: %u", 3168 user_block_count); 3169 return 1; 3170 } 3171 --- 14 unchanged lines hidden (view full) --- 3186 3187 main_segs = le32_to_cpu(raw_super->segment_count_main); 3188 blocks_per_seg = sbi->blocks_per_seg; 3189 3190 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { 3191 if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || 3192 le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) 3193 return 1; |
3194 3195 if (f2fs_sb_has_readonly(sbi)) 3196 goto check_data; 3197 |
|
3178 for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) { 3179 if (le32_to_cpu(ckpt->cur_node_segno[i]) == 3180 le32_to_cpu(ckpt->cur_node_segno[j])) { 3181 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", 3182 i, j, 3183 le32_to_cpu(ckpt->cur_node_segno[i])); 3184 return 1; 3185 } 3186 } 3187 } | 3198 for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) { 3199 if (le32_to_cpu(ckpt->cur_node_segno[i]) == 3200 le32_to_cpu(ckpt->cur_node_segno[j])) { 3201 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", 3202 i, j, 3203 le32_to_cpu(ckpt->cur_node_segno[i])); 3204 return 1; 3205 } 3206 } 3207 } |
3208check_data: |
|
3188 for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { 3189 if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || 3190 le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) 3191 return 1; | 3209 for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { 3210 if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || 3211 le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) 3212 return 1; |
3213 3214 if (f2fs_sb_has_readonly(sbi)) 3215 goto skip_cross; 3216 |
|
3192 for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) { 3193 if (le32_to_cpu(ckpt->cur_data_segno[i]) == 3194 le32_to_cpu(ckpt->cur_data_segno[j])) { 3195 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", 3196 i, j, 3197 le32_to_cpu(ckpt->cur_data_segno[i])); 3198 return 1; 3199 } --- 5 unchanged lines hidden (view full) --- 3205 le32_to_cpu(ckpt->cur_data_segno[j])) { 3206 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", 3207 i, j, 3208 le32_to_cpu(ckpt->cur_node_segno[i])); 3209 return 1; 3210 } 3211 } 3212 } | 3217 for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) { 3218 if (le32_to_cpu(ckpt->cur_data_segno[i]) == 3219 le32_to_cpu(ckpt->cur_data_segno[j])) { 3220 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", 3221 i, j, 3222 le32_to_cpu(ckpt->cur_data_segno[i])); 3223 return 1; 3224 } --- 5 unchanged lines hidden (view full) --- 3230 le32_to_cpu(ckpt->cur_data_segno[j])) { 3231 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", 3232 i, j, 3233 le32_to_cpu(ckpt->cur_node_segno[i])); 3234 return 1; 3235 } 3236 } 3237 } |
3213 | 3238skip_cross: |
3214 sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 3215 nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 3216 3217 if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 || 3218 nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) { 3219 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", 3220 sit_bitmap_size, nat_bitmap_size); 3221 return 1; --- 1104 unchanged lines hidden --- | 3239 sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 3240 nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 3241 3242 if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 || 3243 nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) { 3244 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", 3245 sit_bitmap_size, nat_bitmap_size); 3246 return 1; --- 1104 unchanged lines hidden --- |