Skip to main content

Display LUN information for ASM devices RHEL 5 and 6

I know close to nothing about Perl.  This script was created on RHEL 5 and I wanted the functionality to be extended to RHEL 6.  

In regards to our script the significant differences between RHEL 5 and 6 are:

RHEL5
/dev/mpath     -- path to multipath devices
 \_                   -- identifier for multipath device

RHEL6
/dev/mapper   -- path to multipath devices
  |-                   -- identifier for multipath device
  `-                  -- identifier for multipath device
 

#!/usr/bin/perl

@rhelver = `cat /etc/redhat-release`;
$rhelver[0] =~ / (\d\.\d) /;     
$RELEASE = $1;

# ARRAY OF HDS ARRAYS
$sxm_arrays = {
  '726a'=>'ITSHDS05',
  '71c9'=>'ITSHDS06',
  '61bc'=>'ITSHDS04',
  '4ed0'=>'ITSHDS01',
  '5b68'=>'ITSHDS02',
  '03da'=>'ORION1',
  '03f6'=>'TITAN1',
  'ac75'=>'ATLAS',
  'ba9e'=>'CAPELLA',
  '2924'=>'REGULUS'
};

# BUILD ARRAY BASED ON OUTPUT FROM multipath COMMAND
open MPATH,"multipath -ll -v2|" or die "can't fork: $!";
while (<MPATH>) {
  chomp;
  if (m/^(mpath\d+) \(\w*(\w{4})\w{4}(\w{2})(\w{2})\) (\S+) /) {
    $mpath_id="$sxm_arrays->{$2}_$3$4";
    $ldev{$mpath_id}="$3:$4";
    $array_id{$mpath_id}=$sxm_arrays->{$2};
    $dm_id{$mpath_id}=$5;
    $mpath_to_ldev{$mpath_id}=$1;
  }
  if (m/^([0-9a-zA-Z]+)\_(\w{2})(\w{2}) (dm-\d*) HIT/)
  {
    $mpath_id="$1_$2$3";
    $ldev{"$1_$2$3"}="$2:$3"; 
    $array_id{"$1_$2$3"}=$1;
    $dm_id{"$1_$2$3"}=$4;
  }

  if ($RELEASE >= 6.0) {
    $lun_size{$mpath_id}=$1 if m/size=([0-9A-Z\.]+)/;
    #$sub_path{$mpath_id}.=$1 if m/^  \|- [\d,\:]+ *(\w+ )/;
    #$sub_path{$mpath_id}.=$1 if m/^  `- [\d,\:]+ *(\w+ )/;
    $sub_path{$mpath_id}.=$1 if m/^  [\|`]- [\d,\:]+ *(\w+ )/;
  }
  else
  {
    $lun_size{$mpath_id}=$1 if m/\[size=([0-9A-Z\.]+)\]/;
    $sub_path{$mpath_id}.=$1 if m/ \\\_ [\d,\:]+ *(\w+ )/;
  }

}
close MPATH;

%mpath_to_ldev=reverse %mpath_to_ldev;
if ($RELEASE >= 6.0) {
  open B,"ls -lL /dev/mapper|" or die "can't fork: $!";
}
else
{
  open B,"ls -lL /dev/mpath|" or die "can't fork: $!";
}
while (<B>) {
  chmop;
  $majmin{"$1,$2"}=$3 if m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(\w+\_\w+)/;
  if(m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(mpath\w+)p1/){
    $majmin{"$1,$2"}=$mpath_to_ldev{$3}."p1";
  }
  elsif (m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(mpath\w+)/){
    $majmin{"$1,$2"}=$mpath_to_ldev{$3};
  }
}
close B;

# The following is independent of RHEL version
%rmajmin=reverse %majmin;
open C,"ls -l /dev/oracleasm/disks|" or die "can't fork: $!";
while (<C>) {
  chmop;
  $asmdev{"$1,$2"}=$3 if m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(\S+)$/;
}
close C;
print (keys %sxm_arrays),"\n";

%mpath_to_ldev=reverse %mpath_to_ldev;
%$sxm_arrays=reverse %$sxm_arrays;
@sorted = sort { $asmdev{$a} cmp $asmdev{$b} } keys %asmdev;
format STDOUT=
@<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<@<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<@<<<<@<<<<<@<<<<<@<<<<<<<@*
$a,                   $dgname          $b,       $c,     $d,     $e,    $f,  $g,   $h,   $i,     $j
.
$_='ASM_DEV_NAME ASM_DG PATH DevID D-Path DM SER LDEV SIZE D-DevID SUBPATH';
($a,$dgname,$b,$c,$d,$e,$f,$g,$h,$i,$j)=split;
write (STDOUT);
foreach  (@sorted) {
  ($a,$b,$c)=($asmdev{$_},$majmin{$_},$_);
  $dgname=`dd if=/dev/oracleasm/disks/$a bs=8 skip=13 count=4 2>/dev/null|strings`;
  $_=$majmin{$_};m/([a-zA-Z0-9]+_\w{4})/;$_=$1;
  ($d,$e,$f,$g,$h,$i,$j)=($_,$dm_id{$_},$sxm_arrays->{$array_id{$_}},$ldev{$_},$lun_size{$_},$rmajmin{$_},$sub_path{$_});
  if (scalar(keys %mpath_to_ldev) != 0) {
    $d=$mpath_to_ldev{$d};
    $b=~m/(.*)p1$/;
    $b=$mpath_to_ldev{$1}."p1";
  }
  write (STDOUT);
}


RAW OUTPUT
===============

RHEL5 
ORION1_1014 dm-4 HITACHI,OPEN-V
[size=800G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=1][active]
 \_ 3:0:1:27  sdac 65:192  [active][ready]
 \_ 4:0:1:27  sdcm 69:160  [active][ready]
 \_ 7:0:0:27  sdew 129:128 [active][ready]
 \_ 8:0:0:27  sdhg 133:96  [active][ready]


RHEL6
ORION1_3006 dm-2 HITACHI,OPEN-V
size=50G features='0' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 2:0:0:0 sdc 8:32  active ready  running
  `- 0:0:0:0 sdj 8:144 active ready  running
 

Comments

Popular posts from this blog

P2V using dd for KVM-QEMU guest

Preface: I have certainly not exhaustively tested this process.  I had a specific need and found a specific solution that worked. Situation:  I was issued a shiny new laptop running Red Hat Enterprise Linux 7 (with Corp VPN, certs, Authentication configuration, etc...)  The image was great, but I needed more flexibility on my bare metal.  So, my goal was to P2V the corporate image so I could just run it as a VM. * Remove corporate drive and install new SSD * install corp drive in external USB-3 case * Install RHEL 7 on new SSD * dd old drive to a disk-image file in a temp location which will be an image which is the same size as your actual drive (unless you have enough space in your destination to contain a temp and converted image) * convert the raw disk-image to a qcow file while pushing it to the final location - this step should reduce the disk size - however, I believe it will only reduce/collapse zero-byte blocks (not just free space - i.e. if you de...

Sun USS 7100 foo

TIP: put ALL of your LUNs into a designated TARGET and INITIATOR group when you create them.  If you leave them in the "default" group, then everything that does an discovery against the array will find them :-( I'm struggling to recognize a reason that a default should even be present on the array. Also - who, exactly, is Sun trying to kid.  The USS is simply a box.. running Solaris .. with IPMP and ZFS.  Great.  If you have ever attempted to "break-in" or "p0wn" your IBM HMC, you know that there are people out there that can harden a box - then.. there's Sun.  After a recent meltdown at the office I had to get quite intimate with my USS 7110 and learned quite a bit.  Namely: there's a shell ;-) My current irritation is how they attempt to "warn you" away from using the shell (my coverage expired a long time ago to worry about that) and then how they try to hide things, poorly. I was curious as to what version of SunOS it ...

Extending SNMP to run arbitrary shell script

Why are we here... This is not likely something I would have pursued under normal circumstances.  I happen to be working for a customer/client who is not afforded a lot of flexibility to accomplish their goals.  In this case, the rigor is justified.  They have to sometimes be fairly creative with how they solve problems. In this case they would like to utilize an existing snmp implementation to execute a command (or shell script) on a remote system.  They came to me with the idea of using Net-SNMP extend. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sect-System_Monitoring_Tools-Net-SNMP-Extending.html NOTE:  This is NOT a good implementation strategy in the "real world"  it will simply allow you to test the functionality.  There are a TON of security implications which would need to be taken in to consideration. Implementation Steps: [root@rh7tst01 ~]# yum -y install net-snmp net-snmp-utils ...