@@ -3170,6 +3170,20 @@ static inline int f2fs_compressed_file(struct inode *inode)
is_inode_flag_set(inode, FI_COMPRESSED_FILE);
}
+static inline bool f2fs_is_compressed_file(struct inode *inode)
+{
+ int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode;
+
+ if (compress_mode == COMPR_MODE_FS)
+ return f2fs_compressed_file(inode);
+ else if (atomic_read(&F2FS_I(inode)->i_compr_blocks) ||
+ is_inode_flag_set(inode, FI_COMPRESS_RELEASED) ||
+ is_inode_flag_set(inode, FI_ENABLE_COMPRESS))
+ return true;
+
+ return false;
+}
+
static inline bool f2fs_need_compress_data(struct inode *inode)
{
int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode;
@@ -822,7 +822,7 @@ static bool f2fs_force_buffered_io(struct inode *inode, int rw)
return true;
if (fsverity_active(inode))
return true;
- if (f2fs_compressed_file(inode))
+ if (f2fs_is_compressed_file(inode))
return true;
/* disallow direct IO if any of devices has unaligned blksize */
@@ -4146,6 +4146,9 @@ static int f2fs_ioc_compress_file(struct file *filp)
goto out;
}
+ /* avoid race case between aio and ioc_compress_file */
+ inode_dio_wait(inode);
+
ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
if (ret)
goto out;