inspector: Return canonical block device paths in XML.
[libguestfs.git] / inspector / virt-inspector
index 24501fb..a53c76a 100755 (executable)
@@ -162,7 +162,7 @@ foreach $root (@roots) {
     $xml->startTag ("operatingsystem");
 
     # Basic OS fields.
-    $xml->dataElement (root => $root);
+    $xml->dataElement (root => canonicalize ($root));
 
     my ($s, $distro, $major_version);
     $s = $g->inspect_get_type ($root);
@@ -210,7 +210,8 @@ sub output_mountpoints
 
     $xml->startTag ("mountpoints");
     foreach (@$fskeys) {
-        $xml->dataElement ("mountpoint", $_, dev => $fshash->{$_});
+        $xml->dataElement ("mountpoint", $_,
+                           dev => canonicalize ($fshash->{$_}));
     }
     $xml->endTag ("mountpoints");
 }
@@ -224,7 +225,8 @@ sub output_filesystems
 
     my @fses = $g->inspect_get_filesystems ($root);
     foreach (@fses) {
-        $xml->startTag ("filesystem", dev => $_);
+        $xml->startTag ("filesystem",
+                        dev => canonicalize ($_));
 
         eval {
             my $type = $g->vfs_type ($_);
@@ -347,6 +349,18 @@ sub output_applications_rpm
     }
 }
 
+# The reverse of device name translation, see
+# BLOCK DEVICE NAMING in guestfs(3).
+sub canonicalize
+{
+    local $_ = shift;
+
+    if (m{^/dev/[hv]d([a-z]\d)$}) {
+        return "/dev/sd$1";
+    }
+    $_;
+}
+
 =head1 SHELL QUOTING
 
 Libvirt guest names can contain arbitrary characters, some of which