diff options
Diffstat (limited to 'perl-install/fs/dmraid.pm')
-rw-r--r-- | perl-install/fs/dmraid.pm | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/perl-install/fs/dmraid.pm b/perl-install/fs/dmraid.pm index 80ba3de39..7a279abc7 100644 --- a/perl-install/fs/dmraid.pm +++ b/perl-install/fs/dmraid.pm @@ -1,4 +1,4 @@ -package fs::dmraid; # $Id: dmraid.pm 265309 2010-01-27 00:28:23Z pterjan $ +package fs::dmraid; use diagnostics; use strict; @@ -14,23 +14,54 @@ use fs::wild_device; use run_program; +=head1 SYNOPSYS + +Manage fake RAIDs using dmraid + +=head1 Functions + +=over + +=item init() + +Load kernel modules, init device mapper then scan for fake RAIDs. + +=cut + sub init() { whereis_binary('dmraid') or die "dmraid not installed"; eval { modules::load('dm-mirror', 'dm-zero') }; devices::init_device_mapper(); if ($::isInstall) { - call_dmraid('-ay'); + foreach my $name (call_dmraid('-s', '-c', '-i')) { + chomp($name); + log::l("got: $name"); + call_dmraid('-ay', '-i', '--rm_partitions', '-p', $name); + run_program::run('/sbin/kpartx', '-u', '-a', '/dev/mapper/' . $name); + } } 1; } -#- call_dmraid is overloaded when debugging, see the end of this file +=item call_dmraid($option, @args) + +Runs dmraid with $option & @args. +It is overloaded when debugging, see the end of this file. + +=cut + sub call_dmraid { my ($option, @args) = @_; run_program::get_stdout('dmraid', $option, @args); } +=item check($in) + +Ensures dmraid is installed. If yes, calls init(). + +=cut + sub check { my ($in) = @_; @@ -39,19 +70,26 @@ sub check { 1; } +=item _raid_devices_raw() + +Get the real VG names, needed for ddf1, and safer than begins_with for raid10 + +=cut + sub _raid_devices_raw() { - # get the real vg names, needed for ddf1, and safer than begins_with for raid10 log::l("_raid_devices_raw"); my %vgs; my %pv2vg = map { + chomp(); log::l("got: $_"); my %l; @l{qw(name size stride level status subsets devs spares)} = split(':'); $vgs{$l{name}} = 1 if defined $l{spares}; if (/freeing device "(.*)", path "(.*)"/ && defined $vgs{$1}) { log::l("$2 => $1"); - { $2 => $1 } + $2 => $1; } - } call_dmraid('-d', '-s', '-c', '-c'); + } call_dmraid(qw(-d -s -c -c)); + map { chomp; log::l("got: $_"); @@ -61,7 +99,7 @@ sub _raid_devices_raw() { $l{vg} = $pv2vg{$l{pv}}; } if_(defined $l{size}, \%l); - } call_dmraid('-r', '-c', '-c'); + } call_dmraid(qw(-r -c -c)); } sub _raid_devices() { @@ -108,6 +146,12 @@ sub _sets() { @sets; } +=item vgs() + +Returns the list of VGs corresponding to dmraid + +=cut + sub vgs() { map { my $dev = "mapper/$_->{name}"; @@ -116,7 +160,12 @@ sub vgs() { #- device should exist, created by dmraid(8) using libdevmapper #- if it doesn't, we suppose it's not in use - if_(-e "/dev/$dev", $vg); + if (-e "/dev/$dev") { + $vg; + } else { + log::l("ignoring $dev as /dev/$dev doesn't exist"); + (); + } } grep { if ($_->{status} eq 'ok') { @@ -128,11 +177,15 @@ sub vgs() { } _sets(); } -# the goal is to handle migration from /dev/mapper/xxx1 to /dev/mapper/xxxp1, -# as used by initrd/nash. -# dmraid has been patched to follow xxxp1 device names. -# so until the box has rebooted on new initrd/dmraid, we must cope with /dev/mapper/xxx1 device names -# (cf #44182) +=item migrate_device_names ($vg) + +Handles migration from /dev/mapper/xxx1 to /dev/mapper/xxxp1, as used by initrd/nash. +dmraid has been patched to follow xxxp1 device names. +So until the box has rebooted on new initrd/dmraid, we must cope with /dev/mapper/xxx1 device names +(cf mdk#44182) + +=cut + sub migrate_device_names { my ($vg) = @_; @@ -148,6 +201,14 @@ sub migrate_device_names { } } +=back + +=head1 Debugging + +If $ENV{DRAKX_DEBUG_DMRAID} is set, debugging dmraid is done. +The C<call_dmraid()> function is overloaded and will spit out warnings. +=cut + if ($ENV{DRAKX_DEBUG_DMRAID}) { eval(<<'EOF'); my %debug_data = ( |