linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata when transport returning -EAGAIN
@ 2019-03-15  7:54 Long Li
  2019-03-15  7:55 ` [Patch v2 2/2] CIFS: Fix an issue with re-sending rdata " Long Li
  2019-03-16 18:01 ` [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata " Pavel Shilovsky
  0 siblings, 2 replies; 4+ messages in thread
From: Long Li @ 2019-03-15  7:54 UTC (permalink / raw)
  To: Steve French, linux-cifs, samba-technical, linux-kernel; +Cc: Long Li

From: Long Li <longli@microsoft.com>

When sending a wdata, transport may return -EAGAIN. In this case
we should re-obtain credits because the session may have been
reconnected.

Change in v2: adjust_credits before re-sending

Signed-off-by: Long Li <longli@microsoft.com>
---
 fs/cifs/file.c | 77 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 32 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 9b53f33137b3..321df1d27422 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2620,43 +2620,56 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
 	struct TCP_Server_Info *server =
 		tlink_tcon(wdata->cfile->tlink)->ses->server;
 
-	/*
-	 * Wait for credits to resend this wdata.
-	 * Note: we are attempting to resend the whole wdata not in segments
-	 */
 	do {
-		rc = server->ops->wait_mtu_credits(server, wdata->bytes, &wsize,
-						   &credits);
+		if (wdata->cfile->invalidHandle) {
+			rc = cifs_reopen_file(wdata->cfile, false);
+			if (rc == -EAGAIN)
+				continue;
+			else if (rc)
+				break;
+		}
 
-		if (rc)
-			goto out;
 
-		if (wsize < wdata->bytes) {
-			add_credits_and_wake_if(server, &credits, 0);
-			msleep(1000);
-		}
-	} while (wsize < wdata->bytes);
+		/*
+		 * Wait for credits to resend this wdata.
+		 * Note: we are attempting to resend the whole wdata not in
+		 * segments
+		 */
+		do {
+			rc = server->ops->wait_mtu_credits(server, wdata->bytes,
+						&wsize, &credits);
+			if (rc)
+				goto fail;
+
+			if (wsize < wdata->bytes) {
+				add_credits_and_wake_if(server, &credits, 0);
+				msleep(1000);
+			}
+		} while (wsize < wdata->bytes);
+		wdata->credits = credits;
 
-	wdata->credits = credits;
-	rc = -EAGAIN;
-	while (rc == -EAGAIN) {
-		rc = 0;
-		if (wdata->cfile->invalidHandle)
-			rc = cifs_reopen_file(wdata->cfile, false);
-		if (!rc)
-			rc = server->ops->async_writev(wdata,
+		rc = adjust_credits(server, &wdata->credits, wdata->bytes);
+
+		if (!rc) {
+			if (wdata->cfile->invalidHandle)
+				rc = -EAGAIN;
+			else
+				rc = server->ops->async_writev(wdata,
 					cifs_uncached_writedata_release);
-	}
+		}
 
-	if (!rc) {
-		list_add_tail(&wdata->list, wdata_list);
-		return 0;
-	}
+		/* If the write was successfully sent, we are done */
+		if (!rc) {
+			list_add_tail(&wdata->list, wdata_list);
+			return 0;
+		}
 
-	add_credits_and_wake_if(server, &wdata->credits, 0);
-out:
-	kref_put(&wdata->refcount, cifs_uncached_writedata_release);
+		/* Roll back credits and retry if needed */
+		add_credits_and_wake_if(server, &wdata->credits, 0);
+	} while (rc == -EAGAIN);
 
+fail:
+	kref_put(&wdata->refcount, cifs_uncached_writedata_release);
 	return rc;
 }
 
@@ -2884,12 +2897,12 @@ static void collect_uncached_write_data(struct cifs_aio_ctx *ctx)
 						wdata->bytes, &tmp_from,
 						ctx->cfile, cifs_sb, &tmp_list,
 						ctx);
+
+					kref_put(&wdata->refcount,
+						cifs_uncached_writedata_release);
 				}
 
 				list_splice(&tmp_list, &ctx->list);
-
-				kref_put(&wdata->refcount,
-					 cifs_uncached_writedata_release);
 				goto restart_loop;
 			}
 		}
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Patch v2 2/2] CIFS: Fix an issue with re-sending rdata when transport returning -EAGAIN
  2019-03-15  7:54 [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata when transport returning -EAGAIN Long Li
@ 2019-03-15  7:55 ` Long Li
  2019-03-16 18:03   ` Pavel Shilovsky
  2019-03-16 18:01 ` [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata " Pavel Shilovsky
  1 sibling, 1 reply; 4+ messages in thread
From: Long Li @ 2019-03-15  7:55 UTC (permalink / raw)
  To: Steve French, linux-cifs, samba-technical, linux-kernel; +Cc: Long Li

From: Long Li <longli@microsoft.com>

When sending a rdata, transport may return -EAGAIN. In this case
we should re-obtain credits because the session may have been
reconnected.

Change in v2: adjust_credits before re-sending

Signed-off-by: Long Li <longli@microsoft.com>
---
 fs/cifs/file.c | 71 +++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 41 insertions(+), 30 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 321df1d27422..9d90cc07e38b 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -3347,44 +3347,55 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata,
 	struct TCP_Server_Info *server =
 		tlink_tcon(rdata->cfile->tlink)->ses->server;
 
-	/*
-	 * Wait for credits to resend this rdata.
-	 * Note: we are attempting to resend the whole rdata not in segments
-	 */
 	do {
-		rc = server->ops->wait_mtu_credits(server, rdata->bytes,
+		if (rdata->cfile->invalidHandle) {
+			rc = cifs_reopen_file(rdata->cfile, true);
+			if (rc == -EAGAIN)
+				continue;
+			else if (rc)
+				break;
+		}
+
+		/*
+		 * Wait for credits to resend this rdata.
+		 * Note: we are attempting to resend the whole rdata not in
+		 * segments
+		 */
+		do {
+			rc = server->ops->wait_mtu_credits(server, rdata->bytes,
 						&rsize, &credits);
 
-		if (rc)
-			goto out;
+			if (rc)
+				goto fail;
 
-		if (rsize < rdata->bytes) {
-			add_credits_and_wake_if(server, &credits, 0);
-			msleep(1000);
-		}
-	} while (rsize < rdata->bytes);
+			if (rsize < rdata->bytes) {
+				add_credits_and_wake_if(server, &credits, 0);
+				msleep(1000);
+			}
+		} while (rsize < rdata->bytes);
+		rdata->credits = credits;
 
-	rdata->credits = credits;
-	rc = -EAGAIN;
-	while (rc == -EAGAIN) {
-		rc = 0;
-		if (rdata->cfile->invalidHandle)
-			rc = cifs_reopen_file(rdata->cfile, true);
-		if (!rc)
-			rc = server->ops->async_readv(rdata);
-	}
+		rc = adjust_credits(server, &rdata->credits, rdata->bytes);
+		if (!rc) {
+			if (rdata->cfile->invalidHandle)
+				rc = -EAGAIN;
+			else
+				rc = server->ops->async_readv(rdata);
+		}
 
-	if (!rc) {
-		/* Add to aio pending list */
-		list_add_tail(&rdata->list, rdata_list);
-		return 0;
-	}
+		/* If the read was successfully sent, we are done */
+		if (!rc) {
+			/* Add to aio pending list */
+			list_add_tail(&rdata->list, rdata_list);
+			return 0;
+		}
 
-	add_credits_and_wake_if(server, &rdata->credits, 0);
-out:
-	kref_put(&rdata->refcount,
-		cifs_uncached_readdata_release);
+		/* Roll back credits and retry if needed */
+		add_credits_and_wake_if(server, &rdata->credits, 0);
+	} while (rc == -EAGAIN);
 
+fail:
+	kref_put(&rdata->refcount, cifs_uncached_readdata_release);
 	return rc;
 }
 
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata when transport returning -EAGAIN
  2019-03-15  7:54 [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata when transport returning -EAGAIN Long Li
  2019-03-15  7:55 ` [Patch v2 2/2] CIFS: Fix an issue with re-sending rdata " Long Li
@ 2019-03-16 18:01 ` Pavel Shilovsky
  1 sibling, 0 replies; 4+ messages in thread
From: Pavel Shilovsky @ 2019-03-16 18:01 UTC (permalink / raw)
  To: Long Li; +Cc: Steve French, linux-cifs, samba-technical, Kernel Mailing List

пт, 15 мар. 2019 г. в 00:56, Long Li <longli@linuxonhyperv.com>:
>
> From: Long Li <longli@microsoft.com>
>
> When sending a wdata, transport may return -EAGAIN. In this case
> we should re-obtain credits because the session may have been
> reconnected.
>
> Change in v2: adjust_credits before re-sending
>
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  fs/cifs/file.c | 77 ++++++++++++++++++++++++++++++++++------------------------
>  1 file changed, 45 insertions(+), 32 deletions(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 9b53f33137b3..321df1d27422 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -2620,43 +2620,56 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
>         struct TCP_Server_Info *server =
>                 tlink_tcon(wdata->cfile->tlink)->ses->server;
>
> -       /*
> -        * Wait for credits to resend this wdata.
> -        * Note: we are attempting to resend the whole wdata not in segments
> -        */
>         do {
> -               rc = server->ops->wait_mtu_credits(server, wdata->bytes, &wsize,
> -                                                  &credits);
> +               if (wdata->cfile->invalidHandle) {
> +                       rc = cifs_reopen_file(wdata->cfile, false);
> +                       if (rc == -EAGAIN)
> +                               continue;
> +                       else if (rc)
> +                               break;
> +               }
>
> -               if (rc)
> -                       goto out;
>
> -               if (wsize < wdata->bytes) {
> -                       add_credits_and_wake_if(server, &credits, 0);
> -                       msleep(1000);
> -               }
> -       } while (wsize < wdata->bytes);
> +               /*
> +                * Wait for credits to resend this wdata.
> +                * Note: we are attempting to resend the whole wdata not in
> +                * segments
> +                */
> +               do {
> +                       rc = server->ops->wait_mtu_credits(server, wdata->bytes,
> +                                               &wsize, &credits);
> +                       if (rc)
> +                               goto fail;
> +
> +                       if (wsize < wdata->bytes) {
> +                               add_credits_and_wake_if(server, &credits, 0);
> +                               msleep(1000);
> +                       }
> +               } while (wsize < wdata->bytes);
> +               wdata->credits = credits;
>
> -       wdata->credits = credits;
> -       rc = -EAGAIN;
> -       while (rc == -EAGAIN) {
> -               rc = 0;
> -               if (wdata->cfile->invalidHandle)
> -                       rc = cifs_reopen_file(wdata->cfile, false);
> -               if (!rc)
> -                       rc = server->ops->async_writev(wdata,
> +               rc = adjust_credits(server, &wdata->credits, wdata->bytes);
> +
> +               if (!rc) {
> +                       if (wdata->cfile->invalidHandle)
> +                               rc = -EAGAIN;
> +                       else
> +                               rc = server->ops->async_writev(wdata,
>                                         cifs_uncached_writedata_release);
> -       }
> +               }
>
> -       if (!rc) {
> -               list_add_tail(&wdata->list, wdata_list);
> -               return 0;
> -       }
> +               /* If the write was successfully sent, we are done */
> +               if (!rc) {
> +                       list_add_tail(&wdata->list, wdata_list);
> +                       return 0;
> +               }
>
> -       add_credits_and_wake_if(server, &wdata->credits, 0);
> -out:
> -       kref_put(&wdata->refcount, cifs_uncached_writedata_release);
> +               /* Roll back credits and retry if needed */
> +               add_credits_and_wake_if(server, &wdata->credits, 0);
> +       } while (rc == -EAGAIN);
>
> +fail:
> +       kref_put(&wdata->refcount, cifs_uncached_writedata_release);
>         return rc;
>  }
>
> @@ -2884,12 +2897,12 @@ static void collect_uncached_write_data(struct cifs_aio_ctx *ctx)
>                                                 wdata->bytes, &tmp_from,
>                                                 ctx->cfile, cifs_sb, &tmp_list,
>                                                 ctx);
> +
> +                                       kref_put(&wdata->refcount,
> +                                               cifs_uncached_writedata_release);
>                                 }
>
>                                 list_splice(&tmp_list, &ctx->list);
> -
> -                               kref_put(&wdata->refcount,
> -                                        cifs_uncached_writedata_release);
>                                 goto restart_loop;
>                         }
>                 }
> --
> 2.14.1
>

Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>

--
Best regards,
Pavel Shilovsky

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch v2 2/2] CIFS: Fix an issue with re-sending rdata when transport returning -EAGAIN
  2019-03-15  7:55 ` [Patch v2 2/2] CIFS: Fix an issue with re-sending rdata " Long Li
@ 2019-03-16 18:03   ` Pavel Shilovsky
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Shilovsky @ 2019-03-16 18:03 UTC (permalink / raw)
  To: Long Li; +Cc: Steve French, linux-cifs, samba-technical, Kernel Mailing List

пт, 15 мар. 2019 г. в 00:56, Long Li <longli@linuxonhyperv.com>:
>
> From: Long Li <longli@microsoft.com>
>
> When sending a rdata, transport may return -EAGAIN. In this case
> we should re-obtain credits because the session may have been
> reconnected.
>
> Change in v2: adjust_credits before re-sending
>
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  fs/cifs/file.c | 71 +++++++++++++++++++++++++++++++++-------------------------
>  1 file changed, 41 insertions(+), 30 deletions(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 321df1d27422..9d90cc07e38b 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -3347,44 +3347,55 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata,
>         struct TCP_Server_Info *server =
>                 tlink_tcon(rdata->cfile->tlink)->ses->server;
>
> -       /*
> -        * Wait for credits to resend this rdata.
> -        * Note: we are attempting to resend the whole rdata not in segments
> -        */
>         do {
> -               rc = server->ops->wait_mtu_credits(server, rdata->bytes,
> +               if (rdata->cfile->invalidHandle) {
> +                       rc = cifs_reopen_file(rdata->cfile, true);
> +                       if (rc == -EAGAIN)
> +                               continue;
> +                       else if (rc)
> +                               break;
> +               }
> +
> +               /*
> +                * Wait for credits to resend this rdata.
> +                * Note: we are attempting to resend the whole rdata not in
> +                * segments
> +                */
> +               do {
> +                       rc = server->ops->wait_mtu_credits(server, rdata->bytes,
>                                                 &rsize, &credits);
>
> -               if (rc)
> -                       goto out;
> +                       if (rc)
> +                               goto fail;
>
> -               if (rsize < rdata->bytes) {
> -                       add_credits_and_wake_if(server, &credits, 0);
> -                       msleep(1000);
> -               }
> -       } while (rsize < rdata->bytes);
> +                       if (rsize < rdata->bytes) {
> +                               add_credits_and_wake_if(server, &credits, 0);
> +                               msleep(1000);
> +                       }
> +               } while (rsize < rdata->bytes);
> +               rdata->credits = credits;
>
> -       rdata->credits = credits;
> -       rc = -EAGAIN;
> -       while (rc == -EAGAIN) {
> -               rc = 0;
> -               if (rdata->cfile->invalidHandle)
> -                       rc = cifs_reopen_file(rdata->cfile, true);
> -               if (!rc)
> -                       rc = server->ops->async_readv(rdata);
> -       }
> +               rc = adjust_credits(server, &rdata->credits, rdata->bytes);
> +               if (!rc) {
> +                       if (rdata->cfile->invalidHandle)
> +                               rc = -EAGAIN;
> +                       else
> +                               rc = server->ops->async_readv(rdata);
> +               }
>
> -       if (!rc) {
> -               /* Add to aio pending list */
> -               list_add_tail(&rdata->list, rdata_list);
> -               return 0;
> -       }
> +               /* If the read was successfully sent, we are done */
> +               if (!rc) {
> +                       /* Add to aio pending list */
> +                       list_add_tail(&rdata->list, rdata_list);
> +                       return 0;
> +               }
>
> -       add_credits_and_wake_if(server, &rdata->credits, 0);
> -out:
> -       kref_put(&rdata->refcount,
> -               cifs_uncached_readdata_release);
> +               /* Roll back credits and retry if needed */
> +               add_credits_and_wake_if(server, &rdata->credits, 0);
> +       } while (rc == -EAGAIN);
>
> +fail:
> +       kref_put(&rdata->refcount, cifs_uncached_readdata_release);
>         return rc;
>  }
>
> --
> 2.14.1
>

Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>

--
Best regards,
Pavel Shilovsky

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-16 18:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-15  7:54 [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata when transport returning -EAGAIN Long Li
2019-03-15  7:55 ` [Patch v2 2/2] CIFS: Fix an issue with re-sending rdata " Long Li
2019-03-16 18:03   ` Pavel Shilovsky
2019-03-16 18:01 ` [Patch v2 1/2] CIFS: Fix an issue with re-sending wdata " Pavel Shilovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).