public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: support zero sized file truncate for device aliasing files
@ 2025-03-17 19:08 Daeho Jeong
  2025-03-18  3:45 ` [f2fs-dev] " Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Daeho Jeong @ 2025-03-17 19:08 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong

From: Daeho Jeong <daehojeong@google.com>

support a file truncation to zero size for device aliasing files.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 fs/f2fs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index f92a9fba9991..7ae5a5af5ed9 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1036,7 +1036,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 
 	if ((attr->ia_valid & ATTR_SIZE)) {
 		if (!f2fs_is_compress_backend_ready(inode) ||
-				IS_DEVICE_ALIASING(inode))
+				(IS_DEVICE_ALIASING(inode) && attr->ia_size))
 			return -EOPNOTSUPP;
 		if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) &&
 			!IS_ALIGNED(attr->ia_size,
@@ -1117,6 +1117,9 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		if (err)
 			return err;
 
+		if (IS_DEVICE_ALIASING(inode))
+			f2fs_destroy_extent_tree(inode);
+
 		spin_lock(&fi->i_size_lock);
 		inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
 		fi->last_disk_size = i_size_read(inode);
-- 
2.49.0.rc1.451.g8f38331e32-goog


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

* Re: [f2fs-dev] [PATCH] f2fs: support zero sized file truncate for device aliasing files
  2025-03-17 19:08 [PATCH] f2fs: support zero sized file truncate for device aliasing files Daeho Jeong
@ 2025-03-18  3:45 ` Chao Yu
  2025-03-21 21:16   ` Daeho Jeong
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2025-03-18  3:45 UTC (permalink / raw)
  To: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team
  Cc: chao, Daeho Jeong

On 3/18/25 03:08, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> support a file truncation to zero size for device aliasing files.
> 
> Signed-off-by: Daeho Jeong <daehojeong@google.com>
> ---
>  fs/f2fs/file.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index f92a9fba9991..7ae5a5af5ed9 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1036,7 +1036,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>  
>  	if ((attr->ia_valid & ATTR_SIZE)) {
>  		if (!f2fs_is_compress_backend_ready(inode) ||
> -				IS_DEVICE_ALIASING(inode))
> +				(IS_DEVICE_ALIASING(inode) && attr->ia_size))
>  			return -EOPNOTSUPP;
>  		if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) &&
>  			!IS_ALIGNED(attr->ia_size,
> @@ -1117,6 +1117,9 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
>  		if (err)
>  			return err;

Daeho,

If truncate(, 0) failed due to some reasons, maybe, the file was partially
truncated, should we tag it as inconsistent status to avoid its later access?
thoughts?

Thanks,

>  
> +		if (IS_DEVICE_ALIASING(inode))
> +			f2fs_destroy_extent_tree(inode);
> +
>  		spin_lock(&fi->i_size_lock);
>  		inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
>  		fi->last_disk_size = i_size_read(inode);


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

* Re: [f2fs-dev] [PATCH] f2fs: support zero sized file truncate for device aliasing files
  2025-03-18  3:45 ` [f2fs-dev] " Chao Yu
@ 2025-03-21 21:16   ` Daeho Jeong
  0 siblings, 0 replies; 3+ messages in thread
From: Daeho Jeong @ 2025-03-21 21:16 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel, kernel-team, Daeho Jeong

On Mon, Mar 17, 2025 at 8:45 PM Chao Yu <chao@kernel.org> wrote:
>
> On 3/18/25 03:08, Daeho Jeong wrote:
> > From: Daeho Jeong <daehojeong@google.com>
> >
> > support a file truncation to zero size for device aliasing files.
> >
> > Signed-off-by: Daeho Jeong <daehojeong@google.com>
> > ---
> >  fs/f2fs/file.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index f92a9fba9991..7ae5a5af5ed9 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -1036,7 +1036,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
> >
> >       if ((attr->ia_valid & ATTR_SIZE)) {
> >               if (!f2fs_is_compress_backend_ready(inode) ||
> > -                             IS_DEVICE_ALIASING(inode))
> > +                             (IS_DEVICE_ALIASING(inode) && attr->ia_size))
> >                       return -EOPNOTSUPP;
> >               if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) &&
> >                       !IS_ALIGNED(attr->ia_size,
> > @@ -1117,6 +1117,9 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
> >               if (err)
> >                       return err;
>
> Daeho,
>
> If truncate(, 0) failed due to some reasons, maybe, the file was partially
> truncated, should we tag it as inconsistent status to avoid its later access?
> thoughts?

Hmm, looks like I did it wrong.
Instead of invoking f2fs_destroy_extent_tree(), I need to make the
length of the extent to zero when truncating the file.
Is it okay with you?

>
> Thanks,
>
> >
> > +             if (IS_DEVICE_ALIASING(inode))
> > +                     f2fs_destroy_extent_tree(inode);
> > +
> >               spin_lock(&fi->i_size_lock);
> >               inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
> >               fi->last_disk_size = i_size_read(inode);
>

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

end of thread, other threads:[~2025-03-21 21:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 19:08 [PATCH] f2fs: support zero sized file truncate for device aliasing files Daeho Jeong
2025-03-18  3:45 ` [f2fs-dev] " Chao Yu
2025-03-21 21:16   ` Daeho Jeong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox