Commit d9e4084f authored by Chuck Lever's avatar Chuck Lever Committed by J. Bruce Fields

svcrdma: Generalize svc_rdma_xdr_decode_req()

Clean up: Pass in just the piece of the svc_rqst that is needed
here.

While we're in the area, add an informative documenting comment.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 84f225c2
...@@ -199,7 +199,7 @@ extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt, ...@@ -199,7 +199,7 @@ extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt,
struct xdr_buf *rcvbuf); struct xdr_buf *rcvbuf);
/* svc_rdma_marshal.c */ /* svc_rdma_marshal.c */
extern int svc_rdma_xdr_decode_req(struct rpcrdma_msg *, struct svc_rqst *); extern int svc_rdma_xdr_decode_req(struct xdr_buf *);
extern int svc_rdma_xdr_encode_error(struct svcxprt_rdma *, extern int svc_rdma_xdr_encode_error(struct svcxprt_rdma *,
struct rpcrdma_msg *, struct rpcrdma_msg *,
enum rpcrdma_errcode, __be32 *); enum rpcrdma_errcode, __be32 *);
......
...@@ -145,19 +145,32 @@ static __be32 *decode_reply_array(__be32 *va, __be32 *vaend) ...@@ -145,19 +145,32 @@ static __be32 *decode_reply_array(__be32 *va, __be32 *vaend)
return (__be32 *)&ary->wc_array[nchunks]; return (__be32 *)&ary->wc_array[nchunks];
} }
int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp) /**
* svc_rdma_xdr_decode_req - Parse incoming RPC-over-RDMA header
* @rq_arg: Receive buffer
*
* On entry, xdr->head[0].iov_base points to first byte in the
* RPC-over-RDMA header.
*
* On successful exit, head[0] points to first byte past the
* RPC-over-RDMA header. For RDMA_MSG, this is the RPC message.
* The length of the RPC-over-RDMA header is returned.
*/
int svc_rdma_xdr_decode_req(struct xdr_buf *rq_arg)
{ {
struct rpcrdma_msg *rmsgp;
__be32 *va, *vaend; __be32 *va, *vaend;
unsigned int len; unsigned int len;
u32 hdr_len; u32 hdr_len;
/* Verify that there's enough bytes for header + something */ /* Verify that there's enough bytes for header + something */
if (rqstp->rq_arg.len <= RPCRDMA_HDRLEN_ERR) { if (rq_arg->len <= RPCRDMA_HDRLEN_ERR) {
dprintk("svcrdma: header too short = %d\n", dprintk("svcrdma: header too short = %d\n",
rqstp->rq_arg.len); rq_arg->len);
return -EINVAL; return -EINVAL;
} }
rmsgp = (struct rpcrdma_msg *)rq_arg->head[0].iov_base;
if (rmsgp->rm_vers != rpcrdma_version) { if (rmsgp->rm_vers != rpcrdma_version) {
dprintk("%s: bad version %u\n", __func__, dprintk("%s: bad version %u\n", __func__,
be32_to_cpu(rmsgp->rm_vers)); be32_to_cpu(rmsgp->rm_vers));
...@@ -189,10 +202,10 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp) ...@@ -189,10 +202,10 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
be32_to_cpu(rmsgp->rm_body.rm_padded.rm_thresh); be32_to_cpu(rmsgp->rm_body.rm_padded.rm_thresh);
va = &rmsgp->rm_body.rm_padded.rm_pempty[4]; va = &rmsgp->rm_body.rm_padded.rm_pempty[4];
rqstp->rq_arg.head[0].iov_base = va; rq_arg->head[0].iov_base = va;
len = (u32)((unsigned long)va - (unsigned long)rmsgp); len = (u32)((unsigned long)va - (unsigned long)rmsgp);
rqstp->rq_arg.head[0].iov_len -= len; rq_arg->head[0].iov_len -= len;
if (len > rqstp->rq_arg.len) if (len > rq_arg->len)
return -EINVAL; return -EINVAL;
return len; return len;
default: default:
...@@ -205,7 +218,7 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp) ...@@ -205,7 +218,7 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
* chunk list and a reply chunk list. * chunk list and a reply chunk list.
*/ */
va = &rmsgp->rm_body.rm_chunks[0]; va = &rmsgp->rm_body.rm_chunks[0];
vaend = (__be32 *)((unsigned long)rmsgp + rqstp->rq_arg.len); vaend = (__be32 *)((unsigned long)rmsgp + rq_arg->len);
va = decode_read_list(va, vaend); va = decode_read_list(va, vaend);
if (!va) { if (!va) {
dprintk("svcrdma: failed to decode read list\n"); dprintk("svcrdma: failed to decode read list\n");
...@@ -222,10 +235,9 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp) ...@@ -222,10 +235,9 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
return -EINVAL; return -EINVAL;
} }
rqstp->rq_arg.head[0].iov_base = va; rq_arg->head[0].iov_base = va;
hdr_len = (unsigned long)va - (unsigned long)rmsgp; hdr_len = (unsigned long)va - (unsigned long)rmsgp;
rqstp->rq_arg.head[0].iov_len -= hdr_len; rq_arg->head[0].iov_len -= hdr_len;
return hdr_len; return hdr_len;
} }
......
...@@ -636,7 +636,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp) ...@@ -636,7 +636,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
/* Decode the RDMA header. */ /* Decode the RDMA header. */
rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base; rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base;
ret = svc_rdma_xdr_decode_req(rmsgp, rqstp); ret = svc_rdma_xdr_decode_req(&rqstp->rq_arg);
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
if (ret == 0) if (ret == 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment