• Zheng Bin's avatar
    nfs: set invalid blocks after NFSv4 writes · 3a39e778
    Zheng Bin authored
    Use the following command to test nfsv4(size of file1M is 1MB):
    mount -t nfs -o vers=4.0,actimeo=60 127.0.0.1/dir1 /mnt
    cp file1M /mnt
    du -h /mnt/file1M  -->0 within 60s, then 1M
    
    When write is done(cp file1M /mnt), will call this:
    nfs_writeback_done
      nfs4_write_done
        nfs4_write_done_cb
          nfs_writeback_update_inode
            nfs_post_op_update_inode_force_wcc_locked(change, ctime, mtime
    nfs_post_op_update_inode_force_wcc_locked
       nfs_set_cache_invalid
       nfs_refresh_inode_locked
         nfs_update_inode
    
    nfsd write response contains change, ctime, mtime, the flag will be
    clear after nfs_update_inode. Howerver, write response does not contain
    space_used, previous open response contains space_used whose value is 0,
    so inode->i_blocks is still 0.
    
    nfs_getattr  -->called by "du -h"
      do_update |= force_sync || nfs_attribute_cache_expired -->false in 60s
      cache_validity = READ_ONCE(NFS_I(inode)->cache_validity)
      do_update |= cache_validity & (NFS_INO_INVALID_ATTR    -->false
      if (do_update) {
            __nfs_revalidate_inode
      }
    
    Within 60s, does not send getattr request to nfsd, thus "du -h /mnt/file1M"
    is 0.
    
    Add a NFS_INO_INVALID_BLOCKS flag, set it when nfsv4 write is done.
    
    Fixes: 16e14375 ("NFS: More fine grained attribute tracking")
    Signed-off-by: default avatarZheng Bin <zhengbin13@huawei.com>
    Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
    3a39e778
nfs_fs.h 16.9 KB