Skip to contentSkip to conversation

f2fs: support zero sized file truncate for device aliasing files

PATCH In review Daeho Jeong 3 participants 4 messages Mar 21, 2025 – Mar 25, 2025 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
v2: make the extent length zero

---
 fs/f2fs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/file.c +6 -1
index f92a9fba9991..69952f208086 100644
@@ -775,6 +775,11 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
 		f2fs_update_time(sbi, REQ_TIME);
 
 		f2fs_put_page(ipage, 1);
+
+		write_lock(&et->lock);
+		et->largest.len = 0;
+		write_unlock(&et->lock);
+
 		goto out;
 	}
 
@@ -1036,7 +1041,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,
Signature · 1 line
2.49.0.395.g12beb8f557-goog
maintainer
#1 lore raw

Do we still need this patch?

Quoted 39 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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

---
v2: make the extent length zero

---
 fs/f2fs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/file.c +6 -1
index f92a9fba9991..69952f208086 100644
@@ -775,6 +775,11 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
 		f2fs_update_time(sbi, REQ_TIME);
 
 		f2fs_put_page(ipage, 1);
+
+		write_lock(&et->lock);
+		et->largest.len = 0;
+		write_unlock(&et->lock);
+
 		goto out;
 	}
 
@@ -1036,7 +1041,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,
Signature · 1 line
2.49.0.395.g12beb8f557-goog
#2 lore raw
Quoted 2 lines · Jaegeuk Kim

Do we still need this patch?

Yes, in many circumstances, we cannot remove the aliasing file because of SELinux.

Quoted 41 lines · Daeho Jeong
Quoted 39 lines

From: Daeho Jeong <[email protected]>

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

---
v2: make the extent length zero

---
 fs/f2fs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/file.c +6 -2
index f92a9fba9991..69952f208086 100644
@@ -775,6 +775,11 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
              f2fs_update_time(sbi, REQ_TIME);
 
              f2fs_put_page(ipage, 1);
+
+             write_lock(&et->lock);
+             et->largest.len = 0;
+             write_unlock(&et->lock);
+
              goto out;
      }
 
@@ -1036,7 +1041,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,
--

2.49.0.395.g12beb8f557-goog

maintainer
#3 lore raw
In reply to Daeho Jeong
Quoted 16 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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

---
v2: make the extent length zero

---
 fs/f2fs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/file.c +0 -0
index f92a9fba9991..69952f208086 100644

fs/f2fs/file.c int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock) · line 781

Quoted 7 lines
fs/f2fs/file.c +4 -0
@@ -775,6 +775,11 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
 		f2fs_update_time(sbi, REQ_TIME);
 
 		f2fs_put_page(ipage, 1);
+
+		write_lock(&et->lock);
+		et->largest.len = 0;
+		write_unlock(&et->lock);

f2fs_mark_inode_dirty_sync(inode, true); ?

Thanks,

Quoted 13 lines
fs/f2fs/file.c +2 -1
+
 		goto out;
 	}
 
@@ -1036,7 +1041,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,