Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp196581ybk; Tue, 19 May 2020 19:46:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxT3ohkq5edQxt1NX5OB2Bgib6762/KmlmCERsxKPNgey/w0tnnnhhof9euiXguNLrDV9ZT X-Received: by 2002:a50:cccc:: with SMTP id b12mr1419237edj.68.1589942809428; Tue, 19 May 2020 19:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589942809; cv=none; d=google.com; s=arc-20160816; b=lDeiKfVGfgtcnN41MZk++q2nBjJhRtEewLMUjPOlLQVERo+F5AImKAj8/JjFl0r7w/ WBKOyvDei737D140Z3Z+LEIkhWzTosPtvmyAaci3ODyIc0ymAYOQbXr4RIS/cr4rOFjj kRyYfmDL5eAQyrJjQ0e6ewqLcAoCEyY6aaZtF4koLhAMABdpa7lEYrB0dxfwQ8UXW56S 68Ju3TXyKbyJarwUJf1/rWWqqmqHQRdJDqAekIj45ej/7jtA3Z68cJIdhmo1sqMcoeUX 1Qvtuz/OIWNOJD9bMsfxLD3M4UfpK7S+ZdrOv2jtzkAAF1cHfgi+v01WBsmoBnfKu7yK tUmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=IqZFsPWu8IU8CnUCMjsvkORx2GcCX1M6A1w2Maedar0=; b=rGIHKJ0u0u9OuMhSU0mNCGHMsk/0EzbOWSGTKV0xA3WJIC50pXjtWvnBxfuIGE2FQX fU8s27oKMFq4sFZLKdplmTOLLJk6giU8PonPMtHgLYXfB//aRgH/15swOCKmvovwQx9v l7vp7YDLUcxuLFw2XoJ2PfNrQGEjClfqFpNro0ybqmbW4yxG0Mi9NtXnFtmjJ7pF1uo0 /k7ELxnM06u88Ohh2E9AnVA7jeaI/WW7N4b8skmkelpNtgVqJHFnYNCFkQXoPSzZhilB kPu+04iabGR+7lU4Nbef8XpWjcSHn8U8t15Q1QI5FaB/z71tFM/rjuMfLha2+gmymYl1 LdxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u23si1159801ejr.391.2020.05.19.19.46.14; Tue, 19 May 2020 19:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726379AbgETCqI (ORCPT + 99 others); Tue, 19 May 2020 22:46:08 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:41872 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726318AbgETCqI (ORCPT ); Tue, 19 May 2020 22:46:08 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D885EBD506E7E7080091; Wed, 20 May 2020 10:46:05 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Wed, 20 May 2020 10:45:58 +0800 From: Zheng Bin To: , , CC: , , Subject: [PATCH v2] nfs: set invalid blocks after NFSv4 writes Date: Wed, 20 May 2020 10:53:04 +0800 Message-ID: <20200520025305.85469-1-zhengbin13@huawei.com> X-Mailer: git-send-email 2.26.0.106.g9fadedd MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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: 16e143751727 ("NFS: More fine grained attribute tracking") Signed-off-by: Zheng Bin --- v1->v2: add STATX_BLOCKS check in nfs_getattr fs/nfs/inode.c | 11 +++++++++-- include/linux/nfs_fs.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index b9d0921cb4fe..0a89130a66c0 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -833,6 +833,8 @@ int nfs_getattr(const struct path *path, struct kstat *stat, do_update |= cache_validity & NFS_INO_INVALID_ATIME; if (request_mask & (STATX_CTIME|STATX_MTIME)) do_update |= cache_validity & NFS_INO_REVAL_PAGECACHE; + if (request_mask & STATX_BLOCKS) + do_update |= cache_validity & NFS_INO_INVALID_BLOCKS; if (do_update) { /* Update the attribute cache */ if (!(server->flags & NFS_MOUNT_NOAC)) @@ -1764,7 +1766,8 @@ int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fa status = nfs_post_op_update_inode_locked(inode, fattr, NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME - | NFS_INO_INVALID_MTIME); + | NFS_INO_INVALID_MTIME + | NFS_INO_INVALID_BLOCKS); return status; } @@ -2033,8 +2036,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) inode->i_blocks = fattr->du.nfs2.blocks; - else + else { + nfsi->cache_validity |= save_cache_validity & + (NFS_INO_INVALID_BLOCKS + | NFS_INO_REVAL_FORCED); cache_revalidated = false; + } /* Update attrtimeo value if we're out of the unstable period */ if (attr_changed) { diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 73eda45f1cfd..6ee9119acc5d 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -230,6 +230,7 @@ struct nfs4_copy_state { #define NFS_INO_INVALID_OTHER BIT(12) /* other attrs are invalid */ #define NFS_INO_DATA_INVAL_DEFER \ BIT(13) /* Deferred cache invalidation */ +#define NFS_INO_INVALID_BLOCKS BIT(14) /* cached blocks are invalid */ #define NFS_INO_INVALID_ATTR (NFS_INO_INVALID_CHANGE \ | NFS_INO_INVALID_CTIME \ -- 2.26.0.106.g9fadedd