[pve-devel] [PATCH] add scsi-block detection

Dietmar Maurer dietmar at proxmox.com
Mon Mar 19 09:55:24 CET 2012


Please can you test if this works to identify the multipath scsi devices?

-------------------------
#!/usr/bin/perl -w

use strict;
use IO::File;
use Data::Dumper;

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 undef;
    }
    my $version = unpack("I", $versionbuf);

    if ($version < 30000) {
	die "scsi generic interface too old\n"  if !$noerr;
	return undef;
    }
 	
    my $buf = "\x00" x 36;
    my $sensebuf = "\x00" x 8;
    my $cmd = pack("C x3 C x11", 0x12, 36);
 
    my $packet = pack("i i C C s I P P P I I i P C C C C S S i I I",
		      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 undef;
    }

    my @res = unpack("i i C C s I P P P I I i P C C C C S S i I I", $packet);
    if ($res[17] || $res[18]) {
	die "scsi ioctl SG_IO status error - $!\n" if !$noerr;
	return undef;
    }

    my $res = {};
    ($res->{device}, $res->{removable}, $res->{venodor},
     $res->{product}, $res->{revision}) = unpack("C C x6 A8 A16 A4", $buf);

    return $res;
}

my $devfn = shift || die "no device specified\n";

my $fh=IO::File->new("+<$devfn") || die "can't open '$devfn' - $!\n";

my $data = scsi_inquiry($fh);
print Dumper($data);

close($fh);


> -----Original Message-----
> From: Alexandre DERUMIER [mailto:aderumier at odiso.com]
> Sent: Montag, 19. März 2012 07:06
> To: Dietmar Maurer
> Cc: pve-devel at pve.proxmox.com
> Subject: Re: [pve-devel] [PATCH] add scsi-block detection
> 
> Hi Dietmar,
> I found this :
> 
> http://search.cpan.org/~mooli/Device-SCSI-1.004/lib/Device/SCSI.pm
> 
> 
> use Device::SCSI;
> 
>   my @devices = Device::SCSI->enumerate;
> 
>   my $device = Device::SCSI->new($devices[0]);
>   my %inquiry = %{ $device->inquiry };
>   my ($result, $sense) = $device->execute($command, $wanted, $data);
>   $device->close;
> 
> 
> Seem to be what we want to do ...
> 
> ----- Mail original -----
> 
> De: "Dietmar Maurer" <dietmar at proxmox.com>
> À: "Alexandre DERUMIER" <aderumier at odiso.com>
> Cc: pve-devel at pve.proxmox.com
> Envoyé: Vendredi 16 Mars 2012 15:58:54
> Objet: RE: [pve-devel] [PATCH] add scsi-block detection
> 
> > maybe
> >
> > bdrv_ioctl(s->qdev.conf.bs, SG_GET_VERSION_NUM, &sg_version) do the
> > job ?
> 
> AFAIK the inquiry command fail, so we need to execute an scsi inquiry.
> 
> - Dietmar
> 
> 
> 
> --
> 
> --
> 
> 
> 
> 
> 	Alexandre D erumier
> Ingénieur Système
> Fixe : 03 20 68 88 90
> Fax : 03 20 68 90 81
> 45 Bvd du Général Leclerc 59100 Roubaix - France
> 12 rue Marivaux 75002 Paris - France
> 



More information about the pve-devel mailing list