xprtrdma: Use an anonymous union in struct rpcrdma_mw

Clean up: Make code more readable.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Devesh Sharma <devesh.sharma@broadcom.com>
Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Chuck Lever 2016-03-04 11:28:45 -05:00 committed by Anna Schumaker
parent 552bf22528
commit c882a655b7
3 changed files with 36 additions and 36 deletions

View File

@ -80,13 +80,13 @@ fmr_op_init(struct rpcrdma_xprt *r_xprt)
if (!r) if (!r)
goto out; goto out;
r->r.fmr.physaddrs = kmalloc(RPCRDMA_MAX_FMR_SGES * r->fmr.physaddrs = kmalloc(RPCRDMA_MAX_FMR_SGES *
sizeof(u64), GFP_KERNEL); sizeof(u64), GFP_KERNEL);
if (!r->r.fmr.physaddrs) if (!r->fmr.physaddrs)
goto out_free; goto out_free;
r->r.fmr.fmr = ib_alloc_fmr(pd, mr_access_flags, &fmr_attr); r->fmr.fmr = ib_alloc_fmr(pd, mr_access_flags, &fmr_attr);
if (IS_ERR(r->r.fmr.fmr)) if (IS_ERR(r->fmr.fmr))
goto out_fmr_err; goto out_fmr_err;
list_add(&r->mw_list, &buf->rb_mws); list_add(&r->mw_list, &buf->rb_mws);
@ -95,9 +95,9 @@ fmr_op_init(struct rpcrdma_xprt *r_xprt)
return 0; return 0;
out_fmr_err: out_fmr_err:
rc = PTR_ERR(r->r.fmr.fmr); rc = PTR_ERR(r->fmr.fmr);
dprintk("RPC: %s: ib_alloc_fmr status %i\n", __func__, rc); dprintk("RPC: %s: ib_alloc_fmr status %i\n", __func__, rc);
kfree(r->r.fmr.physaddrs); kfree(r->fmr.physaddrs);
out_free: out_free:
kfree(r); kfree(r);
out: out:
@ -109,7 +109,7 @@ __fmr_unmap(struct rpcrdma_mw *r)
{ {
LIST_HEAD(l); LIST_HEAD(l);
list_add(&r->r.fmr.fmr->list, &l); list_add(&r->fmr.fmr->list, &l);
return ib_unmap_fmr(&l); return ib_unmap_fmr(&l);
} }
@ -148,7 +148,7 @@ fmr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
nsegs = RPCRDMA_MAX_FMR_SGES; nsegs = RPCRDMA_MAX_FMR_SGES;
for (i = 0; i < nsegs;) { for (i = 0; i < nsegs;) {
rpcrdma_map_one(device, seg, direction); rpcrdma_map_one(device, seg, direction);
mw->r.fmr.physaddrs[i] = seg->mr_dma; mw->fmr.physaddrs[i] = seg->mr_dma;
len += seg->mr_len; len += seg->mr_len;
++seg; ++seg;
++i; ++i;
@ -158,13 +158,13 @@ fmr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
break; break;
} }
rc = ib_map_phys_fmr(mw->r.fmr.fmr, mw->r.fmr.physaddrs, rc = ib_map_phys_fmr(mw->fmr.fmr, mw->fmr.physaddrs,
i, seg1->mr_dma); i, seg1->mr_dma);
if (rc) if (rc)
goto out_maperr; goto out_maperr;
seg1->rl_mw = mw; seg1->rl_mw = mw;
seg1->mr_rkey = mw->r.fmr.fmr->rkey; seg1->mr_rkey = mw->fmr.fmr->rkey;
seg1->mr_base = seg1->mr_dma + pageoff; seg1->mr_base = seg1->mr_dma + pageoff;
seg1->mr_nsegs = i; seg1->mr_nsegs = i;
seg1->mr_len = len; seg1->mr_len = len;
@ -219,7 +219,7 @@ fmr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
seg = &req->rl_segments[i]; seg = &req->rl_segments[i];
mw = seg->rl_mw; mw = seg->rl_mw;
list_add(&mw->r.fmr.fmr->list, &unmap_list); list_add(&mw->fmr.fmr->list, &unmap_list);
i += seg->mr_nsegs; i += seg->mr_nsegs;
} }
@ -281,9 +281,9 @@ fmr_op_destroy(struct rpcrdma_buffer *buf)
while (!list_empty(&buf->rb_all)) { while (!list_empty(&buf->rb_all)) {
r = list_entry(buf->rb_all.next, struct rpcrdma_mw, mw_all); r = list_entry(buf->rb_all.next, struct rpcrdma_mw, mw_all);
list_del(&r->mw_all); list_del(&r->mw_all);
kfree(r->r.fmr.physaddrs); kfree(r->fmr.physaddrs);
rc = ib_dealloc_fmr(r->r.fmr.fmr); rc = ib_dealloc_fmr(r->fmr.fmr);
if (rc) if (rc)
dprintk("RPC: %s: ib_dealloc_fmr failed %i\n", dprintk("RPC: %s: ib_dealloc_fmr failed %i\n",
__func__, rc); __func__, rc);

View File

@ -109,20 +109,20 @@ static void
__frwr_recovery_worker(struct work_struct *work) __frwr_recovery_worker(struct work_struct *work)
{ {
struct rpcrdma_mw *r = container_of(work, struct rpcrdma_mw, struct rpcrdma_mw *r = container_of(work, struct rpcrdma_mw,
r.frmr.fr_work); frmr.fr_work);
struct rpcrdma_xprt *r_xprt = r->r.frmr.fr_xprt; struct rpcrdma_xprt *r_xprt = r->frmr.fr_xprt;
unsigned int depth = r_xprt->rx_ia.ri_max_frmr_depth; unsigned int depth = r_xprt->rx_ia.ri_max_frmr_depth;
struct ib_pd *pd = r_xprt->rx_ia.ri_pd; struct ib_pd *pd = r_xprt->rx_ia.ri_pd;
if (ib_dereg_mr(r->r.frmr.fr_mr)) if (ib_dereg_mr(r->frmr.fr_mr))
goto out_fail; goto out_fail;
r->r.frmr.fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth); r->frmr.fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth);
if (IS_ERR(r->r.frmr.fr_mr)) if (IS_ERR(r->frmr.fr_mr))
goto out_fail; goto out_fail;
dprintk("RPC: %s: recovered FRMR %p\n", __func__, r); dprintk("RPC: %s: recovered FRMR %p\n", __func__, r);
r->r.frmr.fr_state = FRMR_IS_INVALID; r->frmr.fr_state = FRMR_IS_INVALID;
rpcrdma_put_mw(r_xprt, r); rpcrdma_put_mw(r_xprt, r);
return; return;
@ -137,15 +137,15 @@ out_fail:
static void static void
__frwr_queue_recovery(struct rpcrdma_mw *r) __frwr_queue_recovery(struct rpcrdma_mw *r)
{ {
INIT_WORK(&r->r.frmr.fr_work, __frwr_recovery_worker); INIT_WORK(&r->frmr.fr_work, __frwr_recovery_worker);
queue_work(frwr_recovery_wq, &r->r.frmr.fr_work); queue_work(frwr_recovery_wq, &r->frmr.fr_work);
} }
static int static int
__frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device, __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device,
unsigned int depth) unsigned int depth)
{ {
struct rpcrdma_frmr *f = &r->r.frmr; struct rpcrdma_frmr *f = &r->frmr;
int rc; int rc;
f->fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth); f->fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth);
@ -179,11 +179,11 @@ __frwr_release(struct rpcrdma_mw *r)
{ {
int rc; int rc;
rc = ib_dereg_mr(r->r.frmr.fr_mr); rc = ib_dereg_mr(r->frmr.fr_mr);
if (rc) if (rc)
dprintk("RPC: %s: ib_dereg_mr status %i\n", dprintk("RPC: %s: ib_dereg_mr status %i\n",
__func__, rc); __func__, rc);
kfree(r->r.frmr.sg); kfree(r->frmr.sg);
} }
static int static int
@ -263,14 +263,14 @@ __frwr_sendcompletion_flush(struct ib_wc *wc, struct rpcrdma_mw *r)
pr_warn("RPC: %s: frmr %p error, status %s (%d)\n", pr_warn("RPC: %s: frmr %p error, status %s (%d)\n",
__func__, r, ib_wc_status_msg(wc->status), wc->status); __func__, r, ib_wc_status_msg(wc->status), wc->status);
r->r.frmr.fr_state = FRMR_IS_STALE; r->frmr.fr_state = FRMR_IS_STALE;
} }
static void static void
frwr_sendcompletion(struct ib_wc *wc) frwr_sendcompletion(struct ib_wc *wc)
{ {
struct rpcrdma_mw *r = (struct rpcrdma_mw *)(unsigned long)wc->wr_id; struct rpcrdma_mw *r = (struct rpcrdma_mw *)(unsigned long)wc->wr_id;
struct rpcrdma_frmr *f = &r->r.frmr; struct rpcrdma_frmr *f = &r->frmr;
if (unlikely(wc->status != IB_WC_SUCCESS)) if (unlikely(wc->status != IB_WC_SUCCESS))
__frwr_sendcompletion_flush(wc, r); __frwr_sendcompletion_flush(wc, r);
@ -314,7 +314,7 @@ frwr_op_init(struct rpcrdma_xprt *r_xprt)
list_add(&r->mw_list, &buf->rb_mws); list_add(&r->mw_list, &buf->rb_mws);
list_add(&r->mw_all, &buf->rb_all); list_add(&r->mw_all, &buf->rb_all);
r->mw_sendcompletion = frwr_sendcompletion; r->mw_sendcompletion = frwr_sendcompletion;
r->r.frmr.fr_xprt = r_xprt; r->frmr.fr_xprt = r_xprt;
} }
return 0; return 0;
@ -347,8 +347,8 @@ frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
mw = rpcrdma_get_mw(r_xprt); mw = rpcrdma_get_mw(r_xprt);
if (!mw) if (!mw)
return -ENOMEM; return -ENOMEM;
} while (mw->r.frmr.fr_state != FRMR_IS_INVALID); } while (mw->frmr.fr_state != FRMR_IS_INVALID);
frmr = &mw->r.frmr; frmr = &mw->frmr;
frmr->fr_state = FRMR_IS_VALID; frmr->fr_state = FRMR_IS_VALID;
frmr->fr_waiter = false; frmr->fr_waiter = false;
mr = frmr->fr_mr; mr = frmr->fr_mr;
@ -434,7 +434,7 @@ static struct ib_send_wr *
__frwr_prepare_linv_wr(struct rpcrdma_mr_seg *seg) __frwr_prepare_linv_wr(struct rpcrdma_mr_seg *seg)
{ {
struct rpcrdma_mw *mw = seg->rl_mw; struct rpcrdma_mw *mw = seg->rl_mw;
struct rpcrdma_frmr *f = &mw->r.frmr; struct rpcrdma_frmr *f = &mw->frmr;
struct ib_send_wr *invalidate_wr; struct ib_send_wr *invalidate_wr;
f->fr_waiter = false; f->fr_waiter = false;
@ -455,7 +455,7 @@ __frwr_dma_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
{ {
struct ib_device *device = r_xprt->rx_ia.ri_device; struct ib_device *device = r_xprt->rx_ia.ri_device;
struct rpcrdma_mw *mw = seg->rl_mw; struct rpcrdma_mw *mw = seg->rl_mw;
struct rpcrdma_frmr *f = &mw->r.frmr; struct rpcrdma_frmr *f = &mw->frmr;
seg->rl_mw = NULL; seg->rl_mw = NULL;
@ -504,7 +504,7 @@ frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
i += seg->mr_nsegs; i += seg->mr_nsegs;
} }
f = &seg->rl_mw->r.frmr; f = &seg->rl_mw->frmr;
/* Strong send queue ordering guarantees that when the /* Strong send queue ordering guarantees that when the
* last WR in the chain completes, all WRs in the chain * last WR in the chain completes, all WRs in the chain
@ -553,7 +553,7 @@ frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
struct rpcrdma_mr_seg *seg1 = seg; struct rpcrdma_mr_seg *seg1 = seg;
struct rpcrdma_ia *ia = &r_xprt->rx_ia; struct rpcrdma_ia *ia = &r_xprt->rx_ia;
struct rpcrdma_mw *mw = seg1->rl_mw; struct rpcrdma_mw *mw = seg1->rl_mw;
struct rpcrdma_frmr *frmr = &mw->r.frmr; struct rpcrdma_frmr *frmr = &mw->frmr;
struct ib_send_wr *invalidate_wr, *bad_wr; struct ib_send_wr *invalidate_wr, *bad_wr;
int rc, nsegs = seg->mr_nsegs; int rc, nsegs = seg->mr_nsegs;
@ -561,7 +561,7 @@ frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
seg1->rl_mw = NULL; seg1->rl_mw = NULL;
frmr->fr_state = FRMR_IS_INVALID; frmr->fr_state = FRMR_IS_INVALID;
invalidate_wr = &mw->r.frmr.fr_invwr; invalidate_wr = &mw->frmr.fr_invwr;
memset(invalidate_wr, 0, sizeof(*invalidate_wr)); memset(invalidate_wr, 0, sizeof(*invalidate_wr));
invalidate_wr->wr_id = (uintptr_t)mw; invalidate_wr->wr_id = (uintptr_t)mw;

View File

@ -225,7 +225,7 @@ struct rpcrdma_mw {
union { union {
struct rpcrdma_fmr fmr; struct rpcrdma_fmr fmr;
struct rpcrdma_frmr frmr; struct rpcrdma_frmr frmr;
} r; };
void (*mw_sendcompletion)(struct ib_wc *); void (*mw_sendcompletion)(struct ib_wc *);
struct list_head mw_list; struct list_head mw_list;
struct list_head mw_all; struct list_head mw_all;