From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@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 C9EF5993E9
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 11:37:05 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id B361811AB0
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 11:37:05 +0100 (CET)
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 <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 11:37:04 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C0432437D7
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 11:37:04 +0100 (CET)
Message-ID: <fb0c3159-8e40-4de9-a244-1dfd1efa89ce@proxmox.com>
Date: Thu, 16 Nov 2023 11:37:03 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Hannes Duerr <h.duerr@proxmox.com>
References: <20231110093358.62006-1-h.duerr@proxmox.com>
 <20231110093358.62006-3-h.duerr@proxmox.com>
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20231110093358.62006-3-h.duerr@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.078 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 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
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: Re: [pve-devel] [PATCH v3 qemu-server 2/2] fix #4957: add vendor
 and product information passthrough for SCSI-Disks
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
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/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 16 Nov 2023 10:37:05 -0000

Am 10.11.23 um 10:33 schrieb Hannes Duerr:
> adds vendor and product information for SCSI devices to the json schema and
> checks in the VM create/update API call if it is possible to add these to QEMU as a device option
> 
> Signed-off-by: Hannes Duerr <h.duerr@proxmox.com>
> ---
>  PVE/API2/Qemu.pm        | 12 ++++++++++++
>  PVE/QemuServer.pm       | 28 ++++++++++++++++++++++++++++
>  PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
>  3 files changed, 64 insertions(+)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 38bdaab..9d8171a 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -1013,6 +1013,13 @@ __PACKAGE__->register_method({
>  		my $conf = $param;
>  		my $arch = PVE::QemuServer::get_vm_arch($conf);
>  
> +		for my $opt (sort keys $param->%*) {
> +		    if ($opt =~ m/scsi/) {

Should be anchored and best to even match for the number too, i.e.
^scsi(\d)+$ to make it future-proof. E.g. there could be a
'scsi-defaults' option at some point

> +			PVE::QemuServer::assert_scsi_feature_compatibility(
> +			    $opt, $conf, $storecfg, $param->{$opt});
> +		    }
> +		}
> +
>  		$conf->{meta} = PVE::QemuServer::new_meta_info_string();
>  
>  		my $vollist = [];
> @@ -1828,6 +1835,11 @@ my $update_vm_api  = sub {
>  		    PVE::QemuServer::vmconfig_register_unused_drive($storecfg, $vmid, $conf, PVE::QemuServer::parse_drive($opt, $conf->{pending}->{$opt}))
>  			if defined($conf->{pending}->{$opt});
>  
> +		    if ($opt =~ m/scsi/) {
> +			PVE::QemuServer::assert_scsi_feature_compatibility(
> +			    $opt, $conf, $storecfg, $param->{$opt});
> +		    }
> +
>  		    my (undef, $created_opts) = $create_disks->(
>  			$rpcenv,
>  			$authuser,
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 9a83021..9c998d6 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -1368,6 +1368,24 @@ my sub get_drive_id {
>      return "$drive->{interface}$drive->{index}";
>  }
>  
> +sub assert_scsi_feature_compatibility {
> +    my ($opt, $conf, $storecfg, $drive_attributes) = @_;
> +

Since it's only used in API2/Qemu.pm, should it live there?

> +    my $drive = parse_drive($opt, $drive_attributes);
> +
> +    my $machine_type = get_vm_machine($conf, undef, $conf->{arch});
> +    my $machine_version = extract_version($machine_type, kvm_user_version());
> +    my $drivetype = PVE::QemuServer::Drive::get_scsi_devicetype(
> +	$drive, $storecfg, $machine_version);
> +
> +    if ($drivetype ne 'hd' && $drivetype ne 'cd') {
> +	if ($drive_attributes =~ m/vendor/ || $drive_attributes =~ m/product/) {

Please check $drive->{vendor} and $drive->{product} here. These regexes
are brittle and not future-proof.

> +	    die "only 'scsi-hd' and 'scsi-cd' devices".
> +		"support passing vendor and product information\n";

Could be a raise_param_exc and maybe give a hint about pass-through? For
example:

only 'scsi-hd' and 'scsi-cd' devices (e.g. not pass-through)

Like that users will know in most situations what the issue is.