SUNRPC: Use struct xdr_stream when constructing RPC Call header
Modernize and harden the code path that constructs each RPC Call message. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:

committed by
Anna Schumaker

parent
fe9a270519
commit
e8680a24a2
@@ -77,7 +77,8 @@ static void call_timeout(struct rpc_task *task);
|
||||
static void call_connect(struct rpc_task *task);
|
||||
static void call_connect_status(struct rpc_task *task);
|
||||
|
||||
static __be32 *rpc_encode_header(struct rpc_task *task);
|
||||
static int rpc_encode_header(struct rpc_task *task,
|
||||
struct xdr_stream *xdr);
|
||||
static __be32 *rpc_verify_header(struct rpc_task *task);
|
||||
static int rpc_ping(struct rpc_clnt *clnt);
|
||||
|
||||
@@ -1728,10 +1729,7 @@ static void
|
||||
rpc_xdr_encode(struct rpc_task *task)
|
||||
{
|
||||
struct rpc_rqst *req = task->tk_rqstp;
|
||||
kxdreproc_t encode;
|
||||
__be32 *p;
|
||||
|
||||
dprint_status(task);
|
||||
struct xdr_stream xdr;
|
||||
|
||||
xdr_buf_init(&req->rq_snd_buf,
|
||||
req->rq_buffer,
|
||||
@@ -1740,18 +1738,13 @@ rpc_xdr_encode(struct rpc_task *task)
|
||||
req->rq_rbuffer,
|
||||
req->rq_rcvsize);
|
||||
|
||||
p = rpc_encode_header(task);
|
||||
if (p == NULL)
|
||||
req->rq_snd_buf.head[0].iov_len = 0;
|
||||
xdr_init_encode(&xdr, &req->rq_snd_buf,
|
||||
req->rq_snd_buf.head[0].iov_base, req);
|
||||
if (rpc_encode_header(task, &xdr))
|
||||
return;
|
||||
|
||||
encode = task->tk_msg.rpc_proc->p_encode;
|
||||
if (encode == NULL)
|
||||
return;
|
||||
|
||||
task->tk_status = rpcauth_wrap_req(task, encode, req, p,
|
||||
task->tk_msg.rpc_argp);
|
||||
if (task->tk_status == 0)
|
||||
xprt_request_prepare(req);
|
||||
task->tk_status = rpcauth_wrap_req(task, &xdr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1762,6 +1755,7 @@ call_encode(struct rpc_task *task)
|
||||
{
|
||||
if (!rpc_task_need_encode(task))
|
||||
goto out;
|
||||
dprint_status(task);
|
||||
/* Encode here so that rpcsec_gss can use correct sequence number. */
|
||||
rpc_xdr_encode(task);
|
||||
/* Did the encode result in an error condition? */
|
||||
@@ -1779,6 +1773,8 @@ call_encode(struct rpc_task *task)
|
||||
rpc_exit(task, task->tk_status);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
xprt_request_prepare(task->tk_rqstp);
|
||||
}
|
||||
|
||||
/* Add task to reply queue before transmission to avoid races */
|
||||
@@ -2322,25 +2318,33 @@ out_retry:
|
||||
}
|
||||
}
|
||||
|
||||
static __be32 *
|
||||
rpc_encode_header(struct rpc_task *task)
|
||||
static int
|
||||
rpc_encode_header(struct rpc_task *task, struct xdr_stream *xdr)
|
||||
{
|
||||
struct rpc_clnt *clnt = task->tk_client;
|
||||
struct rpc_rqst *req = task->tk_rqstp;
|
||||
__be32 *p = req->rq_svec[0].iov_base;
|
||||
__be32 *p;
|
||||
int error;
|
||||
|
||||
/* FIXME: check buffer size? */
|
||||
error = -EMSGSIZE;
|
||||
p = xdr_reserve_space(xdr, RPC_CALLHDRSIZE << 2);
|
||||
if (!p)
|
||||
goto out_fail;
|
||||
*p++ = req->rq_xid;
|
||||
*p++ = rpc_call;
|
||||
*p++ = cpu_to_be32(RPC_VERSION);
|
||||
*p++ = cpu_to_be32(clnt->cl_prog);
|
||||
*p++ = cpu_to_be32(clnt->cl_vers);
|
||||
*p = cpu_to_be32(task->tk_msg.rpc_proc->p_proc);
|
||||
|
||||
*p++ = req->rq_xid; /* XID */
|
||||
*p++ = htonl(RPC_CALL); /* CALL */
|
||||
*p++ = htonl(RPC_VERSION); /* RPC version */
|
||||
*p++ = htonl(clnt->cl_prog); /* program number */
|
||||
*p++ = htonl(clnt->cl_vers); /* program version */
|
||||
*p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
|
||||
p = rpcauth_marshcred(task, p);
|
||||
if (p)
|
||||
req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
|
||||
return p;
|
||||
error = rpcauth_marshcred(task, xdr);
|
||||
if (error < 0)
|
||||
goto out_fail;
|
||||
return 0;
|
||||
out_fail:
|
||||
trace_rpc_bad_callhdr(task);
|
||||
rpc_exit(task, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
static __be32 *
|
||||
|
Reference in New Issue
Block a user