From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62951C433EF for ; Tue, 7 Sep 2021 22:22:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C53E861101 for ; Tue, 7 Sep 2021 22:22:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C53E861101 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:50552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjUE-0002BW-RM for qemu-devel@archiver.kernel.org; Tue, 07 Sep 2021 18:22:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj3Z-000064-VE for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:55:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj3W-0001dz-82 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:55:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631051700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oOM+yH2aoS/BsLUM3KkV/mi5LhM9wiq6wgW4sf+7SiU=; b=XLSZAqpQJ9CO/x0xru0oi48K0CqVca6Tn8la5fj6EC0f6FcX75qSSB5edOnvBeKKAyl6+l 5dp0GBjTa8xENyvYnuGaY9MsduqHLZcYqhuZgjfZiytHolx4fbiRwpS3m/M8mHo96DBqkJ g2ERC2AY+ifd4RKZVhjGV7oJ+HjCgu0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-DLKNSt7fP46P3qkAo4-exQ-1; Tue, 07 Sep 2021 17:54:57 -0400 X-MC-Unique: DLKNSt7fP46P3qkAo4-exQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E26765122; Tue, 7 Sep 2021 21:54:55 +0000 (UTC) Received: from redhat.com (ovpn-112-95.phx2.redhat.com [10.3.112.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E21219739; Tue, 7 Sep 2021 21:54:43 +0000 (UTC) Date: Tue, 7 Sep 2021 16:54:41 -0500 From: "eblake@redhat.com" To: Raphael Norwitz Subject: Re: [PATCH v2] Prevent vhost-user-blk-test hang Message-ID: <20210907215441.43xzjdv6ctkurfsq@redhat.com> References: <20210906132508.15180-1-raphael.norwitz@nutanix.com> MIME-Version: 1.0 In-Reply-To: <20210906132508.15180-1-raphael.norwitz@nutanix.com> User-Agent: NeoMutt/20210205-739-420e15 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "peter.maydell@linaro.org" , "mst@redhat.com" , "qemu-devel@nongnu.org" , "mreitz@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" , "sgarzare@redhat.com" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, Sep 06, 2021 at 01:25:20PM +0000, Raphael Norwitz wrote: > In the vhost-user-blk-test, as of now there is nothing stoping > 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 by > creating a pidfile on initialiation. This ensures that the storage-daemon > backend won't miss vhost-user messages and thereby resolves the hang. > > [1] https://lore.kernel.org/qemu-devel/CAFEAcA8kYpz9LiPNxnWJAPSjc=nv532bEdyfynaBeMeohqBp3A@mail.gmail.com/ > > Signed-off-by: Raphael Norwitz > --- > tests/qtest/vhost-user-blk-test.c | 33 ++++++++++++++++++++++++++++++- > 1 file changed, 32 insertions(+), 1 deletion(-) > > diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c > index 6f108a1b62..78140e6f28 100644 > --- a/tests/qtest/vhost-user-blk-test.c > +++ b/tests/qtest/vhost-user-blk-test.c > @@ -24,6 +24,9 @@ > #define TEST_IMAGE_SIZE (64 * 1024 * 1024) > #define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) > #define PCI_SLOT_HP 0x06 > +#define PIDFILE_RETRIES 5 > + > +const char *pidfile_format = "/tmp/daemon-%d"; Why is this not static? In fact... > > typedef struct { > pid_t pid; > @@ -885,7 +888,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, retries; > + char *daemon_pidfile_path; > gchar *img_path; > GString *storage_daemon_command = g_string_new(NULL); > QemuStorageDaemonState *qsd; > @@ -898,6 +902,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 = asprintf(&daemon_pidfile_path, pidfile_format, getpid()); ...action at a distance makes it harder for gcc to warn about bad formats. I'd just inline "/tmp/daemon-%d" here in the asprintf call, and drop pidfile_format altogether. Why are we using bare asprintf instead of glib's g_strdup_printf? > + if (err == -1) { > + fprintf(stderr, "Failed to format storage-daemon pidfile name %m"); %m in printf is a glibc-ism; not portable to non-Linux. Do we care? > + abort(); Rather than directly abort, since this is a glib test runner, is there a glib function we should be using? For example, using g_assert_cmpint((err, !=, -1)? > + } > + > for (i = 0; i < vus_instances; i++) { > int fd; > char *sock_path = create_listen_socket(&fd); > @@ -914,6 +924,9 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances, > i + 1, sock_path); > } > > + g_string_append_printf(storage_daemon_command, "--pidfile %s", Missing a space on the tail end if there are more arguments to append to the command line. > + daemon_pidfile_path); > + > g_test_message("starting vhost-user backend: %s", > storage_daemon_command->str); > pid_t pid = fork(); > @@ -930,7 +943,25 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances, > execlp("/bin/sh", "sh", "-c", storage_daemon_command->str, NULL); > exit(1); > } > + > + /* > + * Ensure the storage-daemon has come up properly before allowing the > + * test to proceed. > + */ > + retries = 0; > + while (access(daemon_pidfile_path, F_OK) != 0) { > + if (retries > PIDFILE_RETRIES) { > + fprintf(stderr, "The storage-daemon failed to come up after %d " > + "seconds - killing the test", PIDFILE_RETRIES); > + abort(); Again, would some form of g_assert*() be better than bare abort? > + } > + > + retries++; > + usleep(1000); We're inconsistent on whether qtest files use bare usleep or g_usleep. > + } > + > g_string_free(storage_daemon_command, true); > + free(daemon_pidfile_path); Do you want to unlink() the file (if it exists)? > > qsd = g_new(QemuStorageDaemonState, 1); > qsd->pid = pid; > -- > 2.20.1 > -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org