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 B8FA8A018C for ; Wed, 8 Nov 2023 09:52:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9920039F8 for ; Wed, 8 Nov 2023 09:52:02 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 8 Nov 2023 09:52:01 +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 9B25847058 for ; Wed, 8 Nov 2023 09:52:01 +0100 (CET) From: Hannes Duerr To: pve-devel@lists.proxmox.com Date: Wed, 8 Nov 2023 09:51:28 +0100 Message-Id: <20231108085128.38933-1-h.duerr@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.005 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemu.pm, drive.pm, qemuserver.pm] Subject: [pve-devel] [PATCH v2 qemu-server] 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Nov 2023 08:52:02 -0000 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 --- changes in v2: - when calling the API to create/update a VM, check whether the devices are "scsi-hd" or "scsi-cd" devices,where there is the option to add vendor and product information, if not error out - change the format in product_fmt and vendor_fmt to a pattern that only allows 40 characters consisting of upper and lower case letters, numbers and '-' and '_'. PVE/API2/Qemu.pm | 9 +++++ PVE/QemuServer.pm | 83 +++++++++++++++++++++++++++++------------ PVE/QemuServer/Drive.pm | 24 ++++++++++++ 3 files changed, 92 insertions(+), 24 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 38bdaab..6898ec9 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1030,6 +1030,11 @@ __PACKAGE__->register_method({ ); $conf->{$_} = $created_opts->{$_} for keys $created_opts->%*; + foreach my $opt (keys $created_opts->%*) { + if ($opt =~ m/scsi/) { + PVE::QemuServer::check_scsi_feature_compatibility($opt, $created_opts, $conf, $storecfg, $param); + } + } if (!$conf->{boot}) { my $devs = PVE::QemuServer::get_default_bootdevices($conf); $conf->{boot} = PVE::QemuServer::print_bootorder($devs); @@ -1840,6 +1845,10 @@ my $update_vm_api = sub { ); $conf->{pending}->{$_} = $created_opts->{$_} for keys $created_opts->%*; + if ($opt =~ m/scsi/) { + PVE::QemuServer::check_scsi_feature_compatibility($opt, $created_opts, $conf, $storecfg, $param); + } + # default legacy boot order implies all cdroms anyway if (@bootorder) { # append new CD drives to bootorder to mark them bootable diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index dbcd568..919728b 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -26,6 +26,7 @@ use Storable qw(dclone); use Time::HiRes qw(gettimeofday usleep); use URI::Escape; use UUID; +use Data::Dumper; use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file); use PVE::CGroup; @@ -1428,6 +1429,53 @@ my sub get_drive_id { return "$drive->{interface}$drive->{index}"; } +sub get_scsi_devicetype { + my ($drive, $storecfg, $machine_type) = @_; + + my $devicetype = 'hd'; + my $path = ''; + if (drive_is_cdrom($drive)) { + $devicetype = 'cd'; + } else { + if ($drive->{file} =~ m|^/|) { + $path = $drive->{file}; + if (my $info = path_is_scsi($path)) { + if ($info->{type} == 0 && $drive->{scsiblock}) { + $devicetype = 'block'; + } elsif ($info->{type} == 1) { # tape + $devicetype = 'generic'; + } + } + } else { + $path = PVE::Storage::path($storecfg, $drive->{file}); + } + + # for compatibility only, we prefer scsi-hd (#2408, #2355, #2380) + my $version = kvm_user_version(); + $version = extract_version($machine_type, $version); + if ($path =~ m/^iscsi\:\/\// && + !min_version($version, 4, 1)) { + $devicetype = 'generic'; + } + } + + return $devicetype; +} + +sub check_scsi_feature_compatibility { + my($opt, $created_opts, $conf, $storecfg, $param) = @_; + + my $drive = parse_drive($opt, $created_opts->{$opt}); + my $machine_type = get_vm_machine($conf, undef, $conf->{arch}); + my $drivetype = get_scsi_devicetype($drive, $storecfg, $machine_type); + + if ($drivetype ne 'hd' && $drivetype ne 'cd') { + if ($param->{$opt} =~ m/vendor/ || $param->{$opt} =~ m/product/) { + die "only 'scsi-hd' and 'scsi-cd' devices support passing vendor and product information\n"; + } + } +} + sub print_drivedevice_full { my ($storecfg, $conf, $vmid, $drive, $bridges, $arch, $machine_type) = @_; @@ -1443,31 +1491,8 @@ sub print_drivedevice_full { my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive); my $unit = $drive->{index} % $maxdev; - my $devicetype = 'hd'; - my $path = ''; - if (drive_is_cdrom($drive)) { - $devicetype = 'cd'; - } else { - if ($drive->{file} =~ m|^/|) { - $path = $drive->{file}; - if (my $info = path_is_scsi($path)) { - if ($info->{type} == 0 && $drive->{scsiblock}) { - $devicetype = 'block'; - } elsif ($info->{type} == 1) { # tape - $devicetype = 'generic'; - } - } - } else { - $path = PVE::Storage::path($storecfg, $drive->{file}); - } - # for compatibility only, we prefer scsi-hd (#2408, #2355, #2380) - my $version = extract_version($machine_type, kvm_user_version()); - if ($path =~ m/^iscsi\:\/\// && - !min_version($version, 4, 1)) { - $devicetype = 'generic'; - } - } + my $devicetype = get_scsi_devicetype($drive, $storecfg, $machine_type); if (!$conf->{scsihw} || $conf->{scsihw} =~ m/^lsi/ || $conf->{scsihw} eq 'pvscsi') { $device = "scsi-$devicetype,bus=$controller_prefix$controller.0,scsi-id=$unit"; @@ -1482,6 +1507,16 @@ sub print_drivedevice_full { } $device .= ",wwn=$drive->{wwn}" if $drive->{wwn}; + # only scsi-hd and scsi-cd support passing vendor and product information + if ($devicetype eq 'hd' || $devicetype eq 'cd') { + if (my $vendor = $drive->{vendor}) { + $device .= ",vendor=$vendor"; + } + if (my $product = $drive->{product}) { + $device .= ",product=$product"; + } + } + } elsif ($drive->{interface} eq 'ide' || $drive->{interface} eq 'sata') { my $maxdev = ($drive->{interface} eq 'sata') ? $PVE::QemuServer::Drive::MAX_SATA_DISKS : 2; my $controller = int($drive->{index} / $maxdev); diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm index e24ba12..021f182 100644 --- a/PVE/QemuServer/Drive.pm +++ b/PVE/QemuServer/Drive.pm @@ -159,6 +159,26 @@ my %iothread_fmt = ( iothread => { optional => 1, }); +my %product_fmt = ( + product => { + type => 'string', + pattern => '[A-Za-z0-9\-_]{,40}', + format_description => 'product', + description => "The drive's product name, up to 40 bytes long.", + optional => 1, + }, +); + +my %vendor_fmt = ( + vendor => { + type => 'string', + pattern => '[A-Za-z0-9\-_]{,40}', + format_description => 'vendor', + description => "The drive's vendor name, up to 40 bytes long.", + optional => 1, + }, +); + my %model_fmt = ( model => { type => 'string', @@ -281,6 +301,8 @@ my $scsi_fmt = { %scsiblock_fmt, %ssd_fmt, %wwn_fmt, + %vendor_fmt, + %product_fmt, }; my $scsidesc = { optional => 1, @@ -404,6 +426,8 @@ my $alldrive_fmt = { %readonly_fmt, %scsiblock_fmt, %ssd_fmt, + %vendor_fmt, + %product_fmt, %wwn_fmt, %tpmversion_fmt, %efitype_fmt, -- 2.39.2