[Fai-commit] r4831 - in people/michael/features/setup_harddisks_2/implementation: . lib
mt at alioth.debian.org
mt at alioth.debian.org
Sat Dec 22 23:05:23 UTC 2007
Author: mt
Date: 2007-12-22 23:05:14 +0000 (Sat, 22 Dec 2007)
New Revision: 4831
Modified:
people/michael/features/setup_harddisks_2/implementation/lib/commands.pm
people/michael/features/setup_harddisks_2/implementation/lib/exec.pm
people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm
people/michael/features/setup_harddisks_2/implementation/lib/init.pm
people/michael/features/setup_harddisks_2/implementation/lib/parser.pm
people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm
people/michael/features/setup_harddisks_2/implementation/lib/volumes.pm
people/michael/features/setup_harddisks_2/implementation/setup-storage
Log:
huge cleanup as suggested by Thomas - apart from compute_partition_sizes
everything should be done
Modified: people/michael/features/setup_harddisks_2/implementation/lib/commands.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/commands.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/commands.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -24,11 +24,12 @@
#
# @file commands.pm
#
-# @brief Build the required commands using the config stored in %FAI::configs
+# @brief Build the required commands in @FAI::commands using the config stored
+# in %FAI::configs
#
# $Id$
#
-# @author Christian Kern, Michael Tautschnig
+# @author Christian Kern, Michael Tautschnig, Sebastian Hetze, Andreas Schuldei
# @date Sun Jul 23 16:09:36 CEST 2006
#
################################################################################
@@ -42,73 +43,90 @@
# @param $device Device name of the target partition
# @param $partition Reference to partition in the config hash
#
-# The command is added @FAI::commands
-#
################################################################################
sub build_mkfs_commands {
- my ( $device, $partition ) = @_;
- defined( $partition->{filesystem} )
- or die "INTERNAL ERROR: filesystem is undefined\n";
+ my ($device, $partition) = @_;
+
+ defined ($partition->{filesystem})
+ or &FAI::internal_error("filesystem is undefined");
my $fs = $partition->{filesystem};
- return if ( $fs eq "-" );
+ return if ($fs eq "-");
- my ( $create_options ) = $partition->{fs_options} =~ m/createopts="([^"]+)"/;
- my ( $tune_options ) = $partition->{fs_options} =~ m/tuneopts="([^"]+)"/;
+ my ($create_options) = $partition->{fs_options} =~ m/createopts="([^"]+)"/;
+ my ($tune_options) = $partition->{fs_options} =~ m/tuneopts="([^"]+)"/;
$create_options = $partition->{fs_options} unless $create_options;
- print "create_options: $create_options\n" if ( $FAI::debug && $create_options );
- print "tune_options: $tune_options\n" if ( $FAI::debug && $tune_options );
+ print "create_options: $create_options\n" if ($FAI::debug && $create_options);
+ print "tune_options: $tune_options\n" if ($FAI::debug && $tune_options);
# create the file system with options
my $create_tool = "mkfs.$fs";
- ( $fs eq "swap" ) and $create_tool = "mkswap";
+ ($fs eq "swap") and $create_tool = "mkswap";
push @FAI::commands, "$create_tool $create_options $device";
- # possibly tune the file system
+ # possibly tune the file system - this depends on whether the file system
+ # supports tuning at all
return unless $tune_options;
my $tune_tool;
- ( $fs eq "ext2" ) and $tune_tool = "tune2fs";
- ( $fs eq "ext3" ) and $tune_tool = "tune2fs";
- ( $fs eq "reiserfs" ) and $tune_tool = "reiserfstune";
+ ($fs eq "ext2" || $fs eq "ext3") and $tune_tool = "tune2fs";
+ ($fs eq "reiserfs") and $tune_tool = "reiserfstune";
die "Don't know how to tune $fs\n" unless $tune_tool;
push @FAI::commands, "$tune_tool $tune_options $device";
}
+
################################################################################
#
+# @brief Set the partition type $t on a device $d. This is a no-op if $d is not
+# a physical device
+#
+# @param $d Device name
+# @param $t Type (e.g., lvm or raid)
+#
+################################################################################
+sub set_partition_type_on_phys_dev {
+
+ my ($d, $t) = @_;
+ # only match physical partitions (this string of matchings is hopefully complete)
+ return unless($d =~
+ m{^/dev/(cciss/c\dd\dp|ida/c\dd\dp|rd/c\dd\dp|ataraid/d\dp|sd[a-t]|hd[a-t])(\d+)$});
+ my $disk = "/dev/$1";
+ my $part_no = $2;
+ # in case the name was /dev/cciss/c0d1p or the like, remove the trailing
+ # p to get the disk name
+ $disk =~ s/(\d)p$/$1/;
+ # make sure this device really exists (we can't check for the partition
+ # as that may be created later on
+ (-b $disk) or die "Specified disk $disk does not exist in this system!\n";
+ # set the raid flag
+ push @FAI::commands, "parted -s $disk set $part_no $t on";
+}
+
+################################################################################
+#
# @brief Using the configurations from %FAI::configs, a list of commands is
# built to create any RAID devices
#
-# The list is @FAI::commands
-#
################################################################################
sub build_raid_commands {
- # TODO: do we need to stop anything before we continue? Do we need to issue
- # mdadm --misc --zero-superblock /dev/hdx?
# loop through all configs
- foreach my $config ( keys %FAI::configs ) {
+ foreach my $config (keys %FAI::configs) {
+ # no LVM or physical devices here
+ next if ($config =~ /^VG_./ || $config =~ /^PHY_./);
+ ($config eq "RAID") or &FAI::internal_error("Invalid config $config");
- # no LVM here
- next if ( $config =~ /^VG_(.+)$/ );
-
- # no physical devices here
- next if ( $config =~ /^PHY_(.+)$/ );
-
- # create the RAID devices and the filesystems
- ( $config eq "RAID" ) or die "INTERNAL ERROR: Invalid config\n";
-
# create all raid devices
- foreach my $id ( sort keys %{ $FAI::configs{$config}{volumes} } ) {
+ foreach my $id (sort keys %{ $FAI::configs{$config}{volumes} }) {
# keep a reference to the current volume
- my $vol = ( \%FAI::configs )->{$config}->{volumes}->{$id};
+ my $vol = (\%FAI::configs)->{$config}->{volumes}->{$id};
# the desired RAID level
my $level = $vol->{mode};
# prepend "raid", if the mode is numeric-only
- $level = "raid" . $level if ( $level =~ /^\d+$/ );
+ $level = "raid$level" if ($level =~ /^\d+$/);
# the list of RAID devices
my @devs = keys %{ $vol->{devices} };
@@ -116,34 +134,20 @@
# set proper partition types for RAID
foreach my $d (@devs) {
# skip devices marked missing
- next if( 1 == $vol->{devices}{$d}{missing} );
- # only match physical partitions (this string of matchings is hopefully complete)
- next unless( $d =~
- m{^/dev/(cciss/c\dd\dp|ida/c\dd\dp|rd/c\dd\dp|ataraid/d\dp|sd[a-t]|hd[a-t])(\d+)$} );
- my $disk = "/dev/$1";
- my $part_no = $2;
- # in case the name was /dev/cciss/c0d1p or the like, remove the trailing
- # p to get the disk name
- $disk =~ s/(\d)p$/$1/;
- # make sure this device really exists (we can't check for the partition
- # as that may be created later on
- ( -b $disk ) or die "Specified disk $disk does not exist in this system!\n";
- # set the raid flag
- push @FAI::commands, "parted -s $disk set $part_no raid on";
+ next if $vol->{devices}{$d}{missing};
+ &FAI::set_partition_type_on_phys_dev($d, "raid");
}
# wait for udev to set up all devices
push @FAI::commands, "udevsettle --timeout=10";
# create the command
push @FAI::commands,
- "yes | mdadm --create /dev/md$id --level=$level "
- . "--raid-devices="
- . scalar(@devs) . " "
- . join( " ", @devs );
+ "yes | mdadm --create /dev/md$id --level=$level --raid-devices="
+ . scalar(@devs) . " " . join(" ", @devs);
# create the filesystem on the volume
- &FAI::build_mkfs_commands( "/dev/md$id",
- \%{ $FAI::configs{$config}{volumes}{$id} } );
+ &FAI::build_mkfs_commands("/dev/md$id",
+ \%{ $FAI::configs{$config}{volumes}{$id} });
}
}
}
@@ -153,450 +157,480 @@
# @brief Erase the LVM signature from a list of devices that should be prestine
# in order to avoid confusion of the lvm tools
#
-# The list is @FAI::commands
-#
################################################################################
sub erase_lvm_signature {
- my( $devices_aref ) = @_;
- # first remove the dm_mod module to prevent ghost lvm volumes
- # from existing
-# push @FAI::commands, "modprobe -r dm_mod";
- # zero out (broken?) lvm signatures
-# push @FAI::commands, "dd if=/dev/zero of=$_ bs=1 count=1"
-# foreach ( @{$devices_aref} );
- my $device_list = join(" ", (@{$devices_aref}) );
- ( $FAI::debug > 0 ) and print "list of erased devices: $device_list\n";
- push @FAI::commands, "pvremove -ff -y $device_list";
- # reload module
-# push @FAI::commands, "modprobe dm_mod";
+ my ($devices_aref) = @_;
+ # first remove the dm_mod module to prevent ghost lvm volumes
+ # from existing
+ # push @FAI::commands, "modprobe -r dm_mod";
+ # zero out (broken?) lvm signatures
+ # push @FAI::commands, "dd if=/dev/zero of=$_ bs=1 count=1"
+ # foreach ( @{$devices_aref} );
+ my $device_list = join (" ", @{$devices_aref});
+ $FAI::debug and print "Erased devices: $device_list\n";
+ push @FAI::commands, "pvremove -ff -y $device_list";
+ # reload module
+ # push @FAI::commands, "modprobe dm_mod";
}
################################################################################
#
-# @brief Using the configurations from %FAI::configs, a list of commands is
-# built to setup the LVM
+# @brief Create the volume group $config, unless it exists already; if the
+# latter is the case, only add/remove the physical devices
#
-# The list is @FAI::commands
+# @param $config Config entry
#
################################################################################
-sub build_lvm_commands {
- # loop through all configs
- foreach my $config ( keys %FAI::configs ) {
- # no physical devices here
- next if ( $config =~ /^PHY_(.+)$/ );
+sub create_volume_group {
- # no RAID devices here
- next if ( $config eq "RAID" );
+ my ($config) = @_;
+ ($config =~ /^VG_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $vg = $1; # the actual volume group
- # create the volume groups, the logical volumes and the filesystems
- ( $config =~ /^VG_(.+)$/ ) or die "INTERNAL ERROR: Invalid config\n";
+ # create the volume group, if it doesn't exist already
+ if (!defined ($FAI::current_lvm_config{$vg})) {
+ # create all the devices
+ my @devices = keys %{ $FAI::configs{$config}{devices} };
+ &FAI::erase_lvm_signature(\@devices);
+ push @FAI::commands, "pvcreate $_" foreach (@devices);
+ # create the volume group
+ push @FAI::commands, "vgcreate $vg " . join (" ", @devices);
+ # we are done
+ return;
+ }
- # the volume group
- my $vg = $1;
+ # otherwise add or remove the devices for the volume group, run pvcreate
+ # where needed
+ # the list of devices to be created
+ my %new_devs = ();
- # find volumes that should be preserved or resized and ensure that they
- # already exist
- foreach my $lv ( keys %{ $FAI::configs{$config}{volumes} } ) {
- # reference to the size of the current logical volume
- my $lv_size = ( \%FAI::configs )->{$config}->{volumes}->{$lv}->{size};
- next unless ( $lv_size->{preserve} == 1 || $lv_size->{resize} == 1 );
+ # create an undefined entry for each new device
+ @new_devs{ keys %{ $FAI::configs{$config}{devices} } } = ();
- # preserved or resized volumes must exist already
- defined( $FAI::current_lvm_config{$vg}{volumes}{$lv} )
- or die "/dev/$vg/$lv can't be preserved, it does not exist.\n";
- }
+ my @new_devices = keys %new_devs;
- # set proper partition types for LVM
- foreach my $d (keys %{ $FAI::configs{$config}{devices} }) {
- # only match physical partitions (this string of matchings is hopefully complete)
- next unless( $d =~
- m{^/dev/(cciss/c\dd\dp|ida/c\dd\dp|rd/c\dd\dp|ataraid/d\dp|sd[a-t]|hd[a-t])(\d+)$} );
- my $disk = "/dev/$1";
- my $part_no = $2;
- # in case the name was /dev/cciss/c0d1p or the like, remove the trailing
- # p to get the disk name
- $disk =~ s/(\d)p$/$1/;
- # make sure this device really exists (we can't check for the partition
- # as that may be created later on
- ( -b $disk ) or die "Specified disk $disk does not exist in this system!\n";
- # set the lvm flag
- push @FAI::commands, "parted -s $disk set $part_no lvm on";
- }
- # wait for udev to set up all devices
- push @FAI::commands, "udevsettle --timeout=10";
+ # &FAI::erase_lvm_signature( \@new_devices );
- # create the volume group, if it doesn't exist already
- if ( !defined( $FAI::current_lvm_config{$vg} ) ) {
- # create all the devices
- my @devices = keys %{ $FAI::configs{$config}{devices} };
- &FAI::erase_lvm_signature(\@devices);
- push @FAI::commands, "pvcreate $_" foreach ( @devices );
- # create the volume group
- push @FAI::commands, "vgcreate $vg "
- . join( " ", keys %{ $FAI::configs{$config}{devices} } );
- }
+ # create all the devices
+ push @FAI::commands, "pvcreate $_" foreach (@new_devices);
- # otherwise add or remove the devices for the volume group, run pvcreate
- # where needed (using pvdisplay <bla> || pvcreate <bla>)
- else {
+ # extend the volume group by the new devices (includes the current ones)
+ push @FAI::commands, "vgextend $vg " . join(" ", @new_devices);
- # the list of devices to be created
- my %new_devs = ();
+ # the devices to be removed
+ my %rm_devs = ();
+ @rm_devs{ @{ $FAI::current_lvm_config{$vg}{"physical_volumes"} } } = ();
- # create an undefined entry for each new device
- @new_devs{ keys %{ $FAI::configs{$config}{devices} } } = ();
-
- my @new_devices = keys %new_devs;
-
- &FAI::erase_lvm_signature( \@new_devices );
-
- # create all the devices
- push @FAI::commands, "pvcreate $_" foreach ( @new_devices );
+ # remove remaining devices from the list
+ delete $rm_devs{$_} foreach (@new_devices);
- # extend the volume group by the new devices (includes the current ones)
- push @FAI::commands, "vgextend $vg " . join( " ", keys %new_devs );
+ # run vgreduce to get them removed
+ push @FAI::commands, "vgreduce $vg " . join(" ", keys %rm_devs) if (scalar (keys %rm_devs));
+}
- # the devices to be removed
- my %rm_devs = ();
- @rm_devs{ @{ $FAI::current_lvm_config{$vg}{"physical_volumes"} } } = ();
+################################################################################
+#
+# @brief Create the volume group $config, unless it exists already; if the
+# latter is the case, only add/remove the physical devices
+#
+# @param $config Config entry
+#
+################################################################################
+sub setup_logical_volumes {
- # remove remaining devices from the list
- delete $rm_devs{$_} foreach ( keys %new_devs );
+ my ($config) = @_;
+ ($config =~ /^VG_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $vg = $1; # the actual volume group
- # run vgreduce to get them removed
- push @FAI::commands, "vgreduce $vg " . join( " ", keys %rm_devs )
- if ( scalar( keys %rm_devs ) );
+ # remove, resize, create the logical volumes
+ # remove all volumes that do not exist anymore or need not be preserved
+ foreach my $lv (keys %{ $FAI::current_lvm_config{$vg}{volumes} }) {
+ # skip preserved/resized volumes
+ next if (defined ( $FAI::configs{$config}{volumes}{$lv})
+ && ($FAI::configs{$config}{volumes}{$lv}{size}{preserve} == 1
+ || $FAI::configs{$config}{volumes}{$lv}{size}{resize}));
+
+ push @FAI::commands, "lvremove -f $vg/$lv";
+ }
+
+ # now create or resize the configured logical volumes
+ foreach my $lv (keys %{ $FAI::configs{$config}{volumes} }) {
+ # reference to the size of the current logical volume
+ my $lv_size = (\%FAI::configs)->{$config}->{volumes}->{$lv}->{size};
+ # skip preserved partitions, but ensure that they exist
+ if ($lv_size->{preserve}) {
+ defined ($FAI::current_lvm_config{$vg}{volumes}{$lv})
+ or die "Preserved volume $vg/$lv does not exist\n";
+ next;
}
- # enable the volume group
- push @FAI::commands, "vgchange -a y $vg";
+ # resize the volume
+ if ($lv_size->{resize}) {
+ defined ($FAI::current_lvm_config{$vg}{volumes}{$lv})
+ or die "Resized volume $vg/$lv does not exist\n";
- # remove, resize, create the logical volumes
- # remove all volumes that do not exist anymore or need not be preserved
- foreach my $lv ( keys %{ $FAI::current_lvm_config{$vg}{volumes} } ) {
- # skip preserved/resized volumes
- next if ( defined( $FAI::configs{$config}{volumes}{$lv} )
- && ( $FAI::configs{$config}{volumes}{$lv}{size}{preserve} == 1
- || $FAI::configs{$config}{volumes}{$lv}{size}{resize} ));
-
- # remove $lv
- push @FAI::commands, "lvremove -f $vg/$lv";
+ # note that resizing a volume destroys the data on it
+ push @FAI::commands,
+ "lvresize -L " . $lv_size->{eff_size} . " $vg/$lv";
+ next;
}
- # now create or resize the configured logical volumes
- foreach my $lv ( keys %{ $FAI::configs{$config}{volumes} } ) {
- # reference to the size of the current logical volume
- my $lv_size = ( \%FAI::configs )->{$config}->{volumes}->{$lv}->{size};
- # skip preserved partitions, but ensure that they exist
- if ( $lv_size->{preserve} == 1 ) {
- defined( $FAI::current_lvm_config{$vg}{volumes}{$lv} )
- or die "Preserved volume $vg/$lv does not exist\n";
- next;
- }
+ # create a new volume
+ push @FAI::commands,
+ "lvcreate -n $lv -L " . $lv_size->{eff_size} . " $vg";
- # resize the volume
- if ( $lv_size->{resize} == 1 ) {
- defined( $FAI::current_lvm_config{$vg}{volumes}{$lv} )
- or die "Resized volume $vg/$lv does not exist\n";
+ # create the filesystem on the volume
+ &FAI::build_mkfs_commands("/dev/$vg/$lv",
+ \%{ $FAI::configs{$config}{volumes}{$lv} });
+ }
+}
- # note that resizing a volume destroys the data on it
- push @FAI::commands,
- "lvresize -L " . $lv_size->{eff_size} . " $vg/$lv";
- }
+################################################################################
+#
+# @brief Using the configurations from %FAI::configs, a list of commands is
+# built to setup the LVM
+# creates the volume groups, the logical volumes and the filesystems
+#
+################################################################################
+sub build_lvm_commands {
- # create a new volume
- else {
- push @FAI::commands,
- "lvcreate -n $lv -L " . $lv_size->{eff_size} . " $vg";
+ # loop through all configs
+ foreach my $config (keys %FAI::configs) {
+
+ # no physical devices or RAID here
+ next if ($config =~ /^PHY_./ || $config eq "RAID");
+ ($config =~ /^VG_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $vg = $1; # the volume group
- # create the filesystem on the volume
- &FAI::build_mkfs_commands( "/dev/$vg/$lv",
- \%{ $FAI::configs{$config}{volumes}{$lv} } );
- }
- }
+ # set proper partition types for LVM
+ &FAI::set_partition_type_on_phys_dev($_, "lvm")
+ foreach (keys %{ $FAI::configs{$config}{devices} });
+ # wait for udev to set up all devices
+ push @FAI::commands, "udevsettle --timeout=10";
+ # create the volume group or add/remove devices
+ &FAI::create_volume_group($config);
+ # enable the volume group
+ push @FAI::commands, "vgchange -a y $vg";
+
+ # perform all necessary operations on the underlying logical volumes
+ &FAI::setup_logical_volumes($config);
}
}
################################################################################
#
-# @brief Using the configurations from %FAI::configs, a list of commands is
-# built to setup the partitions
+# @brief Return an ordered list of partitions that must be preserved
#
-# The list is @FAI::commands
+# @param $config Config entry
#
################################################################################
-sub build_disk_commands {
- # loop through all configs
- foreach my $config ( keys %FAI::configs ) {
- # no RAID devices here
- next if ( $config eq "RAID" );
+sub get_preserved_partitions {
+
+ my ($config) = @_;
+ ($config =~ /^PHY_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $disk = $1; # the device to be configured
+
+ # the list of partitions that must be preserved
+ my @to_preserve = ();
- # no LVM here
- next if ( $config =~ /^VG_(.+)$/ );
+ # find partitions that should be preserved or resized
+ foreach my $part_id ( sort 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});
- # configure a physical device
- ( $config =~ /^PHY_(.+)$/ ) or die "INTERNAL ERROR: Invalid config\n";
+ # preserved or resized partitions must exist already
+ defined( $FAI::current_config{$disk}{partitions}{$part_id} )
+ or die "$part_id can't be preserved, it does not exist.\n";
- # the device to be configured
- my $disk = $1;
+ # add a mapping from the configured partition to the existing one
+ # (identical here, may change for extended partitions below)
+ $part->{maps_to_existing} = $part_id;
- # create partitions on non-virtual configs
- if ( $FAI::configs{$config}{virtual} == 0 ) {
- # the list of partitions that must be preserved
- my @to_preserve = ();
+ # add $part_id to the list of preserved partitions
+ push @to_preserve, $part_id;
- # find partitions that should be preserved or resized
- foreach my $part_id ( sort keys %{ $FAI::configs{$config}{partitions} } ) {
- # reference to the current partition
- my $part = ( \%FAI::configs )->{$config}->{partitions}->{$part_id};
- next unless (
- $part->{size}->{preserve} == 1 || $part->{size}->{resize} == 1 );
+ }
- # preserved or resized partitions must exist already
- defined( $FAI::current_config{$disk}{partitions}{$part_id} )
- or die "$part_id can't be preserved, it does not exist.\n";
+ # sort the list of preserved partitions
+ @to_preserve = sort { $a <=> $b } @to_preserve;
- # add a mapping from the configured partition to the existing one
- # (identical here, may change for extended partitions below)
- $part->{maps_to_existing} = $part_id;
+ # add the extended partition as well, if logical partitions must be
+ # preserved; and mark it as resize
+ if ($FAI::configs{$config}{disklabel} eq "msdos") {
+ # we assume there are no logical partitions
+ my $has_logical = 0;
+ my $extended = -1;
- # add $part_id to the list of preserved partitions
- push @to_preserve, $part_id;
+ # now check all entries; the array is sorted
+ foreach my $part_id (@to_preserve) {
+ # the extended partition may already be listed; then, the id of the
+ # extended partition must not change
+ if ($FAI::current_config{$disk}{partitions}{$part_id}{is_extended}) {
+ (defined ($FAI::configs{$config}{partitions}{$extended}{size}{extended})
+ && defined ($FAI::current_config{$disk}{partitions}{$extended}{is_extended})
+ && $FAI::configs{$config}{partitions}{$extended}{size}{extended}
+ && $FAI::current_config{$disk}{partitions}{$extended}{is_extended})
+ or die "ID of extended partition changes\n";
+ # make sure resize is set
+ $FAI::configs{$config}{partitions}{$part_id}{size}{resize} = 1;
+ $extended = $part_id;
+ last;
}
- # sort the list of preserved partitions
- @to_preserve = sort { $a <=> $b } @to_preserve;
+ # there is some logical partition
+ if ($part_id > 4) {
+ $has_logical = 1;
+ last;
+ }
+ }
- # add the extended partition as well, if logical partitions must be
- # preserved; and mark it as resize
- if ( $FAI::configs{$config}{disklabel} eq "msdos" ) {
- # we assume there are no logical partitions
- my $has_logical = 0;
- my $extended = -1;
+ # 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} }) {
- # now check all entries; the array is sorted
- foreach my $part_id (@to_preserve) {
- # the extended partition may already be listed; then, the id of the
- # extended partition must not change
- if ( $FAI::current_config{$disk}{partitions}{$part_id}{is_extended} == 1 ) {
- ( defined( $FAI::configs{$config}{partitions}{$extended}{size}{extended})
- && defined( $FAI::current_config{$disk}{partitions}{$extended}{is_extended})
- && $FAI::configs{$config}{partitions}{$extended}{size}{extended} == 1
- && $FAI::current_config{$disk}{partitions}{$extended}{is_extended} == 1 )
- or die "ID of extended partition changes\n";
+ # no extended partition
+ next unless
+ $FAI::current_config{$disk}{partitions}{$part_id}{is_extended};
- # make sure resize is set
- $FAI::configs{$config}{partitions}{$part_id}{size}{resize} = 1;
- $extended = $part_id;
- last;
- }
+ # find the configured extended partition to set the mapping
+ foreach my $p (sort keys %{ $FAI::configs{$config}{partitions} }) {
+ # reference to the current partition
+ my $part = (\%FAI::configs)->{$config}->{partitions}->{$p};
+ next unless $part->{size}->{extended};
- # there is some logical partition
- if ( $part_id > 4 ) {
- $has_logical = 1;
- last;
- }
- }
+ # make sure resize is set
+ $part->{size}->{resize} = 1;
- # if the extended partition is not listed yet, find and add it now; note
- # that we need to add the existing one
- if ( 1 == $has_logical && -1 == $extended ) {
- foreach my $part_id ( sort keys %{ $FAI::current_config{$disk}{partitions} } ) {
+ # store the id for further checks
+ $extended = $p;
- # no extended partition
- next unless ( $FAI::current_config{$disk}{partitions}{$part_id}{is_extended} == 1 );
+ # add a mapping entry to the existing extended partition
+ $part->{maps_to_existing} = $part_id;
- # find the configured extended partition to set the mapping
- foreach my $p ( sort keys %{ $FAI::configs{$config}{partitions} } ) {
- # reference to the current partition
- my $part = ( \%FAI::configs )->{$config}->{partitions}->{$p};
- next unless ( $part->{size}->{extended} == 1 );
+ # add it to the preserved partitions
+ push @to_preserve, $p;
- # make sure resize is set
- $part->{size}->{resize} = 1;
+ last;
+ }
- # store the id for further checks
- $extended = $p;
+ # sort the list of preserved partitions (again)
+ @to_preserve = sort { $a <=> $b } @to_preserve;
- # add a mapping entry to the existing extended partition
- $part->{maps_to_existing} = $part_id;
+ last;
+ }
+ }
- # add it to the preserved partitions
- push @to_preserve, $p;
+ # a sanity check: if there are logical partitions, the extended must
+ # have been added
+ (0 == $has_logical || -1 != $extended)
+ or &FAI::internal_error("Required extended partition not detected for preserve");
+ }
- last;
- }
+ return @to_preserve;
+}
- # sort the list of preserved partitions (again)
- @to_preserve = sort { $a <=> $b } @to_preserve;
+################################################################################
+#
+# @brief Recreate the preserved partitions once the partition table has been
+# flushed
+#
+# @param $config Config entry
+#
+################################################################################
+sub get_preserved_partitions {
+
+ my ($config) = @_;
+ ($config =~ /^PHY_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $disk = $1; # the device to be configured
+
+ # once we rebuild partitions, their ids are likely to change; this counter
+ # helps keeping track of this
+ my $part_nr = 0;
- last;
- }
- }
+ # now rebuild all preserved partitions
+ foreach my $part_id (@to_preserve) {
+ # get the existing id
+ my $mapped_id =
+ $FAI::configs{$config}{partitions}{$part_id}{maps_to_existing};
- # a sanity check: if there are logical partitions, they extended must
- # have been added
- ( 0 == $has_logical || -1 != $extended ) or die
- "INTERNAL ERROR: Required extended partition not detected for preserve\n";
+ # get the original starts and ends
+ my $start =
+ $FAI::current_config{$disk}{partitions}{$mapped_id}{begin_byte};
+ my $end =
+ $FAI::current_config{$disk}{partitions}{$mapped_id}{end_byte};
+
+ # the type of the partition defaults to primary
+ my $part_type = "primary";
+ if ( $FAI::configs{$config}{disklabel} eq "msdos" ) {
+
+ # change the partition type to extended or logical as appropriate
+ if ( $FAI::configs{$config}{partitions}{$part_id}{size}{extended} == 1 ) {
+ $part_type = "extended";
+ } elsif ( $part_id > 4 ) {
+ $part_type = "logical";
+ $part_nr = 4 if ( $part_nr < 4 );
}
+ }
- # A new disk label may only be written if no partitions need to be
- # preserved
- ( ( $FAI::configs{$config}{disklabel} eq
- $FAI::current_config{$disk}{disklabel})
- || ( scalar(@to_preserve) == 0 ) )
- or die "Can't change disklabel, partitions are to be preserved\n";
+ # increase the partition counter for the partition created next and
+ # write it to the configuration
+ $part_nr++;
+ $FAI::current_config{$disk}{partitions}{$mapped_id}{new_id} = $part_nr;
- # write the disklabel to drop the previous partition table
- push @FAI::commands, "parted -s $disk mklabel "
- . $FAI::configs{$config}{disklabel};
+ # build a parted command to create the partition
+ push @FAI::commands,
+ "parted -s $disk mkpart $part_type ${start}B ${end}B";
+ }
+}
- # once we rebuild partitions, their ids are likely to change; this counter
- # helps keeping track of this
- my $part_nr = 0;
+################################################################################
+#
+# @brief Create the volume group $config, unless it exists already; if the
+# latter is the case, only add/remove the physical devices
+#
+# @param $config Config entry
+#
+################################################################################
+sub setup_partitions {
- # now rebuild all preserved partitions
- foreach my $part_id (@to_preserve) {
- # get the existing id
- my $mapped_id =
- $FAI::configs{$config}{partitions}{$part_id}{maps_to_existing};
+ my ($config) = @_;
+ ($config =~ /^PHY_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $disk = $1; # the device to be configured
+
+ # the list of partitions that must be preserved
+ my @to_preserve = &FAI::get_preserved_partitions($config);
- # get the original starts and ends
- my $start =
- $FAI::current_config{$disk}{partitions}{$mapped_id}{begin_byte};
- my $end =
- $FAI::current_config{$disk}{partitions}{$mapped_id}{end_byte};
+ # A new disk label may only be written if no partitions need to be
+ # preserved
+ (($FAI::configs{$config}{disklabel} eq
+ $FAI::current_config{$disk}{disklabel})
+ || (scalar (@to_preserve) == 0))
+ or die "Can't change disklabel, partitions are to be preserved\n";
- # the type of the partition defaults to primary
- my $part_type = "primary";
- if ( $FAI::configs{$config}{disklabel} eq "msdos" ) {
+ # write the disklabel to drop the previous partition table
+ push @FAI::commands, "parted -s $disk mklabel "
+ . $FAI::configs{$config}{disklabel};
- # change the partition type to extended or logical as appropriate
- if ( $FAI::configs{$config}{partitions}{$part_id}{size}{extended} == 1 ) {
- $part_type = "extended";
- } elsif ( $part_id > 4 ) {
- $part_type = "logical";
- $part_nr = 4 if ( $part_nr < 4 );
- }
- }
+ &FAI::rebuild_preserved_partitions($config);
- # increase the partition counter for the partition created next and
- # write it to the configuration
- $part_nr++;
- $FAI::current_config{$disk}{partitions}{$mapped_id}{new_id} = $part_nr;
+ # resize partitions; first we shrink partitions, then grow others;
+ # furthermore we start from the end to shrink logical partitions before
+ # the extended one, but grow partitions starting from the beginning
+ my @shrink_list = ();
+ my @grow_list = ();
- # build a parted command to create the partition
- push @FAI::commands,
- "parted -s $disk mkpart $part_type ${start}B ${end}B";
- }
+ # iterate over the worklists
+ foreach my $part_id (reverse sort (@to_preserve));
+ # reference to the current partition
+ my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
+ # anything to be done?
+ next unless $part->{size}->{resize};
- # resize partitions; first we shrink partitions, then grow others;
- # furthermore we start from the end to shrink logical partitions before
- # the extended one, but grow partitions starting from the beginning
- my @shrink_list = reverse sort (@to_preserve);
- my @grow_list = ();
+ # get the existing id
+ my $mapped_id = $part->{maps_to_existing};
- # iterate over the worklists
- foreach my $part_id (@shrink_list) {
- # reference to the current partition
- my $part = ( \%FAI::configs )->{$config}->{partitions}->{$part_id};
- # anything to be done?
- next unless ( $part->{size}->{resize} == 1 );
+ # if partition is to be grown, move it to then grow_list
+ if ( $part->{size}->{eff_size} >
+ $FAI::current_config{$disk}{partitions}{$mapped_id}{count_byte} ) {
+ unshift @grow_list, $part_id;
+ } else {
+ push @shrink_list, $part_id;
+ }
+ }
- # get the existing id
- my $mapped_id = $part->{maps_to_existing};
+ # grow the remaining partitions
+ foreach my $part_id (@shrink_list, at grow_list) {
+ # reference to the current partition
+ my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
- # if partition is to be grown, move it to then grow_list
- if ( $part->{size}->{eff_size} >
- $FAI::current_config{$disk}{partitions}{$mapped_id}{count_byte} ) {
- unshift @grow_list, $part_id;
- next;
- }
+ # get the existing id
+ my $mapped_id = $part->{maps_to_existing};
+
+ # get the new partition id
+ my $p = $FAI::current_config{$disk}{partitions}{$mapped_id}{new_id};
- # get the new partition id
- my $p = $FAI::current_config{$disk}{partitions}{$mapped_id}{new_id};
+ # get the new starts and ends
+ my $start = $part->{start_byte};
+ my $end = $part->{end_byte};
- # get the new starts and ends
- my $start = $part->{start_byte};
- my $end = $part->{end_byte};
+ # build an appropriate command
+ push @FAI::commands, "parted -s $disk resize $p ${start}B ${end}B";
+ }
- # build an appropriate command
- push @FAI::commands, "parted -s $disk resize $p ${start}B ${end}B";
- }
+ # write the disklabel again to drop the partition table and create a new one
+ # that has the proper ids
+ push @FAI::commands, "parted -s $disk mklabel " . $FAI::configs{$config}{disklabel};
- # grow the remaining partitions
- foreach my $part_id (@grow_list) {
- # reference to the current partition
- my $part = ( \%FAI::configs )->{$config}->{partitions}->{$part_id};
+ # generate the commands for creating all partitions
+ foreach my $part_id (sort 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};
+ my $end = $part->{end_byte};
- # get the new partition id
- my $p = $FAI::current_config{$disk}{partitions}{$mapped_id}{new_id};
+ # the type of the partition defaults to primary
+ my $part_type = "primary";
+ if ($FAI::configs{$config}{disklabel} eq "msdos") {
- # get the new starts and ends
- my $start = $part->{start_byte};
- my $end = $part->{end_byte};
-
- # build an appropriate command
- push @FAI::commands, "parted -s $disk resize $p ${start}B ${end}B";
+ # change the partition type to extended or logical as appropriate
+ if ($part->{size}->{extended} == 1) {
+ $part_type = "extended";
+ } elsif ($part_id > 4) {
+ $part_type = "logical";
}
+ }
- # write the disklabel again to drop the partition table
- push @FAI::commands, "parted -s $disk mklabel " . $FAI::configs{$config}{disklabel};
+ # build a parted command to create the partition
+ push @FAI::commands, "parted -s $disk mkpart $part_type ${start}B ${end}B";
+ }
- # generate the commands for creating all partitions
- foreach my $part_id ( sort keys %{ $FAI::configs{$config}{partitions} } ) {
- # reference to the current partition
- my $part = ( \%FAI::configs )->{$config}->{partitions}->{$part_id};
+ # set the bootable flag, if requested at all
+ push @FAI::commands, "parted -s $disk set "
+ . $FAI::configs{$config}{bootable} . " boot on"
+ if ($FAI::configs{$config}{bootable} > -1);
- # get the new starts and ends
- my $start = $part->{start_byte};
- my $end = $part->{end_byte};
+ # wait for udev to set up all devices
+ push @FAI::commands, "udevsettle --timeout=10";
+}
- # the type of the partition defaults to primary
- my $part_type = "primary";
- if ( $FAI::configs{$config}{disklabel} eq "msdos" ) {
- # change the partition type to extended or logical as appropriate
- if ( $part->{size}->{extended} == 1 ) {
- $part_type = "extended";
- } elsif ( $part_id > 4 ) {
- $part_type = "logical";
- }
- }
+################################################################################
+#
+# @brief Using the configurations from %FAI::configs, a list of commands is
+# built to setup the partitions
+#
+################################################################################
+sub build_disk_commands {
+
+ # loop through all configs
+ foreach my $config ( keys %FAI::configs ) {
+ # no RAID or LVM devices here
+ next if ($config eq "RAID" || $config =~ /^VG_./);
+ ($config =~ /^PHY_(.+)$/) or &FAI::internal_error("Invalid config $config");
+ my $disk = $1; # the device to be configured
- # build a parted command to create the partition
- push @FAI::commands, "parted -s $disk mkpart $part_type ${start}B ${end}B";
- }
-
- # set the bootable flag, if requested at all
- push @FAI::commands,
- "parted -s $disk set "
- . $FAI::configs{$config}{bootable}
- . " boot on"
- if ( $FAI::configs{$config}{bootable} > -1 );
-
- # wait for udev to set up all devices
- push @FAI::commands, "udevsettle --timeout=10";
- }
-
+ # create partitions on non-virtual configs
+ &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} } ) {
# reference to the current partition
- my $part = ( \%FAI::configs )->{$config}->{partitions}->{$part_id};
+ my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id};
# skip preserved/resized/extended partitions
- next if ( $part->{size}->{preserve} == 1
- || $part->{size}->{resize} == 1 || $part->{size}->{extended} == 1 );
+ next if ($part->{size}->{preserve} == 1
+ || $part->{size}->{resize} == 1 || $part->{size}->{extended} == 1);
# create the filesystem on $disk$part_id
- &FAI::build_mkfs_commands( $disk . $part_id, $part );
+ &FAI::build_mkfs_commands( "$disk$part_id", $part );
}
}
}
@@ -609,16 +643,16 @@
sub restore_partition_table {
# loop through all existing configs
- foreach my $disk ( keys %FAI::current_config ) {
+ foreach my $disk (keys %FAI::current_config) {
# write the disklabel again to drop the partition table
- &FAI::execute_command( "parted -s $disk mklabel "
- . $FAI::current_config{$disk}{disklabel} );
+ &FAI::execute_command("parted -s $disk mklabel "
+ . $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 keys %{ $FAI::current_config{$disk}{partitions} }) {
# reference to the current partition
- my $curr_part = ( \%FAI::current_config )->{$disk}->{partitions}->{$part_id};
+ my $curr_part = (\%FAI::current_config)->{$disk}->{partitions}->{$part_id};
# get the starts and ends
my $start = $curr_part->{begin_byte};
@@ -626,18 +660,18 @@
# the type of the partition defaults to primary
my $part_type = "primary";
- if ( $FAI::current_config{$disk}{disklabel} eq "msdos" ) {
+ if ($FAI::current_config{$disk}{disklabel} eq "msdos") {
# change the partition type to extended or logical as appropriate
- if ( $curr_part->{is_extended} == 1 ) {
+ if ($curr_part->{is_extended}) {
$part_type = "extended";
- } elsif ( $part_id > 4 ) {
+ } elsif ($part_id > 4) {
$part_type = "logical";
}
}
# 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 ${start}B ${end}B");
}
warn "Partition table of disk $disk has been restored\n";
}
Modified: people/michael/features/setup_harddisks_2/implementation/lib/exec.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/exec.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/exec.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -115,6 +115,7 @@
#
################################################################################
sub get_error_message {
+
my ($error) = @_;
my @treffer = grep { $_->{error} eq "$error" } @$FAI::error_codes;
@@ -133,7 +134,8 @@
#
################################################################################
sub get_error {
- my ( $error, $field ) = @_;
+
+ my ($error, $field) = @_;
my @treffer = grep { $_->{error} eq "$error" } @$FAI::error_codes;
# returns the first found error message.
@@ -156,24 +158,57 @@
# @return the identifier of the error
#
################################################################################
-sub execute_command_std {
- my ( $command, $stdout, $stderr ) = @_;
- my $err = &execute_command( $command, $stdout, $stderr );
- if ( $err ne "" ) {
- my $response = &get_error( $err, "response" );
- my $message = &get_error( $err, "message" );
+sub execute_command {
- $response->() if ( ref($response) );
+ my ($command, $stdout, $stderr) = @_;
- die $message if ( $response eq "die" );
+ my $err = &execute_command_internal($command, $stdout, $stderr);
+
+ if ($err ne "") {
+ my $response = &get_error($err, "response");
+ my $message = &get_error($err, "message");
- warn $message if ( $response eq "warn" );
+ $response->() if (ref ($response));
+ die $message if ($response eq "die");
+
+ warn $message if ($response eq "warn");
+
return $err;
}
return "";
}
+sub execute_ro_command {
+ my ($command, $stdout, $stderr) = @_;
+
+ # backup value of $FAI::no_dry_run
+ my $no_dry_run = $FAI::no_dry_run;
+
+ # set no_dry_run to perform read-only commands always
+ $FAI::no_dry_run = 1;
+
+ my $err = &execute_command_internal($command, $stdout, $stderr);
+
+ # reset no_dry_run
+ $FAI::no_dry_run = $no_dry_run;
+
+ if ($err ne "") {
+ my $response = &get_error($err, "response");
+ my $message = &get_error($err, "message");
+
+ $response->() if (ref ($response));
+
+ die $message if ($response eq "die");
+
+ warn $message if ($response eq "warn");
+
+ return $err;
+ }
+ return "";
+}
+
+
################################################################################
#
# @brief execute a /bin/bash command, given as string. also catch stderr and
@@ -190,22 +225,23 @@
# @return the identifier of the error
#
################################################################################
-sub execute_command {
- my ( $command, $stdout_ref, $stderr_ref ) = @_;
+sub execute_command_internal {
+ my ($command, $stdout_ref, $stderr_ref) = @_;
+
my @stderr = ();
my @stdout = ();
my $stderr_line = "";
my $stdout_line = "";
#make tempfile, get perl filehandle and filename of the file
- ( my $stderr_fh, my $stderr_filename ) = File::Temp::tempfile( UNLINK => 1 );
- ( my $stdout_fh, my $stdout_filename ) = File::Temp::tempfile( UNLINK => 1 );
+ my ($stderr_fh, $stderr_filename) = File::Temp::tempfile(UNLINK => 1);
+ my ($stdout_fh, $stdout_filename) = File::Temp::tempfile(UNLINK => 1);
# do only execute the given command, when in no_dry_mode
if ($FAI::no_dry_run) {
- ($FAI::debug)
+ $FAI::debug
and print "(CMD) $command 1> $stdout_filename 2> $stderr_filename\n";
# execute the bash command, write stderr and stdout into the testfiles
@@ -219,32 +255,29 @@
@stdout = <$stdout_fh>;
#when closing the files, the tempfiles are removed too
- close($stderr_fh);
- close($stdout_fh);
+ close ($stderr_fh);
+ close ($stdout_fh);
- ($FAI::debug) and print "(STDERR) $_" foreach (@stderr);
- ($FAI::debug) and print "(STDOUT) $_" foreach (@stdout);
+ $FAI::debug and print "(STDERR) $_" foreach (@stderr);
+ $FAI::debug and print "(STDOUT) $_" foreach (@stdout);
#if the stderr contains information, get the first line for error recognition
- $stderr_line = $stderr[0] if ( scalar(@stderr) > 0 );
+ $stderr_line = $stderr[0] if (scalar (@stderr));
#see last comment
- $stdout_line = $stdout[0] if ( scalar(@stdout) > 0 );
+ $stdout_line = $stdout[0] if (scalar (@stdout));
#if an array is passed to the function, it is filled with the stdout
- @$stdout_ref = @stdout if ( 'ARRAY' eq ref($stdout_ref) );
+ @$stdout_ref = @stdout if ('ARRAY' eq ref ($stdout_ref));
#see above
- @$stderr_ref = @stderr if ( 'ARRAY' eq ref($stderr_ref) );
+ @$stderr_ref = @stderr if ('ARRAY' eq ref ($stderr_ref));
#get the error, if there was any
foreach my $err (@$FAI::error_codes) {
- if ( (
- $err->{stdout_regex} eq "" || $stdout_line =~ /$err->{stdout_regex}/
- ) && ( $err->{stderr_regex} eq ""
- || $stderr_line =~ /$err->{stderr_regex}/ )
- && ( $err->{program} eq "" || $command =~ /.*$err->{program}.*/ )
- ) {
+ if (($err->{stdout_regex} eq "" || $stdout_line =~ /$err->{stdout_regex}/)
+ && ($err->{stderr_regex} eq "" || $stderr_line =~ /$err->{stderr_regex}/)
+ && ($err->{program} eq "" || $command =~ /$err->{program}/)) {
return $err->{error};
}
}
Modified: people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/fstab.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -37,6 +37,44 @@
################################################################################
#
+# @brief Create a line for /etc/fstab
+#
+# @reference $d_ref Device reference
+# @param $name Device name used as a key in /etc/fstab
+# @param $dev_name Real (current) device name to be used in SWAPLIST
+#
+# @return fstab line
+#
+################################################################################
+sub create_fstab_line {
+ my ($d_ref, $name, $dev_name) = @_;
+
+ my @fstab_line = ();
+
+ # start with the device key
+ push @fstab_line, $name;
+
+ # add mount information, never dump, order of filesystem checks
+ push @fstab_line, ($d_ref->{mountpoint}, $d_ref->{filesystem},
+ $d_ref->{mount_options}, 0, 2);
+ # order of filesystem checks: the root filesystem gets a 1, the others
+ # got 2
+ $fstab_line[-1] = 1 if ($d_ref->{mountpoint} eq "/");
+
+ # set the ROOT_PARTITION variable, if this is the mountpoint for /
+ $FAI::disk_var{ROOT_PARTITION} = $name
+ if ($d_ref->{mountpoint} eq "/");
+
+ # add to the swaplist, if the filesystem is swap
+ $FAI::disk_var{SWAPLIST} .= " " . $dev_name
+ if ($d_ref->{filesystem} eq "swap");
+
+ # join the columns of one line with tabs
+ return join ("\t", @fstab_line);
+}
+
+################################################################################
+#
# @brief this function generates the fstab file from our representation of the
# partitions to be created.
#
@@ -59,189 +97,102 @@
# walk through all configured parts
# the order of entries is most likely wrong, it is fixed at the end
- foreach my $c ( keys %$config ) {
+ foreach my $c (keys %$config) {
# entry is a physical device
- if ( $c =~ /^PHY_(.+)$/ ) {
+ if ($c =~ /^PHY_(.+)$/) {
my $device = $1;
# make sure the desired fstabkey is defined at all
- defined( $config->{$c}->{fstabkey} )
- or die "INTERNAL ERROR: fstabkey undefined\n";
+ defined ($config->{$c}->{fstabkey})
+ 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 keys %{ $config->{$c}->{partitions} }) {
# keep a reference to save some typing
my $p_ref = $config->{$c}->{partitions}->{$p};
- # skip extended partitions
- next if ( $p_ref->{size}->{extended} );
+ # skip extended partitions and entries without a mountpoint
+ next if ($p_ref->{size}->{extended} || $p_ref->{mountpoint} eq "-");
- # skip entries without a mountpoint
- next if ( $p_ref->{mountpoint} eq "-" );
+ # device key used for mounting
+ my $fstab_key = "";
- # each line is a list of values
- my @fstab_line = ();
-
# write the device name as the first entry; if the user prefers uuids
# or labels, use these if available
my @uuid = ();
- &execute_command_std(
- "/lib/udev/vol_id -u $device" . $p_ref->{number},
- \@uuid, 0 );
+ &FAI::execute_ro_command(
+ "/lib/udev/vol_id -u $device" . $p_ref->{number}, \@uuid, 0);
# every device must have a uuid, otherwise this is an error (unless we
# are testing only)
- ( $FAI::no_dry_run == 0 || scalar(@uuid) == 1 )
- or die "Failed to obtain UUID for $device"
- . $p_ref->{number} . "\n";
+ ($FAI::no_dry_run == 0 || scalar (@uuid) == 1)
+ or die "Failed to obtain UUID for $device" . $p_ref->{number} . "\n";
# get the label -- this is likely empty
my @label = ();
- &execute_command_std(
- "/lib/udev/vol_id -l $device" . $p_ref->{number},
- \@label, 0 );
+ &FAI::execute_ro_command(
+ "/lib/udev/vol_id -l $device" . $p_ref->{number}, \@label, 0);
# using the fstabkey value the desired device entry is defined
- if ( $config->{$c}->{fstabkey} eq "uuid" ) {
- chomp( $uuid[0] );
- push @fstab_line, "UUID=" . $uuid[0];
- } elsif ( $config->{$c}->{fstabkey} eq "label" && scalar(@label) == 1 ) {
- chomp( $label[0] );
- push @fstab_line, "LABEL=" . $label[0];
+ if ($config->{$c}->{fstabkey} eq "uuid") {
+ chomp ($uuid[0]);
+ $fstab_key = "UUID=$uuid[0]";
+ } elsif ($config->{$c}->{fstabkey} eq "label" && scalar(@label) == 1) {
+ chomp($label[0]);
+ $fstab_key = "LABEL=$label[0]";
} else {
# otherwise, use the usual device path
- push @fstab_line, $device . $p_ref->{number};
+ $fstab_key = $device . $p_ref->{number};
}
+
+ push @fstab, &FAI::create_fstab_line($p_ref, $fstab_key, $device . $p_ref->{number});
- # next is the mountpoint
- push @fstab_line, $p_ref->{mountpoint};
-
- # the filesystem to be used
- push @fstab_line, $p_ref->{filesystem};
-
- # add the mount options
- push @fstab_line, $p_ref->{mount_options};
-
- # never dump
- push @fstab_line, 0;
-
- # order of filesystem checks; the root filesystem gets a 1, the others 2
- push @fstab_line, 2;
- $fstab_line[-1] = 1 if ( $p_ref->{mountpoint} eq "/" );
-
- # join the columns of one line with tabs, and push it to our fstab line array
- push @fstab, join( "\t", @fstab_line );
-
- # set the ROOT_PARTITION variable, if this is the mountpoint for /
- $FAI::disk_var{ROOT_PARTITION} = $fstab_line[0]
- if ( $p_ref->{mountpoint} eq "/" );
-
- # add to the swaplist, if the filesystem is swap
- $FAI::disk_var{SWAPLIST} .= " " . $device . $p_ref->{number}
- if ( $p_ref->{filesystem} eq "swap" );
}
- } elsif ( $c =~ /^VG_(.+)$/ ) {
+ } elsif ($c =~ /^VG_(.+)$/) {
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 keys %{ $config->{$c}->{volumes} }) {
# keep a reference to save some typing
my $l_ref = $config->{$c}->{volumes}->{$l};
# skip entries without a mountpoint
- next if ( $l_ref->{mountpoint} eq "-" );
+ next if ($l_ref->{mountpoint} eq "-");
- # each line is a list of values
- my @fstab_line = ();
+ # real device name
+ my @fstab_key = ();
# resolve the symlink to the real device
# and write it as the first entry
- &execute_command_std(
- "readlink -f /dev/$device/$l", \@fstab_line, 0 );
+ &FAI::execute_ro_command("readlink -f /dev/$device/$l", \@fstab_key, 0);
# remove the newline
- chomp( $fstab_line[0] );
+ chomp ($fstab_key[0]);
# make sure we got back a real device
- ( $FAI::no_dry_run == 0 || -b $fstab_line[0] )
+ ($FAI::no_dry_run == 0 || -b $fstab_key[0])
or die "Failed to resolve /dev/$device/$l\n";
- # next is the mountpoint
- push @fstab_line, $l_ref->{mountpoint};
-
- # the filesystem to be used
- push @fstab_line, $l_ref->{filesystem};
-
- # add the mount options
- push @fstab_line, $l_ref->{mount_options};
-
- # never dump
- push @fstab_line, 0;
-
- # order of filesystem checks; the root filesystem gets a 1, the others 2
- push @fstab_line, 2;
- $fstab_line[-1] = 1 if ( $l_ref->{mountpoint} eq "/" );
-
- # join the columns of one line with tabs, and push it to our fstab line array
- push @fstab, join( "\t", @fstab_line );
-
- # set the ROOT_PARTITION variable, if this is the mountpoint for /
- $FAI::disk_var{ROOT_PARTITION} = $fstab_line[0]
- if ( $l_ref->{mountpoint} eq "/" );
-
- # add to the swaplist, if the filesystem is swap
- $FAI::disk_var{SWAPLIST} .= " " . $fstab_line[0]
- if ( $l_ref->{filesystem} eq "swap" );
+ push @fstab, &FAI::create_fstab_line($l_ref, $fstab_key[0], $fstab_key[0]);
}
- } elsif ( $c eq "RAID" ) {
+ } 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 keys %{ $config->{$c}->{volumes} }) {
# keep a reference to save some typing
my $r_ref = $config->{$c}->{volumes}->{$r};
# skip entries without a mountpoint
- next if ( $r_ref->{mountpoint} eq "-" );
+ next if ($r_ref->{mountpoint} eq "-");
- # each line is a list of values
- my @fstab_line = ();
-
- # write the device name as the first entry
- push @fstab_line, "/dev/md" . $r;
-
- # next is the mountpoint
- push @fstab_line, $r_ref->{mountpoint};
-
- # the filesystem to be used
- push @fstab_line, $r_ref->{filesystem};
-
- # add the mount options
- push @fstab_line, $r_ref->{mount_options};
-
- # never dump
- push @fstab_line, 0;
-
- # order of filesystem checks; the root filesystem gets a 1, the others 2
- push @fstab_line, 2;
- $fstab_line[-1] = 1 if ( $r_ref->{mountpoint} eq "/" );
-
- # join the columns of one line with tabs, and push it to our fstab line array
- push @fstab, join( "\t", @fstab_line );
-
- # set the ROOT_PARTITION variable, if this is the mountpoint for /
- $FAI::disk_var{ROOT_PARTITION} = "/dev/md" . $r
- if ( $r_ref->{mountpoint} eq "/" );
-
- # add to the swaplist, if the filesystem is swap
- $FAI::disk_var{SWAPLIST} .= " /dev/md$r"
- if ( $r_ref->{filesystem} eq "swap" );
+ push @fstab, &FAI::create_fstab_line($r_ref, "/dev/md$r", "/dev/md$r");
}
} else {
- die "INTERNAL ERROR: Unexpected key $c\n";
+ &FAI::internal_error("Unexpected key $c");
}
}
Modified: people/michael/features/setup_harddisks_2/implementation/lib/init.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/init.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/init.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -106,5 +106,23 @@
################################################################################
@FAI::commands = ();
+################################################################################
+#
+# @brief Report an error that is due to a bug in the implementation
+#
+# @param $error_msg Error message
+#
+################################################################################
+sub internal_error {
+
+ my ($error_msg) = @_;
+
+ die <<EOF;
+INTERNAL ERROR in setup-storage:
+$error_msg
+Please report this error to the Debian Bug Tracking System.
+EOF
+}
+
1;
Modified: people/michael/features/setup_harddisks_2/implementation/lib/parser.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/parser.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/parser.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -62,7 +62,7 @@
# split $PATH into its components, search all of its components
# and test for $cmd being executable
- ( -x "$_/$cmd" ) and return 1 foreach ( split( ":", $ENV{PATH} ) );
+ (-x "$_/$cmd") and return 1 foreach (split (":", $ENV{PATH}));
# return 0 otherwise
return 0;
}
@@ -86,10 +86,10 @@
my ($disk) = @_;
# test $disk for being numeric
- if ( $disk =~ /^\d+$/ ) {
+ if ($disk =~ /^\d+$/) {
# $disk-1 must be a valid index in the map of all disks in the system
- ( scalar(@FAI::disks) >= $disk )
+ (scalar(@FAI::disks) >= $disk)
or die "this system does not have a physical disk $disk\n";
# fetch the (short) device name
@@ -98,16 +98,16 @@
# test, whether the device name starts with a / and prepend /dev/, if
# appropriate
- ( $disk =~ m{^/} ) or $disk = "/dev/$disk";
+ ($disk =~ m{^/}) or $disk = "/dev/$disk";
# test, whether $disk is a block special device
- ( -b $disk ) or die "$disk is not a valid device name\n";
+ (-b $disk) or die "$disk is not a valid device name\n";
# prepend PHY_
$FAI::device = "PHY_$disk";
# test, whether this is the first disk_config stanza to configure $disk
- defined( $FAI::configs{$FAI::device} )
+ defined ($FAI::configs{$FAI::device})
and die "Duplicate configuration for disk $FAI::disks[ $1-1 ]\n";
# Initialise the entry in $FAI::configs
@@ -134,30 +134,30 @@
# type must either be primary or logical, nothing else may be accepted by the
# parser
- ( $type eq "primary" || $type eq "logical" ) or die "INTERNAL PARSER ERROR\n";
+ ($type eq "primary" || $type eq "logical") or
+ &FAI::internal_error("invalid type $type");
# check that a physical device is being configured; logical partitions are
# only supported on msdos disk labels.
- (
- $FAI::device =~ /^PHY_/ && ( $type ne "logical"
- || $FAI::configs{$FAI::device}{disklabel} eq "msdos" )
- ) or die "Syntax error: invalid partition type";
+ ($FAI::device =~ /^PHY_/ && ($type ne "logical"
+ || $FAI::configs{$FAI::device}{disklabel} eq "msdos")) or
+ die "Syntax error: invalid partition type";
# the index of the new partition
my $part_number = 0;
# create a primary partition
- if ( $type eq "primary" ) {
+ 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 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;
+ defined ($FAI::configs{$FAI::device}{partitions}{$part_id}{size}{extended}) or last;
# on msdos disklabels we cannot have more than 4 primary partitions
- last if ( $part_id > 4
- && $FAI::configs{$FAI::device}{disklabel} eq "msdos" );
+ last if ($part_id > 4
+ && $FAI::configs{$FAI::device}{disklabel} eq "msdos");
# store the latest index found
$part_number = $part_id;
@@ -167,7 +167,7 @@
$part_number++;
# msdos disk labels don't allow for more than 4 primary partitions
- ( $part_number < 5 || $FAI::configs{$FAI::device}{disklabel} ne "msdos" )
+ ($part_number < 5 || $FAI::configs{$FAI::device}{disklabel} ne "msdos")
or die "$part_number are too many primary partitions\n";
} else {
@@ -175,13 +175,13 @@
# 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 keys %{ $FAI::configs{$FAI::device}{partitions} }) {
# skip primary partitions
- next if ( $part_id < 5 );
+ next if ($part_id < 5);
# break, if the partition has not been created by init_part_config
- defined( $FAI::configs{$FAI::device}{partitions}{$part_id}{size}{extended} )
+ defined($FAI::configs{$FAI::device}{partitions}{$part_id}{size}{extended})
or last;
# store the latest index found
@@ -193,20 +193,20 @@
# if this is the first logical partition, the index must be set to 5 and an
# extended partition must be created
- if ( $part_number <= 5 ) {
+ if ($part_number <= 5) {
$part_number = 5;
# the proposed index of the extended partition
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 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;
+ defined ($FAI::configs{$FAI::device}{partitions}{$part_id}{size}{extended}) or last;
# we cannot have more than 4 primary partitions
- last if ( $part_id > 4 );
+ last if ($part_id > 4);
# store the latest index found
$extended = $part_id;
@@ -216,33 +216,34 @@
$extended++;
# msdos disk labels don't allow for more than 4 primary partitions
- ( $extended < 5 )
+ ($extended < 5)
or die "Too many primary partitions while creating extended\n";
+
+ my $part_size =
+ (\%FAI::configs)->{$FAI::device}->{partitions}->{$extended}->{size};
# mark the entry as an extended partition
- $FAI::configs{$FAI::device}{partitions}{$extended}{size}{extended} = 1;
+ $part_size->{extended} = 1;
# add the preserve = 0 flag, if it doesn't exist already
- defined( $FAI::configs{$FAI::device}{partitions}{$extended}{size}{preserve} )
- or $FAI::configs{$FAI::device}{partitions}{$extended}{size}{preserve} = 0;
+ defined ($part_size->{preserve})
+ or $part_size->{preserve} = 0;
# add the resize = 0 flag, if it doesn't exist already
- defined(
- $FAI::configs{$FAI::device}{partitions}{$extended}{size}{resize} ) or
- $FAI::configs{$FAI::device}{partitions}{$extended}{size}{resize} = 0;
+ defined ($part_size->{resize}) or $part_size->{resize} = 0;
}
}
# initialise the hash for the partitions, if it doesn't exist already
# note that it might exists due to options, such as preserve:x,y
# the initialisation is required for the reference defined next
- defined( $FAI::configs{$FAI::device}{partitions}{$part_number} )
+ defined ($FAI::configs{$FAI::device}{partitions}{$part_number})
or $FAI::configs{$FAI::device}{partitions}{$part_number} = {};
# set the reference to the current partition
# the reference is used by all further processing of this config line
$FAI::partition_pointer =
- ( \%FAI::configs )->{$FAI::device}->{partitions}->{$part_number};
+ (\%FAI::configs)->{$FAI::device}->{partitions}->{$part_number};
# as we can't compute the index from the reference, we need to store the
# $part_number explicitly
@@ -252,11 +253,11 @@
$FAI::partition_pointer->{size}->{extended} = 0;
# add the preserve = 0 flag, if it doesn't exist already
- defined( $FAI::partition_pointer->{size}->{preserve} )
+ defined ($FAI::partition_pointer->{size}->{preserve})
or $FAI::partition_pointer->{size}->{preserve} = 0;
# add the resize = 0 flag, if it doesn't exist already
- defined( $FAI::partition_pointer->{size}->{resize} )
+ defined ($FAI::partition_pointer->{size}->{resize})
or $FAI::partition_pointer->{size}->{resize} = 0;
}
@@ -270,12 +271,13 @@
sub convert_unit
{
my ($val) = @_;
- ( $val =~ /^(\d+)([kMGTP%]?)(B)?\s*$/ ) or die "INTERNAL ERROR (convert_unit)\n";
- $val = $1 * ( 1 / 1024 ) if ( $2 eq "k" );
- $val = $1 if ( $2 eq "M" );
- $val = $1 * 1024 if ( $2 eq "G" );
- $val = $1 * ( 1024 * 1024 ) if ( $2 eq "T" );
- $val = $1 * ( 1024 * 1024 * 1024 ) if ( $2 eq "P" );
+ ($val =~ /^(\d+)([kMGTP%]?)(B)?\s*$/) or
+ &FAI::internal_error("convert_unit $val");
+ $val = $1 * (1 / 1024) if ($2 eq "k");
+ $val = $1 if ($2 eq "M");
+ $val = $1 * 1024 if ($2 eq "G");
+ $val = $1 * (1024 * 1024) if ($2 eq "T");
+ $val = $1 * (1024 * 1024 * 1024) if ($2 eq "P");
# % is returned as is
return $val;
}
@@ -308,16 +310,14 @@
disk_config_arg: 'raid'
{
# check, whether raid tools are available
- ( &FAI::in_path( "mdadm" ) == 1 ) or
- die "mdadm not found in PATH\n";
+ &FAI::in_path("mdadm") or die "mdadm not found in PATH\n";
$FAI::device = "RAID";
}
| /^lvm/
{
# check, whether lvm tools are available
- ( &FAI::in_path( "lvcreate" ) == 1 ) or
- die "LVM tools not found in PATH\n";
+ &FAI::in_path("lvcreate") or die "LVM tools not found in PATH\n";
# initialise $FAI::device to inform the following lines about the LVM
# being configured
$FAI::device = "VG_";
@@ -330,38 +330,36 @@
| /^disk(\d+)/
{
# check, whether parted is available
- ( &FAI::in_path( "parted" ) == 1 ) or
- die "parted not found in PATH\n";
+ &FAI::in_path("parted") or die "parted not found in PATH\n";
# initialise the entry of the hash corresponding to disk$1
- &FAI::init_disk_config( $1 );
+ &FAI::init_disk_config($1);
}
option(s?)
| /^\S+/
{
# check, whether parted is available
- ( &FAI::in_path( "parted" ) == 1 ) or
- die "parted not found in PATH\n";
+ &FAI::in_path("parted") or die "parted not found in PATH\n";
# initialise the entry of the hash corresponding to $item[1]
- &FAI::init_disk_config( $item[ 1 ] );
+ &FAI::init_disk_config($item[ 1 ]);
}
option(s?)
option: /^preserve_always:(\d+(,\d+)*)/
{
# set the preserve flag for all ids in all cases
- $FAI::configs{$FAI::device}{partitions}{$_}{size}{preserve} = 1 foreach ( split( ",", $1 ) );
+ $FAI::configs{$FAI::device}{partitions}{$_}{size}{preserve} = 1 foreach (split (",", $1));
}
/^preserve_reinstall:(\d+(,\d+)*)/
{
# set the preserve flag for all ids if $FAI::reinstall is set
- if( $FAI::reinstall == 1 ) {
- $FAI::configs{$FAI::device}{partitions}{$_}{size}{preserve} = 1 foreach ( split( ",", $1 ) );
+ if ($FAI::reinstall) {
+ $FAI::configs{$FAI::device}{partitions}{$_}{size}{preserve} = 1 foreach (split(",", $1));
}
}
| /^resize:(\d+(,\d+)*)/
{
# set the resize flag for all ids
- $FAI::configs{$FAI::device}{partitions}{$_}{size}{resize} = 1 foreach ( split( ",", $1 ) );
+ $FAI::configs{$FAI::device}{partitions}{$_}{size}{resize} = 1 foreach (split(",", $1));
}
| /^disklabel:(msdos|gpt)/
{
@@ -374,8 +372,8 @@
{
# specify a partition that should get the bootable flag set
$FAI::configs{$FAI::device}{bootable} = $1;
- ( $FAI::device =~ /^PHY_(.+)$/ ) or die
- "INTERNAL ERROR: unexpected device name\n";
+ ($FAI::device =~ /^PHY_(.+)$/) or
+ &FAI::internal_error("unexpected device name");
$FAI::disk_var{BOOT_DEVICE} = $1;
}
| 'virtual'
@@ -393,18 +391,18 @@
| /^raid([0156])\s+/
{
# make sure that this is a RAID configuration
- ( $FAI::device eq "RAID" ) or die "RAID entry invalid in this context\n";
+ ($FAI::device eq "RAID") or die "RAID entry invalid in this context\n";
# initialise RAID entry, if it doesn't exist already
- defined( $FAI::configs{RAID} ) or $FAI::configs{RAID}{volumes} = {};
+ defined ($FAI::configs{RAID}) or $FAI::configs{RAID}{volumes} = {};
# compute the next available index - the size of the entry
- my $vol_id = scalar( keys %{ $FAI::configs{RAID}{volumes} } );
+ my $vol_id = scalar (keys %{ $FAI::configs{RAID}{volumes} });
# set the RAID type of this volume
$FAI::configs{RAID}{volumes}{$vol_id}{mode} = $1;
# initialise the hash of devices
$FAI::configs{RAID}{volumes}{$vol_id}{devices} = {};
# set the reference to the current volume
# the reference is used by all further processing of this config line
- $FAI::partition_pointer = ( \%FAI::configs )->{RAID}->{volumes}->{$vol_id};
+ $FAI::partition_pointer = (\%FAI::configs)->{RAID}->{volumes}->{$vol_id};
}
mountpoint devices filesystem mount_options fs_options
| type mountpoint size filesystem mount_options fs_options
@@ -412,22 +410,22 @@
type: 'primary'
{
# initialise a primary partition
- &FAI::init_part_config( $item[ 1 ] );
+ &FAI::init_part_config($item[ 1 ]);
}
| 'logical'
{
# initialise a logical partition
- &FAI::init_part_config( $item[ 1 ] );
+ &FAI::init_part_config($item[ 1 ]);
}
| m{^([^/\s\-]+)-([^/\s\-]+)\s+}
{
# set $FAI::device to VG_$1
$FAI::device = "VG_$1";
# make sure, the volume group $1 has been defined before
- defined( $FAI::configs{$FAI::device} ) or
+ defined ($FAI::configs{$FAI::device}) or
die "Volume group $1 has not been declared yet.\n";
# make sure, $2 has not been defined already
- defined( $FAI::configs{$FAI::device}{volumes}{$2} ) and
+ defined ($FAI::configs{$FAI::device}{volumes}{$2}) and
die "Logical volume $2 has been defined already.\n";
# initialise the new hash
$FAI::configs{$FAI::device}{volumes}{$2} = {};
@@ -436,7 +434,7 @@
$FAI::configs{$FAI::device}{volumes}{$2}{size}{resize} = 0;
# set the reference to the current volume
# the reference is used by all further processing of this config line
- $FAI::partition_pointer = ( \%FAI::configs )->{$FAI::device}->{volumes}->{$2};
+ $FAI::partition_pointer = (\%FAI::configs)->{$FAI::device}->{volumes}->{$2};
}
mountpoint: '-'
@@ -456,13 +454,13 @@
# if the mount point is / or /boot and we are currently doing a
# physical device, the variables should be set, unless they are
# already
- if ( $FAI::device =~ /^PHY_(.+)$/ &&
- ( $item[ 1 ] eq "/boot" || ( $item[ 1 ] eq "/" &&
- !defined( $FAI::disk_var{BOOT_PARTITION} ) ) ) ) {
+ if ($FAI::device =~ /^PHY_(.+)$/ &&
+ ($item[ 1 ] eq "/boot" || ($item[ 1 ] eq "/" &&
+ !defined ($FAI::disk_var{BOOT_PARTITION})))) {
# set the BOOT_DEVICE and BOOT_PARTITION variables, if necessary
$FAI::disk_var{BOOT_PARTITION} = $1 .
$FAI::partition_pointer->{number};
- defined( $FAI::disk_var{BOOT_DEVICE} ) or
+ defined ($FAI::disk_var{BOOT_DEVICE}) or
$FAI::disk_var{BOOT_DEVICE} = $1;
}
}
@@ -472,10 +470,10 @@
# set the device name to VG_ and the name of the volume group
$FAI::device = "VG_$1";
# make sure, the volume group $1 not has been defined already
- defined( $FAI::configs{$FAI::device} ) and
+ defined ($FAI::configs{$FAI::device}) and
die "Volume group $1 has been defined already.\n";
# make sure this line is part of an LVM configuration
- ( $FAI::device =~ /^VG_/ ) or
+ ($FAI::device =~ /^VG_/) or
die "vg is invalid in a non LVM-context.\n";
# initialise the new hash
$FAI::configs{$FAI::device}{volumes} = {};
@@ -490,33 +488,33 @@
# complete the size specification to be a range in all cases
my $range = $1;
# the size is fixed
- if( ! defined( $2 ) )
+ if (!defined ($2))
{
# make it a range of the form x-x
$range = "$range-$1";
}
- elsif( ! defined( $3 ) )
+ elsif (!defined ($3))
{
# range has no upper limit, assume the whole disk
- $range = $range . "100%";
+ $range = "${range}100%";
}
# convert the units, if necessary
- my ($min, $max) = split(/-/, $range);
+ my ($min, $max) = split (/-/, $range);
$min = &FAI::convert_unit($min);
$max = &FAI::convert_unit($max);
$range = "$min-$max";
# enter the range into the hash
$FAI::partition_pointer->{size}->{range} = $range;
# set the resize flag, if required
- defined( $4 ) and $FAI::partition_pointer->{size}->{resize} = 1;
+ defined ($4) and $FAI::partition_pointer->{size}->{resize} = 1;
}
| /^(-\d+[kMGTP%]?)(:resize)?\s+/
{
# complete the range by assuming 0 as the lower limit
my $range = "0$1";
# convert the units, if necessary
- my ($min, $max) = split(/-/, $range);
+ my ($min, $max) = split (/-/, $range);
$min = &FAI::convert_unit($min);
$max = &FAI::convert_unit($max);
$range = "$min-$max";
@@ -530,46 +528,42 @@
devices: /^([^\d,:\s\-][^,:\s]*(:(spare|missing))*(,[^,:\s]+(:(spare|missing))*)*)/
{
# split the device list by ,
- foreach my $dev ( split( ",", $1 ) )
+ foreach my $dev (split(",", $1))
{
# match the substrings
- ( $dev =~ /^([^\d,:\s\-][^,:\s]*)(:(spare|missing))*$/ ) or die "INTERNAL PARSER ERROR\n";
+ ($dev =~ /^([^\d,:\s\-][^,:\s]*)(:(spare|missing))*$/) or
+ &FAI::internal_error("PARSER ERROR");
# redefine the device string
$dev = $1;
# make $dev a full path name; can't validate device name yet as it
# might be created later on
- unless ( $dev =~ m{^/} ) {
- if ( $dev =~ m/^disk(\d+)\.(\d+)/ ) {
- my $short_dev = $FAI::disks[ $1 - 1 ];
- $dev = "/dev/$short_dev$2";
- }
- else {
- $dev = "/dev/$dev";
- }
- }
+ unless ($dev =~ m{^/}) {
+ if ($dev =~ m/^disk(\d+)\.(\d+)/) {
+ my $short_dev = $FAI::disks[ $1 - 1 ];
+ $dev = "/dev/$short_dev$2";
+ } else {
+ $dev = "/dev/$dev";
+ }
+ }
# options are only valid for RAID
- defined( $2 ) and ( $FAI::device ne "RAID" ) and die "Option $2 invalid in a non-RAID context\n";
- if( $FAI::device eq "RAID" )
- {
+ defined ($2) and ($FAI::device ne "RAID") and die "Option $2 invalid in a non-RAID context\n";
+ if ($FAI::device eq "RAID") {
# parse all options
my $spare = 0;
my $missing = 0;
- if( defined( $2 ) )
- {
- ( $2 =~ /spare/ ) and $spare = 1;
- ( $2 =~ /missing/ ) and $missing = 1;
+ if (defined ($2)) {
+ ($2 =~ /spare/) and $spare = 1;
+ ($2 =~ /missing/) and $missing = 1;
}
# each device may only appear once
- defined( $FAI::partition_pointer->{devices}->{$dev} ) and
+ defined ($FAI::partition_pointer->{devices}->{$dev}) and
die "$dev is already part of the RAID volume\n";
# set the options
$FAI::partition_pointer->{devices}->{$dev}->{options} = {
"spare" => $spare,
"missing" => $missing
};
- }
- else
- {
+ } else {
# create an empty hash for each device
$FAI::configs{$FAI::device}{devices}{$dev} = {};
}
@@ -593,7 +587,7 @@
}
| /^\S+/
{
- ( &FAI::in_path("mkfs.$item[1]") == 1 ) or
+ &FAI::in_path("mkfs.$item[1]") or
die "unknown/invalid filesystem type $item[1] (mkfs.$item[1] not found in PATH)\n";
$FAI::partition_pointer->{filesystem} = $item[ 1 ];
}
@@ -622,10 +616,10 @@
$/ = $ifs;
# print the contents of <$IN> for debugging purposes
- ( $FAI::debug > 0 ) and print "Input was:\n" . $input;
+ $FAI::debug and print "Input was:\n" . $input;
# check for old-style configuration files
- ( $input =~ m{(^|\n)[^\n#]+;} )
+ ($input =~ m{(^|\n)[^\n#]+;})
and die "Old style configuration files are not supported\n";
# attempt to parse $input - any error will lead to termination
Modified: people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/sizes.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -39,6 +39,24 @@
################################################################################
#
+# @brief Build an array $start,$end from ($start-$end)
+#
+# @param $rstr Range string
+#
+# @return ($start,$end)
+#
+################################################################################
+sub make_range {
+
+ my ($rstr) = @_;
+ ($rstr =~ /^(\d+%?)-(\d+%?)$/) or &FAI::internal_error("Invalid range");
+ my @range = ();
+ push @range, ($1, $2);
+ return @range;
+}
+
+################################################################################
+#
# @brief Estimate the size of the device $dev
#
# @param $dev Device the size of which should be determined. This may be a
@@ -53,34 +71,34 @@
# try the entire disk first; we then use the data from the current
# configuration; this matches in fact for than the allowable strings, but
# this should be caught later on
- if ( $dev =~ /^\/dev\/[sh]d[a-z]$/ ) {
- defined( $FAI::current_config{$dev}{end_byte} )
+ if ($dev =~ /^\/dev\/[sh]d[a-z]$/) {
+ defined ($FAI::current_config{$dev}{end_byte})
or die "$dev is not a valid block device\n";
# the size is known, return it
- return ( $FAI::current_config{$dev}{end_byte} -
- $FAI::current_config{$dev}{begin_byte} ) / ( 1024 * 1024 );
+ return ($FAI::current_config{$dev}{end_byte} -
+ $FAI::current_config{$dev}{begin_byte}) / (1024 * 1024);
}
# try a partition
- elsif ( $dev =~ /^(\/dev\/[sh]d[a-z])(\d+)$/ ) {
+ elsif ($dev =~ /^(\/dev\/[sh]d[a-z])(\d+)$/) {
# the size is configured, return it
- defined( $FAI::configs{"PHY_$1"}{partitions}{$2}{size}{eff_size} )
+ defined ($FAI::configs{"PHY_$1"}{partitions}{$2}{size}{eff_size})
and return $FAI::configs{"PHY_$1"}{partitions}{$2}{size}{eff_size} /
- ( 1024 * 1024 );
+ (1024 * 1024);
# the size is known from the current configuration on disk, return it
- defined( $FAI::current_config{$1}{partitions}{$2}{count_byte} )
+ defined ($FAI::current_config{$1}{partitions}{$2}{count_byte})
and return $FAI::current_config{$1}{partitions}{$2}{count_byte} /
- ( 1024 * 1024 );
+ (1024 * 1024);
# the size is not known (yet?)
die "Cannot determine size of $dev\n";
}
# try RAID; estimations here are very limited and possible imprecise
- elsif ( $dev =~ /^\/dev\/md(\d+)$/ ) {
+ elsif ($dev =~ /^\/dev\/md(\d+)$/) {
# the list of underlying devices
my @devs = ();
@@ -89,10 +107,10 @@
my $level = "";
# let's see, whether there is a configuration of this volume
- if ( defined( $FAI::configs{RAID}{volumes}{$1}{devices} ) ) {
+ if (defined ($FAI::configs{RAID}{volumes}{$1}{devices})) {
@devs = keys %{ $FAI::configs{RAID}{volumes}{$1}{devices} };
$level = $FAI::configs{RAID}{volumes}{$1}{mode};
- } elsif ( defined( $FAI::current_raid_config{$1}{devices} ) ) {
+ } elsif (defined ($FAI::current_raid_config{$1}{devices})) {
@devs = $FAI::current_raid_config{$1}{devices};
$level = $FAI::current_raid_config{$1}{mode};
} else {
@@ -100,23 +118,23 @@
}
# prepend "raid", if the mode is numeric-only
- $level = "raid" . $level if ( $level =~ /^\d+$/ );
+ $level = "raid$level" if ($level =~ /^\d+$/);
# the number of devices in the volume
- my $dev_count = scalar(@devs);
+ my $dev_count = scalar (@devs);
# now do the mode-specific size estimations
- if ( $level =~ /^raid[015]$/ ) {
- my $min_size = &estimate_size( shift @devs );
+ if ($level =~ /^raid[015]$/) {
+ my $min_size = &estimate_size(shift @devs);
foreach (@devs) {
- my $s = &estimate_size($_);
- $min_size = $s if ( $s < $min_size );
+ my $s = &FAI::estimate_size($_);
+ $min_size = $s if ($s < $min_size);
}
- return $min_size * POSIX::floor( $dev_count / 2 )
- if ( $level eq "raid1" );
- return $min_size * $dev_count if ( $level eq "raid0" );
- return $min_size * ( $dev_count - 1 ) if ( $level eq "raid5" );
+ return $min_size * POSIX::floor($dev_count / 2)
+ if ($level eq "raid1");
+ return $min_size * $dev_count if ($level eq "raid0");
+ return $min_size * ($dev_count - 1) if ($level eq "raid5");
} else {
# probably some more should be implemented
@@ -138,30 +156,22 @@
sub compute_lv_sizes {
# loop through all device configurations
- foreach my $config ( keys %FAI::configs ) {
+ foreach my $config (keys %FAI::configs) {
- # for RAID, there is nothing to be done here
- next if ( $config eq "RAID" );
+ # for RAID or physical disks there is nothing to be done here
+ next if ($config eq "RAID" || $config =~ /^PHY_./);
+ ($config =~ /^VG_(.+)$/) or &FAI::internal_error("invalid config entry $config");
+ my $vg = $1; # the volume group name
- # device is an effective disk
- next if ( $config =~ /^PHY_(.+)$/ );
-
- # configure a volume group
- ( $config =~ /^VG_(.+)$/ )
- or die "INTERNAL ERROR: invalid config entry $config.\n";
-
- # the volume group name
- my $vg = $1;
-
# compute the size of the volume group; this is not exact, but should at
# least give a rough estimation, we assume 1 % of overhead; the value is
# stored in megabytes
my $vg_size = 0;
- foreach my $dev ( keys %{ $FAI::configs{$config}{devices} } ) {
+ foreach my $dev (keys %{ $FAI::configs{$config}{devices} }) {
# $dev may be a partition, an entire disk or a RAID device; otherwise we
# cannot deal with it
- $vg_size += &estimate_size($dev);
+ $vg_size += &FAI::estimate_size($dev);
}
# now subtract 1% of overhead
@@ -170,32 +180,30 @@
# the volumes that require redistribution of free space
my @redist_list = ();
- # the minimum space required in this volume group
+ # the minimum and maximum space required in this volume group
my $min_space = 0;
-
- # the maximum space used in this volume group
my $max_space = 0;
# set effective sizes where available
- foreach my $lv ( keys %{ $FAI::configs{$config}{volumes} } ) {
+ foreach my $lv (keys %{ $FAI::configs{$config}{volumes} }) {
# reference to the size of the current logical volume
- my $lv_size = ( \%FAI::configs )->{$config}->{volumes}->{$lv}->{size};
+ my $lv_size = (\%FAI::configs)->{$config}->{volumes}->{$lv}->{size};
# make sure the size specification is a range (even though it might be
# something like x-x) and store the dimensions
- ( $lv_size->{range} =~ /^(\d+%?)-(\d+%?)$/ )
- or die "INTERNAL ERROR: Invalid range\n";
+ ($lv_size->{range} =~ /^(\d+%?)-(\d+%?)$/)
+ or &FAI::internal_error("Invalid range");
my $start = $1;
my $end = $2;
# start may be given in percents of the size, rewrite it to megabytes
- $start = POSIX::floor( $vg_size * $1 / 100 ) if ( $start =~ /^(\d+)%$/ );
+ $start = POSIX::floor($vg_size * $1 / 100) if ($start =~ /^(\d+)%$/);
# end may be given in percents of the size, rewrite it to megabytes
- $end = POSIX::ceil( $vg_size * $1 / 100 ) if ( $end =~ /^(\d+)%$/ );
+ $end = POSIX::ceil($vg_size * $1 / 100) if ($end =~ /^(\d+)%$/);
# make sure that $end >= $start
- ( $end >= $start ) or die "INTERNAL ERROR: end < start\n";
+ ($end >= $start) or &FAI::internal_error("end < start");
# increase the used space
$min_space += $start;
@@ -205,7 +213,7 @@
$lv_size->{range} = "$start-$end";
# the size is fixed
- if ( $start == $end ) {
+ if ($start == $end) {
# write the size back to the configuration
$lv_size->{eff_size} = $start;
} else {
@@ -216,26 +224,23 @@
}
# test, whether the configuration fits on the volume group at all
- ( $min_space < $vg_size )
+ ($min_space < $vg_size)
or die "Volume group $vg requires $min_space MB\n";
# the extension factor
my $redist_factor = 0;
- $redist_factor = ( $vg_size - $min_space ) / ( $max_space - $min_space )
- if ( $max_space > $min_space );
+ $redist_factor = ($vg_size - $min_space) / ($max_space - $min_space)
+ if ($max_space > $min_space);
# update all sizes that are still ranges
foreach my $lv (@redist_list) {
# get the range again
- ( $FAI::configs{$config}{volumes}{$lv}{size}{range} =~ /^(\d+%?)-(\d+%?)$/ )
- or die "INTERNAL ERROR: Invalid range\n";
- my $start = $1;
- my $end = $2;
+ my ($start, $end) = &FAI::make_range($FAI::configs{$config}{volumes}{$lv}{size}{range});
# write the final size
$FAI::configs{$config}{volumes}{$lv}{size}{eff_size} =
- $start + ( ( $end - $start ) * $redist_factor );
+ $start + (($end - $start) * $redist_factor);
}
}
}
@@ -260,7 +265,7 @@
# device is an effective disk
( $config =~ /^PHY_(.+)$/ )
- or die "INTERNAL ERROR: invalid config entry $config.\n";
+ or &FAI::internal_error("invalid config entry $config");
# nothing to be done, if this is a configuration for a virtual disk
next if ( $FAI::configs{$config}{virtual} == 1 );
@@ -393,11 +398,11 @@
# make sure that there is only one extended partition
( $extended == -1 || 1 == scalar(@worklist) )
- or die "INTERNAL ERROR: More than 1 extended partition\n";
+ or &FAI::internal_error("More than 1 extended partition");
# ensure that it is a primary partition
- ( $part_id <= 4 ) or die
- "INTERNAL ERROR: Extended partition wouldn't be a primary one\n";
+ ( $part_id <= 4 ) or
+ &FAI::internal_error("Extended partition wouldn't be a primary one");
# set the local variable to this id
$extended = $part_id;
@@ -448,7 +453,7 @@
# make sure the size specification is a range (even though it might be
# something like x-x) and store the dimensions
( $part->{size}->{range} =~
- /^(\d+%?)-(\d+%?)$/ ) or die "INTERNAL ERROR: Invalid range\n";
+ /^(\d+%?)-(\d+%?)$/ ) or &FAI::internal_error("Invalid range");
my $start = $1;
my $end = $2;
@@ -475,7 +480,7 @@
}
# make sure that $end >= $start
- ( $end >= $start ) or die "INTERNAL ERROR: end < start\n";
+ ( $end >= $start ) or &FAI::internal_error("end < start");
# check, whether the size is fixed
if ( $end != $start ) {
@@ -517,7 +522,7 @@
# something like x-x) and store the dimensions
( $FAI::configs{$config}{partitions}{$p}{size}{range} =~
/^(\d+%?)-(\d+%?)$/ )
- or die "INTERNAL ERROR: Invalid range\n";
+ or &FAI::internal_error("Invalid range");
my $min_size = $1;
my $max_size = $2;
@@ -576,8 +581,7 @@
if ( $max_space > $available_space );
( $scaled_size >= $start )
- or die
- "INTERNAL ERROR: scaled size is smaller than the desired minimum\n";
+ or &FAI::internal_error("scaled size is smaller than the desired minimum");
$start = $scaled_size;
$end = $start;
@@ -648,13 +652,13 @@
# make sure, extended partitions are only created on msdos disklabels
( $FAI::configs{$config}{disklabel} ne "msdos" && $extended > -1 )
- and die "INTERNAL ERROR: extended partitions are not supported by this disklabel\n";
+ and &FAI::internal_error("extended partitions are not supported by this disklabel");
# ensure that we have done our work
foreach my $part_id ( sort keys %{ $FAI::configs{$config}{partitions} } ) {
( defined( $FAI::configs{$config}{partitions}{$part_id}{start_byte} )
&& defined( $FAI::configs{$config}{partitions}{$part_id}{end_byte} ) )
- or die "INTERNAL ERROR: start or end of partition $part_id not set\n";
+ or &FAI::internal_error("start or end of partition $part_id not set");
}
}
Modified: people/michael/features/setup_harddisks_2/implementation/lib/volumes.pm
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/lib/volumes.pm 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/lib/volumes.pm 2007-12-22 23:05:14 UTC (rev 4831)
@@ -43,9 +43,6 @@
################################################################################
sub get_current_disks {
- # backup value of $FAI::no_dry_run
- my $no_dry_run = $FAI::no_dry_run;
-
# obtain the current state of all disks
foreach my $disk (@FAI::disks) {
@@ -61,44 +58,31 @@
# the list to hold the output of parted commands as parsed below
my @parted_print = ();
- # set no_dry_run to perform read-only commands always
- $FAI::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_std( "parted -s $disk unit TiB print", \@parted_print, 0 );
+ &FAI::execute_ro_command( "parted -s $disk unit TiB print", \@parted_print, 0 );
- # reset no_dry_run
- $FAI::no_dry_run = $no_dry_run;
-
# parted_2 happens when the disk has no disk label, because parted then
# provides no information about the disk
if ( $error eq "parted_2" ) {
- ( $FAI::no_dry_run == 1 ) or die
+ $FAI::no_dry_run or die
"Can't run on test-only mode on this system because there is no disklabel on $disk\n";
# if there is no disk configuration, write an msdos disklabel
if ( !defined( $FAI::configs{"PHY_$disk"}{disklabel} ) ) {
# write the disk label as configured
- $error = &FAI::execute_command( "parted -s $disk mklabel msdos" );
+ $error = &FAI::execute_command("parted -s $disk mklabel msdos");
} else {
# write the disk label as configured
$error = &FAI::execute_command(
"parted -s $disk mklabel " . $FAI::configs{"PHY_$disk"}{disklabel} );
}
-
- # set no_dry_run to perform read-only commands always
- $FAI::no_dry_run = 1;
-
# retry partition-table print
$error =
- &FAI::execute_command( "parted -s $disk unit TiB print", \@parted_print, 0 );
-
- # reset no_dry_run
- $FAI::no_dry_run = $no_dry_run;
+ &FAI::execute_ro_command( "parted -s $disk unit TiB print", \@parted_print, 0 );
}
# check, whether there is still an error
@@ -203,8 +187,7 @@
# we must have seen the header, otherwise probably the format has
# changed
defined( $cols{"File system"}{"start"} )
- or die
- or die "INTERNAL ERROR: Table header not seen yet\n";
+ or &FAI::internal_error("Table header not seen yet");
# the info for the partition number
my $num_cols_before = $cols{"Number"}{"start"};
@@ -235,28 +218,13 @@
}
}
- # set no_dry_run to perform read-only commands always
- $FAI::no_dry_run = 1;
-
# reset the output list
@parted_print = ();
# obtain the partition table using bytes as units
$error =
- &FAI::execute_command_std( "parted -s $disk unit B print free", \@parted_print, 0 );
+ &FAI::execute_ro_command( "parted -s $disk unit B print free", \@parted_print, 0 );
- # reset no_dry_run
- $FAI::no_dry_run = $no_dry_run;
-
- # check, whether an error has occured - already handled by
- # execute_command_std
- # 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" );
- # }
-
# Parse the output of the byte-wise partition table
foreach my $line (@parted_print) {
@@ -290,20 +258,14 @@
and $FAI::current_config{$disk}{partitions}{$1}{is_extended} = 1;
}
- # set no_dry_run to perform read-only commands always
- $FAI::no_dry_run = 1;
-
# reset the output list
@parted_print = ();
# obtain the partition table using bytes as units
$error =
- &FAI::execute_command_std(
+ &FAI::execute_ro_command(
"parted -s $disk unit chs print free", \@parted_print, 0 );
- # reset no_dry_run
- $FAI::no_dry_run = $no_dry_run;
-
# Parse the output of the CHS partition table
foreach my $line (@parted_print) {
@@ -378,18 +340,12 @@
################################################################################
sub get_current_raid {
- # backup value of $FAI::no_dry_run
- my $no_dry_run = $FAI::no_dry_run;
-
# the list to hold the output of mdadm commands as parsed below
my @mdadm_print = ();
- # set no_dry_run to perform read-only commands always
- $FAI::no_dry_run = 1;
-
# try to obtain the list of existing RAID arrays
my $error =
- &FAI::execute_command_std( "mdadm --detail --scan --verbose -c partitions",
+ &FAI::execute_ro_command( "mdadm --detail --scan --verbose -c partitions",
\@mdadm_print, 0 );
# the expected output is as follows
@@ -411,9 +367,6 @@
@{ $FAI::current_raid_config{$id}{devices} } = split( ",", $1 );
}
}
-
- # reset no_dry_run
- $FAI::no_dry_run = $no_dry_run;
}
1;
Modified: people/michael/features/setup_harddisks_2/implementation/setup-storage
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/setup-storage 2007-12-19 18:51:42 UTC (rev 4830)
+++ people/michael/features/setup_harddisks_2/implementation/setup-storage 2007-12-22 23:05:14 UTC (rev 4831)
@@ -25,7 +25,7 @@
################################################################################
#
-# @file shdd2
+# @file setup-storage
#
# @brief The main function of setup-storage - the tool to configure the
# partitioning from within FAI.
@@ -36,6 +36,13 @@
# Some (developer) documentation may be found on
# http://faiwiki.debian.net/index.php/Setup-storage
#
+# Some coding conventions:
+# - no whitespace after ( and before )
+# - keyword<whitespace>(...)
+# - do not start a new line for {
+# - } goes on a line on its own
+# - one blank line after sub ...
+#
# $Id$
#
# @author Christian Kern, Michael Tautschnig
@@ -49,7 +56,7 @@
use Getopt::Std;
# the variables for getopt
-our ( $opt_X, $opt_f );
+our ($opt_X, $opt_f);
# parse the command line
&getopts('Xf:') || die <<EOF;
@@ -59,7 +66,7 @@
EOF
# $disklist must be provided by the environment
-defined( $ENV{disklist} ) or die "Environment variable disklist is not set";
+defined ($ENV{disklist}) or die "Environment variable disklist is not set\n";
################################################################################
#
@@ -67,12 +74,11 @@
#
################################################################################
$FAI::no_dry_run = 0;
-($opt_X) and $FAI::no_dry_run = 1;
-($opt_X) or warn "shdd2 is running in test-only mode!\n";
+$opt_X and $FAI::no_dry_run = 1;
+$opt_X or warn "setup-harddisks is running in test-only mode\n";
-# include all subparts
-unshift @INC, "/var/lib/fai/sm/lib/";
-# unshift @INC, "/usr/share/fai/setup-storage/";
+# include all subparts, which are part of the FAI perl package
+unshift @INC, "/usr/share/fai/setup-storage/";
require "init.pm";
require "volumes.pm";
require "parser.pm";
@@ -85,21 +91,20 @@
my $config_file = undef;
# use the config file, if given
-if ($opt_f) {
- open( $config_file, $opt_f ) or die "Failed to open config file $opt_f\n";
-}
+open($config_file, $opt_f) or die "Failed to open config file $opt_f\n" if ($opt_f);
-# see which class file to use
-else {
- foreach my $classfile ( reverse split( /\s+/, $ENV{classes} ) ) {
- next unless ( -r "$ENV{FAI}/disk_config/$classfile" );
- open( $config_file, "$ENV{FAI}/disk_config/$classfile" );
+unless ($opt_f) {
+ # see which class file to use
+ foreach my $classfile (reverse split(/\s+/, $ENV{classes})) {
+ next unless (-r "$ENV{FAI}/disk_config/$classfile");
+ open($config_file, "$ENV{FAI}/disk_config/$classfile")
+ or die "Failed to open $ENV{FAI}/disk_config/$classfile\n";
last;
}
}
# if we could not find any matching class file, bail out
-defined($config_file) or die "No matching disk_config found\n";
+defined ($config_file) or die "No matching disk_config found\n";
# start the parsing - thereby $FAI::configs is filled
&FAI::run_parser($config_file);
@@ -117,26 +122,24 @@
`modprobe md-mod`;
&FAI::get_current_raid;
-# for debugging purposes to print the hash structures
-use Data::Dumper;
+# debugging only: print the current configuration
+if ($FAI::debug) {
+ # for debugging purposes to print the hash structures
+ use Data::Dumper;
-# debugging only: print the current contents of $FAI::current_config
-if ($FAI::debug) {
print "Current disk layout\n";
- # make sure perl doesn't warn about it being used only once
+ # make sure perl doesn't warn about it being used only once, same below
our %current_config;
print Dumper \%current_config;
print "Current LVM layout\n";
- # make sure perl doesn't warn about it being used only once
our %current_lvm_config;
print Dumper \%current_lvm_config;
print "Current RAID layout\n";
- # make sure perl doesn't warn about it being used only once
our %current_raid_config;
print Dumper \%current_raid_config;
}
@@ -159,21 +162,20 @@
# run all commands
# debugging only: print the command script
-($FAI::debug) and print "$_\n" foreach (@FAI::commands);
+$FAI::debug and print "$_\n" foreach (@FAI::commands);
-# run the command (if $FAI::no_dry_run is set)
-&FAI::execute_command_std($_) foreach (@FAI::commands);
+# run the commands (if $FAI::no_dry_run is set)
+&FAI::execute_command($_) foreach (@FAI::commands);
# generate the proposed fstab contents
-my @fstab = &FAI::generate_fstab( \%FAI::configs );
+my @fstab = &FAI::generate_fstab(\%FAI::configs);
# debugging only; print fstab
-($FAI::debug) and print "$_\n" foreach (@fstab);
+$FAI::debug and print "$_\n" foreach (@fstab);
-# write the proposed contents of fstab to $LOGDIR/fstab, if $FAI::no_dry_run is set
+# write the proposed contents of fstab to $LOGDIR/fstab
if ($FAI::no_dry_run) {
- # write fstab to $LOGDIR/fstab
- open( FSTAB, ">$ENV{LOGDIR}/fstab" )
+ open(FSTAB, ">$ENV{LOGDIR}/fstab")
or die "Failed to open $ENV{LOGDIR}/fstab for writing\n";
print FSTAB "$_\n" foreach (@fstab);
close FSTAB;
@@ -181,15 +183,14 @@
# write variables to $LOGDIR/disk_var.sh
# debugging
-($FAI::debug) and print "$_=$FAI::disk_var{$_}\n"
- foreach ( keys %FAI::disk_var );
+$FAI::debug and print "$_=$FAI::disk_var{$_}\n"
+ foreach (keys %FAI::disk_var);
-# do it, if $FAI::no_dry_run is set
if ($FAI::no_dry_run)
{
- open( DISK_VAR, ">$ENV{LOGDIR}/disk_var.sh" )
+ open(DISK_VAR, ">$ENV{LOGDIR}/disk_var.sh")
or die "Unable to write to file $ENV{LOGDIR}/disk_var.sh\n";
- print DISK_VAR "$_=$FAI::disk_var{$_}\n" foreach ( keys %FAI::disk_var );
+ print DISK_VAR "$_=$FAI::disk_var{$_}\n" foreach (keys %FAI::disk_var);
close DISK_VAR;
}
More information about the Fai-commit
mailing list