linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
@ 2025-06-24  3:59 wangzijie
  2025-06-24  3:59 ` [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
  2025-06-24 14:18 ` [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() Chao Yu
  0 siblings, 2 replies; 7+ messages in thread
From: wangzijie @ 2025-06-24  3:59 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, bintian.wang, feng.han,
	niuzhiguo84, 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 6bd3de64f..209f43653 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1026,9 +1026,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)))
@@ -1068,12 +1069,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;
 		}
 		/*
@@ -1083,7 +1083,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) {
@@ -1144,7 +1144,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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
  2025-06-24  3:59 [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
@ 2025-06-24  3:59 ` wangzijie
  2025-06-24 14:19   ` Chao Yu
  2025-06-30  2:04   ` Chao Yu
  2025-06-24 14:18 ` [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() Chao Yu
  1 sibling, 2 replies; 7+ messages in thread
From: wangzijie @ 2025-06-24  3:59 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, bintian.wang, feng.han,
	niuzhiguo84, 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.

Signed-off-by: wangzijie <wangzijie1@honor.com>
---
v4:
- convert sbi first and apply change
---
 fs/f2fs/file.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 209f43653..4809f0fd6 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1048,6 +1048,17 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 			!IS_ALIGNED(attr->ia_size,
 			F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
 			return -EINVAL;
+		/*
+		 * 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.
+		 */
+		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 = setattr_prepare(idmap, dentry, attr);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
  2025-06-24  3:59 [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
  2025-06-24  3:59 ` [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
@ 2025-06-24 14:18 ` Chao Yu
  1 sibling, 0 replies; 7+ messages in thread
From: Chao Yu @ 2025-06-24 14:18 UTC (permalink / raw)
  To: wangzijie, jaegeuk
  Cc: chao, linux-f2fs-devel, linux-kernel, bintian.wang, feng.han,
	niuzhiguo84

On 2025/6/24 11:59, 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,

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
  2025-06-24  3:59 ` [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
@ 2025-06-24 14:19   ` Chao Yu
  2025-06-30  2:04   ` Chao Yu
  1 sibling, 0 replies; 7+ messages in thread
From: Chao Yu @ 2025-06-24 14:19 UTC (permalink / raw)
  To: wangzijie, jaegeuk
  Cc: chao, linux-f2fs-devel, linux-kernel, bintian.wang, feng.han,
	niuzhiguo84

On 2025/6/24 11:59, 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.
> 
> Signed-off-by: wangzijie <wangzijie1@honor.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
  2025-06-24  3:59 ` [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
  2025-06-24 14:19   ` Chao Yu
@ 2025-06-30  2:04   ` Chao Yu
  2025-06-30  2:50     ` wangzijie
  1 sibling, 1 reply; 7+ messages in thread
From: Chao Yu @ 2025-06-30  2:04 UTC (permalink / raw)
  To: wangzijie, jaegeuk
  Cc: chao, linux-f2fs-devel, linux-kernel, bintian.wang, feng.han,
	niuzhiguo84

On 6/24/25 11:59, 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.

Zijie, can you take a look generic/494? suspect that it is caused by this change.

generic/494 3s ... - output mismatch (see /share/git/fstests/results//generic/494.out.bad)
    --- tests/generic/494.out   2025-01-12 21:57:40.279440664 +0800
    +++ /share/git/fstests/results//generic/494.out.bad 2025-06-30 10:01:37.000000000 +0800
    @@ -2,7 +2,7 @@
     Format and mount
     Initialize file
     Try to truncate
    -ftruncate: Text file busy
    +ftruncate: Invalid argument
     Try to punch hole
     fallocate: Text file busy
    ...
    (Run 'diff -u /share/git/fstests/tests/generic/494.out /share/git/fstests/results//generic/494.out.bad'  to see the entire diff)
Ran: generic/494
Failures: generic/494
Failed 1 of 1 tests

Thanks,

> 
> Signed-off-by: wangzijie <wangzijie1@honor.com>
> ---
> v4:
> - convert sbi first and apply change
> ---
>  fs/f2fs/file.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 209f43653..4809f0fd6 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1048,6 +1048,17 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>  			!IS_ALIGNED(attr->ia_size,
>  			F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
>  			return -EINVAL;
> +		/*
> +		 * 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.
> +		 */
> +		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 = setattr_prepare(idmap, dentry, attr);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
  2025-06-30  2:04   ` Chao Yu
@ 2025-06-30  2:50     ` wangzijie
  2025-06-30  3:41       ` Chao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: wangzijie @ 2025-06-30  2:50 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: chao, feng.han, jaegeuk, linux-kernel, wangzijie1

>On 6/24/25 11:59, 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.
>
>Zijie, can you take a look generic/494? suspect that it is caused by this change.
>
>generic/494 3s ... - output mismatch (see /share/git/fstests/results//generic/494.out.bad)
>    --- tests/generic/494.out   2025-01-12 21:57:40.279440664 +0800
>    +++ /share/git/fstests/results//generic/494.out.bad 2025-06-30 10:01:37.000000000 +0800
>    @@ -2,7 +2,7 @@
>     Format and mount
>     Initialize file
>     Try to truncate
>    -ftruncate: Text file busy
>    +ftruncate: Invalid argument
>     Try to punch hole
>     fallocate: Text file busy
>    ...
>    (Run 'diff -u /share/git/fstests/tests/generic/494.out /share/git/fstests/results//generic/494.out.bad'  to see the entire diff)
>Ran: generic/494
>Failures: generic/494
>Failed 1 of 1 tests
>
>Thanks,

Hi, Chao
generic/494 swapon file and try to ftruncate.

Before this change
swap_acticate:
set_inode_flag(inode, FI_PIN_FILE)

ftruncate:
setattr_prepare
-inode_newsize_ok
--return -ETXTBSY for SWAPFILE

After this change:
swap_acticate:
set_inode_flag(inode, FI_PIN_FILE)

ftruncate: 
prevent unaligned truncation before setattr_prepare()
return -EINVAL

Sorry for this. Maybe I should apply this check after setattr_prepare()? Or do
you have some suggestions?


>> 
>> Signed-off-by: wangzijie <wangzijie1@honor.com>
>> ---
>> v4:
>> - convert sbi first and apply change
>> ---
>>  fs/f2fs/file.c | 11 +++++++++++
>>  1 file changed, 11 insertions(+)
>> 
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 209f43653..4809f0fd6 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1048,6 +1048,17 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>>  			!IS_ALIGNED(attr->ia_size,
>>  			F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
>>  			return -EINVAL;
>> +		/*
>> +		 * 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.
>> +		 */
>> +		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 = setattr_prepare(idmap, dentry, attr);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
  2025-06-30  2:50     ` wangzijie
@ 2025-06-30  3:41       ` Chao Yu
  0 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2025-06-30  3:41 UTC (permalink / raw)
  To: wangzijie, linux-f2fs-devel; +Cc: chao, feng.han, jaegeuk, linux-kernel

On 6/30/25 10:50, wangzijie wrote:
>> On 6/24/25 11:59, 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.
>>
>> Zijie, can you take a look generic/494? suspect that it is caused by this change.
>>
>> generic/494 3s ... - output mismatch (see /share/git/fstests/results//generic/494.out.bad)
>>    --- tests/generic/494.out   2025-01-12 21:57:40.279440664 +0800
>>    +++ /share/git/fstests/results//generic/494.out.bad 2025-06-30 10:01:37.000000000 +0800
>>    @@ -2,7 +2,7 @@
>>     Format and mount
>>     Initialize file
>>     Try to truncate
>>    -ftruncate: Text file busy
>>    +ftruncate: Invalid argument
>>     Try to punch hole
>>     fallocate: Text file busy
>>    ...
>>    (Run 'diff -u /share/git/fstests/tests/generic/494.out /share/git/fstests/results//generic/494.out.bad'  to see the entire diff)
>> Ran: generic/494
>> Failures: generic/494
>> Failed 1 of 1 tests
>>
>> Thanks,
> 
> Hi, Chao
> generic/494 swapon file and try to ftruncate.
> 
> Before this change
> swap_acticate:
> set_inode_flag(inode, FI_PIN_FILE)
> 
> ftruncate:
> setattr_prepare
> -inode_newsize_ok
> --return -ETXTBSY for SWAPFILE
> 
> After this change:
> swap_acticate:
> set_inode_flag(inode, FI_PIN_FILE)
> 
> ftruncate: 
> prevent unaligned truncation before setattr_prepare()
> return -EINVAL
> 
> Sorry for this. Maybe I should apply this check after setattr_prepare()? Or do

Check after setattr_prepare() looks fine to me, in addition, can you please add
more comments for the reason why we relocate code there?

Thanks,

> you have some suggestions?
> 
> 
>>>
>>> Signed-off-by: wangzijie <wangzijie1@honor.com>
>>> ---
>>> v4:
>>> - convert sbi first and apply change
>>> ---
>>>  fs/f2fs/file.c | 11 +++++++++++
>>>  1 file changed, 11 insertions(+)
>>>
>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>>> index 209f43653..4809f0fd6 100644
>>> --- a/fs/f2fs/file.c
>>> +++ b/fs/f2fs/file.c
>>> @@ -1048,6 +1048,17 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>>>  			!IS_ALIGNED(attr->ia_size,
>>>  			F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
>>>  			return -EINVAL;
>>> +		/*
>>> +		 * 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.
>>> +		 */
>>> +		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 = setattr_prepare(idmap, dentry, attr);
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-06-30  3:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24  3:59 [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() wangzijie
2025-06-24  3:59 ` [f2fs-dev] [PATCH v4 2/2] f2fs: don't allow unaligned truncation to smaller/equal size on pinned file wangzijie
2025-06-24 14:19   ` Chao Yu
2025-06-30  2:04   ` Chao Yu
2025-06-30  2:50     ` wangzijie
2025-06-30  3:41       ` Chao Yu
2025-06-24 14:18 ` [f2fs-dev] [PATCH v4 1/2] f2fs: convert F2FS_I_SB to sbi in f2fs_setattr() Chao Yu

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