From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 27EB076247 for ; Mon, 18 Oct 2021 09:48:47 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 15CC51E26F for ; Mon, 18 Oct 2021 09:48:47 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A33961E261 for ; Mon, 18 Oct 2021 09:48:45 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6FFA345D75 for ; Mon, 18 Oct 2021 09:48:45 +0200 (CEST) Message-ID: Date: Mon, 18 Oct 2021 09:48:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:94.0) Gecko/20100101 Thunderbird/94.0 Content-Language: en-US To: Proxmox VE development discussion , Stefan Reiter References: <20211014092849.2397997-1-s.reiter@proxmox.com> <20211014092849.2397997-2-s.reiter@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20211014092849.2397997-2-s.reiter@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.202 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pve-devel] [PATCH qemu-server 2/2] swtpm: wait for pidfile X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2021 07:48:47 -0000 On 14.10.21 11:28, Stefan Reiter wrote: > swtpm may take a little bit to daemonize, so the pidfile might not be > available right after run_command. Causes an ugly warning about using an > undefined value in a match, so wait up to 5s for it to appear. > > Note that in testing this loop only ever got to the first or second > iteration, so I believe the timeout duration should be more than enough. > > Also add a missing 'usleep' import, 'usleep' was used before but never > imported, apparently the other case never got triggered... > > Signed-off-by: Stefan Reiter > --- > > Triggered during rollback testing, potentially due to extra load. Didn't cause > any failure (as long as the VM starts fine it's all good), but looks ugly in the > log and may cause lingering instances if QEMU fails afterward. > > PVE/QemuServer.pm | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index d5dfdbb..7a7cdb0 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -22,7 +22,7 @@ use JSON; > use MIME::Base64; > use POSIX; > use Storable qw(dclone); > -use Time::HiRes qw(gettimeofday); > +use Time::HiRes qw(gettimeofday usleep); > use URI::Escape; > use UUID; > > @@ -3059,6 +3059,14 @@ sub start_swtpm { > push @$emulator_cmd, "--tpm2" if $tpm->{version} eq 'v2.0'; > run_command($emulator_cmd, outfunc => sub { print $1; }); > > + # swtpm may take a bit to start before daemonizing, wait up to 5s for pid > + my $tries = 100; > + while (! -e $paths->{pid}) { > + usleep(50000); > + die "failed to start swtpm: pid file '$paths->{pid}' wasn't created.\n" > + if --$tries == 0; I moved the die before the sleep, as else we'd wait extra 50 ms if we'd die anyway. > + } > + > # return untainted PID of swtpm daemon so it can be killed on error > file_read_firstline($paths->{pid}) =~ m/(\d+)/; > return $1; >