All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 4/9] cifs: teach smb_send_rqst how to handle arrays of pages
Date: Wed, 25 Jul 2012 11:54:07 -0400	[thread overview]
Message-ID: <1343231652-10459-5-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1343231652-10459-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Add code that allows smb_send_rqst to send an array of pages after the
initial kvec array has been sent. For now, we simply kmap the page
array and send it using the standard smb_send_kvec function. Eventually,
we may want to convert this code to use kernel_sendpage under the hood
and avoid the kmap altogether for the page data.

Reviewed-by: Pavel Shilovsky <pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
Signed-off-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 fs/cifs/transport.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index a3e58b2..946a462 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -28,6 +28,7 @@
 #include <linux/delay.h>
 #include <linux/freezer.h>
 #include <linux/tcp.h>
+#include <linux/highmem.h>
 #include <asm/uaccess.h>
 #include <asm/processor.h>
 #include <linux/mempool.h>
@@ -240,6 +241,38 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,
 	return rc;
 }
 
+/**
+ * rqst_page_to_kvec - Turn a slot in the smb_rqst page array into a kvec
+ * @rqst: pointer to smb_rqst
+ * @idx: index into the array of the page
+ * @iov: pointer to struct kvec that will hold the result
+ *
+ * Helper function to convert a slot in the rqst->rq_pages array into a kvec.
+ * The page will be kmapped and the address placed into iov_base. The length
+ * will then be adjusted according to the ptailoff.
+ */
+static void
+cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx,
+			struct kvec *iov)
+{
+	/*
+	 * FIXME: We could avoid this kmap altogether if we used
+	 * kernel_sendpage instead of kernel_sendmsg. That will only
+	 * work if signing is disabled though as sendpage inlines the
+	 * page directly into the fraglist. If userspace modifies the
+	 * page after we calculate the signature, then the server will
+	 * reject it and may break the connection. kernel_sendmsg does
+	 * an extra copy of the data and avoids that issue.
+	 */
+	iov->iov_base = kmap(rqst->rq_pages[idx]);
+
+	/* if last page, don't send beyond this offset into page */
+	if (idx == (rqst->rq_npages - 1))
+		iov->iov_len = rqst->rq_tailsz;
+	else
+		iov->iov_len = rqst->rq_pagesz;
+}
+
 static int
 smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
 {
@@ -247,7 +280,8 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
 	struct kvec *iov = rqst->rq_iov;
 	int n_vec = rqst->rq_nvec;
 	unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base);
-	size_t total_len;
+	unsigned int i;
+	size_t total_len = 0, sent;
 	struct socket *ssocket = server->ssocket;
 	int val = 1;
 
@@ -258,8 +292,26 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
 	kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
 				(char *)&val, sizeof(val));
 
-	rc = smb_send_kvec(server, iov, n_vec, &total_len);
+	rc = smb_send_kvec(server, iov, n_vec, &sent);
+	if (rc < 0)
+		goto uncork;
+
+	total_len += sent;
+
+	/* now walk the page array and send each page in it */
+	for (i = 0; i < rqst->rq_npages; i++) {
+		struct kvec p_iov;
+
+		cifs_rqst_page_to_kvec(rqst, i, &p_iov);
+		rc = smb_send_kvec(server, &p_iov, 1, &sent);
+		kunmap(rqst->rq_pages[i]);
+		if (rc < 0)
+			break;
+
+		total_len += sent;
+	}
 
+uncork:
 	/* uncork it */
 	val = 0;
 	kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
-- 
1.7.11.2

  parent reply	other threads:[~2012-07-25 15:54 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-25 15:54 [PATCH v2 0/9] cifs: convert async write code to use less kmapping Jeff Layton
     [not found] ` <1343231652-10459-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-07-25 15:54   ` [PATCH v2 1/9] cifs: change signing routines to deal with smb_rqst structs Jeff Layton
     [not found]     ` <1343231652-10459-2-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-07-25 18:46       ` Pavel Shilovsky
2012-07-25 15:54   ` [PATCH v2 2/9] cifs: convert send code to use " Jeff Layton
2012-07-25 15:54   ` [PATCH v2 3/9] cifs: cork the socket before a send and uncork it afterward Jeff Layton
     [not found]     ` <1343231652-10459-4-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-07-26 23:57       ` Pavel Shilovsky
     [not found]         ` <CAKywueQDJax9SqN95ZKbBmjtxZZs4Y34H5Xi3N3AJtiG09uVpw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-27  1:33           ` Jeff Layton
     [not found]             ` <20120726213304.1db924f1-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2012-07-27  6:05               ` Pavel Shilovsky
     [not found]                 ` <CAKywueRYLeMHkVPi+NB_Z0sa3QCbQnnVSUDai8N+omMg2FPDSQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-29 12:13                   ` Jeff Layton
     [not found]                     ` <20120729081309.1cabacf7-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-07-30 21:11                       ` Pavel Shilovsky
     [not found]                         ` <CAKywueS9yo59J_P3JV+NDpWbHg=8Jw=pzKuOn4TKe_fDHf9-EA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-31  1:17                           ` Jeff Layton
     [not found]                             ` <20120730211753.7a22e740-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2012-07-31 11:24                               ` Jeff Layton
     [not found]                                 ` <20120731072414.185b1ff0-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2012-08-01 13:37                                   ` Pavel Shilovsky
     [not found]                                     ` <CAKywueSRgfTstMkWNHYqS-OXGF7wSnVwE57zcWasvAiAZTTT3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-08-01 13:45                                       ` Jeff Layton
     [not found]                                         ` <20120801094542.10220150-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-08-04 20:51                                           ` Pavel Shilovsky
2012-08-04 21:37                                             ` Steve French
     [not found]                                               ` <CAH2r5mtgTCqv1bKb6PmnBG9QzUUMLAOyJk5hZYWSd75Pi38P1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-08-20 18:38                                                 ` Pavel Shilovsky
2012-08-01 14:34                                       ` Jeff Layton
     [not found]                                         ` <20120801103435.17d5c75a-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-08-04 20:49                                           ` Pavel Shilovsky
2012-07-25 15:54   ` Jeff Layton [this message]
2012-07-25 15:54   ` [PATCH v2 5/9] cifs: teach signing routines how to deal with arrays of pages in a smb_rqst Jeff Layton
2012-07-25 15:54   ` [PATCH v2 6/9] cifs: change cifs_call_async to use smb_rqst structs Jeff Layton
     [not found]     ` <1343231652-10459-7-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-07-25 18:49       ` Pavel Shilovsky
     [not found]         ` <CAKywueRUbMbxUNVGZnSH4CyKFUnvSmcWwQAZEVuZv9SoLh2tMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-26  8:10           ` Pavel Shilovsky
     [not found]             ` <CAKywueTCyhe6MSdekOc1SBTR6+8v-sCmJ4Ezab7JS29uXhk16g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-26  8:54               ` Pavel Shilovsky
     [not found]                 ` <CAKywueQWGJf_BWAKtizF5R_zqWiF=5Lp4BcCXRTmf6JpJFa5sQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-07-26 10:27                   ` Jeff Layton
2012-07-26 11:03                   ` Jeff Layton
2012-07-25 15:54   ` [PATCH v2 7/9] cifs: convert async write code to pass in data via rq_pages array Jeff Layton
     [not found]     ` <1343231652-10459-8-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-07-25 18:56       ` Pavel Shilovsky
2012-07-25 15:54   ` [PATCH v2 8/9] cifs: remove the kmap size limit from wsize Jeff Layton
2012-07-25 15:54   ` [PATCH v2 9/9] cifs: add deprecation warning to sockopt=TCP_NODELAY option Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343231652-10459-5-git-send-email-jlayton@redhat.com \
    --to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.