On Fri, Sep 18, 2020 at 09:47:32AM +0800, Chao Yu wrote: > Ah, I got it. > > Step of enabling compressed inode is not correct, we should touch an empty > file, and then use 'chattr +c' on that file to enable compression, otherwise > the race condition could be complicated to handle. So we need below diff to > disallow setting compression flag on an non-empty file: > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 8a422400e824..b462db7898fd 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -1836,6 +1836,8 @@ static int f2fs_setflags_common(struct inode *inode, > u32 iflags, u32 mask) > if (iflags & F2FS_COMPR_FL) { > if (!f2fs_may_compress(inode)) > return -EINVAL; > + if (get_dirty_pages(inode) || fi->i_compr_blocks) > + return -EINVAL; > > set_compress_context(inode); > }
Why not: if (inode->i_size) return -EINVAL;