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

Dietmar Maurer dietmar at proxmox.com
Mon Mar 19 10:42:17 CET 2012


Just committed the scsi_inquiry fix instead (because that is the same test done inside the scsi-block driver itself).

- Dietmar

> -----Original Message-----
> From: pve-devel-bounces at pve.proxmox.com [mailto:pve-devel-
> bounces at pve.proxmox.com] On Behalf Of Derumier Alexandre
> Sent: Freitag, 16. März 2012 08:57
> To: pve-devel at pve.proxmox.com
> Subject: [pve-devel] [PATCH] add scsi-block detection
> 
> 
> Signed-off-by: Derumier Alexandre <aderumier at odiso.com>
> ---
>  PVE/QemuServer.pm |   48
> +++++++++++++++++++++++++++++++++++++++++++++---
>  1 files changed, 45 insertions(+), 3 deletions(-)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index
> 3991606..13a7852 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -25,6 +25,7 @@ use PVE::Cluster qw(cfs_register_file cfs_read_file
> cfs_write_file cfs_lock_file  use PVE::INotify;  use PVE::ProcFSTools;  use
> Time::HiRes qw(gettimeofday);
> +use Unix::Mknod qw(:all);
> 
>  my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
> 
> @@ -904,9 +905,8 @@ sub print_drivedevice_full {
>                } else {
>                    $path = PVE::Storage::path($storecfg, $drive->{file});
>                }
> -              if ($path =~ m|^/dev/| ) {
> -                  $devicetype = 'block';
> -              }
> +
> +	      $devicetype = 'block' if path_is_scsi($path);
>           }
> 
>  	$device = "scsi-$devicetype,bus=lsi$controller.0,scsi-
> id=$unit,drive=drive-$drive->{interface}$drive->{index},id=$drive-
> >{interface}$drive->{index}";
> @@ -2904,6 +2904,48 @@ sub vm_stopall {
>      print $msg;
>  }
> 
> +sub path_is_scsi {
> +    my ($path) = @_;
> +
> +    return if ($path !~ m|^/dev/|);
> +
> +    my $bdev = undef;
> +    #if path is /dev/xxx
> +    if($path =~ m|^/dev/[^/]+/?$|) {
> +        $bdev = $path;
> +    }
> +    #if path is /dev/disk/
> +    elsif ($path =~ m|^/dev/disk/|) {
> +        $bdev = readlink($path);
> +        #if multipath, we need to find real device
> +        if($bdev =~ m/(dm-(\d+))$/) {
> +            my $dir="/sys/block/$1/slaves/";
> +            my $dh = IO::Dir->new ($dir);
> +            if (defined $dh) {
> +                while (defined(my $tmp = $dh->read)) {
> +                    if ($tmp =~ m/([0-9A-Za-z])$/) {
> +                        $bdev="/dev/$tmp";
> +                    }
> +                }
> +            }
> +        }
> +        elsif ($bdev =~ m/(\w+)/) {
> +            $bdev="/dev/$1";
> +        }
> +    }
> +
> +    return if !$bdev;
> +
> +    my $st=stat($bdev);
> +    my $major=Unix::Mknod::major($st->rdev);
> +
> +    if ($major =~ m/^(\d+)$/) {
> +        $major = $1;
> +        my @scsimajors =
> (8,65,66,67,68,69,70,71,128,129,130,131,132,133,134,135);
> +        return 1 if (grep /^$major$/, @scsimajors)
> +    }
> +}
> +
>  # pci helpers
> 
>  sub file_write {
> --
> 1.7.2.5
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel





More information about the pve-devel mailing list