[pve-devel] [PATCH qemu-server v5 01/11] usb: mapping: move implementation of find_on_current_node here

Dominik Csapak d.csapak at proxmox.com
Mon Jan 20 15:51:46 CET 2025


this was the only user, and it's easy enough

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v4:
* refactor code into sub to keep the 'parse_usb_device' function smaller

 PVE/QemuServer/USB.pm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer/USB.pm b/PVE/QemuServer/USB.pm
index 017ef9c0..c701485b 100644
--- a/PVE/QemuServer/USB.pm
+++ b/PVE/QemuServer/USB.pm
@@ -5,6 +5,7 @@ use warnings;
 use PVE::QemuServer::PCI qw(print_pci_addr);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Helpers qw(min_version windows_version);
+use PVE::INotify;
 use PVE::JSONSchema;
 use PVE::Mapping::USB;
 use base 'Exporter';
@@ -74,6 +75,18 @@ our $usbdesc = {
 };
 PVE::JSONSchema::register_standard_option("pve-qm-usb", $usbdesc);
 
+my sub get_current_node_mapping {
+    my ($mapping) = @_;
+
+    my $config = PVE::Mapping::USB::config();
+    my $node = PVE::INotify::nodename();
+    my $devices = PVE::Mapping::USB::get_node_mapping($config, $mapping, $node);
+    die "USB device mapping not found for '$mapping'\n" if !$devices || !scalar($devices->@*);
+    die "More than one USB mapping per host not supported\n" if scalar($devices->@*) > 1;
+
+    return $devices;
+}
+
 sub parse_usb_device {
     my ($value, $mapping) = @_;
 
@@ -91,9 +104,7 @@ sub parse_usb_device {
 	    $res->{spice} = 1;
 	}
     } elsif (defined($mapping)) {
-	my $devices = PVE::Mapping::USB::find_on_current_node($mapping);
-	die "USB device mapping not found for '$mapping'\n" if !$devices || !scalar($devices->@*);
-	die "More than one USB mapping per host not supported\n" if scalar($devices->@*) > 1;
+	my $devices = get_current_node_mapping($mapping);
 	eval {
 	    PVE::Mapping::USB::assert_valid($mapping, $devices->[0]);
 	};
-- 
2.39.5





More information about the pve-devel mailing list