diff mbox

[V9fs-developer,5/5,net/9p] Achieve zero copy on read path.

Message ID 1282066045-3945-6-git-send-email-jvrao@linux.vnet.ibm.com (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

jvrao Aug. 17, 2010, 5:27 p.m. UTC
None
diff mbox

Patch

diff --git a/net/9p/client.c b/net/9p/client.c
index 7ce58fb..d11c7dd 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -1282,6 +1282,7 @@  p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 	struct p9_client *clnt;
 	struct p9_req_t *req;
 	char *dataptr;
+	int page_direct = 0;
 
 	P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", fid->fid,
 					(long long unsigned) offset, count);
@@ -1296,7 +1297,20 @@  p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 	if (count < rsize)
 		rsize = count;
 
-	req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize);
+	if (clnt->trans_mod->capability &&
+		clnt->trans_mod->capability(P9_CAP_GET_MAX_SG_PAGES) &&
+			(udata && !segment_eq(get_fs(), KERNEL_DS)))
+		page_direct = 1;
+
+	if (page_direct) {
+		rsize = count;
+		req = p9_client_rpc(clnt, P9_TREAD, "dqE", fid->fid, offset,
+				rsize, udata);
+	} else {
+		req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset,
+				rsize);
+	}
+
 	if (IS_ERR(req)) {
 		err = PTR_ERR(req);
 		goto error;
@@ -1314,7 +1328,7 @@  p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 		memmove(data, dataptr, count);
 	}
 
-	if (udata) {
+	if (udata && !page_direct) {
 		err = copy_to_user(udata, dataptr, count);
 		if (err) {
 			err = -EFAULT;
diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index 97f313d..b82d117 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -194,6 +194,25 @@  pdu_write_u(struct p9_fcall *pdu, struct p9_client *c, const char __user *udata,
 	return len;
 }
 
+	static size_t
+pdu_write_ur(struct p9_fcall *pdu, struct p9_client *c,
+		const char __user *udata, size_t size)
+{
+	size_t len = size;
+	int max_req_sg_pages = 0;
+
+	if (c->trans_mod->capability)
+		max_req_sg_pages =
+			c->trans_mod->capability(P9_CAP_GET_MAX_SG_PAGES);
+	if (max_req_sg_pages) {
+		len = pdu_fill_pages(pdu, udata, size, 1, max_req_sg_pages);
+		if (len < 0)
+			return len;
+		pdu->pdata_read_len = len;
+	}
+	return len;
+}
+
 /*
 	b - int8_t
 	w - int16_t
@@ -534,8 +553,18 @@  p9pdu_vwritef(struct p9_fcall *pdu, struct p9_client *c, const char *fmt,
 				if (!errcode &&
 					pdu_write_u(pdu, c, udata, count) < 0)
 					errcode = -EFAULT;
-			}
-			break;
+			 }
+			 break;
+		case 'E':{
+				 int32_t count = va_arg(ap, int32_t);
+				 const char __user *udata =
+					 va_arg(ap, const void __user *);
+				 errcode = p9pdu_writef(pdu, c, "d", count);
+				 if (!errcode &&
+					pdu_write_ur(pdu, c, udata, count) < 0)
+					errcode = -EFAULT;
+			 }
+			 break;
 		case 'T':{
 				int16_t nwname = va_arg(ap, int);
 				const char **wnames = va_arg(ap, const char **);