From: Andrea R. <ar...@sy...> - 2006-05-28 17:02:04
|
Author: arighi Date: 2006-05-28 12:01:54 -0500 (Sun, 28 May 2006) New Revision: 3604 Modified: trunk/lib/SystemImager/Server.pm Log: fix: change mdadm command to be compliant with disk autodetection Modified: trunk/lib/SystemImager/Server.pm =================================================================== --- trunk/lib/SystemImager/Server.pm 2006-05-28 15:30:23 UTC (rev 3603) +++ trunk/lib/SystemImager/Server.pm 2006-05-28 17:01:54 UTC (rev 3604) @@ -304,7 +304,27 @@ return @dev_list; } +# Description: +# Returns a list of all disks from a given autoinstallscript.conf +# file. +# +# Usage: +# get_all_disks($file) +# +sub get_all_disks($) { + my ($file) = @_; + my @dev_list = (); + + my $fs_config = XMLin($file, keyattr => { disk => "+dev", part => "+num" }, forcearray => 1 ); + foreach my $key (keys %{$fs_config->{disk}}) { + push @dev_list, $key; + } + + return @dev_list; +} + + # Description: # A sort for raid controller device names # @@ -855,6 +875,7 @@ print $out qq(modprobe raid10\n); my $xml = XMLin($file, keyattr => { raid => "+name" }, forcearray => 1 ); + my @all_devices = reverse(get_all_disks($file)); # mdadm --create $name \ # --chunk $chunk_size \ @@ -865,6 +886,23 @@ foreach my $md ( sort (keys %{$xml->{raid}}) ) { + my @devices = split(/ /, $xml->{raid}->{$md}->{devices}); + my $part_list = ''; + + # Translate partitions in disk variables (disk autodetection compliant). + foreach my $part (@devices) { + my $i = 0; + foreach my $dev (@all_devices) { + if ($part =~ /^$dev(.+)$/) { + $part_list .= ' ${DISK'.$i.'}'.$1; + goto next_part; + } + $i++; + } + print "WARNING: partition $part doesn't belong to any disk!\n"; + next_part: + } + my $cmd = qq(mdadm --create $md \\\n); $cmd .= qq( --auto yes \\\n); $cmd .= qq( --level $xml->{raid}->{$md}->{raid_level} \\\n) if($xml->{raid}->{$md}->{raid_level}); @@ -879,7 +917,7 @@ $xml->{raid}->{$md}->{chunk_size} =~ s/K$//; $cmd .= qq( --chunk $xml->{raid}->{$md}->{chunk_size} \\\n); } - $cmd .= qq( $xml->{raid}->{$md}->{devices}\n); + $cmd .= qq( $part_list\n); print $out "\nlogmsg \"$cmd\""; print $out "\n$cmd\n"; |