Skip to content

Commit abef972

Browse files
committed
NFSD: Clean up nfsd4_encode_exchange_id()
Restructure nfsd4_encode_exchange_id() so that it will be more straightforward to add support for SSV one day. Also, adopt the use of the conventional XDR utility functions. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 91c7a90 commit abef972

File tree

1 file changed

+74
-55
lines changed

1 file changed

+74
-55
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,77 +4733,96 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr,
47334733
}
47344734

47354735
static __be32
4736-
nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
4737-
union nfsd4_op_u *u)
4736+
nfsd4_encode_state_protect_ops4(struct xdr_stream *xdr,
4737+
struct nfsd4_exchange_id *exid)
47384738
{
4739-
struct nfsd4_exchange_id *exid = &u->exchange_id;
4740-
struct xdr_stream *xdr = resp->xdr;
4741-
__be32 *p;
4742-
char *major_id;
4743-
char *server_scope;
4744-
int major_id_sz;
4745-
int server_scope_sz;
4746-
uint64_t minor_id = 0;
4747-
struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
4739+
__be32 status;
47484740

4749-
major_id = nn->nfsd_name;
4750-
major_id_sz = strlen(nn->nfsd_name);
4751-
server_scope = nn->nfsd_name;
4752-
server_scope_sz = strlen(nn->nfsd_name);
4741+
/* spo_must_enforce */
4742+
status = nfsd4_encode_bitmap4(xdr, exid->spo_must_enforce[0],
4743+
exid->spo_must_enforce[1],
4744+
exid->spo_must_enforce[2]);
4745+
if (status != nfs_ok)
4746+
return status;
4747+
/* spo_must_allow */
4748+
return nfsd4_encode_bitmap4(xdr, exid->spo_must_allow[0],
4749+
exid->spo_must_allow[1],
4750+
exid->spo_must_allow[2]);
4751+
}
47534752

4754-
if (nfsd4_encode_clientid4(xdr, &exid->clientid) != nfs_ok)
4755-
return nfserr_resource;
4756-
if (xdr_stream_encode_u32(xdr, exid->seqid) < 0)
4757-
return nfserr_resource;
4758-
if (xdr_stream_encode_u32(xdr, exid->flags) < 0)
4759-
return nfserr_resource;
4753+
static __be32
4754+
nfsd4_encode_state_protect4_r(struct xdr_stream *xdr, struct nfsd4_exchange_id *exid)
4755+
{
4756+
__be32 status;
47604757

4761-
if (xdr_stream_encode_u32(xdr, exid->spa_how) < 0)
4758+
if (xdr_stream_encode_u32(xdr, exid->spa_how) != XDR_UNIT)
47624759
return nfserr_resource;
47634760
switch (exid->spa_how) {
47644761
case SP4_NONE:
4762+
status = nfs_ok;
47654763
break;
47664764
case SP4_MACH_CRED:
4767-
/* spo_must_enforce bitmap: */
4768-
nfserr = nfsd4_encode_bitmap4(xdr,
4769-
exid->spo_must_enforce[0],
4770-
exid->spo_must_enforce[1],
4771-
exid->spo_must_enforce[2]);
4772-
if (nfserr)
4773-
return nfserr;
4774-
/* spo_must_allow bitmap: */
4775-
nfserr = nfsd4_encode_bitmap4(xdr,
4776-
exid->spo_must_allow[0],
4777-
exid->spo_must_allow[1],
4778-
exid->spo_must_allow[2]);
4779-
if (nfserr)
4780-
return nfserr;
4765+
/* spr_mach_ops */
4766+
status = nfsd4_encode_state_protect_ops4(xdr, exid);
47814767
break;
47824768
default:
4783-
WARN_ON_ONCE(1);
4769+
status = nfserr_serverfault;
47844770
}
4771+
return status;
4772+
}
47854773

4786-
p = xdr_reserve_space(xdr,
4787-
8 /* so_minor_id */ +
4788-
4 /* so_major_id.len */ +
4789-
(XDR_QUADLEN(major_id_sz) * 4) +
4790-
4 /* eir_server_scope.len */ +
4791-
(XDR_QUADLEN(server_scope_sz) * 4) +
4792-
4 /* eir_server_impl_id.count (0) */);
4793-
if (!p)
4794-
return nfserr_resource;
4774+
static __be32
4775+
nfsd4_encode_server_owner4(struct xdr_stream *xdr, struct svc_rqst *rqstp)
4776+
{
4777+
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
4778+
__be32 status;
47954779

4796-
/* The server_owner struct */
4797-
p = xdr_encode_hyper(p, minor_id); /* Minor id */
4798-
/* major id */
4799-
p = xdr_encode_opaque(p, major_id, major_id_sz);
4780+
/* so_minor_id */
4781+
status = nfsd4_encode_uint64_t(xdr, 0);
4782+
if (status != nfs_ok)
4783+
return status;
4784+
/* so_major_id */
4785+
return nfsd4_encode_opaque(xdr, nn->nfsd_name, strlen(nn->nfsd_name));
4786+
}
48004787

4801-
/* Server scope */
4802-
p = xdr_encode_opaque(p, server_scope, server_scope_sz);
4788+
static __be32
4789+
nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
4790+
union nfsd4_op_u *u)
4791+
{
4792+
struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
4793+
struct nfsd4_exchange_id *exid = &u->exchange_id;
4794+
struct xdr_stream *xdr = resp->xdr;
48034795

4804-
/* Implementation id */
4805-
*p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */
4806-
return 0;
4796+
/* eir_clientid */
4797+
nfserr = nfsd4_encode_clientid4(xdr, &exid->clientid);
4798+
if (nfserr != nfs_ok)
4799+
return nfserr;
4800+
/* eir_sequenceid */
4801+
nfserr = nfsd4_encode_sequenceid4(xdr, exid->seqid);
4802+
if (nfserr != nfs_ok)
4803+
return nfserr;
4804+
/* eir_flags */
4805+
nfserr = nfsd4_encode_uint32_t(xdr, exid->flags);
4806+
if (nfserr != nfs_ok)
4807+
return nfserr;
4808+
/* eir_state_protect */
4809+
nfserr = nfsd4_encode_state_protect4_r(xdr, exid);
4810+
if (nfserr != nfs_ok)
4811+
return nfserr;
4812+
/* eir_server_owner */
4813+
nfserr = nfsd4_encode_server_owner4(xdr, resp->rqstp);
4814+
if (nfserr != nfs_ok)
4815+
return nfserr;
4816+
/* eir_server_scope */
4817+
nfserr = nfsd4_encode_opaque(xdr, nn->nfsd_name,
4818+
strlen(nn->nfsd_name));
4819+
if (nfserr != nfs_ok)
4820+
return nfserr;
4821+
/* eir_server_impl_id<1> */
4822+
if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
4823+
return nfserr_resource;
4824+
4825+
return nfs_ok;
48074826
}
48084827

48094828
static __be32

0 commit comments

Comments
 (0)