xprtrdma: Initialize rb_credits in one place
authorChuck Lever <chuck.lever@oracle.com>
Wed, 9 Oct 2019 17:07:32 +0000 (13:07 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Thu, 24 Oct 2019 14:30:39 +0000 (10:30 -0400)
Clean up/code de-duplication.

Nit: RPC_CWNDSHIFT is incorrect as the initial value for xprt->cwnd.
This mistake does not appear to have operational consequences, since
the cwnd value is replaced with a valid value upon the first Receive
completion.

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

index b86b5fd62d9f515d23f47e30cdbc31ad708408eb..f1e3639d20502aa235cc2d24350c2fc1e3571f3b 100644 (file)
@@ -916,6 +916,40 @@ out_err:
        return ret;
 }
 
+static void __rpcrdma_update_cwnd_locked(struct rpc_xprt *xprt,
+                                        struct rpcrdma_buffer *buf,
+                                        u32 grant)
+{
+       buf->rb_credits = grant;
+       xprt->cwnd = grant << RPC_CWNDSHIFT;
+}
+
+static void rpcrdma_update_cwnd(struct rpcrdma_xprt *r_xprt, u32 grant)
+{
+       struct rpc_xprt *xprt = &r_xprt->rx_xprt;
+
+       spin_lock(&xprt->transport_lock);
+       __rpcrdma_update_cwnd_locked(xprt, &r_xprt->rx_buf, grant);
+       spin_unlock(&xprt->transport_lock);
+}
+
+/**
+ * rpcrdma_reset_cwnd - Reset the xprt's congestion window
+ * @r_xprt: controlling transport instance
+ *
+ * Prepare @r_xprt for the next connection by reinitializing
+ * its credit grant to one (see RFC 8166, Section 3.3.3).
+ */
+void rpcrdma_reset_cwnd(struct rpcrdma_xprt *r_xprt)
+{
+       struct rpc_xprt *xprt = &r_xprt->rx_xprt;
+
+       spin_lock(&xprt->transport_lock);
+       xprt->cong = 0;
+       __rpcrdma_update_cwnd_locked(xprt, &r_xprt->rx_buf, 1);
+       spin_unlock(&xprt->transport_lock);
+}
+
 /**
  * rpcrdma_inline_fixup - Scatter inline received data into rqst's iovecs
  * @rqst: controlling RPC request
@@ -1356,12 +1390,8 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
                credits = 1;    /* don't deadlock */
        else if (credits > buf->rb_max_requests)
                credits = buf->rb_max_requests;
-       if (buf->rb_credits != credits) {
-               spin_lock(&xprt->transport_lock);
-               buf->rb_credits = credits;
-               xprt->cwnd = credits << RPC_CWNDSHIFT;
-               spin_unlock(&xprt->transport_lock);
-       }
+       if (buf->rb_credits != credits)
+               rpcrdma_update_cwnd(r_xprt, credits);
 
        req = rpcr_to_rdmar(rqst);
        if (req->rl_reply) {
index c67d465dc06201a736fb1604b3ea9fe30c2cda4f..0711308277ebdad3169687b7bdf4bb78c43a8d85 100644 (file)
@@ -425,15 +425,6 @@ void xprt_rdma_close(struct rpc_xprt *xprt)
                return;
        rpcrdma_ep_disconnect(ep, ia);
 
-       /* Prepare @xprt for the next connection by reinitializing
-        * its credit grant to one (see RFC 8166, Section 3.3.3).
-        */
-       spin_lock(&xprt->transport_lock);
-       r_xprt->rx_buf.rb_credits = 1;
-       xprt->cong = 0;
-       xprt->cwnd = RPC_CWNDSHIFT;
-       spin_unlock(&xprt->transport_lock);
-
 out:
        xprt->reestablish_timeout = 0;
        ++xprt->connect_cookie;
index f4b136504e96456db9c24440920c02ee782bb161..97bc15e287b20816af354efbaba851fff44fdea3 100644 (file)
@@ -727,6 +727,7 @@ retry:
        ep->rep_connected = 0;
        xprt_clear_connected(xprt);
 
+       rpcrdma_reset_cwnd(r_xprt);
        rpcrdma_post_recvs(r_xprt, true);
 
        rc = rdma_connect(ia->ri_id, &ep->rep_remote_cma);
@@ -1163,7 +1164,6 @@ int rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
                list_add(&req->rl_list, &buf->rb_send_bufs);
        }
 
-       buf->rb_credits = 1;
        init_llist_head(&buf->rb_free_reps);
 
        rc = rpcrdma_sendctxs_create(r_xprt);
index 65e6b0eb862e3559d1e57089ca6970893eecb213..b170cf52c638db7799dd3be495c18f4235c1d970 100644 (file)
@@ -576,6 +576,7 @@ int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,
 void rpcrdma_sendctx_unmap(struct rpcrdma_sendctx *sc);
 int rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst);
 void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *);
+void rpcrdma_reset_cwnd(struct rpcrdma_xprt *r_xprt);
 void rpcrdma_complete_rqst(struct rpcrdma_rep *rep);
 void rpcrdma_reply_handler(struct rpcrdma_rep *rep);