[pve-devel] [PATCH qemu-server 1/7] PVE/QemuServer: allow mapped usb devices in config
Dominik Csapak
d.csapak at proxmox.com
Mon Jun 21 15:55:20 CEST 2021
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/QemuServer.pm | 2 ++
PVE/QemuServer/USB.pm | 22 +++++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index fe31741..5589bc7 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1016,6 +1016,8 @@ The Host USB device or port or the value 'spice'. HOSTUSBDEVICE syntax is:
You can use the 'lsusb -t' command to list existing usb devices.
+Alternatively, you can used an ID of a mapped usb device.
+
NOTE: This option allows direct access to host hardware. So it is no longer possible to migrate such
machines - use with special care.
diff --git a/PVE/QemuServer/USB.pm b/PVE/QemuServer/USB.pm
index 3c8da2c..ea3193f 100644
--- a/PVE/QemuServer/USB.pm
+++ b/PVE/QemuServer/USB.pm
@@ -4,6 +4,8 @@ use strict;
use warnings;
use PVE::QemuServer::PCI qw(print_pci_addr);
use PVE::JSONSchema;
+use PVE::HardwareMap;
+use PVE::HardwareMap::PCIPlugin;
use base 'Exporter';
our @EXPORT_OK = qw(
@@ -27,7 +29,25 @@ sub parse_usb_device {
} elsif ($value =~ m/^spice$/i) {
$res->{spice} = 1;
} else {
- return;
+ # we have no ordinary usb device, must be a mapping
+ my $device = PVE::HardwareMap::find_device_on_current_node('usb', $value);
+ return undef if !defined($device);
+ eval {
+ PVE::HardwareMap::USBPlugin->assert_device_valid($device);
+ };
+ if (my $err = $@) {
+ warn "USB Mapping invalid (hardware probably changed): $err\n";
+ return;
+ }
+
+ if ($device->{usbpath}) {
+ $res = parse_usb_device($device->{usbpath});
+ } else {
+ $res->{vendorid} = $device->{vendor};
+ $res->{productid} = $device->{device};
+ }
+
+ $res->{mapped} = 1;
}
return $res;
--
2.20.1
More information about the pve-devel
mailing list