[Fai-commit] r3627 - people/michael/features/setup_harddisks_2/implementation

fai-commit at lists.alioth.debian.org fai-commit at lists.alioth.debian.org
Sat Jul 22 22:25:40 UTC 2006


Author: michael-guest
Date: 2006-07-22 22:25:39 +0000 (Sat, 22 Jul 2006)
New Revision: 3627

Modified:
   people/michael/features/setup_harddisks_2/implementation/shdd2
   people/michael/features/setup_harddisks_2/implementation/shdd2-commands
   people/michael/features/setup_harddisks_2/implementation/shdd2-fstab
   people/michael/features/setup_harddisks_2/implementation/shdd2-init
   people/michael/features/setup_harddisks_2/implementation/shdd2-parser
   people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
Log:
moved to functions


Modified: people/michael/features/setup_harddisks_2/implementation/shdd2
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2	2006-07-22 22:12:30 UTC (rev 3626)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2	2006-07-22 22:25:39 UTC (rev 3627)
@@ -2,6 +2,8 @@
 
 use strict;
 
+package FAI;
+
 require "shdd2-lib";
 require "shdd2-init";
 require "shdd2-parser";
@@ -10,3 +12,24 @@
 require "shdd2-fstab";
 require "shdd2-exec";
 
+&FAI::run_parser;
+
+&FAI::get_current_disks;
+
+&FAI::compute_sizes;
+
+&FAI::print_hash( \%FAI::configs );
+
+&FAI::build_commands;
+
+foreach my $cmd (@FAI::commands)
+{
+  print $cmd . "\n";
+}
+
+my @fstab = &FAI::generate_fstab( \%FAI::configs );
+foreach my $line (@fstab)
+{
+  printf $line. "\n";
+}
+

Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-commands
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-commands	2006-07-22 22:12:30 UTC (rev 3626)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-commands	2006-07-22 22:25:39 UTC (rev 3627)
@@ -4,102 +4,176 @@
 
 package FAI;
 
- at FAI::commands = ();
+sub build_commands
+{
 
-$FAI::parted_binary = "/sbin/parted -s";
+  #TODO: remove
+  $FAI::current_config{"/dev/hda"}{"disklabel"} = "msdos";
 
-foreach my $config ( keys %FAI::configs )
-{
-  if ( $config eq "RAID" || $config =~ /^VG_/ )
+  foreach my $config ( keys %FAI::configs )
   {
+    if ( $config eq "RAID" || $config =~ /^VG_/ )
+    {
 
-    # compute the sizes of lvms
-    next;
-  }
-  elsif ( $config =~ /^PHY_(.*)$/ )
-  {
-    my $disk        = $1;
-    my @to_preserve = ();
-    my $extended    = -1;
+      # compute the sizes of lvms
+      next;
+    }
+    elsif ( $config =~ /^PHY_(.*)$/ )
+    {
+      my $disk        = $1;
+      my @to_preserve = ();
+      my $extended    = -1;
 
-    my $target_label = $FAI::configs{$config}{'disklabel'};
-    my $source_label = $FAI::current_config{$disk}{'disklabel'};
+      my $target_label = $FAI::configs{$config}{'disklabel'};
+      my $source_label = $FAI::current_config{$disk}{'disklabel'};
 
-    foreach
-      my $part_id ( sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
-    {
-      if ( $FAI::current_config{$disk}{"disklabel"} eq "msdos"
-        && $FAI::current_config{$disk}{$part_id}{"is_extended"} == 1 )
+      foreach
+        my $part_id ( sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
       {
-        $extended = $part_id;
+        if ( $FAI::current_config{$disk}{"disklabel"} eq "msdos"
+          && $FAI::current_config{$disk}{"partitions"}{$part_id}
+          {"is_extended"} == 1 )
+        {
+          $extended = $part_id;
+        }
       }
-    }
 
-    foreach my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
-    {
+      foreach
+        my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
+      {
 
-      if (
-        $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} == 1
-        || $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} ==
-        1 )
+        if (
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
+          1
+          || $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} ==
+          1 )
+        {
+          if ( !defined( $FAI::current_config{$disk}{"partitions"}{$part_id} ) )
+          {
+            warn "$part_id can't be preserved, it does not exist.\n";
+          }
+          else
+          {
+            push @to_preserve, $part_id;
+            if ( $extended > -1
+              && $part_id > 4
+              && $FAI::current_config{$disk}{"disklabel"} eq "msdos" )
+            {
+              push @to_preserve, $extended;
+              $extended = -1;
+            }
+          }
+        }
+
+      }
+      @to_preserve = sort { $a <=> $b } @to_preserve;
+
+      if ( $target_label ne $source_label )
       {
-        if ( !defined( $FAI::current_config{$disk}{"partitions"}{$part_id} ) )
+        if ( scalar(@to_preserve) > 0 )
         {
-          warn "$part_id can't be preserved, it does not exist.\n";
+          warn "Can't change disklabel, partitions are to be preserved!\n";
         }
         else
         {
-          push @to_preserve, $part_id;
-          if ( $extended > -1
-            && $part_id > 4
-            && $FAI::current_config{$disk}{"disklabel"} eq "msdos" )
+          push @FAI::commands,
+            "$FAI::parted_binary $disk mklabel $target_label";
+        }
+      }
+      else
+      {
+        foreach my $part_id (
+          sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
+        {
+          if ( $to_preserve[0] == $part_id )
           {
-            push @to_preserve, $extended;
-            $extended = -1;
+            shift @to_preserve;
+            next;
           }
+          push @FAI::commands, "$FAI::parted_binary $disk rm $part_id";
         }
       }
 
-    }
-    @to_preserve = sort { $a <=> $b } @to_preserve;
+      my $next_start = 0;
 
-    if ( $target_label ne $source_label )
-    {
-      if ( scalar(@to_preserve) > 0 )
-      {
-        warn "Can't change disklabel, partitions are to be preserved!\n";
-      }
-      else
-      {
-        push @FAI::commands, "$FAI::parted_binary $disk mklabel $target_label";
-      }
-    }
-    else
-    {
       foreach
-        my $part_id ( sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
+        my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
       {
-        if ( $to_preserve[0] == $part_id )
+        print "testing $part_id\n";
+        if (
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
+          1 )
         {
-          shift @to_preserve;
-          next;
+          if ( !defined( $FAI::current_config{$disk}{"partitions"}{$part_id} ) )
+          {
+            warn "$part_id can't be preserved, it does not exist.\n";
+          }
+          unless ( $FAI::configs{$config}{"disklabel"} eq "msdos"
+            && $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+            {"extended"} == 1 )
+          {
+            $next_start =
+              $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"} +
+              1;
+          }
         }
-        push @FAI::commands, "$FAI::parted_binary $disk rm $part_id";
+        elsif (
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} ==
+          1 )
+        {
+          if ( !defined( $FAI::current_config{$disk}{"partitions"}{$part_id} ) )
+          {
+            warn "$part_id can't be resized, it does not exist.\n";
+          }
+          elsif ( $FAI::current_config{$disk}{"partitions"}{"filesystem"} ne
+            $FAI::configs{$config}{"partitions"}{$part_id}{"filesystem"} )
+          {
+            warn "Filesystem change has been requested for $part_id, can't
+            resize\n";
+          }
+          my $part_size =
+            $FAI::configs{$config}{"partitions"}{"size"}{"eff_size"} +
+            $next_start - 1;
+          push @FAI::commands,
+            "$FAI::parted_binary $disk resize $part_id $next_start" . "B "
+            . $part_size . "B";
+          unless ( $FAI::configs{$config}{"disklabel"} eq "msdos"
+            && $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+            {"extended"} == 1 )
+          {
+            $next_start = $part_size + 1;
+          }
+        }
+        else
+        {
+          my $part_type = "primary";
+          if ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
+          {
+            if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+              {"extended"} == 1 )
+            {
+              $part_type = "extended";
+            }
+            elsif ( $part_id > 4 )
+            {
+              $part_type = "logical";
+            }
+          }
+          my $part_size =
+            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} +
+            $next_start - 1;
+          push @FAI::commands,
+            "$FAI::parted_binary $disk mkpart $part_type $next_start" . "B "
+            . $part_size . "B";
+          unless ( $FAI::configs{$config}{"disklabel"} eq "msdos"
+            && $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+            {"extended"} == 1 )
+          {
+            $next_start = $part_size + 1;
+          }
+        }
       }
     }
-
-    foreach my $cmd (@FAI::commands)
-    {
-      print $cmd . "\n";
-    }
-
-    foreach
-      my $part_id ( sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
-    {
-    }
-    foreach my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
-    {
-    }
   }
 }
 

Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-fstab
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-fstab	2006-07-22 22:12:30 UTC (rev 3626)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-fstab	2006-07-22 22:25:39 UTC (rev 3627)
@@ -74,11 +74,5 @@
   }
 }
 
-my @fstab = &FAI::generate_fstab( \%FAI::configs );
-foreach my $line (@fstab)
-{
-  printf $line. "\n";
-}
-
 1;
 

Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-init
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-init	2006-07-22 22:12:30 UTC (rev 3626)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-init	2006-07-22 22:25:39 UTC (rev 3627)
@@ -16,5 +16,13 @@
 
 @FAI::disks = split( /\n/, $ENV{disklist} );
 
+%FAI::configs = ();
+
+%FAI::current_config = ();
+
+ at FAI::commands = ();
+
+$FAI::parted_binary = "/sbin/parted -s";
+
 1;
 

Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-parser
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-parser	2006-07-22 22:12:30 UTC (rev 3626)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-parser	2006-07-22 22:25:39 UTC (rev 3627)
@@ -2,8 +2,6 @@
 
 use strict;
 
-require "shdd2-fstab";
-
 #
 # file ::= <lines> EOF
 #
@@ -84,13 +82,11 @@
 
 package FAI;
 
-%FAI::configs = ();
-
 $FAI::device                    = "";
 $FAI::partition_primary_counter = 0;
 $FAI::partition_logical_counter = 0;
 
-my $Parser = Parse::RecDescent->new(
+$FAI::Parser = Parse::RecDescent->new(
   q{
     file: line(s?) /\Z/
     line: <skip: qr/[ \t]*/> "\\n"
@@ -134,7 +130,7 @@
               "virtual" => 0,
               "disklabel" => "msdos",
               "bootable" => -1,
-              "partitions" => ()
+              "partitions" => {}
             };
           }
           else
@@ -202,11 +198,14 @@
           {
             ( $FAI::partition_primary_counter < 4 || $FAI::configs{ $FAI::device }{ "disklabel" } ne "msdos" ) or die "Too many primary partitions\n";
             $FAI::partition_primary_counter++;
-            $FAI::configs{ $FAI::device }{ "partitions" }{ $FAI::partition_primary_counter }= {};
+            if( ! defined( $FAI::configs{ $FAI::device }{ "partitions" }{ $FAI::partition_primary_counter } ) )
+            {
+              $FAI::configs{ $FAI::device }{ "partitions" }{ $FAI::partition_primary_counter }= {};
+            }
             $FAI::partition_pointer = (\%FAI::configs)->{ $FAI::device }->{ "partitions" }->{ $FAI::partition_primary_counter };
             $FAI::partition_pointer->{ "size" }->{ "extended" } = 0;
             $FAI::partition_pointer->{ "number" } = $FAI::partition_primary_counter;
-            if( ! defined( $FAI::partition_pointer->{ "size" }{ "preserve" } ) )
+            if( ! defined( $FAI::partition_pointer->{ "size" }->{ "preserve" } ) )
             {
               $FAI::partition_pointer->{ "size" }->{ "preserve" } = 0;
             }
@@ -231,11 +230,14 @@
               }
             }
             $FAI::partition_logical_counter++;
-            $FAI::configs{ $FAI::device }{ "partitions" }{ $FAI::partition_logical_counter + 4 }= {};
+            if( ! defined( $FAI::configs{ $FAI::device }{ "partitions" }{ $FAI::partition_logical_counter + 4 } ) )
+            {
+              $FAI::configs{ $FAI::device }{ "partitions" }{ $FAI::partition_logical_counter + 4 }= {};
+            }
             $FAI::partition_pointer = (\%FAI::configs)->{ $FAI::device }->{ "partitions" }->{ $FAI::partition_logical_counter + 4 };
             $FAI::partition_pointer->{ "size" }->{ "extended" } = 0;
             $FAI::partition_pointer->{ "number" } = $FAI::partition_logical_counter + 4;
-            if( ! defined( $FAI::partition_pointer->{ "size" }{ "preserve" } ) )
+            if( ! defined( $FAI::partition_pointer->{ "size" }->{ "preserve" } ) )
             {
               $FAI::partition_pointer->{ "size" }->{ "preserve" } = 0;
             }
@@ -294,7 +296,7 @@
           $FAI::partition_pointer->{ "size" } = {
             "range" => "0" . $1
           };
-          if( defined( $2 ) || defined( $FAI::partition_pointer->{ "size" }{ "resize" } ) )
+          if( defined( $2 ) || defined( $FAI::partition_pointer->{ "size" }->{ "resize" } ) )
           {
             $FAI::partition_pointer->{ "size" }->{ "resize" } = 1;
           }
@@ -354,14 +356,17 @@
 }
 );
 
-my $ifs = $/;
-undef $/;
-my $input = <STDIN>;
-$/ = $ifs;
+sub run_parser
+{
+  my $ifs = $/;
+  undef $/;
+  my $input = <STDIN>;
+  $/ = $ifs;
 
-print "Input was:\n" . $input;
+  print "Input was:\n" . $input;
 
-defined $Parser->file($input) or die "Syntax error\n";
+  defined $FAI::Parser->file($input) or die "Syntax error\n";
+}
 
 1;
 

Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-sizes	2006-07-22 22:12:30 UTC (rev 3626)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-sizes	2006-07-22 22:25:39 UTC (rev 3627)
@@ -6,274 +6,282 @@
 
 package FAI;
 
-%FAI::current_config = ();
-
-foreach my $disk (@FAI::disks)
+sub get_current_disks
 {
-  if ( !( $disk =~ m{^/} ) )
+  foreach my $disk (@FAI::disks)
   {
-    $disk = "/dev/" . $disk;
-  }
-  $FAI::current_config{$disk}{"partitions"} = {};
+    if ( !( $disk =~ m{^/} ) )
+    {
+      $disk = "/dev/" . $disk;
+    }
+    $FAI::current_config{$disk}{"partitions"} = {};
 
-  my @parted_print    = split( "\n", `/sbin/parted -s $disk unit TB print` );
-  my $parted_fs_start = 0;
-  my $parted_fs_end   = 0;
+    my @parted_print    = split( "\n", `/sbin/parted -s $disk unit TB print` );
+    my $parted_fs_start = 0;
+    my $parted_fs_end   = 0;
 
-  foreach my $line (@parted_print)
-  {
-    if ( $line =~ /^Disk geometry/ )
+    foreach my $line (@parted_print)
     {
-      next;
-    }
-    elsif ( $line =~ /^Disk label type: (.*)$/ )
-    {
-      $FAI::current_config{$disk}{"disklabel"} = $1;
-      next;
-    }
-    elsif ( $line =~ /^Number/ )
-    {
-      $parted_fs_start = 0;
-      $parted_fs_end   = 0;
-      my @chars = split( "", $line );
-      foreach my $char (@chars)
+      if ( $line =~ /^Disk geometry/ )
       {
-        $parted_fs_end++;
-        if ( $char eq "F" )
+        next;
+      }
+      elsif ( $line =~ /^Disk label type: (.*)$/ )
+      {
+        $FAI::current_config{$disk}{"disklabel"} = $1;
+        next;
+      }
+      elsif ( $line =~ /^Number/ )
+      {
+        $parted_fs_start = 0;
+        $parted_fs_end   = 0;
+        my @chars = split( "", $line );
+        foreach my $char (@chars)
         {
-          $parted_fs_start = $parted_fs_end;
+          $parted_fs_end++;
+          if ( $char eq "F" )
+          {
+            $parted_fs_start = $parted_fs_end;
+          }
+          elsif ( $char eq "m" && $parted_fs_start > 0 )
+          {
+            last;
+          }
         }
-        elsif ( $char eq "m" && $parted_fs_start > 0 )
-        {
-          last;
-        }
+        $parted_fs_start--;
+        $parted_fs_end -= $parted_fs_start;
       }
-      $parted_fs_start--;
-      $parted_fs_end -= $parted_fs_start;
+      else
+      {
+        $line =~ /^(\d+)/;
+        my $id = $1;
+        $line =~ /^.{$parted_fs_start}(.{$parted_fs_end})/;
+        my $fs = $1;
+        $FAI::current_config{$disk}{"partitions"}{$id}{"filesystem"} = $fs;
+      }
     }
-    else
-    {
-      $line =~ /^(\d+)/;
-      my $id = $1;
-      $line =~ /^.{$parted_fs_start}(.{$parted_fs_end})/;
-      my $fs = $1;
-      $FAI::current_config{$disk}{"partitions"}{$id}{"filesystem"} = $fs;
-    }
-  }
 
-  @parted_print = split( "\n", `/sbin/parted -s $disk unit B print` );
-  {
-    foreach my $line (@parted_print)
+    @parted_print = split( "\n", `/sbin/parted -s $disk unit B print` );
     {
-      if ( $FAI::current_config{$disk}{"disklabel"} eq "msdos" )
+      foreach my $line (@parted_print)
       {
-        if ( $line =~
-          /^(\d+)*\s+(\d+)B\s+(\d+)B\s+(\d+)B\s+(primary|logical|extended)/i )
+        if ( $FAI::current_config{$disk}{"disklabel"} eq "msdos" )
         {
+          if ( $line =~
+            /^(\d+)*\s+(\d+)B\s+(\d+)B\s+(\d+)B\s+(primary|logical|extended)/i )
+          {
 
-          $FAI::current_config{$disk}{"partitions"}{$1}{"begin_byte"} = $2;
-          $FAI::current_config{$disk}{"partitions"}{$1}{"end_byte"}   = $3;
-          $FAI::current_config{$disk}{"partitions"}{$1}{"count_byte"} = $4;
-          if ( $5 eq "extended" )
-          {
-            $FAI::current_config{$disk}{"partitions"}{$1}{"is_extended"} = 1;
+            $FAI::current_config{$disk}{"partitions"}{$1}{"begin_byte"} = $2;
+            $FAI::current_config{$disk}{"partitions"}{$1}{"end_byte"}   = $3;
+            $FAI::current_config{$disk}{"partitions"}{$1}{"count_byte"} = $4;
+            if ( $5 eq "extended" )
+            {
+              $FAI::current_config{$disk}{"partitions"}{$1}{"is_extended"} = 1;
+            }
+            else
+            {
+              $FAI::current_config{$disk}{"partitions"}{$1}{"is_extended"} = 0;
+            }
           }
-          else
+        }
+        else
+        {
+          if ( $line =~ /^(\d+)*\s+(\d+)B\s+(\d+)B\s+(\d+)B/i )
           {
+
+            $FAI::current_config{$disk}{"partitions"}{$1}{"begin_byte"}  = $2;
+            $FAI::current_config{$disk}{"partitions"}{$1}{"end_byte"}    = $3;
+            $FAI::current_config{$disk}{"partitions"}{$1}{"count_byte"}  = $4;
             $FAI::current_config{$disk}{"partitions"}{$1}{"is_extended"} = 0;
           }
         }
-      }
-      else
-      {
-        if ( $line =~ /^(\d+)*\s+(\d+)B\s+(\d+)B\s+(\d+)B/i )
+
+        if ( $line =~ /^Disk geometry for.*(\d+)B - (\d+)B/i )
         {
-
-          $FAI::current_config{$disk}{"partitions"}{$1}{"begin_byte"}  = $2;
-          $FAI::current_config{$disk}{"partitions"}{$1}{"end_byte"}    = $3;
-          $FAI::current_config{$disk}{"partitions"}{$1}{"count_byte"}  = $4;
-          $FAI::current_config{$disk}{"partitions"}{$1}{"is_extended"} = 0;
+          $FAI::current_config{$disk}{"begin_byte"} = $1;
+          $FAI::current_config{$disk}{"end_byte"}   = $2;
         }
       }
-
-      if ( $line =~ /^Disk geometry for.*(\d+)B - (\d+)B/i )
-      {
-        $FAI::current_config{$disk}{"begin_byte"} = $1;
-        $FAI::current_config{$disk}{"end_byte"}   = $2;
-      }
     }
-  }
 
-  @parted_print = split( "\n", `/sbin/parted -s $disk unit chs print` );
-  {
-    foreach my $line (@parted_print)
+    @parted_print = split( "\n", `/sbin/parted -s $disk unit chs print` );
     {
-
-      if ( $line =~ /^(\d+)\s+(\d+),(\d+),(\d+)\s+(\d+),(\d+),(\d+)/i )
+      foreach my $line (@parted_print)
       {
-        $FAI::current_config{$disk}{"partitions"}{$1}{"begin_cylinder"} = $2;
-        $FAI::current_config{$disk}{"partitions"}{$1}{"begin_head"}     = $3;
-        $FAI::current_config{$disk}{"partitions"}{$1}{"begin_sector"}   = $4;
-        $FAI::current_config{$disk}{"partitions"}{$1}{"end_cylinder"}   = $5;
-        $FAI::current_config{$disk}{"partitions"}{$1}{"end_head"}       = $6;
-        $FAI::current_config{$disk}{"partitions"}{$1}{"end_sector"}     = $7;
-      }
 
-      if (
-        $line =~ /^Disk geometry for.*(\d+),(\d+),(\d+) - (\d+),(\d+),(\d+)/i )
-      {
-        $FAI::current_config{$disk}{"begin_cylinder"} = $1;
-        $FAI::current_config{$disk}{"begin_head"}     = $2;
-        $FAI::current_config{$disk}{"begin_sector"}   = $3;
-        $FAI::current_config{$disk}{"end_cylinder"}   = $4;
-        $FAI::current_config{$disk}{"end_head"}       = $5;
-        $FAI::current_config{$disk}{"end_sector"}     = $6;
+        if ( $line =~ /^(\d+)\s+(\d+),(\d+),(\d+)\s+(\d+),(\d+),(\d+)/i )
+        {
+          $FAI::current_config{$disk}{"partitions"}{$1}{"begin_cylinder"} = $2;
+          $FAI::current_config{$disk}{"partitions"}{$1}{"begin_head"}     = $3;
+          $FAI::current_config{$disk}{"partitions"}{$1}{"begin_sector"}   = $4;
+          $FAI::current_config{$disk}{"partitions"}{$1}{"end_cylinder"}   = $5;
+          $FAI::current_config{$disk}{"partitions"}{$1}{"end_head"}       = $6;
+          $FAI::current_config{$disk}{"partitions"}{$1}{"end_sector"}     = $7;
+        }
+
+        if ( $line =~
+          /^Disk geometry for.*(\d+),(\d+),(\d+) - (\d+),(\d+),(\d+)/i )
+        {
+          $FAI::current_config{$disk}{"begin_cylinder"} = $1;
+          $FAI::current_config{$disk}{"begin_head"}     = $2;
+          $FAI::current_config{$disk}{"begin_sector"}   = $3;
+          $FAI::current_config{$disk}{"end_cylinder"}   = $4;
+          $FAI::current_config{$disk}{"end_head"}       = $5;
+          $FAI::current_config{$disk}{"end_sector"}     = $6;
+        }
       }
     }
   }
 }
 
-# &print_hash( \%FAI::current_config );
-
-foreach my $config ( keys %FAI::configs )
+sub compute_sizes
 {
-  if ( $config eq "RAID" || $config =~ /^VG_/ )
+  foreach my $config ( keys %FAI::configs )
   {
+    if ( $config eq "RAID" || $config =~ /^VG_/ )
+    {
 
-    # compute the sizes of lvms
-    next;
-  }
-  elsif ( $config =~ /^PHY_(.*)$/ )
-  {
-    my $extended      = -1;
-    my $disk          = $1;
-    my $redist_space  = 0;
-    my $min_req_space = 0;
+      # compute the sizes of lvms
+      next;
+    }
+    elsif ( $config =~ /^PHY_(.*)$/ )
+    {
+      my $extended      = -1;
+      my $disk          = $1;
+      my $redist_space  = 0;
+      my $min_req_space = 0;
 
-    foreach my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
-    {
-      if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"extended"} ==
-        1 )
+      foreach
+        my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
       {
-        ( $extended == -1 ) or warn "more than 1 extended partition\n";
-        ( $part_id <= 4 )
-          or warn "extended partition won't be a primary one\n";
-        $extended = $part_id;
-        $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} = 0;
-      }
-      elsif (
-        $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
-        0 )
-      {
-        if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =~
-          /^(\d+%?)-(\d+%?)$/ )
+        if (
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"extended"} ==
+          1 )
         {
-          my $start = $1;
-          my $end   = $2;
-          if ( $start =~ /^(\d+)%$/ )
+          ( $extended == -1 ) or warn "more than 1 extended partition\n";
+          ( $part_id <= 4 )
+            or warn "extended partition won't be a primary one\n";
+          $extended = $part_id;
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
+            0;
+        }
+        elsif (
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
+          0 )
+        {
+          if (
+            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =~
+            /^(\d+%?)-(\d+%?)$/ )
           {
-            $start =
-              POSIX::floor(
-              $FAI::current_config{$disk}{"end_byte"} * $1 / 100 );
+            my $start = $1;
+            my $end   = $2;
+            if ( $start =~ /^(\d+)%$/ )
+            {
+              $start =
+                POSIX::floor(
+                $FAI::current_config{$disk}{"end_byte"} * $1 / 100 );
+            }
+            else
+            {
+              $start = $start * 1024.0 * 1024.0;
+            }
+            if ( $end =~ /^(\d+)%$/ )
+            {
+              $end =
+                POSIX::ceil(
+                $FAI::current_config{$disk}{"end_byte"} * $1 / 100 );
+            }
+            else
+            {
+              $end = $end * 1024.0 * 1024.0;
+            }
+            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =
+              $start . "-" . $end;
+            if ( $end == $start )
+            {
+              $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+                {"eff_size"} = $start;
+            }
+            else
+            {
+              $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+                {"eff_size"} = -1;
+              $redist_space += $end - $start;
+            }
+            $min_req_space += $start;
           }
           else
           {
-            $start = $start * 1024.0 * 1024.0;
+            warn "invalid range\n";
           }
-          if ( $end =~ /^(\d+)%$/ )
+        }
+        else
+        {
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
+            $FAI::current_config{$disk}{"partitions"}{$part_id}{"count_byte"};
+          $min_req_space +=
+            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"};
+        }
+      }
+
+      if ( $min_req_space > $FAI::current_config{$disk}{"end_byte"} )
+      {
+        warn "Disk is too small - at least $min_req_space is required\n";
+      }
+
+      my $redist_factor =
+        ( $FAI::current_config{$disk}{"end_byte"} - $min_req_space ) /
+        $redist_space;
+      print "redist factor is $redist_factor\n";
+
+      foreach
+        my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
+      {
+        if (
+          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} ==
+          -1 )
+        {
+          if (
+            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =~
+            /^(\d+%?)-(\d+%?)$/ )
           {
-            $end =
-              POSIX::ceil( $FAI::current_config{$disk}{"end_byte"} * $1 / 100 );
-          }
-          else
-          {
-            $end = $end * 1024.0 * 1024.0;
-          }
-          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =
-            $start . "-" . $end;
-          if ( $end == $start )
-          {
+            my $start = $1;
+            my $end   = $2;
             $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
-              $start;
+              POSIX::floor( $start + ( ( $end - $start ) * $redist_factor ) );
           }
           else
           {
-            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
-              -1;
-            $redist_space += $end - $start;
+            warn "invalid range\n";
           }
-          $min_req_space += $start;
         }
-        else
-        {
-          warn "invalid range\n";
-        }
       }
-      else
+
+      if ( $FAI::configs{$config}{"disklabel"} ne "msdos" && $extended > -1 )
       {
-        $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
-          $FAI::current_config{$disk}{"partitions"}{$part_id}{"count_byte"};
-        $min_req_space +=
-          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"};
+        warn "extended partitions are not supported by this disklabel\n";
       }
-    }
 
-    if ( $min_req_space > $FAI::current_config{$disk}{"end_byte"} )
-    {
-      warn "Disk is too small - at least $min_req_space is required\n";
-    }
-
-    my $redist_factor =
-      ( $FAI::current_config{$disk}{"end_byte"} - $min_req_space ) /
-      $redist_space;
-    print "redist factor is $redist_factor\n";
-
-    foreach my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
-    {
-      if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} ==
-        -1 )
+      if ( $FAI::configs{$config}{"disklabel"} eq "msdos" && $extended > -1 )
       {
-        if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =~
-          /^(\d+%?)-(\d+%?)$/ )
+        my $extended_size = 0;
+        foreach
+          my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
         {
-          my $start = $1;
-          my $end   = $2;
-          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
-            POSIX::floor( $start + ( ( $end - $start ) * $redist_factor ) );
+          next if ( $part_id <= 4 );
+          $extended_size +=
+            $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"};
         }
-        else
-        {
-          warn "invalid range\n";
-        }
+        $FAI::configs{$config}{"partitions"}{$extended}{"size"}{"eff_size"} =
+          $extended_size;
       }
     }
-
-    if ( $FAI::configs{$config}{"disklabel"} ne "msdos" && $extended > -1 )
+    else
     {
-      warn "extended partitions are not supported by this disklabel\n";
+      warn "Internal error (invalid config entry $config).\n";
     }
-
-    if ( $FAI::configs{$config}{"disklabel"} eq "msdos" && $extended > -1 )
-    {
-      my $extended_size = 0;
-      foreach
-        my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
-      {
-        next if ( $part_id <= 4 );
-        $extended_size +=
-          $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"};
-      }
-      $FAI::configs{$config}{"partitions"}{$extended}{"size"}{"eff_size"} =
-        $extended_size;
-    }
   }
-  else
-  {
-    warn "Internal error (invalid config entry $config).\n";
-  }
 }
 
-&print_hash( \%FAI::configs );
-
 1;
 




More information about the Fai-commit mailing list