Commit 1890896b authored by Chuck Lever's avatar Chuck Lever Committed by Anna Schumaker

xprtrdma: Refactor rpcrdma_ep_connect

I'm about to add another arm to

    if (ep->rep_connected != 0)

It will be cleaner to use a switch statement here. We'll be looking
for a couple of specific errnos, or "anything else," basically to
sort out the difference between a normal reconnect and recovery from
device removal.

This is a refactoring change only.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent bebd0318
...@@ -711,69 +711,84 @@ rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia) ...@@ -711,69 +711,84 @@ rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
ib_free_cq(ep->rep_attr.send_cq); ib_free_cq(ep->rep_attr.send_cq);
} }
/* static int
* Connect unconnected endpoint. rpcrdma_ep_reconnect(struct rpcrdma_xprt *r_xprt, struct rpcrdma_ep *ep,
*/ struct rpcrdma_ia *ia)
int
rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
{ {
struct rpcrdma_xprt *r_xprt = container_of(ia, struct rpcrdma_xprt, struct sockaddr *sap = (struct sockaddr *)&r_xprt->rx_data.addr;
rx_ia);
struct rdma_cm_id *id, *old; struct rdma_cm_id *id, *old;
struct sockaddr *sap; int err, rc;
unsigned int extras;
int rc = 0;
if (ep->rep_connected != 0) {
retry:
dprintk("RPC: %s: reconnecting...\n", __func__); dprintk("RPC: %s: reconnecting...\n", __func__);
rpcrdma_ep_disconnect(ep, ia); rpcrdma_ep_disconnect(ep, ia);
sap = (struct sockaddr *)&r_xprt->rx_data.addr;
id = rpcrdma_create_id(r_xprt, ia, sap);
if (IS_ERR(id)) {
rc = -EHOSTUNREACH; rc = -EHOSTUNREACH;
id = rpcrdma_create_id(r_xprt, ia, sap);
if (IS_ERR(id))
goto out; goto out;
}
/* TEMP TEMP TEMP - fail if new device: /* As long as the new ID points to the same device as the
* Deregister/remarshal *all* requests! * old ID, we can reuse the transport's existing PD and all
* Close and recreate adapter, pd, etc! * previously allocated MRs. Also, the same device means
* Re-determine all attributes still sane! * the transport's previous DMA mappings are still valid.
* More stuff I haven't thought of! *
* Rrrgh! * This is a sanity check only. There should be no way these
* point to two different devices here.
*/ */
if (ia->ri_device != id->device) { old = id;
printk("RPC: %s: can't reconnect on "
"different device!\n", __func__);
rpcrdma_destroy_id(id);
rc = -ENETUNREACH; rc = -ENETUNREACH;
goto out; if (ia->ri_device != id->device) {
pr_err("rpcrdma: can't reconnect on different device!\n");
goto out_destroy;
} }
/* END TEMP */
rc = rdma_create_qp(id, ia->ri_pd, &ep->rep_attr); err = rdma_create_qp(id, ia->ri_pd, &ep->rep_attr);
if (rc) { if (err) {
dprintk("RPC: %s: rdma_create_qp failed %i\n", dprintk("RPC: %s: rdma_create_qp returned %d\n",
__func__, rc); __func__, err);
rpcrdma_destroy_id(id); goto out_destroy;
rc = -ENETUNREACH;
goto out;
} }
/* Atomically replace the transport's ID and QP. */
rc = 0;
old = ia->ri_id; old = ia->ri_id;
ia->ri_id = id; ia->ri_id = id;
rdma_destroy_qp(old); rdma_destroy_qp(old);
out_destroy:
rpcrdma_destroy_id(old); rpcrdma_destroy_id(old);
} else { out:
return rc;
}
/*
* Connect unconnected endpoint.
*/
int
rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
{
struct rpcrdma_xprt *r_xprt = container_of(ia, struct rpcrdma_xprt,
rx_ia);
unsigned int extras;
int rc;
retry:
switch (ep->rep_connected) {
case 0:
dprintk("RPC: %s: connecting...\n", __func__); dprintk("RPC: %s: connecting...\n", __func__);
rc = rdma_create_qp(ia->ri_id, ia->ri_pd, &ep->rep_attr); rc = rdma_create_qp(ia->ri_id, ia->ri_pd, &ep->rep_attr);
if (rc) { if (rc) {
dprintk("RPC: %s: rdma_create_qp failed %i\n", dprintk("RPC: %s: rdma_create_qp failed %i\n",
__func__, rc); __func__, rc);
/* do not update ep->rep_connected */ rc = -ENETUNREACH;
return -ENETUNREACH; goto out_noupdate;
} }
break;
default:
rc = rpcrdma_ep_reconnect(r_xprt, ep, ia);
if (rc)
goto out;
} }
ep->rep_connected = 0; ep->rep_connected = 0;
...@@ -801,6 +816,8 @@ rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia) ...@@ -801,6 +816,8 @@ rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
out: out:
if (rc) if (rc)
ep->rep_connected = rc; ep->rep_connected = rc;
out_noupdate:
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment