inspector: Return canonical block device paths in XML.
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 28 Oct 2010 21:29:43 +0000 (22:29 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 28 Oct 2010 21:30:55 +0000 (22:30 +0100)
inspector/example1.xml
inspector/example2.xml
inspector/example3.xml
inspector/example4.xml
inspector/example5.xml
inspector/example6.xml
inspector/virt-inspector

index 790e887..05eecd7 100644 (file)
@@ -9,7 +9,7 @@
     <minor_version>0</minor_version>
     <mountpoints>
       <mountpoint dev="/dev/vg_f13x64/lv_root">/</mountpoint>
-      <mountpoint dev="/dev/vda1">/boot</mountpoint>
+      <mountpoint dev="/dev/sda1">/boot</mountpoint>
     </mountpoints>
     <filesystems>
       <filesystem dev="/dev/vg_f13x64/lv_root">
@@ -17,7 +17,7 @@
         <label>Fedora-13-x86_64</label>
         <uuid>e6a4db1e-15c2-477b-ac2a-699181c396aa</uuid>
       </filesystem>
-      <filesystem dev="/dev/vda1">
+      <filesystem dev="/dev/sda1">
         <type>ext4</type>
         <uuid>59336587-da50-4b87-ad47-577a0fd95498</uuid>
       </filesystem>
index 67bcc01..88afa76 100644 (file)
@@ -1,6 +1,6 @@
 <operatingsystems>
   <operatingsystem>
-    <root>/dev/vda2</root>
+    <root>/dev/sda2</root>
     <name>linux</name>
     <arch>x86_64</arch>
     <distro>rhel</distro>
@@ -8,21 +8,21 @@
     <major_version>3</major_version>
     <minor_version>9</minor_version>
     <mountpoints>
-      <mountpoint dev="/dev/vda2">/</mountpoint>
-      <mountpoint dev="/dev/vda1">/boot</mountpoint>
+      <mountpoint dev="/dev/sda2">/</mountpoint>
+      <mountpoint dev="/dev/sda1">/boot</mountpoint>
     </mountpoints>
     <filesystems>
-      <filesystem dev="/dev/vda2">
+      <filesystem dev="/dev/sda2">
         <type>ext3</type>
         <label>/</label>
         <uuid>a3dde7db-0e74-4545-9f4b-a0fe7d853702</uuid>
       </filesystem>
-      <filesystem dev="/dev/vda1">
+      <filesystem dev="/dev/sda1">
         <type>ext3</type>
         <label>/boot</label>
         <uuid>690b600c-201f-4e16-9c11-06e73e248746</uuid>
       </filesystem>
-      <filesystem dev="/dev/vda3">
+      <filesystem dev="/dev/sda3">
         <type>swap</type>
         <uuid>c53d3294-9465-456c-a9ee-1b08d270b1b6</uuid>
       </filesystem>
index ff01256..8281326 100644 (file)
@@ -9,14 +9,14 @@
     <minor_version>0</minor_version>
     <mountpoints>
       <mountpoint dev="/dev/vg_rhel6brewx64/lv_root">/</mountpoint>
-      <mountpoint dev="/dev/vda1">/boot</mountpoint>
+      <mountpoint dev="/dev/sda1">/boot</mountpoint>
     </mountpoints>
     <filesystems>
       <filesystem dev="/dev/vg_rhel6brewx64/lv_root">
         <type>ext4</type>
         <uuid>acffb3a7-ace7-4398-8233-d554d4b01174</uuid>
       </filesystem>
-      <filesystem dev="/dev/vda1">
+      <filesystem dev="/dev/sda1">
         <type>ext4</type>
         <uuid>1267df04-7310-4f0e-bd53-f4c30ff2fff7</uuid>
       </filesystem>
index cc34481..f517ddd 100644 (file)
@@ -1,6 +1,6 @@
 <operatingsystems>
   <operatingsystem>
-    <root>/dev/vda2</root>
+    <root>/dev/sda2</root>
     <name>windows</name>
     <arch>i386</arch>
     <distro>windows</distro>
@@ -9,10 +9,10 @@
     <minor_version>1</minor_version>
     <windows_systemroot>/Windows</windows_systemroot>
     <mountpoints>
-      <mountpoint dev="/dev/vda2">/</mountpoint>
+      <mountpoint dev="/dev/sda2">/</mountpoint>
     </mountpoints>
     <filesystems>
-      <filesystem dev="/dev/vda2">
+      <filesystem dev="/dev/sda2">
         <type>ntfs</type>
         <uuid>F2E8996AE8992E3B</uuid>
       </filesystem>
index 3bb982c..666248e 100644 (file)
       <mountpoint dev="/dev/debian5x64.home.annexia.org/var">/var</mountpoint>
       <mountpoint dev="/dev/debian5x64.home.annexia.org/tmp">/tmp</mountpoint>
       <mountpoint dev="/dev/debian5x64.home.annexia.org/home">/home</mountpoint>
-      <mountpoint dev="/dev/vda1">/boot</mountpoint>
+      <mountpoint dev="/dev/sda1">/boot</mountpoint>
     </mountpoints>
     <filesystems>
       <filesystem dev="/dev/debian5x64.home.annexia.org/root">
         <type>ext3</type>
         <uuid>e15bda18-deca-40d1-beb4-ff31e4068741</uuid>
       </filesystem>
-      <filesystem dev="/dev/vda1">
+      <filesystem dev="/dev/sda1">
         <type>ext2</type>
         <uuid>b6590940-dc13-4fc5-b306-7c7bdf075f17</uuid>
       </filesystem>
index d213d6e..52edbcc 100644 (file)
@@ -1,6 +1,6 @@
 <operatingsystems>
   <operatingsystem>
-    <root>/dev/vda1</root>
+    <root>/dev/sda1</root>
     <name>linux</name>
     <arch>x86_64</arch>
     <distro>debian</distro>
@@ -8,14 +8,14 @@
     <major_version>0</major_version>
     <minor_version>0</minor_version>
     <mountpoints>
-      <mountpoint dev="/dev/vda1">/</mountpoint>
+      <mountpoint dev="/dev/sda1">/</mountpoint>
     </mountpoints>
     <filesystems>
-      <filesystem dev="/dev/vda1">
+      <filesystem dev="/dev/sda1">
         <type>ext4</type>
         <uuid>09384d4f-df19-479b-85fc-6451e56d41aa</uuid>
       </filesystem>
-      <filesystem dev="/dev/vda5">
+      <filesystem dev="/dev/sda5">
         <type>swap</type>
         <uuid>c0d1b68f-c0f9-4497-a366-938b37532613</uuid>
       </filesystem>
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