xprtrdma: Clean up disconnect
authorChuck Lever <chuck.lever@oracle.com>
Mon, 15 Jun 2020 13:21:07 +0000 (09:21 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 22 Jun 2020 13:34:35 +0000 (09:34 -0400)
1. Ensure that only rpcrdma_cm_event_handler() modifies
   ep->re_connect_status to avoid racy changes to that field.

2. Ensure that xprt_force_disconnect() is invoked only once as a
   transport is closed or destroyed.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
net/sunrpc/xprtrdma/verbs.c
net/sunrpc/xprtrdma/xprt_rdma.h

index 7a112612fc8f51eda29e3a7d7a7c45973c2dc0cb..2198c8ec8dff62e7c3ce620fe3c22418c5d12e3c 100644 (file)
@@ -130,6 +130,16 @@ static void rpcrdma_qp_event_handler(struct ib_event *event, void *context)
        trace_xprtrdma_qp_event(ep, event);
 }
 
+/* Ensure xprt_force_disconnect() is invoked exactly once when a
+ * connection is closed or lost. (The important thing is it needs
+ * to be invoked "at least" once).
+ */
+static void rpcrdma_force_disconnect(struct rpcrdma_ep *ep)
+{
+       if (atomic_add_unless(&ep->re_force_disconnect, 1, 1))
+               xprt_force_disconnect(ep->re_xprt);
+}
+
 /**
  * rpcrdma_flush_disconnect - Disconnect on flushed completion
  * @r_xprt: transport to disconnect
@@ -139,13 +149,8 @@ static void rpcrdma_qp_event_handler(struct ib_event *event, void *context)
  */
 void rpcrdma_flush_disconnect(struct rpcrdma_xprt *r_xprt, struct ib_wc *wc)
 {
-       struct rpc_xprt *xprt = &r_xprt->rx_xprt;
-
-       if (wc->status != IB_WC_SUCCESS &&
-           r_xprt->rx_ep->re_connect_status == 1) {
-               r_xprt->rx_ep->re_connect_status = -ECONNABORTED;
-               xprt_force_disconnect(xprt);
-       }
+       if (wc->status != IB_WC_SUCCESS)
+               rpcrdma_force_disconnect(r_xprt->rx_ep);
 }
 
 /**
@@ -243,7 +248,6 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
 {
        struct sockaddr *sap = (struct sockaddr *)&id->route.addr.dst_addr;
        struct rpcrdma_ep *ep = id->context;
-       struct rpc_xprt *xprt = ep->re_xprt;
 
        might_sleep();
 
@@ -267,7 +271,6 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
                /* fall through */
        case RDMA_CM_EVENT_ADDR_CHANGE:
                ep->re_connect_status = -ENODEV;
-               xprt_force_disconnect(xprt);
                goto disconnected;
        case RDMA_CM_EVENT_ESTABLISHED:
                rpcrdma_ep_get(ep);
@@ -292,7 +295,7 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
        case RDMA_CM_EVENT_DISCONNECTED:
                ep->re_connect_status = -ECONNABORTED;
 disconnected:
-               xprt_force_disconnect(xprt);
+               rpcrdma_force_disconnect(ep);
                return rpcrdma_ep_put(ep);
        default:
                break;
index 098d05a62eadd53587903fc1766d455e293aa2b7..43974ef39a5055f9c56b736cc5c5da20d36a4c55 100644 (file)
@@ -82,6 +82,7 @@ struct rpcrdma_ep {
        unsigned int            re_max_inline_recv;
        int                     re_async_rc;
        int                     re_connect_status;
+       atomic_t                re_force_disconnect;
        struct ib_qp_init_attr  re_attr;
        wait_queue_head_t       re_connect_wait;
        struct rpc_xprt         *re_xprt;