Skip to content

Commit a74ee0e

Browse files
dhowellsbrauner
authored andcommitted
afs: Fix post-setattr file edit to do truncation correctly
At the end of an kAFS RPC operation, there is an "edit" phase (originally intended for post-directory modification ops to edit the local image) that the setattr VFS op uses to fix up the pagecache if the RPC that requested truncation of a file was successful. afs_setattr_edit_file() calls truncate_setsize() which sets i_size, expands the pagecache if needed and truncates the pagecache. The first two of those, however, are redundant as they've already been done by afs_setattr_success() under the io_lock and the first is also done under the callback lock (cb_lock). Fix afs_setattr_edit_file() to call truncate_pagecache() instead (which is called by truncate_setsize(), thereby skipping the redundant parts. Fixes: 100ccd1 ("netfs: Optimise away reads above the point at which there can be no data") Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/r/[email protected] cc: Matthew Wilcox (Oracle) <[email protected]> cc: Pankaj Raghav <[email protected]> cc: Jeff Layton <[email protected]> cc: Marc Dionne <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] cc: [email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 0aa2e1b commit a74ee0e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/afs/inode.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,18 @@ static void afs_setattr_edit_file(struct afs_operation *op)
695695
{
696696
struct afs_vnode_param *vp = &op->file[0];
697697
struct afs_vnode *vnode = vp->vnode;
698+
struct inode *inode = &vnode->netfs.inode;
698699

699700
if (op->setattr.attr->ia_valid & ATTR_SIZE) {
700701
loff_t size = op->setattr.attr->ia_size;
701-
loff_t i_size = op->setattr.old_i_size;
702+
loff_t old = op->setattr.old_i_size;
703+
704+
/* Note: inode->i_size was updated by afs_apply_status() inside
705+
* the I/O and callback locks.
706+
*/
702707

703-
if (size != i_size) {
704-
truncate_setsize(&vnode->netfs.inode, size);
708+
if (size != old) {
709+
truncate_pagecache(inode, size);
705710
netfs_resize_file(&vnode->netfs, size, true);
706711
fscache_resize_cookie(afs_vnode_cache(vnode), size);
707712
}

0 commit comments

Comments
 (0)