Skip to content

Commit 5dbc746

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
Pull fuse bugfix from Miklos Szeredi: "This fixes a race between fallocate() and truncate()" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: hold i_mutex in fuse_file_fallocate()
2 parents f97f7d2 + 14c1441 commit 5dbc746

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎fs/fuse/file.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,13 +2470,16 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
24702470
.mode = mode
24712471
};
24722472
int err;
2473+
bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
2474+
(mode & FALLOC_FL_PUNCH_HOLE);
24732475

24742476
if (fc->no_fallocate)
24752477
return -EOPNOTSUPP;
24762478

2477-
if (mode & FALLOC_FL_PUNCH_HOLE) {
2479+
if (lock_inode) {
24782480
mutex_lock(&inode->i_mutex);
2479-
fuse_set_nowrite(inode);
2481+
if (mode & FALLOC_FL_PUNCH_HOLE)
2482+
fuse_set_nowrite(inode);
24802483
}
24812484

24822485
req = fuse_get_req_nopages(fc);
@@ -2511,8 +2514,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
25112514
fuse_invalidate_attr(inode);
25122515

25132516
out:
2514-
if (mode & FALLOC_FL_PUNCH_HOLE) {
2515-
fuse_release_nowrite(inode);
2517+
if (lock_inode) {
2518+
if (mode & FALLOC_FL_PUNCH_HOLE)
2519+
fuse_release_nowrite(inode);
25162520
mutex_unlock(&inode->i_mutex);
25172521
}
25182522

0 commit comments

Comments
 (0)