Skip to content

Commit a7d9fe3

Browse files
author
Jaegeuk Kim
committed
f2fs: support RO feature
Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 833dcd3 commit a7d9fe3

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

fs/f2fs/f2fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
168168
#define F2FS_FEATURE_SB_CHKSUM 0x0800
169169
#define F2FS_FEATURE_CASEFOLD 0x1000
170170
#define F2FS_FEATURE_COMPRESSION 0x2000
171+
#define F2FS_FEATURE_RO 0x4000
171172

172173
#define __F2FS_HAS_FEATURE(raw_super, mask) \
173174
((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -940,6 +941,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
940941
#define NR_CURSEG_DATA_TYPE (3)
941942
#define NR_CURSEG_NODE_TYPE (3)
942943
#define NR_CURSEG_INMEM_TYPE (2)
944+
#define NR_CURSEG_RO_TYPE (2)
943945
#define NR_CURSEG_PERSIST_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
944946
#define NR_CURSEG_TYPE (NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
945947

@@ -4128,6 +4130,7 @@ F2FS_FEATURE_FUNCS(verity, VERITY);
41284130
F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
41294131
F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
41304132
F2FS_FEATURE_FUNCS(compression, COMPRESSION);
4133+
F2FS_FEATURE_FUNCS(readonly, RO);
41314134

41324135
#ifdef CONFIG_BLK_DEV_ZONED
41334136
static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,

fs/f2fs/segment.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
46834683
struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
46844684
unsigned int blkofs = curseg->next_blkoff;
46854685

4686+
if (f2fs_sb_has_readonly(sbi) &&
4687+
i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
4688+
continue;
4689+
46864690
sanity_check_seg_type(sbi, curseg->seg_type);
46874691

46884692
if (f2fs_test_bit(blkofs, se->cur_valid_map))

fs/f2fs/super.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
555555
int ret;
556556

557557
if (!options)
558-
return 0;
558+
goto default_check;
559559

560560
while ((p = strsep(&options, ",")) != NULL) {
561561
int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
10901090
return -EINVAL;
10911091
}
10921092
}
1093+
default_check:
10931094
#ifdef CONFIG_QUOTA
10941095
if (f2fs_check_quota_options(sbi))
10951096
return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
11621163
*/
11631164
if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
11641165
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+
}
11651171
return 0;
11661172
}
11671173

@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
18191825
static void default_options(struct f2fs_sb_info *sbi)
18201826
{
18211827
/* 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+
18231833
F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
18241834
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
18251835
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2004,6 +2014,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
20042014
if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
20052015
goto skip;
20062016

2017+
if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) {
2018+
err = -EROFS;
2019+
goto restore_opts;
2020+
}
2021+
20072022
#ifdef CONFIG_QUOTA
20082023
if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
20092024
err = dquot_suspend(sb, -1);
@@ -3137,14 +3152,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
31373152
ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
31383153
reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
31393154

3140-
if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
3155+
if (!f2fs_sb_has_readonly(sbi) &&
3156+
unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
31413157
ovp_segments == 0 || reserved_segments == 0)) {
31423158
f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
31433159
return 1;
31443160
}
3145-
31463161
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);
31483164
log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
31493165
if (!user_block_count || user_block_count >=
31503166
segment_count_main << log_blocks_per_seg) {
@@ -3175,6 +3191,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
31753191
if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
31763192
le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
31773193
return 1;
3194+
3195+
if (f2fs_sb_has_readonly(sbi))
3196+
goto check_data;
3197+
31783198
for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
31793199
if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
31803200
le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3205,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
31853205
}
31863206
}
31873207
}
3208+
check_data:
31883209
for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
31893210
if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
31903211
le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
31913212
return 1;
3213+
3214+
if (f2fs_sb_has_readonly(sbi))
3215+
goto skip_cross;
3216+
31923217
for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
31933218
if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
31943219
le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3235,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
32103235
}
32113236
}
32123237
}
3213-
3238+
skip_cross:
32143239
sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
32153240
nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
32163241

fs/f2fs/sysfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ static ssize_t features_show(struct f2fs_attr *a,
158158
if (f2fs_sb_has_casefold(sbi))
159159
len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
160160
len ? ", " : "", "casefold");
161+
if (f2fs_sb_has_readonly(sbi))
162+
len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
163+
len ? ", " : "", "readonly");
161164
if (f2fs_sb_has_compression(sbi))
162165
len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
163166
len ? ", " : "", "compression");
@@ -578,6 +581,7 @@ enum feat_id {
578581
FEAT_SB_CHECKSUM,
579582
FEAT_CASEFOLD,
580583
FEAT_COMPRESSION,
584+
FEAT_RO,
581585
FEAT_TEST_DUMMY_ENCRYPTION_V2,
582586
};
583587

@@ -599,6 +603,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
599603
case FEAT_SB_CHECKSUM:
600604
case FEAT_CASEFOLD:
601605
case FEAT_COMPRESSION:
606+
case FEAT_RO:
602607
case FEAT_TEST_DUMMY_ENCRYPTION_V2:
603608
return sprintf(buf, "supported\n");
604609
}
@@ -721,12 +726,14 @@ F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY);
721726
#endif
722727
F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
723728
F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD);
729+
F2FS_FEATURE_RO_ATTR(readonly, FEAT_RO);
724730
#ifdef CONFIG_F2FS_FS_COMPRESSION
725731
F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION);
726732
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
727733
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
728734
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
729735
#endif
736+
730737
/* For ATGC */
731738
F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
732739
F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
@@ -830,6 +837,7 @@ static struct attribute *f2fs_feat_attrs[] = {
830837
#endif
831838
ATTR_LIST(sb_checksum),
832839
ATTR_LIST(casefold),
840+
ATTR_LIST(readonly),
833841
#ifdef CONFIG_F2FS_FS_COMPRESSION
834842
ATTR_LIST(compression),
835843
#endif

0 commit comments

Comments
 (0)