f2fs: compress: allow write compress released file after truncate to zero
authorFengnan Chang <changfengnan@vivo.com>
Mon, 9 Aug 2021 02:21:04 +0000 (10:21 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 17 Aug 2021 18:59:04 +0000 (11:59 -0700)
For compressed file, after release compress blocks, don't allow write
direct, but we should allow write direct after truncate to zero.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/filesystems/f2fs.rst
fs/f2fs/file.c

index 8f251a6625424f114843e1a2ed9ed84cce8f681c..9b0517d900637266efd766f448fa77bb947d3d7a 100644 (file)
@@ -865,8 +865,11 @@ Compression implementation
   directly in order to guarantee potential data updates later to the space.
   Instead, the main goal is to reduce data writes to flash disk as much as
   possible, resulting in extending disk life time as well as relaxing IO
-  congestion. Alternatively, we've added ioctl interface to reclaim compressed
-  space and show it to user after putting the immutable bit.
+  congestion. Alternatively, we've added ioctl(F2FS_IOC_RELEASE_COMPRESS_BLOCKS)
+  interface to reclaim compressed space and show it to user after putting the
+  immutable bit. Immutable bit, after release, it doesn't allow writing/mmaping
+  on the file, until reserving compressed space via
+  ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) or truncating filesize to zero.
 
 Compress metadata layout::
 
index 7d8ee60f6c1f987857b6b01c347a297f0d186b58..d4fc5e0d2ffe166dcf712d6ec7fd40afc68d505a 100644 (file)
@@ -753,6 +753,14 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock)
                return err;
 
 #ifdef CONFIG_F2FS_FS_COMPRESSION
+       /*
+        * For compressed file, after release compress blocks, don't allow write
+        * direct, but we should allow write direct after truncate to zero.
+        */
+       if (f2fs_compressed_file(inode) && !free_from
+                       && is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
+               clear_inode_flag(inode, FI_COMPRESS_RELEASED);
+
        if (from != free_from) {
                err = f2fs_truncate_partial_cluster(inode, from, lock);
                if (err)