Use UUIDs in mdadm.conf when creating new arrays, thanks to Caspar Smit

This commit is contained in:
Jamie Cameron
2015-01-06 16:43:49 -08:00
parent 65ee16aad9
commit c8b4672cc8
4 changed files with 45 additions and 18 deletions

View File

@@ -79,16 +79,29 @@ elsif ($in{'group_mode'} == 2) {
'value' => $in{'newgroup'} });
}
&create_raid($raid);
&unlock_raid_files();
if ($raid_mode eq "raidtools") {
# Create config before actually creating RAID.
&create_raid($raid);
}
if ($err = &make_raid($raid, $in{'force'}, $in{'missing'}, $in{'assume'})) {
&delete_raid($raid);
if ($raid_mode eq "raidtools") {
&delete_raid($raid);
}
&error($err);
}
elsif ($in{'level'} != 0) {
# Set RAID to read/write mode after creation except for RAID0 which is automatically set to read/write.
&readwrite_raid($raid);
}
elsif ($raid_mode eq "mdadm") {
# Create config after actually creating RAID to be able to get UUID.
$uuid = &get_uuid($raid);
&create_raid($raid, $uuid);
if ($in{'level'} != 0) {
# Set RAID to read/write mode after creation except for RAID0 which is automatically set to read/write.
&readwrite_raid($raid);
}
}
&unlock_raid_files();
&webmin_log("create", undef, $in{'device'}, \%in);
&redirect("");

View File

@@ -67,6 +67,7 @@ create_o3_layout=3 Offset Copies
view_title=RAID Device
view_header=RAID device options
view_device=Device file
view_uuid=UUID
view_level=RAID level
view_status=Filesystem status
view_errors=RAID errors

View File

@@ -177,6 +177,11 @@ else {
{ 'name' => 'parity-algorithm',
'value' => $1 });
}
elsif (/^\s+UUID\s+:\s*(.*)/) {
push(@{$md->{'members'}},
{ 'name' => 'array-uuid',
'value' => $1 });
}
}
close(MDSTAT);
local $lastdev;
@@ -216,6 +221,19 @@ else {
return \@get_raidtab_cache;
}
# get_uuid(&raid)
# Get the UUID of an mdadm RAID after creation.
sub get_uuid
{
open(MDSTAT, "mdadm --detail $_[0]->{'value'} |");
while(<MDSTAT>) {
if (/^\s+UUID\s+:\s*(.*)/) {
return $1;
}
}
close(MDSTAT);
}
# disk_errors(string)
# Converts an mdstat errors string into an array of disk statuses
sub disk_errors
@@ -255,19 +273,10 @@ if ($raid_mode eq "raidtools") {
&flush_file_lines();
}
else {
# Add to /etc/mdadm.conf
local ($d, @devices);
foreach $d (&find("device", $_[0]->{'members'})) {
push(@devices, $d->{'value'});
}
# Add to mdadm.conf
local $sg = &find_value("spare-group", $_[0]->{'members'});
local $lref = &read_file_lines($config{'mdadm'});
local $lvl = &find_value('raid-level', $_[0]->{'members'});
$lvl = $lvl =~ /^\d+$/ ? "raid$lvl" : $lvl;
push(@$lref, "DEVICE ".
join(" ", map { &device_to_volid($_) } @devices));
push(@$lref, "ARRAY $_[0]->{'value'} level=$lvl devices=".
join(",", @devices).
push(@$lref, "ARRAY $_[0]->{'value'} uuid=$_[1]".
($sg ? " spare-group=$sg" : ""));
&flush_file_lines();
&update_initramfs();

View File

@@ -20,6 +20,10 @@ print &ui_table_start($text{'view_header'}, undef, 2);
# Device name
print &ui_table_row($text{'view_device'}, "<tt>$raid->{'value'}</tt>");
# UUID
$uuid = &find_value('array-uuid', $raid->{'members'});
print &ui_table_row($text{'view_uuid'}, $uuid);
# RAID level
$lvl = &find_value('raid-level', $raid->{'members'});
print &ui_table_row($text{'view_level'},