aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2015-01-21 11:03:52 -0500
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2015-01-30 10:47:48 -0500
commit1392402c405a75de1cdc658d36c6007ea1c037de (patch)
tree247d3def284df947cc7812c3212aa9a61bb0ed41 /net/sunrpc
parentac920d04a7f307bfd7633f60abe33fb626f6ec83 (diff)
xprtrdma: Refactor rpcrdma_buffer_create() and rpcrdma_buffer_destroy()
Move the details of how to create and destroy rpcrdma_req and rpcrdma_rep structures into helper functions. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Reviewed-by: Steve Wise <swise@opengridcomputing.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/xprtrdma/verbs.c148
1 files changed, 95 insertions, 53 deletions
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
index fd71501403fd..24ea6dd184e4 100644
--- a/net/sunrpc/xprtrdma/verbs.c
+++ b/net/sunrpc/xprtrdma/verbs.c
@@ -1075,6 +1075,69 @@ rpcrdma_ep_disconnect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
1075 } 1075 }
1076} 1076}
1077 1077
1078static struct rpcrdma_req *
1079rpcrdma_create_req(struct rpcrdma_xprt *r_xprt)
1080{
1081 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
1082 size_t wlen = 1 << fls(cdata->inline_wsize +
1083 sizeof(struct rpcrdma_req));
1084 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
1085 struct rpcrdma_req *req;
1086 int rc;
1087
1088 rc = -ENOMEM;
1089 req = kmalloc(wlen, GFP_KERNEL);
1090 if (req == NULL)
1091 goto out;
1092 memset(req, 0, sizeof(struct rpcrdma_req));
1093
1094 rc = rpcrdma_register_internal(ia, req->rl_base, wlen -
1095 offsetof(struct rpcrdma_req, rl_base),
1096 &req->rl_handle, &req->rl_iov);
1097 if (rc)
1098 goto out_free;
1099
1100 req->rl_size = wlen - sizeof(struct rpcrdma_req);
1101 req->rl_buffer = &r_xprt->rx_buf;
1102 return req;
1103
1104out_free:
1105 kfree(req);
1106out:
1107 return ERR_PTR(rc);
1108}
1109
1110static struct rpcrdma_rep *
1111rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt)
1112{
1113 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
1114 size_t rlen = 1 << fls(cdata->inline_rsize +
1115 sizeof(struct rpcrdma_rep));
1116 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
1117 struct rpcrdma_rep *rep;
1118 int rc;
1119
1120 rc = -ENOMEM;
1121 rep = kmalloc(rlen, GFP_KERNEL);
1122 if (rep == NULL)
1123 goto out;
1124 memset(rep, 0, sizeof(struct rpcrdma_rep));
1125
1126 rc = rpcrdma_register_internal(ia, rep->rr_base, rlen -
1127 offsetof(struct rpcrdma_rep, rr_base),
1128 &rep->rr_handle, &rep->rr_iov);
1129 if (rc)
1130 goto out_free;
1131
1132 rep->rr_buffer = &r_xprt->rx_buf;
1133 return rep;
1134
1135out_free:
1136 kfree(rep);
1137out:
1138 return ERR_PTR(rc);
1139}
1140
1078static int 1141static int
1079rpcrdma_init_fmrs(struct rpcrdma_ia *ia, struct rpcrdma_buffer *buf) 1142rpcrdma_init_fmrs(struct rpcrdma_ia *ia, struct rpcrdma_buffer *buf)
1080{ 1143{
@@ -1167,7 +1230,7 @@ rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
1167 struct rpcrdma_ia *ia = &r_xprt->rx_ia; 1230 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
1168 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data; 1231 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
1169 char *p; 1232 char *p;
1170 size_t len, rlen, wlen; 1233 size_t len;
1171 int i, rc; 1234 int i, rc;
1172 1235
1173 buf->rb_max_requests = cdata->max_requests; 1236 buf->rb_max_requests = cdata->max_requests;
@@ -1227,62 +1290,29 @@ rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
1227 break; 1290 break;
1228 } 1291 }
1229 1292
1230 /*
1231 * Allocate/init the request/reply buffers. Doing this
1232 * using kmalloc for now -- one for each buf.
1233 */
1234 wlen = 1 << fls(cdata->inline_wsize + sizeof(struct rpcrdma_req));
1235 rlen = 1 << fls(cdata->inline_rsize + sizeof(struct rpcrdma_rep));
1236 dprintk("RPC: %s: wlen = %zu, rlen = %zu\n",
1237 __func__, wlen, rlen);
1238
1239 for (i = 0; i < buf->rb_max_requests; i++) { 1293 for (i = 0; i < buf->rb_max_requests; i++) {
1240 struct rpcrdma_req *req; 1294 struct rpcrdma_req *req;
1241 struct rpcrdma_rep *rep; 1295 struct rpcrdma_rep *rep;
1242 1296
1243 req = kmalloc(wlen, GFP_KERNEL); 1297 req = rpcrdma_create_req(r_xprt);
1244 if (req == NULL) { 1298 if (IS_ERR(req)) {
1245 dprintk("RPC: %s: request buffer %d alloc" 1299 dprintk("RPC: %s: request buffer %d alloc"
1246 " failed\n", __func__, i); 1300 " failed\n", __func__, i);
1247 rc = -ENOMEM; 1301 rc = PTR_ERR(req);
1248 goto out; 1302 goto out;
1249 } 1303 }
1250 memset(req, 0, sizeof(struct rpcrdma_req));
1251 buf->rb_send_bufs[i] = req; 1304 buf->rb_send_bufs[i] = req;
1252 buf->rb_send_bufs[i]->rl_buffer = buf;
1253
1254 rc = rpcrdma_register_internal(ia, req->rl_base,
1255 wlen - offsetof(struct rpcrdma_req, rl_base),
1256 &buf->rb_send_bufs[i]->rl_handle,
1257 &buf->rb_send_bufs[i]->rl_iov);
1258 if (rc)
1259 goto out;
1260 1305
1261 buf->rb_send_bufs[i]->rl_size = wlen - 1306 rep = rpcrdma_create_rep(r_xprt);
1262 sizeof(struct rpcrdma_req); 1307 if (IS_ERR(rep)) {
1263
1264 rep = kmalloc(rlen, GFP_KERNEL);
1265 if (rep == NULL) {
1266 dprintk("RPC: %s: reply buffer %d alloc failed\n", 1308 dprintk("RPC: %s: reply buffer %d alloc failed\n",
1267 __func__, i); 1309 __func__, i);
1268 rc = -ENOMEM; 1310 rc = PTR_ERR(rep);
1269 goto out; 1311 goto out;
1270 } 1312 }
1271 memset(rep, 0, sizeof(struct rpcrdma_rep));
1272 buf->rb_recv_bufs[i] = rep; 1313 buf->rb_recv_bufs[i] = rep;
1273 buf->rb_recv_bufs[i]->rr_buffer = buf;
1274
1275 rc = rpcrdma_register_internal(ia, rep->rr_base,
1276 rlen - offsetof(struct rpcrdma_rep, rr_base),
1277 &buf->rb_recv_bufs[i]->rr_handle,
1278 &buf->rb_recv_bufs[i]->rr_iov);
1279 if (rc)
1280 goto out;
1281
1282 } 1314 }
1283 dprintk("RPC: %s: max_requests %d\n", 1315
1284 __func__, buf->rb_max_requests);
1285 /* done */
1286 return 0; 1316 return 0;
1287out: 1317out:
1288 rpcrdma_buffer_destroy(buf); 1318 rpcrdma_buffer_destroy(buf);
@@ -1290,6 +1320,26 @@ out:
1290} 1320}
1291 1321
1292static void 1322static void
1323rpcrdma_destroy_rep(struct rpcrdma_ia *ia, struct rpcrdma_rep *rep)
1324{
1325 if (!rep)
1326 return;
1327
1328 rpcrdma_deregister_internal(ia, rep->rr_handle, &rep->rr_iov);
1329 kfree(rep);
1330}
1331
1332static void
1333rpcrdma_destroy_req(struct rpcrdma_ia *ia, struct rpcrdma_req *req)
1334{
1335 if (!req)
1336 return;
1337
1338 rpcrdma_deregister_internal(ia, req->rl_handle, &req->rl_iov);
1339 kfree(req);
1340}
1341
1342static void
1293rpcrdma_destroy_fmrs(struct rpcrdma_buffer *buf) 1343rpcrdma_destroy_fmrs(struct rpcrdma_buffer *buf)
1294{ 1344{
1295 struct rpcrdma_mw *r; 1345 struct rpcrdma_mw *r;
@@ -1344,18 +1394,10 @@ rpcrdma_buffer_destroy(struct rpcrdma_buffer *buf)
1344 dprintk("RPC: %s: entering\n", __func__); 1394 dprintk("RPC: %s: entering\n", __func__);
1345 1395
1346 for (i = 0; i < buf->rb_max_requests; i++) { 1396 for (i = 0; i < buf->rb_max_requests; i++) {
1347 if (buf->rb_recv_bufs && buf->rb_recv_bufs[i]) { 1397 if (buf->rb_recv_bufs)
1348 rpcrdma_deregister_internal(ia, 1398 rpcrdma_destroy_rep(ia, buf->rb_recv_bufs[i]);
1349 buf->rb_recv_bufs[i]->rr_handle, 1399 if (buf->rb_send_bufs)
1350 &buf->rb_recv_bufs[i]->rr_iov); 1400 rpcrdma_destroy_req(ia, buf->rb_send_bufs[i]);
1351 kfree(buf->rb_recv_bufs[i]);
1352 }
1353 if (buf->rb_send_bufs && buf->rb_send_bufs[i]) {
1354 rpcrdma_deregister_internal(ia,
1355 buf->rb_send_bufs[i]->rl_handle,
1356 &buf->rb_send_bufs[i]->rl_iov);
1357 kfree(buf->rb_send_bufs[i]);
1358 }
1359 } 1401 }
1360 1402
1361 switch (ia->ri_memreg_strategy) { 1403 switch (ia->ri_memreg_strategy) {