> Alexandre Derumier via pve-devel <[email protected]> hat am
> 11.03.2025 11:28 CET geschrieben:
> Look at qdev value, as cdrom drives can be empty
> without any inserted media
>
> Signed-off-by: Alexandre Derumier <[email protected]>
> ---
> PVE/QemuServer.pm | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index faa17edb..5ccc026a 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -3937,11 +3937,12 @@ 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)
> my $resblock = mon_cmd($vmid, 'query-block');
> - foreach my $block (@$resblock) {
> - if($block->{device} =~ m/^drive-(\S+)/){
> - $devices->{$1} = 1;
> - }
> + $resblock = { map { $_->{qdev} => $_ } $resblock->@* };
here you map the full thing
> + foreach my $blockid (keys %$resblock) {
> + $devices->{$blockid} = 1;
but you are only interested in the IDs anyway?
so you could just do it like above for PCI devices:
foreach my $block (@$resblock) {
my $qdev_id = $block->{qdev};
$devices->{$qdev_id} = 1 if $qdev_id;
}
that way you don't need to loop twice ;)
this now returns more devices than before/different values for some cases?
e.g., efidisk0 has a really different qdev ID compared to its device name, the
UEFI firmware (pflash0) is also contained even though it is not a drive, and
that's just for the first test VM I checked ;)
would it maybe make more sense to special-case the CD drive(s) here?
> }
>
> my $resmice = mon_cmd($vmid, 'query-mice');
> --
> 2.39.5
_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel