* [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
@ 2025-06-30 9:54 wangzijie
2025-06-30 9:54 ` [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: wangzijie @ 2025-06-30 9:54 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: feng.han, linux-kernel, linux-f2fs-devel, wangzijie
Introduce sbi in f2fs_setattr() and convert F2FS_I_SB to it. No logic
change, just cleanup and prepare to get CAP_BLKS_PER_SEC(sbi).
Signed-off-by: wangzijie <wangzijie1@honor.com>
---
fs/f2fs/file.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 696131e65..78368b793 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1042,9 +1042,10 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
{
struct inode *inode = d_inode(dentry);
struct f2fs_inode_info *fi = F2FS_I(inode);
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
int err;
- if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
+ if (unlikely(f2fs_cp_error(sbi)))
return -EIO;
if (unlikely(IS_IMMUTABLE(inode)))
@@ -1084,12 +1085,11 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
}
if (i_uid_needs_update(idmap, attr, inode) ||
i_gid_needs_update(idmap, attr, inode)) {
- f2fs_lock_op(F2FS_I_SB(inode));
+ f2fs_lock_op(sbi);
err = dquot_transfer(idmap, inode, attr);
if (err) {
- set_sbi_flag(F2FS_I_SB(inode),
- SBI_QUOTA_NEED_REPAIR);
- f2fs_unlock_op(F2FS_I_SB(inode));
+ set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
+ f2fs_unlock_op(sbi);
return err;
}
/*
@@ -1099,7 +1099,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
i_uid_update(idmap, attr, inode);
i_gid_update(idmap, attr, inode);
f2fs_mark_inode_dirty_sync(inode, true);
- f2fs_unlock_op(F2FS_I_SB(inode));
+ f2fs_unlock_op(sbi);
}
if (attr->ia_valid & ATTR_SIZE) {
@@ -1162,7 +1162,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
f2fs_mark_inode_dirty_sync(inode, true);
/* inode change will produce dirty node pages flushed by checkpoint */
- f2fs_balance_fs(F2FS_I_SB(inode), true);
+ f2fs_balance_fs(sbi, true);
return err;
}
--
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] 7+ messages in thread
* [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
2025-06-30 9:54 [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
@ 2025-06-30 9:54 ` wangzijie
2025-06-30 11:12 ` Chao Yu via Linux-f2fs-devel
2025-06-30 16:35 ` Jaegeuk Kim via Linux-f2fs-devel
2025-06-30 11:11 ` [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() Chao Yu via Linux-f2fs-devel
2025-07-09 18:10 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
2 siblings, 2 replies; 7+ messages in thread
From: wangzijie @ 2025-06-30 9:54 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: feng.han, linux-kernel, linux-f2fs-devel, wangzijie
To prevent scattered pin block generation, don't allow non-section aligned truncation
to smaller or equal size on pinned file. But for truncation to larger size, after
commit 3fdd89b452c2("f2fs: prevent writing without fallocate() for pinned files"),
we only support overwrite IO to pinned file, so we don't need to consider
attr->ia_size > i_size case.
In addition, xfstests #494 assumes truncation on active swapfile(pinned) will return
ETXTBSY by setattr_prepare() -> inode_newsize_ok(), so we relocate this check after
setattr_prepare().
Signed-off-by: wangzijie <wangzijie1@honor.com>
---
v5:
- fix xfstests #494 fail
---
fs/f2fs/file.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 78368b793..d4feea44b 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1070,6 +1070,23 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
if (err)
return err;
+ /*
+ * To prevent scattered pin block generation, we don't allow
+ * smaller/equal size unaligned truncation for pinned file.
+ * We only support overwrite IO to pinned file, so don't
+ * care about larger size truncation.
+ * We need to check this after setattr_prepare() because xfstests
+ * #494 assumes truncation on active swapfile(pinned) will
+ * return ETXTBSY by setattr_prepare() -> inode_newsize_ok().
+ */
+ if (attr->ia_valid & ATTR_SIZE) {
+ if (f2fs_is_pinned_file(inode) &&
+ attr->ia_size <= i_size_read(inode) &&
+ !IS_ALIGNED(attr->ia_size,
+ F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
+ return -EINVAL;
+ }
+
err = fscrypt_prepare_setattr(dentry, attr);
if (err)
return err;
--
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] 7+ messages in thread
* Re: [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
2025-06-30 9:54 [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
2025-06-30 9:54 ` [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
@ 2025-06-30 11:11 ` Chao Yu via Linux-f2fs-devel
2025-07-09 18:10 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
2 siblings, 0 replies; 7+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-06-30 11:11 UTC (permalink / raw)
To: wangzijie, jaegeuk; +Cc: feng.han, linux-kernel, linux-f2fs-devel
On 6/30/25 17:54, wangzijie wrote:
> Introduce sbi in f2fs_setattr() and convert F2FS_I_SB to it. No logic
> change, just cleanup and prepare to get CAP_BLKS_PER_SEC(sbi).
>
> Signed-off-by: wangzijie <wangzijie1@honor.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
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] 7+ messages in thread
* Re: [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
2025-06-30 9:54 ` [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
@ 2025-06-30 11:12 ` Chao Yu via Linux-f2fs-devel
2025-06-30 16:35 ` Jaegeuk Kim via Linux-f2fs-devel
1 sibling, 0 replies; 7+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-06-30 11:12 UTC (permalink / raw)
To: wangzijie, jaegeuk; +Cc: feng.han, linux-kernel, linux-f2fs-devel
On 6/30/25 17:54, wangzijie wrote:
> To prevent scattered pin block generation, don't allow non-section aligned truncation
> to smaller or equal size on pinned file. But for truncation to larger size, after
> commit 3fdd89b452c2("f2fs: prevent writing without fallocate() for pinned files"),
> we only support overwrite IO to pinned file, so we don't need to consider
> attr->ia_size > i_size case.
> In addition, xfstests #494 assumes truncation on active swapfile(pinned) will return
> ETXTBSY by setattr_prepare() -> inode_newsize_ok(), so we relocate this check after
> setattr_prepare().
>
> Signed-off-by: wangzijie <wangzijie1@honor.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
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] 7+ messages in thread
* Re: [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
2025-06-30 9:54 ` [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
2025-06-30 11:12 ` Chao Yu via Linux-f2fs-devel
@ 2025-06-30 16:35 ` Jaegeuk Kim via Linux-f2fs-devel
2025-07-01 1:53 ` wangzijie
1 sibling, 1 reply; 7+ messages in thread
From: Jaegeuk Kim via Linux-f2fs-devel @ 2025-06-30 16:35 UTC (permalink / raw)
To: wangzijie; +Cc: feng.han, linux-kernel, linux-f2fs-devel
I think we can clean up more like this?
https://lore.kernel.org/linux-f2fs-devel/20250630160839.1142073-1-jaegeuk@kernel.org/T/#u
On 06/30, wangzijie wrote:
> To prevent scattered pin block generation, don't allow non-section aligned truncation
> to smaller or equal size on pinned file. But for truncation to larger size, after
> commit 3fdd89b452c2("f2fs: prevent writing without fallocate() for pinned files"),
> we only support overwrite IO to pinned file, so we don't need to consider
> attr->ia_size > i_size case.
> In addition, xfstests #494 assumes truncation on active swapfile(pinned) will return
> ETXTBSY by setattr_prepare() -> inode_newsize_ok(), so we relocate this check after
> setattr_prepare().
>
> Signed-off-by: wangzijie <wangzijie1@honor.com>
> ---
> v5:
> - fix xfstests #494 fail
> ---
> fs/f2fs/file.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 78368b793..d4feea44b 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1070,6 +1070,23 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
> if (err)
> return err;
>
> + /*
> + * To prevent scattered pin block generation, we don't allow
> + * smaller/equal size unaligned truncation for pinned file.
> + * We only support overwrite IO to pinned file, so don't
> + * care about larger size truncation.
> + * We need to check this after setattr_prepare() because xfstests
> + * #494 assumes truncation on active swapfile(pinned) will
> + * return ETXTBSY by setattr_prepare() -> inode_newsize_ok().
> + */
> + if (attr->ia_valid & ATTR_SIZE) {
> + if (f2fs_is_pinned_file(inode) &&
> + attr->ia_size <= i_size_read(inode) &&
> + !IS_ALIGNED(attr->ia_size,
> + F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
> + return -EINVAL;
> + }
> +
> err = fscrypt_prepare_setattr(dentry, attr);
> if (err)
> return err;
> --
> 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 [flat|nested] 7+ messages in thread
* Re: [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
2025-06-30 16:35 ` Jaegeuk Kim via Linux-f2fs-devel
@ 2025-07-01 1:53 ` wangzijie
0 siblings, 0 replies; 7+ messages in thread
From: wangzijie @ 2025-07-01 1:53 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: jaegeuk, wangzijie1, linux-kernel, feng.han
>I think we can clean up more like this?
>
>https://lore.kernel.org/linux-f2fs-devel/20250630160839.1142073-1-jaegeuk@kernel.org/T/#u
Hi Kim,
Yes, I think we can apply the patch you showed and v4 of this patch. Thank you.
https://lore.kernel.org/linux-f2fs-devel/20250624035938.3176350-1-wangzijie1@honor.com/
https://lore.kernel.org/linux-f2fs-devel/20250624035938.3176350-2-wangzijie1@honor.com/
>On 06/30, wangzijie wrote:
>> To prevent scattered pin block generation, don't allow non-section aligned truncation
>> to smaller or equal size on pinned file. But for truncation to larger size, after
>> commit 3fdd89b452c2("f2fs: prevent writing without fallocate() for pinned files"),
>> we only support overwrite IO to pinned file, so we don't need to consider
>> attr->ia_size > i_size case.
>> In addition, xfstests #494 assumes truncation on active swapfile(pinned) will return
>> ETXTBSY by setattr_prepare() -> inode_newsize_ok(), so we relocate this check after
>> setattr_prepare().
>>
>> Signed-off-by: wangzijie <wangzijie1@honor.com>
>> ---
>> v5:
>> - fix xfstests #494 fail
>> ---
>> fs/f2fs/file.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 78368b793..d4feea44b 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1070,6 +1070,23 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>> if (err)
>> return err;
>>
>> + /*
>> + * To prevent scattered pin block generation, we don't allow
>> + * smaller/equal size unaligned truncation for pinned file.
>> + * We only support overwrite IO to pinned file, so don't
>> + * care about larger size truncation.
>> + * We need to check this after setattr_prepare() because xfstests
>> + * #494 assumes truncation on active swapfile(pinned) will
>> + * return ETXTBSY by setattr_prepare() -> inode_newsize_ok().
>> + */
>> + if (attr->ia_valid & ATTR_SIZE) {
>> + if (f2fs_is_pinned_file(inode) &&
>> + attr->ia_size <= i_size_read(inode) &&
>> + !IS_ALIGNED(attr->ia_size,
>> + F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
>> + return -EINVAL;
>> + }
>> +
>> err = fscrypt_prepare_setattr(dentry, attr);
>> if (err)
>> return err;
>> --
>> 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 [flat|nested] 7+ messages in thread
* Re: [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
2025-06-30 9:54 [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
2025-06-30 9:54 ` [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
2025-06-30 11:11 ` [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() Chao Yu via Linux-f2fs-devel
@ 2025-07-09 18:10 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2025-07-09 18:10 UTC (permalink / raw)
To: wangzijie; +Cc: jaegeuk, linux-kernel, feng.han, linux-f2fs-devel
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Mon, 30 Jun 2025 17:54:53 +0800 you wrote:
> Introduce sbi in f2fs_setattr() and convert F2FS_I_SB to it. No logic
> change, just cleanup and prepare to get CAP_BLKS_PER_SEC(sbi).
>
> Signed-off-by: wangzijie <wangzijie1@honor.com>
> ---
> fs/f2fs/file.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
Here is the summary with links:
- [f2fs-dev,v5,1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
https://git.kernel.org/jaegeuk/f2fs/c/90c5ce37adf0
- [f2fs-dev,v5,2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
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] 7+ messages in thread
end of thread, other threads:[~2025-07-09 18:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30 9:54 [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
2025-06-30 9:54 ` [f2fs-dev] [PATCH v5 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
2025-06-30 11:12 ` Chao Yu via Linux-f2fs-devel
2025-06-30 16:35 ` Jaegeuk Kim via Linux-f2fs-devel
2025-07-01 1:53 ` wangzijie
2025-06-30 11:11 ` [f2fs-dev] [PATCH v5 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() Chao Yu via Linux-f2fs-devel
2025-07-09 18:10 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).