Skip to content

Commit 283d285

Browse files
committed
svcrdma: Refactor the creation of listener CMA ID
In a moment, I will add a second consumer of CMA ID creation in svcrdma. Refactor so this code can be reused. Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 022d057 commit 283d285

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

net/sunrpc/xprtrdma/svc_rdma_transport.c

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565

6666
static struct svcxprt_rdma *svc_rdma_create_xprt(struct svc_serv *serv,
6767
struct net *net, int node);
68+
static int svc_rdma_listen_handler(struct rdma_cm_id *cma_id,
69+
struct rdma_cm_event *event);
6870
static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
6971
struct net *net,
7072
struct sockaddr *sa, int salen,
@@ -122,6 +124,41 @@ static void qp_event_handler(struct ib_event *event, void *context)
122124
}
123125
}
124126

127+
static struct rdma_cm_id *
128+
svc_rdma_create_listen_id(struct net *net, struct sockaddr *sap,
129+
void *context)
130+
{
131+
struct rdma_cm_id *listen_id;
132+
int ret;
133+
134+
listen_id = rdma_create_id(net, svc_rdma_listen_handler, context,
135+
RDMA_PS_TCP, IB_QPT_RC);
136+
if (IS_ERR(listen_id))
137+
return listen_id;
138+
139+
/* Allow both IPv4 and IPv6 sockets to bind a single port
140+
* at the same time.
141+
*/
142+
#if IS_ENABLED(CONFIG_IPV6)
143+
ret = rdma_set_afonly(listen_id, 1);
144+
if (ret)
145+
goto out_destroy;
146+
#endif
147+
ret = rdma_bind_addr(listen_id, sap);
148+
if (ret)
149+
goto out_destroy;
150+
151+
ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
152+
if (ret)
153+
goto out_destroy;
154+
155+
return listen_id;
156+
157+
out_destroy:
158+
rdma_destroy_id(listen_id);
159+
return ERR_PTR(ret);
160+
}
161+
125162
static struct svcxprt_rdma *svc_rdma_create_xprt(struct svc_serv *serv,
126163
struct net *net, int node)
127164
{
@@ -307,7 +344,6 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
307344
{
308345
struct rdma_cm_id *listen_id;
309346
struct svcxprt_rdma *cma_xprt;
310-
int ret;
311347

312348
if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6)
313349
return ERR_PTR(-EAFNOSUPPORT);
@@ -317,30 +353,13 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
317353
set_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
318354
strcpy(cma_xprt->sc_xprt.xpt_remotebuf, "listener");
319355

320-
listen_id = rdma_create_id(net, svc_rdma_listen_handler, cma_xprt,
321-
RDMA_PS_TCP, IB_QPT_RC);
356+
listen_id = svc_rdma_create_listen_id(net, sa, cma_xprt);
322357
if (IS_ERR(listen_id)) {
323-
ret = PTR_ERR(listen_id);
324-
goto err0;
358+
kfree(cma_xprt);
359+
return (struct svc_xprt *)listen_id;
325360
}
326-
327-
/* Allow both IPv4 and IPv6 sockets to bind a single port
328-
* at the same time.
329-
*/
330-
#if IS_ENABLED(CONFIG_IPV6)
331-
ret = rdma_set_afonly(listen_id, 1);
332-
if (ret)
333-
goto err1;
334-
#endif
335-
ret = rdma_bind_addr(listen_id, sa);
336-
if (ret)
337-
goto err1;
338361
cma_xprt->sc_cm_id = listen_id;
339362

340-
ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
341-
if (ret)
342-
goto err1;
343-
344363
/*
345364
* We need to use the address from the cm_id in case the
346365
* caller specified 0 for the port number.
@@ -349,12 +368,6 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
349368
svc_xprt_set_local(&cma_xprt->sc_xprt, sa, salen);
350369

351370
return &cma_xprt->sc_xprt;
352-
353-
err1:
354-
rdma_destroy_id(listen_id);
355-
err0:
356-
kfree(cma_xprt);
357-
return ERR_PTR(ret);
358371
}
359372

360373
/*

0 commit comments

Comments
 (0)