[pnfs] [PATCH 06/11] New backchannel_rqst.c file.

ricardo.labiaga at netapp.com ricardo.labiaga at netapp.com
Tue Nov 27 23:25:16 EST 2007


This file contains the code to setup the callback xprt on the client side.
it allocates/ destroys the mempools.  It also has routines to allocate and
free back channel requests.
Original code by Rahul Iyer <iyer at netapp.com>

Signed-off-by: Ricardo Labiaga <ricardo.labiaga at netapp.com>
---
 net/sunrpc/backchannel_rqst.c |  158 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 158 insertions(+), 0 deletions(-)
 create mode 100644 net/sunrpc/backchannel_rqst.c

diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c
new file mode 100644
index 0000000..214e36b
--- /dev/null
+++ b/net/sunrpc/backchannel_rqst.c
@@ -0,0 +1,158 @@
+/*
+ * This file is distributed under GPL. Please see Documentation/COPYING for
+ * details.
+ *
+ * Author: Rahul Iyer <iyer at netapp.com>
+ */
+
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/capability.h>
+#include <linux/sched.h>
+#include <linux/pagemap.h>
+#include <linux/errno.h>
+#include <linux/socket.h>
+#include <linux/in.h>
+#include <linux/net.h>
+#include <linux/mm.h>
+#include <linux/tcp.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/sched.h>
+#include <linux/sunrpc/xprt.h>
+#include <linux/file.h>
+//#include <linux/sunrpc/xprt_params.h>
+#include <linux/sunrpc/svcsock.h>
+#include <linux/mempool.h>
+
+#include <net/sock.h>
+#include <net/checksum.h>
+#include <net/tcp.h>
+
+#ifdef RPC_DEBUG
+# undef  RPC_DEBUG_DATA
+# define RPCDBG_FACILITY	RPCDBG_TRANS
+#endif
+
+#if defined (CONFIG_NFS_V4_1)
+
+#define MAX_BC_SLABNAME_SIZE		128
+int xprt_setup_backchannel(struct rpc_xprt *xprt, unsigned int min_reqs)
+{
+	char slab_name[MAX_BC_SLABNAME_SIZE];
+
+	snprintf(slab_name, MAX_BC_SLABNAME_SIZE,
+					"bc_request_cache(xprt:%p)\n", xprt);
+
+	xprt->bc_slab = kmem_cache_create(slab_name,
+					sizeof(struct rpc_rqst), 0, 0, NULL);
+	if (!xprt->bc_slab) {
+		printk(KERN_ERR "Failed to create slab for backchannel!\n");
+		goto out;
+	}
+
+	xprt->bc_mempool = mempool_create(min_reqs, mempool_alloc_slab,
+					mempool_free_slab,
+					xprt->bc_slab);
+	if (!xprt->bc_mempool) {
+		printk(KERN_ERR "Failed to create mempool for callbacks!\n");
+		goto out_free;
+	}
+
+	return 0;
+
+out_free:
+	kmem_cache_destroy(xprt->bc_slab);
+out:
+	return -1;
+}
+
+EXPORT_SYMBOL(xprt_setup_backchannel);
+
+void xprt_destroy_backchannel(struct rpc_xprt *xprt)
+{
+	/*
+	 * Either of these could be NULL in the case of
+	 * the user hitting ^C
+	 */
+	if (xprt->bc_mempool)
+		mempool_destroy(xprt->bc_mempool);
+
+	if (xprt->bc_slab)
+		kmem_cache_destroy(xprt->bc_slab);
+}
+
+EXPORT_SYMBOL(xprt_destroy_backchannel);
+
+struct rpc_rqst *xprt_alloc_bc_request(struct rpc_xprt *xprt)
+{
+/*
+	struct rpc_rqst *req;
+	struct page *page;
+	struct xdr_buf *xbufp;
+	struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
+
+
+	BUG_ON(xprt->bc_mempool == NULL);
+
+	req = mempool_alloc(xprt->bc_mempool, GFP_ATOMIC);
+
+	if (!req)
+		goto out;
+
+	req->rq_xprt = xprt;
+	req->rq_xid = transport->tcp_xid;
+
+	page = alloc_page(GFP_ATOMIC);
+
+	if (!page)
+		goto out_free;
+
+	xbufp = &req->rq_private_buf;
+
+	xbufp->head[0].iov_base = page_address(page);
+	xbufp->head[0].iov_len = PAGE_SIZE;
+	xbufp->tail[0].iov_len = 0;
+	xbufp->page_len = 0;
+	xbufp->len = PAGE_SIZE;
+	xbufp->buflen = PAGE_SIZE;
+
+	page = alloc_page(GFP_ATOMIC);
+
+	if (!page)
+		goto out_free_page;
+
+	xbufp = &req->rq_snd_buf;
+
+	xbufp->head[0].iov_base = page_address(page);
+	xbufp->head[0].iov_len = 0;
+	xbufp->tail[0].iov_len = 0;
+	xbufp->page_len = 0;
+	xbufp->len = 0;
+	xbufp->buflen = PAGE_SIZE;
+	return req;
+
+out_free_page:
+	free_page((unsigned long)xbufp->head[0].iov_base);
+out_free:
+	mempool_free(req, xprt->bc_mempool);
+out:
+*/
+	return NULL;
+}
+
+void xprt_free_bc_request(struct rpc_rqst *req)
+{
+	struct xdr_buf *xbufp;
+	struct rpc_xprt *xprt = req->rq_xprt;
+
+	xbufp = &req->rq_private_buf;
+	free_page((unsigned long)xbufp->head[0].iov_base);
+	
+	xbufp = &req->rq_snd_buf;
+	free_page((unsigned long)xbufp->head[0].iov_base);
+
+	mempool_free(req, xprt->bc_mempool);
+}
+
+#endif
+
-- 
1.5.2


More information about the pNFS mailing list