From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 2B55D1FF13A for ; Wed, 15 Apr 2026 09:42:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0DEB2733B; Wed, 15 Apr 2026 09:42:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776237308; x=1776842108; darn=lists.proxmox.com; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yQUbhu2X0zJgmXPul49U4Y5zVqVU/UHIb9L0b2cXw+c=; b=pLRVIxmnbAKDMnPxjzu//OZnFpjhlo2zAtoHSSLvtLwaRv9refMtO0+AofTuUfj9So CgrTWi/zQ2GRlpzbU1WZdYtvGcopbW+lLk0JGGW1uB1IHt3sd+eGdLt5QIQ8fRkAj6Kr WVE7eXu3hQjipYfGNNBC+BC6SaWhybNWmBFP0u2mvc/t9ZGNVMQRg15SZDdz0zAruInI bdAFNqbAcUBgE79OfrM0tZN5yBbPPMDoaqnHcX3zFA55LntpHFt2uQ68i3/KFiwdCoZ2 /2EaBYxnTA8sDPbCy+oG1bAN6Bd5vFG3+rsc6EyEeR//D+LmA9I0lnVn6whwuL8QoPqQ ronQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776237308; x=1776842108; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yQUbhu2X0zJgmXPul49U4Y5zVqVU/UHIb9L0b2cXw+c=; b=rJMakzbk6v7BSbAmccAmaje6P79hGZcnB0Tm5qDhUn+ktqxRX7iZ9u//Z0GH4dWAHV 5FjvPm6bis31udOavoEOE+N207jRCh+4vZwA4/H3kFHqxqB8JbDnx8Wqby8jC18mz8CY FpyJoH8DLhJdXbF1g6r6/QtIiOkFIrk1e8CR49ZdSjefMLcZ6QIWM34xFBcZT+vt+TXJ UP77ySvF4sAy5MlF3a1atUryxRmGZ5Shzo+2+I53GSXUI8xQAEj494FvYHGU2/nAR5/+ EQ+EbHsyDkFMqLWYor7Pq4bxAl8MR8bueEYc8Ul70jfsNi+o4KeXzRksel88HzrL/lZR 6jXw== X-Gm-Message-State: AOJu0YxT2cXHeTiYmnIchZYQirk74dIcc9U2qJBpnBhYm+mYlw9BOb+t 4M8ljoP+yCISKI0fjQ37OuhZFiuz/Irf31A6QVeBm61fVYSwNoiOMJdR X-Gm-Gg: AeBDieuRBBRzBPLMPLr0E58nGg153mXCS4qqPM9XGAnj6E9M974zQt+0V15rzXXvmd5 iR5iHVBkcGiKurznraYd1GnVz0OebNc2MTXEyTjTG2cMBlBmi3aqkdmUBM95gpZS2kWf9AA40x5 MyJwSc66UTI0Y8MQIA5UkhHmK7e3Zpl+pagxsQd43oaALLDSnreUnjvA15+sAQxs/fwKcBATEav n4aUQX2tPG5ybkPHurJYLAZSDKJOKJxteQ1b7f3hq1bsG3KnhgCjMuLrsALPu5Lur6UiBZ9mf0N dcJr0bHGayG2Kv8/Eu5jGIHyA8g5WlUNMZtFOJxX0mqGgTelLfRJy/6ahSEmhXAzoI6Py9fyxLK zkqNlMKQ87UI9Xy5DJhJlWrFwgAJs4NV3hZ033y9XUXcgoweO145yY4tiOIpSJGO/jIxl7QasvU TMnTTs9kLd5Rh3TCWYYoakvzbIbBqYnjA7uXR8JsklHh+8rBqfJLvR X-Received: by 2002:a05:690c:89:b0:7b4:ad41:483c with SMTP id 00721157ae682-7b4ad415648mr73527277b3.30.1776237308025; Wed, 15 Apr 2026 00:15:08 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: [PATCH qemu-server v3 3/3] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds From: Benjamin McGuire In-Reply-To: <20260226140752.1792378-4-d.csapak@proxmox.com> Date: Wed, 15 Apr 2026 03:14:56 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <13CB46EB-46CB-481A-A626-1EEB6CBFFEBF@gmail.com> References: <20260226140752.1792378-1-d.csapak@proxmox.com> <20260226140752.1792378-4-d.csapak@proxmox.com> To: Dominik Csapak X-Mailer: Apple Mail (2.3864.400.21) X-SPAM-LEVEL: Spam detection results: 0 BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy FREEMAIL_FROM 0.001 Sender email is commonly abused enduser mail provider RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record X-MailFrom: jaminmc@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation Message-ID-Hash: IWKUIIEGEAIZJ7LDFHTMUJRKH3OBQ3F7 X-Message-ID-Hash: IWKUIIEGEAIZJ7LDFHTMUJRKH3OBQ3F7 X-Mailman-Approved-At: Wed, 15 Apr 2026 09:42:40 +0200 CC: pve-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Tested-by: Benjamin McGuire I=E2=80=99ve applied all three patches to the latest master. Here=E2=80=99= s the commit: 473b67746639c4859f2a6838e4b8d05c7a9a3f5a. I=E2=80=99ve 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=E2=80=99= 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. =E2=80=94 Benjamin > On Feb 26, 2026, at 8:52=E2=80=AFAM, Dominik Csapak = wrote: >=20 > When qmeventd detects a vm exiting, it starts 'qm cleanup'. >=20 > 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 >=20 > 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). >=20 > Signed-off-by: Dominik Csapak > --- > src/PVE/CLI/qm.pm | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) >=20 > 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 =3D PVE::QemuConfig->load_config($vmid); > - my $pid =3D PVE::QemuServer::check_running($vmid); > + my $pid =3D = PVE::QemuServer::Helpers::vm_running_locally($vmid); >=20 > # 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'; >=20 > - 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 =3D 30; > + my $starttime =3D time(); > + warn "QEMU process $pid for VM $vmid still running = (or newly started)\n" > + if $pid; > + > + while ($pid && (time() - $starttime) < $timeout) { > + sleep(1); > + $pid =3D PVE::QemuServer::check_running($vmid); > + } > + > + die "vm still running after timeout - aborting = cleanup\n" if $pid; >=20 > # Rollback already does cleanup when preparing and = afterwards temporarily drops the > # lock on the configuration file to rollback the = volumes. Deactivating volumes here > --=20 > 2.47.3 >=20 >=20 >=20 >=20 >=20