Skip to content

Commit 280227a

Browse files
dccitytso
authored andcommitted
ext4: move check under lock scope to close a race.
fallocate() checks that the file is extent-based and returns EOPNOTSUPP in case is not. Other tasks can convert from and to indirect and extent so it's safe to check only after grabbing the inode mutex. Signed-off-by: Davide Italiano <dccitaliano@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent d2dc317 commit 280227a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/ext4/extents.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4927,13 +4927,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
49274927
if (ret)
49284928
return ret;
49294929

4930-
/*
4931-
* currently supporting (pre)allocate mode for extent-based
4932-
* files _only_
4933-
*/
4934-
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
4935-
return -EOPNOTSUPP;
4936-
49374930
if (mode & FALLOC_FL_COLLAPSE_RANGE)
49384931
return ext4_collapse_range(inode, offset, len);
49394932

@@ -4955,6 +4948,14 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
49554948

49564949
mutex_lock(&inode->i_mutex);
49574950

4951+
/*
4952+
* We only support preallocation for extent-based files only
4953+
*/
4954+
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
4955+
ret = -EOPNOTSUPP;
4956+
goto out;
4957+
}
4958+
49584959
if (!(mode & FALLOC_FL_KEEP_SIZE) &&
49594960
offset + len > i_size_read(inode)) {
49604961
new_size = offset + len;

0 commit comments

Comments
 (0)