Add support for spare groups
authorJamie Cameron <jcameron@webmin.com>
Fri, 14 Aug 2009 21:36:10 +0000 (14:36 -0700)
committerJamie Cameron <jcameron@webmin.com>
Fri, 14 Aug 2009 21:36:10 +0000 (14:36 -0700)
raid/CHANGELOG
raid/create_raid.cgi
raid/index.cgi
raid/lang/en
raid/raid-lib.pl
raid/raid_form.cgi
raid/view_raid.cgi

index 666a593..559bc11 100644 (file)
@@ -22,3 +22,4 @@ Added an option to the RAID 1 creation form to mark one of the disks as missing
 Run the update-initramfs -u command after changing mdadm.conf, to sync it into any ramdisk for use at boot time.
 ---- Changes since 1.480 ----
 Raw disks with no partitions can now also be used as RAID members.
+Spare groups can now be created and used when creating a RAID device.
index cb2a0e7..dd4b47a 100755 (executable)
@@ -65,6 +65,18 @@ if ($in{'pdisk'}) {
                                          'value' => 0 } ] } );
        }
 
+# Parse spare group
+if ($in{'group_mode'} == 1) {
+       push(@members, { 'name' => 'spare-group',
+                        'value' => $in{'group'} });
+       }
+elsif ($in{'group_mode'} == 2) {
+       $in{'newgroup'} =~ /^[a-z0-9\_]+$/i ||
+               &error($text{'create_enewgroup'});
+       push(@members, { 'name' => 'spare-group',
+                        'value' => $in{'newgroup'} });
+       }
+
 &create_raid($raid);
 &unlock_raid_files();
 if ($err = &make_raid($raid, $in{'force'}, $in{'missing'})) {
index 4ffb1b7..df4d133 100755 (executable)
@@ -1,5 +1,4 @@
 #!/usr/local/bin/perl
-# index.cgi
 # Display all RAID devices
 
 require './raid-lib.pl';
index cd2c73b..ffe93b3 100644 (file)
@@ -50,6 +50,11 @@ create_edisks=No partitions selected
 create_edisks2=At least 2 partitions must be selected for mirroring
 create_espare=Spare partition $1 cannot also be a RAID partition
 create_epdisk=Parity partition cannot also be a RAID partition
+create_group=Member of spare group
+create_nogroup=None (use own spares only)
+create_oldgroup=Existing group
+create_newgroup=New group
+create_enewgroup=Missing or non-alphnumeric spare group name
 
 view_title=RAID Device
 view_header=RAID device options
@@ -94,6 +99,7 @@ view_newmount2=Mount RAID as Virtual Memory
 view_mountmsg=Enter a directory and click this button to go to a form for mounting the RAID device, which must already contain a filesystem.
 view_mountmsg2=Click this button to use this RAID device for virtual memory on your system.
 view_blocks=$1 blocks
+view_sparegroup=Spare group
 
 mkfs_title=Create Filesystem
 mkfs_header2=This form allows you to build a new $2 filesystem on $1. <b>All</b> existing data will be erased!
index e7c6e75..063d51d 100755 (executable)
@@ -170,6 +170,23 @@ else {
                close(MDSTAT);
                push(@get_raidtab_cache, $md);
                }
+
+       # Merge in info from mdadm.conf
+       local $lref = &read_file_lines($config{'mdadm'});
+       foreach my $l (@$lref) {
+               if ($l =~ /^ARRAY\s+(\S+)\s*(.*)/) {
+                       local $dev = $1;
+                       local %opts = map { split(/=/, $_, 2) }
+                                         split(/\s+/, $2);
+                       local ($md) = grep { $_->{'value'} eq $dev }
+                                          @get_raidtab_cache;
+                       if ($md) {
+                               push(@{$md->{'members'}},
+                                       { 'name' => 'spare-group',
+                                         'value' => $opts{'spare-group'} });
+                               }
+                       }
+               }
        }
 return \@get_raidtab_cache;
 }
@@ -218,12 +235,14 @@ else {
        foreach $d (&find("device", $_[0]->{'members'})) {
                push(@devices, $d->{'value'});
                }
+       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(" ", @devices));
        push(@$lref, "ARRAY $_[0]->{'value'} level=$lvl devices=".
-                    join(",", @devices));
+                    join(",", @devices).
+                    ($sg ? " spare-group=$sg" : ""));
        &flush_file_lines();
        &update_initramfs();
        }
index bc5bb0e..293c252 100755 (executable)
@@ -87,6 +87,24 @@ if ($lvl == 1 && $raid_mode eq 'mdadm') {
                &ui_yesno_radio("missing", 0));
        }
 
+# Spare-group name option
+if ($raid_mode eq 'mdadm') {
+       @opts = ( [ 0, $text{'create_nogroup'} ] );
+       @groups = ( );
+       foreach $c (@$conf) {
+               $sg = &find_value("spare-group", $c->{'members'});
+               push(@groups, $sg) if ($sg);
+               }
+       if (@groups) {
+               push(@opts, [ 1, $text{'create_oldgroup'},
+                             &ui_select("group", undef, \@groups) ]);
+               }
+       push(@opts, [ 2, $text{'create_newgroup'},
+                     &ui_textbox("newgroup", undef, 30) ]);
+       print &ui_table_row($text{'create_group'},
+               &ui_radio_table("group_mode", 0, \@opts, 1));
+       }
+
 # Force creation
 print &ui_table_row($text{'create_force'},
        &ui_yesno_radio("force", 0));
index 5a27568..5f2f872 100755 (executable)
@@ -121,6 +121,13 @@ foreach $d (@devs) {
 if ($sp) {
        print &ui_table_row($text{'view_spares'}, $sp);
        }
+
+# Display spare group, if any
+$sg = &find_value("spare-group", $raid->{'members'});
+if ($sg) {
+       print &ui_table_row($text{'view_sparegroup'}, "<tt>$sg</tt>");
+       }
+
 print &ui_table_end();
 
 print &ui_hr();