On July 19, 2022 1:46 pm, Dominik Csapak wrote: > Signed-off-by: Dominik Csapak <d.csa...@proxmox.com> > --- > PVE/QemuServer.pm | 2 ++ > PVE/QemuServer/USB.pm | 21 ++++++++++++++++++++- > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index 7d9cf22..a6ca80d 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -1069,6 +1069,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..279078a 100644 > --- a/PVE/QemuServer/USB.pm > +++ b/PVE/QemuServer/USB.pm > @@ -4,6 +4,7 @@ use strict; > use warnings; > use PVE::QemuServer::PCI qw(print_pci_addr); > use PVE::JSONSchema; > +use PVE::HardwareMap; > use base 'Exporter'; > > our @EXPORT_OK = qw( > @@ -27,7 +28,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::assert_device_valid('usb', $device); > + }; > + if (my $err = $@) { > + warn "USB Mapping invalid (hardware probably changed): $err\n"; > + return; > + }
nit: this would also trigger on deleting such an invalid mapping, which is a bit strange? > + > + if ($device->{path}) { > + $res = parse_usb_device($device->{path}); > + } else { > + $res->{vendorid} = $device->{vendor}; > + $res->{productid} = $device->{device}; > + } > + > + $res->{mapped} = 1; > } > > return $res; > -- > 2.30.2 > > > > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel > > > _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel