* [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed
@ 2026-03-30 11:09 Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 1/2] hotplug pending: only check if USB devices are left when one was unplugged Fiona Ebner
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Fiona Ebner @ 2026-03-30 11:09 UTC (permalink / raw)
To: pve-devel
There is a report in the enterprise support about Veeam failing to set
the 'lock' property in the VM configuration, because they are blocking
the QMP socket. The proper fix would be for them to not block the QMP
socket (at least not while interacting with our API), but there still
is an improvement to be made on the Proxmox VE side, which is to avoid
doing QMP commands related to USB hotplug if they are not actually
needed.
qemu-server:
Fiona Ebner (2):
hotplug pending: only check if USB devices are left when one was
unplugged
hotplug pending: only check for USB hoptplug support when actually
needed
src/PVE/QemuServer.pm | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
Summary over all repositories:
1 files changed, 30 insertions(+), 11 deletions(-)
--
Generated by git-murpp 0.5.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH qemu-server 1/2] hotplug pending: only check if USB devices are left when one was unplugged
2026-03-30 11:09 [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed Fiona Ebner
@ 2026-03-30 11:09 ` Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 2/2] hotplug pending: only check for USB hoptplug support when actually needed Fiona Ebner
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Fiona Ebner @ 2026-03-30 11:09 UTC (permalink / raw)
To: pve-devel
The call to unplug the 'xhci' controller would happen each time as
part of the vmconfig_hotplug_pending() call as long as the VM did not
have any USB devices and as long as it had a new enough version to
support USB hotplug, even if the actual changes have nothing to do
with USB.
Only check if there are any USB devices left if one was unplugged. In
particular, this avoid issuing superfluous QMP commands (via
vm_devices_list()) to check for the presence of the 'xhci' controller
for unrelated changes.
Previously, if an 'xhci' was added as part of a failing USB hotplug in
qemu_usb_hotplug(), it would be removed again implicitly by the check
at the end of vmconfig_hotplug_pending() that is now guarded. Add
explicitly error handling to remove the added 'xhci' controller again
in the error handling case in qemu_usb_hotplug() to avoid a left-over.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/QemuServer.pm | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 5acd1ac8..26560122 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -4245,15 +4245,26 @@ sub qemu_usb_hotplug {
vm_deviceunplug($vmid, $conf, $deviceid);
# check if xhci controller is necessary and available
+ my $added_xhci;
my $devicelist = vm_devices_list($vmid);
if (!$devicelist->{xhci}) {
my $pciaddr = print_pci_addr("xhci", undef, $arch);
qemu_deviceadd($vmid, PVE::QemuServer::USB::print_qemu_xhci_controller($pciaddr));
+ $added_xhci = 1;
}
# add the new one
- vm_deviceplug($storecfg, $conf, $vmid, $deviceid, $device, $arch, $machine_type);
+ eval { vm_deviceplug($storecfg, $conf, $vmid, $deviceid, $device, $arch, $machine_type); };
+ if (my $err = $@) {
+ if ($added_xhci) {
+ eval { vm_deviceunplug($vmid, $conf, 'xhci'); };
+ warn "failed to unplug xhci controller - $@" if $@;
+ }
+ die $err;
+ }
+
+ return;
}
sub qemu_cpu_hotplug {
@@ -4650,6 +4661,7 @@ sub vmconfig_hotplug_pending {
my $version = extract_version($machine_type, get_running_qemu_version($vmid));
my $hotplug_features =
parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
+ my $usb_was_unplugged = 0;
my $usb_hotplug =
$hotplug_features->{usb}
&& min_version($version, 7, 1)
@@ -4680,6 +4692,7 @@ sub vmconfig_hotplug_pending {
die "skip\n" if !$usb_hotplug;
vm_deviceunplug($vmid, $conf, "usbredirdev$index"); # if it's a spice port
vm_deviceunplug($vmid, $conf, $opt);
+ $usb_was_unplugged = 1;
} elsif ($opt eq 'vcpus') {
die "skip\n" if !$hotplug_features->{cpu};
qemu_cpu_hotplug($vmid, $conf, undef);
@@ -4852,7 +4865,7 @@ sub vmconfig_hotplug_pending {
}
# unplug xhci controller if no usb device is left
- if ($usb_hotplug) {
+ if ($usb_was_unplugged) {
my $has_usb = 0;
for (my $i = 0; $i < $PVE::QemuServer::USB::MAX_USB_DEVICES; $i++) {
next if !defined($conf->{"usb$i"});
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH qemu-server 2/2] hotplug pending: only check for USB hoptplug support when actually needed
2026-03-30 11:09 [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 1/2] hotplug pending: only check if USB devices are left when one was unplugged Fiona Ebner
@ 2026-03-30 11:09 ` Fiona Ebner
2026-03-31 14:29 ` [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if " Manuel Federanko
2026-03-31 18:40 ` applied: " Thomas Lamprecht
3 siblings, 0 replies; 5+ messages in thread
From: Fiona Ebner @ 2026-03-30 11:09 UTC (permalink / raw)
To: pve-devel
In particular, this makes the variables $ostype and $version more
local and, for VMs without and explicit machine version, avoids a
'query-version' QMP call when not actually needed.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/QemuServer.pm | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 26560122..da2379e0 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -4657,16 +4657,22 @@ sub vmconfig_hotplug_pending {
PVE::QemuConfig->write_config($vmid, $conf);
}
- my $ostype = $conf->{ostype};
- my $version = extract_version($machine_type, get_running_qemu_version($vmid));
my $hotplug_features =
parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
+
+ my $usb_hotplug;
my $usb_was_unplugged = 0;
- my $usb_hotplug =
- $hotplug_features->{usb}
- && min_version($version, 7, 1)
- && defined($ostype)
- && ($ostype eq 'l26' || windows_version($ostype) > 7);
+ my $is_usb_hotplug_supported = sub {
+ return $usb_hotplug if defined($usb_hotplug);
+ my $ostype = $conf->{ostype};
+ my $version = extract_version($machine_type, get_running_qemu_version($vmid));
+ $usb_hotplug =
+ $hotplug_features->{usb}
+ && min_version($version, 7, 1)
+ && defined($ostype)
+ && ($ostype eq 'l26' || windows_version($ostype) > 7) ? 1 : 0;
+ return $usb_hotplug;
+ };
my $cgroup = PVE::QemuServer::CGroup->new($vmid);
my $pending_delete_hash = PVE::QemuConfig->parse_pending_delete($conf->{pending}->{delete});
@@ -4689,7 +4695,7 @@ sub vmconfig_hotplug_pending {
}
} elsif ($opt =~ m/^usb(\d+)$/) {
my $index = $1;
- die "skip\n" if !$usb_hotplug;
+ die "skip\n" if !$is_usb_hotplug_supported->();
vm_deviceunplug($vmid, $conf, "usbredirdev$index"); # if it's a spice port
vm_deviceunplug($vmid, $conf, $opt);
$usb_was_unplugged = 1;
@@ -4760,7 +4766,7 @@ sub vmconfig_hotplug_pending {
}
} elsif ($opt =~ m/^usb(\d+)$/) {
my $index = $1;
- die "skip\n" if !$usb_hotplug;
+ die "skip\n" if !$is_usb_hotplug_supported->();
my $d = eval { parse_property_string('pve-qm-usb', $value) };
my $id = $opt;
if ($d->{host} =~ m/^spice$/i) {
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed
2026-03-30 11:09 [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 1/2] hotplug pending: only check if USB devices are left when one was unplugged Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 2/2] hotplug pending: only check for USB hoptplug support when actually needed Fiona Ebner
@ 2026-03-31 14:29 ` Manuel Federanko
2026-03-31 18:40 ` applied: " Thomas Lamprecht
3 siblings, 0 replies; 5+ messages in thread
From: Manuel Federanko @ 2026-03-31 14:29 UTC (permalink / raw)
To: pve-devel
On 2026-03-30 1:09 PM, Fiona Ebner wrote:
> There is a report in the enterprise support about Veeam failing to set
> the 'lock' property in the VM configuration, because they are blocking
> the QMP socket. The proper fix would be for them to not block the QMP
> socket (at least not while interacting with our API), but there still
> is an improvement to be made on the Proxmox VE side, which is to avoid
> doing QMP commands related to USB hotplug if they are not actually
> needed.
>
> qemu-server:
>
> Fiona Ebner (2):
> hotplug pending: only check if USB devices are left when one was
> unplugged
> hotplug pending: only check for USB hoptplug support when actually
> needed
>
> src/PVE/QemuServer.pm | 41 ++++++++++++++++++++++++++++++-----------
> 1 file changed, 30 insertions(+), 11 deletions(-)
>
>
> Summary over all repositories:
> 1 files changed, 30 insertions(+), 11 deletions(-)
>
Thanks!
Tested this by blocking the QMP socket and acquiring a lock on the
guest afterwards, also tried to add a USB device while blocking the
socket, which times out as expected.
Tested-by: Manuel Federanko <m.federanko@proxmox.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* applied: [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed
2026-03-30 11:09 [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed Fiona Ebner
` (2 preceding siblings ...)
2026-03-31 14:29 ` [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if " Manuel Federanko
@ 2026-03-31 18:40 ` Thomas Lamprecht
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2026-03-31 18:40 UTC (permalink / raw)
To: pve-devel, Fiona Ebner
On Mon, 30 Mar 2026 13:09:42 +0200, Fiona Ebner wrote:
> There is a report in the enterprise support about Veeam failing to set
> the 'lock' property in the VM configuration, because they are blocking
> the QMP socket. The proper fix would be for them to not block the QMP
> socket (at least not while interacting with our API), but there still
> is an improvement to be made on the Proxmox VE side, which is to avoid
> doing QMP commands related to USB hotplug if they are not actually
> needed.
>
> [...]
Applied, thanks!
[1/2] hotplug pending: only check if USB devices are left when one was unplugged
commit: a23bab5178ecbe2df7d6d425bbd5e0a7005b8c7e
[2/2] hotplug pending: only check for USB hoptplug support when actually needed
commit: ebe5f14c50d938a654eebf72a1bfb006caeceaff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-31 18:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30 11:09 [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if actually needed Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 1/2] hotplug pending: only check if USB devices are left when one was unplugged Fiona Ebner
2026-03-30 11:09 ` [PATCH qemu-server 2/2] hotplug pending: only check for USB hoptplug support when actually needed Fiona Ebner
2026-03-31 14:29 ` [PATCH-SERIES qemu-server 0/2] hotplug pending: only issue QMP commands related to USB hotplug if " Manuel Federanko
2026-03-31 18:40 ` applied: " Thomas Lamprecht
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.