From 5276a3dc84d84116b49fb63107c5a72e2cfdbc6e Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Wed, 27 Jul 2005 09:43:44 +0000 Subject: backport of dmraid support --- perl-install/any.pm | 2 +- perl-install/bootloader.pm | 13 ++++++++----- perl-install/devices.pm | 38 +++++++++++++++++++++---------------- perl-install/fs/dmraid.pm | 3 ++- perl-install/fs/type.pm | 2 ++ perl-install/fsedit.pm | 27 +++++++++++++++++++++++++- perl-install/install2.pm | 3 ++- perl-install/install_any.pm | 1 + perl-install/partition_table/raw.pm | 29 +++++++++++++++------------- 9 files changed, 80 insertions(+), 38 deletions(-) diff --git a/perl-install/any.pm b/perl-install/any.pm index 75e430e80..d82b8b56b 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -256,7 +256,7 @@ sub setupBootloader__general { my ($in, $b, $all_hds, $fstab, $security) = @_; return if is_xbox(); - my @method_choices = bootloader::method_choices($fstab); + my @method_choices = bootloader::method_choices($all_hds); my $prev_force_acpi = my $force_acpi = bootloader::get_append_with_key($b, 'acpi') !~ /off|ht/; my $prev_force_noapic = my $force_noapic = bootloader::get_append_simple($b, 'noapic'); my $prev_force_nolapic = my $force_nolapic = bootloader::get_append_simple($b, 'nolapic'); diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm index e97395979..16caeddb3 100644 --- a/perl-install/bootloader.pm +++ b/perl-install/bootloader.pm @@ -819,7 +819,7 @@ wait for default boot. $bootloader->{default} ||= $preferred; } $bootloader->{default} ||= "linux"; - $bootloader->{method} ||= first(method_choices($fstab)); + $bootloader->{method} ||= first(method_choices($all_hds)); } sub detect_main_method { @@ -853,13 +853,16 @@ sub method_choices_raw() { ); } sub method_choices { - my ($fstab) = @_; + my ($all_hds) = @_; + my $fstab = [ fs::get::fstab($all_hds) ]; my $root_part = fs::get::root($fstab); + my $boot_part = fs::get::root($fstab, 'boot'); + my $boot_disk = fs::get::part2hd($boot_part, $all_hds); grep { - !(/lilo/ && isLoopback($root_part)) - && !(/lilo-graphic/ && detect_devices::matching_desc__regexp('ProSavageDDR')) - && !(/grub/ && isRAID($root_part)); + (!/lilo/ || !isLoopback($root_part) && !fs::type::is_dmraid($boot_disk)) + && (!/lilo-graphic/ || !detect_devices::matching_desc__regexp('ProSavageDDR')) + && (!/grub/ || !isRAID($root_part)); } method_choices_raw(); } diff --git a/perl-install/devices.pm b/perl-install/devices.pm index 513c1714a..1b6798041 100644 --- a/perl-install/devices.pm +++ b/perl-install/devices.pm @@ -75,12 +75,17 @@ sub find_clp_loop { undef; } +sub get_dynamic_major { + my ($name) = @_; + cat_('/proc/devices') =~ /^(\d+) \Q$name\E$/m && $1; +} + sub init_device_mapper() { eval { modules::load('dm-mod') }; make('urandom'); my $control = '/dev/mapper/control'; if (! -e $control) { - my ($major) = cat_('/proc/devices') =~ /(\d+) misc$/m or return; + my ($major) = get_dynamic_major('misc') or return; my ($minor) = cat_('/proc/misc') =~ /(\d+) device-mapper$/m or return; mkdir_p(dirname($control)); syscall_('mknod', $control, c::S_IFCHR() | 0600, makedev($major, $minor)) or die "mknod $control failed: $!"; @@ -132,21 +137,22 @@ sub entry { $type = c::S_IFBLK(); $major = 114; $minor = 16 * $1 + ($2 || 0); - } elsif (/(.*?)(\d+)$/) { - ($type, $major, $minor) = - @{ ${{"fd" => [ c::S_IFBLK(), 2, 0 ], - "hidbp-mse-" => [ c::S_IFCHR(), 10, 32 ], - "lp" => [ c::S_IFCHR(), 6, 0 ], - "usb/lp" => [ c::S_IFCHR(), 180, 0 ], - "input/event" => [ c::S_IFCHR(), 13, 64 ], - "loop" => [ c::S_IFBLK(), 7, 0 ], - "md" => [ c::S_IFBLK(), 9, 0 ], - "nst" => [ c::S_IFCHR(), 9, 128 ], - "sr" => [ c::S_IFBLK(), 11, 0 ], - "ttyS" => [ c::S_IFCHR(), 4, 64 ], - "ubd/" => [ c::S_IFBLK(), 98, 0 ], - }}{$1} }; - $minor += $2; + } elsif (my ($prefix, $nb) = /(.*?)(\d+)$/) { + my $f = ${{"fd" => sub { c::S_IFBLK(), 2, 0 }, + "hidbp-mse-" => sub { c::S_IFCHR(), 10, 32 }, + "lp" => sub { c::S_IFCHR(), 6, 0 }, + "usb/lp" => sub { c::S_IFCHR(), 180, 0 }, + "input/event" => sub { c::S_IFCHR(), 13, 64 }, + "loop" => sub { c::S_IFBLK(), 7, 0 }, + "md" => sub { c::S_IFBLK(), 9, 0 }, + "nst" => sub { c::S_IFCHR(), 9, 128 }, + "sr" => sub { c::S_IFBLK(), 11, 0 }, + "ttyS" => sub { c::S_IFCHR(), 4, 64 }, + "ubd/" => sub { c::S_IFBLK(), 98, 0 }, + "dm-" => sub { c::S_IFBLK(), get_dynamic_major('device-mapper'), 0 }, + }}{$prefix} or internal_error("unknown device $prefix $nb"); + ($type, $major, $minor) = $f->(); + $minor += $nb; } unless ($type) { ($type, $major, $minor) = diff --git a/perl-install/fs/dmraid.pm b/perl-install/fs/dmraid.pm index 7bc5d9162..b716c6aa8 100644 --- a/perl-install/fs/dmraid.pm +++ b/perl-install/fs/dmraid.pm @@ -87,7 +87,8 @@ sub _sets() { sub vgs() { map { my $dev = "mapper/$_->{name}"; - my $vg = fs::wild_device::to_subpart("/dev/$dev"); + my $vg = fs::subpart_from_wild_device_name("/dev/$dev"); + add2hash($vg, { media_type => 'hd', prefix => $dev, bus => "dmraid_$_->{format}", disks => $_->{disks} }); #- device should exist, created by dmraid(8) using libdevmapper diff --git a/perl-install/fs/type.pm b/perl-install/fs/type.pm index 841d6e12b..79ee51fe3 100644 --- a/perl-install/fs/type.pm +++ b/perl-install/fs/type.pm @@ -343,6 +343,8 @@ sub isMounted { $_[0]{isMounted} } sub isBusy { isMounted($_[0]) || isPartOfRAID($_[0]) || isPartOfLVM($_[0]) || isPartOfLoopback($_[0]) } sub isSpecial { isRAID($_[0]) || isLVM($_[0]) || isLoopback($_[0]) || isUBD($_[0]) } +sub is_dmraid { $_[0]{bus} =~ /^dmraid_/ } + sub can_be_this_fs_type { my ($part, $fs_type) = @_; can_be_one_of_those_fs_types($part, $fs_type); diff --git a/perl-install/fsedit.pm b/perl-install/fsedit.pm index 6f28ff6fe..de6e2d037 100644 --- a/perl-install/fsedit.pm +++ b/perl-install/fsedit.pm @@ -96,6 +96,28 @@ sub lvms { @lvms; } +sub handle_dmraid { + my ($drives) = @_; + + @$drives > 1 or return; + + devices::make($_->{device}) foreach @$drives; + + eval { require fs::dmraid; 1 } or return; + + my @vgs = fs::dmraid::vgs(); + log::l(sprintf('dmraid: ' . join(' ', map { "$_->{device} [" . join(' ', @{$_->{disks}}) . "]" } @vgs))); + + my @used_hds = map { + my $part = fs::get::device2part($_, $drives) or log::l("handle_dmraid: can't find $_ in known drives"); + if_($part, $part); + } map { @{$_->{disks}} } @vgs; + + @$drives = difference2($drives, \@used_hds); + + push @$drives, @vgs; +} + sub get_hds { my ($o_flags, $o_in) = @_; my $flags = $o_flags || {}; @@ -103,6 +125,9 @@ sub get_hds { my @drives = detect_devices::hds(); + #- replace drives used in dmraid by the merged name + handle_dmraid(\@drives); + foreach my $hd (@drives) { $hd->{file} = devices::make($hd->{device}); $hd->{prefix} ||= $hd->{device}; @@ -163,7 +188,7 @@ sub get_hds { if (listlength(partition_table::get_normal_parts($hd)) == 0) { $handled = 1 if $handle_die_and_cdie->(); } else { - compare_with_proc_partitions($hd) if $::isInstall; + compare_with_proc_partitions($hd) if !fs::type::is_dmraid($hd) && $::isInstall; } } sub { my $err = $@; diff --git a/perl-install/install2.pm b/perl-install/install2.pm index 7a0356c06..77a113c35 100644 --- a/perl-install/install2.pm +++ b/perl-install/install2.pm @@ -213,7 +213,8 @@ sub formatPartitions { raid::prepare_prefixed($o->{all_hds}{raids}); #- needed by lilo - if (my @vgs = map { $_->{VG_name} } @{$o->{all_hds}{lvms}}) { + if (-d '/dev/mapper') { + my @vgs = map { $_->{VG_name} } @{$o->{all_hds}{lvms}}; cp_af("/dev/$_", "$::prefix/dev") foreach 'mapper', @vgs; } } diff --git a/perl-install/install_any.pm b/perl-install/install_any.pm index 26ad0865d..a5d24e241 100644 --- a/perl-install/install_any.pm +++ b/perl-install/install_any.pm @@ -824,6 +824,7 @@ sub default_packages { push @l, "numlock" if $o->{miscellaneous}{numlock}; push @l, "mdadm" if !is_empty_array_ref($o->{all_hds}{raids}); push @l, "lvm2" if !is_empty_array_ref($o->{all_hds}{lvms}); + push @l, "dmraid" if any { fs::type::is_dmraid($_) } @{$o->{all_hds}{hds}}; push @l, "alsa", "alsa-utils" if any { $o->{modules_conf}->get_alias("sound-slot-$_") =~ /^snd-/ } 0 .. 4; push @l, map { if_($_->{driver} =~ /^Pkg:(.*)/, $1) } detect_devices::probeall(); diff --git a/perl-install/partition_table/raw.pm b/perl-install/partition_table/raw.pm index db1d40584..c78680bb5 100644 --- a/perl-install/partition_table/raw.pm +++ b/perl-install/partition_table/raw.pm @@ -149,22 +149,25 @@ sub get_geometries { sub get_geometry { my ($dev) = @_; - my $g = ""; - sysopen(my $F, $dev, 0) or return; - ioctl($F, c::HDIO_GETGEO(), $g) or return; - my %geom; @geom{qw(heads sectors cylinders start)} = unpack "CCSL", $g; - $geom{totalcylinders} = $geom{cylinders}; - - my $total; - #- $geom{cylinders} is no good (only a ushort, that means less than 2^16 => at best 512MB) - if ($total = c::total_sectors(fileno $F)) { - compute_nb_cylinders(\%geom, $total); - } else { - $total = $geom{heads} * $geom{sectors} * $geom{cylinders}; + + my $total = c::total_sectors(fileno $F); + + my $g = ""; + my %geom; + if (ioctl($F, c::HDIO_GETGEO(), $g)) { + @geom{qw(heads sectors cylinders start)} = unpack "CCSL", $g; + $geom{totalcylinders} = $geom{cylinders}; + + #- $geom{cylinders} is no good (only a ushort, that means less than 2^16 => at best 512MB) + if ($total) { + compute_nb_cylinders(\%geom, $total); + } else { + $total = $geom{heads} * $geom{sectors} * $geom{cylinders}; + } } - { geom => \%geom, totalsectors => $total }; + { totalsectors => $total, if_($geom{heads}, geom => \%geom) }; } sub openit { -- cgit v1.2.1