Skip to content

Commit 278a625

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to relocate check condition in f2fs_fallocate()
compress and pinfile flag should be checked after inode lock held to avoid race condition, fix it. Fixes: 4c8ff70 ("f2fs: support data compression") Fixes: 5fed0be ("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>
1 parent bd9ae4a commit 278a625

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

fs/f2fs/file.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,22 +1820,24 @@ static long f2fs_fallocate(struct file *file, int mode,
18201820
(mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)))
18211821
return -EOPNOTSUPP;
18221822

1823-
/*
1824-
* Pinned file should not support partial truncation since the block
1825-
* can be used by applications.
1826-
*/
1827-
if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) &&
1828-
(mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
1829-
FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)))
1830-
return -EOPNOTSUPP;
1831-
18321823
if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
18331824
FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
18341825
FALLOC_FL_INSERT_RANGE))
18351826
return -EOPNOTSUPP;
18361827

18371828
inode_lock(inode);
18381829

1830+
/*
1831+
* Pinned file should not support partial truncation since the block
1832+
* can be used by applications.
1833+
*/
1834+
if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) &&
1835+
(mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
1836+
FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) {
1837+
ret = -EOPNOTSUPP;
1838+
goto out;
1839+
}
1840+
18391841
ret = file_modified(file);
18401842
if (ret)
18411843
goto out;

0 commit comments

Comments
 (0)