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 D98E69A708 for ; Fri, 17 Nov 2023 13:18:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A4B3D32753 for ; Fri, 17 Nov 2023 13:18:41 +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:40 +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 B024F43DEB for ; Fri, 17 Nov 2023 13:18:40 +0100 (CET) From: Hannes Duerr To: pve-devel@lists.proxmox.com Date: Fri, 17 Nov 2023 13:17:23 +0100 Message-Id: <20231117121726.119792-2-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 1/4] Move path_is_scsi to QemuServer/Drive.pm 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:41 -0000 Prepare for introduction of new helper Signed-off-by: Hannes Duerr --- PVE/QemuServer.pm | 62 +---------------------------------------- PVE/QemuServer/Drive.pm | 61 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index c465fb6..294702d 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); +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::Machine; use PVE::QemuServer::Memory qw(get_current_memory); use PVE::QemuServer::Monitor qw(mon_cmd); @@ -1342,66 +1342,6 @@ sub pve_verify_hotplug_features { die "unable to parse hotplug option\n"; } -sub scsi_inquiry { - my($fh, $noerr) = @_; - - my $SG_IO = 0x2285; - my $SG_GET_VERSION_NUM = 0x2282; - - my $versionbuf = "\x00" x 8; - my $ret = ioctl($fh, $SG_GET_VERSION_NUM, $versionbuf); - if (!$ret) { - die "scsi ioctl SG_GET_VERSION_NUM failoed - $!\n" if !$noerr; - return; - } - my $version = unpack("I", $versionbuf); - if ($version < 30000) { - die "scsi generic interface too old\n" if !$noerr; - return; - } - - my $buf = "\x00" x 36; - my $sensebuf = "\x00" x 8; - my $cmd = pack("C x3 C x1", 0x12, 36); - - # see /usr/include/scsi/sg.h - my $sg_io_hdr_t = "i i C C s I P P P I I i P C C C C S S i I I"; - - my $packet = pack( - $sg_io_hdr_t, ord('S'), -3, length($cmd), length($sensebuf), 0, length($buf), $buf, $cmd, $sensebuf, 6000 - ); - - $ret = ioctl($fh, $SG_IO, $packet); - if (!$ret) { - die "scsi ioctl SG_IO failed - $!\n" if !$noerr; - return; - } - - my @res = unpack($sg_io_hdr_t, $packet); - if ($res[17] || $res[18]) { - die "scsi ioctl SG_IO status error - $!\n" if !$noerr; - return; - } - - my $res = {}; - $res->@{qw(type removable vendor product revision)} = unpack("C C x6 A8 A16 A4", $buf); - - $res->{removable} = $res->{removable} & 128 ? 1 : 0; - $res->{type} &= 0x1F; - - return $res; -} - -sub path_is_scsi { - my ($path) = @_; - - my $fh = IO::File->new("+<$path") || return; - my $res = scsi_inquiry($fh, 1); - close($fh); - - return $res; -} - sub print_tabletdevice_full { my ($conf, $arch) = @_; diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm index e24ba12..dce1398 100644 --- a/PVE/QemuServer/Drive.pm +++ b/PVE/QemuServer/Drive.pm @@ -17,6 +17,7 @@ drive_is_cdrom drive_is_read_only parse_drive print_drive +path_is_scsi ); our $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/; @@ -760,4 +761,64 @@ sub resolve_first_disk { return; } +sub scsi_inquiry { + my($fh, $noerr) = @_; + + my $SG_IO = 0x2285; + my $SG_GET_VERSION_NUM = 0x2282; + + my $versionbuf = "\x00" x 8; + my $ret = ioctl($fh, $SG_GET_VERSION_NUM, $versionbuf); + if (!$ret) { + die "scsi ioctl SG_GET_VERSION_NUM failoed - $!\n" if !$noerr; + return; + } + my $version = unpack("I", $versionbuf); + if ($version < 30000) { + die "scsi generic interface too old\n" if !$noerr; + return; + } + + my $buf = "\x00" x 36; + my $sensebuf = "\x00" x 8; + my $cmd = pack("C x3 C x1", 0x12, 36); + + # see /usr/include/scsi/sg.h + my $sg_io_hdr_t = "i i C C s I P P P I I i P C C C C S S i I I"; + + my $packet = pack( + $sg_io_hdr_t, ord('S'), -3, length($cmd), length($sensebuf), 0, length($buf), $buf, $cmd, $sensebuf, 6000 + ); + + $ret = ioctl($fh, $SG_IO, $packet); + if (!$ret) { + die "scsi ioctl SG_IO failed - $!\n" if !$noerr; + return; + } + + my @res = unpack($sg_io_hdr_t, $packet); + if ($res[17] || $res[18]) { + die "scsi ioctl SG_IO status error - $!\n" if !$noerr; + return; + } + + my $res = {}; + $res->@{qw(type removable vendor product revision)} = unpack("C C x6 A8 A16 A4", $buf); + + $res->{removable} = $res->{removable} & 128 ? 1 : 0; + $res->{type} &= 0x1F; + + return $res; +} + +sub path_is_scsi { + my ($path) = @_; + + my $fh = IO::File->new("+<$path") || return; + my $res = scsi_inquiry($fh, 1); + close($fh); + + return $res; +} + 1; -- 2.39.2