--- Begin Message ---
From: Tyst Marin <modding...@foxtek.us>

This change intends to add support for optional mapped usb devices.
Currently if a mapped device is unplugged vm boot will fail, tihs will provide 
an option to ignore specified missing devices.
This keeps the default behavior while allowing for optional devices to be 
specified.
---
 PVE/QemuServer/USB.pm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer/USB.pm b/PVE/QemuServer/USB.pm
index 017ef9c0..be2bef29 100644
--- a/PVE/QemuServer/USB.pm
+++ b/PVE/QemuServer/USB.pm
@@ -62,6 +62,12 @@ EODESCR
            ." is irrelevant (all devices are plugged into a xhci controller).",
         default => 0,
     },
+    bootwhenmissing => {
+        optional => 1,
+        type => 'boolean',
+        description => "Specifies whether given mapped usb device is optional 
at vm boot.",
+        default => 0,
+    },
 };
 
 PVE::JSONSchema::register_format('pve-qm-usb', $usb_fmt);
@@ -75,7 +81,7 @@ our $usbdesc = {
 PVE::JSONSchema::register_standard_option("pve-qm-usb", $usbdesc);
 
 sub parse_usb_device {
-    my ($value, $mapping) = @_;
+    my ($value, $mapping, $bootwhenmissing) = @_;
 
     return if $value && $mapping; # not a valid configuration
 
@@ -98,7 +104,11 @@ sub parse_usb_device {
            PVE::Mapping::USB::assert_valid($mapping, $devices->[0]);
        };
        if (my $err = $@) {
-           die "USB Mapping invalid (hardware probably changed): $err\n";
+           if (defined($bootwhenmissing) && $bootwhenmissing == 1) {
+               print "USB Mapping invalid (hardware probably changed): $err\n";
+           } else {
+               die "USB Mapping invalid (hardware probably changed): $err\n";
+           }
        }
        my $device = $devices->[0];
 
@@ -228,7 +238,7 @@ sub print_usbdevice_full {
        $usbdevice .= ",port=$port" if defined($port);
     }
 
-    my $parsed = parse_usb_device($device->{host}, $device->{mapping});
+    my $parsed = parse_usb_device($device->{host}, $device->{mapping}, 
$device->{bootwhenmissing});
 
     if (defined($parsed->{vendorid}) && defined($parsed->{productid})) {
        $usbdevice .= 
",vendorid=0x$parsed->{vendorid},productid=0x$parsed->{productid}";
-- 
2.39.5



--- End Message ---
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to