Skip to content

Commit e464830

Browse files
author
Miklos Szeredi
committed
fuse: truncate pending writes on O_TRUNC
Make sure cached writes are not reordered around open(..., O_TRUNC), with the obvious wrong results. Fixes: 4d99ff8 ("fuse: Turn writeback cache on") Cc: <[email protected]> # v3.15+ Signed-off-by: Miklos Szeredi <[email protected]>
1 parent b24e759 commit e464830

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/fuse/file.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,28 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
217217
{
218218
struct fuse_conn *fc = get_fuse_conn(inode);
219219
int err;
220-
bool lock_inode = (file->f_flags & O_TRUNC) &&
220+
bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
221221
fc->atomic_o_trunc &&
222222
fc->writeback_cache;
223223

224224
err = generic_file_open(inode, file);
225225
if (err)
226226
return err;
227227

228-
if (lock_inode)
228+
if (is_wb_truncate) {
229229
inode_lock(inode);
230+
fuse_set_nowrite(inode);
231+
}
230232

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

233235
if (!err)
234236
fuse_finish_open(inode, file);
235237

236-
if (lock_inode)
238+
if (is_wb_truncate) {
239+
fuse_release_nowrite(inode);
237240
inode_unlock(inode);
241+
}
238242

239243
return err;
240244
}

0 commit comments

Comments
 (0)