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 AD1657CC4F for ; Tue, 19 Jul 2022 13:46:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9BB5628D77 for ; Tue, 19 Jul 2022 13:46:42 +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 for ; Tue, 19 Jul 2022 13:46:40 +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 9F34E4361C for ; Tue, 19 Jul 2022 13:46:40 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Tue, 19 Jul 2022 13:46:21 +0200 Message-Id: <20220719114639.3035048-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220719114639.3035048-1-d.csapak@proxmox.com> References: <20220719114639.3035048-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.092 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [usb.pm, qemuserver.pm] 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: Tue, 19 Jul 2022 11:46:42 -0000 Signed-off-by: Dominik Csapak --- 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; + } + + 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