Skip to content

Commit 81fe0c5

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Invoke rpcrdma_ia_open in the connect worker
Move rdma_cm_id creation into rpcrdma_ep_create() so that it is now responsible for allocating all per-connection hardware resources. With this clean-up, all three arms of the switch statement in rpcrdma_ep_connect are exactly the same now, thus the switch can be removed. Because device removal behaves a little differently than disconnection, there is a little more work to be done before rpcrdma_ep_destroy() can release the connection's rdma_cm_id. So it is not quite symmetrical with rpcrdma_ep_create() yet. Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 9ba373e commit 81fe0c5

File tree

4 files changed

+20
-143
lines changed

4 files changed

+20
-143
lines changed

include/trace/events/rpcrdma.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ DEFINE_CONN_EVENT(disconnect);
415415
DEFINE_RXPRT_EVENT(xprtrdma_create);
416416
DEFINE_RXPRT_EVENT(xprtrdma_op_destroy);
417417
DEFINE_RXPRT_EVENT(xprtrdma_remove);
418-
DEFINE_RXPRT_EVENT(xprtrdma_reinsert);
419418
DEFINE_RXPRT_EVENT(xprtrdma_op_inject_dsc);
420419
DEFINE_RXPRT_EVENT(xprtrdma_op_close);
421420
DEFINE_RXPRT_EVENT(xprtrdma_op_setport);

net/sunrpc/xprtrdma/transport.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ xprt_rdma_destroy(struct rpc_xprt *xprt)
286286

287287
rpcrdma_xprt_disconnect(r_xprt);
288288
rpcrdma_buffer_destroy(&r_xprt->rx_buf);
289-
rpcrdma_ia_close(&r_xprt->rx_ia);
290289

291290
xprt_rdma_free_addresses(xprt);
292291
xprt_free(xprt);
@@ -347,10 +346,6 @@ xprt_setup_rdma(struct xprt_create *args)
347346
xprt_rdma_format_addresses(xprt, sap);
348347

349348
new_xprt = rpcx_to_rdmax(xprt);
350-
rc = rpcrdma_ia_open(new_xprt);
351-
if (rc)
352-
goto out1;
353-
354349
rc = rpcrdma_buffer_create(new_xprt);
355350
if (rc)
356351
goto out2;
@@ -372,8 +367,6 @@ xprt_setup_rdma(struct xprt_create *args)
372367
rpcrdma_buffer_destroy(&new_xprt->rx_buf);
373368
rc = -ENODEV;
374369
out2:
375-
rpcrdma_ia_close(&new_xprt->rx_ia);
376-
out1:
377370
trace_xprtrdma_op_destroy(new_xprt);
378371
xprt_rdma_free_addresses(xprt);
379372
xprt_free(xprt);

net/sunrpc/xprtrdma/verbs.c

Lines changed: 20 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -345,31 +345,6 @@ rpcrdma_create_id(struct rpcrdma_xprt *xprt, struct rpcrdma_ia *ia)
345345
* Exported functions.
346346
*/
347347

348-
/**
349-
* rpcrdma_ia_open - Open and initialize an Interface Adapter.
350-
* @xprt: transport with IA to (re)initialize
351-
*
352-
* Returns 0 on success, negative errno if an appropriate
353-
* Interface Adapter could not be found and opened.
354-
*/
355-
int
356-
rpcrdma_ia_open(struct rpcrdma_xprt *xprt)
357-
{
358-
struct rpcrdma_ia *ia = &xprt->rx_ia;
359-
int rc;
360-
361-
ia->ri_id = rpcrdma_create_id(xprt, ia);
362-
if (IS_ERR(ia->ri_id)) {
363-
rc = PTR_ERR(ia->ri_id);
364-
goto out_err;
365-
}
366-
return 0;
367-
368-
out_err:
369-
rpcrdma_ia_close(ia);
370-
return rc;
371-
}
372-
373348
/**
374349
* rpcrdma_ia_remove - Handle device driver unload
375350
* @ia: interface adapter being removed
@@ -401,34 +376,26 @@ rpcrdma_ia_remove(struct rpcrdma_ia *ia)
401376
trace_xprtrdma_remove(r_xprt);
402377
}
403378

404-
/**
405-
* rpcrdma_ia_close - Clean up/close an IA.
406-
* @ia: interface adapter to close
407-
*
408-
*/
409-
void
410-
rpcrdma_ia_close(struct rpcrdma_ia *ia)
411-
{
412-
if (ia->ri_id && !IS_ERR(ia->ri_id))
413-
rdma_destroy_id(ia->ri_id);
414-
ia->ri_id = NULL;
415-
}
416-
417-
static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt,
418-
struct rdma_cm_id *id)
379+
static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt)
419380
{
420381
struct rpcrdma_ep *ep = &r_xprt->rx_ep;
421382
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
422383
struct rpcrdma_connect_private *pmsg = &ep->rep_cm_private;
384+
struct rdma_cm_id *id;
423385
int rc;
424386

387+
id = rpcrdma_create_id(r_xprt, ia);
388+
if (IS_ERR(id))
389+
return PTR_ERR(id);
390+
425391
ep->rep_max_requests = r_xprt->rx_xprt.max_reqs;
426392
ep->rep_inline_send = xprt_rdma_max_inline_write;
427393
ep->rep_inline_recv = xprt_rdma_max_inline_read;
428394

429395
rc = frwr_query_device(r_xprt, id->device);
430396
if (rc)
431-
return rc;
397+
goto out_destroy;
398+
432399
r_xprt->rx_buf.rb_max_requests = cpu_to_be32(ep->rep_max_requests);
433400

434401
ep->rep_attr.event_handler = rpcrdma_qp_event_handler;
@@ -507,10 +474,12 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt,
507474
rc = rdma_create_qp(id, ia->ri_pd, &ep->rep_attr);
508475
if (rc)
509476
goto out_destroy;
477+
ia->ri_id = id;
510478
return 0;
511479

512480
out_destroy:
513481
rpcrdma_ep_destroy(r_xprt);
482+
rdma_destroy_id(id);
514483
return rc;
515484
}
516485

@@ -536,79 +505,8 @@ static void rpcrdma_ep_destroy(struct rpcrdma_xprt *r_xprt)
536505
ia->ri_pd = NULL;
537506
}
538507

539-
/* Re-establish a connection after a device removal event.
540-
* Unlike a normal reconnection, a fresh PD and a new set
541-
* of MRs and buffers is needed.
542-
*/
543-
static int rpcrdma_ep_recreate_xprt(struct rpcrdma_xprt *r_xprt)
544-
{
545-
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
546-
int rc, err;
547-
548-
trace_xprtrdma_reinsert(r_xprt);
549-
550-
rc = -EHOSTUNREACH;
551-
if (rpcrdma_ia_open(r_xprt))
552-
goto out1;
553-
554-
rc = -ENETUNREACH;
555-
err = rpcrdma_ep_create(r_xprt, ia->ri_id);
556-
if (err)
557-
goto out2;
558-
return 0;
559-
560-
out2:
561-
rpcrdma_ia_close(ia);
562-
out1:
563-
return rc;
564-
}
565-
566-
static int rpcrdma_ep_reconnect(struct rpcrdma_xprt *r_xprt)
567-
{
568-
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
569-
struct rdma_cm_id *id, *old;
570-
int err, rc;
571-
572-
rc = -EHOSTUNREACH;
573-
id = rpcrdma_create_id(r_xprt, ia);
574-
if (IS_ERR(id))
575-
goto out;
576-
577-
/* As long as the new ID points to the same device as the
578-
* old ID, we can reuse the transport's existing PD and all
579-
* previously allocated MRs. Also, the same device means
580-
* the transport's previous DMA mappings are still valid.
581-
*
582-
* This is a sanity check only. There should be no way these
583-
* point to two different devices here.
584-
*/
585-
old = id;
586-
rc = -ENETUNREACH;
587-
if (ia->ri_id->device != id->device) {
588-
pr_err("rpcrdma: can't reconnect on different device!\n");
589-
goto out_destroy;
590-
}
591-
592-
err = rpcrdma_ep_create(r_xprt, id);
593-
if (err)
594-
goto out_destroy;
595-
596-
/* Atomically replace the transport's ID. */
597-
rc = 0;
598-
old = ia->ri_id;
599-
ia->ri_id = id;
600-
601-
out_destroy:
602-
rdma_destroy_id(old);
603-
out:
604-
return rc;
605-
}
606-
607-
/**
608-
* rpcrdma_xprt_connect - Connect an unconnected transport
609-
* @r_xprt: controlling transport instance
610-
*
611-
* Returns 0 on success or a negative errno.
508+
/*
509+
* Connect unconnected endpoint.
612510
*/
613511
int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt)
614512
{
@@ -618,25 +516,10 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt)
618516
int rc;
619517

620518
retry:
621-
switch (ep->rep_connected) {
622-
case 0:
623-
rc = -ENETUNREACH;
624-
if (rpcrdma_ep_create(r_xprt, ia->ri_id))
625-
goto out_noupdate;
626-
break;
627-
case -ENODEV:
628-
rc = rpcrdma_ep_recreate_xprt(r_xprt);
629-
if (rc)
630-
goto out_noupdate;
631-
break;
632-
case 1:
633-
rpcrdma_xprt_disconnect(r_xprt);
634-
/* fall through */
635-
default:
636-
rc = rpcrdma_ep_reconnect(r_xprt);
637-
if (rc)
638-
goto out;
639-
}
519+
rpcrdma_xprt_disconnect(r_xprt);
520+
rc = rpcrdma_ep_create(r_xprt);
521+
if (rc)
522+
goto out_noupdate;
640523

641524
ep->rep_connected = 0;
642525
xprt_clear_connected(xprt);
@@ -712,6 +595,10 @@ void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt)
712595
rpcrdma_sendctxs_destroy(r_xprt);
713596

714597
rpcrdma_ep_destroy(r_xprt);
598+
599+
if (ia->ri_id)
600+
rdma_destroy_id(ia->ri_id);
601+
ia->ri_id = NULL;
715602
}
716603

717604
/* Fixed-size circular FIFO queue. This implementation is wait-free and

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ extern unsigned int xprt_rdma_memreg_strategy;
457457
/*
458458
* Interface Adapter calls - xprtrdma/verbs.c
459459
*/
460-
int rpcrdma_ia_open(struct rpcrdma_xprt *xprt);
461460
void rpcrdma_ia_remove(struct rpcrdma_ia *ia);
462-
void rpcrdma_ia_close(struct rpcrdma_ia *);
463461

464462
/*
465463
* Endpoint calls - xprtrdma/verbs.c

0 commit comments

Comments
 (0)