From: Fiona Ebner <f.ebner@proxmox.com>
To: Dominik Csapak <d.csapak@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH qemu-server v4 3/3] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds
Date: Fri, 15 May 2026 12:14:07 +0200 [thread overview]
Message-ID: <d3208881-cb7e-454d-89d6-71e1a893676b@proxmox.com> (raw)
In-Reply-To: <20260515100842.1980636-4-d.csapak@proxmox.com>
Am 15.05.26 um 12:08 PM schrieb Dominik Csapak:
> When qmeventd detects a vm exiting, it starts 'qm cleanup'.
>
> Since the vm process exits is sometimes not instant, wait up to 30
> seconds here to start the cleanup process instead of immediately
> aborting if the pid still exits. This prevented executing the hookscript
> on the 'post-stop' phase when either
> * the cleanup mechanism is still the old one
> * the guest was powered down from inside, not via the API
>
> This can be reproduced by e.g. passing through a usb device, which
> delays the qemu process exit for a few seconds (for most devices).
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from v3:
> * adapt to indentation change of previous patch
> * use non-deprecated vm_running_locally helper
> * improve warning message
>
> src/PVE/CLI/qm.pm | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
> index 3c9e8812..a35d9f74 100755
> --- a/src/PVE/CLI/qm.pm
> +++ b/src/PVE/CLI/qm.pm
> @@ -1101,7 +1101,7 @@ __PACKAGE__->register_method({
> 60,
> sub {
> my $conf = PVE::QemuConfig->load_config($vmid);
> - my $pid = PVE::QemuServer::check_running($vmid);
> + my $pid = PVE::QemuServer::Helpers::vm_running_locally($vmid);
>
> if ($pid) {
> # With a stop mode backup, we might run here into a running vm with a backup
> @@ -1110,7 +1110,21 @@ __PACKAGE__->register_method({
> die "skipping cleanup - 'backup' lock is present and vm is running again\n"
> if $clean && $conf->{lock} && $conf->{lock} eq 'backup';
>
> - die "vm still running\n";
> + # wait for some time until the QEMU process exits after the QMP
> + # 'SHUTDOWN' event, since this might not be instant
> +
> + my $timeout = 30;
> + warn
> + "QEMU process $pid for VM $vmid still running (or newly started), waiting up to $timeout seconds for it to exit\n";
See my reply in v3:
https://lore.proxmox.com/pve-devel/a6b4e32d-70cf-4c1a-b389-8dfecca84e89@proxmox.com/
> + my $starttime = time();
> +
> + while ($pid && (time() - $starttime) < $timeout) {
> + sleep(1);
> + $pid = PVE::QemuServer::Helpers::vm_running_locally($vmid);
> + }
> +
> + die "aborting cleanup, VM is still running after $timeout seconds\n"
> + if $pid;
> }
>
> # Rollback already does cleanup when preparing and afterwards temporarily drops the
next prev parent reply other threads:[~2026-05-15 10:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 10:04 [PATCH qemu-server v4 0/3] improve guest cleanup handling Dominik Csapak
2026-05-15 10:04 ` [PATCH qemu-server v4 1/3] cleanup: refactor to make cleanup flow consistent Dominik Csapak
2026-05-15 10:04 ` [PATCH qemu-server v4 2/3] qm cleanup: die early when encountering a running stop mode backup Dominik Csapak
2026-05-15 10:04 ` [PATCH qemu-server v4 3/3] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds Dominik Csapak
2026-05-15 10:14 ` Fiona Ebner [this message]
2026-05-15 12:35 ` superseded: [PATCH qemu-server v4 0/3] improve guest cleanup handling Dominik Csapak
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=d3208881-cb7e-454d-89d6-71e1a893676b@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=d.csapak@proxmox.com \
--cc=pve-devel@lists.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