All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Hani Benhabiles <kroosec@gmail.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, kwolf@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-trivial] [PATCH 1/2] nbd: Close socket on negotiation failure.
Date: Tue, 13 May 2014 11:07:56 +0200	[thread overview]
Message-ID: <5371E0EC.5000406@redhat.com> (raw)
In-Reply-To: <1399937716-6086-1-git-send-email-kroosec@gmail.com>

Il 13/05/2014 01:35, Hani Benhabiles ha scritto:
> Otherwise, the nbd client may hang waiting for the server response.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
>
> Quick method to trigger such behaviour:
>
> (qemu) nbd_server_start localhost:10809
> (qemu) nbd_server_add sd0
> $ nbd-client localhost 10809 -name AAAA /dev/nbd0
> Negotiation: ..
>
> (Client will hang indefinitely.)
>
>  blockdev-nbd.c | 4 ++--
>  qemu-nbd.c     | 4 +++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/blockdev-nbd.c b/blockdev-nbd.c
> index 922cf56..b60b66d 100644
> --- a/blockdev-nbd.c
> +++ b/blockdev-nbd.c
> @@ -27,8 +27,8 @@ static void nbd_accept(void *opaque)
>      socklen_t addr_len = sizeof(addr);
>
>      int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len);
> -    if (fd >= 0) {
> -        nbd_client_new(NULL, fd, nbd_client_put);
> +    if (fd >= 0 && !nbd_client_new(NULL, fd, nbd_client_put)) {
> +        close(fd);
>      }
>  }
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index eed79fa..f70e4b0 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -369,8 +369,10 @@ static void nbd_accept(void *opaque)
>          return;
>      }
>
> -    if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) {
> +    if (nbd_client_new(exp, fd, nbd_client_closed)) {
>          nb_fds++;
> +    } else {
> +        close(fd);
>      }
>  }
>
>

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Michael, can you queue this yourself?

Paolo


WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: Hani Benhabiles <kroosec@gmail.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, kwolf@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/2] nbd: Close socket on negotiation failure.
Date: Tue, 13 May 2014 11:07:56 +0200	[thread overview]
Message-ID: <5371E0EC.5000406@redhat.com> (raw)
In-Reply-To: <1399937716-6086-1-git-send-email-kroosec@gmail.com>

Il 13/05/2014 01:35, Hani Benhabiles ha scritto:
> Otherwise, the nbd client may hang waiting for the server response.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
>
> Quick method to trigger such behaviour:
>
> (qemu) nbd_server_start localhost:10809
> (qemu) nbd_server_add sd0
> $ nbd-client localhost 10809 -name AAAA /dev/nbd0
> Negotiation: ..
>
> (Client will hang indefinitely.)
>
>  blockdev-nbd.c | 4 ++--
>  qemu-nbd.c     | 4 +++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/blockdev-nbd.c b/blockdev-nbd.c
> index 922cf56..b60b66d 100644
> --- a/blockdev-nbd.c
> +++ b/blockdev-nbd.c
> @@ -27,8 +27,8 @@ static void nbd_accept(void *opaque)
>      socklen_t addr_len = sizeof(addr);
>
>      int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len);
> -    if (fd >= 0) {
> -        nbd_client_new(NULL, fd, nbd_client_put);
> +    if (fd >= 0 && !nbd_client_new(NULL, fd, nbd_client_put)) {
> +        close(fd);
>      }
>  }
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index eed79fa..f70e4b0 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -369,8 +369,10 @@ static void nbd_accept(void *opaque)
>          return;
>      }
>
> -    if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) {
> +    if (nbd_client_new(exp, fd, nbd_client_closed)) {
>          nb_fds++;
> +    } else {
> +        close(fd);
>      }
>  }
>
>

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Michael, can you queue this yourself?

Paolo

  parent reply	other threads:[~2014-05-13  9:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-12 23:35 [Qemu-trivial] [PATCH 1/2] nbd: Close socket on negotiation failure Hani Benhabiles
2014-05-12 23:35 ` [Qemu-devel] " Hani Benhabiles
2014-05-12 23:35 ` [Qemu-trivial] [PATCH 2/2] nbd: Miscellaneous typo fixes Hani Benhabiles
2014-05-12 23:35   ` [Qemu-devel] " Hani Benhabiles
2014-05-13  9:08   ` [Qemu-trivial] " Paolo Bonzini
2014-05-13  9:08     ` [Qemu-devel] " Paolo Bonzini
2014-05-14 12:46   ` [Qemu-trivial] " Stefan Hajnoczi
2014-05-14 12:46     ` Stefan Hajnoczi
2014-05-17  8:02   ` [Qemu-trivial] " Michael Tokarev
2014-05-17  8:02     ` [Qemu-devel] " Michael Tokarev
2014-05-13  9:07 ` Paolo Bonzini [this message]
2014-05-13  9:07   ` [Qemu-devel] [PATCH 1/2] nbd: Close socket on negotiation failure Paolo Bonzini
2014-05-17  8:02 ` [Qemu-trivial] " Michael Tokarev
2014-05-17  8:02   ` [Qemu-devel] " Michael Tokarev

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=5371E0EC.5000406@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kroosec@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.