Skip to contentSkip to conversation

f2fs: do not allow to defragment files have FI_COMPRESS_RELEASED

PATCH In review Yangtao Li 3 participants 4 messages Apr 25, 2023 – Apr 28, 2023 F2FS file system

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH v2 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 | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/file.c +5 -0
index 5ac53d2627d2..46c62923f096 100644
@@ -2593,6 +2593,11 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
 
 	inode_lock(inode);
 
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
+		inode_unlock(inode);
+		return -EINVAL;
+	}
+
 	/* if in-place-update policy is enabled, don't waste time here */
 	set_inode_flag(inode, FI_OPU_WRITE);
 	if (f2fs_should_update_inplace(inode, NULL)) {
Signature · 1 line
2.39.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 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")

Oh, I just see v2.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#2 lore raw
Quoted 11 lines · Chao Yu
Quoted 6 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")

Oh, I just see v2.

Applied with using goto for code consistency.

+ if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
+ err = -EINVAL;
+ goto unlock_out;
+ }
+

        /* if in-place-update policy is enabled, don't waste time here */
        set_inode_flag(inode, FI_OPU_WRITE);
        if (f2fs_should_update_inplace(inode, NULL)) {
@@ -2712,6 +2717,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
        clear_inode_flag(inode, FI_SKIP_WRITES);
 out:
        clear_inode_flag(inode, FI_OPU_WRITE);
+unlock_out:
        inode_unlock(inode);
        if (!err)
                range->len = (u64)total << PAGE_SHIFT;
Quoted 2 lines

Thanks,

maintainer Reviewed-by
#3 lore raw
Quoted 9 lines · Jaegeuk Kim
Quoted 8 lines · Chao Yu
Quoted 6 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")
Quoted 5 lines
Quoted 3 lines

Oh, I just see v2.

Applied with using goto for code consistency.

It makes sense,

Thanks,

Quoted 20 lines
fs/f2fs/file.c +6 -0
+       if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
+               err = -EINVAL;
+               goto unlock_out;
+       }
+
         /* if in-place-update policy is enabled, don't waste time here */
         set_inode_flag(inode, FI_OPU_WRITE);
         if (f2fs_should_update_inplace(inode, NULL)) {
@@ -2712,6 +2717,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
         clear_inode_flag(inode, FI_SKIP_WRITES);
  out:
         clear_inode_flag(inode, FI_OPU_WRITE);
+unlock_out:
         inode_unlock(inode);
         if (!err)
                 range->len = (u64)total << PAGE_SHIFT;
Quoted 3 lines

Thanks,