[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221121080049.3850133-5-yebin@huaweicloud.com>
Date: Mon, 21 Nov 2022 16:00:48 +0800
From: Ye Bin <yebin@...weicloud.com>
To: ericvh@...il.com, lucho@...kov.net, asmadeus@...ewreck.org,
linux_oss@...debyte.com, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com,
v9fs-developer@...ts.sourceforge.net, netdev@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, yebin10@...wei.com
Subject: [PATCH 4/5] 9p: factor out 'post_send()'
From: Ye Bin <yebin10@...wei.com>
Factor out 'post_send()' to send request. No functional change.
Signed-off-by: Ye Bin <yebin10@...wei.com>
---
net/9p/trans_rdma.c | 130 +++++++++++++++++++++++---------------------
1 file changed, 69 insertions(+), 61 deletions(-)
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index bcab550c2e2c..bb917389adc9 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -417,14 +417,72 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c)
return err;
}
-static int rdma_request(struct p9_client *client, struct p9_req_t *req)
+static int post_send(struct p9_client *client, struct p9_req_t *req)
{
struct p9_trans_rdma *rdma = client->trans;
+ struct p9_rdma_context *c = NULL;
struct ib_send_wr wr;
struct ib_sge sge;
+ int err;
+
+ c = kmalloc(sizeof *c, GFP_NOFS);
+ if (!c) {
+ err = -ENOMEM;
+ goto error;
+ }
+ c->req = req;
+
+ c->busa = ib_dma_map_single(rdma->cm_id->device,
+ c->req->tc.sdata, c->req->tc.size,
+ DMA_TO_DEVICE);
+ if (ib_dma_mapping_error(rdma->cm_id->device, c->busa)) {
+ err = -EIO;
+ goto error;
+ }
+
+ c->cqe.done = send_done;
+
+ sge.addr = c->busa;
+ sge.length = c->req->tc.size;
+ sge.lkey = rdma->pd->local_dma_lkey;
+
+ wr.next = NULL;
+ wr.wr_cqe = &c->cqe;
+ wr.opcode = IB_WR_SEND;
+ wr.send_flags = IB_SEND_SIGNALED;
+ wr.sg_list = &sge;
+ wr.num_sge = 1;
+
+ if (down_interruptible(&rdma->sq_sem)) {
+ err = -EINTR;
+ goto mapping_error;
+ }
+
+ /* Mark request as `sent' *before* we actually send it,
+ * because doing if after could erase the REQ_STATUS_RCVD
+ * status in case of a very fast reply.
+ */
+ req->status = REQ_STATUS_SENT;
+ err = ib_post_send(rdma->qp, &wr, NULL);
+ if (err)
+ goto sem_error;
+
+ return 0;
+sem_error:
+ up(&rdma->sq_sem);
+mapping_error:
+ ib_dma_unmap_single(rdma->cm_id->device, c->busa,
+ c->req->tc.size, DMA_TO_DEVICE);
+error:
+ kfree(c);
+ return err;
+}
+
+static int rdma_request(struct p9_client *client, struct p9_req_t *req)
+{
+ struct p9_trans_rdma *rdma = client->trans;
int err = 0;
unsigned long flags;
- struct p9_rdma_context *c = NULL;
struct p9_rdma_context *rpl_context = NULL;
/* When an error occurs between posting the recv and the send,
@@ -476,67 +534,17 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
req->rc.sdata = NULL;
dont_need_post_recv:
- /* Post the request */
- c = kmalloc(sizeof *c, GFP_NOFS);
- if (!c) {
- err = -ENOMEM;
- goto send_error;
- }
- c->req = req;
-
- c->busa = ib_dma_map_single(rdma->cm_id->device,
- c->req->tc.sdata, c->req->tc.size,
- DMA_TO_DEVICE);
- if (ib_dma_mapping_error(rdma->cm_id->device, c->busa)) {
- err = -EIO;
- goto send_error;
- }
-
- c->cqe.done = send_done;
-
- sge.addr = c->busa;
- sge.length = c->req->tc.size;
- sge.lkey = rdma->pd->local_dma_lkey;
-
- wr.next = NULL;
- wr.wr_cqe = &c->cqe;
- wr.opcode = IB_WR_SEND;
- wr.send_flags = IB_SEND_SIGNALED;
- wr.sg_list = &sge;
- wr.num_sge = 1;
-
- if (down_interruptible(&rdma->sq_sem)) {
- err = -EINTR;
- goto mapping_error;
- }
-
- /* Mark request as `sent' *before* we actually send it,
- * because doing if after could erase the REQ_STATUS_RCVD
- * status in case of a very fast reply.
- */
- req->status = REQ_STATUS_SENT;
- err = ib_post_send(rdma->qp, &wr, NULL);
+ err = post_send(client, req);
if (err) {
- up(&rdma->sq_sem);
- goto mapping_error;
+ req->status = REQ_STATUS_ERROR;
+ p9_debug(P9_DEBUG_ERROR, "Error %d in rdma_request()\n", err);
+
+ /* Ach.
+ * We did recv_post(), but not send. We have one recv_post
+ * in excess.
+ */
+ atomic_inc(&rdma->excess_rc);
}
-
- /* Success */
- return 0;
-
- /* Handle errors that happened during or while preparing the send: */
- mapping_error:
- ib_dma_unmap_single(rdma->cm_id->device, c->busa,
- c->req->tc.size, DMA_TO_DEVICE);
- send_error:
- req->status = REQ_STATUS_ERROR;
- kfree(c);
- p9_debug(P9_DEBUG_ERROR, "Error %d in rdma_request()\n", err);
-
- /* Ach.
- * We did recv_post(), but not send. We have one recv_post in excess.
- */
- atomic_inc(&rdma->excess_rc);
return err;
/* Handle errors that happened during or while preparing post_recv(): */
--
2.31.1
Powered by blists - more mailing lists