qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "eblake@redhat.com" <eblake@redhat.com>
To: Raphael Norwitz <raphael.norwitz@nutanix.com>
Cc: "peter.maydell@linaro.org" <peter.maydell@linaro.org>,
	"mst@redhat.com" <mst@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"mreitz@redhat.com" <mreitz@redhat.com>,
	"stefanha@redhat.com" <stefanha@redhat.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"sgarzare@redhat.com" <sgarzare@redhat.com>
Subject: Re: [PATCH 2/2] Prevent vhost-user-blk-test hang
Date: Fri, 27 Aug 2021 13:55:41 -0500	[thread overview]
Message-ID: <20210827185541.ehmhgoznavtyogfc@redhat.com> (raw)
In-Reply-To: <20210827164954.13951-2-raphael.norwitz@nutanix.com>

On Fri, Aug 27, 2021 at 04:50:47PM +0000, Raphael Norwitz wrote:
> In the vhost-user-blk-test, as of now there is nothing stoping

stopping

> vhost-user-blk in QEMU writing to the socket right after forking off the
> storage daemon before it has a chance to come up properly, leaving the
> test hanging forever. This intermittently hanging test has caused QEMU
> automation failures reported multiple times on the mailing list [1].
> 
> This change makes the storage-daemon notify the vhost-user-blk-test
> that it is fully initialized and ready to handle client connections via
> a pipefd before allowing the test to proceed. This ensures that the
> storage-daemon backend won't miss vhost-user messages and thereby
> resolves the hang.

As I said on patch 1, I think the proper fix here is to utilize the
--pidfile option.

> 
> [1] https://lore.kernel.org/qemu-devel/CAFEAcA8kYpz9LiPNxnWJAPSjc=nv532bEdyfynaBeMeohqBp3A@mail.gmail.com/
> 
> Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
> ---
>  tests/qtest/vhost-user-blk-test.c | 33 ++++++++++++++++++++++++++++---
>  1 file changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c
> index 6f108a1b62..b62af449df 100644
> --- a/tests/qtest/vhost-user-blk-test.c
> +++ b/tests/qtest/vhost-user-blk-test.c
> @@ -21,6 +21,8 @@
>  #include "libqos/vhost-user-blk.h"
>  #include "libqos/libqos-pc.h"
>  
> +const char *daemon_msg = "Block exports setup\n";
> +
>  #define TEST_IMAGE_SIZE         (64 * 1024 * 1024)
>  #define QVIRTIO_BLK_TIMEOUT_US  (30 * 1000 * 1000)
>  #define PCI_SLOT_HP             0x06
> @@ -885,7 +887,8 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances,
>                                   int num_queues)
>  {
>      const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary();
> -    int i;
> +    int i, err, pipe_fds[2];
> +    char buf[32] = {0};
>      gchar *img_path;
>      GString *storage_daemon_command = g_string_new(NULL);
>      QemuStorageDaemonState *qsd;
> @@ -898,6 +901,12 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances,
>              " -object memory-backend-memfd,id=mem,size=256M,share=on "
>              " -M memory-backend=mem -m 256M ");
>  
> +    err = pipe(pipe_fds);
> +    if (err != 0) {
> +        fprintf(stderr, "start_vhost_user_blk: pipe() failed %m\n");
> +        abort();
> +    }

Instead of setting up a pipe()...

> +
>      for (i = 0; i < vus_instances; i++) {
>          int fd;
>          char *sock_path = create_listen_socket(&fd);
> @@ -914,22 +923,40 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances,
>                                 i + 1, sock_path);
>      }
>  
> +    g_string_append_printf(storage_daemon_command, "--printset");

...change this to request the --pidfile option...

> +
>      g_test_message("starting vhost-user backend: %s",
>                     storage_daemon_command->str);
> +
>      pid_t pid = fork();
>      if (pid == 0) {
> +        close(pipe_fds[0]);
> +
>          /*
>           * Close standard file descriptors so tap-driver.pl pipe detects when
>           * our parent terminates.
>           */
>          close(0);
> -        close(1);
>          open("/dev/null", O_RDONLY);
> -        open("/dev/null", O_WRONLY);
> +        close(1);
> +        dup2(pipe_fds[1], 1);
>  
>          execlp("/bin/sh", "sh", "-c", storage_daemon_command->str, NULL);
>          exit(1);
>      }
> +
> +    close(pipe_fds[1]);
> +
> +    err = read(pipe_fds[0], buf, 20);
> +    if (err < 0) {
> +        fprintf(stderr, "Failed to read from storage-daemon pipe %m\n");
> +        abort();
> +    } else if (strcmp(buf, daemon_msg) != 0) {
> +        fprintf(stderr, "qemu-storage-daemon did not write expected messaage "
> +                "to the pipe. Total bytes read: %d. Got: %s\n", err, buf);
> +        abort();
> +    }

...and instead of trying to read() from a pipe, you instead wait until
the pid file exists.

> +
>      g_string_free(storage_daemon_command, true);
>  
>      qsd = g_new(QemuStorageDaemonState, 1);
> -- 
> 2.20.1
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2021-08-27 18:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 16:50 [PATCH 1/2] storage-daemon: add opt to print when initialized Raphael Norwitz
2021-08-27 16:50 ` [PATCH 2/2] Prevent vhost-user-blk-test hang Raphael Norwitz
2021-08-27 18:55   ` eblake [this message]
2021-08-27 18:51 ` [PATCH 1/2] storage-daemon: add opt to print when initialized eblake
2021-08-30 15:56   ` Raphael Norwitz
2021-08-30 16:05     ` eblake
2021-08-30 21:51       ` Michael S. Tsirkin

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=20210827185541.ehmhgoznavtyogfc@redhat.com \
    --to=eblake@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    --cc=sgarzare@redhat.com \
    --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 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).