From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
Stefan Reiter <s.reiter@proxmox.com>
Subject: Re: [pve-devel] [PATCH qemu-server 2/2] swtpm: wait for pidfile
Date: Mon, 18 Oct 2021 09:48:44 +0200 [thread overview]
Message-ID: <ff04065a-8fc9-1c1c-328d-5d7bd8e6714c@proxmox.com> (raw)
In-Reply-To: <20211014092849.2397997-2-s.reiter@proxmox.com>
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 <s.reiter@proxmox.com>
> ---
>
> 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;
>
next prev parent reply other threads:[~2021-10-18 7:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 9:28 [pve-devel] [PATCH qemu-server 1/2] snapshot: fix tpmstate with rbd Stefan Reiter
2021-10-14 9:28 ` [pve-devel] [PATCH qemu-server 2/2] swtpm: wait for pidfile Stefan Reiter
2021-10-18 7:48 ` Thomas Lamprecht [this message]
2021-10-18 7:46 ` [pve-devel] applied: [PATCH qemu-server 1/2] snapshot: fix tpmstate with rbd Thomas Lamprecht
2021-10-18 7:49 ` Thomas Lamprecht
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=ff04065a-8fc9-1c1c-328d-5d7bd8e6714c@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=s.reiter@proxmox.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