From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Chuck Lever <chuck.lever@oracle.com>,
Jeff Layton <jlayton@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 2/7] NFSD: Clean up nfsd4_encode_stateid()
Date: Fri, 4 Sep 2026 23:28:25 -0400 [thread overview]
Message-ID: <20260905032830.1915148-2-sashal@kernel.org> (raw)
In-Reply-To: <20260905032830.1915148-1-sashal@kernel.org>
From: Chuck Lever <chuck.lever@oracle.com>
[ Upstream commit 40bb2baaa8edecfc21a3c176e4af1a3445157677 ]
Update the encoder function name to match the type name, as is the
convention with other such encoder utility functions, and with
nfsd4_decode_stateid4().
Make the @stateid argument a const so that callers of
nfsd4_encode_stateid4() in the future can be passed const pointers
to structures.
Since the compiler is allowed to add padding to structs, use the
wire (spec-defined) size when reserving buffer space.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Stable-dep-of: ca94ba361720 ("nfsd: fix BUG_ON in nfsd4_alloc_layout_stateid on racing delegation revoke")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/nfsd/nfs4xdr.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 52fe95d02fc47..f45e46bec8c69 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3713,18 +3713,18 @@ nfsd4_encode_clientid4(struct xdr_stream *xdr, const clientid_t *clientid)
return nfs_ok;
}
+/* This is a frequently-encoded item; open-coded for speed */
static __be32
-nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid)
+nfsd4_encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid)
{
__be32 *p;
- p = xdr_reserve_space(xdr, sizeof(stateid_t));
+ p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE);
if (!p)
return nfserr_resource;
*p++ = cpu_to_be32(sid->si_generation);
- p = xdr_encode_opaque_fixed(p, &sid->si_opaque,
- sizeof(stateid_opaque_t));
- return 0;
+ memcpy(p, &sid->si_opaque, sizeof(sid->si_opaque));
+ return nfs_ok;
}
static __be32
@@ -3768,7 +3768,8 @@ nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_close *close = &u->close;
struct xdr_stream *xdr = resp->xdr;
- return nfsd4_encode_stateid(xdr, &close->cl_stateid);
+ /* open_stateid */
+ return nfsd4_encode_stateid4(xdr, &close->cl_stateid);
}
@@ -3872,7 +3873,7 @@ nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr,
struct xdr_stream *xdr = resp->xdr;
if (!nfserr)
- nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid);
+ nfserr = nfsd4_encode_stateid4(xdr, &lock->lk_resp_stateid);
else if (nfserr == nfserr_denied)
nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied);
@@ -3898,7 +3899,8 @@ nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_locku *locku = &u->locku;
struct xdr_stream *xdr = resp->xdr;
- return nfsd4_encode_stateid(xdr, &locku->lu_stateid);
+ /* lock_stateid */
+ return nfsd4_encode_stateid4(xdr, &locku->lu_stateid);
}
@@ -3921,7 +3923,7 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
struct xdr_stream *xdr = resp->xdr;
__be32 *p;
- nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid);
+ nfserr = nfsd4_encode_stateid4(xdr, &open->op_stateid);
if (nfserr)
return nfserr;
nfserr = nfsd4_encode_change_info4(xdr, &open->op_cinfo);
@@ -3944,7 +3946,7 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
case NFS4_OPEN_DELEGATE_NONE:
break;
case NFS4_OPEN_DELEGATE_READ:
- nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid);
+ nfserr = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid);
if (nfserr)
return nfserr;
p = xdr_reserve_space(xdr, 20);
@@ -3961,7 +3963,7 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
*p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */
break;
case NFS4_OPEN_DELEGATE_WRITE:
- nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid);
+ nfserr = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid);
if (nfserr)
return nfserr;
@@ -4019,7 +4021,8 @@ nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_open_confirm *oc = &u->open_confirm;
struct xdr_stream *xdr = resp->xdr;
- return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid);
+ /* open_stateid */
+ return nfsd4_encode_stateid4(xdr, &oc->oc_resp_stateid);
}
static __be32
@@ -4029,7 +4032,8 @@ nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_open_downgrade *od = &u->open_downgrade;
struct xdr_stream *xdr = resp->xdr;
- return nfsd4_encode_stateid(xdr, &od->od_stateid);
+ /* open_stateid */
+ return nfsd4_encode_stateid4(xdr, &od->od_stateid);
}
/*
@@ -4773,7 +4777,7 @@ nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr,
return nfserr_resource;
*p++ = cpu_to_be32(lrp->lrs_present);
if (lrp->lrs_present)
- return nfsd4_encode_stateid(xdr, &lrp->lr_sid);
+ return nfsd4_encode_stateid4(xdr, &lrp->lr_sid);
return 0;
}
#endif /* CONFIG_NFSD_PNFS */
@@ -4792,7 +4796,7 @@ nfsd42_encode_write_res(struct nfsd4_compoundres *resp,
else {
__be32 nfserr;
*p++ = cpu_to_be32(1);
- nfserr = nfsd4_encode_stateid(resp->xdr, &write->cb_stateid);
+ nfserr = nfsd4_encode_stateid4(resp->xdr, &write->cb_stateid);
if (nfserr)
return nfserr;
}
@@ -4976,7 +4980,7 @@ nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr,
*p++ = cpu_to_be32(cn->cpn_nsec);
/* cnr_stateid */
- nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid);
+ nfserr = nfsd4_encode_stateid4(xdr, &cn->cpn_cnr_stateid);
if (nfserr)
return nfserr;
--
2.53.0
next prev parent reply other threads:[~2026-09-05 3:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 13:13 FAILED: patch "[PATCH] nfsd: fix BUG_ON in nfsd4_alloc_layout_stateid on racing" failed to apply to 6.6-stable tree gregkh
2026-09-05 3:28 ` [PATCH 6.6.y 1/7] NFSD: Add simple u32, u64, and bool encoders Sasha Levin
2026-09-05 3:28 ` Sasha Levin [this message]
2026-09-05 3:28 ` [PATCH 6.6.y 3/7] NFSD: Clean up nfsd4_encode_layoutreturn() Sasha Levin
2026-09-05 3:28 ` [PATCH 6.6.y 4/7] nfsd: don't call functions with side-effecting inside WARN_ON() Sasha Levin
2026-09-05 3:28 ` [PATCH 6.6.y 5/7] nfsd: avoid race after unhash_delegation_locked() Sasha Levin
2026-09-05 3:28 ` [PATCH 6.6.y 6/7] nfsd: split sc_status out of sc_type Sasha Levin
2026-09-05 3:28 ` [PATCH 6.6.y 7/7] nfsd: fix BUG_ON in nfsd4_alloc_layout_stateid on racing delegation revoke Sasha Levin
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=20260905032830.1915148-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.