mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neil@brown.name>,
	 Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>,  Tom Talpey <tom@talpey.com>,
	Christian Brauner <brauner@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Jeff Layton <jlayton@kernel.org>
Subject: [PATCH 07/11] nfsd: recall when a CB_GETATTR reply omits the size
Date: Fri, 20 Nov 2026 08:40:13 -0800	[thread overview]
Message-ID: <20261120-delegts-fixes-v1-7-c89b37d2d462@kernel.org> (raw)
In-Reply-To: <20261120-delegts-fixes-v1-0-c89b37d2d462@kernel.org>

decode_cb_fattr4() zeroes ncf_cb_fsize and fills it in only if the
reply's bitmap includes SIZE. nfsd4_deleg_getattr_conflict() doesn't
look at that bitmap. For a reply without SIZE, a non-empty file's size
doesn't match zero, so the waiter marks the file modified, sets
ncf_cur_fsize to zero, and GETATTR reports the file as empty to
everyone but the delegation holder.

The server always requests SIZE, and a holder may have changed it.
Keep word 0 of the reply's bitmap, cleared when the callback is issued,
and in nfsd4_cb_getattr_done() treat a reply without SIZE as failed.
The waiter then recalls the delegation, as it does for any other
CB_GETATTR failure.

A reply that omits CHANGE is left alone: the zero change attribute
mismatches, so the file is treated as modified, which is the safe
answer.

Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfsd/nfs4callback.c | 1 +
 fs/nfsd/nfs4state.c    | 8 ++++++++
 fs/nfsd/state.h        | 1 +
 3 files changed, 10 insertions(+)

diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 70ab4fd32195..ac65ba4c4b7d 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -737,6 +737,7 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp,
 		return status;
 	if (xdr_stream_decode_uint32_array(xdr, bitmap, 3) < 0)
 		return -EIO;
+	ncf->ncf_cb_bitmap0 = bitmap[0];
 	if (xdr_stream_decode_u32(xdr, &attrlen) < 0)
 		return -EIO;
 	maxlen = sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize);
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 0cd139ee0048..eead615aac0a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -3876,6 +3876,13 @@ nfsd4_cb_getattr_done(struct nfsd4_callback *cb, struct rpc_task *task)
 
 	trace_nfsd_cb_getattr_done(&dp->dl_stid.sc_stateid, task);
 	ncf->ncf_cb_status = task->tk_status;
+	/*
+	 * A reply without SIZE leaves ncf_cb_fsize at zero, which the
+	 * waiter would report as the file's size. Fail it, so the waiter
+	 * recalls the delegation instead.
+	 */
+	if (!task->tk_status && !(ncf->ncf_cb_bitmap0 & FATTR4_WORD0_SIZE))
+		ncf->ncf_cb_status = NFS4ERR_IO;
 	switch (task->tk_status) {
 	case -NFS4ERR_DELAY:
 		rpc_delay(task, 2 * HZ);
@@ -4123,6 +4130,7 @@ static void nfs4_cb_getattr(struct nfs4_cb_fattr *ncf)
 
 	/* set to proper status when nfsd4_cb_getattr_done runs */
 	ncf->ncf_cb_status = NFS4ERR_IO;
+	ncf->ncf_cb_bitmap0 = 0;
 
 	/* ensure that wake_bit is done when RUNNING is cleared */
 	set_bit(NFSD4_CALLBACK_WAKE, &ncf->ncf_getattr.cb_flags);
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index f80abcc278f6..c5f607049aaf 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -205,6 +205,7 @@ struct nfs4_cb_fattr {
 	u32 ncf_cb_status;
 
 	/* from CB_GETATTR reply */
+	u32 ncf_cb_bitmap0;		/* word 0 of the returned bitmap */
 	u64 ncf_cb_change;
 	u64 ncf_cb_fsize;
 	struct timespec64 ncf_cb_mtime;

-- 
2.56.1


  parent reply	other threads:[~2026-11-20 16:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:40 [PATCH 00/11] nfsd: various delegated timestamp fixes Jeff Layton
2026-11-20 16:40 ` [PATCH 01/11] nfsd: don't hold inode_lock while waiting for a delegation in nfsd_setattr() Jeff Layton
2026-11-20 16:40 ` [PATCH 02/11] nfsd: take freeze protection before updating delegation timestamps Jeff Layton
2026-11-20 16:40 ` [PATCH 03/11] nfsd: count a delegation in cl_delegs_in_recall only once Jeff Layton
2026-11-20 16:40 ` [PATCH 04/11] nfsd: don't grant write delegations to NFSv4.0 clients on CLAIM_PREVIOUS Jeff Layton
2026-11-20 16:40 ` [PATCH 05/11] nfsd: set ctime when a SETATTR with delegated times changes other attributes Jeff Layton
2026-11-20 16:40 ` [PATCH 06/11] nfsd: pin the client while a GETATTR holds a conflicting delegation Jeff Layton
2026-11-20 16:40 ` Jeff Layton [this message]
2026-11-20 16:40 ` [PATCH 08/11] nfsd: apply delegated times in a separate times-only setattr Jeff Layton
2026-11-20 16:40 ` [PATCH 09/11] nfsd: grant a plain read delegation when timestamps are wanted on a read open Jeff Layton
2026-11-20 16:40 ` [PATCH 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation Jeff Layton
2026-11-20 16:40 ` [PATCH 11/11] nfsd: take the write delegation grant stat before hashing Jeff Layton

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=20261120-delegts-fixes-v1-7-c89b37d2d462@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@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

all inboxes | Powered by JetHome®