Merge tag 'nfs-for-4.21-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
[sfrench/cifs-2.6.git] / net / sunrpc / xprtrdma / transport.c
index 9141068693fafab2b28e68c8130698b70e54bc3d..fbc171ebfe9172dd8eb9a29f35ce6ef3e9bdeea3 100644 (file)
@@ -268,7 +268,7 @@ xprt_rdma_inject_disconnect(struct rpc_xprt *xprt)
 {
        struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
 
-       trace_xprtrdma_inject_dsc(r_xprt);
+       trace_xprtrdma_op_inject_dsc(r_xprt);
        rdma_disconnect(r_xprt->rx_ia.ri_id);
 }
 
@@ -284,7 +284,7 @@ xprt_rdma_destroy(struct rpc_xprt *xprt)
 {
        struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
 
-       trace_xprtrdma_destroy(r_xprt);
+       trace_xprtrdma_op_destroy(r_xprt);
 
        cancel_delayed_work_sync(&r_xprt->rx_connect_worker);
 
@@ -318,17 +318,12 @@ xprt_setup_rdma(struct xprt_create *args)
        struct sockaddr *sap;
        int rc;
 
-       if (args->addrlen > sizeof(xprt->addr)) {
-               dprintk("RPC:       %s: address too large\n", __func__);
+       if (args->addrlen > sizeof(xprt->addr))
                return ERR_PTR(-EBADF);
-       }
 
        xprt = xprt_alloc(args->net, sizeof(struct rpcrdma_xprt), 0, 0);
-       if (xprt == NULL) {
-               dprintk("RPC:       %s: couldn't allocate rpcrdma_xprt\n",
-                       __func__);
+       if (!xprt)
                return ERR_PTR(-ENOMEM);
-       }
 
        /* 60 second timeout, no retries */
        xprt->timeout = &xprt_rdma_default_timeout;
@@ -399,7 +394,7 @@ xprt_setup_rdma(struct xprt_create *args)
        INIT_DELAYED_WORK(&new_xprt->rx_connect_worker,
                          xprt_rdma_connect_worker);
 
-       xprt->max_payload = new_xprt->rx_ia.ri_ops->ro_maxpages(new_xprt);
+       xprt->max_payload = frwr_maxpages(new_xprt);
        if (xprt->max_payload == 0)
                goto out4;
        xprt->max_payload <<= PAGE_SHIFT;
@@ -423,7 +418,7 @@ out3:
 out2:
        rpcrdma_ia_close(&new_xprt->rx_ia);
 out1:
-       trace_xprtrdma_destroy(new_xprt);
+       trace_xprtrdma_op_destroy(new_xprt);
        xprt_rdma_free_addresses(xprt);
        xprt_free(xprt);
        return ERR_PTR(rc);
@@ -433,29 +428,33 @@ out1:
  * xprt_rdma_close - close a transport connection
  * @xprt: transport context
  *
- * Called during transport shutdown, reconnect, or device removal.
+ * Called during autoclose or device removal.
+ *
  * Caller holds @xprt's send lock to prevent activity on this
  * transport while the connection is torn down.
  */
-static void
-xprt_rdma_close(struct rpc_xprt *xprt)
+void xprt_rdma_close(struct rpc_xprt *xprt)
 {
        struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
        struct rpcrdma_ep *ep = &r_xprt->rx_ep;
        struct rpcrdma_ia *ia = &r_xprt->rx_ia;
 
-       dprintk("RPC:       %s: closing xprt %p\n", __func__, xprt);
+       might_sleep();
+
+       trace_xprtrdma_op_close(r_xprt);
+
+       /* Prevent marshaling and sending of new requests */
+       xprt_clear_connected(xprt);
 
        if (test_and_clear_bit(RPCRDMA_IAF_REMOVING, &ia->ri_flags)) {
-               xprt_clear_connected(xprt);
                rpcrdma_ia_remove(ia);
-               return;
+               goto out;
        }
+
        if (ep->rep_connected == -ENODEV)
                return;
        if (ep->rep_connected > 0)
                xprt->reestablish_timeout = 0;
-       xprt_disconnect_done(xprt);
        rpcrdma_ep_disconnect(ep, ia);
 
        /* Prepare @xprt for the next connection by reinitializing
@@ -463,6 +462,10 @@ xprt_rdma_close(struct rpc_xprt *xprt)
         */
        r_xprt->rx_buf.rb_credits = 1;
        xprt->cwnd = RPC_CWNDSHIFT;
+
+out:
+       ++xprt->connect_cookie;
+       xprt_disconnect_done(xprt);
 }
 
 /**
@@ -525,6 +528,7 @@ xprt_rdma_connect(struct rpc_xprt *xprt, struct rpc_task *task)
 {
        struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
 
+       trace_xprtrdma_op_connect(r_xprt);
        if (r_xprt->rx_ep.rep_connected != 0) {
                /* Reconnect */
                schedule_delayed_work(&r_xprt->rx_connect_worker,
@@ -659,11 +663,11 @@ xprt_rdma_allocate(struct rpc_task *task)
 
        rqst->rq_buffer = req->rl_sendbuf->rg_base;
        rqst->rq_rbuffer = req->rl_recvbuf->rg_base;
-       trace_xprtrdma_allocate(task, req);
+       trace_xprtrdma_op_allocate(task, req);
        return 0;
 
 out_fail:
-       trace_xprtrdma_allocate(task, NULL);
+       trace_xprtrdma_op_allocate(task, NULL);
        return -ENOMEM;
 }
 
@@ -682,7 +686,7 @@ xprt_rdma_free(struct rpc_task *task)
 
        if (test_bit(RPCRDMA_REQ_F_PENDING, &req->rl_flags))
                rpcrdma_release_rqst(r_xprt, req);
-       trace_xprtrdma_rpc_done(task, req);
+       trace_xprtrdma_op_free(task, req);
 }
 
 /**
@@ -696,8 +700,10 @@ xprt_rdma_free(struct rpc_task *task)
  *     %-ENOTCONN if the caller should reconnect and call again
  *     %-EAGAIN if the caller should call again
  *     %-ENOBUFS if the caller should call again after a delay
- *     %-EIO if a permanent error occurred and the request was not
- *             sent. Do not try to send this message again.
+ *     %-EMSGSIZE if encoding ran out of buffer space. The request
+ *             was not sent. Do not try to send this message again.
+ *     %-EIO if an I/O error occurred. The request was not sent.
+ *             Do not try to send this message again.
  */
 static int
 xprt_rdma_send_request(struct rpc_rqst *rqst)
@@ -713,7 +719,7 @@ xprt_rdma_send_request(struct rpc_rqst *rqst)
 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
 
        if (!xprt_connected(xprt))
-               goto drop_connection;
+               return -ENOTCONN;
 
        if (!xprt_request_get_cong(xprt, rqst))
                return -EBADSLT;
@@ -745,8 +751,8 @@ failed_marshal:
        if (rc != -ENOTCONN)
                return rc;
 drop_connection:
-       xprt_disconnect_done(xprt);
-       return -ENOTCONN;       /* implies disconnect */
+       xprt_rdma_close(xprt);
+       return -ENOTCONN;
 }
 
 void xprt_rdma_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
@@ -843,58 +849,31 @@ static struct xprt_class xprt_rdma = {
 
 void xprt_rdma_cleanup(void)
 {
-       int rc;
-
-       dprintk("RPCRDMA Module Removed, deregister RPC RDMA transport\n");
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
        if (sunrpc_table_header) {
                unregister_sysctl_table(sunrpc_table_header);
                sunrpc_table_header = NULL;
        }
 #endif
-       rc = xprt_unregister_transport(&xprt_rdma);
-       if (rc)
-               dprintk("RPC:       %s: xprt_unregister returned %i\n",
-                       __func__, rc);
-
-       rpcrdma_destroy_wq();
 
-       rc = xprt_unregister_transport(&xprt_rdma_bc);
-       if (rc)
-               dprintk("RPC:       %s: xprt_unregister(bc) returned %i\n",
-                       __func__, rc);
+       xprt_unregister_transport(&xprt_rdma);
+       xprt_unregister_transport(&xprt_rdma_bc);
 }
 
 int xprt_rdma_init(void)
 {
        int rc;
 
-       rc = rpcrdma_alloc_wq();
-       if (rc)
-               return rc;
-
        rc = xprt_register_transport(&xprt_rdma);
-       if (rc) {
-               rpcrdma_destroy_wq();
+       if (rc)
                return rc;
-       }
 
        rc = xprt_register_transport(&xprt_rdma_bc);
        if (rc) {
                xprt_unregister_transport(&xprt_rdma);
-               rpcrdma_destroy_wq();
                return rc;
        }
 
-       dprintk("RPCRDMA Module Init, register RPC RDMA transport\n");
-
-       dprintk("Defaults:\n");
-       dprintk("\tSlots %d\n"
-               "\tMaxInlineRead %d\n\tMaxInlineWrite %d\n",
-               xprt_rdma_slot_table_entries,
-               xprt_rdma_max_inline_read, xprt_rdma_max_inline_write);
-       dprintk("\tPadding 0\n\tMemreg %d\n", xprt_rdma_memreg_strategy);
-
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
        if (!sunrpc_table_header)
                sunrpc_table_header = register_sysctl_table(sunrpc_table);