Skip to content

Commit 07e9a63

Browse files
committed
SUNRPC: Add helpers for decoding list discriminators symbolically
Use these helpers in a few spots to demonstrate their use. The remaining open-coded discriminator checks in rpcrdma will be addressed in subsequent patches. Signed-off-by: Chuck Lever <[email protected]>
1 parent 0b8dc1b commit 07e9a63

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

include/linux/sunrpc/xdr.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,32 @@ xdr_stream_encode_uint32_array(struct xdr_stream *xdr,
474474
return ret;
475475
}
476476

477+
/**
478+
* xdr_item_is_absent - symbolically handle XDR discriminators
479+
* @p: pointer to undecoded discriminator
480+
*
481+
* Return values:
482+
* %true if the following XDR item is absent
483+
* %false if the following XDR item is present
484+
*/
485+
static inline bool xdr_item_is_absent(const __be32 *p)
486+
{
487+
return *p == xdr_zero;
488+
}
489+
490+
/**
491+
* xdr_item_is_present - symbolically handle XDR discriminators
492+
* @p: pointer to undecoded discriminator
493+
*
494+
* Return values:
495+
* %true if the following XDR item is present
496+
* %false if the following XDR item is absent
497+
*/
498+
static inline bool xdr_item_is_present(const __be32 *p)
499+
{
500+
return *p != xdr_zero;
501+
}
502+
477503
/**
478504
* xdr_stream_decode_u32 - Decode a 32-bit integer
479505
* @xdr: pointer to xdr_stream

net/sunrpc/xprtrdma/rpc_rdma.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,11 +1133,11 @@ rpcrdma_is_bcall(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep)
11331133
p = xdr_inline_decode(xdr, 0);
11341134

11351135
/* Chunk lists */
1136-
if (*p++ != xdr_zero)
1136+
if (xdr_item_is_present(p++))
11371137
return false;
1138-
if (*p++ != xdr_zero)
1138+
if (xdr_item_is_present(p++))
11391139
return false;
1140-
if (*p++ != xdr_zero)
1140+
if (xdr_item_is_present(p++))
11411141
return false;
11421142

11431143
/* RPC header */
@@ -1215,7 +1215,7 @@ static int decode_read_list(struct xdr_stream *xdr)
12151215
p = xdr_inline_decode(xdr, sizeof(*p));
12161216
if (unlikely(!p))
12171217
return -EIO;
1218-
if (unlikely(*p != xdr_zero))
1218+
if (unlikely(xdr_item_is_present(p)))
12191219
return -EIO;
12201220
return 0;
12211221
}
@@ -1234,7 +1234,7 @@ static int decode_write_list(struct xdr_stream *xdr, u32 *length)
12341234
p = xdr_inline_decode(xdr, sizeof(*p));
12351235
if (unlikely(!p))
12361236
return -EIO;
1237-
if (*p == xdr_zero)
1237+
if (xdr_item_is_absent(p))
12381238
break;
12391239
if (!first)
12401240
return -EIO;
@@ -1256,7 +1256,7 @@ static int decode_reply_chunk(struct xdr_stream *xdr, u32 *length)
12561256
return -EIO;
12571257

12581258
*length = 0;
1259-
if (*p != xdr_zero)
1259+
if (xdr_item_is_present(p))
12601260
if (decode_write_chunk(xdr, length))
12611261
return -EIO;
12621262
return 0;

net/sunrpc/xprtrdma/svc_rdma_recvfrom.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static bool xdr_check_read_list(struct svc_rdma_recv_ctxt *rctxt)
419419

420420
len = 0;
421421
first = true;
422-
while (*p != xdr_zero) {
422+
while (xdr_item_is_present(p)) {
423423
p = xdr_inline_decode(&rctxt->rc_stream,
424424
rpcrdma_readseg_maxsz * sizeof(*p));
425425
if (!p)
@@ -500,7 +500,7 @@ static bool xdr_check_write_list(struct svc_rdma_recv_ctxt *rctxt)
500500
if (!p)
501501
return false;
502502
rctxt->rc_write_list = p;
503-
while (*p != xdr_zero) {
503+
while (xdr_item_is_present(p)) {
504504
if (!xdr_check_write_chunk(rctxt, MAX_BYTES_WRITE_CHUNK))
505505
return false;
506506
++chcount;
@@ -532,12 +532,11 @@ static bool xdr_check_reply_chunk(struct svc_rdma_recv_ctxt *rctxt)
532532
p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
533533
if (!p)
534534
return false;
535-
rctxt->rc_reply_chunk = p;
536-
if (*p != xdr_zero) {
535+
rctxt->rc_reply_chunk = NULL;
536+
if (xdr_item_is_present(p)) {
537537
if (!xdr_check_write_chunk(rctxt, MAX_BYTES_SPECIAL_CHUNK))
538538
return false;
539-
} else {
540-
rctxt->rc_reply_chunk = NULL;
539+
rctxt->rc_reply_chunk = p;
541540
}
542541
return true;
543542
}
@@ -568,7 +567,7 @@ static void svc_rdma_get_inv_rkey(struct svcxprt_rdma *rdma,
568567
p += rpcrdma_fixed_maxsz;
569568

570569
/* Read list */
571-
while (*p++ != xdr_zero) {
570+
while (xdr_item_is_present(p++)) {
572571
p++; /* position */
573572
if (inv_rkey == xdr_zero)
574573
inv_rkey = *p;
@@ -578,7 +577,7 @@ static void svc_rdma_get_inv_rkey(struct svcxprt_rdma *rdma,
578577
}
579578

580579
/* Write list */
581-
while (*p++ != xdr_zero) {
580+
while (xdr_item_is_present(p++)) {
582581
segcount = be32_to_cpup(p++);
583582
for (i = 0; i < segcount; i++) {
584583
if (inv_rkey == xdr_zero)
@@ -590,7 +589,7 @@ static void svc_rdma_get_inv_rkey(struct svcxprt_rdma *rdma,
590589
}
591590

592591
/* Reply chunk */
593-
if (*p++ != xdr_zero) {
592+
if (xdr_item_is_present(p++)) {
594593
segcount = be32_to_cpup(p++);
595594
for (i = 0; i < segcount; i++) {
596595
if (inv_rkey == xdr_zero)

0 commit comments

Comments
 (0)