[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/2] perl: Don't fail if 'type' (disk format) attribute is missing in libvirt XML (RHBZ#701814).

From: "Richard W.M. Jones" <rjones redhat com>

Old versions of libvirt allowed you to define disks like this:

    <disk type='file' device='disk'>
      <driver name='qemu'/>

Since the <driver> element does not have a 'type' attribute (which
defines the format), we are supposed to do autodetection, so the
format should be undefined.

However what actually happened was that the code in
Sys::Guestfs::Lib::open_guest received format as an empty string from
the xpath query, causing libguestfs to give an error.

If the xpath query returns the format as an empty string, undefine it.
 perl/lib/Sys/Guestfs/Lib.pm |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm
index 42d2e81..2ccc09a 100644
--- a/perl/lib/Sys/Guestfs/Lib.pm
+++ b/perl/lib/Sys/Guestfs/Lib.pm
@@ -234,7 +234,11 @@ sub open_guest
             # Get the disk format (may not be set).
             my $format = $p->find ('./driver/@type', $node);
-            $format = $format->to_literal if $format;
+            if ($format) {
+                $format = $format->to_literal;
+            } else {
+                undef $format; # RHBZ#701814.
+            }
             push @disks, [ $filename, $format ];

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]