Re: [PATCH] f2fs: fix to enable compress for newly created file if extension matches

From: Chao Yu
Date: Wed Nov 09 2022 - 08:57:27 EST


On 2022/11/9 19:01, Sheng Yong wrote:
If compress_extension is set, and a newly created file matches the
extension, the file could be marked as compression file. However,
if inline_data is also enabled, there is no chance to check its
extension since f2fs_should_compress() always returns false.

So if a new file is created (its inode has I_NEW flag and must have
no pin/atomic/swap flag), instead of calling f2fs_should_compress(),
checking its file type is enough here.

Signed-off-by: Sheng Yong <shengyong@xxxxxxxx>
---
fs/f2fs/namei.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index e104409c3a0e5..99dbd051ae0ba 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -295,9 +295,14 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,

if (!f2fs_sb_has_compression(sbi) ||
F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
- !f2fs_may_compress(inode) ||
(!ext_cnt && !noext_cnt))
return;
+ if (inode->i_state & I_NEW) {
+ if (!S_ISREG(inode->i_mode))
+ return;
+ } else if (!f2fs_may_compress(inode)) {
+ return;
+ }

How about moving set_compress_inode() into f2fs_new_inode()?

if (f2fs_sb_has_compression(sbi)) {
/* Inherit the compression flag in directory */
if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) &&
f2fs_may_compress(inode))
set_compress_context(inode);

set_compress_inode(sbi, inode, name);
}

/* Should enable inline_data after compression set */
if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
set_inode_flag(inode, FI_INLINE_DATA);


f2fs_down_read(&sbi->sb_lock);

--
2.25.1