[Fai-commit] r3616 -
people/michael/features/setup_harddisks_2/implementation
fai-commit at lists.alioth.debian.org
fai-commit at lists.alioth.debian.org
Sat Jul 22 14:46:19 UTC 2006
Author: michael-guest
Date: 2006-07-22 14:46:18 +0000 (Sat, 22 Jul 2006)
New Revision: 3616
Added:
people/michael/features/setup_harddisks_2/implementation/shdd2-lib
Modified:
people/michael/features/setup_harddisks_2/implementation/NOTES
people/michael/features/setup_harddisks_2/implementation/shdd2
people/michael/features/setup_harddisks_2/implementation/shdd2-parser
people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
Log:
size computation is complete for ordinary disks
Modified: people/michael/features/setup_harddisks_2/implementation/NOTES
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/NOTES 2006-07-22 14:39:27 UTC (rev 3615)
+++ people/michael/features/setup_harddisks_2/implementation/NOTES 2006-07-22 14:46:18 UTC (rev 3616)
@@ -1 +1,6 @@
libparse-recdescent-perl must get installed in nfsroot
+
+auto mode
+
+query commands
+
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2 2006-07-22 14:39:27 UTC (rev 3615)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2 2006-07-22 14:46:18 UTC (rev 3616)
@@ -2,6 +2,7 @@
use strict;
+require "shdd2-lib";
require "shdd2-init";
require "shdd2-parser";
require "shdd2-sizes";
Added: people/michael/features/setup_harddisks_2/implementation/shdd2-lib
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-lib 2006-07-22 14:39:27 UTC (rev 3615)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-lib 2006-07-22 14:46:18 UTC (rev 3616)
@@ -0,0 +1,24 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+package FAI;
+
+sub in_path
+{
+ my ($filesystem) = @_;
+
+ my @path_list = split(":", $ENV{"PATH"});
+
+ foreach my $p (@path_list)
+ {
+ if( -x $p."/mkfs.$filesystem")
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+1;
+
Property changes on: people/michael/features/setup_harddisks_2/implementation/shdd2-lib
___________________________________________________________________
Name: svn:executable
+ *
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-parser
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-parser 2006-07-22 14:39:27 UTC (rev 3615)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-parser 2006-07-22 14:46:18 UTC (rev 3616)
@@ -103,12 +103,12 @@
| volume
disk_config_arg: 'raid'
{
- #check wether raid tools are available
+ #TODO: check, whether raid tools are available
$FAI::device = "RAID";
}
| 'lvm'
{
- #check wether lvm tools are available
+ #TODO: check, whether lvm tools are available
$FAI::device = "VG_";
}
| 'end'
@@ -146,7 +146,7 @@
option(s?)
| /^\S+/
{
- # check for valid device name
+ # TODO check for valid device name
if( $item[ 1 ] =~ m{^/} )
{
$FAI::device = "PHY_" . $item[ 1 ];
@@ -183,7 +183,7 @@
$FAI::configs{ $FAI::device }{ "partitions" }{ $id }{ "size" }{ "resize" } = 1;
}
}
- | /^disklabel:(msdos|sun)/
+ | /^disklabel:(msdos|sun|gpt|mac)/
{
$FAI::configs{ $FAI::device }{ "disklabel" } = $1;
}
@@ -197,13 +197,6 @@
}
volume: type mountpoint size filesystem mount_options fs_options
| 'vg' name size
- {
- if( ! $FAI::device =~ /^VG_/ )
- {
- die "vg is invalid in a non LVM-context.\n";
- }
- # TODO create vg
- }
type: 'primary'
{
( $FAI::device =~ /^PHY_/ ) or die "wrong partition type";
@@ -264,6 +257,14 @@
$FAI::partition_pointer->{ "mountpoint" } = $item[ 1 ];
}
name: /^\S+/
+ {
+ if( ! $FAI::device =~ /^VG_/ )
+ {
+ die "vg is invalid in a non LVM-context.\n";
+ }
+ $FAI::device = "VG_" . $item[ 1 ];
+ $FAI::partition_pointer = (\%FAI::configs)->{ $FAI::device };
+ }
size: /^(\d+%?(-(\d+%?)?)?)(:resize)?\s+/
{
my $range = $1;
@@ -312,14 +313,14 @@
}
| /^[^\d,:\s\-][^,:\s]*(:(spare|missing))*(,[^,:\s]+(:(spare|missing))*)*\s+/
{
- if( $FAI::device ne "RAID" )
+ if( $FAI::device ne "RAID" || ! ( $FAI::device =~ /^VG_/ ) )
{
warn "invalid within this context\n";
}
else
{
- $FAI::partition_pointer->{ "size" }->{ "range" } = -1;
- $FAI::partition_pointer->{ "size" }->{ "devices" } = $item[ 0 ];
+ $FAI::partition_pointer->{ "devices" } = $item[ 0 ];
+ # TODO parse and check for validity
}
}
| <error: invalid partition size near "$text">
@@ -344,26 +345,12 @@
$FAI::partition_pointer->{ "filesystem" } = $item[ 1 ];
}
fs_options: /.*/
+ {
+ $FAI::partition_pointer->{ "fs_options" } = $item[ 1 ];
+ }
});
-sub in_path
-{
- my ($filesystem) = @_;
-
- my @path_list = split(":", $ENV{"PATH"});
-
- foreach my $p (@path_list)
- {
- if( -x $p."/mkfs.$filesystem")
- {
- return 1;
- }
- }
- return 0;
-
-}
-
sub print_hash
{
my ($hash_ref, $k) = @_;
@@ -393,13 +380,11 @@
defined $Parser->file( $input ) or die "Syntax error\n";
-&print_hash(\%FAI::configs);
my @fstab = &FAI::generate_fstab(\%FAI::configs);
foreach my $line (@fstab)
{
printf $line."\n";
}
-
1;
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-sizes 2006-07-22 14:39:27 UTC (rev 3615)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-sizes 2006-07-22 14:46:18 UTC (rev 3616)
@@ -2,6 +2,8 @@
use strict;
+use POSIX qw(ceil floor);
+
package FAI;
%FAI::current_config = ();
@@ -12,9 +14,7 @@
{
$disk = "/dev/" . $disk;
}
- $FAI::current_config{ $disk } = {
- "partitions" => {}
- };
+ $FAI::current_config{ $disk }{ "partitions" } = {};
my @parted_print = split( "\n", `/sbin/parted -s $disk unit TB print` );
my $parted_fs_start = 0;
@@ -28,9 +28,7 @@
}
elsif( $line =~ /^Disk label type: (.*)$/ )
{
- $FAI::current_config{ $disk } = {
- "disklabel" => $1
- };
+ $FAI::current_config{ $disk }{ "disklabel" } = $1;
next;
}
elsif( $line =~ /^Number/ )
@@ -59,9 +57,7 @@
my $id = $1;
$line =~ /^.{$parted_fs_start}(.{$parted_fs_end})/;
my $fs = $1;
- $FAI::current_config{ $disk }{ "partitions" }{ $id } = {
- "filesystem" => $fs
- };
+ $FAI::current_config{ $disk }{ "partitions" }{ $id }{ "filesystem" } = $fs;
}
}
@@ -73,26 +69,16 @@
if( $line =~ /^(\d+)*\s+(\d+)B\s+(\d+)B\s+(\d+)B/i )
{
- $FAI::current_config{ $disk }{ "partitions" }{ $1 } = {
- "begin_byte" => $2,
- "end_byte" => $3,
- "count_byte" => $4
- };
+ $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( $line =~ /^Disk geometry for.*(\d+)B - (\d+)B/i )
{
- $FAI::current_config{ $disk } = {
- "begin_byte" => $1,
- "end_byte" => $2
- }
+ $FAI::current_config{ $disk }{ "begin_byte" } = $1;
+ $FAI::current_config{ $disk }{ "end_byte" } = $2;
}
-
- # if( $line =~ /^Disk label type:\s*(\w*)\s*/i )
- # {
- #
- # printf $1;
- # }
}
}
@@ -105,55 +91,139 @@
if( $line =~ /^(\d+)\s+(\d+),(\d+),(\d+)\s+(\d+),(\d+),(\d+)/i )
{
- $FAI::current_config{ $disk }{ "partitions" }{ $1 } = {
- "begin_cylinder" => $2,
- "begin_head" => $3,
- "begin_sector" => $4,
- "end_cylinder" => $5,
- "end_head" => $6,
- "end_sector" => $7
- };
-
+ $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,
- "begin_head" => $2,
- "begin_sector" => $3,
- "end_cylinder" => $4,
- "end_head" => $5,
- "end_sector" => $6
- };
+ $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 )
{
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;
+
foreach my $part_id ( sort keys %{ $FAI::configs{ $config }{ "partitions" } } )
{
if( $FAI::configs{ $config }{ "partitions" }{ $part_id }{ "size" }{ "extended" } == 1 )
{
+ ( $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 )
{
- my $part_size = $FAI::configs{ $config }{ "partitions" }{ $part_id }{
- "size" }{ "range" };
+ if( $FAI::configs{ $config }{ "partitions" }{ $part_id }{ "size" }{ "range" } =~ /^(\d+%?)-(\d+%?)$/ )
+ {
+ 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
+ {
+ warn "invalid range\n";
+ }
}
- # compute size of extended later on
+ 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+%?)$/ )
+ {
+ my $start = $1;
+ my $end = $2;
+ $FAI::configs{ $config }{ "partitions" }{ $part_id }{ "size" }{ "eff_size" } = POSIX::floor( $start + ( ( $end - $start ) * $redist_factor ) );
+ }
+ else
+ {
+ warn "invalid range\n";
+ }
+ }
+ }
+
+ if( $FAI::configs{ $config }{ "disklabel" } ne "msdos" && $extended > -1 )
+ {
+ warn "extended partitions are not supported by this disklabel\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
{
@@ -161,5 +231,7 @@
}
}
+&print_hash(\%FAI::configs);
+
1;
More information about the Fai-commit
mailing list