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 8B5929A70A for ; Fri, 17 Nov 2023 13:18:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 738B1326FF for ; Fri, 17 Nov 2023 13:18:42 +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 ; Fri, 17 Nov 2023 13:18:41 +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 7DE8B43DF6 for ; Fri, 17 Nov 2023 13:18:41 +0100 (CET) From: Hannes Duerr To: pve-devel@lists.proxmox.com Date: Fri, 17 Nov 2023 13:17:25 +0100 Message-Id: <20231117121726.119792-4-h.duerr@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231117121726.119792-1-h.duerr@proxmox.com> References: <20231117121726.119792-1-h.duerr@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.002 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: [pve-devel] [PATCH v5 qemu-server 3/4] drive: Create get_scsi_devicetype 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: Fri, 17 Nov 2023 12:18:42 -0000 Encapsulation of the functionality for determining the scsi device type in a new function for reusability in QemuServer/Drive.pm Signed-off-by: Hannes Duerr --- PVE/QemuServer.pm | 29 ++++------------------------- PVE/QemuServer/Drive.pm | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 294702d..6090f91 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -53,7 +53,7 @@ use PVE::QemuServer::Helpers qw(config_aware_timeout min_version windows_version use PVE::QemuServer::Cloudinit; use PVE::QemuServer::CGroup; use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options); -use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive path_is_scsi); +use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive); use PVE::QemuServer::Machine; use PVE::QemuServer::Memory qw(get_current_memory); use PVE::QemuServer::Monitor qw(mon_cmd); @@ -1386,31 +1386,10 @@ 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 $machine_version = extract_version($machine_type, kvm_user_version()); + my $devicetype = PVE::QemuServer::Drive::get_scsi_devicetype( + $drive, $storecfg, $machine_version); if (!$conf->{scsihw} || $conf->{scsihw} =~ m/^lsi/ || $conf->{scsihw} eq 'pvscsi') { $device = "scsi-$devicetype,bus=$controller_prefix$controller.0,scsi-id=$unit"; diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm index 6d94a2f..de62d43 100644 --- a/PVE/QemuServer/Drive.pm +++ b/PVE/QemuServer/Drive.pm @@ -15,9 +15,9 @@ is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only +get_scsi_devicetype parse_drive print_drive -path_is_scsi ); our $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/; @@ -822,4 +822,37 @@ sub path_is_scsi { return $res; } +sub get_scsi_devicetype { + my ($drive, $storecfg, $machine_version) = @_; + + 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'; + } + } + } elsif ($drive->{file} =~ $NEW_DISK_RE){ + # special syntax cannot be parsed to path + return $devicetype; + } else { + $path = PVE::Storage::path($storecfg, $drive->{file}); + } + + # for compatibility only, we prefer scsi-hd (#2408, #2355, #2380) + if ($path =~ m/^iscsi\:\/\// && + !min_version($machine_version, 4, 1)) { + $devicetype = 'generic'; + } + } + + return $devicetype; +} 1; -- 2.39.2