[Fai-commit] r4859 - people/michael/features/setup_harddisks_2/implementation/lib

mt at alioth.debian.org mt at alioth.debian.org
Tue Apr 8 15:30:31 UTC 2008


Author: mt
Date: 2008-04-08 15:30:31 +0000 (Tue, 08 Apr 2008)
New Revision: 4859

Modified:
   people/michael/features/setup_harddisks_2/implementation/lib/commands.pm
   people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm
   people/michael/features/setup_harddisks_2/implementation/lib/parser.pm
   people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm
Log:
bug fixing:
- sort partition ids _numerically_ - always.
- when creating or rebuilding partitions, set a proper partition id as well


Modified: people/michael/features/setup_harddisks_2/implementation/lib/commands.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/commands.pm	2008-04-08 14:04:33 UTC (rev 4858)
+++ people/michael/features/setup_harddisks_2/implementation/lib/commands.pm	2008-04-08 15:30:31 UTC (rev 4859)
@@ -117,7 +117,7 @@
     ($config eq "RAID") or &FAI::internal_error("Invalid config $config");
 
     # create all raid devices
-    foreach my $id (sort keys %{ $FAI::configs{$config}{volumes} }) {
+    foreach my $id (sort { $a <=> $b } keys %{ $FAI::configs{$config}{volumes} }) {
 
       # keep a reference to the current volume
       my $vol = (\%FAI::configs)->{$config}->{volumes}->{$id};
@@ -344,7 +344,7 @@
   my @to_preserve = ();
 
   # find partitions that should be preserved or resized
-  foreach my $part_id ( sort keys %{ $FAI::configs{$config}{partitions} } ) {
+  foreach my $part_id ( sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} } ) {
     # reference to the current partition
     my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
     next unless ($part->{size}->{preserve} || $part->{size}->{resize});
@@ -399,14 +399,14 @@
     # if the extended partition is not listed yet, find and add it now; note
     # that we need to add the existing one
     if ($has_logical && -1 == $extended) {
-      foreach my $part_id (sort keys %{ $FAI::current_config{$disk}{partitions} }) {
+      foreach my $part_id (sort { $a <=> $b } keys %{ $FAI::current_config{$disk}{partitions} }) {
 
         # no extended partition
         next unless
           $FAI::current_config{$disk}{partitions}{$part_id}{is_extended};
 
         # find the configured extended partition to set the mapping
-        foreach my $p (sort keys %{ $FAI::configs{$config}{partitions} }) {
+        foreach my $p (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} }) {
           # reference to the current partition
           my $part = (\%FAI::configs)->{$config}->{partitions}->{$p};
           next unless $part->{size}->{extended};
@@ -485,6 +485,10 @@
         $part_nr = 4 if ( $part_nr < 4 );
       }
     }
+    
+    # restore the partition type, if any
+    my $fs =
+      $FAI::current_config{$disk}{partitions}{$mapped_id}{filesystem};
 
     # increase the partition counter for the partition created next and
     # write it to the configuration
@@ -493,7 +497,7 @@
 
     # build a parted command to create the partition
     push @FAI::commands,
-      "parted -s $disk mkpart $part_type ${start}B ${end}B";
+      "parted -s $disk mkpart $part_type $fs ${start}B ${end}B";
   }
 }
 
@@ -534,7 +538,7 @@
   my @grow_list   = ();
 
   # iterate over the worklists
-  foreach my $part_id (reverse sort (@to_preserve)) {
+  foreach my $part_id (reverse sort { $a <=> $b } (@to_preserve)) {
     # reference to the current partition
     my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
     # anything to be done?
@@ -576,9 +580,11 @@
   push @FAI::commands, "parted -s $disk mklabel " . $FAI::configs{$config}{disklabel};
 
   # generate the commands for creating all partitions
-  foreach my $part_id (sort keys %{ $FAI::configs{$config}{partitions} }) {
+  foreach my $part_id (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} }) {
     # reference to the current partition
     my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
+    # get the existing id
+    my $mapped_id = $part->{maps_to_existing};
 
     # get the new starts and ends
     my $start = $part->{start_byte};
@@ -595,9 +601,16 @@
         $part_type = "logical";
       }
     }
+    
+    my $fs = $part->{filesystem};
+    $fs = "linux-swap" if ($fs eq "swap");
+    $fs = "fat32" if ($fs eq "vfat");
+    $fs = "fat16" if ($fs eq "msdos");
+    $fs = $FAI::current_config{$disk}{partitions}{$mapped_id}{filesystem}
+      if ($part->{size}->{preserve} || $part->{size}->{resize});
 
     # build a parted command to create the partition
-    push @FAI::commands, "parted -s $disk mkpart $part_type ${start}B ${end}B";
+    push @FAI::commands, "parted -s $disk mkpart $part_type $fs ${start}B ${end}B";
   }
 
   # set the bootable flag, if requested at all
@@ -629,7 +642,7 @@
     &FAI::setup_partitions($config) unless ($FAI::configs{$config}{virtual});
     
     # generate the commands for creating all filesystems
-    foreach my $part_id ( sort keys %{ $FAI::configs{$config}{partitions} } ) {
+    foreach my $part_id ( sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} } ) {
       # reference to the current partition
       my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
 
@@ -658,7 +671,7 @@
         . $FAI::current_config{$disk}{disklabel}, 0, 0);
 
     # generate the commands for creating all partitions
-    foreach my $part_id (sort keys %{ $FAI::current_config{$disk}{partitions} }) {
+    foreach my $part_id (sort { $a <=> $b } keys %{ $FAI::current_config{$disk}{partitions} }) {
       # reference to the current partition
       my $curr_part = (\%FAI::current_config)->{$disk}->{partitions}->{$part_id};
 
@@ -677,9 +690,12 @@
           $part_type = "logical";
         }
       }
+      
+      # restore the partition type, if any
+      my $fs = $curr_part->{filesystem};
 
       # build a parted command to create the partition
-      &FAI::execute_command("parted -s $disk mkpart $part_type ${start}B ${end}B");
+      &FAI::execute_command("parted -s $disk mkpart $part_type $fs ${start}B ${end}B");
     }
     warn "Partition table of disk $disk has been restored\n";
   }

Modified: people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm	2008-04-08 14:04:33 UTC (rev 4858)
+++ people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm	2008-04-08 15:30:31 UTC (rev 4859)
@@ -108,7 +108,7 @@
         or &FAI::internal_error("fstabkey undefined");
 
       # create a line in the output file for each partition
-      foreach my $p (sort keys %{ $config->{$c}->{partitions} }) {
+      foreach my $p (sort { $a <=> $b } keys %{ $config->{$c}->{partitions} }) {
 
         # keep a reference to save some typing
         my $p_ref = $config->{$c}->{partitions}->{$p};
@@ -154,7 +154,7 @@
       my $device = $1;
 
       # create a line in the output file for each logical volume
-      foreach my $l (sort keys %{ $config->{$c}->{volumes} }) {
+      foreach my $l (sort { $a <=> $b } keys %{ $config->{$c}->{volumes} }) {
 
         # keep a reference to save some typing
         my $l_ref = $config->{$c}->{volumes}->{$l};
@@ -181,7 +181,7 @@
     } elsif ($c eq "RAID") {
 
       # create a line in the output file for each device
-      foreach my $r (sort keys %{ $config->{$c}->{volumes} }) {
+      foreach my $r (sort { $a <=> $b } keys %{ $config->{$c}->{volumes} }) {
 
         # keep a reference to save some typing
         my $r_ref = $config->{$c}->{volumes}->{$r};

Modified: people/michael/features/setup_harddisks_2/implementation/lib/parser.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/parser.pm	2008-04-08 14:04:33 UTC (rev 4858)
+++ people/michael/features/setup_harddisks_2/implementation/lib/parser.pm	2008-04-08 15:30:31 UTC (rev 4859)
@@ -147,7 +147,7 @@
   if ($type eq "primary") {
 
     # find all previously defined primary partitions
-    foreach my $part_id (sort keys %{ $FAI::configs{$FAI::device}{partitions} }) {
+    foreach my $part_id (sort { $a <=> $b } keys %{ $FAI::configs{$FAI::device}{partitions} }) {
 
       # break, if the partition has not been created by init_part_config
       defined ($FAI::configs{$FAI::device}{partitions}{$part_id}{size}{extended}) or last;
@@ -173,7 +173,7 @@
     # this branch, it has been ensured above
 
     # find the index of the new partition, initialise it to the highest current index
-    foreach my $part_id (sort keys %{ $FAI::configs{$FAI::device}{partitions} }) {
+    foreach my $part_id (sort { $a <=> $b } keys %{ $FAI::configs{$FAI::device}{partitions} }) {
 
       # skip primary partitions
       next if ($part_id < 5);
@@ -198,7 +198,7 @@
       my $extended = 0;
 
       # find all previously defined primary partitions
-      foreach my $part_id (sort keys %{ $FAI::configs{$FAI::device}{partitions} }) {
+      foreach my $part_id (sort { $a <=> $b } keys %{ $FAI::configs{$FAI::device}{partitions} }) {
 
         # break, if the partition has not been created by init_part_config
         defined ($FAI::configs{$FAI::device}{partitions}{$part_id}{size}{extended}) or last;

Modified: people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm	2008-04-08 14:04:33 UTC (rev 4858)
+++ people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm	2008-04-08 15:30:31 UTC (rev 4859)
@@ -369,7 +369,7 @@
   $part->{size}->{eff_size} = 0;
   $part->{start_byte} = -1;
 
-  foreach my $p (sort keys %{ $FAI::configs{$config}{partitions} }) {
+  foreach my $p (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} }) {
     next if ($p < 5);
 
     $part->{start_byte} = $FAI::configs{$config}{partitions}{$p}{start_byte} -
@@ -576,7 +576,7 @@
     my $current_extended = -1;
 
     # find the first existing extended partition
-    foreach my $part_id (sort keys %{ $current_disk->{partitions} }) {
+    foreach my $part_id (sort { $a <=> $b } keys %{ $current_disk->{partitions} }) {
       if ($current_disk->{partitions}->{$part_id}->{is_extended}) {
         $current_extended = $part_id;
         last;
@@ -611,7 +611,7 @@
     }
 
     # the list of partitions that we need to find start and end bytes for
-    my @worklist = (sort keys %{ $FAI::configs{$config}{partitions} });
+    my @worklist = (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} });
 
     while (scalar (@worklist))
     {
@@ -673,7 +673,7 @@
     (defined ($FAI::configs{$config}{partitions}{$_}{start_byte})
         && defined ($FAI::configs{$config}{partitions}{$_}{end_byte}))
       or &FAI::internal_error("start or end of partition $_ not set")
-        foreach (sort keys %{ $FAI::configs{$config}{partitions} });
+        foreach (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} });
   }
 }
 




More information about the Fai-commit mailing list