From: Richard W.M. Jones Date: Thu, 28 Oct 2010 21:29:43 +0000 (+0100) Subject: inspector: Return canonical block device paths in XML. X-Git-Tag: 1.5.26~13 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=237627df37b97c18362755f646bbe1c4b05ee692;p=libguestfs.git inspector: Return canonical block device paths in XML. --- diff --git a/inspector/example1.xml b/inspector/example1.xml index 790e887..05eecd7 100644 --- a/inspector/example1.xml +++ b/inspector/example1.xml @@ -9,7 +9,7 @@ 0 / - /boot + /boot @@ -17,7 +17,7 @@ e6a4db1e-15c2-477b-ac2a-699181c396aa - + ext4 59336587-da50-4b87-ad47-577a0fd95498 diff --git a/inspector/example2.xml b/inspector/example2.xml index 67bcc01..88afa76 100644 --- a/inspector/example2.xml +++ b/inspector/example2.xml @@ -1,6 +1,6 @@ - /dev/vda2 + /dev/sda2 linux x86_64 rhel @@ -8,21 +8,21 @@ 3 9 - / - /boot + / + /boot - + ext3 a3dde7db-0e74-4545-9f4b-a0fe7d853702 - + ext3 690b600c-201f-4e16-9c11-06e73e248746 - + swap c53d3294-9465-456c-a9ee-1b08d270b1b6 diff --git a/inspector/example3.xml b/inspector/example3.xml index ff01256..8281326 100644 --- a/inspector/example3.xml +++ b/inspector/example3.xml @@ -9,14 +9,14 @@ 0 / - /boot + /boot ext4 acffb3a7-ace7-4398-8233-d554d4b01174 - + ext4 1267df04-7310-4f0e-bd53-f4c30ff2fff7 diff --git a/inspector/example4.xml b/inspector/example4.xml index cc34481..f517ddd 100644 --- a/inspector/example4.xml +++ b/inspector/example4.xml @@ -1,6 +1,6 @@ - /dev/vda2 + /dev/sda2 windows i386 windows @@ -9,10 +9,10 @@ 1 /Windows - / + / - + ntfs F2E8996AE8992E3B diff --git a/inspector/example5.xml b/inspector/example5.xml index 3bb982c..666248e 100644 --- a/inspector/example5.xml +++ b/inspector/example5.xml @@ -13,14 +13,14 @@ /var /tmp /home - /boot + /boot ext3 e15bda18-deca-40d1-beb4-ff31e4068741 - + ext2 b6590940-dc13-4fc5-b306-7c7bdf075f17 diff --git a/inspector/example6.xml b/inspector/example6.xml index d213d6e..52edbcc 100644 --- a/inspector/example6.xml +++ b/inspector/example6.xml @@ -1,6 +1,6 @@ - /dev/vda1 + /dev/sda1 linux x86_64 debian @@ -8,14 +8,14 @@ 0 0 - / + / - + ext4 09384d4f-df19-479b-85fc-6451e56d41aa - + swap c0d1b68f-c0f9-4497-a366-938b37532613 diff --git a/inspector/virt-inspector b/inspector/virt-inspector index 24501fb..a53c76a 100755 --- a/inspector/virt-inspector +++ b/inspector/virt-inspector @@ -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