All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to set DISCARD opt
@ 2022-11-15 18:40 ` Yangtao Li via Linux-f2fs-devel
  0 siblings, 0 replies; 4+ messages in thread
From: Yangtao Li @ 2022-11-15 18:40 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, 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.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/f2fs.h  |  5 +++++
 fs/f2fs/super.c | 53 +++++++++++++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index b89b5d755ce0..be23059344b4 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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 */
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 75027ff85cd9..baa8f0860192 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -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)) &&
-		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;
+	}
+
 	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))
+			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)) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [f2fs-dev] [PATCH] f2fs: fix to set DISCARD opt
@ 2022-11-15 18:40 ` Yangtao Li via Linux-f2fs-devel
  0 siblings, 0 replies; 4+ messages in thread
From: Yangtao Li via Linux-f2fs-devel @ 2022-11-15 18:40 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Yangtao Li, linux-kernel, linux-f2fs-devel

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.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/f2fs.h  |  5 +++++
 fs/f2fs/super.c | 53 +++++++++++++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index b89b5d755ce0..be23059344b4 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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 */
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 75027ff85cd9..baa8f0860192 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -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)) &&
-		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;
+	}
+
 	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))
+			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)) {
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] f2fs: fix to set DISCARD opt
  2022-11-15 18:40 ` [f2fs-dev] " Yangtao Li via Linux-f2fs-devel
@ 2022-11-23 15:11   ` Chao Yu
  -1 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2022-11-23 15:11 UTC (permalink / raw)
  To: Yangtao Li, jaegeuk; +Cc: linux-f2fs-devel, linux-kernel

On 2022/11/16 2:40, Yangtao Li wrote:
> 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.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>   fs/f2fs/f2fs.h  |  5 +++++
>   fs/f2fs/super.c | 53 +++++++++++++++++++++++++++----------------------
>   2 files changed, 34 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index b89b5d755ce0..be23059344b4 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -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 */
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 75027ff85cd9..baa8f0860192 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -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)) &&
> -		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?

> +
>   	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))
> +			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)) {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix to set DISCARD opt
@ 2022-11-23 15:11   ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2022-11-23 15:11 UTC (permalink / raw)
  To: Yangtao Li, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel

On 2022/11/16 2:40, Yangtao Li wrote:
> 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.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>   fs/f2fs/f2fs.h  |  5 +++++
>   fs/f2fs/super.c | 53 +++++++++++++++++++++++++++----------------------
>   2 files changed, 34 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index b89b5d755ce0..be23059344b4 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -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 */
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 75027ff85cd9..baa8f0860192 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -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)) &&
> -		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?

> +
>   	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))
> +			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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-23 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 18:40 [PATCH] f2fs: fix to set DISCARD opt Yangtao Li
2022-11-15 18:40 ` [f2fs-dev] " Yangtao Li via Linux-f2fs-devel
2022-11-23 15:11 ` Chao Yu
2022-11-23 15:11   ` [f2fs-dev] " Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.