From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Wenjie Qi <qwjhust@gmail.com>, jaegeuk@kernel.org
Cc: stable@kernel.org, qiwenjie@xiaomi.com,
linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: keep pinned fallocate failures section-aligned
Date: Mon, 3 Aug 2026 15:24:34 +0800 [thread overview]
Message-ID: <f0eb26ed-c624-47d0-9450-6e6e014bbcd7@kernel.org> (raw)
In-Reply-To: <20260723133617.3841286-1-qiwenjie@xiaomi.com>
On 7/23/26 21:36, Wenjie Qi wrote:
> Pinned fallocate allocates one section at a time. If f2fs_map_blocks()
> fails after allocating part of the current section, the error path still
> adds the partial length to expanded and clears FADVISE_TRUNC_BIT. A failed
> fallocate can then leave a pinned file with a non-section-aligned size.
Do you have a reproducer? maybe inject memory allocation failure?
Thanks,
>
> Count only complete sections on failure and keep FADVISE_TRUNC_BIT set
> until the failed section preallocation has been removed.
>
> Fixes: f5a53edcf01e ("f2fs: support aligned pinned file")
> Cc: stable@kernel.org
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> ---
> fs/f2fs/file.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index c54897a25981..83af73f3831e 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1966,11 +1966,12 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
>
> map.m_seg_type = CURSEG_COLD_DATA_PINNED;
> err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_PRE_DIO);
> - file_dont_truncate(inode);
> + if (!err)
> + file_dont_truncate(inode);
>
> f2fs_up_write(&sbi->pin_sem);
>
> - expanded += map.m_len;
> + expanded += err ? rounddown(map.m_len, sec_blks) : map.m_len;
> sec_len -= map.m_len;
> map.m_lblk += map.m_len;
> if (!err && sec_len)
> @@ -1986,7 +1987,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
> pgoff_t last_off;
>
> if (!expanded)
> - return err;
> + goto out;
>
> last_off = pg_start + expanded - 1;
>
> @@ -2004,6 +2005,16 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
> f2fs_i_size_write(inode, new_size);
> }
>
> +out:
> + if (err && f2fs_is_pinned_file(inode) && file_should_truncate(inode)) {
> + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> + filemap_invalidate_lock(inode->i_mapping);
> + if (!f2fs_truncate(inode))
> + file_dont_truncate(inode);
> + filemap_invalidate_unlock(inode->i_mapping);
> + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> + }
> +
> return err;
> }
>
_______________________________________________
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: Chao Yu <chao@kernel.org>
To: Wenjie Qi <qwjhust@gmail.com>, jaegeuk@kernel.org
Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com,
stable@kernel.org
Subject: Re: [PATCH] f2fs: keep pinned fallocate failures section-aligned
Date: Mon, 3 Aug 2026 15:24:34 +0800 [thread overview]
Message-ID: <f0eb26ed-c624-47d0-9450-6e6e014bbcd7@kernel.org> (raw)
In-Reply-To: <20260723133617.3841286-1-qiwenjie@xiaomi.com>
On 7/23/26 21:36, Wenjie Qi wrote:
> Pinned fallocate allocates one section at a time. If f2fs_map_blocks()
> fails after allocating part of the current section, the error path still
> adds the partial length to expanded and clears FADVISE_TRUNC_BIT. A failed
> fallocate can then leave a pinned file with a non-section-aligned size.
Do you have a reproducer? maybe inject memory allocation failure?
Thanks,
>
> Count only complete sections on failure and keep FADVISE_TRUNC_BIT set
> until the failed section preallocation has been removed.
>
> Fixes: f5a53edcf01e ("f2fs: support aligned pinned file")
> Cc: stable@kernel.org
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> ---
> fs/f2fs/file.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index c54897a25981..83af73f3831e 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1966,11 +1966,12 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
>
> map.m_seg_type = CURSEG_COLD_DATA_PINNED;
> err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_PRE_DIO);
> - file_dont_truncate(inode);
> + if (!err)
> + file_dont_truncate(inode);
>
> f2fs_up_write(&sbi->pin_sem);
>
> - expanded += map.m_len;
> + expanded += err ? rounddown(map.m_len, sec_blks) : map.m_len;
> sec_len -= map.m_len;
> map.m_lblk += map.m_len;
> if (!err && sec_len)
> @@ -1986,7 +1987,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
> pgoff_t last_off;
>
> if (!expanded)
> - return err;
> + goto out;
>
> last_off = pg_start + expanded - 1;
>
> @@ -2004,6 +2005,16 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
> f2fs_i_size_write(inode, new_size);
> }
>
> +out:
> + if (err && f2fs_is_pinned_file(inode) && file_should_truncate(inode)) {
> + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> + filemap_invalidate_lock(inode->i_mapping);
> + if (!f2fs_truncate(inode))
> + file_dont_truncate(inode);
> + filemap_invalidate_unlock(inode->i_mapping);
> + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> + }
> +
> return err;
> }
>
next prev parent reply other threads:[~2026-08-03 7:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 13:36 [PATCH] f2fs: keep pinned fallocate failures section-aligned Wenjie Qi
2026-07-23 13:36 ` [f2fs-dev] " Wenjie Qi
2026-08-03 7:24 ` Chao Yu via Linux-f2fs-devel [this message]
2026-08-03 7:24 ` Chao Yu
2026-08-03 8:35 ` [f2fs-dev] " Wenjie Qi
2026-08-03 8:35 ` Wenjie Qi
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=f0eb26ed-c624-47d0-9450-6e6e014bbcd7@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qiwenjie@xiaomi.com \
--cc=qwjhust@gmail.com \
--cc=stable@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.