Skip to content

Commit

Permalink
SUNRPC: Add encoders for list item discriminators
Browse files Browse the repository at this point in the history
Clean up. These are taken from the client-side RPC/RDMA transport
to a more global header file so they can be used elsewhere.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
  • Loading branch information
Chuck Lever committed Mar 16, 2020
1 parent a406c56 commit 5c266df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
38 changes: 38 additions & 0 deletions include/linux/sunrpc/xdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,44 @@ static inline size_t xdr_pad_size(size_t n)
return xdr_align_size(n) - n;
}

/**
* xdr_stream_encode_item_present - Encode a "present" list item
* @xdr: pointer to xdr_stream
*
* Return values:
* On success, returns length in bytes of XDR buffer consumed
* %-EMSGSIZE on XDR buffer overflow
*/
static inline ssize_t xdr_stream_encode_item_present(struct xdr_stream *xdr)
{
const size_t len = sizeof(__be32);
__be32 *p = xdr_reserve_space(xdr, len);

if (unlikely(!p))
return -EMSGSIZE;
*p = xdr_one;
return len;
}

/**
* xdr_stream_encode_item_absent - Encode a "not present" list item
* @xdr: pointer to xdr_stream
*
* Return values:
* On success, returns length in bytes of XDR buffer consumed
* %-EMSGSIZE on XDR buffer overflow
*/
static inline int xdr_stream_encode_item_absent(struct xdr_stream *xdr)
{
const size_t len = sizeof(__be32);
__be32 *p = xdr_reserve_space(xdr, len);

if (unlikely(!p))
return -EMSGSIZE;
*p = xdr_zero;
return len;
}

/**
* xdr_stream_encode_u32 - Encode a 32-bit integer
* @xdr: pointer to xdr_stream
Expand Down
36 changes: 5 additions & 31 deletions net/sunrpc/xprtrdma/rpc_rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,32 +275,6 @@ rpcrdma_convert_iovs(struct rpcrdma_xprt *r_xprt, struct xdr_buf *xdrbuf,
return n;
}

static inline int
encode_item_present(struct xdr_stream *xdr)
{
__be32 *p;

p = xdr_reserve_space(xdr, sizeof(*p));
if (unlikely(!p))
return -EMSGSIZE;

*p = xdr_one;
return 0;
}

static inline int
encode_item_not_present(struct xdr_stream *xdr)
{
__be32 *p;

p = xdr_reserve_space(xdr, sizeof(*p));
if (unlikely(!p))
return -EMSGSIZE;

*p = xdr_zero;
return 0;
}

static void
xdr_encode_rdma_segment(__be32 *iptr, struct rpcrdma_mr *mr)
{
Expand Down Expand Up @@ -414,7 +388,7 @@ static int rpcrdma_encode_read_list(struct rpcrdma_xprt *r_xprt,
} while (nsegs);

done:
return encode_item_not_present(xdr);
return xdr_stream_encode_item_absent(xdr);
}

/* Register and XDR encode the Write list. Supports encoding a list
Expand Down Expand Up @@ -453,7 +427,7 @@ static int rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt,
if (nsegs < 0)
return nsegs;

if (encode_item_present(xdr) < 0)
if (xdr_stream_encode_item_present(xdr) < 0)
return -EMSGSIZE;
segcount = xdr_reserve_space(xdr, sizeof(*segcount));
if (unlikely(!segcount))
Expand All @@ -480,7 +454,7 @@ static int rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt,
*segcount = cpu_to_be32(nchunks);

done:
return encode_item_not_present(xdr);
return xdr_stream_encode_item_absent(xdr);
}

/* Register and XDR encode the Reply chunk. Supports encoding an array
Expand All @@ -507,14 +481,14 @@ static int rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt,
__be32 *segcount;

if (wtype != rpcrdma_replych)
return encode_item_not_present(xdr);
return xdr_stream_encode_item_absent(xdr);

seg = req->rl_segments;
nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_rcv_buf, 0, wtype, seg);
if (nsegs < 0)
return nsegs;

if (encode_item_present(xdr) < 0)
if (xdr_stream_encode_item_present(xdr) < 0)
return -EMSGSIZE;
segcount = xdr_reserve_space(xdr, sizeof(*segcount));
if (unlikely(!segcount))
Expand Down

0 comments on commit 5c266df

Please sign in to comment.