mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Yangtao Li <frank.li@vivo.com>, jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: fix to set DISCARD opt
Date: Wed, 23 Nov 2022 23:11:55 +0800	[thread overview]
Message-ID: <c8145b2b-f8fa-9065-73dd-497c48a10a46@kernel.org> (raw)
In-Reply-To: <20221115184023.78070-1-frank.li@vivo.com>

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

      reply	other threads:[~2022-11-23 15:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 18:40 Yangtao Li
2022-11-23 15:11 ` Chao Yu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c8145b2b-f8fa-9065-73dd-497c48a10a46@kernel.org \
    --to=chao@kernel.org \
    --cc=frank.li@vivo.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®