sunrpc: Factor out rpc_xprt allocation
authorPavel Emelyanov <xemul@parallels.com>
Wed, 29 Sep 2010 12:02:43 +0000 (16:02 +0400)
committerJ. Bruce Fields <bfields@redhat.com>
Fri, 1 Oct 2010 21:18:52 +0000 (17:18 -0400)
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
include/linux/sunrpc/xprt.h
net/sunrpc/xprt.c
net/sunrpc/xprtrdma/transport.c
net/sunrpc/xprtsock.c

index ff5a77b28c50c61044e150591d2148c76414cdf3..00f6e3fe29004aaeb862d18bd25751c59a517feb 100644 (file)
@@ -280,6 +280,7 @@ void                        xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task);
 void                   xprt_release(struct rpc_task *task);
 struct rpc_xprt *      xprt_get(struct rpc_xprt *xprt);
 void                   xprt_put(struct rpc_xprt *xprt);
+struct rpc_xprt *      xprt_alloc(int size, int max_req);
 
 static inline __be32 *xprt_skip_transport_header(struct rpc_xprt *xprt, __be32 *p)
 {
index 970fb00f388ce532d7f0a4e3c7285f98e57af2f5..26cbe219388bd22df303b8fed523c91ced2ed267 100644 (file)
@@ -962,6 +962,28 @@ static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
        spin_unlock(&xprt->reserve_lock);
 }
 
+struct rpc_xprt *xprt_alloc(int size, int max_req)
+{
+       struct rpc_xprt *xprt;
+
+       xprt = kzalloc(size, GFP_KERNEL);
+       if (xprt == NULL)
+               goto out;
+
+       xprt->max_reqs = max_req;
+       xprt->slot = kcalloc(max_req, sizeof(struct rpc_rqst), GFP_KERNEL);
+       if (xprt->slot == NULL)
+               goto out_free;
+
+       return xprt;
+
+out_free:
+       kfree(xprt);
+out:
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(xprt_alloc);
+
 /**
  * xprt_reserve - allocate an RPC request slot
  * @task: RPC task requesting a slot allocation
index a85e866a77f73d2abde623b3d89a264331f63999..9d77bf25829f6619e37ec12a82c3c2895798e222 100644 (file)
@@ -285,23 +285,14 @@ xprt_setup_rdma(struct xprt_create *args)
                return ERR_PTR(-EBADF);
        }
 
-       xprt = kzalloc(sizeof(struct rpcrdma_xprt), GFP_KERNEL);
+       xprt = xprt_alloc(sizeof(struct rpcrdma_xprt),
+                       xprt_rdma_slot_table_entries);
        if (xprt == NULL) {
                dprintk("RPC:       %s: couldn't allocate rpcrdma_xprt\n",
                        __func__);
                return ERR_PTR(-ENOMEM);
        }
 
-       xprt->max_reqs = xprt_rdma_slot_table_entries;
-       xprt->slot = kcalloc(xprt->max_reqs,
-                               sizeof(struct rpc_rqst), GFP_KERNEL);
-       if (xprt->slot == NULL) {
-               dprintk("RPC:       %s: couldn't allocate %d slots\n",
-                       __func__, xprt->max_reqs);
-               kfree(xprt);
-               return ERR_PTR(-ENOMEM);
-       }
-
        /* 60 second timeout, no retries */
        xprt->timeout = &xprt_rdma_default_timeout;
        xprt->bind_timeout = (60U * HZ);
index b6309db5622689deaf1c76a6acb1f6a09a02602c..a7a763821b8815f17066a5c26dc6a248ca30d350 100644 (file)
@@ -2273,23 +2273,14 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
                return ERR_PTR(-EBADF);
        }
 
-       new = kzalloc(sizeof(*new), GFP_KERNEL);
-       if (new == NULL) {
+       xprt = xprt_alloc(sizeof(*new), slot_table_size);
+       if (xprt == NULL) {
                dprintk("RPC:       xs_setup_xprt: couldn't allocate "
                                "rpc_xprt\n");
                return ERR_PTR(-ENOMEM);
        }
-       xprt = &new->xprt;
-
-       xprt->max_reqs = slot_table_size;
-       xprt->slot = kcalloc(xprt->max_reqs, sizeof(struct rpc_rqst), GFP_KERNEL);
-       if (xprt->slot == NULL) {
-               kfree(xprt);
-               dprintk("RPC:       xs_setup_xprt: couldn't allocate slot "
-                               "table\n");
-               return ERR_PTR(-ENOMEM);
-       }
 
+       new = container_of(xprt, struct sock_xprt, xprt);
        memcpy(&xprt->addr, args->dstaddr, args->addrlen);
        xprt->addrlen = args->addrlen;
        if (args->srcaddr)