public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Don't always trust server inode size while client holds write delegation
@ 2026-04-01 18:52 Dai Ngo
  2026-04-13 22:19 ` Trond Myklebust
  0 siblings, 1 reply; 2+ messages in thread
From: Dai Ngo @ 2026-04-01 18:52 UTC (permalink / raw)
  To: trondmy, anna; +Cc: linux-nfs

With a write delegation, the server permits the client to buffer writes
and associated metadata updates (including file size changes) locally and
defer propagating them to the server. As a result, the server-reported
GETATTR size may legitimately lag behind the client’s cached size for the
duration of the delegation, so it must not be treated as authoritative.

This patch modifies nfs_wcc_update_inode to update the cached inode size
only when the client does not hold a write delegation or the cache_validity
of the nfs_inode has the NFS_INO_INVALID_SIZE bit set.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
 fs/nfs/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 4786343eeee0..21161ebbd953 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1649,8 +1649,11 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 			&& (fattr->valid & NFS_ATTR_FATTR_SIZE)
 			&& i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
 			&& !nfs_have_writebacks(inode)) {
-		trace_nfs_size_wcc(inode, fattr->size);
-		i_size_write(inode, nfs_size_to_loff_t(fattr->size));
+		if ((!nfs_have_write_delegation(inode)) ||
+			(NFS_I(inode)->cache_validity & NFS_INO_INVALID_SIZE)) {
+			trace_nfs_size_wcc(inode, fattr->size);
+			i_size_write(inode, nfs_size_to_loff_t(fattr->size));
+		}
 	}
 }
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] Don't always trust server inode size while client holds write delegation
  2026-04-01 18:52 [PATCH 1/1] Don't always trust server inode size while client holds write delegation Dai Ngo
@ 2026-04-13 22:19 ` Trond Myklebust
  0 siblings, 0 replies; 2+ messages in thread
From: Trond Myklebust @ 2026-04-13 22:19 UTC (permalink / raw)
  To: Dai Ngo, anna; +Cc: linux-nfs

Hi Dai,

On Wed, 2026-04-01 at 11:52 -0700, Dai Ngo wrote:
> With a write delegation, the server permits the client to buffer
> writes
> and associated metadata updates (including file size changes) locally
> and
> defer propagating them to the server. As a result, the server-
> reported
> GETATTR size may legitimately lag behind the client’s cached size for
> the
> duration of the delegation, so it must not be treated as
> authoritative.
> 
> This patch modifies nfs_wcc_update_inode to update the cached inode
> size
> only when the client does not hold a write delegation or the
> cache_validity
> of the nfs_inode has the NFS_INO_INVALID_SIZE bit set.
> 
> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> ---
>  fs/nfs/inode.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
> index 4786343eeee0..21161ebbd953 100644
> --- a/fs/nfs/inode.c
> +++ b/fs/nfs/inode.c
> @@ -1649,8 +1649,11 @@ static void nfs_wcc_update_inode(struct inode
> *inode, struct nfs_fattr *fattr)
>  			&& (fattr->valid & NFS_ATTR_FATTR_SIZE)
>  			&& i_size_read(inode) ==
> nfs_size_to_loff_t(fattr->pre_size)
>  			&& !nfs_have_writebacks(inode)) {
> -		trace_nfs_size_wcc(inode, fattr->size);
> -		i_size_write(inode, nfs_size_to_loff_t(fattr-
> >size));
> +		if ((!nfs_have_write_delegation(inode)) ||
> +			(NFS_I(inode)->cache_validity &
> NFS_INO_INVALID_SIZE)) {
> +			trace_nfs_size_wcc(inode, fattr->size);
> +			i_size_write(inode,
> nfs_size_to_loff_t(fattr->size));
> +		}
>  	}
>  }
>  

Under what circumstances are you seeing this making a difference?
Please see the call to nfs_writeback_check_extend() in
nfs_writeback_update_inode() which is supposed to prevent the issue
you're talking about.

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-13 22:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 18:52 [PATCH 1/1] Don't always trust server inode size while client holds write delegation Dai Ngo
2026-04-13 22:19 ` Trond Myklebust

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox