f2fs: compress: disallow disabling compress on non-empty compressed file

[ Upstream commit 02d58cd253d7536c412993573fc6b3b4454960eb ]

Compresse file and normal file has differ in i_addr addressing,
specifically addrs per inode/block. So, we will face data loss, if we
disable the compression flag on non-empty files. Therefore we should
disallow not only enabling but disabling the compression flag on
non-empty files.

Fixes: 4c8ff7095b ("f2fs: support data compression")
Signed-off-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Hyeong-Jun Kim <hj514.kim@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Hyeong-Jun Kim 2021-10-27 13:16:00 +09:00 committed by Greg Kroah-Hartman
parent 4ce685cc9a
commit 0a17fff6f0

View File

@ -3908,8 +3908,7 @@ static inline bool f2fs_disable_compressed_file(struct inode *inode)
if (!f2fs_compressed_file(inode)) if (!f2fs_compressed_file(inode))
return true; return true;
if (S_ISREG(inode->i_mode) && if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
(get_dirty_pages(inode) || atomic_read(&fi->i_compr_blocks)))
return false; return false;
fi->i_flags &= ~F2FS_COMPR_FL; fi->i_flags &= ~F2FS_COMPR_FL;