Skip to content

Commit 31a701a

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Add "reset MRs" memreg op
This method is invoked when a transport instance is about to be reconnected. Each Memory Region object is reset to its initial state. Signed-off-by: Chuck Lever <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Tested-by: Devesh Sharma <[email protected]> Tested-by: Meghana Cheripady <[email protected]> Tested-by: Veeresh U. Kokatnur <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 91e70e7 commit 31a701a

File tree

5 files changed

+83
-101
lines changed

5 files changed

+83
-101
lines changed

net/sunrpc/xprtrdma/fmr_ops.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,33 @@ fmr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
146146
return nsegs;
147147
}
148148

149+
/* After a disconnect, unmap all FMRs.
150+
*
151+
* This is invoked only in the transport connect worker in order
152+
* to serialize with rpcrdma_register_fmr_external().
153+
*/
154+
static void
155+
fmr_op_reset(struct rpcrdma_xprt *r_xprt)
156+
{
157+
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
158+
struct rpcrdma_mw *r;
159+
LIST_HEAD(list);
160+
int rc;
161+
162+
list_for_each_entry(r, &buf->rb_all, mw_all)
163+
list_add(&r->r.fmr->list, &list);
164+
165+
rc = ib_unmap_fmr(&list);
166+
if (rc)
167+
dprintk("RPC: %s: ib_unmap_fmr failed %i\n",
168+
__func__, rc);
169+
}
170+
149171
const struct rpcrdma_memreg_ops rpcrdma_fmr_memreg_ops = {
150172
.ro_map = fmr_op_map,
151173
.ro_unmap = fmr_op_unmap,
152174
.ro_maxpages = fmr_op_maxpages,
153175
.ro_init = fmr_op_init,
176+
.ro_reset = fmr_op_reset,
154177
.ro_displayname = "fmr",
155178
};

net/sunrpc/xprtrdma/frwr_ops.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device,
4646
return rc;
4747
}
4848

49+
static void
50+
__frwr_release(struct rpcrdma_mw *r)
51+
{
52+
int rc;
53+
54+
rc = ib_dereg_mr(r->r.frmr.fr_mr);
55+
if (rc)
56+
dprintk("RPC: %s: ib_dereg_mr status %i\n",
57+
__func__, rc);
58+
ib_free_fast_reg_page_list(r->r.frmr.fr_pgl);
59+
}
60+
4961
/* FRWR mode conveys a list of pages per chunk segment. The
5062
* maximum length of that list is the FRWR page list depth.
5163
*/
@@ -210,10 +222,49 @@ frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
210222
return nsegs;
211223
}
212224

225+
/* After a disconnect, a flushed FAST_REG_MR can leave an FRMR in
226+
* an unusable state. Find FRMRs in this state and dereg / reg
227+
* each. FRMRs that are VALID and attached to an rpcrdma_req are
228+
* also torn down.
229+
*
230+
* This gives all in-use FRMRs a fresh rkey and leaves them INVALID.
231+
*
232+
* This is invoked only in the transport connect worker in order
233+
* to serialize with rpcrdma_register_frmr_external().
234+
*/
235+
static void
236+
frwr_op_reset(struct rpcrdma_xprt *r_xprt)
237+
{
238+
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
239+
struct ib_device *device = r_xprt->rx_ia.ri_id->device;
240+
unsigned int depth = r_xprt->rx_ia.ri_max_frmr_depth;
241+
struct ib_pd *pd = r_xprt->rx_ia.ri_pd;
242+
struct rpcrdma_mw *r;
243+
int rc;
244+
245+
list_for_each_entry(r, &buf->rb_all, mw_all) {
246+
if (r->r.frmr.fr_state == FRMR_IS_INVALID)
247+
continue;
248+
249+
__frwr_release(r);
250+
rc = __frwr_init(r, pd, device, depth);
251+
if (rc) {
252+
dprintk("RPC: %s: mw %p left %s\n",
253+
__func__, r,
254+
(r->r.frmr.fr_state == FRMR_IS_STALE ?
255+
"stale" : "valid"));
256+
continue;
257+
}
258+
259+
r->r.frmr.fr_state = FRMR_IS_INVALID;
260+
}
261+
}
262+
213263
const struct rpcrdma_memreg_ops rpcrdma_frwr_memreg_ops = {
214264
.ro_map = frwr_op_map,
215265
.ro_unmap = frwr_op_unmap,
216266
.ro_maxpages = frwr_op_maxpages,
217267
.ro_init = frwr_op_init,
268+
.ro_reset = frwr_op_reset,
218269
.ro_displayname = "frwr",
219270
};

net/sunrpc/xprtrdma/physical_ops.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ physical_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
5959
return 1;
6060
}
6161

62+
static void
63+
physical_op_reset(struct rpcrdma_xprt *r_xprt)
64+
{
65+
}
66+
6267
const struct rpcrdma_memreg_ops rpcrdma_physical_memreg_ops = {
6368
.ro_map = physical_op_map,
6469
.ro_unmap = physical_op_unmap,
6570
.ro_maxpages = physical_op_maxpages,
6671
.ro_init = physical_op_init,
72+
.ro_reset = physical_op_reset,
6773
.ro_displayname = "physical",
6874
};

net/sunrpc/xprtrdma/verbs.c

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
# define RPCDBG_FACILITY RPCDBG_TRANS
6464
#endif
6565

66-
static void rpcrdma_reset_frmrs(struct rpcrdma_ia *);
67-
static void rpcrdma_reset_fmrs(struct rpcrdma_ia *);
68-
6966
/*
7067
* internal functions
7168
*/
@@ -945,21 +942,9 @@ rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
945942
rpcrdma_ep_disconnect(ep, ia);
946943
rpcrdma_flush_cqs(ep);
947944

948-
switch (ia->ri_memreg_strategy) {
949-
case RPCRDMA_FRMR:
950-
rpcrdma_reset_frmrs(ia);
951-
break;
952-
case RPCRDMA_MTHCAFMR:
953-
rpcrdma_reset_fmrs(ia);
954-
break;
955-
case RPCRDMA_ALLPHYSICAL:
956-
break;
957-
default:
958-
rc = -EIO;
959-
goto out;
960-
}
961-
962945
xprt = container_of(ia, struct rpcrdma_xprt, rx_ia);
946+
ia->ri_ops->ro_reset(xprt);
947+
963948
id = rpcrdma_create_id(xprt, ia,
964949
(struct sockaddr *)&xprt->rx_data.addr);
965950
if (IS_ERR(id)) {
@@ -1289,90 +1274,6 @@ rpcrdma_buffer_destroy(struct rpcrdma_buffer *buf)
12891274
kfree(buf->rb_pool);
12901275
}
12911276

1292-
/* After a disconnect, unmap all FMRs.
1293-
*
1294-
* This is invoked only in the transport connect worker in order
1295-
* to serialize with rpcrdma_register_fmr_external().
1296-
*/
1297-
static void
1298-
rpcrdma_reset_fmrs(struct rpcrdma_ia *ia)
1299-
{
1300-
struct rpcrdma_xprt *r_xprt =
1301-
container_of(ia, struct rpcrdma_xprt, rx_ia);
1302-
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1303-
struct list_head *pos;
1304-
struct rpcrdma_mw *r;
1305-
LIST_HEAD(l);
1306-
int rc;
1307-
1308-
list_for_each(pos, &buf->rb_all) {
1309-
r = list_entry(pos, struct rpcrdma_mw, mw_all);
1310-
1311-
INIT_LIST_HEAD(&l);
1312-
list_add(&r->r.fmr->list, &l);
1313-
rc = ib_unmap_fmr(&l);
1314-
if (rc)
1315-
dprintk("RPC: %s: ib_unmap_fmr failed %i\n",
1316-
__func__, rc);
1317-
}
1318-
}
1319-
1320-
/* After a disconnect, a flushed FAST_REG_MR can leave an FRMR in
1321-
* an unusable state. Find FRMRs in this state and dereg / reg
1322-
* each. FRMRs that are VALID and attached to an rpcrdma_req are
1323-
* also torn down.
1324-
*
1325-
* This gives all in-use FRMRs a fresh rkey and leaves them INVALID.
1326-
*
1327-
* This is invoked only in the transport connect worker in order
1328-
* to serialize with rpcrdma_register_frmr_external().
1329-
*/
1330-
static void
1331-
rpcrdma_reset_frmrs(struct rpcrdma_ia *ia)
1332-
{
1333-
struct rpcrdma_xprt *r_xprt =
1334-
container_of(ia, struct rpcrdma_xprt, rx_ia);
1335-
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1336-
struct list_head *pos;
1337-
struct rpcrdma_mw *r;
1338-
int rc;
1339-
1340-
list_for_each(pos, &buf->rb_all) {
1341-
r = list_entry(pos, struct rpcrdma_mw, mw_all);
1342-
1343-
if (r->r.frmr.fr_state == FRMR_IS_INVALID)
1344-
continue;
1345-
1346-
rc = ib_dereg_mr(r->r.frmr.fr_mr);
1347-
if (rc)
1348-
dprintk("RPC: %s: ib_dereg_mr failed %i\n",
1349-
__func__, rc);
1350-
ib_free_fast_reg_page_list(r->r.frmr.fr_pgl);
1351-
1352-
r->r.frmr.fr_mr = ib_alloc_fast_reg_mr(ia->ri_pd,
1353-
ia->ri_max_frmr_depth);
1354-
if (IS_ERR(r->r.frmr.fr_mr)) {
1355-
rc = PTR_ERR(r->r.frmr.fr_mr);
1356-
dprintk("RPC: %s: ib_alloc_fast_reg_mr"
1357-
" failed %i\n", __func__, rc);
1358-
continue;
1359-
}
1360-
r->r.frmr.fr_pgl = ib_alloc_fast_reg_page_list(
1361-
ia->ri_id->device,
1362-
ia->ri_max_frmr_depth);
1363-
if (IS_ERR(r->r.frmr.fr_pgl)) {
1364-
rc = PTR_ERR(r->r.frmr.fr_pgl);
1365-
dprintk("RPC: %s: "
1366-
"ib_alloc_fast_reg_page_list "
1367-
"failed %i\n", __func__, rc);
1368-
1369-
ib_dereg_mr(r->r.frmr.fr_mr);
1370-
continue;
1371-
}
1372-
r->r.frmr.fr_state = FRMR_IS_INVALID;
1373-
}
1374-
}
1375-
13761277
/* "*mw" can be NULL when rpcrdma_buffer_get_mrs() fails, leaving
13771278
* some req segments uninitialized.
13781279
*/

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ struct rpcrdma_memreg_ops {
342342
struct rpcrdma_mr_seg *);
343343
size_t (*ro_maxpages)(struct rpcrdma_xprt *);
344344
int (*ro_init)(struct rpcrdma_xprt *);
345+
void (*ro_reset)(struct rpcrdma_xprt *);
345346
const char *ro_displayname;
346347
};
347348

0 commit comments

Comments
 (0)