[Libguestfs] [PATCH 1/1] Track hd->sd block device remaps

Mike Latimer mlatimer at suse.com
Wed Sep 25 19:40:03 UTC 2013


---
 lib/Sys/VirtConvert/Converter/RedHat.pm | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/Sys/VirtConvert/Converter/RedHat.pm b/lib/Sys/VirtConvert/Converter/RedHat.pm
index 36345e7..fc4f5f0 100644
--- a/lib/Sys/VirtConvert/Converter/RedHat.pm
+++ b/lib/Sys/VirtConvert/Converter/RedHat.pm
@@ -2234,6 +2234,10 @@ sub _remap_block_devices
     # Fedora has used libata since FC7, which is long out of support. We assume
     # that all Fedora distributions in use use libata.
 
+    # Create a hash to track any hd->sd conversions, as any references to
+    # hd devices (in fstab, menu.lst, etc) will need to be converted later.
+    my %idemap;
+
     if ($libata) {
         # If there are any IDE devices, the guest will have named these sdX
         # after any SCSI devices. i.e. If we have disks hda, hdb, sda and sdb,
@@ -2246,10 +2250,15 @@ sub _remap_block_devices
         # this is a weird and somewhat unlikely situation I'm going with SCSI
         # first until we have a more comprehensive solution.
 
+        my $idedev;
         my @newdevices;
         my $suffix = 'a';
         foreach my $device (@devices) {
-            $device = 'sd'.$suffix++ if ($device =~ /(?:h|s)d[a-z]+/);
+            if ($device =~ /(?:h|s)d[a-z]+/) {
+                $idedev = $device;
+                $device = 'sd'.$suffix++;
+                $idemap{$device} = $idedev if ($device ne $idedev);
+            }
             push(@newdevices, $device);
         }
         @devices = @newdevices;
@@ -2285,6 +2294,13 @@ sub _remap_block_devices
             $map{'xvd'.$1} = $mapped;
         }
         $map{$device} = $mapped;
+        # Also add a mapping for previously saved hd->sd conversions
+        if (defined($idemap{$device})) {
+            my $idedevice;
+            $idedevice = $idemap{$device};
+            $map{$idedevice} = $mapped;
+        }
+
         $letter++;
     }
 
-- 
1.8.1.4




More information about the Libguestfs mailing list