Prepare for introduction of new helper Signed-off-by: Hannes Duerr <h.du...@proxmox.com> --- 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel