mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
svcrdma: Add common XDR decoders for RDMA and Read segments
Clean up: De-duplicate some code. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
@@ -124,4 +124,41 @@ rpcrdma_decode_buffer_size(u8 val)
|
|||||||
return ((unsigned int)val + 1) << 10;
|
return ((unsigned int)val + 1) << 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xdr_decode_rdma_segment - Decode contents of an RDMA segment
|
||||||
|
* @p: Pointer to the undecoded RDMA segment
|
||||||
|
* @handle: Upon return, the RDMA handle
|
||||||
|
* @length: Upon return, the RDMA length
|
||||||
|
* @offset: Upon return, the RDMA offset
|
||||||
|
*
|
||||||
|
* Return value:
|
||||||
|
* Pointer to the XDR item that follows the RDMA segment
|
||||||
|
*/
|
||||||
|
static inline __be32 *xdr_decode_rdma_segment(__be32 *p, u32 *handle,
|
||||||
|
u32 *length, u64 *offset)
|
||||||
|
{
|
||||||
|
*handle = be32_to_cpup(p++);
|
||||||
|
*length = be32_to_cpup(p++);
|
||||||
|
return xdr_decode_hyper(p, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xdr_decode_read_segment - Decode contents of a Read segment
|
||||||
|
* @p: Pointer to the undecoded Read segment
|
||||||
|
* @position: Upon return, the segment's position
|
||||||
|
* @handle: Upon return, the RDMA handle
|
||||||
|
* @length: Upon return, the RDMA length
|
||||||
|
* @offset: Upon return, the RDMA offset
|
||||||
|
*
|
||||||
|
* Return value:
|
||||||
|
* Pointer to the XDR item that follows the Read segment
|
||||||
|
*/
|
||||||
|
static inline __be32 *xdr_decode_read_segment(__be32 *p, u32 *position,
|
||||||
|
u32 *handle, u32 *length,
|
||||||
|
u64 *offset)
|
||||||
|
{
|
||||||
|
*position = be32_to_cpup(p++);
|
||||||
|
return xdr_decode_rdma_segment(p, handle, length, offset);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _LINUX_SUNRPC_RPC_RDMA_H */
|
#endif /* _LINUX_SUNRPC_RPC_RDMA_H */
|
||||||
|
@@ -40,7 +40,6 @@
|
|||||||
* New MRs are created on demand.
|
* New MRs are created on demand.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/sunrpc/rpc_rdma.h>
|
|
||||||
#include <linux/sunrpc/svc_rdma.h>
|
#include <linux/sunrpc/svc_rdma.h>
|
||||||
|
|
||||||
#include "xprt_rdma.h"
|
#include "xprt_rdma.h"
|
||||||
|
@@ -1176,10 +1176,7 @@ static int decode_rdma_segment(struct xdr_stream *xdr, u32 *length)
|
|||||||
if (unlikely(!p))
|
if (unlikely(!p))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
handle = be32_to_cpup(p++);
|
xdr_decode_rdma_segment(p, &handle, length, &offset);
|
||||||
*length = be32_to_cpup(p++);
|
|
||||||
xdr_decode_hyper(p, &offset);
|
|
||||||
|
|
||||||
trace_xprtrdma_decode_seg(handle, *length, offset);
|
trace_xprtrdma_decode_seg(handle, *length, offset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -466,9 +466,7 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt, u32 maxlen)
|
|||||||
if (!p)
|
if (!p)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
handle = be32_to_cpup(p++);
|
xdr_decode_rdma_segment(p, &handle, &length, &offset);
|
||||||
length = be32_to_cpup(p++);
|
|
||||||
xdr_decode_hyper(p, &offset);
|
|
||||||
trace_svcrdma_decode_wseg(handle, length, offset);
|
trace_svcrdma_decode_wseg(handle, length, offset);
|
||||||
|
|
||||||
total += length;
|
total += length;
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <rdma/rw.h>
|
#include <rdma/rw.h>
|
||||||
|
|
||||||
|
#include <linux/sunrpc/xdr.h>
|
||||||
#include <linux/sunrpc/rpc_rdma.h>
|
#include <linux/sunrpc/rpc_rdma.h>
|
||||||
#include <linux/sunrpc/svc_rdma.h>
|
#include <linux/sunrpc/svc_rdma.h>
|
||||||
|
|
||||||
@@ -441,34 +442,32 @@ svc_rdma_build_writes(struct svc_rdma_write_info *info,
|
|||||||
seg = info->wi_segs + info->wi_seg_no * rpcrdma_segment_maxsz;
|
seg = info->wi_segs + info->wi_seg_no * rpcrdma_segment_maxsz;
|
||||||
do {
|
do {
|
||||||
unsigned int write_len;
|
unsigned int write_len;
|
||||||
u32 seg_length, seg_handle;
|
u32 handle, length;
|
||||||
u64 seg_offset;
|
u64 offset;
|
||||||
|
|
||||||
if (info->wi_seg_no >= info->wi_nsegs)
|
if (info->wi_seg_no >= info->wi_nsegs)
|
||||||
goto out_overflow;
|
goto out_overflow;
|
||||||
|
|
||||||
seg_handle = be32_to_cpup(seg);
|
xdr_decode_rdma_segment(seg, &handle, &length, &offset);
|
||||||
seg_length = be32_to_cpup(seg + 1);
|
offset += info->wi_seg_off;
|
||||||
xdr_decode_hyper(seg + 2, &seg_offset);
|
|
||||||
seg_offset += info->wi_seg_off;
|
|
||||||
|
|
||||||
write_len = min(remaining, seg_length - info->wi_seg_off);
|
write_len = min(remaining, length - info->wi_seg_off);
|
||||||
ctxt = svc_rdma_get_rw_ctxt(rdma,
|
ctxt = svc_rdma_get_rw_ctxt(rdma,
|
||||||
(write_len >> PAGE_SHIFT) + 2);
|
(write_len >> PAGE_SHIFT) + 2);
|
||||||
if (!ctxt)
|
if (!ctxt)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
constructor(info, write_len, ctxt);
|
constructor(info, write_len, ctxt);
|
||||||
ret = svc_rdma_rw_ctx_init(rdma, ctxt, seg_offset, seg_handle,
|
ret = svc_rdma_rw_ctx_init(rdma, ctxt, offset, handle,
|
||||||
DMA_TO_DEVICE);
|
DMA_TO_DEVICE);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
trace_svcrdma_send_wseg(seg_handle, write_len, seg_offset);
|
trace_svcrdma_send_wseg(handle, write_len, offset);
|
||||||
|
|
||||||
list_add(&ctxt->rw_list, &cc->cc_rwctxts);
|
list_add(&ctxt->rw_list, &cc->cc_rwctxts);
|
||||||
cc->cc_sqecount += ret;
|
cc->cc_sqecount += ret;
|
||||||
if (write_len == seg_length - info->wi_seg_off) {
|
if (write_len == length - info->wi_seg_off) {
|
||||||
seg += 4;
|
seg += 4;
|
||||||
info->wi_seg_no++;
|
info->wi_seg_no++;
|
||||||
info->wi_seg_off = 0;
|
info->wi_seg_off = 0;
|
||||||
@@ -689,21 +688,17 @@ static int svc_rdma_build_read_chunk(struct svc_rqst *rqstp,
|
|||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
info->ri_chunklen = 0;
|
info->ri_chunklen = 0;
|
||||||
while (*p++ != xdr_zero && be32_to_cpup(p++) == info->ri_position) {
|
while (*p++ != xdr_zero && be32_to_cpup(p++) == info->ri_position) {
|
||||||
u32 rs_handle, rs_length;
|
u32 handle, length;
|
||||||
u64 rs_offset;
|
u64 offset;
|
||||||
|
|
||||||
rs_handle = be32_to_cpup(p++);
|
p = xdr_decode_rdma_segment(p, &handle, &length, &offset);
|
||||||
rs_length = be32_to_cpup(p++);
|
ret = svc_rdma_build_read_segment(info, rqstp, handle, length,
|
||||||
p = xdr_decode_hyper(p, &rs_offset);
|
offset);
|
||||||
|
|
||||||
ret = svc_rdma_build_read_segment(info, rqstp,
|
|
||||||
rs_handle, rs_length,
|
|
||||||
rs_offset);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
trace_svcrdma_send_rseg(rs_handle, rs_length, rs_offset);
|
trace_svcrdma_send_rseg(handle, length, offset);
|
||||||
info->ri_chunklen += rs_length;
|
info->ri_chunklen += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -106,7 +106,6 @@
|
|||||||
#include <rdma/rdma_cm.h>
|
#include <rdma/rdma_cm.h>
|
||||||
|
|
||||||
#include <linux/sunrpc/debug.h>
|
#include <linux/sunrpc/debug.h>
|
||||||
#include <linux/sunrpc/rpc_rdma.h>
|
|
||||||
#include <linux/sunrpc/svc_rdma.h>
|
#include <linux/sunrpc/svc_rdma.h>
|
||||||
|
|
||||||
#include "xprt_rdma.h"
|
#include "xprt_rdma.h"
|
||||||
@@ -375,9 +374,7 @@ static ssize_t svc_rdma_encode_write_segment(__be32 *src,
|
|||||||
if (!p)
|
if (!p)
|
||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
|
|
||||||
handle = be32_to_cpup(src++);
|
xdr_decode_rdma_segment(src, &handle, &length, &offset);
|
||||||
length = be32_to_cpup(src++);
|
|
||||||
xdr_decode_hyper(src, &offset);
|
|
||||||
|
|
||||||
*p++ = cpu_to_be32(handle);
|
*p++ = cpu_to_be32(handle);
|
||||||
if (*remaining < length) {
|
if (*remaining < length) {
|
||||||
|
@@ -55,7 +55,6 @@
|
|||||||
|
|
||||||
#include <linux/sunrpc/addr.h>
|
#include <linux/sunrpc/addr.h>
|
||||||
#include <linux/sunrpc/debug.h>
|
#include <linux/sunrpc/debug.h>
|
||||||
#include <linux/sunrpc/rpc_rdma.h>
|
|
||||||
#include <linux/sunrpc/svc_xprt.h>
|
#include <linux/sunrpc/svc_xprt.h>
|
||||||
#include <linux/sunrpc/svc_rdma.h>
|
#include <linux/sunrpc/svc_rdma.h>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user