From: "Chuck Lever" <cel@kernel.org>
To: "Scott Mayhew" <smayhew@redhat.com>,
"Chuck Lever" <chuck.lever@oracle.com>,
"Jeff Layton" <jlayton@kernel.org>
Cc: NeilBrown <neil@brown.name>,
"Olga Kornievskaia" <okorniev@redhat.com>,
"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH] nfsd: fix file change detection in CB_GETATTR
Date: Fri, 03 Apr 2026 10:31:29 -0400 [thread overview]
Message-ID: <7ab0da92-bb0e-466a-b566-acc832ae56c2@app.fastmail.com> (raw)
In-Reply-To: <20260403132209.1479385-1-smayhew@redhat.com>
On Fri, Apr 3, 2026, at 9:22 AM, Scott Mayhew wrote:
> RFC 8881, section 10.4.3 doesn't say anything about caching the file
> size in the delegation record, nor does it say anything about comparing
> a cached file size with the size reported by the client in the
> CB_GETATTR reply for the purpose of determining if the client holds
> modified data for the file.
>
> What section 10.4.3 of RFC 8881 does say is that the server should
> compare the *current* file size with size reported by the client holding
> the delegation in the CB_GETATTR reply, and if they differ to treat it
> as a modification regardless of the change attribute retrieved via the
> CB_GETATTR.
>
> Doing otherwise would cause the server to believe the client holding the
> delegation has a modified version of the file, even if the client
> flushed the modifications to the server prior to the CB_GETATTR. This
> would have the added side effect of subsequent CB_GETATTRs causing
> updates to the mtime, ctime, and change attribute even if the client
> holding the delegation makes no further updates to the file.
>
> Modify nfsd4_deleg_getattr_conflict() to obtain the current file size
> via vfs_getattr(). Retain the ncf_cur_fsize field, since it's a
> convenient way to return the file size back to nfsd4_encode_fattr4(),
> but don't use it for the purpose of detecting file changes.
>
> Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation")
> Signed-off-by: Scott Mayhew <smayhew@redhat.com>
> ---
> Note this patch is against Chuck's nfsd-next branch.
Thanks for the patch! I prefer patches against nfsd-testing, though
this patch applied just fine there. This fix will likely go in via
an early 7.1-rc PR.
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index b4d0e82b2690..2c82438918f6 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -9372,7 +9372,7 @@ static int cb_getattr_update_times(struct dentry
> *dentry, struct nfs4_delegation
> * caller must put the reference.
> */
> __be32
> -nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry
> *dentry,
> +nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct path *path,
> struct nfs4_delegation **pdp)
The kernel-doc comment for nfsd4_deleg_getattr_conflict also
needs to be updated since you have modified the name of one
of its parameters.
> {
> struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
> @@ -9381,7 +9381,9 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst
> *rqstp, struct dentry *dentry,
> struct nfs4_delegation *dp = NULL;
> struct file_lease *fl;
> struct nfs4_cb_fattr *ncf;
> - struct inode *inode = d_inode(dentry);
> + struct inode *inode = d_inode(path->dentry);
Nit: relocate this declaration to maintain reverse-christmas
tree ordering
> + struct kstat stat;
A minor concern here -- The caller already allocates its own
struct kstat via struct nfsd4_fattr_args. Two kstat instances
on the stack simultaneously is meaningful on 8KB stacks. Worth
verifying with scripts/checkstack.pl, especially under
CONFIG_KASAN or CONFIG_FRAME_WARN builds.
> + int err;
> __be32 status;
>
> ctx = locks_inode_context(inode);
> @@ -9430,19 +9432,22 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst
> *rqstp, struct dentry *dentry,
> !nfsd_wait_for_delegreturn(rqstp, inode))
> goto out_status;
> }
> + err = vfs_getattr(path, &stat, STATX_SIZE, AT_STATX_SYNC_AS_STAT);
> + if (err) {
> + status = nfserrno(err);
> + goto out_status;
> + }
When ncf_file_modified is already true (set on a prior call),
the check at line 9527 is skipped, so stat.size is never used.
Perhaps the new vfs_getattr() could be skipped in that case.
Also, after a successful delegation recall, proceeding with
CB_GETATTR comparison logic is probably unnecessary. But that
particular control flow predates your patch.
> if (!ncf->ncf_file_modified &&
> (ncf->ncf_initial_cinfo != ncf->ncf_cb_change ||
> - ncf->ncf_cur_fsize != ncf->ncf_cb_fsize))
> + stat.size != ncf->ncf_cb_fsize))
> ncf->ncf_file_modified = true;
> if (ncf->ncf_file_modified) {
> - int err;
> -
> /*
> * Per section 10.4.3 of RFC 8881, the server would
> * not update the file's metadata with the client's
> * modified size
> */
> - err = cb_getattr_update_times(dentry, dp);
> + err = cb_getattr_update_times(path->dentry, dp);
> if (err) {
> status = nfserrno(err);
> goto out_status;
--
Chuck Lever
prev parent reply other threads:[~2026-04-03 14:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 13:22 [PATCH] nfsd: fix file change detection in CB_GETATTR Scott Mayhew
2026-04-03 14:25 ` Jeff Layton
2026-04-03 14:31 ` Chuck Lever [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7ab0da92-bb0e-466a-b566-acc832ae56c2@app.fastmail.com \
--to=cel@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=smayhew@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).