From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: compress: fix to cover f2fs_disable_compressed_file() w/ i_sem
Date: Tue, 16 Jan 2024 10:29:23 -0800 [thread overview]
Message-ID: <ZabLA4EWNzNFGb5Q@google.com> (raw)
In-Reply-To: <20240111064406.2970205-1-chao@kernel.org>
On 01/11, Chao Yu wrote:
> - f2fs_disable_compressed_file
> - check inode_has_data
> - f2fs_file_mmap
> - mkwrite
> - f2fs_get_block_locked
> : update metadata in compressed
> inode's disk layout
> - fi->i_flags &= ~F2FS_COMPR_FL
> - clear_inode_flag(inode, FI_COMPRESSED_FILE);
>
> we should use i_sem lock to prevent above race case.
>
> Meanwhile, this patch adds i_size check to restrict compress inode
> conversion condition.
Sorry, what was the reason to check i_size?
>
> Fixes: 4c8ff7095bef ("f2fs: support data compression")
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> fs/f2fs/f2fs.h | 18 ++++++++++++++++--
> fs/f2fs/file.c | 5 ++---
> 2 files changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 74729db0b381..e2e0ca45f881 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -4406,19 +4406,33 @@ static inline int set_compress_context(struct inode *inode)
> #endif
> }
>
> +static inline bool inode_has_data(struct inode *inode)
> +{
> + return (S_ISREG(inode->i_mode) &&
> + (F2FS_HAS_BLOCKS(inode) || i_size_read(inode)));
> +}
> +
> static inline bool f2fs_disable_compressed_file(struct inode *inode)
> {
> struct f2fs_inode_info *fi = F2FS_I(inode);
>
> - if (!f2fs_compressed_file(inode))
> + f2fs_down_write(&F2FS_I(inode)->i_sem);
> +
> + if (!f2fs_compressed_file(inode)) {
> + f2fs_up_write(&F2FS_I(inode)->i_sem);
> return true;
> - if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
> + }
> + if (f2fs_is_mmap_file(inode) || inode_has_data(inode)) {
> + f2fs_up_write(&F2FS_I(inode)->i_sem);
> return false;
> + }
>
> fi->i_flags &= ~F2FS_COMPR_FL;
> stat_dec_compr_inode(inode);
> clear_inode_flag(inode, FI_COMPRESSED_FILE);
> f2fs_mark_inode_dirty_sync(inode, true);
> +
> + f2fs_up_write(&F2FS_I(inode)->i_sem);
> return true;
> }
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 0e4c871d6aed..5e5df234eb92 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1926,8 +1926,7 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
>
> f2fs_down_write(&F2FS_I(inode)->i_sem);
> if (!f2fs_may_compress(inode) ||
> - (S_ISREG(inode->i_mode) &&
> - F2FS_HAS_BLOCKS(inode))) {
> + inode_has_data(inode)) {
> f2fs_up_write(&F2FS_I(inode)->i_sem);
> return -EINVAL;
> }
> @@ -4011,7 +4010,7 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg)
> goto out;
> }
>
> - if (F2FS_HAS_BLOCKS(inode)) {
> + if (inode_has_data(inode)) {
> ret = -EFBIG;
> goto out;
> }
> --
> 2.40.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: compress: fix to cover f2fs_disable_compressed_file() w/ i_sem
Date: Tue, 16 Jan 2024 10:29:23 -0800 [thread overview]
Message-ID: <ZabLA4EWNzNFGb5Q@google.com> (raw)
In-Reply-To: <20240111064406.2970205-1-chao@kernel.org>
On 01/11, Chao Yu wrote:
> - f2fs_disable_compressed_file
> - check inode_has_data
> - f2fs_file_mmap
> - mkwrite
> - f2fs_get_block_locked
> : update metadata in compressed
> inode's disk layout
> - fi->i_flags &= ~F2FS_COMPR_FL
> - clear_inode_flag(inode, FI_COMPRESSED_FILE);
>
> we should use i_sem lock to prevent above race case.
>
> Meanwhile, this patch adds i_size check to restrict compress inode
> conversion condition.
Sorry, what was the reason to check i_size?
>
> Fixes: 4c8ff7095bef ("f2fs: support data compression")
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> fs/f2fs/f2fs.h | 18 ++++++++++++++++--
> fs/f2fs/file.c | 5 ++---
> 2 files changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 74729db0b381..e2e0ca45f881 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -4406,19 +4406,33 @@ static inline int set_compress_context(struct inode *inode)
> #endif
> }
>
> +static inline bool inode_has_data(struct inode *inode)
> +{
> + return (S_ISREG(inode->i_mode) &&
> + (F2FS_HAS_BLOCKS(inode) || i_size_read(inode)));
> +}
> +
> static inline bool f2fs_disable_compressed_file(struct inode *inode)
> {
> struct f2fs_inode_info *fi = F2FS_I(inode);
>
> - if (!f2fs_compressed_file(inode))
> + f2fs_down_write(&F2FS_I(inode)->i_sem);
> +
> + if (!f2fs_compressed_file(inode)) {
> + f2fs_up_write(&F2FS_I(inode)->i_sem);
> return true;
> - if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
> + }
> + if (f2fs_is_mmap_file(inode) || inode_has_data(inode)) {
> + f2fs_up_write(&F2FS_I(inode)->i_sem);
> return false;
> + }
>
> fi->i_flags &= ~F2FS_COMPR_FL;
> stat_dec_compr_inode(inode);
> clear_inode_flag(inode, FI_COMPRESSED_FILE);
> f2fs_mark_inode_dirty_sync(inode, true);
> +
> + f2fs_up_write(&F2FS_I(inode)->i_sem);
> return true;
> }
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 0e4c871d6aed..5e5df234eb92 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1926,8 +1926,7 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
>
> f2fs_down_write(&F2FS_I(inode)->i_sem);
> if (!f2fs_may_compress(inode) ||
> - (S_ISREG(inode->i_mode) &&
> - F2FS_HAS_BLOCKS(inode))) {
> + inode_has_data(inode)) {
> f2fs_up_write(&F2FS_I(inode)->i_sem);
> return -EINVAL;
> }
> @@ -4011,7 +4010,7 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg)
> goto out;
> }
>
> - if (F2FS_HAS_BLOCKS(inode)) {
> + if (inode_has_data(inode)) {
> ret = -EFBIG;
> goto out;
> }
> --
> 2.40.1
next prev parent reply other threads:[~2024-01-16 18:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 6:44 [f2fs-dev] [PATCH] f2fs: compress: fix to cover f2fs_disable_compressed_file() w/ i_sem Chao Yu
2024-01-11 6:44 ` Chao Yu
2024-01-16 18:29 ` Jaegeuk Kim [this message]
2024-01-16 18:29 ` Jaegeuk Kim
2024-01-22 2:25 ` [f2fs-dev] " Chao Yu
2024-01-22 2:25 ` Chao Yu
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=ZabLA4EWNzNFGb5Q@google.com \
--to=jaegeuk@kernel.org \
--cc=chao@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 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.