Skip to content

Commit df0e91d

Browse files
author
Miklos Szeredi
committed
fuse: atomic_o_trunc should truncate pagecache
Fuse has an "atomic_o_trunc" mode, where userspace filesystem uses the O_TRUNC flag in the OPEN request to truncate the file atomically with the open. In this mode there's no need to send a SETATTR request to userspace after the open, so fuse_do_setattr() checks this mode and returns. But this misses the important step of truncating the pagecache. Add the missing parts of truncation to the ATTR_OPEN branch. Reported-by: Chad Austin <[email protected]> Fixes: 6ff958e ("fuse: add atomic open+truncate support") Signed-off-by: Miklos Szeredi <[email protected]> Cc: <[email protected]>
1 parent c698ca5 commit df0e91d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

fs/fuse/dir.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,8 +1629,19 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
16291629
return err;
16301630

16311631
if (attr->ia_valid & ATTR_OPEN) {
1632-
if (fc->atomic_o_trunc)
1632+
/* This is coming from open(..., ... | O_TRUNC); */
1633+
WARN_ON(!(attr->ia_valid & ATTR_SIZE));
1634+
WARN_ON(attr->ia_size != 0);
1635+
if (fc->atomic_o_trunc) {
1636+
/*
1637+
* No need to send request to userspace, since actual
1638+
* truncation has already been done by OPEN. But still
1639+
* need to truncate page cache.
1640+
*/
1641+
i_size_write(inode, 0);
1642+
truncate_pagecache(inode, 0);
16331643
return 0;
1644+
}
16341645
file = NULL;
16351646
}
16361647

0 commit comments

Comments
 (0)