From: Benjamin McGuire <jaminmc@gmail.com>
To: Dominik Csapak <d.csapak@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [PATCH qemu-server v3 3/3] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds
Date: Wed, 15 Apr 2026 03:14:56 -0400 [thread overview]
Message-ID: <13CB46EB-46CB-481A-A626-1EEB6CBFFEBF@gmail.com> (raw)
In-Reply-To: <20260226140752.1792378-4-d.csapak@proxmox.com>
Tested-by: Benjamin McGuire <jaminmc@gmail.com>
I’ve applied all three patches to the latest master. Here’s the commit: 473b67746639c4859f2a6838e4b8d05c7a9a3f5a.
I’ve tested it with USB passthrough, shutting down the OS from within the VM, and the hook script works for all the VMs I have. I’ve tested it with Windows 11, Fedora, Ubuntu, macOS Mojave, and macOS Tahoe. My Vega 64, USB keyboard, and mouse were all passed through. The hook script now correctly runs in the cleanup stage, which fixes #7119.
— Benjamin
> On Feb 26, 2026, at 8:52 AM, Dominik Csapak <d.csapak@proxmox.com> wrote:
>
> 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>
> ---
> src/PVE/CLI/qm.pm | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
> index 6aff5b7a..ee3ccedd 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);
>
> # With a stop mode backup, we might run here into a running vm with a backup
> # lock, but this already did the cleanup and is an expected state, so abort
> @@ -1109,7 +1109,19 @@ __PACKAGE__->register_method({
> die "skipping cleanup - 'backup' lock is present and vm is running again\n"
> if $pid && $clean && $conf->{lock} && $conf->{lock} eq 'backup';
>
> - die "vm still running\n" if $pid;
> + # wait for some time until the QEMU process exits after the QMP
> + # 'SHUTDOWN' event, since this might not be instant
> + my $timeout = 30;
> + my $starttime = time();
> + warn "QEMU process $pid for VM $vmid still running (or newly started)\n"
> + if $pid;
> +
> + while ($pid && (time() - $starttime) < $timeout) {
> + sleep(1);
> + $pid = PVE::QemuServer::check_running($vmid);
> + }
> +
> + die "vm still running after timeout - aborting cleanup\n" if $pid;
>
> # Rollback already does cleanup when preparing and afterwards temporarily drops the
> # lock on the configuration file to rollback the volumes. Deactivating volumes here
> --
> 2.47.3
>
>
>
>
>
next prev parent reply other threads:[~2026-04-15 7:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 13:51 [PATCH qemu-server v3 0/3] improve guest cleanup handling Dominik Csapak
2026-02-26 13:52 ` [PATCH qemu-server v3 1/3] cleanup: refactor to make cleanup flow consistent Dominik Csapak
2026-02-27 11:44 ` Dominik Csapak
2026-02-26 13:52 ` [PATCH qemu-server v3 2/3] qm cleanup: die early when encountering a running stop mode backup Dominik Csapak
2026-02-26 13:52 ` [PATCH qemu-server v3 3/3] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds Dominik Csapak
2026-04-15 7:14 ` Benjamin McGuire [this message]
2026-04-14 11:42 ` [PATCH qemu-server v3 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=13CB46EB-46CB-481A-A626-1EEB6CBFFEBF@gmail.com \
--to=jaminmc@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.