Skip to content

Commit f60a086

Browse files
committed
svcrdma: Add common XDR decoders for RDMA and Read segments
Clean up: De-duplicate some code. Signed-off-by: Chuck Lever <[email protected]>
1 parent 07e9a63 commit f60a086

File tree

7 files changed

+56
-34
lines changed

7 files changed

+56
-34
lines changed

include/linux/sunrpc/rpc_rdma.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,41 @@ rpcrdma_decode_buffer_size(u8 val)
124124
return ((unsigned int)val + 1) << 10;
125125
}
126126

127+
/**
128+
* xdr_decode_rdma_segment - Decode contents of an RDMA segment
129+
* @p: Pointer to the undecoded RDMA segment
130+
* @handle: Upon return, the RDMA handle
131+
* @length: Upon return, the RDMA length
132+
* @offset: Upon return, the RDMA offset
133+
*
134+
* Return value:
135+
* Pointer to the XDR item that follows the RDMA segment
136+
*/
137+
static inline __be32 *xdr_decode_rdma_segment(__be32 *p, u32 *handle,
138+
u32 *length, u64 *offset)
139+
{
140+
*handle = be32_to_cpup(p++);
141+
*length = be32_to_cpup(p++);
142+
return xdr_decode_hyper(p, offset);
143+
}
144+
145+
/**
146+
* xdr_decode_read_segment - Decode contents of a Read segment
147+
* @p: Pointer to the undecoded Read segment
148+
* @position: Upon return, the segment's position
149+
* @handle: Upon return, the RDMA handle
150+
* @length: Upon return, the RDMA length
151+
* @offset: Upon return, the RDMA offset
152+
*
153+
* Return value:
154+
* Pointer to the XDR item that follows the Read segment
155+
*/
156+
static inline __be32 *xdr_decode_read_segment(__be32 *p, u32 *position,
157+
u32 *handle, u32 *length,
158+
u64 *offset)
159+
{
160+
*position = be32_to_cpup(p++);
161+
return xdr_decode_rdma_segment(p, handle, length, offset);
162+
}
163+
127164
#endif /* _LINUX_SUNRPC_RPC_RDMA_H */

net/sunrpc/xprtrdma/frwr_ops.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
* New MRs are created on demand.
4141
*/
4242

43-
#include <linux/sunrpc/rpc_rdma.h>
4443
#include <linux/sunrpc/svc_rdma.h>
4544

4645
#include "xprt_rdma.h"

net/sunrpc/xprtrdma/rpc_rdma.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,7 @@ static int decode_rdma_segment(struct xdr_stream *xdr, u32 *length)
11761176
if (unlikely(!p))
11771177
return -EIO;
11781178

1179-
handle = be32_to_cpup(p++);
1180-
*length = be32_to_cpup(p++);
1181-
xdr_decode_hyper(p, &offset);
1182-
1179+
xdr_decode_rdma_segment(p, &handle, length, &offset);
11831180
trace_xprtrdma_decode_seg(handle, *length, offset);
11841181
return 0;
11851182
}

net/sunrpc/xprtrdma/svc_rdma_recvfrom.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,7 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt, u32 maxlen)
466466
if (!p)
467467
return false;
468468

469-
handle = be32_to_cpup(p++);
470-
length = be32_to_cpup(p++);
471-
xdr_decode_hyper(p, &offset);
469+
xdr_decode_rdma_segment(p, &handle, &length, &offset);
472470
trace_svcrdma_decode_wseg(handle, length, offset);
473471

474472
total += length;

net/sunrpc/xprtrdma/svc_rdma_rw.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <rdma/rw.h>
99

10+
#include <linux/sunrpc/xdr.h>
1011
#include <linux/sunrpc/rpc_rdma.h>
1112
#include <linux/sunrpc/svc_rdma.h>
1213

@@ -441,34 +442,32 @@ svc_rdma_build_writes(struct svc_rdma_write_info *info,
441442
seg = info->wi_segs + info->wi_seg_no * rpcrdma_segment_maxsz;
442443
do {
443444
unsigned int write_len;
444-
u32 seg_length, seg_handle;
445-
u64 seg_offset;
445+
u32 handle, length;
446+
u64 offset;
446447

447448
if (info->wi_seg_no >= info->wi_nsegs)
448449
goto out_overflow;
449450

450-
seg_handle = be32_to_cpup(seg);
451-
seg_length = be32_to_cpup(seg + 1);
452-
xdr_decode_hyper(seg + 2, &seg_offset);
453-
seg_offset += info->wi_seg_off;
451+
xdr_decode_rdma_segment(seg, &handle, &length, &offset);
452+
offset += info->wi_seg_off;
454453

455-
write_len = min(remaining, seg_length - info->wi_seg_off);
454+
write_len = min(remaining, length - info->wi_seg_off);
456455
ctxt = svc_rdma_get_rw_ctxt(rdma,
457456
(write_len >> PAGE_SHIFT) + 2);
458457
if (!ctxt)
459458
return -ENOMEM;
460459

461460
constructor(info, write_len, ctxt);
462-
ret = svc_rdma_rw_ctx_init(rdma, ctxt, seg_offset, seg_handle,
461+
ret = svc_rdma_rw_ctx_init(rdma, ctxt, offset, handle,
463462
DMA_TO_DEVICE);
464463
if (ret < 0)
465464
return -EIO;
466465

467-
trace_svcrdma_send_wseg(seg_handle, write_len, seg_offset);
466+
trace_svcrdma_send_wseg(handle, write_len, offset);
468467

469468
list_add(&ctxt->rw_list, &cc->cc_rwctxts);
470469
cc->cc_sqecount += ret;
471-
if (write_len == seg_length - info->wi_seg_off) {
470+
if (write_len == length - info->wi_seg_off) {
472471
seg += 4;
473472
info->wi_seg_no++;
474473
info->wi_seg_off = 0;
@@ -689,21 +688,17 @@ static int svc_rdma_build_read_chunk(struct svc_rqst *rqstp,
689688
ret = -EINVAL;
690689
info->ri_chunklen = 0;
691690
while (*p++ != xdr_zero && be32_to_cpup(p++) == info->ri_position) {
692-
u32 rs_handle, rs_length;
693-
u64 rs_offset;
691+
u32 handle, length;
692+
u64 offset;
694693

695-
rs_handle = be32_to_cpup(p++);
696-
rs_length = be32_to_cpup(p++);
697-
p = xdr_decode_hyper(p, &rs_offset);
698-
699-
ret = svc_rdma_build_read_segment(info, rqstp,
700-
rs_handle, rs_length,
701-
rs_offset);
694+
p = xdr_decode_rdma_segment(p, &handle, &length, &offset);
695+
ret = svc_rdma_build_read_segment(info, rqstp, handle, length,
696+
offset);
702697
if (ret < 0)
703698
break;
704699

705-
trace_svcrdma_send_rseg(rs_handle, rs_length, rs_offset);
706-
info->ri_chunklen += rs_length;
700+
trace_svcrdma_send_rseg(handle, length, offset);
701+
info->ri_chunklen += length;
707702
}
708703

709704
return ret;

net/sunrpc/xprtrdma/svc_rdma_sendto.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
#include <rdma/rdma_cm.h>
107107

108108
#include <linux/sunrpc/debug.h>
109-
#include <linux/sunrpc/rpc_rdma.h>
110109
#include <linux/sunrpc/svc_rdma.h>
111110

112111
#include "xprt_rdma.h"
@@ -375,9 +374,7 @@ static ssize_t svc_rdma_encode_write_segment(__be32 *src,
375374
if (!p)
376375
return -EMSGSIZE;
377376

378-
handle = be32_to_cpup(src++);
379-
length = be32_to_cpup(src++);
380-
xdr_decode_hyper(src, &offset);
377+
xdr_decode_rdma_segment(src, &handle, &length, &offset);
381378

382379
*p++ = cpu_to_be32(handle);
383380
if (*remaining < length) {

net/sunrpc/xprtrdma/svc_rdma_transport.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555

5656
#include <linux/sunrpc/addr.h>
5757
#include <linux/sunrpc/debug.h>
58-
#include <linux/sunrpc/rpc_rdma.h>
5958
#include <linux/sunrpc/svc_xprt.h>
6059
#include <linux/sunrpc/svc_rdma.h>
6160

0 commit comments

Comments
 (0)