[PATCH 07/11] nfsd: recall when a CB_GETATTR reply omits the size

From: Jeff Layton

Date: Fri Nov 20 2026 - 11:40:56 EST


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@xxxxxxxxxx>
---
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