f2fs: fix to check return value of f2fs_do_truncate_blocks()
authorChao Yu <chao@kernel.org>
Wed, 5 Apr 2023 14:44:53 +0000 (22:44 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 13 Apr 2023 23:37:57 +0000 (16:37 -0700)
Otherwise, if truncation on cow_inode failed, remained data may
pollute current transaction of atomic write.

Cc: Daeho Jeong <daehojeong@google.com>
Fixes: a46bebd502fe ("f2fs: synchronize atomic write aborts")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index 14e9a20e68df39cc6a6dff8c2b6f0328dae26187..48a563cc0f34689b8e5a0a5fbb0e4ca6cc5c7e51 100644 (file)
@@ -2113,7 +2113,11 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
                clear_inode_flag(fi->cow_inode, FI_INLINE_DATA);
        } else {
                /* Reuse the already created COW inode */
-               f2fs_do_truncate_blocks(fi->cow_inode, 0, true);
+               ret = f2fs_do_truncate_blocks(fi->cow_inode, 0, true);
+               if (ret) {
+                       f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
+                       goto out;
+               }
        }
 
        f2fs_write_inode(inode, NULL);