From 4be29179df81601bf92cd61cb4be89aebd81991b Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 30 Dec 2009 11:12:55 -0800 Subject: [PATCH] Fix 3ward disk counting --- smart-status/smart-status-lib.pl | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/smart-status/smart-status-lib.pl b/smart-status/smart-status-lib.pl index 7d5cb6f23..cd95fb12d 100755 --- a/smart-status/smart-status-lib.pl +++ b/smart-status/smart-status-lib.pl @@ -57,7 +57,9 @@ foreach my $d (&fdisk::list_disks_partitions()) { # underlying real disks, so add fake devices for them foreach my $twdev (keys %tcount) { next if (!-r $twdev.$tcount{$twdev}); - my $count = &count_subdisks($d, "3ware", + my $count = &count_3ware_subdisks($d, $tcount{$twdev}) + || + &count_subdisks($d, "3ware", $twdev.$tcount{$twdev}); next if (!$count); for(my $i=0; $i<$count; $i++) { @@ -94,6 +96,26 @@ return sort { $a->{'device'} cmp $b->{'device'} || $a->{'subdisk'} <=> $b->{'subdisk'} } @rv; } +=head2 count_3ware_subdisks(&drive, number) + +Returns the number of underlying hard drives in a 3ware device, or undef +if we can't work this out. + +=cut +sub count_3ware_subdisks +{ +local ($d, $n) = @_; +local $out = &backquote_command("tw_cli info c$n"); +return undef if ($?); +local $max_disk; +foreach my $l (split(/\r?\n/, $out)) { + if ($l =~ /^p(\d+)\s+/ && $1 >= $max_disk) { + $max_disk = $1; + } + } +return $max_disk; +} + =head2 count_subdisks(&drive, type, [device]) Returns the number of sub-disks for a hardware RAID device, by calling