[PATCH qemu-server 06/14] blockdev: vm_devices_list : fix block-query

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Tue Apr 22 13:51:33 CEST 2025


Look at qdev value, as cdrom drives can be empty
without any inserted media

Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 PVE/QemuServer.pm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 11bdc9ff..02bbadd4 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3997,11 +3997,22 @@ sub vm_devices_list {
 	$devices_to_check = $to_check;
     }
 
+    # block devices need to be queried at qdev level, as a device
+    # don't always have a blockdev drive media attached (cdrom for example).
+    # Also top node of the graph could have a different name than the device
+    # (we still use "drive-$deviceid" for throttle filter, but it's not 100% safe
+    # if we change that in the future
     my $resblock = mon_cmd($vmid, 'query-block');
     foreach my $block (@$resblock) {
-	if($block->{device} =~ m/^drive-(\S+)/){
-		$devices->{$1} = 1;
-	}
+	my $qdev_id = $block->{qdev};
+	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 if $qdev_id;
     }
 
     my $resmice = mon_cmd($vmid, 'query-mice');
-- 
2.39.5




More information about the pve-devel mailing list