xprtrdma: Refactor management of mw_list field
authorChuck Lever <chuck.lever@oracle.com>
Wed, 8 Feb 2017 22:00:43 +0000 (17:00 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Fri, 10 Feb 2017 19:02:37 +0000 (14:02 -0500)
Clean up some duplicate code.

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

index 1ebb09e1ac4f8766cd99037b5d02b3b2b3965fae..59e64025ed96b52a0cb618638034de8282317c21 100644 (file)
@@ -310,10 +310,7 @@ fmr_op_unmap_safe(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
        struct rpcrdma_mw *mw;
 
        while (!list_empty(&req->rl_registered)) {
-               mw = list_first_entry(&req->rl_registered,
-                                     struct rpcrdma_mw, mw_list);
-               list_del_init(&mw->mw_list);
-
+               mw = rpcrdma_pop_mw(&req->rl_registered);
                if (sync)
                        fmr_op_recover_mr(mw);
                else
index 47bed5333c7ff20652af8dcb31f11ba1947927f6..f81dd93176c0767cd783328710a042ffe22aff6d 100644 (file)
@@ -466,8 +466,8 @@ frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
        struct ib_send_wr *first, **prev, *last, *bad_wr;
        struct rpcrdma_rep *rep = req->rl_reply;
        struct rpcrdma_ia *ia = &r_xprt->rx_ia;
-       struct rpcrdma_mw *mw, *tmp;
        struct rpcrdma_frmr *f;
+       struct rpcrdma_mw *mw;
        int count, rc;
 
        dprintk("RPC:       %s: req %p\n", __func__, req);
@@ -534,10 +534,10 @@ frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
         * them to the free MW list.
         */
 unmap:
-       list_for_each_entry_safe(mw, tmp, &req->rl_registered, mw_list) {
+       while (!list_empty(&req->rl_registered)) {
+               mw = rpcrdma_pop_mw(&req->rl_registered);
                dprintk("RPC:       %s: DMA unmapping frmr %p\n",
                        __func__, &mw->frmr);
-               list_del_init(&mw->mw_list);
                ib_dma_unmap_sg(ia->ri_device,
                                mw->mw_sg, mw->mw_nents, mw->mw_dir);
                rpcrdma_put_mw(r_xprt, mw);
@@ -571,10 +571,7 @@ frwr_op_unmap_safe(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
        struct rpcrdma_mw *mw;
 
        while (!list_empty(&req->rl_registered)) {
-               mw = list_first_entry(&req->rl_registered,
-                                     struct rpcrdma_mw, mw_list);
-               list_del_init(&mw->mw_list);
-
+               mw = rpcrdma_pop_mw(&req->rl_registered);
                if (sync)
                        frwr_op_recover_mr(mw);
                else
index 72b3ca0253a07de49e6bcb772b487afebecc6036..a044be2d6ad726eccfbd991038086aefc746df47 100644 (file)
@@ -322,7 +322,7 @@ rpcrdma_encode_read_list(struct rpcrdma_xprt *r_xprt,
                                                 false, &mw);
                if (n < 0)
                        return ERR_PTR(n);
-               list_add(&mw->mw_list, &req->rl_registered);
+               rpcrdma_push_mw(mw, &req->rl_registered);
 
                *iptr++ = xdr_one;      /* item present */
 
@@ -390,7 +390,7 @@ rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
                                                 true, &mw);
                if (n < 0)
                        return ERR_PTR(n);
-               list_add(&mw->mw_list, &req->rl_registered);
+               rpcrdma_push_mw(mw, &req->rl_registered);
 
                iptr = xdr_encode_rdma_segment(iptr, mw);
 
@@ -455,7 +455,7 @@ rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt,
                                                 true, &mw);
                if (n < 0)
                        return ERR_PTR(n);
-               list_add(&mw->mw_list, &req->rl_registered);
+               rpcrdma_push_mw(mw, &req->rl_registered);
 
                iptr = xdr_encode_rdma_segment(iptr, mw);
 
index d1ee33fa8055f8fe3a659874e4e654a0d1a94518..81cd31acf690f41573e5fedd9b837376543f5ce9 100644 (file)
@@ -776,9 +776,7 @@ rpcrdma_mr_recovery_worker(struct work_struct *work)
 
        spin_lock(&buf->rb_recovery_lock);
        while (!list_empty(&buf->rb_stale_mrs)) {
-               mw = list_first_entry(&buf->rb_stale_mrs,
-                                     struct rpcrdma_mw, mw_list);
-               list_del_init(&mw->mw_list);
+               mw = rpcrdma_pop_mw(&buf->rb_stale_mrs);
                spin_unlock(&buf->rb_recovery_lock);
 
                dprintk("RPC:       %s: recovering MR %p\n", __func__, mw);
@@ -796,7 +794,7 @@ rpcrdma_defer_mr_recovery(struct rpcrdma_mw *mw)
        struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
 
        spin_lock(&buf->rb_recovery_lock);
-       list_add(&mw->mw_list, &buf->rb_stale_mrs);
+       rpcrdma_push_mw(mw, &buf->rb_stale_mrs);
        spin_unlock(&buf->rb_recovery_lock);
 
        schedule_delayed_work(&buf->rb_recovery_worker, 0);
@@ -1072,11 +1070,8 @@ rpcrdma_get_mw(struct rpcrdma_xprt *r_xprt)
        struct rpcrdma_mw *mw = NULL;
 
        spin_lock(&buf->rb_mwlock);
-       if (!list_empty(&buf->rb_mws)) {
-               mw = list_first_entry(&buf->rb_mws,
-                                     struct rpcrdma_mw, mw_list);
-               list_del_init(&mw->mw_list);
-       }
+       if (!list_empty(&buf->rb_mws))
+               mw = rpcrdma_pop_mw(&buf->rb_mws);
        spin_unlock(&buf->rb_mwlock);
 
        if (!mw)
@@ -1099,7 +1094,7 @@ rpcrdma_put_mw(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mw *mw)
        struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
 
        spin_lock(&buf->rb_mwlock);
-       list_add_tail(&mw->mw_list, &buf->rb_mws);
+       rpcrdma_push_mw(mw, &buf->rb_mws);
        spin_unlock(&buf->rb_mwlock);
 }
 
index 852dd0a750a5d80d70b9cd91ae371c5f4e8ce731..171a35116de911878ce88402c3bac2979740af63 100644 (file)
@@ -354,6 +354,22 @@ rpcr_to_rdmar(struct rpc_rqst *rqst)
        return rqst->rq_xprtdata;
 }
 
+static inline void
+rpcrdma_push_mw(struct rpcrdma_mw *mw, struct list_head *list)
+{
+       list_add_tail(&mw->mw_list, list);
+}
+
+static inline struct rpcrdma_mw *
+rpcrdma_pop_mw(struct list_head *list)
+{
+       struct rpcrdma_mw *mw;
+
+       mw = list_first_entry(list, struct rpcrdma_mw, mw_list);
+       list_del(&mw->mw_list);
+       return mw;
+}
+
 /*
  * struct rpcrdma_buffer -- holds list/queue of pre-registered memory for
  * inline requests/replies, and client/server credits.