Skip to contentSkip to conversation

f2fs: do not allow to defragment files have FI_COMPRESS_RELEASED

PATCH Superseded Yangtao Li 2 participants 2 messages Apr 25, 2023 – Apr 27, 2023 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 f2fs: do not allow to defragment files have FI_COMPRESS_RELEASED

If a file has FI_COMPRESS_RELEASED, all writes for it should not be allowed.

Fixes 5fdb322ff2c2 ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE")
---
 fs/f2fs/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/file.c +3 -0
index 9c9c3f660e01..c21d6a829c4a 100644
@@ -2734,6 +2734,9 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)
 	if (f2fs_readonly(sbi->sb))
 		return -EROFS;
 
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
+		return -EINVAL;
+
 	if (copy_from_user(&range, (struct f2fs_defragment __user *)arg,
 							sizeof(range)))
 		return -EFAULT;
Signature · 1 line
2.39.0
maintainer
#1 lore raw
Quoted 15 lines · Yangtao Li

If a file has FI_COMPRESS_RELEASED, all writes for it should not be allowed.

Fixes 5fdb322ff2c2 ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE")
---
  fs/f2fs/file.c | 3 +++
  1 file changed, 3 insertions(+)
fs/f2fs/file.c +0 -0
index 9c9c3f660e01..c21d6a829c4a 100644

fs/f2fs/file.c static int f2fs_ioc_defragment(struct file *filp, unsigned long arg) · line 2738

Quoted 5 lines
fs/f2fs/file.c +2 -0
@@ -2734,6 +2734,9 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)
  	if (f2fs_readonly(sbi->sb))
  		return -EROFS;
 
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
+		return -EINVAL;

This flag should be checked w/ inode lock.

Thanks,

Quoted 4 lines
fs/f2fs/file.c +1 -0
+
  	if (copy_from_user(&range, (struct f2fs_defragment __user *)arg,
  							sizeof(range)))
  		return -EFAULT;