fuse: truncate pending writes on O_TRUNC

Make sure cached writes are not reordered around open(..., O_TRUNC), with
the obvious wrong results.

Fixes: 4d99ff8f12 ("fuse: Turn writeback cache on")
Cc: <stable@vger.kernel.org> # v3.15+
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
Miklos Szeredi 2019-10-23 14:26:37 +02:00
parent b24e7598db
commit e4648309b8
1 changed files with 7 additions and 3 deletions

View File

@ -217,7 +217,7 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
{ {
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
int err; int err;
bool lock_inode = (file->f_flags & O_TRUNC) && bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
fc->atomic_o_trunc && fc->atomic_o_trunc &&
fc->writeback_cache; fc->writeback_cache;
@ -225,16 +225,20 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
if (err) if (err)
return err; return err;
if (lock_inode) if (is_wb_truncate) {
inode_lock(inode); inode_lock(inode);
fuse_set_nowrite(inode);
}
err = fuse_do_open(fc, get_node_id(inode), file, isdir); err = fuse_do_open(fc, get_node_id(inode), file, isdir);
if (!err) if (!err)
fuse_finish_open(inode, file); fuse_finish_open(inode, file);
if (lock_inode) if (is_wb_truncate) {
fuse_release_nowrite(inode);
inode_unlock(inode); inode_unlock(inode);
}
return err; return err;
} }