From 80dadc0c749f5521377808360e4e9fa7aff7389b Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Thu, 19 Nov 2020 19:42:08 +0000 Subject: Fix a crash when detecting a mdadm RAID array (mga#26707) get_hds() did not handle the case of a mdadm RAID array created using raw devices instead of partitions. The drakx tools never do this, but the user may have done it another way. --- perl-install/fsedit.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'perl-install/fsedit.pm') diff --git a/perl-install/fsedit.pm b/perl-install/fsedit.pm index e53648a37..d209b0196 100644 --- a/perl-install/fsedit.pm +++ b/perl-install/fsedit.pm @@ -82,11 +82,11 @@ sub recompute_loopbacks { } sub raids { - my ($hds) = @_; + my ($hds, $raw_hds) = @_; my @parts = fs::get::hds_fstab(@$hds); - my @l = grep { isRawRAID($_) } @parts or return []; + my @l = grep { isRawRAID($_) } ( @parts, @$raw_hds ) or return []; log::l("looking for raids in " . join(' ', map { $_->{device} } @l)); @@ -197,6 +197,20 @@ sub get_hds { foreach my $hd (@drives) { $hd->{readonly} = $flags->{readonly}; + #- We only create RAID components in disk partitions, but users may have used + #- mdadm directly to create them on raw disk devices. Detect that now, before + #- looking for a partition table (which is likely to fail badly - mga#26707). + if (my $type = fs::type::type_subpart_from_magic($hd)) { + if (isRawRAID($type)) { + #- Add the necessary information to the raw device to allow the RAID + #- array to be properly characterised in diskdrake. + put_in_hash($hd, $type); + $hd->{size} = $hd->{totalsectors}; + push @raw_hds, $hd; + next; + } + } + eval { partition_table::raw::test_for_bad_drives($hd) if !$flags->{no_bad_drives} }; if (my $err = $@) { log::l("test_for_bad_drives returned $err"); @@ -310,7 +324,7 @@ Do you agree to lose all the partitions? } #- detect raids before LVM allowing LVM on raid - my $raids = raids(\@hds); + my $raids = raids(\@hds, \@raw_hds); my $all_hds = { %{ fs::get::empty_all_hds() }, hds => \@hds, raw_hds => \@raw_hds, lvms => [], raids => $raids }; $all_hds->{lvms} = [ lvms($all_hds) ]; -- cgit v1.2.1