Skip to contentSkip to conversation

f2fs: immutable file can have null address in compressed chunk

PATCH In review Jaegeuk Kim 4 participants 25 messages May 21, 2021 – Jun 4, 2021 F2FS file system

lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/2 f2fs: immutable file can have null address in compressed chunk

If we released compressed blocks having an immutable bit, we can see less number of compressed block addresses. Let's fix wrong BUG_ON.

---
 fs/f2fs/compress.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/compress.c +2 -1
index d4f7371fb0d8..1189740aa141 100644
@@ -927,7 +927,8 @@ static int __f2fs_cluster_blocks(struct inode *inode,
 			}
 		}
 
-		f2fs_bug_on(F2FS_I_SB(inode), !compr && ret != cluster_size);
+		f2fs_bug_on(F2FS_I_SB(inode),
+			!compr && ret != cluster_size && !IS_IMMUTABLE(inode));
 	}
 fail:
 	f2fs_put_dnode(&dn);
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
author maintainer
#1 lore raw

PATCH 2/2 f2fs: support RO feature

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
 fs/f2fs/f2fs.h    |  2 ++
 fs/f2fs/segment.c |  3 +++
 fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
 3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_SB_CHKSUM		0x0800
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
 #define	NR_CURSEG_DATA_TYPE	(3)
 #define NR_CURSEG_NODE_TYPE	(3)
 #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
 #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
 #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +3 -0
index 8668df7870d0..67cec8f858a2 100644
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 {
 	int i;
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		return 0;
+
 	/*
 	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
 	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +31 -4
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 static void default_options(struct f2fs_sb_info *sbi)
 {
 	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
 	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
 	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
 	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	err = parse_options(sb, data, true);
 	if (err)
 		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))
+		goto restore_opts;
+
 	checkpoint_changed =
 			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
 
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
 	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
 	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
 			ovp_segments == 0 || reserved_segments == 0)) {
 		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
 		return 1;
 	}
-
+no_reserved:
 	user_block_count = le64_to_cpu(ckpt->user_block_count);
 	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
 	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >
 			segment_count_main << log_blocks_per_seg) {
 		f2fs_err(sbi, "Wrong user_block_count: %u",
 			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
 		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
 				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
+check_data:
 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
 		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
 		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
 				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
-
+skip_cross:
 	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
 	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	if (err)
 		goto free_options;
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}
+
 	sb->s_maxbytes = max_file_blocks(NULL) <<
 				le32_to_cpu(raw_super->log_blocksize);
 	sb->s_max_links = F2FS_LINK_MAX;
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
#2 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 2 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

Cool, any solution to update files of ro f2fs image if there is such scenario?

Quoted 33 lines
---
  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  3 +++
  fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
  3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4677

Quoted 4 lines
fs/f2fs/segment.c +1 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  {
  	int i;
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))

Why not using F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))?

Ditto for all below __F2FS_HAS_FEATURE().

Thanks,

Quoted 96 lines
fs/f2fs/segment.c +2 -0
+		return 0;
+
  	/*
  	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
  	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +24 -4
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	err = parse_options(sb, data, true);
  	if (err)
  		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))
+		goto restore_opts;
+
  	checkpoint_changed =
  			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
 
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
  	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}
-
+no_reserved:
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
  	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >
  			segment_count_main << log_blocks_per_seg) {
  		f2fs_err(sbi, "Wrong user_block_count: %u",
  			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  	if (err)
  		goto free_options;
 

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent) · line 3735

Quoted 10 lines
fs/f2fs/super.c +7 -0
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}
+
  	sb->s_maxbytes = max_file_blocks(NULL) <<
  				le32_to_cpu(raw_super->log_blocksize);
  	sb->s_max_links = F2FS_LINK_MAX;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#3 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 6 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

Cool, any solution to update files of ro f2fs image if there is such scenario?

Hmm, overlayfs?

Quoted 29 lines
Quoted 29 lines
---
  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  3 +++
  fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
  3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644
Quoted 8 lines

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4676

Quoted 6 lines
fs/f2fs/segment.c +1 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  {
  	int i;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))

Why not using F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))?

Oh, updated.

Quoted 107 lines

Ditto for all below __F2FS_HAS_FEATURE().

Thanks,

Quoted 102 lines
fs/f2fs/segment.c +2 -0
+		return 0;
+
  	/*
  	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
  	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +31 -4
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	err = parse_options(sb, data, true);
  	if (err)
  		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))
+		goto restore_opts;
+
  	checkpoint_changed =
  			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
  	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}
-
+no_reserved:
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
  	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >
  			segment_count_main << log_blocks_per_seg) {
  		f2fs_err(sbi, "Wrong user_block_count: %u",
  			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  	if (err)
  		goto free_options;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}
+
  	sb->s_maxbytes = max_file_blocks(NULL) <<
  				le32_to_cpu(raw_super->log_blocksize);
  	sb->s_max_links = F2FS_LINK_MAX;
 
#4 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

Cool, any solution to update files of ro f2fs image if there is such scenario?

Hmm, overlayfs?

I mean using f2fs-tools, maybe...

Thanks,

Quoted 150 lines
Quoted 30 lines
Quoted 30 lines
---
   fs/f2fs/f2fs.h    |  2 ++
   fs/f2fs/segment.c |  3 +++
   fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
   3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
   #define F2FS_FEATURE_SB_CHKSUM		0x0800
   #define F2FS_FEATURE_CASEFOLD		0x1000
   #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
   #define __F2FS_HAS_FEATURE(raw_super, mask)				\
   	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
   #define	NR_CURSEG_DATA_TYPE	(3)
   #define NR_CURSEG_NODE_TYPE	(3)
   #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
   #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
   #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644
Quoted 8 lines

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4676

Quoted 6 lines
fs/f2fs/segment.c +1 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
   {
   	int i;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))

Why not using F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))?

Oh, updated.

Quoted 99 lines

Ditto for all below __F2FS_HAS_FEATURE().

Thanks,

Quoted 94 lines
fs/f2fs/segment.c +2 -0
+		return 0;
+
   	/*
   	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
   	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +27 -4
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
   static void default_options(struct f2fs_sb_info *sbi)
   {
   	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
   	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
   	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
   	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
   	err = parse_options(sb, data, true);
   	if (err)
   		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))
+		goto restore_opts;
+
   	checkpoint_changed =
   			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
   	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
   	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
   			ovp_segments == 0 || reserved_segments == 0)) {
   		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
   		return 1;
   	}
-
+no_reserved:
   	user_block_count = le64_to_cpu(ckpt->user_block_count);
   	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
   	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >
   			segment_count_main << log_blocks_per_seg) {
   		f2fs_err(sbi, "Wrong user_block_count: %u",
   			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
   		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
   				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
+check_data:
   	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
   		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
   		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
   				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
-
+skip_cross:
   	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
   	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
   	if (err)
   		goto free_options;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
Quoted 8 lines

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent)

Quoted 8 lines
fs/f2fs/super.c +4 -0
+		err = -EINVAL;
+		goto free_options;
+	}
+
   	sb->s_maxbytes = max_file_blocks(NULL) <<
   				le32_to_cpu(raw_super->log_blocksize);
   	sb->s_max_links = F2FS_LINK_MAX;
 

.

author maintainer
#5 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 6 lines · Chao Yu
Quoted 5 lines · Jaegeuk Kim
Quoted 4 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Cool, any solution to update files of ro f2fs image if there is such scenario?

Hmm, overlayfs?

I mean using f2fs-tools, maybe...

sload.f2fs supports it with this patch?

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev&id=9069b6b6f17faa66c8546567882b2e66bc78b8eb

Quoted 153 lines

Thanks,

Quoted 150 lines
Quoted 30 lines
Quoted 30 lines
---
   fs/f2fs/f2fs.h    |  2 ++
   fs/f2fs/segment.c |  3 +++
   fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
   3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
   #define F2FS_FEATURE_SB_CHKSUM		0x0800
   #define F2FS_FEATURE_CASEFOLD		0x1000
   #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
   #define __F2FS_HAS_FEATURE(raw_super, mask)				\
   	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
   #define	NR_CURSEG_DATA_TYPE	(3)
   #define NR_CURSEG_NODE_TYPE	(3)
   #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
   #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
   #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644
Quoted 8 lines

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4676

Quoted 6 lines
fs/f2fs/segment.c +1 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
   {
   	int i;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))

Why not using F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))?

Oh, updated.

Quoted 99 lines

Ditto for all below __F2FS_HAS_FEATURE().

Thanks,

Quoted 94 lines
fs/f2fs/segment.c +2 -0
+		return 0;
+
   	/*
   	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
   	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +27 -4
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
   static void default_options(struct f2fs_sb_info *sbi)
   {
   	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
   	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
   	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
   	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
   	err = parse_options(sb, data, true);
   	if (err)
   		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))
+		goto restore_opts;
+
   	checkpoint_changed =
   			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
   	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
   	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
   			ovp_segments == 0 || reserved_segments == 0)) {
   		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
   		return 1;
   	}
-
+no_reserved:
   	user_block_count = le64_to_cpu(ckpt->user_block_count);
   	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
   	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >
   			segment_count_main << log_blocks_per_seg) {
   		f2fs_err(sbi, "Wrong user_block_count: %u",
   			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
   		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
   				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
+check_data:
   	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
   		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
   		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
   				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
-
+skip_cross:
   	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
   	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
   	if (err)
   		goto free_options;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
Quoted 8 lines

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent)

Quoted 8 lines
fs/f2fs/super.c +4 -0
+		err = -EINVAL;
+		goto free_options;
+	}
+
   	sb->s_maxbytes = max_file_blocks(NULL) <<
   				le32_to_cpu(raw_super->log_blocksize);
   	sb->s_max_links = F2FS_LINK_MAX;
 

.

#6 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

In reply to Jaegeuk Kim
Quoted 35 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  3 +++
  fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
  3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4678

Quoted 5 lines
fs/f2fs/segment.c +2 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  {
  	int i;
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		return 0;

We need to skip this sanity check because .next_blkoff may point to end position of image?

Quoted 22 lines
fs/f2fs/segment.c +1 -0
+
  	/*
  	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
  	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +5 -1
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2003

Quoted 6 lines
fs/f2fs/super.c +3 -0
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	err = parse_options(sb, data, true);
  	if (err)
  		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))

err = -EROFS; ?

Quoted 6 lines
fs/f2fs/super.c +2 -0
+		goto restore_opts;
+
  	checkpoint_changed =
  			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
 

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3155

Quoted 10 lines
fs/f2fs/super.c +2 -0
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
  	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}

Well, why not:

if (!F2FS_HAS_FEATURE(, RO) && unlikely()) {
}

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3160

Quoted 7 lines
fs/f2fs/super.c +2 -2
-
+no_reserved:
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
  	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >

Does this change related to RO feature? if so, let's split condition for RO feature here?

Quoted 40 lines
fs/f2fs/super.c +10 -1
  			segment_count_main << log_blocks_per_seg) {
  		f2fs_err(sbi, "Wrong user_block_count: %u",
  			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent) · line 3731

Quoted 9 lines
fs/f2fs/super.c +6 -0
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  	if (err)
  		goto free_options;
 
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}

How about relocating this to parse_options() like other features did, then we don't need to handle this in both fill_super() and remount()?

Thanks,

Quoted 5 lines
fs/f2fs/super.c +1 -0
+
  	sb->s_maxbytes = max_file_blocks(NULL) <<
  				le32_to_cpu(raw_super->log_blocksize);
  	sb->s_max_links = F2FS_LINK_MAX;
author maintainer
#7 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 33 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  3 +++
  fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
  3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644
Quoted 8 lines

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4677

Quoted 5 lines
fs/f2fs/segment.c +2 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  {
  	int i;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		return 0;

We need to skip this sanity check because .next_blkoff may point to end position of image?

Since we only use hot data and node. Let me check them only.

Quoted 23 lines
Quoted 23 lines
fs/f2fs/segment.c +1 -0
+
  	/*
  	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
  	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +5 -1
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
Quoted 8 lines

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2003

Quoted 6 lines
fs/f2fs/super.c +3 -0
  	err = parse_options(sb, data, true);
  	if (err)
  		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))

err = -EROFS; ?

Done.

Quoted 18 lines
Quoted 6 lines
fs/f2fs/super.c +2 -0
+		goto restore_opts;
+
  	checkpoint_changed =
  			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3154

Quoted 9 lines
fs/f2fs/super.c +2 -0
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
  	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}

Well, why not:

Quoted 2 lines

if (!F2FS_HAS_FEATURE(, RO) && unlikely()) {
}

Done.

Quoted 11 lines

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3160

Quoted 8 lines
fs/f2fs/super.c +2 -2
-
+no_reserved:
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
  	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >

Does this change related to RO feature? if so, let's split condition for RO feature here?

Done.

Quoted 43 lines
Quoted 43 lines
fs/f2fs/super.c +11 -1
  			segment_count_main << log_blocks_per_seg) {
  		f2fs_err(sbi, "Wrong user_block_count: %u",
  			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  	if (err)
  		goto free_options;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
Quoted 8 lines

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent) · line 3731

Quoted 5 lines
fs/f2fs/super.c +5 -0
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}

How about relocating this to parse_options() like other features did, then we don't need to handle this in both fill_super() and remount()?

Done. But not sure what you mean "we don't need to handle both".

Thanks,

Quoted 8 lines

Thanks,

Quoted 5 lines
fs/f2fs/super.c +1 -0
+
  	sb->s_maxbytes = max_file_blocks(NULL) <<
  				le32_to_cpu(raw_super->log_blocksize);
  	sb->s_max_links = F2FS_LINK_MAX;
 
maintainer
#8 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 168 lines · Jaegeuk Kim
Quoted 33 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
   fs/f2fs/f2fs.h    |  2 ++
   fs/f2fs/segment.c |  3 +++
   fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
   3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
   #define F2FS_FEATURE_SB_CHKSUM		0x0800
   #define F2FS_FEATURE_CASEFOLD		0x1000
   #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
   #define __F2FS_HAS_FEATURE(raw_super, mask)				\
   	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
   #define	NR_CURSEG_DATA_TYPE	(3)
   #define NR_CURSEG_NODE_TYPE	(3)
   #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
   #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
   #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644
Quoted 8 lines

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4677

Quoted 5 lines
fs/f2fs/segment.c +2 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
   {
   	int i;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		return 0;

We need to skip this sanity check because .next_blkoff may point to end position of image?

Since we only use hot data and node. Let me check them only.

Quoted 23 lines
Quoted 23 lines
fs/f2fs/segment.c +1 -0
+
   	/*
   	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
   	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +5 -1
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
   static void default_options(struct f2fs_sb_info *sbi)
   {
   	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
   	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
   	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
   	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
Quoted 8 lines

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2003

Quoted 6 lines
fs/f2fs/super.c +3 -0
   	err = parse_options(sb, data, true);
   	if (err)
   		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))

err = -EROFS; ?

Done.

Quoted 18 lines
Quoted 6 lines
fs/f2fs/super.c +2 -0
+		goto restore_opts;
+
   	checkpoint_changed =
   			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3154

Quoted 9 lines
fs/f2fs/super.c +2 -0
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
   	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
   	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
   			ovp_segments == 0 || reserved_segments == 0)) {
   		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
   		return 1;
   	}

Well, why not:

Quoted 2 lines

if (!F2FS_HAS_FEATURE(, RO) && unlikely()) {
}

Done.

Quoted 11 lines

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3160

Quoted 8 lines
fs/f2fs/super.c +2 -2
-
+no_reserved:
   	user_block_count = le64_to_cpu(ckpt->user_block_count);
   	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
   	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >

Does this change related to RO feature? if so, let's split condition for RO feature here?

Done.

Quoted 43 lines
Quoted 43 lines
fs/f2fs/super.c +11 -1
   			segment_count_main << log_blocks_per_seg) {
   		f2fs_err(sbi, "Wrong user_block_count: %u",
   			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
   		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
   				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
+check_data:
   	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
   		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
   		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
   				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
-
+skip_cross:
   	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
   	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
   	if (err)
   		goto free_options;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
Quoted 8 lines

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent) · line 3731

Quoted 5 lines
fs/f2fs/super.c +5 -0
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}

How about relocating this to parse_options() like other features did, then we don't need to handle this in both fill_super() and remount()?

Quoted 1 line

Done. But not sure what you mean "we don't need to handle both".

Oh, I mean both fill_super() and remount() will call parse_options(), so if we want to avoid mounting ro image with rw mountoption, we just need to add one condition check in parse_option().

Thanks,

Quoted 18 lines

Thanks,

Quoted 8 lines

Thanks,

Quoted 5 lines
fs/f2fs/super.c +1 -0
+
   	sb->s_maxbytes = max_file_blocks(NULL) <<
   				le32_to_cpu(raw_super->log_blocksize);
   	sb->s_max_links = F2FS_LINK_MAX;
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#9 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: support RO feature

Quoted 169 lines · Chao Yu
Quoted 168 lines · Jaegeuk Kim
Quoted 33 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
   fs/f2fs/f2fs.h    |  2 ++
   fs/f2fs/segment.c |  3 +++
   fs/f2fs/super.c   | 35 +++++++++++++++++++++++++++++++----
   3 files changed, 36 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +2 -0
index c0bead0df66a..2c6913261586 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
   #define F2FS_FEATURE_SB_CHKSUM		0x0800
   #define F2FS_FEATURE_CASEFOLD		0x1000
   #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
   #define __F2FS_HAS_FEATURE(raw_super, mask)				\
   	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -939,6 +940,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
   #define	NR_CURSEG_DATA_TYPE	(3)
   #define NR_CURSEG_NODE_TYPE	(3)
   #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
   #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
   #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +0 -0
index 8668df7870d0..67cec8f858a2 100644
Quoted 8 lines

fs/f2fs/segment.c static int sanity_check_curseg(struct f2fs_sb_info *sbi) · line 4677

Quoted 5 lines
fs/f2fs/segment.c +2 -0
@@ -4674,6 +4674,9 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
   {
   	int i;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		return 0;

We need to skip this sanity check because .next_blkoff may point to end position of image?

Since we only use hot data and node. Let me check them only.

Quoted 23 lines
Quoted 23 lines
fs/f2fs/segment.c +1 -0
+
   	/*
   	 * In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
   	 * In LFS curseg, all blkaddr after .next_blkoff should be unused.
fs/f2fs/super.c +5 -1
index b29de80ab60e..312bfab54693 100644
@@ -1819,7 +1819,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
   static void default_options(struct f2fs_sb_info *sbi)
   {
   	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
   	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
   	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
   	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -1994,6 +1998,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
Quoted 8 lines

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2003

Quoted 6 lines
fs/f2fs/super.c +3 -0
   	err = parse_options(sb, data, true);
   	if (err)
   		goto restore_opts;
+
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!(*flags & SB_RDONLY))

err = -EROFS; ?

Done.

Quoted 18 lines
Quoted 6 lines
fs/f2fs/super.c +2 -0
+		goto restore_opts;
+
   	checkpoint_changed =
   			disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3154

Quoted 9 lines
fs/f2fs/super.c +2 -0
@@ -3137,16 +3146,18 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
   	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+		goto no_reserved;
   	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
   			ovp_segments == 0 || reserved_segments == 0)) {
   		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
   		return 1;
   	}

Well, why not:

Quoted 2 lines

if (!F2FS_HAS_FEATURE(, RO) && unlikely()) {
}

Done.

Quoted 11 lines

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3160

Quoted 8 lines
fs/f2fs/super.c +2 -2
-
+no_reserved:
   	user_block_count = le64_to_cpu(ckpt->user_block_count);
   	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
   	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
-	if (!user_block_count || user_block_count >=
+	if (!user_block_count || user_block_count >

Does this change related to RO feature? if so, let's split condition for RO feature here?

Done.

Quoted 51 lines
Quoted 40 lines
fs/f2fs/super.c +10 -1
   			segment_count_main << log_blocks_per_seg) {
   		f2fs_err(sbi, "Wrong user_block_count: %u",
   			 user_block_count);
@@ -3175,6 +3186,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto check_data;
+
   		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
   				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3185,10 +3200,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
+check_data:
   	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
   		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO))
+			goto skip_cross;
+
   		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
   				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3210,7 +3230,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
-
+skip_cross:
   	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
   	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent) · line 3730

Quoted 8 lines
fs/f2fs/super.c +6 -0
@@ -3703,6 +3723,13 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
   	if (err)
   		goto free_options;
+	if (__F2FS_HAS_FEATURE(sbi->raw_super, F2FS_FEATURE_RO) &&
+					!f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}

How about relocating this to parse_options() like other features did, then we don't need to handle this in both fill_super() and remount()?

Quoted 5 lines
Quoted 1 line

Done. But not sure what you mean "we don't need to handle both".

Oh, I mean both fill_super() and remount() will call parse_options(), so if we want to avoid mounting ro image with rw mountoption, we just need to add one condition check in parse_option().

1. mount forced mounting ro only.
2. remount needs to check rw mount after parse_options.

Quoted 21 lines

Thanks,

Quoted 18 lines

Thanks,

Quoted 8 lines

Thanks,

Quoted 5 lines
fs/f2fs/super.c +1 -0
+
   	sb->s_maxbytes = max_file_blocks(NULL) <<
   				le32_to_cpu(raw_super->log_blocksize);
   	sb->s_max_links = F2FS_LINK_MAX;
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#10 lore raw

Re: [PATCH 2/2 v2] f2fs: support RO feature

In reply to Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
 fs/f2fs/f2fs.h    |  2 ++
 fs/f2fs/segment.c |  4 ++++
 fs/f2fs/super.c   | 35 ++++++++++++++++++++++++++++++-----
 3 files changed, 36 insertions(+), 5 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_SB_CHKSUM		0x0800
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((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,
 #define	NR_CURSEG_DATA_TYPE	(3)
 #define NR_CURSEG_NODE_TYPE	(3)
 #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
 #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
 #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
 		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
 		sanity_check_seg_type(sbi, curseg->seg_type);
 
 		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +30 -5
index e70aca8f97bd..7769ed789b38 100644
@@ -1162,6 +1162,12 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	 */
 	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
 		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;
+	}
 	return 0;
 }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 static void default_options(struct f2fs_sb_info *sbi)
 {
 	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
 	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
 	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
 	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
 		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
 #ifdef CONFIG_QUOTA
 	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
 		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
 	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
 			ovp_segments == 0 || reserved_segments == 0)) {
 		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
 		return 1;
 	}
-
 	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0;
 	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
 			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
 		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
 				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
+check_data:
 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
 		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
 		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
 				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
-
+skip_cross:
 	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
 	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
Signature · 1 line
2.32.0.rc0.204.g9fa02ecfa5-goog
author maintainer
#11 lore raw

Re: [f2fs-dev] [PATCH 2/2 v2] f2fs: support RO feature

Quoted 50 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
 fs/f2fs/f2fs.h    |  2 ++
 fs/f2fs/segment.c |  4 ++++
 fs/f2fs/super.c   | 35 ++++++++++++++++++++++++++++++-----
 3 files changed, 36 insertions(+), 5 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_SB_CHKSUM		0x0800
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((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,
 #define	NR_CURSEG_DATA_TYPE	(3)
 #define NR_CURSEG_NODE_TYPE	(3)
 #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
 #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
 #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
 		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
 		sanity_check_seg_type(sbi, curseg->seg_type);
 
 		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +0 -0
index e70aca8f97bd..7769ed789b38 100644

fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1169

Quoted 8 lines
fs/f2fs/super.c +5 -0
@@ -1162,6 +1162,12 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	 */
 	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
 		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_info(sbi, "Allow to mount readonly mode only");
+		err = -EINVAL;
+		goto free_options;

Fixed:

       if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
               f2fs_err(sbi, "Allow to mount readonly mode only");
               return EINVAL;
       }
Quoted 93 lines
fs/f2fs/super.c +25 -5
+	}
 	return 0;
 }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 static void default_options(struct f2fs_sb_info *sbi)
 {
 	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
 	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
 	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
 	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
 		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
 #ifdef CONFIG_QUOTA
 	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
 		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
 	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
 			ovp_segments == 0 || reserved_segments == 0)) {
 		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
 		return 1;
 	}
-
 	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0;
 	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
 			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
 		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
 				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
+check_data:
 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
 		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
 		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
 				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
-
+skip_cross:
 	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
 	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
Signature · 8 lines
2.32.0.rc0.204.g9fa02ecfa5-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
author maintainer
#12 lore raw

Re: [f2fs-dev] [PATCH 2/2 v3] f2fs: support RO feature

In reply to Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
Change log from v2:
- allow curseg updates
- fix some bugs

 fs/f2fs/f2fs.h    |  2 ++
 fs/f2fs/segment.c |  4 ++++
 fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
 3 files changed, 37 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_SB_CHKSUM		0x0800
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((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,
 #define	NR_CURSEG_DATA_TYPE	(3)
 #define NR_CURSEG_NODE_TYPE	(3)
 #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
 #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
 #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
 		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
 		sanity_check_seg_type(sbi, curseg->seg_type);
 
 		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +31 -6
index e70aca8f97bd..6788e7b71e27 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	int ret;
 
 	if (!options)
-		return 0;
+		goto default_check;
 
 	while ((p = strsep(&options, ",")) != NULL) {
 		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 			return -EINVAL;
 		}
 	}
+default_check:
 #ifdef CONFIG_QUOTA
 	if (f2fs_check_quota_options(sbi))
 		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	 */
 	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
 		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
 	return 0;
 }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 static void default_options(struct f2fs_sb_info *sbi)
 {
 	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
 	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
 	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
 	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
 		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
 #ifdef CONFIG_QUOTA
 	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
 		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
 	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
 			ovp_segments == 0 || reserved_segments == 0)) {
 		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
 		return 1;
 	}
-
 	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
 	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
 			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
 		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
 				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
+check_data:
 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
 		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
 		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
 				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
-
+skip_cross:
 	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
 	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
Signature · 1 line
2.32.0.rc0.204.g9fa02ecfa5-goog
#13 lore raw

Re: [f2fs-dev] [PATCH 2/2 v3] f2fs: support RO feature

Quoted 96 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
Change log from v2:
- allow curseg updates
- fix some bugs

  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  4 ++++
  fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
  3 files changed, 37 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((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,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
  		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
  		sanity_check_seg_type(sbi, curseg->seg_type);
 
  		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +12 -2
index e70aca8f97bd..6788e7b71e27 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	int ret;
 
  	if (!options)
-		return 0;
+		goto default_check;
 
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  			return -EINVAL;
  		}
  	}
+default_check:
  #ifdef CONFIG_QUOTA
  	if (f2fs_check_quota_options(sbi))
  		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	 */
  	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
  		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
  	return 0;
  }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2017

Quoted 7 lines
fs/f2fs/super.c +4 -0
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
  		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}

remount() -> parse_options() will fail due to below check, so it doesn't need to check again? Am I missing something?

@@ -1162,6 +1163,11 @@

static int parse_options(struct super_block *sb, char *options, bool is_remount)

*/
if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+ if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+ f2fs_err(sbi, "Allow to mount readonly mode only");
+ return -EROFS;
+ }
return 0;
}

Thanks,

Quoted 60 lines
fs/f2fs/super.c +15 -4
+
  #ifdef CONFIG_QUOTA
  	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
  		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}
-
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  	if (!user_block_count || user_block_count >=
  			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
author maintainer
#14 lore raw

Re: [f2fs-dev] [PATCH 2/2 v3] f2fs: support RO feature

Quoted 91 lines · Chao Yu
Quoted 90 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
Change log from v2:
- allow curseg updates
- fix some bugs

  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  4 ++++
  fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
  3 files changed, 37 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((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,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
  		unsigned int blkofs = curseg->next_blkoff;
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
  		sanity_check_seg_type(sbi, curseg->seg_type);
  		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +12 -2
index e70aca8f97bd..6788e7b71e27 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	int ret;
  	if (!options)
-		return 0;
+		goto default_check;
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  			return -EINVAL;
  		}
  	}
+default_check:
  #ifdef CONFIG_QUOTA
  	if (f2fs_check_quota_options(sbi))
  		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	 */
  	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
  		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
  	return 0;
  }
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
Quoted 8 lines

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2017

Quoted 5 lines
fs/f2fs/super.c +4 -0
  		goto skip;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}

remount() -> parse_options() will fail due to below check, so it doesn't need to check again? Am I missing something?

We haven't changed sb->ro at this point yet.

Quoted 76 lines
fs/f2fs/super.c +5 -0
@@ -1162,6 +1163,11 @@
 
 static int parse_options(struct super_block *sb, char *options, bool is_remount)
 
 	 */
 	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
 		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}

return 0;
}

Thanks,

Quoted 58 lines
fs/f2fs/super.c +15 -4
+
  #ifdef CONFIG_QUOTA
  	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
  		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}
-
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  	if (!user_block_count || user_block_count >=
  			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
#15 lore raw

Re: [f2fs-dev] [PATCH 2/2 v3] f2fs: support RO feature

Quoted 101 lines · Jaegeuk Kim
Quoted 91 lines · Chao Yu
Quoted 90 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
Change log from v2:
- allow curseg updates
- fix some bugs

   fs/f2fs/f2fs.h    |  2 ++
   fs/f2fs/segment.c |  4 ++++
   fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
   3 files changed, 37 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
   #define F2FS_FEATURE_SB_CHKSUM		0x0800
   #define F2FS_FEATURE_CASEFOLD		0x1000
   #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
   #define __F2FS_HAS_FEATURE(raw_super, mask)				\
   	((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,
   #define	NR_CURSEG_DATA_TYPE	(3)
   #define NR_CURSEG_NODE_TYPE	(3)
   #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
   #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
   #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
   		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
   		unsigned int blkofs = curseg->next_blkoff;
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
   		sanity_check_seg_type(sbi, curseg->seg_type);
   		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +12 -2
index e70aca8f97bd..6788e7b71e27 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
   	int ret;
   	if (!options)
-		return 0;
+		goto default_check;
   	while ((p = strsep(&options, ",")) != NULL) {
   		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
   			return -EINVAL;
   		}
   	}
+default_check:
   #ifdef CONFIG_QUOTA
   	if (f2fs_check_quota_options(sbi))
   		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
   	 */
   	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
   		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
   	return 0;
   }
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
   static void default_options(struct f2fs_sb_info *sbi)
   {
   	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
   	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
   	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
   	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
   	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
Quoted 8 lines

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2017

Quoted 5 lines
fs/f2fs/super.c +4 -0
   		goto skip;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}

remount() -> parse_options() will fail due to below check, so it doesn't need to check again? Am I missing something?

Quoted 1 line

We haven't changed sb->ro at this point yet.

Correct.

Thanks,

Quoted 79 lines
Quoted 69 lines
fs/f2fs/super.c +5 -0
@@ -1162,6 +1163,11 @@
 
  static int parse_options(struct super_block *sb, char *options, bool is_remount)
 
  	 */
  	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
  		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
  	return 0;
  }

Thanks,

Quoted 50 lines
fs/f2fs/super.c +14 -3
+
   #ifdef CONFIG_QUOTA
   	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
   		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
   	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
   			ovp_segments == 0 || reserved_segments == 0)) {
   		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
   		return 1;
   	}
-
   	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
   	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
   	if (!user_block_count || user_block_count >=
   			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
   		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
   				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
   			}
   		}
   	}
+check_data:
   	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
   		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
   			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
   			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
   		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
   			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
   				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
Quoted 8 lines

fs/f2fs/super.c int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 3238

Quoted 8 lines
fs/f2fs/super.c +1 -1
   			}
   		}
   	}
-
+skip_cross:
   	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
   	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 

.

maintainer
#16 lore raw

Re: [f2fs-dev] [PATCH 2/2 v3] f2fs: support RO feature

In reply to Jaegeuk Kim
Quoted 2 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

It needs to update below two sysfs entries for RO feature? /sys/fs/f2fs/<device>/features /sys/fs/f2fs/features/..

Thanks,

Quoted 161 lines

---
Change log from v2:
- allow curseg updates
- fix some bugs

  fs/f2fs/f2fs.h    |  2 ++
  fs/f2fs/segment.c |  4 ++++
  fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
  3 files changed, 37 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..9ad502f92529 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((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,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
fs/f2fs/segment.c +4 -0
index 8668df7870d0..02e0c38be7eb 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
  		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
  		sanity_check_seg_type(sbi, curseg->seg_type);
 
  		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +31 -6
index e70aca8f97bd..6788e7b71e27 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	int ret;
 
  	if (!options)
-		return 0;
+		goto default_check;
 
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  			return -EINVAL;
  		}
  	}
+default_check:
  #ifdef CONFIG_QUOTA
  	if (f2fs_check_quota_options(sbi))
  		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	 */
  	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
  		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
  	return 0;
  }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
  		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
  #ifdef CONFIG_QUOTA
  	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
  		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}
-
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  	if (!user_block_count || user_block_count >=
  			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
author maintainer
#17 lore raw

Re: [f2fs-dev] [PATCH 2/2 v4] f2fs: support RO feature

In reply to Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---

Change log from v3:
- add feature sysfs entries

 fs/f2fs/f2fs.h    |  3 +++
 fs/f2fs/segment.c |  4 ++++
 fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
 fs/f2fs/sysfs.c   |  8 ++++++++
 4 files changed, 46 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +3 -0
index eaf57b5f3c4b..8903c43091f8 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_SB_CHKSUM		0x0800
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((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,
 #define	NR_CURSEG_DATA_TYPE	(3)
 #define NR_CURSEG_NODE_TYPE	(3)
 #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
 #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
 #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
@@ -4128,6 +4130,7 @@ F2FS_FEATURE_FUNCS(verity, VERITY);
 F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
 F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
 F2FS_FEATURE_FUNCS(compression, COMPRESSION);
+F2FS_FEATURE_FUNCS(readonly, RO);
 
 #ifdef CONFIG_BLK_DEV_ZONED
 static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
fs/f2fs/segment.c +4 -0
index 380ef34e1a59..376c33ab71e2 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
 		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
 		sanity_check_seg_type(sbi, curseg->seg_type);
 
 		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +31 -6
index 2fa59c674cd9..fb490383c767 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	int ret;
 
 	if (!options)
-		return 0;
+		goto default_check;
 
 	while ((p = strsep(&options, ",")) != NULL) {
 		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 			return -EINVAL;
 		}
 	}
+default_check:
 #ifdef CONFIG_QUOTA
 	if (f2fs_check_quota_options(sbi))
 		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	 */
 	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
 		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
 	return 0;
 }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 static void default_options(struct f2fs_sb_info *sbi)
 {
 	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
 	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
 	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
 	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
 		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
 #ifdef CONFIG_QUOTA
 	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
 		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
 	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
 			ovp_segments == 0 || reserved_segments == 0)) {
 		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
 		return 1;
 	}
-
 	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
 	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
 			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
 		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
 				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
+check_data:
 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
 		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
 		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
 				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
-
+skip_cross:
 	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
 	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
fs/f2fs/sysfs.c +8 -0
index 09e3f258eb52..62fbe4f20dd6 100644
@@ -158,6 +158,9 @@ static ssize_t features_show(struct f2fs_attr *a,
 	if (f2fs_sb_has_casefold(sbi))
 		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
 				len ? ", " : "", "casefold");
+	if (f2fs_sb_has_readonly(sbi))
+		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
+				len ? ", " : "", "readonly");
 	if (f2fs_sb_has_compression(sbi))
 		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
 				len ? ", " : "", "compression");
@@ -578,6 +581,7 @@ enum feat_id {
 	FEAT_SB_CHECKSUM,
 	FEAT_CASEFOLD,
 	FEAT_COMPRESSION,
+	FEAT_RO,
 	FEAT_TEST_DUMMY_ENCRYPTION_V2,
 };
 
@@ -599,6 +603,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
 	case FEAT_SB_CHECKSUM:
 	case FEAT_CASEFOLD:
 	case FEAT_COMPRESSION:
+	case FEAT_RO:
 	case FEAT_TEST_DUMMY_ENCRYPTION_V2:
 		return sprintf(buf, "supported\n");
 	}
@@ -723,12 +728,14 @@ F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
 #ifdef CONFIG_UNICODE
 F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD);
 #endif
+F2FS_FEATURE_RO_ATTR(readonly, FEAT_RO);
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
 #endif
+
 /* For ATGC */
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
@@ -834,6 +841,7 @@ static struct attribute *f2fs_feat_attrs[] = {
 #ifdef CONFIG_UNICODE
 	ATTR_LIST(casefold),
 #endif
+	ATTR_LIST(readonly),
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	ATTR_LIST(compression),
 #endif
Signature · 1 line
2.32.0.rc0.204.g9fa02ecfa5-goog
maintainer
#18 lore raw

Re: [f2fs-dev] [PATCH 2/2 v4] f2fs: support RO feature

Quoted 36 lines · Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---

Change log from v3:
- add feature sysfs entries

  fs/f2fs/f2fs.h    |  3 +++
  fs/f2fs/segment.c |  4 ++++
  fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
  fs/f2fs/sysfs.c   |  8 ++++++++
  4 files changed, 46 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
index eaf57b5f3c4b..8903c43091f8 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_SB_CHKSUM		0x0800
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((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,
  #define	NR_CURSEG_DATA_TYPE	(3)
  #define NR_CURSEG_NODE_TYPE	(3)
  #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
  #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 

fs/f2fs/f2fs.h F2FS_FEATURE_FUNCS(verity, VERITY); · line 4133

Quoted 4 lines
fs/f2fs/f2fs.h +1 -0
@@ -4128,6 +4130,7 @@ F2FS_FEATURE_FUNCS(verity, VERITY);
  F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
  F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
  F2FS_FEATURE_FUNCS(compression, COMPRESSION);
+F2FS_FEATURE_FUNCS(readonly, RO);

If so, we'd better to use f2fs_sb_has_readonly() instead of F2FS_HAS_FEATURE()?

Thanks,

Quoted 185 lines
fs/f2fs/f2fs.h +0 -0
  #ifdef CONFIG_BLK_DEV_ZONED
  static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
fs/f2fs/segment.c +4 -0
index 380ef34e1a59..376c33ab71e2 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
  		unsigned int blkofs = curseg->next_blkoff;
 
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
  		sanity_check_seg_type(sbi, curseg->seg_type);
 
  		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +31 -6
index 2fa59c674cd9..fb490383c767 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	int ret;
 
  	if (!options)
-		return 0;
+		goto default_check;
 
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  			return -EINVAL;
  		}
  	}
+default_check:
  #ifdef CONFIG_QUOTA
  	if (f2fs_check_quota_options(sbi))
  		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	 */
  	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
  		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
  	return 0;
  }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  static void default_options(struct f2fs_sb_info *sbi)
  {
  	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
  	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
  	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
  	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
  		goto skip;
 
+	if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
  #ifdef CONFIG_QUOTA
  	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
  		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
  	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
  			ovp_segments == 0 || reserved_segments == 0)) {
  		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
  		return 1;
  	}
-
  	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0);
  	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
  	if (!user_block_count || user_block_count >=
  			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto check_data;
+
  		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
  				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
+check_data:
  	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
  		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
  			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
  			return 1;
+
+		if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO))
+			goto skip_cross;
+
  		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
  			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
  				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
  			}
  		}
  	}
-
+skip_cross:
  	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
fs/f2fs/sysfs.c +8 -0
index 09e3f258eb52..62fbe4f20dd6 100644
@@ -158,6 +158,9 @@ static ssize_t features_show(struct f2fs_attr *a,
  	if (f2fs_sb_has_casefold(sbi))
  		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
  				len ? ", " : "", "casefold");
+	if (f2fs_sb_has_readonly(sbi))
+		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
+				len ? ", " : "", "readonly");
  	if (f2fs_sb_has_compression(sbi))
  		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
  				len ? ", " : "", "compression");
@@ -578,6 +581,7 @@ enum feat_id {
  	FEAT_SB_CHECKSUM,
  	FEAT_CASEFOLD,
  	FEAT_COMPRESSION,
+	FEAT_RO,
  	FEAT_TEST_DUMMY_ENCRYPTION_V2,
  };
 
@@ -599,6 +603,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
  	case FEAT_SB_CHECKSUM:
  	case FEAT_CASEFOLD:
  	case FEAT_COMPRESSION:
+	case FEAT_RO:
  	case FEAT_TEST_DUMMY_ENCRYPTION_V2:
  		return sprintf(buf, "supported\n");
  	}
@@ -723,12 +728,14 @@ F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
  #ifdef CONFIG_UNICODE
  F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD);
  #endif
+F2FS_FEATURE_RO_ATTR(readonly, FEAT_RO);
  #ifdef CONFIG_F2FS_FS_COMPRESSION
  F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION);
  F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
  F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
  F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
  #endif
+
  /* For ATGC */
  F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
  F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
@@ -834,6 +841,7 @@ static struct attribute *f2fs_feat_attrs[] = {
  #ifdef CONFIG_UNICODE
  	ATTR_LIST(casefold),
  #endif
+	ATTR_LIST(readonly),
  #ifdef CONFIG_F2FS_FS_COMPRESSION
  	ATTR_LIST(compression),
  #endif
author maintainer
#19 lore raw

Re: [f2fs-dev] [PATCH 2/2 v5] f2fs: support RO feature

In reply to Jaegeuk Kim

Given RO feature in superblock, we don't need to check provisioning/reserve spaces and SSA area.

---
Change log from v4:
- use f2fs_sb_has_readonly

 fs/f2fs/f2fs.h    |  3 +++
 fs/f2fs/segment.c |  4 ++++
 fs/f2fs/super.c   | 37 +++++++++++++++++++++++++++++++------
 fs/f2fs/sysfs.c   |  8 ++++++++
 4 files changed, 46 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +3 -0
index eaf57b5f3c4b..8903c43091f8 100644
@@ -168,6 +168,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_SB_CHKSUM		0x0800
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
+#define F2FS_FEATURE_RO			0x4000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((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,
 #define	NR_CURSEG_DATA_TYPE	(3)
 #define NR_CURSEG_NODE_TYPE	(3)
 #define NR_CURSEG_INMEM_TYPE	(2)
+#define NR_CURSEG_RO_TYPE	(2)
 #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
 #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
 
@@ -4128,6 +4130,7 @@ F2FS_FEATURE_FUNCS(verity, VERITY);
 F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
 F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
 F2FS_FEATURE_FUNCS(compression, COMPRESSION);
+F2FS_FEATURE_FUNCS(readonly, RO);
 
 #ifdef CONFIG_BLK_DEV_ZONED
 static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
fs/f2fs/segment.c +4 -0
index 380ef34e1a59..54847eebc5ca 100644
@@ -4683,6 +4683,10 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 		struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
 		unsigned int blkofs = curseg->next_blkoff;
 
+		if (f2fs_sb_has_readonly(sbi) &&
+			i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
+			continue;
+
 		sanity_check_seg_type(sbi, curseg->seg_type);
 
 		if (f2fs_test_bit(blkofs, se->cur_valid_map))
fs/f2fs/super.c +31 -6
index 2fa59c674cd9..df8ac902886d 100644
@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	int ret;
 
 	if (!options)
-		return 0;
+		goto default_check;
 
 	while ((p = strsep(&options, ",")) != NULL) {
 		int token;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 			return -EINVAL;
 		}
 	}
+default_check:
 #ifdef CONFIG_QUOTA
 	if (f2fs_check_quota_options(sbi))
 		return -EINVAL;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 	 */
 	if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
 		F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
+
+	if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) {
+		f2fs_err(sbi, "Allow to mount readonly mode only");
+		return -EROFS;
+	}
 	return 0;
 }
 
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 static void default_options(struct f2fs_sb_info *sbi)
 {
 	/* init some FS parameters */
-	F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+	if (f2fs_sb_has_readonly(sbi))
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
+	else
+		F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
+
 	F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
 	F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
 	F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
@@ -2001,6 +2011,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
 		goto skip;
 
+	if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) {
+		err = -EROFS;
+		goto restore_opts;
+	}
+
 #ifdef CONFIG_QUOTA
 	if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
 		err = dquot_suspend(sb, -1);
@@ -3134,14 +3149,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
 	reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
 
-	if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
+	if (!f2fs_sb_has_readonly(sbi) &&
+			unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
 			ovp_segments == 0 || reserved_segments == 0)) {
 		f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
 		return 1;
 	}
-
 	user_block_count = le64_to_cpu(ckpt->user_block_count);
-	segment_count_main = le32_to_cpu(raw_super->segment_count_main);
+	segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
+			(f2fs_sb_has_readonly(sbi) ? 1 : 0);
 	log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
 			segment_count_main << log_blocks_per_seg) {
@@ -3172,6 +3188,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 		if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (f2fs_sb_has_readonly(sbi))
+			goto check_data;
+
 		for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
 				le32_to_cpu(ckpt->cur_node_segno[j])) {
@@ -3182,10 +3202,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
+check_data:
 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
 		if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
 			le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
 			return 1;
+
+		if (f2fs_sb_has_readonly(sbi))
+			goto skip_cross;
+
 		for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
 			if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
 				le32_to_cpu(ckpt->cur_data_segno[j])) {
@@ -3207,7 +3232,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 			}
 		}
 	}
-
+skip_cross:
 	sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
 	nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
 
fs/f2fs/sysfs.c +8 -0
index dc71bc968c72..c579d5d3a916 100644
@@ -158,6 +158,9 @@ static ssize_t features_show(struct f2fs_attr *a,
 	if (f2fs_sb_has_casefold(sbi))
 		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
 				len ? ", " : "", "casefold");
+	if (f2fs_sb_has_readonly(sbi))
+		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
+				len ? ", " : "", "readonly");
 	if (f2fs_sb_has_compression(sbi))
 		len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
 				len ? ", " : "", "compression");
@@ -578,6 +581,7 @@ enum feat_id {
 	FEAT_SB_CHECKSUM,
 	FEAT_CASEFOLD,
 	FEAT_COMPRESSION,
+	FEAT_RO,
 	FEAT_TEST_DUMMY_ENCRYPTION_V2,
 };
 
@@ -599,6 +603,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
 	case FEAT_SB_CHECKSUM:
 	case FEAT_CASEFOLD:
 	case FEAT_COMPRESSION:
+	case FEAT_RO:
 	case FEAT_TEST_DUMMY_ENCRYPTION_V2:
 		return sprintf(buf, "supported\n");
 	}
@@ -721,12 +726,14 @@ F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY);
 #endif
 F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
 F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD);
+F2FS_FEATURE_RO_ATTR(readonly, FEAT_RO);
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
 #endif
+
 /* For ATGC */
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
@@ -830,6 +837,7 @@ static struct attribute *f2fs_feat_attrs[] = {
 #endif
 	ATTR_LIST(sb_checksum),
 	ATTR_LIST(casefold),
+	ATTR_LIST(readonly),
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	ATTR_LIST(compression),
 #endif
Signature · 1 line
2.32.0.rc0.204.g9fa02ecfa5-goog
#21 lore raw

Re: [PATCH 2/2 v2] f2fs: support RO feature

In reply to Jaegeuk Kim
I love your patch! Yet something to improve:

Hi Jaegeuk,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.13-rc3]
[cannot apply to f2fs/dev-test next-20210526]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jaegeuk-Kim/Re-PATCH-2-2-v2-f2fs-support-RO-feature/20210526-220009
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git dd860052c99b1e088352bdd4fb7aef46f8d2ef47
config: i386-randconfig-m021-20210526 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/7c8442f8e27347c3c91ad75db2961cd58b7c8c62
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Jaegeuk-Kim/Re-PATCH-2-2-v2-f2fs-support-RO-feature/20210526-220009
        git checkout 7c8442f8e27347c3c91ad75db2961cd58b7c8c62
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

fs/f2fs/super.c: In function 'parse_options':

>> fs/f2fs/super.c:1168:3: error: 'err' undeclared (first use in this function)
    1168 |   err = -EINVAL;
         |   ^~~
   fs/f2fs/super.c:1168:3: note: each undeclared identifier is reported only once for each function it appears in
>> fs/f2fs/super.c:1169:3: error: label 'free_options' used but not defined
    1169 |   goto free_options;
         |   ^~~~

vim +/err +1168 fs/f2fs/super.c

1124
1125 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
1126 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
1127 F2FS_IO_SIZE_KB(sbi));
1128 return -EINVAL;
1129 }
1130
1131 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
1132 int min_size, max_size;
1133
1134 if (!f2fs_sb_has_extra_attr(sbi) ||
1135 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
1136 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
1137 return -EINVAL;
1138 }
1139 if (!test_opt(sbi, INLINE_XATTR)) {
1140 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
1141 return -EINVAL;
1142 }
1143
1144 min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32);
1145 max_size = MAX_INLINE_XATTR_SIZE;
1146
1147 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
1148 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
1149 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
1150 min_size, max_size);
1151 return -EINVAL;
1152 }
1153 }
1154
1155 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
1156 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
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;
1165
1166 if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
1167 f2fs_info(sbi, "Allow to mount readonly mode only");

> 1168			err = -EINVAL;
> 1169			goto free_options;

1170 }
1171 return 0;
1172 }
1173

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#22 lore raw

Re: [PATCH 2/2 v2] f2fs: support RO feature

In reply to Jaegeuk Kim
I love your patch! Yet something to improve:

Hi Jaegeuk,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.13-rc3]
[cannot apply to f2fs/dev-test next-20210526]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jaegeuk-Kim/Re-PATCH-2-2-v2-f2fs-support-RO-feature/20210526-220009
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git dd860052c99b1e088352bdd4fb7aef46f8d2ef47
config: powerpc-randconfig-r013-20210526 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 99155e913e9bad5f7f8a247f8bb3a3ff3da74af1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/0day-ci/linux/commit/7c8442f8e27347c3c91ad75db2961cd58b7c8c62
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jaegeuk-Kim/Re-PATCH-2-2-v2-f2fs-support-RO-feature/20210526-220009 git checkout 7c8442f8e27347c3c91ad75db2961cd58b7c8c62
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

>> fs/f2fs/super.c:1168:3: error: use of undeclared identifier 'err'
                   err = -EINVAL;
                   ^
>> fs/f2fs/super.c:1169:8: error: use of undeclared label 'free_options'
                   goto free_options;
                        ^
>> fs/f2fs/super.c:3163:43: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Wparentheses]
                           F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0;
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
   fs/f2fs/super.c:3163:43: note: place parentheses around the '+' expression to silence this warning
                           F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0;
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
   fs/f2fs/super.c:3163:43: note: place parentheses around the '?:' expression to evaluate it first
                           F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) ? 1 : 0;
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~

1 warning and 2 errors generated.

vim +/err +1168 fs/f2fs/super.c

1124
1125 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
1126 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
1127 F2FS_IO_SIZE_KB(sbi));
1128 return -EINVAL;
1129 }
1130
1131 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
1132 int min_size, max_size;
1133
1134 if (!f2fs_sb_has_extra_attr(sbi) ||
1135 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
1136 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
1137 return -EINVAL;
1138 }
1139 if (!test_opt(sbi, INLINE_XATTR)) {
1140 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
1141 return -EINVAL;
1142 }
1143
1144 min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32);
1145 max_size = MAX_INLINE_XATTR_SIZE;
1146
1147 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
1148 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
1149 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
1150 min_size, max_size);
1151 return -EINVAL;
1152 }
1153 }
1154
1155 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
1156 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
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;
1165
1166 if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_RO) && !f2fs_readonly(sbi->sb)) {
1167 f2fs_info(sbi, "Allow to mount readonly mode only");

> 1168			err = -EINVAL;
> 1169			goto free_options;

1170 }
1171 return 0;
1172 }
1173

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#24 lore raw
Quoted 8 lines · Chao Yu
Quoted 4 lines · Jaegeuk Kim

If we released compressed blocks having an immutable bit, we can see less number of compressed block addresses. Let's fix wrong BUG_ON.

It looks it will be better to merge this into ("f2fs: compress: remove unneeded preallocation")?

Right, fixed there. :)

Quoted 4 lines

Thanks,