vm devices list: prepare querying block device names for -blockdev

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.

[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: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Alexandre Derumier via pve-devel 2025-06-18 15:02:02 +02:00 committed by Fabian Grünbichler
parent 25161b43bd
commit 9af3ef69c7

View file

@ -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');