OSDN Git Service

afs: Fix truncation issues and mmap writeback size
authorDavid Howells <dhowells@redhat.com>
Fri, 12 Jun 2020 15:13:52 +0000 (16:13 +0100)
committerDavid Howells <dhowells@redhat.com>
Mon, 15 Jun 2020 14:41:02 +0000 (15:41 +0100)
commit793fe82ee33aab1023cf023cd7d744af19a3dff9
tree7573b381e7c832b6c589e4057990e6db793567b4
parentda8d07551275abb3a38fae2d16e02bc9cc7396b2
afs: Fix truncation issues and mmap writeback size

Fix the following issues:

 (1) Fix writeback to reduce the size of a store operation to i_size,
     effectively discarding the extra data.

     The problem comes when afs_page_mkwrite() records that a page is about
     to be modified by mmap().  It doesn't know what bits of the page are
     going to be modified, so it records the whole page as being dirty
     (this is stored in page->private as start and end offsets).

     Without this, the marshalling for the store to the server extends the
     size of the file to the end of the page (in afs_fs_store_data() and
     yfs_fs_store_data()).

 (2) Fix setattr to actually truncate the pagecache, thereby clearing
     the discarded part of a file.

 (3) Fix setattr to check that the new size is okay and to disable
     ATTR_SIZE if i_size wouldn't change.

 (4) Force i_size to be updated as the result of a truncate.

 (5) Don't truncate if ATTR_SIZE is not set.

 (6) Call pagecache_isize_extended() if the file was enlarged.

Note that truncate_set_size() isn't used because the setting of i_size is
done inside afs_vnode_commit_status() under the vnode->cb_lock.

Found with the generic/029 and generic/393 xfstests.

Fixes: 31143d5d515e ("AFS: implement basic file write support")
Fixes: 4343d00872e1 ("afs: Get rid of the afs_writeback record")
Signed-off-by: David Howells <dhowells@redhat.com>
fs/afs/inode.c
fs/afs/internal.h
fs/afs/write.c