Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

afs: Fix getattr to report server i_size on dirs, not local size

Fix afs_getattr() to report the server's idea of the file size of a
directory rather than the local size. The local size may differ as we edit
the local copy to avoid having to redownload it and we may end up with a
differently structured blob of a different size.

However, if the directory is discarded from the pagecache we then download
it again and the user may see the directory file size apparently change.

Fixes: 63a4681ff39c ("afs: Locally edit directory data for mkdir/create/unlink/...")
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org

+8 -1
+8 -1
fs/afs/inode.c
··· 450 450 0 : FSCACHE_ADV_SINGLE_CHUNK, 451 451 &key, sizeof(key), 452 452 &aux, sizeof(aux), 453 - vnode->status.size)); 453 + i_size_read(&vnode->netfs.inode))); 454 454 #endif 455 455 } 456 456 ··· 777 777 if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && 778 778 stat->nlink > 0) 779 779 stat->nlink -= 1; 780 + 781 + /* Lie about the size of directories. We maintain a locally 782 + * edited copy and may make different allocation decisions on 783 + * it, but we need to give userspace the server's size. 784 + */ 785 + if (S_ISDIR(inode->i_mode)) 786 + stat->size = vnode->netfs.remote_i_size; 780 787 } while (need_seqretry(&vnode->cb_lock, seq)); 781 788 782 789 done_seqretry(&vnode->cb_lock, seq);