[pve-devel] [PATCH qemu-server v2 25/32] vm devices list: prepare querying block device names for -blockdev
Fiona Ebner
f.ebner at proxmox.com
Wed Jun 18 15:02:02 CEST 2025
From: Alexandre Derumier via pve-devel <pve-devel at lists.proxmox.com>
Look at the 'qdev' value, because the 'device' property is not
initialized with '-blockdev'. This can be seen in the QEMU source code
(the device property is the name of the block backend and blk->name is
assigned a value only in a code path reached via drive_new()). This
most likely was done to avoid confusion/clashes, since with
'-blockdev', the node that's inserted for a front-end device can
change and then both the block backend and the node would be named
the same, but not connected.
Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
[FE: fix commit message and comment - it does not depend on the presence of media
escape dot in regex
skip right away if qdev is undef to avoid warning when regex matching]
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
Newly included in v2, makes hot{,un}plug after switch to -blockdev
work.
src/PVE/QemuServer.pm | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 843db76a..f8adb890 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -4249,11 +4249,19 @@ sub vm_devices_list {
$devices_to_check = $to_check;
}
+ # Block device IDs need to be checked at the qdev level, since with '-blockdev', the 'device'
+ # property will not be set.
my $resblock = mon_cmd($vmid, 'query-block');
- foreach my $block (@$resblock) {
- if ($block->{device} =~ m/^drive-(\S+)/) {
- $devices->{$1} = 1;
+ for my $block ($resblock->@*) {
+ my $qdev_id = $block->{qdev} or next;
+ if ($qdev_id =~ m|^/machine/peripheral/(virtio(\d+))/virtio-backend$|) {
+ $qdev_id = $1;
+ } elsif ($qdev_id =~ m|^/machine/system\.flash0$|) {
+ $qdev_id = 'pflash0';
+ } elsif ($qdev_id =~ m|^/machine/system\.flash1$|) {
+ $qdev_id = 'efidisk0';
}
+ $devices->{$qdev_id} = 1;
}
my $resmice = mon_cmd($vmid, 'query-mice');
--
2.39.5
More information about the pve-devel
mailing list