linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: wangzijie <wangzijie1@honor.com>
To: <linux-f2fs-devel@lists.sourceforge.net>
Cc: jaegeuk@kernel.org, wangzijie1@honor.com,
	linux-kernel@vger.kernel.org, feng.han@honor.com
Subject: Re: [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation
Date: Tue, 17 Jun 2025 18:05:27 +0800	[thread overview]
Message-ID: <20250617100527.2373435-1-wangzijie1@honor.com> (raw)
In-Reply-To: <e6a2233f-5f32-4e1a-87b3-4ecb935e3997@kernel.org>

>On 6/17/25 15:36, wangzijie wrote:
>>> On 6/17/25 11:57, wangzijie wrote:
>>>> To prevent non-section-aligned size pinned file generated from truncation,
>>>> add check condition in setattr.
>>>>
>>>> Signed-off-by: wangzijie <wangzijie1@honor.com>
>>>> ---
>>>>  fs/f2fs/file.c | 6 ++++++
>>>>  1 file changed, 6 insertions(+)
>>>>
>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>>>> index 6bd3de64f..72f7d1b4a 100644
>>>> --- a/fs/f2fs/file.c
>>>> +++ b/fs/f2fs/file.c
>>>> @@ -1026,6 +1026,7 @@ 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))))
>>>> @@ -1047,6 +1048,11 @@ 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;
>>>> +		if (f2fs_is_pinned_file(inode) &&
>>>> +			attr->ia_size < i_size_read(inode) &&
>>>
>>> Do we need to consider attr->ia_size > i_size case?
>>>
>>> Thanks,
>> 
>> Hi, Chao
>> After commit 3fdd89b452c2("f2fs: prevent writing without fallocate() for pinned
>> files"), when we want to write data to pinned file, we need to use pin+fallocate, 
>> and we did CAP_BLKS_PER_SEC roundup align when fallocate pinned file:
>> 
>> block_t sec_len = roundup(map.m_len, sec_blks);
>> 
>> Even if we truncate the file to a larger size(maybe larger than sec_len, section
>> align or not), and write data to offset beyond sec_len, the write will fail(commit
>> 3fdd89b452c2 prevent it). The scattered pin block cannot be generated by this way,
>> so I did not consider attr->ia_size > i_size case.
>> Do you have some suggestions?
>
>Ah, correct, so what about adding comments here to describe why we don't
>need consider attr->ia_size > i_size case?

OK, I will add comments in next version.

>> 
>>>> +			!IS_ALIGNED(attr->ia_size,
>>>> +			F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
>>>> +			return -EINVAL;
>>>>  	}
>>>>  
>>>>  	err = setattr_prepare(idmap, dentry, attr);
>> 
>> 
>> 





_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

      reply	other threads:[~2025-06-17 10:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17  3:57 [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation wangzijie
2025-06-17  3:57 ` [f2fs-dev] [PATCH 2/2] f2fs: cleanup F2FS_I_SB in f2fs_setattr() wangzijie
2025-06-17  5:22 ` [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation Chao Yu via Linux-f2fs-devel
2025-06-17  7:36   ` wangzijie
2025-06-17  9:30     ` Chao Yu via Linux-f2fs-devel
2025-06-17 10:05       ` wangzijie [this message]

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=20250617100527.2373435-1-wangzijie1@honor.com \
    --to=wangzijie1@honor.com \
    --cc=feng.han@honor.com \
    --cc=jaegeuk@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 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).