Skip to content

Commit

Permalink
fuse: truncate pending writes on O_TRUNC
Browse files Browse the repository at this point in the history
Make sure cached writes are not reordered around open(..., O_TRUNC), with
the obvious wrong results.

Fixes: 4d99ff8 ("fuse: Turn writeback cache on")
Cc: <stable@vger.kernel.org> # v3.15+
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Miklos Szeredi committed Oct 23, 2019
1 parent b24e759 commit e464830
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,28 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
{
struct fuse_conn *fc = get_fuse_conn(inode);
int err;
bool lock_inode = (file->f_flags & O_TRUNC) &&
bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
fc->atomic_o_trunc &&
fc->writeback_cache;

err = generic_file_open(inode, file);
if (err)
return err;

if (lock_inode)
if (is_wb_truncate) {
inode_lock(inode);
fuse_set_nowrite(inode);
}

err = fuse_do_open(fc, get_node_id(inode), file, isdir);

if (!err)
fuse_finish_open(inode, file);

if (lock_inode)
if (is_wb_truncate) {
fuse_release_nowrite(inode);
inode_unlock(inode);
}

return err;
}
Expand Down

0 comments on commit e464830

Please sign in to comment.