From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 8AE481FF168
	for <inbox@lore.proxmox.com>; Tue, 26 Nov 2024 11:37:04 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 706F72C8E5;
	Tue, 26 Nov 2024 11:36:58 +0100 (CET)
To: pve-devel@lists.proxmox.com
Date: Tue, 26 Nov 2024 01:51:57 +0000
In-Reply-To: <20241126015157.1107116-1-moddingfox@foxtek.us>
References: <20241126015157.1107116-1-moddingfox@foxtek.us>
X-Mailman-Approved-At: Tue, 26 Nov 2024 11:36:57 +0100
MIME-Version: 1.0
Message-ID: <mailman.693.1732617417.391.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: moddingfox via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: moddingfox <moddingfox@gmail.com>, Tyst Marin <moddingfox@foxtek.us>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH container 1/1] Optional mapped devices at vm boot
Content-Type: multipart/mixed; boundary="===============5204836352811644947=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============5204836352811644947==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <moddingfox@gmail.com>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
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 8CCB8C9D93
	for <pve-devel@lists.proxmox.com>; Tue, 26 Nov 2024 02:52:38 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 63D9D1E184
	for <pve-devel@lists.proxmox.com>; Tue, 26 Nov 2024 02:52:38 +0100 (CET)
Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Tue, 26 Nov 2024 02:52:37 +0100 (CET)
Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-212581a0b33so50251845ad.0
        for <pve-devel@lists.proxmox.com>; Mon, 25 Nov 2024 17:52:37 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1732585950; x=1733190750; darn=lists.proxmox.com;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=nwzNEAchB+Ai3+xPvWx+0MRFAUgVdkrgpSHujsXXVV0=;
        b=Zm7etDPpnCTkNO4vd27CczVYvVz2rZQ1I7aPIJ2qZAfHt9di4nivQBdKp+RNzqriCi
         ABM8qGrqb0mkj9WYgZYDFqCL5J5rpW/YMNxVOk/ZTpBhtWp2zUz2WuHNYHohXllKhI7T
         JL/Wd28TJKa6GZHJKIhWTe/fRIkxKTfY5NuvoaziiBLXG2eFo8pLkxoHNfPlFLbBvNkJ
         dpWPhGqynvwPfruhW8f+PdwL1cKN0FdNbV2eL5HslQfd624mhFfVfAsCXQxDqbx1qzIQ
         /eeF7OjghQh9RAHTtLay5i1hU0GSaHZlSqaBg8twZMTZ4MzTJqQipHylLp5YQUxN3OsA
         vNvg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1732585950; x=1733190750;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=nwzNEAchB+Ai3+xPvWx+0MRFAUgVdkrgpSHujsXXVV0=;
        b=tZ38z24ewEeGdILTJIbsHFAvxeC2x0mslAh+2Fs7prfKfzOa1IICXKB3KgQQQefDTb
         hauWB7tXLeT5QWRA1dLTLNbsui9gphf7shQjq5guvYkg9DlCxBOGQwcWEJzvHYLgPJpS
         g+wpkYDPCTVX3DoPM3SRBC7Ei4IOUeo4v58LeVVrfOgA+vPlWzq2LWhhpPhIG5SR631b
         uBWRhskKR/MbrXcBpUXBa8hCHYfUA09DFoNS99jFrAkknElcOrLfZv651/1Eym24DlA3
         ZDOCkIh0V7Ls0gamJU5Jq/NXIpsf1frix7YicdjOnvUYALmpV6kIf8p2ySGKChL72h9p
         +1sA==
X-Gm-Message-State: AOJu0YyBP3h3WsLW+bWjBD/rOZb4SL0FXES7/ihjBYTdGMKB/EOJE9B1
	mbrZjixOFB3t0BkQkZC+kSsPwAA6FbSo7ZrxL+mgvx18CpWKThCz
X-Gm-Gg: ASbGncs9kyA7tD6GqPDbyJE3zHH/DZAsxMo3d9E59l/L+4nBVA4neg1mEam8iDmUrfm
	o3gABmTBLNCtscO6odwZQCwY6+3XJuKDn1u0ckG2FqQRwdpL6Qszx+YwcaLJV4Qcp5/fVo959Ul
	2CMa9Zc+n4tHjKqjoWJIKYIS+JeNE3vJem9jOToZEf0iK2dASH4cCDwPcOkwlf93voFpI0dk6Iq
	ysSMh+vu+XFyjBqU2GbFEQ9qgPRvlztAuG878i3b3izj+5BLOks8bODTsAYszzZNNg5grS+zn/j
	cabBCWJfON/J1+yudVgXISiEp5Nb7tPJXXeCFwob1gBIaqfiXF6R
X-Google-Smtp-Source: AGHT+IFldT9MYyaE3HNmHxI8Q4pmRoMpPEeusHaRtfkGPbjZlIUEgq2CPdB331swwojGLMkU1JZ/qw==
X-Received: by 2002:a17:902:f682:b0:212:530:a659 with SMTP id d9443c01a7336-2129f31dd5cmr197231265ad.19.1732585949856;
        Mon, 25 Nov 2024 17:52:29 -0800 (PST)
Received: from Tyst-Proxmox-00.foxtek.us (c-24-18-146-249.hsd1.wa.comcast.net. [24.18.146.249])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc2024asm72302945ad.224.2024.11.25.17.52.29
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 25 Nov 2024 17:52:29 -0800 (PST)
From: moddingfox <moddingfox@gmail.com>
X-Google-Original-From: moddingfox <moddingfox@foxtek.us>
Received: by Tyst-Proxmox-00.foxtek.us (Postfix, from userid 1000)
	id 4F9AF1B9; Tue, 26 Nov 2024 01:52:29 +0000 (UTC)
To: pve-devel@lists.proxmox.com
Cc: Tyst Marin <moddingfox@foxtek.us>
Subject: [PATCH container 1/1] Optional mapped devices at vm boot
Date: Tue, 26 Nov 2024 01:51:57 +0000
Message-Id: <20241126015157.1107116-2-moddingfox@foxtek.us>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20241126015157.1107116-1-moddingfox@foxtek.us>
References: <20241126015157.1107116-1-moddingfox@foxtek.us>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DKIM_SIGNED               0.1 Message has a DKIM or DK signature, not necessarily valid
	DKIM_VALID               -0.1 Message has at least one valid DKIM or DK signature
	DKIM_VALID_AU            -0.1 Message has a valid DKIM or DK signature from author's domain
	DKIM_VALID_EF            -0.1 Message has a valid DKIM or DK signature from envelope-from domain
	DMARC_PASS               -0.1 DMARC pass policy
	FREEMAIL_FROM           0.001 Sender email is commonly abused enduser mail provider
	RCVD_IN_DNSWL_NONE     -0.0001 Sender listed at https://www.dnswl.org/, no trust
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_PASS               -0.001 SPF: sender matches SPF record
X-Mailman-Approved-At: Tue, 26 Nov 2024 11:36:57 +0100

From: Tyst Marin <moddingfox@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



--===============5204836352811644947==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============5204836352811644947==--