From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 7BD0074499 for ; Mon, 21 Jun 2021 15:56:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B59C01C3F4 for ; Mon, 21 Jun 2021 15:55:40 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 288D11C300 for ; Mon, 21 Jun 2021 15:55:36 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E92E341DA7 for ; Mon, 21 Jun 2021 15:55:35 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 21 Jun 2021 15:55:20 +0200 Message-Id: <20210621135534.14807-8-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210621135534.14807-1-d.csapak@proxmox.com> References: <20210621135534.14807-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.836 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server 1/7] PVE/QemuServer: allow mapped usb devices in config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jun 2021 13:56:21 -0000 Signed-off-by: Dominik Csapak --- 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