From: Richard W.M. Jones Date: Mon, 17 Oct 2016 10:09:42 +0000 (+0100) Subject: Test if qemu-img supports -o compat option. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=001e24ec7af047cdf3c5ccb535468c78a89dcdba;p=import-to-ovirt.git Test if qemu-img supports -o compat option. On RHEL 6, this option is not needed (it's the default, and the ancient qemu-img there does not support setting the option). --- diff --git a/import-to-ovirt.pl b/import-to-ovirt.pl index 38bbde2..112e6d6 100755 --- a/import-to-ovirt.pl +++ b/import-to-ovirt.pl @@ -229,6 +229,17 @@ if ($vmtype =~ /^Desktop$/i) { die "$0: --vmtype parameter must be 'Desktop' or 'Server'\n" } +# Does qemu-img generally work OK? +system ("qemu-img create -f qcow2 .test.qcow2 10M >/dev/null") == 0 + or die "qemu-img command not installed or not working\n"; + +# Does this version of qemu-img support compat=0.10? RHEL 6 +# did NOT support it. +my $qemu_img_supports_compat = 0; +system ("qemu-img create -f qcow2 -o compat=0.10 .test.qcow2 10M >/dev/null") == 0 + and $qemu_img_supports_compat = 1; +unlink ".test.qcow2"; + # Open the guest in libguestfs so we can inspect it. my $g = Sys::Guestfs->new (); $g->set_program ("virt-import-to-ovirt"); @@ -447,10 +458,14 @@ for ($i = 0; $i < @disks; ++$i) { chmod (0666, $output_file) or die "chmod: $output_file: $!"; }); print "Copying $input_file ...\n"; + my @compat_option = (); + if ($qemu_img_supports_compat) { + @compat_option = ("-o", "compat=0.10") # for RHEL 6-based ovirt nodes + } system ("qemu-img", "convert", "-p", $input_file, "-O", "qcow2", - "-o", "compat=0.10", # for RHEL 6-based ovirt nodes + @compat_option, $output_file) == 0 or die "qemu-img: $input_file: failed (status $?)"; push @real_sizes, -s $output_file;