Skip to content

Commit 8018100

Browse files
Miklos Szeredigregkh
authored andcommitted
fuse: truncate pagecache on atomic_o_trunc
commit 7622435 upstream. fuse_finish_open() will be called with FUSE_NOWRITE in case of atomic O_TRUNC. This can deadlock with fuse_wait_on_page_writeback() in fuse_launder_page() triggered by invalidate_inode_pages2(). Fix by replacing invalidate_inode_pages2() in fuse_finish_open() with a truncate_pagecache() call. This makes sense regardless of FOPEN_KEEP_CACHE or fc->writeback cache, so do it unconditionally. Reported-by: Xie Yongji <[email protected]> Reported-and-tested-by: [email protected] Fixes: e464830 ("fuse: truncate pending writes on O_TRUNC") Cc: <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a8ca1fb commit 8018100

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/fuse/file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,26 @@ void fuse_finish_open(struct inode *inode, struct file *file)
194194
struct fuse_file *ff = file->private_data;
195195
struct fuse_conn *fc = get_fuse_conn(inode);
196196

197-
if (!(ff->open_flags & FOPEN_KEEP_CACHE))
198-
invalidate_inode_pages2(inode->i_mapping);
199197
if (ff->open_flags & FOPEN_STREAM)
200198
stream_open(inode, file);
201199
else if (ff->open_flags & FOPEN_NONSEEKABLE)
202200
nonseekable_open(inode, file);
201+
203202
if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
204203
struct fuse_inode *fi = get_fuse_inode(inode);
205204

206205
spin_lock(&fi->lock);
207206
fi->attr_version = atomic64_inc_return(&fc->attr_version);
208207
i_size_write(inode, 0);
209208
spin_unlock(&fi->lock);
209+
truncate_pagecache(inode, 0);
210210
fuse_invalidate_attr(inode);
211211
if (fc->writeback_cache)
212212
file_update_time(file);
213+
} else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) {
214+
invalidate_inode_pages2(inode->i_mapping);
213215
}
216+
214217
if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
215218
fuse_link_write_file(file);
216219
}

0 commit comments

Comments
 (0)