Skip to content

Commit 6621b88

Browse files
committed
NFSD: Clean up nfsd4_encode_sequence()
De-duplicate open-coded encoding of the sessionid, and convert the rest of the function to use conventional XDR utility functions. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent b0c1b1b commit 6621b88

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

fs/nfsd/nfs4xdr.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4853,22 +4853,35 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
48534853
{
48544854
struct nfsd4_sequence *seq = &u->sequence;
48554855
struct xdr_stream *xdr = resp->xdr;
4856-
__be32 *p;
48574856

4858-
p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20);
4859-
if (!p)
4860-
return nfserr_resource;
4861-
p = xdr_encode_opaque_fixed(p, seq->sessionid.data,
4862-
NFS4_MAX_SESSIONID_LEN);
4863-
*p++ = cpu_to_be32(seq->seqid);
4864-
*p++ = cpu_to_be32(seq->slotid);
4857+
/* sr_sessionid */
4858+
nfserr = nfsd4_encode_sessionid4(xdr, &seq->sessionid);
4859+
if (nfserr != nfs_ok)
4860+
return nfserr;
4861+
/* sr_sequenceid */
4862+
nfserr = nfsd4_encode_sequenceid4(xdr, seq->seqid);
4863+
if (nfserr != nfs_ok)
4864+
return nfserr;
4865+
/* sr_slotid */
4866+
nfserr = nfsd4_encode_slotid4(xdr, seq->slotid);
4867+
if (nfserr != nfs_ok)
4868+
return nfserr;
48654869
/* Note slotid's are numbered from zero: */
4866-
*p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */
4867-
*p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */
4868-
*p++ = cpu_to_be32(seq->status_flags);
4870+
/* sr_highest_slotid */
4871+
nfserr = nfsd4_encode_slotid4(xdr, seq->maxslots - 1);
4872+
if (nfserr != nfs_ok)
4873+
return nfserr;
4874+
/* sr_target_highest_slotid */
4875+
nfserr = nfsd4_encode_slotid4(xdr, seq->maxslots - 1);
4876+
if (nfserr != nfs_ok)
4877+
return nfserr;
4878+
/* sr_status_flags */
4879+
nfserr = nfsd4_encode_uint32_t(xdr, seq->status_flags);
4880+
if (nfserr != nfs_ok)
4881+
return nfserr;
48694882

48704883
resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */
4871-
return 0;
4884+
return nfs_ok;
48724885
}
48734886

48744887
static __be32

fs/nfsd/xdr4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
9797
#define nfsd4_encode_mode4(x, v) nfsd4_encode_uint32_t(x, v)
9898
#define nfsd4_encode_nfs_lease4(x, v) nfsd4_encode_uint32_t(x, v)
9999
#define nfsd4_encode_sequenceid4(x, v) nfsd4_encode_uint32_t(x, v)
100+
#define nfsd4_encode_slotid4(x, v) nfsd4_encode_uint32_t(x, v)
100101

101102
/**
102103
* nfsd4_encode_uint64_t - Encode an XDR uint64_t type result

0 commit comments

Comments
 (0)