All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Shilovsky <pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
To: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 09/16] CIFS: Fix wsize usage in iovec write
Date: Fri, 27 Jun 2014 13:57:46 +0400	[thread overview]
Message-ID: <1403863073-19526-10-git-send-email-pshilovsky@samba.org> (raw)
In-Reply-To: <1403863073-19526-1-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>

If a server change maximum buffer size for write (wsize) requests
on reconnect we can fail on repeating with a big size buffer on
-EAGAIN error in iovec write. Fix this by checking wsize all the
time before repeating request in iovec write.

Signed-off-by: Pavel Shilovsky <pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
---
 fs/cifs/cifssmb.c |  4 ----
 fs/cifs/file.c    | 62 ++++++++++++++++++++++++++++++++++---------------------
 fs/cifs/smb2pdu.c |  4 ----
 3 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 41c9067..e411d2e 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -196,10 +196,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
 	if (rc)
 		goto out;
 
-	/*
-	 * FIXME: check if wsize needs updated due to negotiated smb buffer
-	 * 	  size shrinking
-	 */
 	atomic_inc(&tconInfoReconnectCount);
 
 	/* tell server Unix caps we support */
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 06080e0..f661977 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2401,28 +2401,6 @@ cifs_uncached_writev_complete(struct work_struct *work)
 	kref_put(&wdata->refcount, cifs_uncached_writedata_release);
 }
 
-/* attempt to send write to server, retry on any -EAGAIN errors */
-static int
-cifs_uncached_retry_writev(struct cifs_writedata *wdata)
-{
-	int rc;
-	struct TCP_Server_Info *server;
-
-	server = tlink_tcon(wdata->cfile->tlink)->ses->server;
-
-	do {
-		if (wdata->cfile->invalidHandle) {
-			rc = cifs_reopen_file(wdata->cfile, false);
-			if (rc != 0)
-				continue;
-		}
-		rc = server->ops->async_writev(wdata,
-					       cifs_uncached_writedata_release);
-	} while (rc == -EAGAIN);
-
-	return rc;
-}
-
 static int
 wdata_fill_from_iovec(struct cifs_writedata *wdata, struct iov_iter *from,
 		      size_t *len, unsigned long nr_pages)
@@ -2477,13 +2455,19 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
 	size_t cur_len;
 	unsigned long nr_pages, i;
 	struct cifs_writedata *wdata;
+	struct iov_iter saved_from;
+	loff_t saved_offset = offset;
 	pid_t pid;
+	struct TCP_Server_Info *server;
 
 	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
 		pid = open_file->pid;
 	else
 		pid = current->tgid;
 
+	server = tlink_tcon(open_file->tlink)->ses->server;
+	memcpy(&saved_from, from, sizeof(struct iov_iter));
+
 	do {
 		nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
 		wdata = cifs_writedata_alloc(nr_pages,
@@ -2515,10 +2499,20 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
 		wdata->bytes = cur_len;
 		wdata->pagesz = PAGE_SIZE;
 		wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE);
-		rc = cifs_uncached_retry_writev(wdata);
+
+		if (!wdata->cfile->invalidHandle ||
+		    !cifs_reopen_file(wdata->cfile, false))
+			rc = server->ops->async_writev(wdata,
+					cifs_uncached_writedata_release);
 		if (rc) {
 			kref_put(&wdata->refcount,
 				 cifs_uncached_writedata_release);
+			if (rc == -EAGAIN) {
+				memcpy(from, &saved_from,
+				       sizeof(struct iov_iter));
+				iov_iter_advance(from, offset - saved_offset);
+				continue;
+			}
 			break;
 		}
 
@@ -2541,6 +2535,7 @@ cifs_iovec_write(struct file *file, struct iov_iter *from, loff_t *poffset)
 	struct cifs_sb_info *cifs_sb;
 	struct cifs_writedata *wdata, *tmp;
 	struct list_head wdata_list;
+	struct iov_iter saved_from;
 	int rc;
 
 	len = iov_iter_count(from);
@@ -2562,6 +2557,7 @@ cifs_iovec_write(struct file *file, struct iov_iter *from, loff_t *poffset)
 		return -ENOSYS;
 
 	offset = *poffset;
+	memcpy(&saved_from, from, sizeof(struct iov_iter));
 
 	rc = cifs_write_from_iter(*poffset, len, from, open_file, cifs_sb,
 				  &wdata_list);
@@ -2594,7 +2590,25 @@ restart_loop:
 
 			/* resend call if it's a retryable error */
 			if (rc == -EAGAIN) {
-				rc = cifs_uncached_retry_writev(wdata);
+				struct list_head tmp_list;
+				struct iov_iter tmp_from;
+
+				INIT_LIST_HEAD(&tmp_list);
+				list_del_init(&wdata->list);
+
+				memcpy(&tmp_from, &saved_from,
+				       sizeof(struct iov_iter));
+				iov_iter_advance(&tmp_from,
+						 wdata->offset - *poffset);
+
+				rc = cifs_write_from_iter(wdata->offset,
+						wdata->bytes, &tmp_from,
+						open_file, cifs_sb, &tmp_list);
+
+				list_splice(&tmp_list, &wdata_list);
+
+				kref_put(&wdata->refcount,
+					 cifs_uncached_writedata_release);
 				goto restart_loop;
 			}
 		}
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 0158104..da7aa62 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -245,10 +245,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon)
 	if (rc)
 		goto out;
 	atomic_inc(&tconInfoReconnectCount);
-	/*
-	 * BB FIXME add code to check if wsize needs update due to negotiated
-	 * smb buffer size shrinking.
-	 */
 out:
 	/*
 	 * Check if handle based operation so we know whether we can continue
-- 
1.8.1.2

  parent reply	other threads:[~2014-06-27  9:57 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27  9:57 [PATCH v2 00/16] SMB 2.1/3 multicredit requests for reading/writing Pavel Shilovsky
     [not found] ` <1403863073-19526-1-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-06-27  9:57   ` [PATCH v2 01/16] CIFS: Fix async reading on reconnects Pavel Shilovsky
     [not found]     ` <1403863073-19526-2-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-06-27 10:52       ` Jeff Layton
     [not found]         ` <CAH2r5mvWfmgZb=7oGqbqbRDKv4xPP3RszHXpe-rxGv5FbGBerw@mail.gmail.com>
     [not found]           ` <CAH2r5mvWfmgZb=7oGqbqbRDKv4xPP3RszHXpe-rxGv5FbGBerw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-06-27 14:14             ` Fwd: " Steve French
     [not found]         ` <20140627065222.434cd5ea-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-06-27 16:06           ` Pavel Shilovsky
     [not found]             ` <CAKywueSpPjEpyQYLvrSixf4tasxd5v4a51EBKhBboaTXcs5O1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-03 10:45               ` Jeff Layton
     [not found]                 ` <20140703064549.7f6913f3-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-07-03 16:12                   ` Pavel Shilovsky
2014-07-03 16:39                   ` Jeff Layton
     [not found]                     ` <20140703123930.5feb046f-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-07-21 15:41                       ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 02/16] CIFS: Separate page processing from writepages Pavel Shilovsky
     [not found]     ` <1403863073-19526-3-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-09 12:59       ` Jeff Layton
2014-06-27  9:57   ` [PATCH v2 03/16] CIFS: Separate page sending " Pavel Shilovsky
     [not found]     ` <1403863073-19526-4-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-09 13:08       ` Jeff Layton
     [not found]         ` <20140709090823.08bbd37b-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-07-21 15:53           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 04/16] CIFS: Separate pages initialization " Pavel Shilovsky
     [not found]     ` <1403863073-19526-5-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-19  6:24       ` Shirish Pargaonkar
2014-06-27  9:57   ` [PATCH v2 05/16] CIFS: Fix wsize usage in writepages Pavel Shilovsky
     [not found]     ` <1403863073-19526-6-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-20 15:17       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+ce727VwQD6WmhY_SWG_Xm+2JxGuC2GnPZG==nv9FgxQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-20 17:41           ` Pavel Shilovsky
     [not found]             ` <CAKywueRP6y7gdyXCYVBCXQU3_65=rU7+cP-UdgBrO5cwx+_nCA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-20 18:13               ` Shirish Pargaonkar
     [not found]                 ` <CADT32eK15DRUnrogmFFv2TicqhOhcNA0Y62dUeM+41YtjrZwFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  7:03                   ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 06/16] CIFS: Fix cifs_writev_requeue when wsize changes Pavel Shilovsky
     [not found]     ` <1403863073-19526-7-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-20 19:49       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+kGf-b989EFr4c_-e9+_MCVMkDShkh_30an8YKLiD6Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  6:43           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 07/16] CIFS: Separate filling pages from iovec write Pavel Shilovsky
     [not found]     ` <1403863073-19526-8-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-21  3:59       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+RhpebBn-2k-GrNomJ_=uY8v12KmWHFbd+NozNSi1t9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  6:48           ` Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 08/16] CIFS: Separate writing " Pavel Shilovsky
     [not found]     ` <1403863073-19526-9-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2014-07-21  5:05       ` Shirish Pargaonkar
     [not found]         ` <CADT32e+2Z_ryfg8JznJoFt9=4mSU1bVYmeR-+nguXUq1vQVMMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21  6:56           ` Pavel Shilovsky
2014-06-27  9:57   ` Pavel Shilovsky [this message]
2014-06-27  9:57   ` [PATCH v2 10/16] CIFS: Use multicredits for SMB 2.1/3 writes Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 11/16] CIFS: Separate page search from readpages Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 12/16] CIFS: Fix rsize usage in readpages Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 13/16] CIFS: Separate page reading from user read Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 14/16] CIFS: Fix rsize usage in " Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 15/16] CIFS: Fix rsize usage for sync read Pavel Shilovsky
2014-06-27  9:57   ` [PATCH v2 16/16] CIFS: Use multicredits for SMB 2.1/3 reads Pavel Shilovsky

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=1403863073-19526-10-git-send-email-pshilovsky@samba.org \
    --to=pshilovsky-eunubhrolfbytjvyw6ydsg@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@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.