[Fai-commit] r6708 - trunk/lib/setup-storage

Michael Tautschnig mt at alioth.debian.org
Sat Oct 22 12:41:58 UTC 2011


Author: mt
Date: 2011-10-22 12:41:58 +0000 (Sat, 22 Oct 2011)
New Revision: 6708

Modified:
   trunk/lib/setup-storage/Commands.pm
   trunk/lib/setup-storage/Init.pm
   trunk/lib/setup-storage/Parser.pm
   trunk/lib/setup-storage/Volumes.pm
Log:
setup-storage: support for /dev/loop*, parse floating point output of parted

* 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.


Modified: trunk/lib/setup-storage/Commands.pm
===================================================================
--- trunk/lib/setup-storage/Commands.pm	2011-10-22 12:40:34 UTC (rev 6707)
+++ trunk/lib/setup-storage/Commands.pm	2011-10-22 12:41:58 UTC (rev 6708)
@@ -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);
   }
 }
 
@@ -1131,8 +1135,13 @@
     my $pre = "cleared2_$disk";
     $pre .= ",exist_" . &FAI::make_device_name($disk, $prev_id) if ($prev_id > -1);
     # build a parted command to create the partition
+    my $dn = &FAI::make_device_name($disk, $part_id);
     &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;
   }
 

Modified: trunk/lib/setup-storage/Init.pm
===================================================================
--- trunk/lib/setup-storage/Init.pm	2011-10-22 12:40:34 UTC (rev 6707)
+++ trunk/lib/setup-storage/Init.pm	2011-10-22 12:41:58 UTC (rev 6708)
@@ -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;

Modified: trunk/lib/setup-storage/Parser.pm
===================================================================
--- trunk/lib/setup-storage/Parser.pm	2011-10-22 12:40:34 UTC (rev 6707)
+++ trunk/lib/setup-storage/Parser.pm	2011-10-22 12:41:58 UTC (rev 6708)
@@ -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";
 

Modified: trunk/lib/setup-storage/Volumes.pm
===================================================================
--- trunk/lib/setup-storage/Volumes.pm	2011-10-22 12:40:34 UTC (rev 6707)
+++ trunk/lib/setup-storage/Volumes.pm	2011-10-22 12:41:58 UTC (rev 6708)
@@ -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;




More information about the Fai-commit mailing list