diff options
author | Chao Yu <chao@kernel.org> | 2024-04-03 22:24:19 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-06-16 13:32:18 +0200 |
commit | 2b16554fb26db0185ef9cfa4110c8c47b09c8626 (patch) | |
tree | 1e8f24abd6b316b795a70055d15f240542321cd2 | |
parent | f1169d2b2aa2ece587db5398494a83e881f664b2 (diff) | |
download | linux-stable-2b16554fb26db0185ef9cfa4110c8c47b09c8626.tar.gz linux-stable-2b16554fb26db0185ef9cfa4110c8c47b09c8626.tar.bz2 linux-stable-2b16554fb26db0185ef9cfa4110c8c47b09c8626.zip |
f2fs: fix to relocate check condition in f2fs_fallocate()
[ Upstream commit 278a6253a673611dbc8ab72a3b34b151a8e75822 ]
compress and pinfile flag should be checked after inode lock held to
avoid race condition, fix it.
Fixes: 4c8ff7095bef ("f2fs: support data compression")
Fixes: 5fed0be8583f ("f2fs: do not allow partial truncation on pinned file")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | fs/f2fs/file.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 367b19f059f3..9cf04b9d3ad8 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1745,15 +1745,6 @@ static long f2fs_fallocate(struct file *file, int mode, (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))) return -EOPNOTSUPP; - /* - * Pinned file should not support partial truncation since the block - * can be used by applications. - */ - if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && - (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | - FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) - return -EOPNOTSUPP; - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)) @@ -1761,6 +1752,17 @@ static long f2fs_fallocate(struct file *file, int mode, inode_lock(inode); + /* + * Pinned file should not support partial truncation since the block + * can be used by applications. + */ + if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && + (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | + FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) { + ret = -EOPNOTSUPP; + goto out; + } + ret = file_modified(file); if (ret) goto out; |