All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Jaegeuk Kim <jaegeuk@kernel.org>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH 2/2] f2fs: fix redundant block allocation
Date: Sat, 26 Nov 2016 00:05:33 +0800	[thread overview]
Message-ID: <3253f1bd-e39f-821b-2b4e-5a64deced726@kernel.org> (raw)
In-Reply-To: <20161112013043.8058-2-jaegeuk@kernel.org>

On 2016/11/12 9:30, Jaegeuk Kim wrote:
> In direct_IO path of f2fs_file_write_iter(),
> 1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
>    -> allocate LBA X
> 2. f2fs_direct_IO()
>    -> return 0;
> 
> Then,
> f2fs_write_data_page() will allocate another LBA X+1.
> 
> This makes EIO triggered by HM-SMR.

Good catch, :) how do you find this problem?

> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

> ---
>  fs/f2fs/data.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 2938311..59203a3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
>  	return 0;
>  }
>  
> +static inline bool __force_buffered_io(struct inode *inode, int rw)
> +{
> +	return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
> +			(rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
> +			F2FS_I_SB(inode)->s_ndevs);
> +}
> +
>  int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
>  {
>  	struct inode *inode = file_inode(iocb->ki_filp);
> @@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
>  		err = f2fs_convert_inline_inode(inode);
>  		if (err)
>  			return err;
> -		return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
> +		return f2fs_map_blocks(inode, &map, 1,
> +			__force_buffered_io(inode, WRITE) ?
> +				F2FS_GET_BLOCK_PRE_AIO :
> +				F2FS_GET_BLOCK_PRE_DIO);
>  	}
>  	if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
>  		err = f2fs_convert_inline_inode(inode);
> @@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
>  	if (err)
>  		return err;
>  
> -	if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
> -		return 0;
> -	if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
> -		return 0;
> -	if (F2FS_I_SB(inode)->s_ndevs)
> +	if (__force_buffered_io(inode, rw))
>  		return 0;
>  
>  	trace_f2fs_direct_IO_enter(inode, offset, count, rw);
> 

------------------------------------------------------------------------------

WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: Jaegeuk Kim <jaegeuk@kernel.org>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: fix redundant block allocation
Date: Sat, 26 Nov 2016 00:05:33 +0800	[thread overview]
Message-ID: <3253f1bd-e39f-821b-2b4e-5a64deced726@kernel.org> (raw)
In-Reply-To: <20161112013043.8058-2-jaegeuk@kernel.org>

On 2016/11/12 9:30, Jaegeuk Kim wrote:
> In direct_IO path of f2fs_file_write_iter(),
> 1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
>    -> allocate LBA X
> 2. f2fs_direct_IO()
>    -> return 0;
> 
> Then,
> f2fs_write_data_page() will allocate another LBA X+1.
> 
> This makes EIO triggered by HM-SMR.

Good catch, :) how do you find this problem?

> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

> ---
>  fs/f2fs/data.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 2938311..59203a3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
>  	return 0;
>  }
>  
> +static inline bool __force_buffered_io(struct inode *inode, int rw)
> +{
> +	return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
> +			(rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
> +			F2FS_I_SB(inode)->s_ndevs);
> +}
> +
>  int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
>  {
>  	struct inode *inode = file_inode(iocb->ki_filp);
> @@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
>  		err = f2fs_convert_inline_inode(inode);
>  		if (err)
>  			return err;
> -		return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
> +		return f2fs_map_blocks(inode, &map, 1,
> +			__force_buffered_io(inode, WRITE) ?
> +				F2FS_GET_BLOCK_PRE_AIO :
> +				F2FS_GET_BLOCK_PRE_DIO);
>  	}
>  	if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
>  		err = f2fs_convert_inline_inode(inode);
> @@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
>  	if (err)
>  		return err;
>  
> -	if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
> -		return 0;
> -	if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
> -		return 0;
> -	if (F2FS_I_SB(inode)->s_ndevs)
> +	if (__force_buffered_io(inode, rw))
>  		return 0;
>  
>  	trace_f2fs_direct_IO_enter(inode, offset, count, rw);
> 

  reply	other threads:[~2016-11-25 16:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-12  1:30 [PATCH 1/2] f2fs: use err for f2fs_preallocate_blocks Jaegeuk Kim
2016-11-12  1:30 ` Jaegeuk Kim
2016-11-12  1:30 ` [PATCH 2/2] f2fs: fix redundant block allocation Jaegeuk Kim
2016-11-12  1:30   ` Jaegeuk Kim
2016-11-25 16:05   ` Chao Yu [this message]
2016-11-25 16:05     ` [f2fs-dev] " Chao Yu
2016-11-25 18:16     ` Jaegeuk Kim

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=3253f1bd-e39f-821b-2b4e-5a64deced726@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --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 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.