[pve-devel] [PATCH qemu-server 03/13] blockdev: vm_devices_list : fix block-query

Fiona Ebner f.ebner at proxmox.com
Tue Jun 17 16:44:16 CEST 2025


Am 03.06.25 um 09:55 schrieb Alexandre Derumier via pve-devel:
> 
> 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 a27dcabb..b15b05aa 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -4061,11 +4061,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+)/){

But this is already looking at the device ID, not the block node
name. AFAICS, the function does always work for -drive, but never for
-blockdev, regardless of the presence of a media. So I'm a bit confused
by the comment and commit message.

That said, the change itself looks good to me. I slightly adapted it and
will pick it up for v2 of the preparatory series with the following
commit message:

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.

> -		$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