Skip to content

Commit b9c5bc0

Browse files
chuckleveramschuma-ntap
authored andcommitted
SUNRPC: Refactor rpc_xdr_buf_init()
Clean up: there is some XDR initialization logic that is common to the forward channel and backchannel. Move it to an XDR header so it can be shared. rpc_rqst::rq_buffer points to a buffer containing big-endian data. Update its annotation as part of the clean up. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent eb342e9 commit b9c5bc0

File tree

5 files changed

+21
-37
lines changed

5 files changed

+21
-37
lines changed

include/linux/sunrpc/xdr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ struct xdr_buf {
6767
len; /* Length of XDR encoded message */
6868
};
6969

70+
static inline void
71+
xdr_buf_init(struct xdr_buf *buf, void *start, size_t len)
72+
{
73+
buf->head[0].iov_base = start;
74+
buf->head[0].iov_len = len;
75+
buf->tail[0].iov_len = 0;
76+
buf->page_len = 0;
77+
buf->flags = 0;
78+
buf->len = 0;
79+
buf->buflen = len;
80+
}
81+
7082
/*
7183
* pre-xdr'ed macros.
7284
*/

include/linux/sunrpc/xprt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct rpc_rqst {
8383
void (*rq_release_snd_buf)(struct rpc_rqst *); /* release rq_enc_pages */
8484
struct list_head rq_list;
8585

86-
__u32 * rq_buffer; /* XDR encode buffer */
86+
void *rq_buffer; /* Call XDR encode buffer */
8787
size_t rq_callsize,
8888
rq_rcvsize;
8989
size_t rq_xmit_bytes_sent; /* total bytes sent */

net/sunrpc/backchannel_rqst.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ static int xprt_alloc_xdr_buf(struct xdr_buf *buf, gfp_t gfp_flags)
7676
page = alloc_page(gfp_flags);
7777
if (page == NULL)
7878
return -ENOMEM;
79-
buf->head[0].iov_base = page_address(page);
80-
buf->head[0].iov_len = PAGE_SIZE;
81-
buf->tail[0].iov_base = NULL;
82-
buf->tail[0].iov_len = 0;
83-
buf->page_len = 0;
84-
buf->len = 0;
85-
buf->buflen = PAGE_SIZE;
79+
xdr_buf_init(buf, page_address(page), PAGE_SIZE);
8680
return 0;
8781
}
8882

net/sunrpc/clnt.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,18 +1746,6 @@ rpc_task_force_reencode(struct rpc_task *task)
17461746
task->tk_rqstp->rq_bytes_sent = 0;
17471747
}
17481748

1749-
static inline void
1750-
rpc_xdr_buf_init(struct xdr_buf *buf, void *start, size_t len)
1751-
{
1752-
buf->head[0].iov_base = start;
1753-
buf->head[0].iov_len = len;
1754-
buf->tail[0].iov_len = 0;
1755-
buf->page_len = 0;
1756-
buf->flags = 0;
1757-
buf->len = 0;
1758-
buf->buflen = len;
1759-
}
1760-
17611749
/*
17621750
* 3. Encode arguments of an RPC call
17631751
*/
@@ -1770,12 +1758,12 @@ rpc_xdr_encode(struct rpc_task *task)
17701758

17711759
dprint_status(task);
17721760

1773-
rpc_xdr_buf_init(&req->rq_snd_buf,
1774-
req->rq_buffer,
1775-
req->rq_callsize);
1776-
rpc_xdr_buf_init(&req->rq_rcv_buf,
1777-
(char *)req->rq_buffer + req->rq_callsize,
1778-
req->rq_rcvsize);
1761+
xdr_buf_init(&req->rq_snd_buf,
1762+
req->rq_buffer,
1763+
req->rq_callsize);
1764+
xdr_buf_init(&req->rq_rcv_buf,
1765+
(char *)req->rq_buffer + req->rq_callsize,
1766+
req->rq_rcvsize);
17791767

17801768
p = rpc_encode_header(task);
17811769
if (p == NULL) {

net/sunrpc/xprtrdma/backchannel.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static int rpcrdma_bc_setup_rqst(struct rpcrdma_xprt *r_xprt,
3838
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
3939
struct rpcrdma_regbuf *rb;
4040
struct rpcrdma_req *req;
41-
struct xdr_buf *buf;
4241
size_t size;
4342

4443
req = rpcrdma_create_req(r_xprt);
@@ -60,16 +59,7 @@ static int rpcrdma_bc_setup_rqst(struct rpcrdma_xprt *r_xprt,
6059
req->rl_sendbuf = rb;
6160
/* so that rpcr_to_rdmar works when receiving a request */
6261
rqst->rq_buffer = (void *)req->rl_sendbuf->rg_base;
63-
64-
buf = &rqst->rq_snd_buf;
65-
buf->head[0].iov_base = rqst->rq_buffer;
66-
buf->head[0].iov_len = 0;
67-
buf->tail[0].iov_base = NULL;
68-
buf->tail[0].iov_len = 0;
69-
buf->page_len = 0;
70-
buf->len = 0;
71-
buf->buflen = size;
72-
62+
xdr_buf_init(&rqst->rq_snd_buf, rqst->rq_buffer, size);
7363
return 0;
7464

7565
out_fail:

0 commit comments

Comments
 (0)