diff mbox series

[5/6] cifs: add a timeout argument to wait_for_free_credits

Message ID 20190308025823.24382-6-lsahlber@redhat.com (mailing list archive)
State New, archived
Headers show
Series cifs: simplify handling of credits for compounds | expand

Commit Message

Ronnie Sahlberg March 8, 2019, 2:58 a.m. UTC
A negative timeout is the same as the current behaviour, i.e. no timeout.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/transport.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

Comments

Pavel Shilovsky March 9, 2019, 12:58 a.m. UTC | #1
чт, 7 мар. 2019 г. в 19:35, Ronnie Sahlberg <lsahlber@redhat.com>:
>
> A negative timeout is the same as the current behaviour, i.e. no timeout.
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/transport.c | 40 ++++++++++++++++++++++++++++++----------
>  1 file changed, 30 insertions(+), 10 deletions(-)
>
> diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
> index f4ec9635dab2..62c58ce80123 100644
> --- a/fs/cifs/transport.c
> +++ b/fs/cifs/transport.c
> @@ -478,11 +478,18 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
>
>  static int
>  wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
> -                     const int flags, unsigned int *instance)
> +                     const int timeout, const int flags,
> +                     unsigned int *instance)
>  {
>         int rc;
>         int *credits;
>         int optype;
> +       long int t;
> +
> +       if (timeout < 0)
> +               t = MAX_JIFFY_OFFSET;
> +       else
> +               t = msecs_to_jiffies(timeout);
>
>         optype = flags & CIFS_OP_MASK;
>
> @@ -507,11 +514,16 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
>                 if (*credits < num_credits) {
>                         spin_unlock(&server->req_lock);
>                         cifs_num_waiters_inc(server);
> -                       rc = wait_event_killable(server->request_q,
> -                               has_credits(server, credits, num_credits));
> +                       rc = wait_event_killable_timeout(server->request_q,
> +                               has_credits(server, credits, num_credits), t);
>                         cifs_num_waiters_dec(server);
> -                       if (rc)
> -                               return rc;
> +                       if (!rc) {
> +                               cifs_dbg(VFS, "wait timed out after %d ms\n",
> +                                        timeout);
> +                               return -ENOTSUPP;
> +                       }
> +                       if (rc == -ERESTARTSYS)
> +                               return -ERESTARTSYS;
>                         spin_lock(&server->req_lock);
>                 } else {
>                         if (server->tcpStatus == CifsExiting) {
> @@ -537,12 +549,19 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
>                             *credits <= MAX_COMPOUND) {
>                                 spin_unlock(&server->req_lock);
>                                 cifs_num_waiters_inc(server);
> -                               rc = wait_event_killable(server->request_q,
> +                               rc = wait_event_killable_timeout(
> +                                       server->request_q,
>                                         has_credits(server, credits,
> -                                                   MAX_COMPOUND + 1));
> +                                                   MAX_COMPOUND + 1),
> +                                       t);
>                                 cifs_num_waiters_dec(server);
> -                               if (rc)
> -                                       return rc;
> +                               if (!rc) {
> +                                       cifs_dbg(VFS, "wait timed out after %d ms\n",
> +                                                timeout);
> +                                       return -ENOTSUPP;
> +                               }
> +                               if (rc == -ERESTARTSYS)
> +                                       return -ERESTARTSYS;
>                                 spin_lock(&server->req_lock);
>                                 continue;
>                         }
> @@ -569,7 +588,8 @@ static int
>  wait_for_free_request(struct TCP_Server_Info *server, const int flags,
>                       unsigned int *instance)
>  {
> -       return wait_for_free_credits(server, 1, flags, instance);
> +       return wait_for_free_credits(server, 1, -1, flags,
> +                                    instance);
>  }
>
>  int
> --
> 2.13.6
>

We may consider adding trace points for cases where we timed out.

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

--
Best regards,
Pavel Shilovsky
Pavel Shilovsky March 9, 2019, 1:06 a.m. UTC | #2
пт, 8 мар. 2019 г. в 17:03, Steve French <smfrench@gmail.com>:
>
> Any ideas how to simulate the timeout to test the proposed trace points
>

We can use Samba's max credit setting and set it to some small number.

--
Best regards,
Pavel Shilovsky
Steve French March 10, 2019, 2:21 a.m. UTC | #3
How about this to add the trace point you requested (I will send out a
patch for it on the list)

diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index b3d04018195c..8731cfa66026 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -527,6 +527,8 @@ wait_for_free_credits(struct TCP_Server_Info
*server, const int num_credits,
                                has_credits(server, credits, num_credits), t);
                        cifs_num_waiters_dec(server);
                        if (!rc) {
+                               trace_smb3_credit_timeout(server->CurrentMid,
+                                       server->hostname, num_credits);
                                cifs_dbg(VFS, "wait timed out after %d ms\n",
                                         timeout);
                                return -ENOTSUPP;
@@ -565,6 +567,9 @@ wait_for_free_credits(struct TCP_Server_Info
*server, const int num_credits,
                                        t);
                                cifs_num_waiters_dec(server);
                                if (!rc) {
+                                       trace_smb3_credit_timeout(
+                                               server->CurrentMid,
+                                               server->hostname, num_credits);
                                        cifs_dbg(VFS, "wait timed out
after %d ms\n",
                                                 timeout);
                                        return -ENOTSUPP;

On Fri, Mar 8, 2019 at 6:58 PM Pavel Shilovsky <piastryyy@gmail.com> wrote:
>
> чт, 7 мар. 2019 г. в 19:35, Ronnie Sahlberg <lsahlber@redhat.com>:
> >
> > A negative timeout is the same as the current behaviour, i.e. no timeout.
> >
> > Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> > ---
> >  fs/cifs/transport.c | 40 ++++++++++++++++++++++++++++++----------
> >  1 file changed, 30 insertions(+), 10 deletions(-)
> >
> > diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
> > index f4ec9635dab2..62c58ce80123 100644
> > --- a/fs/cifs/transport.c
> > +++ b/fs/cifs/transport.c
> > @@ -478,11 +478,18 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
> >
> >  static int
> >  wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
> > -                     const int flags, unsigned int *instance)
> > +                     const int timeout, const int flags,
> > +                     unsigned int *instance)
> >  {
> >         int rc;
> >         int *credits;
> >         int optype;
> > +       long int t;
> > +
> > +       if (timeout < 0)
> > +               t = MAX_JIFFY_OFFSET;
> > +       else
> > +               t = msecs_to_jiffies(timeout);
> >
> >         optype = flags & CIFS_OP_MASK;
> >
> > @@ -507,11 +514,16 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
> >                 if (*credits < num_credits) {
> >                         spin_unlock(&server->req_lock);
> >                         cifs_num_waiters_inc(server);
> > -                       rc = wait_event_killable(server->request_q,
> > -                               has_credits(server, credits, num_credits));
> > +                       rc = wait_event_killable_timeout(server->request_q,
> > +                               has_credits(server, credits, num_credits), t);
> >                         cifs_num_waiters_dec(server);
> > -                       if (rc)
> > -                               return rc;
> > +                       if (!rc) {
> > +                               cifs_dbg(VFS, "wait timed out after %d ms\n",
> > +                                        timeout);
> > +                               return -ENOTSUPP;
> > +                       }
> > +                       if (rc == -ERESTARTSYS)
> > +                               return -ERESTARTSYS;
> >                         spin_lock(&server->req_lock);
> >                 } else {
> >                         if (server->tcpStatus == CifsExiting) {
> > @@ -537,12 +549,19 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
> >                             *credits <= MAX_COMPOUND) {
> >                                 spin_unlock(&server->req_lock);
> >                                 cifs_num_waiters_inc(server);
> > -                               rc = wait_event_killable(server->request_q,
> > +                               rc = wait_event_killable_timeout(
> > +                                       server->request_q,
> >                                         has_credits(server, credits,
> > -                                                   MAX_COMPOUND + 1));
> > +                                                   MAX_COMPOUND + 1),
> > +                                       t);
> >                                 cifs_num_waiters_dec(server);
> > -                               if (rc)
> > -                                       return rc;
> > +                               if (!rc) {
> > +                                       cifs_dbg(VFS, "wait timed out after %d ms\n",
> > +                                                timeout);
> > +                                       return -ENOTSUPP;
> > +                               }
> > +                               if (rc == -ERESTARTSYS)
> > +                                       return -ERESTARTSYS;
> >                                 spin_lock(&server->req_lock);
> >                                 continue;
> >                         }
> > @@ -569,7 +588,8 @@ static int
> >  wait_for_free_request(struct TCP_Server_Info *server, const int flags,
> >                       unsigned int *instance)
> >  {
> > -       return wait_for_free_credits(server, 1, flags, instance);
> > +       return wait_for_free_credits(server, 1, -1, flags,
> > +                                    instance);
> >  }
> >
> >  int
> > --
> > 2.13.6
> >
>
> We may consider adding trace points for cases where we timed out.
>
> Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
>
> --
> Best regards,
> Pavel Shilovsky
diff mbox series

Patch

diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index f4ec9635dab2..62c58ce80123 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -478,11 +478,18 @@  smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
 
 static int
 wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
-		      const int flags, unsigned int *instance)
+		      const int timeout, const int flags,
+		      unsigned int *instance)
 {
 	int rc;
 	int *credits;
 	int optype;
+	long int t;
+
+	if (timeout < 0)
+		t = MAX_JIFFY_OFFSET;
+	else
+		t = msecs_to_jiffies(timeout);
 
 	optype = flags & CIFS_OP_MASK;
 
@@ -507,11 +514,16 @@  wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
 		if (*credits < num_credits) {
 			spin_unlock(&server->req_lock);
 			cifs_num_waiters_inc(server);
-			rc = wait_event_killable(server->request_q,
-				has_credits(server, credits, num_credits));
+			rc = wait_event_killable_timeout(server->request_q,
+				has_credits(server, credits, num_credits), t);
 			cifs_num_waiters_dec(server);
-			if (rc)
-				return rc;
+			if (!rc) {
+				cifs_dbg(VFS, "wait timed out after %d ms\n",
+					 timeout);
+				return -ENOTSUPP;
+			}
+			if (rc == -ERESTARTSYS)
+				return -ERESTARTSYS;
 			spin_lock(&server->req_lock);
 		} else {
 			if (server->tcpStatus == CifsExiting) {
@@ -537,12 +549,19 @@  wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
 			    *credits <= MAX_COMPOUND) {
 				spin_unlock(&server->req_lock);
 				cifs_num_waiters_inc(server);
-				rc = wait_event_killable(server->request_q,
+				rc = wait_event_killable_timeout(
+					server->request_q,
 					has_credits(server, credits,
-						    MAX_COMPOUND + 1));
+						    MAX_COMPOUND + 1),
+					t);
 				cifs_num_waiters_dec(server);
-				if (rc)
-					return rc;
+				if (!rc) {
+					cifs_dbg(VFS, "wait timed out after %d ms\n",
+						 timeout);
+					return -ENOTSUPP;
+				}
+				if (rc == -ERESTARTSYS)
+					return -ERESTARTSYS;
 				spin_lock(&server->req_lock);
 				continue;
 			}
@@ -569,7 +588,8 @@  static int
 wait_for_free_request(struct TCP_Server_Info *server, const int flags,
 		      unsigned int *instance)
 {
-	return wait_for_free_credits(server, 1, flags, instance);
+	return wait_for_free_credits(server, 1, -1, flags,
+				     instance);
 }
 
 int