[Fai-commit] r6568 - branches/experimental/patches
Michael Tautschnig
mt at alioth.debian.org
Sun Jun 5 14:17:02 UTC 2011
Author: mt
Date: 2011-06-05 14:17:01 +0000 (Sun, 05 Jun 2011)
New Revision: 6568
Added:
branches/experimental/patches/setup-storage_loopback-support
branches/experimental/patches/setup-storage_syntax-check-mode
Modified:
branches/experimental/patches/series
Log:
New setup-storage features: loopback support, sytnax check mode
- Added support for /dev/loopX as requested by mikap
- Added new option -s to perform syntax check only (closes: #627913)
Modified: branches/experimental/patches/series
===================================================================
--- branches/experimental/patches/series 2011-06-03 12:03:59 UTC (rev 6567)
+++ branches/experimental/patches/series 2011-06-05 14:17:01 UTC (rev 6568)
@@ -16,3 +16,5 @@
setup-storage_dont-create-current-config
setup-storage_more-verbose-parser
setup-storage_first-part-at-1M
+setup-storage_loopback-support
+setup-storage_syntax-check-mode
Added: branches/experimental/patches/setup-storage_loopback-support
===================================================================
--- branches/experimental/patches/setup-storage_loopback-support (rev 0)
+++ branches/experimental/patches/setup-storage_loopback-support 2011-06-05 14:17:01 UTC (rev 6568)
@@ -0,0 +1,131 @@
+2011-06-05 Michael Tautschnig <mt at debian.org>
+
+ * setup-storage/Commands.pm: setup loopback devices when working on
+ /dev/loop*.
+ * setup-storage/Init.pm: explicit handling of /dev/loop*.
+ * setup-storage/Parser.pm: check for losetup being available in case
+ /dev/loop* is used.
+ * setup-storage/Volumes.pm: support x.ykB as sector size when printed by
+ parted.
+Index: trunk/lib/setup-storage/Init.pm
+===================================================================
+--- trunk.orig/lib/setup-storage/Init.pm
++++ trunk/lib/setup-storage/Init.pm
+@@ -197,6 +197,22 @@
+
+ ################################################################################
+ #
++# @brief Test whether device is a loopback device and, if so, extract the
++# numeric device id
++#
++# @param $dev Device name of disk
++#
++# @return 1, iff it is a loopback device, and device id as second item
++#
++################################################################################
++sub loopback_dev {
++ my ($dev) = @_;
++ return (1, $1) if ($dev =~ m{^/dev/loop(\d+)$});
++ return (0, -1);
++}
++
++################################################################################
++#
+ # @brief Check, whether $dev is a physical device, and extract sub-parts
+ #
+ # @param $dev Device string
+@@ -218,6 +234,11 @@
+ defined($2) or return (1, "/dev/$1", -1);
+ return (1, "/dev/$1", $3);
+ }
++ elsif ((&FAI::loopback_dev($dev))[0])
++ {
++ # we can't tell whether this is a disk of its own or a partition
++ return (1, $dev, -1);
++ }
+ return (0, "", -2);
+ }
+
+@@ -293,6 +314,11 @@
+ my ($dev, $p) = @_;
+ $dev .= "p" if ($dev =~
+ m{^/dev/(cciss/c\dd\d|ida/c\dd\d|rd/c\dd\d|ataraid/d\d|etherd/e\d+\.\d+)$});
++ if ((&FAI::loopback_dev($dev))[0])
++ {
++ $p += (&FAI::loopback_dev($dev))[1];
++ $dev = "/dev/loop"
++ }
+ $dev .= $p;
+ internal_error("Invalid device $dev") unless (&FAI::phys_dev($dev))[0];
+ return $dev;
+Index: trunk/lib/setup-storage/Commands.pm
+===================================================================
+--- trunk.orig/lib/setup-storage/Commands.pm
++++ trunk/lib/setup-storage/Commands.pm
+@@ -917,12 +917,16 @@
+ $part_nr++;
+ $FAI::current_config{$disk}{partitions}{$mapped_id}{new_id} = $part_nr;
+
+- my $post = "exist_" . &FAI::make_device_name($disk, $part_nr);
+- $post .= ",rebuilt_" . &FAI::make_device_name($disk, $part_nr) if
+- $FAI::configs{$config}{partitions}{$part_id}{size}{resize};
+ # build a parted command to create the partition
++ my $dn = &FAI::make_device_name($disk, $part_nr);
+ &FAI::push_command( "parted -s $disk mkpart $part_type \"$fs\" ${start}B ${end}B",
+- "cleared1_$disk", $post );
++ "cleared1_$disk", "prep1_$dn" );
++ my $post = "exist_$dn";
++ $post .= ",rebuilt_$dn" if
++ $FAI::configs{$config}{partitions}{$part_id}{size}{resize};
++ my $cmd = "true";
++ $cmd = "losetup -o $start $dn $disk" if ((&FAI::loopback_dev($disk))[0]);
++ &FAI::push_command($cmd, "prep1_$dn", $post);
+ }
+ }
+
+@@ -1128,11 +1132,16 @@
+ if ($part->{size}->{preserve} || $part->{size}->{resize});
+ $fs = "" if ($fs eq "-");
+
++ my $dn = &FAI::make_device_name($disk, $part_id);
+ my $pre = "cleared2_$disk";
+- $pre .= ",exist_" . &FAI::make_device_name($disk, $prev_id) if ($prev_id > -1);
++ $pre .= ",exist_$dn" if ($prev_id > -1);
+ # build a parted command to create the partition
+ &FAI::push_command( "parted -s $disk mkpart $part_type \"$fs\" ${start}B ${end}B",
+- $pre, "exist_" . &FAI::make_device_name($disk, $part_id) );
++ $pre, "prep2_$dn");
++ my $cmd = "true";
++ $cmd = "losetup -o $start $dn $disk" if ((&FAI::loopback_dev($disk))[0]);
++ &FAI::push_command($cmd, "prep2_$dn", "exist_$dn");
++
+ $prev_id = $part_id;
+ }
+
+Index: trunk/lib/setup-storage/Parser.pm
+===================================================================
+--- trunk.orig/lib/setup-storage/Parser.pm
++++ trunk/lib/setup-storage/Parser.pm
+@@ -123,6 +123,9 @@
+
+ $disk = &FAI::resolve_disk_shortname($disk);
+
++ &FAI::in_path("losetup") or die "losetup not found in PATH\n"
++ if ((&FAI::loopback_dev($disk))[0]);
++
+ # prepend PHY_
+ $FAI::device = "PHY_$disk";
+
+Index: trunk/lib/setup-storage/Volumes.pm
+===================================================================
+--- trunk.orig/lib/setup-storage/Volumes.pm
++++ trunk/lib/setup-storage/Volumes.pm
+@@ -348,7 +348,7 @@
+ # find the BIOS geometry that looks like this:
+ # BIOS cylinder,head,sector geometry: 10011,255,63. Each cylinder is 8225kB.
+ if ($line =~
+- /^BIOS cylinder,head,sector geometry:\s*(\d+),(\d+),(\d+)\.\s*Each cylinder is \d+kB\.$/) {
++ /^BIOS cylinder,head,sector geometry:\s*(\d+),(\d+),(\d+)\.\s*Each cylinder is \d+(\.\d+)?kB\.$/) {
+ $FAI::current_config{$disk}{bios_cylinders} = $1;
+ $FAI::current_config{$disk}{bios_heads} = $2;
+ $FAI::current_config{$disk}{bios_sectors_per_track} = $3;
Added: branches/experimental/patches/setup-storage_syntax-check-mode
===================================================================
--- branches/experimental/patches/setup-storage_syntax-check-mode (rev 0)
+++ branches/experimental/patches/setup-storage_syntax-check-mode 2011-06-05 14:17:01 UTC (rev 6568)
@@ -0,0 +1,97 @@
+2011-06-05 Michael Tautschnig <mt at debian.org>
+
+ * setup-storage: added option -s to perform syntax check only
+ (closes: #627913)
+ * setup-storage/{Init.pm,Parser.pm}: ignore several checks if doing syntax
+ check only.
+
+Index: trunk/bin/setup-storage
+===================================================================
+--- trunk.orig/bin/setup-storage
++++ trunk/bin/setup-storage
+@@ -59,14 +59,15 @@
+ use Getopt::Std;
+ $main::VERSION = $version;
+ $Getopt::Std::STANDARD_HELP_VERSION = 1;
+-our ($opt_X, $opt_f, $opt_h, $opt_d); # the variables for getopt
+-(&getopts('Xf:hd') && !$opt_h) || die <<EOF;
++our ($opt_X, $opt_f, $opt_h, $opt_d, $opt_s); # the variables for getopt
++(&getopts('Xf:hds') && !$opt_h) || die <<EOF;
+ setup-storage version $version
+
+ USAGE: [-X] no test, your harddisks will be formated
+ default: only test, no real formating
+ [-f<config-filename>] default: parse classes
+ [-d] enable debug output (equivalent to debug=1)
++ [-s] perform syntax check only and exit
+ [-h] print this help message
+ EOF
+
+@@ -87,6 +88,9 @@
+ $opt_X and $FAI::no_dry_run = 1;
+ warn "setup-storage is running in test-only mode\n" unless ($FAI::no_dry_run);
+
++# syntactic checks only
++$opt_s and $FAI::check_only = 1;
++
+ # Find out whether $LOGDIR is usable or default to /tmp/fai
+ if (! -d $FAI::DATADIR) {
+ defined ($ENV{LOGDIR}) and die
+@@ -137,6 +141,12 @@
+ # make sure there are no empty disk_config stanzas
+ &FAI::check_config;
+
++if ($FAI::check_only)
++{
++ print "Syntax ok\n";
++ exit 0;
++}
++
+ # first find the proper way to tell udev to settle
+ $FAI::udev_settle = "udevadm settle --timeout=10" if (&FAI::in_path("udevadm"));
+ $FAI::udev_settle = "udevsettle --timeout=10" if (&FAI::in_path("udevsettle"));
+Index: trunk/lib/setup-storage/Init.pm
+===================================================================
+--- trunk.orig/lib/setup-storage/Init.pm
++++ trunk/lib/setup-storage/Init.pm
+@@ -64,6 +64,13 @@
+
+ ################################################################################
+ #
++# @brief Perform syntactic checks only if set to 1
++#
++################################################################################
++$FAI::check_only = 0;
++
++################################################################################
++#
+ # @brief The command to tell udev to settle (udevsettle or udevadm settle)
+ #
+ ################################################################################
+Index: trunk/lib/setup-storage/Parser.pm
+===================================================================
+--- trunk.orig/lib/setup-storage/Parser.pm
++++ trunk/lib/setup-storage/Parser.pm
+@@ -61,6 +61,9 @@
+ # initialize the parameter
+ my ($cmd) = @_;
+
++ # ignored in syntax-check mode
++ return 1 if ($FAI::check_only);
++
+ # 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}));
+@@ -82,9 +85,11 @@
+ sub resolve_disk_shortname {
+ my ($disk) = @_;
+
++ $disk = "sdx" . chr(ord('a') + $disk - 1)
++ if ($FAI::check_only && $disk =~ /^\d+$/);
++
+ # test $disk for being numeric
+ if ($disk =~ /^\d+$/) {
+-
+ # $disk-1 must be a valid index in the map of all disks in the system
+ (scalar(@FAI::disks) >= $disk)
+ or die "this system does not have a physical disk $disk\n";
More information about the Fai-commit
mailing list