Skip to contentSkip to conversation

f2fs: support zero sized file truncate for device aliasing files

PATCH Superseded Daeho Jeong 2 participants 3 messages Mar 17, 2025 – Mar 21, 2025 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: support zero sized file truncate for device aliasing files

From: Daeho Jeong <[email protected]>

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

---
 fs/f2fs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/file.c +4 -1
index f92a9fba9991..7ae5a5af5ed9 100644
@@ -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);
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
maintainer
#1 lore raw
Quoted 23 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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

---
 fs/f2fs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/file.c +1 -1
index f92a9fba9991..7ae5a5af5ed9 100644
@@ -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,

fs/f2fs/file.c int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 1118

Quoted 2 lines
fs/f2fs/file.c +0 -0
@@ -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,

Quoted 7 lines
fs/f2fs/file.c +3 -0
+		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 lore raw
Quoted 30 lines · Chao Yu
Quoted 23 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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

---
 fs/f2fs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/file.c +1 -1
index f92a9fba9991..7ae5a5af5ed9 100644
@@ -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,

fs/f2fs/file.c int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 1118

Quoted 2 lines
fs/f2fs/file.c +0 -0
@@ -1117,6 +1117,9 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
              if (err)
                      return err;

Daeho,

Quoted 3 lines

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?

Quoted 11 lines

Thanks,

Quoted 7 lines
fs/f2fs/file.c +3 -0
+             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);