[pve-devel] [PATCH qemu-server 4/7] get usbdevices in vm_devices_list

Dominik Csapak d.csapak at proxmox.com
Tue Jun 14 10:50:38 CEST 2016


since usb devices do not have their own
"query" command in qmp, we have to use
qom-list /machines/peripheral

which essentially gets a list of peripheral devices of
the vm

there we only get the usb devices

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
this will only work with usb devices after this patch series,
since we did not give the usb devices an id (so they do not
appear in the qom-list call)
 PVE/QemuServer.pm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 5ba46c9..f12e587 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3238,6 +3238,16 @@ sub vm_devices_list {
 	}
     }
 
+    # for usb devices there is no query-usb
+    # but we can iterate over the entries in
+    # qom-list path=/machine/peripheral
+    my $resperipheral = vm_mon_cmd($vmid, 'qom-list', path => '/machine/peripheral');
+    foreach my $per (@$resperipheral) {
+	if ($per->{name} =~ m/^usb\d+$/) {
+	    $devices->{$per->{name}} = 1;
+	}
+    }
+
     return $devices;
 }
 
-- 
2.1.4





More information about the pve-devel mailing list