#!/usr/bin/perl use warnings; use strict; # Author: David Morris # Version: $Id: c2wwn,v 1.5 2004/11/05 21:01:27 davey Exp $ # Purpose: Map fibre controllers to their WWN on Solaris # License: Released under the GNU Public Licence (GPL) # The terms of the GPL are available at: # http://www.gnu.org/licenses/gpl.html # Notes: # There is a bug where you might see duplicate WWNs in the output. # See Bug Report: 4969197 Crystal-2A HBA reports incorrect WWN # Patches, 111853-03, 112244-04, 114873-02, 114874-02 # Works on Solaris, Q-Logic, Crystal-2 HBA's my $cfgadm = "/usr/sbin/cfgadm"; my $cfgadm_opt = "-v"; my $prtpicl = "/usr/sbin/prtpicl"; my $prtpicl_opt = "-v -c scsi-fcp"; open(CFG, "$cfgadm $cfgadm_opt |") or die "Cannot run $cfgadm $cfgadm_opt: $!"; my @cfgadm_out = ; # Gives us a cfgadm_out array containing: #c11 connected configured unknown #unavailable fc-fabric n /devices/pci@dd,600000/SUNW,qlc@1,1/fp@0,0:fc open(PRT, "$prtpicl $prtpicl_opt |") or die "Cannot run $cfgadm $cfgadm_opt: $!"; my @prtpicl_out = ; close CFG; close PRT; my ($spare, $spare2, $devfs, $portwwn, @report, $ln); my $oldsep = $/; sub PrtpiclProc { foreach (@prtpicl_out) { local $/ = " SUNW,qlc"; my @record = split /\n/, $_; { local $/ = $oldsep; foreach (@record) { if ( /port-wwn/ ) { ($spare,$portwwn) = split /\t/, $_ ; $portwwn =~ s/\s+//g ; #push @report, "$portwwn,"; } elsif ( /devfs-path/ ) { ($spare,$devfs) = split /\t/, $_ ; my $ctlr = CfgadmProc($devfs); push @report, "$ctlr $portwwn $devfs\n"; } } } } } sub CfgadmProc { my $cfg = shift; my $count = 0; my ($ctlr, $bobbins, $ctlrline); $cfg =~ s/\s+//g; $cfg = $cfg . "/"; foreach (@cfgadm_out) { if ( /$cfg/ ) { my $prev= $count - 1; $ctlrline = $cfgadm_out[$prev]; ($ctlr, $bobbins) = split(/ /, $ctlrline); return $ctlr; } ++$count; } } PrtpiclProc(); sunreport(); sub sunreport { my ($ctlr, $wwn, $devpath, $line); # Begin Format Definition format STDOUT_TOP = Ctlr WWN Device Path ---- ---------------- ---------------------------- . # End Format Definition format STDOUT = @>>> @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<< $ctlr, $wwn, $devpath . foreach $line (@report) { ($ctlr, $wwn, $devpath) = split / +/, $line; write; } } __DATA__ __END__