]> Pileus Git - ~andy/linux/commitdiff
[net/9p] Preparation and helper functions for zero copy
authorVenkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Fri, 28 Jan 2011 22:11:13 +0000 (14:11 -0800)
committerEric Van Hensbergen <ericvh@gmail.com>
Tue, 15 Mar 2011 14:57:34 +0000 (09:57 -0500)
This patch prepares p9_fcall structure for zero copy. Added
fields send the payload buffer information to the transport layer.
In addition it adds a 'private' field for the transport layer to
store mapped/pinned page information so that it can be freed/unpinned
during req_done.

This patch also creates trans_common.[ch] to house helper functions.
It adds the following helper functions.

p9_release_req_pages - Release pages after the transaction.
p9_nr_pages - Return number of pages needed to accomodate the payload.
payload_gup - Translates user buffer into kernel pages.

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
include/net/9p/9p.h
net/9p/Makefile
net/9p/protocol.c
net/9p/trans_common.c [new file with mode: 0644]
net/9p/trans_common.h [new file with mode: 0644]

index 071fd7a8d781ebe934c103c4010e4fb9b8dace44..7aefa6d975ac9fcd9fa534993f212592d9e1b9f4 100644 (file)
@@ -689,6 +689,10 @@ struct p9_rwstat {
  * @tag: transaction id of the request
  * @offset: used by marshalling routines to track currentposition in buffer
  * @capacity: used by marshalling routines to track total capacity
+ * @pubuf: Payload user buffer given by the caller
+ * @pubuf: Payload kernel buffer given by the caller
+ * @pbuf_size: pubuf/pkbuf(only one will be !NULL) size to be read/write.
+ * @private: For transport layer's use.
  * @sdata: payload
  *
  * &p9_fcall represents the structure for all 9P RPC
@@ -705,6 +709,10 @@ struct p9_fcall {
 
        size_t offset;
        size_t capacity;
+       char __user *pubuf;
+       char *pkbuf;
+       size_t pbuf_size;
+       void *private;
 
        uint8_t *sdata;
 };
index 198a640d53a64b681e89f4032f8ed133158fa96a..a0874cc1f718bcadbb604458127bebcf5664a2c5 100644 (file)
@@ -9,6 +9,7 @@ obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o
        util.o \
        protocol.o \
        trans_fd.o \
+       trans_common.o \
 
 9pnet_virtio-objs := \
        trans_virtio.o \
index 1e308f210928647196624d36627e4b2d0f168979..d888847db56ecc0cd6c72dfd82e74585261dc838 100644 (file)
@@ -606,6 +606,10 @@ void p9pdu_reset(struct p9_fcall *pdu)
 {
        pdu->offset = 0;
        pdu->size = 0;
+       pdu->private = NULL;
+       pdu->pubuf = NULL;
+       pdu->pkbuf = NULL;
+       pdu->pbuf_size = 0;
 }
 
 int p9dirent_read(char *buf, int len, struct p9_dirent *dirent,
diff --git a/net/9p/trans_common.c b/net/9p/trans_common.c
new file mode 100644 (file)
index 0000000..d62b9aa
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright IBM Corporation, 2010
+ * Author Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <net/9p/9p.h>
+#include <net/9p/client.h>
+#include <linux/scatterlist.h>
+#include "trans_common.h"
+
+/**
+ *  p9_release_req_pages - Release pages after the transaction.
+ *  @*private: PDU's private page of struct trans_rpage_info
+ */
+void
+p9_release_req_pages(struct trans_rpage_info *rpinfo)
+{
+       int i = 0;
+
+       while (rpinfo->rp_data[i] && rpinfo->rp_nr_pages--) {
+               put_page(rpinfo->rp_data[i]);
+               i++;
+       }
+}
+EXPORT_SYMBOL(p9_release_req_pages);
+
+/**
+ * p9_nr_pages - Return number of pages needed to accomodate the payload.
+ */
+int
+p9_nr_pages(struct p9_req_t *req)
+{
+       int start_page, end_page;
+       start_page =  (unsigned long long)req->tc->pubuf >> PAGE_SHIFT;
+       end_page = ((unsigned long long)req->tc->pubuf + req->tc->pbuf_size +
+                       PAGE_SIZE - 1) >> PAGE_SHIFT;
+       return end_page - start_page;
+}
+EXPORT_SYMBOL(p9_nr_pages);
+
+/**
+ * payload_gup - Translates user buffer into kernel pages and
+ * pins them either for read/write through get_user_pages_fast().
+ * @req: Request to be sent to server.
+ * @pdata_off: data offset into the first page after translation (gup).
+ * @pdata_len: Total length of the IO. gup may not return requested # of pages.
+ * @nr_pages: number of pages to accomodate the payload
+ * @rw: Indicates if the pages are for read or write.
+ */
+int
+p9_payload_gup(struct p9_req_t *req, size_t *pdata_off, int *pdata_len,
+               int nr_pages, u8 rw)
+{
+       uint32_t first_page_bytes = 0;
+       uint32_t pdata_mapped_pages;
+       struct trans_rpage_info  *rpinfo;
+
+       *pdata_off = (size_t)req->tc->pubuf & (PAGE_SIZE-1);
+
+       if (*pdata_off)
+               first_page_bytes = min((PAGE_SIZE - *pdata_off),
+                               req->tc->pbuf_size);
+
+       rpinfo = req->tc->private;
+       pdata_mapped_pages = get_user_pages_fast((unsigned long)req->tc->pubuf,
+                       nr_pages, rw, &rpinfo->rp_data[0]);
+
+       if (pdata_mapped_pages < 0) {
+               printk(KERN_ERR "get_user_pages_fast failed:%d udata:%p"
+                               "nr_pages:%d\n", pdata_mapped_pages,
+                               req->tc->pubuf, nr_pages);
+               pdata_mapped_pages = 0;
+               return -EIO;
+       }
+       rpinfo->rp_nr_pages = pdata_mapped_pages;
+       if (*pdata_off) {
+               *pdata_len = first_page_bytes;
+               *pdata_len += min((req->tc->pbuf_size - *pdata_len),
+                               ((size_t)pdata_mapped_pages - 1) << PAGE_SHIFT);
+       } else {
+               *pdata_len = min(req->tc->pbuf_size,
+                               (size_t)pdata_mapped_pages << PAGE_SHIFT);
+       }
+       return 0;
+}
+EXPORT_SYMBOL(p9_payload_gup);
diff --git a/net/9p/trans_common.h b/net/9p/trans_common.h
new file mode 100644 (file)
index 0000000..04977e0
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright IBM Corporation, 2010
+ * Author Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+/**
+ * struct trans_rpage_info - To store mapped page information in PDU.
+ * @rp_alloc:Set if this structure is allocd, not a reuse unused space in pdu.
+ * @rp_nr_pages: Number of mapped pages
+ * @rp_data: Array of page pointers
+ */
+struct trans_rpage_info {
+       u8 rp_alloc;
+       int rp_nr_pages;
+       struct page *rp_data[0];
+};
+
+void p9_release_req_pages(struct trans_rpage_info *);
+int p9_payload_gup(struct p9_req_t *, size_t *, int *, int, u8);
+int p9_nr_pages(struct p9_req_t *);