Skip to contentSkip to conversation

f2fs: fix to set DISCARD opt

PATCH In review Yangtao Li 2 participants 2 messages Nov 15, 2022 – Nov 23, 2022 F2FS file system

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 f2fs: fix to set DISCARD opt

Some minor modifications to discard opt and related parameters:

1.introduce f2fs_is_readonly() and use it to simplify code 2.The FLUSH_MERGE opt is set by default only in non-ro mode. 3.When ro and DISCARD are set at the same time, an error is reported. 4.Display discard_unit mount opt when has discard opt. 5.clear DISCARD when remount as ro.

---
 fs/f2fs/f2fs.h  |  5 +++++
 fs/f2fs/super.c | 53 +++++++++++++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 24 deletions(-)
fs/f2fs/f2fs.h +5 -0
index b89b5d755ce0..be23059344b4 100644
@@ -4579,4 +4579,9 @@ static inline void f2fs_handle_page_eio(struct f2fs_sb_info *sbi, pgoff_t ofs,
 #define EFSBADCRC	EBADMSG		/* Bad CRC detected */
 #define EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
 
+static inline bool f2fs_is_readonly(struct f2fs_sb_info *sbi)
+{
+	return !!f2fs_sb_has_readonly(sbi) || f2fs_readonly(sbi->sb);
+}
+
 #endif /* _LINUX_F2FS_H */
fs/f2fs/super.c +29 -24

88 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 37 lines · Yangtao Li

Some minor modifications to discard opt and related parameters:

1.introduce f2fs_is_readonly() and use it to simplify code 2.The FLUSH_MERGE opt is set by default only in non-ro mode. 3.When ro and DISCARD are set at the same time, an error is reported. 4.Display discard_unit mount opt when has discard opt. 5.clear DISCARD when remount as ro.

---
  fs/f2fs/f2fs.h  |  5 +++++
  fs/f2fs/super.c | 53 +++++++++++++++++++++++++++----------------------
  2 files changed, 34 insertions(+), 24 deletions(-)
fs/f2fs/f2fs.h +5 -0
index b89b5d755ce0..be23059344b4 100644
@@ -4579,4 +4579,9 @@ static inline void f2fs_handle_page_eio(struct f2fs_sb_info *sbi, pgoff_t ofs,
  #define EFSBADCRC	EBADMSG		/* Bad CRC detected */
  #define EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
 
+static inline bool f2fs_is_readonly(struct f2fs_sb_info *sbi)
+{
+	return !!f2fs_sb_has_readonly(sbi) || f2fs_readonly(sbi->sb);
+}
+
  #endif /* _LINUX_F2FS_H */
fs/f2fs/super.c +0 -1
index 75027ff85cd9..baa8f0860192 100644
@@ -1353,12 +1353,16 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  		return -EINVAL;
  	}
 
-	if ((f2fs_sb_has_readonly(sbi) || f2fs_readonly(sbi->sb)) &&

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

Quoted 10 lines
fs/f2fs/super.c +5 -1
-		test_opt(sbi, FLUSH_MERGE)) {
+	if (f2fs_is_readonly(sbi) && test_opt(sbi, FLUSH_MERGE)) {
  		f2fs_err(sbi, "FLUSH_MERGE not compatible with readonly mode");
  		return -EINVAL;
  	}
 
+	if (f2fs_is_readonly(sbi) && test_opt(sbi, DISCARD)) {
+		f2fs_err(sbi, "DISCARD not compatible with readonly mode");
+		return -EINVAL;
+	}

Well, it looks ext4 support mounting image w/ both discard and ro option.

And I guess for the case device is rw, and filesystem is ro, it may allow filesystem itself issue command to trim device, and that won't break semantic of readonly filesystem?

Quoted 68 lines
fs/f2fs/super.c +17 -22
+
  	if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) {
  		f2fs_err(sbi, "Allow to mount readonly mode only");
  		return -EROFS;
@@ -2035,12 +2039,14 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
  	if (test_opt(sbi, ATGC))
  		seq_puts(seq, ",atgc");
 
-	if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK)
-		seq_printf(seq, ",discard_unit=%s", "block");
-	else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT)
-		seq_printf(seq, ",discard_unit=%s", "segment");
-	else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
-		seq_printf(seq, ",discard_unit=%s", "section");
+	if (test_opt(sbi, DISCARD)) {
+		if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK)
+			seq_printf(seq, ",discard_unit=%s", "block");
+		else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT)
+			seq_printf(seq, ",discard_unit=%s", "segment");
+		else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
+			seq_printf(seq, ",discard_unit=%s", "section");
+	}
 
  	if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_NORMAL)
  		seq_printf(seq, ",memory=%s", "normal");
@@ -2081,9 +2087,10 @@ static void default_options(struct f2fs_sb_info *sbi)
  	set_opt(sbi, MERGE_CHECKPOINT);
  	F2FS_OPTION(sbi).unusable_cap = 0;
  	sbi->sb->s_flags |= SB_LAZYTIME;
-	if (!f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb))
+	if (!f2fs_is_readonly(sbi))
  		set_opt(sbi, FLUSH_MERGE);
-	if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi))
+	if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
+		!f2fs_is_readonly(sbi))
  		set_opt(sbi, DISCARD);
  	if (f2fs_sb_has_blkzoned(sbi)) {
  		F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
@@ -2221,7 +2228,6 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT);
  	bool no_io_align = !F2FS_IO_ALIGNED(sbi);
  	bool no_atgc = !test_opt(sbi, ATGC);
-	bool no_discard = !test_opt(sbi, DISCARD);
  	bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
  	bool block_unit_discard = f2fs_block_unit_discard(sbi);
  	struct discard_cmd_control *dcc;
@@ -2398,19 +2404,18 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  		need_stop_flush = true;
  	}
 
-	if (no_discard == !!test_opt(sbi, DISCARD)) {
-		if (test_opt(sbi, DISCARD)) {
-			err = f2fs_start_discard_thread(sbi);
-			if (err)
-				goto restore_flush;
-			need_stop_discard = true;
-		} else {
-			dcc = SM_I(sbi)->dcc_info;
-			f2fs_stop_discard_thread(sbi);
-			if (atomic_read(&dcc->discard_cmd_cnt))
-				f2fs_issue_discard_timeout(sbi);
-			need_restart_discard = true;
-		}
+	if ((*flags & SB_RDONLY) || !test_opt(sbi, DISCARD)) {
+		clear_opt(sbi, DISCARD);
+		dcc = SM_I(sbi)->dcc_info;
+		f2fs_stop_discard_thread(sbi);
+		if (atomic_read(&dcc->discard_cmd_cnt))

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

Quoted 10 lines
fs/f2fs/super.c +7 -0
+			f2fs_issue_discard_timeout(sbi);
+		need_restart_discard = true;
+	} else {
+		err = f2fs_start_discard_thread(sbi);
+		if (err)
+			goto restore_flush;
+		need_stop_discard = true;
  	}
 
  	if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) {

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