Skip to content

Commit 2239535

Browse files
committed
svcrdma: Factor out WR chain linking into helper
svc_rdma_prepare_write_chunk() and svc_rdma_prepare_reply_chunk() contain identical code for linking RDMA R/W work requests onto a Send context's WR chain. This duplication increases maintenance burden and risks divergent bug fixes. Introduce svc_rdma_cc_link_wrs() to consolidate the WR chain linking logic. The helper walks the chunk context's rwctxts list, chains each WR via rdma_rw_ctx_wrs(), and updates the Send context's chain head and SQE count. Completion signaling is requested only for the tail WR (posted first). No functional change. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent d16f060 commit 2239535

1 file changed

Lines changed: 28 additions & 39 deletions

File tree

net/sunrpc/xprtrdma/svc_rdma_rw.c

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -619,15 +619,32 @@ static int svc_rdma_xb_write(const struct xdr_buf *xdr, void *data)
619619
return xdr->len;
620620
}
621621

622-
/*
623-
* svc_rdma_prepare_write_chunk - Link Write WRs for @chunk onto @sctxt's chain
624-
*
625-
* Write WRs are prepended to the Send WR chain so that a single
626-
* ib_post_send() posts both RDMA Writes and the final Send. Only
627-
* the first WR in each chunk gets a CQE for error detection;
628-
* subsequent WRs complete without individual completion events.
629-
* The Send WR's signaled completion indicates all chained
630-
* operations have finished.
622+
/* Link chunk WRs onto @sctxt's WR chain. Completion is requested
623+
* for the tail WR, which is posted first.
624+
*/
625+
static void svc_rdma_cc_link_wrs(struct svcxprt_rdma *rdma,
626+
struct svc_rdma_send_ctxt *sctxt,
627+
struct svc_rdma_chunk_ctxt *cc)
628+
{
629+
struct ib_send_wr *first_wr;
630+
struct list_head *pos;
631+
struct ib_cqe *cqe;
632+
633+
first_wr = sctxt->sc_wr_chain;
634+
cqe = &cc->cc_cqe;
635+
list_for_each(pos, &cc->cc_rwctxts) {
636+
struct svc_rdma_rw_ctxt *rwc;
637+
638+
rwc = list_entry(pos, struct svc_rdma_rw_ctxt, rw_list);
639+
first_wr = rdma_rw_ctx_wrs(&rwc->rw_ctx, rdma->sc_qp,
640+
rdma->sc_port_num, cqe, first_wr);
641+
cqe = NULL;
642+
}
643+
sctxt->sc_wr_chain = first_wr;
644+
sctxt->sc_sqecount += cc->cc_sqecount;
645+
}
646+
647+
/* Link Write WRs for @chunk onto @sctxt's WR chain.
631648
*/
632649
static int svc_rdma_prepare_write_chunk(struct svcxprt_rdma *rdma,
633650
struct svc_rdma_send_ctxt *sctxt,
@@ -636,10 +653,7 @@ static int svc_rdma_prepare_write_chunk(struct svcxprt_rdma *rdma,
636653
{
637654
struct svc_rdma_write_info *info;
638655
struct svc_rdma_chunk_ctxt *cc;
639-
struct ib_send_wr *first_wr;
640656
struct xdr_buf payload;
641-
struct list_head *pos;
642-
struct ib_cqe *cqe;
643657
int ret;
644658

645659
if (xdr_buf_subsegment(xdr, &payload, chunk->ch_position,
@@ -659,18 +673,7 @@ static int svc_rdma_prepare_write_chunk(struct svcxprt_rdma *rdma,
659673
if (unlikely(sctxt->sc_sqecount + cc->cc_sqecount > rdma->sc_sq_depth))
660674
goto out_err;
661675

662-
first_wr = sctxt->sc_wr_chain;
663-
cqe = &cc->cc_cqe;
664-
list_for_each(pos, &cc->cc_rwctxts) {
665-
struct svc_rdma_rw_ctxt *rwc;
666-
667-
rwc = list_entry(pos, struct svc_rdma_rw_ctxt, rw_list);
668-
first_wr = rdma_rw_ctx_wrs(&rwc->rw_ctx, rdma->sc_qp,
669-
rdma->sc_port_num, cqe, first_wr);
670-
cqe = NULL;
671-
}
672-
sctxt->sc_wr_chain = first_wr;
673-
sctxt->sc_sqecount += cc->cc_sqecount;
676+
svc_rdma_cc_link_wrs(rdma, sctxt, cc);
674677
list_add(&info->wi_list, &sctxt->sc_write_info_list);
675678

676679
trace_svcrdma_post_write_chunk(&cc->cc_cid, cc->cc_sqecount);
@@ -732,9 +735,6 @@ int svc_rdma_prepare_reply_chunk(struct svcxprt_rdma *rdma,
732735
{
733736
struct svc_rdma_write_info *info = &sctxt->sc_reply_info;
734737
struct svc_rdma_chunk_ctxt *cc = &info->wi_cc;
735-
struct ib_send_wr *first_wr;
736-
struct list_head *pos;
737-
struct ib_cqe *cqe;
738738
int ret;
739739

740740
info->wi_rdma = rdma;
@@ -748,18 +748,7 @@ int svc_rdma_prepare_reply_chunk(struct svcxprt_rdma *rdma,
748748
if (ret < 0)
749749
return ret;
750750

751-
first_wr = sctxt->sc_wr_chain;
752-
cqe = &cc->cc_cqe;
753-
list_for_each(pos, &cc->cc_rwctxts) {
754-
struct svc_rdma_rw_ctxt *rwc;
755-
756-
rwc = list_entry(pos, struct svc_rdma_rw_ctxt, rw_list);
757-
first_wr = rdma_rw_ctx_wrs(&rwc->rw_ctx, rdma->sc_qp,
758-
rdma->sc_port_num, cqe, first_wr);
759-
cqe = NULL;
760-
}
761-
sctxt->sc_wr_chain = first_wr;
762-
sctxt->sc_sqecount += cc->cc_sqecount;
751+
svc_rdma_cc_link_wrs(rdma, sctxt, cc);
763752

764753
trace_svcrdma_post_reply_chunk(&cc->cc_cid, cc->cc_sqecount);
765754
return xdr->len;

0 commit comments

Comments
 (0)