linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Shilovsky <piastryyy@gmail.com>
To: linux-cifs <linux-cifs@vger.kernel.org>
Subject: Re: [PATCH 10/23] CIFS: Mask signals during sock_sendmsg()
Date: Tue, 5 Mar 2019 15:53:52 -0800	[thread overview]
Message-ID: <CAKywueQ7NeSRHOmRRhdetYBrGM5truJNJqJ8xukRfX2J3b9KOQ@mail.gmail.com> (raw)
In-Reply-To: <1549051452-5968-12-git-send-email-pshilov@microsoft.com>

пт, 1 февр. 2019 г. в 12:04, Pavel Shilovsky <piastryyy@gmail.com>:
>
> We don't want to break a session if we receive a signal during
> sending a packet through the network. Fix it by masking signals
> during execution of sock_sendmsg() and then checking for pending
> signals.
>
> Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
> Signed-off-by: Steve French <stfrench@microsoft.com>
> ---
>  fs/cifs/transport.c | 33 ++++++++++++++++++++++++++++++---
>  1 file changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
> index 53532bd..eff9e3c 100644
> --- a/fs/cifs/transport.c
> +++ b/fs/cifs/transport.c
> @@ -33,6 +33,7 @@
>  #include <linux/uaccess.h>
>  #include <asm/processor.h>
>  #include <linux/mempool.h>
> +#include <linux/signal.h>
>  #include "cifspdu.h"
>  #include "cifsglob.h"
>  #include "cifsproto.h"
> @@ -176,6 +177,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,
>         int rc = 0;
>         int retries = 0;
>         struct socket *ssocket = server->ssocket;
> +       sigset_t mask, oldmask;
>
>         *sent = 0;
>
> @@ -189,6 +191,28 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,
>                 smb_msg->msg_flags = MSG_NOSIGNAL;
>
>         while (msg_data_left(smb_msg)) {
> +               if (signal_pending(current)) {
> +                       /* Should we stop sending if we receive SIG_KILL? */
> +                       if (__fatal_signal_pending(current))
> +                               cifs_dbg(FYI, "SIG_KILL signal is pending\n");
> +
> +                       /* It is safe to return if we haven't sent anything */
> +                       if (*sent == 0) {
> +                               cifs_dbg(FYI, "signal is pending before sending any data\n");
> +                               return -EINTR;
> +                       }
> +               }
> +
> +               /*
> +                * We should not allow signals to interrupt the network send
> +                * because any partial send will cause session reconnects thus
> +                * increasing latency of system calls and overload a server
> +                * with unnecessary requests.
> +                */
> +
> +               sigfillset(&mask);
> +               sigprocmask(SIG_BLOCK, &mask, &oldmask);
> +
>                 /*
>                  * If blocking send, we try 3 times, since each can block
>                  * for 5 seconds. For nonblocking  we have to try more
> @@ -208,20 +232,23 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,
>                  * reconnect which may clear the network problem.
>                  */
>                 rc = sock_sendmsg(ssocket, smb_msg);
> +
> +               sigprocmask(SIG_SETMASK, &oldmask, NULL);
> +
>                 if (rc == -EAGAIN) {
>                         retries++;
>                         if (retries >= 14 ||
>                             (!server->noblocksnd && (retries > 2))) {
>                                 cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n",
>                                          ssocket);
> -                               return -EAGAIN;
> +                               return signal_pending(current) ? -EINTR : rc;
>                         }
>                         msleep(1 << retries);
>                         continue;
>                 }
>
>                 if (rc < 0)
> -                       return rc;
> +                       return signal_pending(current) ? -EINTR : rc;
>
>                 if (rc == 0) {
>                         /* should never happen, letting socket clear before
> @@ -235,7 +262,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,
>                 *sent += rc;
>                 retries = 0; /* in case we get ENOSPC on the next send */
>         }
> -       return 0;
> +       return signal_pending(current) ? -EINTR : 0;
>  }
>
>  unsigned long
> --
> 2.7.4
>

Please ignore this one. I posted the new version of it:

CIFS: Mask off signals when sending SMB packets

--
Best regards,
Pavel Shilovsky

           reply	other threads:[~2019-03-05 23:54 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1549051452-5968-12-git-send-email-pshilov@microsoft.com>]

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=CAKywueQ7NeSRHOmRRhdetYBrGM5truJNJqJ8xukRfX2J3b9KOQ@mail.gmail.com \
    --to=piastryyy@gmail.com \
    --cc=linux-cifs@vger.kernel.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 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).