aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2010-09-29 08:02:43 -0400
committerJ. Bruce Fields <bfields@redhat.com>2010-10-01 17:18:52 -0400
commitbd1722d4316e42a12fe6337ebe34d7e1e2c088b2 (patch)
tree358d45aaf5fb08a177fd6fbe5dcf8872160c30fc /net
parent2b44f1ba40914777f4b1075254ba97663d4e2574 (diff)
sunrpc: Factor out rpc_xprt allocation
Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/xprt.c22
-rw-r--r--net/sunrpc/xprtrdma/transport.c13
-rw-r--r--net/sunrpc/xprtsock.c15
3 files changed, 27 insertions, 23 deletions
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 970fb00f388c..26cbe219388b 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -962,6 +962,28 @@ static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
962 spin_unlock(&xprt->reserve_lock); 962 spin_unlock(&xprt->reserve_lock);
963} 963}
964 964
965struct rpc_xprt *xprt_alloc(int size, int max_req)
966{
967 struct rpc_xprt *xprt;
968
969 xprt = kzalloc(size, GFP_KERNEL);
970 if (xprt == NULL)
971 goto out;
972
973 xprt->max_reqs = max_req;
974 xprt->slot = kcalloc(max_req, sizeof(struct rpc_rqst), GFP_KERNEL);
975 if (xprt->slot == NULL)
976 goto out_free;
977
978 return xprt;
979
980out_free:
981 kfree(xprt);
982out:
983 return NULL;
984}
985EXPORT_SYMBOL_GPL(xprt_alloc);
986
965/** 987/**
966 * xprt_reserve - allocate an RPC request slot 988 * xprt_reserve - allocate an RPC request slot
967 * @task: RPC task requesting a slot allocation 989 * @task: RPC task requesting a slot allocation
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index a85e866a77f7..9d77bf25829f 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -285,23 +285,14 @@ xprt_setup_rdma(struct xprt_create *args)
285 return ERR_PTR(-EBADF); 285 return ERR_PTR(-EBADF);
286 } 286 }
287 287
288 xprt = kzalloc(sizeof(struct rpcrdma_xprt), GFP_KERNEL); 288 xprt = xprt_alloc(sizeof(struct rpcrdma_xprt),
289 xprt_rdma_slot_table_entries);
289 if (xprt == NULL) { 290 if (xprt == NULL) {
290 dprintk("RPC: %s: couldn't allocate rpcrdma_xprt\n", 291 dprintk("RPC: %s: couldn't allocate rpcrdma_xprt\n",
291 __func__); 292 __func__);
292 return ERR_PTR(-ENOMEM); 293 return ERR_PTR(-ENOMEM);
293 } 294 }
294 295
295 xprt->max_reqs = xprt_rdma_slot_table_entries;
296 xprt->slot = kcalloc(xprt->max_reqs,
297 sizeof(struct rpc_rqst), GFP_KERNEL);
298 if (xprt->slot == NULL) {
299 dprintk("RPC: %s: couldn't allocate %d slots\n",
300 __func__, xprt->max_reqs);
301 kfree(xprt);
302 return ERR_PTR(-ENOMEM);
303 }
304
305 /* 60 second timeout, no retries */ 296 /* 60 second timeout, no retries */
306 xprt->timeout = &xprt_rdma_default_timeout; 297 xprt->timeout = &xprt_rdma_default_timeout;
307 xprt->bind_timeout = (60U * HZ); 298 xprt->bind_timeout = (60U * HZ);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index b6309db56226..a7a763821b88 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2273,23 +2273,14 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
2273 return ERR_PTR(-EBADF); 2273 return ERR_PTR(-EBADF);
2274 } 2274 }
2275 2275
2276 new = kzalloc(sizeof(*new), GFP_KERNEL); 2276 xprt = xprt_alloc(sizeof(*new), slot_table_size);
2277 if (new == NULL) { 2277 if (xprt == NULL) {
2278 dprintk("RPC: xs_setup_xprt: couldn't allocate " 2278 dprintk("RPC: xs_setup_xprt: couldn't allocate "
2279 "rpc_xprt\n"); 2279 "rpc_xprt\n");
2280 return ERR_PTR(-ENOMEM); 2280 return ERR_PTR(-ENOMEM);
2281 } 2281 }
2282 xprt = &new->xprt;
2283
2284 xprt->max_reqs = slot_table_size;
2285 xprt->slot = kcalloc(xprt->max_reqs, sizeof(struct rpc_rqst), GFP_KERNEL);
2286 if (xprt->slot == NULL) {
2287 kfree(xprt);
2288 dprintk("RPC: xs_setup_xprt: couldn't allocate slot "
2289 "table\n");
2290 return ERR_PTR(-ENOMEM);
2291 }
2292 2282
2283 new = container_of(xprt, struct sock_xprt, xprt);
2293 memcpy(&xprt->addr, args->dstaddr, args->addrlen); 2284 memcpy(&xprt->addr, args->dstaddr, args->addrlen);
2294 xprt->addrlen = args->addrlen; 2285 xprt->addrlen = args->addrlen;
2295 if (args->srcaddr) 2286 if (args->srcaddr)