[Fai-commit] r3672 -
people/michael/features/setup_harddisks_2/implementation
fai-commit at lists.alioth.debian.org
fai-commit at lists.alioth.debian.org
Sun Jul 23 22:05:49 UTC 2006
Author: michael-guest
Date: 2006-07-23 22:05:48 +0000 (Sun, 23 Jul 2006)
New Revision: 3672
Modified:
people/michael/features/setup_harddisks_2/implementation/shdd2-commands
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:
minor fixes of bugs introduced with the prior commit, started commenting and
improving shdd2-sizes. Good night guys!
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-commands
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-commands 2006-07-23 20:26:11 UTC (rev 3671)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-commands 2006-07-23 22:05:48 UTC (rev 3672)
@@ -195,7 +195,7 @@
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} +
$next_start - 1;
push @FAI::commands,
- "$FAI::system_commands{'parted'} $disk mkpart $part_type $next_start"
+"$FAI::system_commands{'parted'} $disk mkpart $part_type $next_start"
. "B "
. $part_size . "B";
unless ( $FAI::configs{$config}{"disklabel"} eq "msdos"
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-init
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-init 2006-07-23 20:26:11 UTC (rev 3671)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-init 2006-07-23 22:05:48 UTC (rev 3672)
@@ -88,15 +88,15 @@
################################################################################
#
-# @brief A map of commands
+# @brief A map of commands
#
# TODO check for availability, exact version?
#
################################################################################
-%FAI::system_commands = {
- mdadm => "/sbin/mdadm",
- parted => "/sbin/parted -s"
-};
+%FAI::system_commands = (
+ "mdadm" => "/sbin/mdadm",
+ "parted" => "/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-23 20:26:11 UTC (rev 3671)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-parser 2006-07-23 22:05:48 UTC (rev 3672)
@@ -348,6 +348,7 @@
q{
file: line(s?) /\Z/
{
+ $return = 1;
}
line: <skip: qr/[ \t]*/> "\\n"
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-sizes 2006-07-23 20:26:11 UTC (rev 3671)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-sizes 2006-07-23 22:05:48 UTC (rev 3672)
@@ -24,7 +24,7 @@
#
# @file shdd2-sizes
#
-# @brief A set of functions to obtain the current partition table and to
+# @brief A set of functions to obtain the current partition table and to
# compute the size of the partitions to be created
#
# $Id$
@@ -40,61 +40,127 @@
################################################################################
#
-# @brief TODO
+# @brief Collect the current partition information from all disks listed both
+# in $FAI::disks and $FAI::configs{PHY_<disk>}
#
################################################################################
sub get_current_disks
{
+
+ # obtain the current state of all disks
foreach my $disk (@FAI::disks)
{
- if ( !( $disk =~ m{^/} ) )
- {
- $disk = "/dev/" . $disk;
- }
+
+ # create full paths
+ ( $disk =~ m{^/} ) or $disk = "/dev/$disk";
+
+ # make sure, $disk is a proper block device
+ ( -b $disk ) or die "$disk is not a block special device!\n";
+
+ # skip this disk, if it is not listed in $FAI::configs
+ defined( $FAI::configs{"PHY_$disk"} ) or next;
+
+ # initialise the hash
$FAI::current_config{$disk}{"partitions"} = {};
+ # the list to hold the output of parted commands
my @parted_print = ();
- while (1)
+ # backup value of $ENV{"NO_DRY_RUN"}
+ my $no_dry_run = "";
+ defined( $ENV{"NO_DRY_RUN"} ) and $no_dry_run = $ENV{"NO_DRY_RUN"};
+
+ # set NO_DRY_RUN to perform read-only commands always
+ $ENV{"NO_DRY_RUN"} = "1";
+
+ # try to obtain the partition table for $disk
+ # it might fail with parted_2 in case the disk has no partition table
+ my $error =
+ &FAI::execute_command(
+ $FAI::system_commands{"parted"} . " $disk unit TiB print",
+ \@parted_print, 0 );
+
+ # reset NO_DRY_RUN
+ $ENV{"NO_DRY_RUN"} = $no_dry_run;
+
+# parted_2 happens when the disk has no disk label. then, parted provides no information about the disk
+ if ( $error eq "parted_2" )
{
- $ENV{"NO_DRY_RUN"} = "1";
- my $error =
+
+ # write the disk label as configured
+ $error =
+ &FAI::execute_command( $FAI::system_commands{"parted"}
+ . " $disk mklabel "
+ . $FAI::configs{$disk}{"disklabel"} );
+
+ # retry partition-table print
+ $error =
&FAI::execute_command(
- "$FAI::system_commands{'parted'}} $disk unit TiB print",
+ $FAI::system_commands{"parted"} . " $disk unit TiB print",
\@parted_print, 0 );
- $ENV{"NO_DRY_RUN"} = "";
+ }
- if ( $error eq "parted_2"
- ) #this error happens when the disk has no disk label. then, parted provides no information about the disk
- {
- $error =
- &FAI::execute_command(
- "$FAI::system_commands{'parted'}} $disk mklabel msdos");
- next;
- }
+ # check, whether there is still an error
+ if ( $error ne "" )
+ {
+ my $response = &FAI::get_error( $error, "response" );
+ ( $response eq "die" ) and die &FAI::get_error( $error, "message" );
+ ( $response eq "warn" ) and warn &FAI::get_error( $error, "message" );
+ }
- if ( $error ne "" )
- {
- my $response = &FAI::get_error( $error, "response" );
- if ( $response eq "die" )
- {
- die &FAI::get_error( $error, "message" );
- }
- if ( $response eq "warn" )
- {
- warn &FAI::get_error( $error, "message" );
- }
- }
+# the following code parses the output of parted print, using various units
+# (TiB, B, chs)
+# the parser is capable of reading the output of parted version 1.7.1, which
+# looks like
+#
+# $ /sbin/parted -s /dev/hda unit B print
+# WARNING: You are not superuser. Watch out for permissions.
+#
+# Disk /dev/hda: 80026361855B
+# Sector size (logical/physical): 512B/512B
+# Partition Table: mac
+#
+# Number Start End Size File system Name Flags
+# 1 512B 32767B 32256B primary
+# 5 32768B 1033215B 1000448B hfs primary boot
+# 3 134250496B 32212287487B 32078036992B hfs+ primary
+# 6 32212287488B 46212287487B 14000000000B ext3 primary
+# 2 46212287488B 47212287999B 1000000512B linux-swap primary swap
+# 4 47212288000B 80026361855B 32814073856B ext3 primary
+#
+# Note that the output contains an additional column on msdos, indicating,
+# whether the type of a partition is primary, logical or extended.
+#
+# $ parted -s /dev/hda unit B print
+#
+# Disk /dev/hda: 82348277759B
+# Sector size (logical/physical): 512B/512B
+# Partition Table: msdos
+#
+# Number Start End Size Type File system Flags
+# 1 32256B 24675839B 24643584B primary ext3
+# 2 24675840B 1077511679B 1052835840B primary linux-swap
+# 3 1077511680B 13662190079B 12584678400B primary ext3 boot
+# 4 13662190080B 82343278079B 68681088000B extended
+# 5 13662222336B 14715025919B 1052803584B logical ext3
+# 6 14715058176B 30449986559B 15734928384B logical ext3
+# 7 30450018816B 32547432959B 2097414144B logical ext3
+# 8 32547465216B 82343278079B 49795812864B logical ext3
+#
- last;
- }
+ # As shown above, the file system might be blank, if its type is not known
+ # to parted. Thus the exact columns of "File system" have to be extracted
+ # These two variables keep the indices
+ my $parted_fs_before = 0;
+ my $parted_fs_len = 0;
- my $parted_fs_start = 0;
- my $parted_fs_end = 0;
-
foreach my $line (@parted_print)
{
+
+ # print the line read - for debugging purposes only
( $FAI::debug > 0 ) and print "$line";
+
+ # now we test line by line - some of them may be ignored
if ( $line =~ /^Disk /
|| $line =~ /^\s*$/
|| $line =~ /^WARNING: You are not superuser/
@@ -102,41 +168,49 @@
{
next;
}
+
+ # read and store the current disk label
elsif ( $line =~ /^Partition Table: (.*)$/ )
{
$FAI::current_config{$disk}{"disklabel"} = $1;
- next;
}
- elsif ( $line =~ /^Number/ )
+
+ # the line containing the table headers
+ elsif ( $line =~ /^(Number.*\s+)(File system\s+)\S+/ )
{
- $parted_fs_start = 0;
- $parted_fs_end = 0;
- my @chars = split( "", $line );
- foreach my $char (@chars)
- {
- $parted_fs_end++;
- if ( $char eq "F" )
- {
- $parted_fs_start = $parted_fs_end;
- }
- elsif ( $char eq "m" && $parted_fs_start > 0 )
- {
- last;
- }
- }
- $parted_fs_start--;
- $parted_fs_end -= $parted_fs_start;
+
+ # the number of characters before File system
+ $parted_fs_before = length($1) + 1;
+
+ # the length of the File system column
+ $parted_fs_len = length($2);
}
+
+ # one of the partitions
else
{
- $line =~ /^(\d+)/;
+
+ # we must have seen the header, otherwise probably the format has
+ # changed
+ ( $parted_fs_len > 0 ) or die "Table header not seen yet\n";
+
+ # get the partition number
+ $line =~ /^\s*(\d+)/;
my $id = $1;
- $line =~ /^.{$parted_fs_start}(.{$parted_fs_end})/;
+
+ # extract the set of characters
+ $line =~ /^.{$parted_fs_before}(.{$parted_fs_len})/;
my $fs = $1;
+
+ # remove any trailing space
+ $fs =~ s/\s*$//g;
+
+ # store the information in the hash
$FAI::current_config{$disk}{"partitions"}{$id}{"filesystem"} = $fs;
}
}
+ # MT: TODO: CONT HERE
$ENV{"NO_DRY_RUN"} = "1";
@parted_print = ();
&FAI::execute_command_std(
More information about the Fai-commit
mailing list