From 90521da5d45aea60dc3f47f90b97151fd3b484f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Date: Thu, 23 Feb 2017 16:02:24 +0100 Subject: [PATCH] v2v: ova: check libvirt version before OVA import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Libvirt < 3.1.0 lacks enough support for json: pseudo-URLs. Notably it does not allow use of "raw" driver that we need. Signed-off-by: Tomáš Golembiovský --- v2v/Makefile.am | 5 +++-- v2v/input_ova.ml | 3 ++- v2v/utils.ml | 14 ++++++++++++++ v2v/utils.mli | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/v2v/Makefile.am b/v2v/Makefile.am index c458833c4..e30031f7b 100644 --- a/v2v/Makefile.am +++ b/v2v/Makefile.am @@ -63,10 +63,10 @@ SOURCES_MLI = \ SOURCES_ML = \ types.ml \ uefi.ml \ + domainxml.ml \ utils.ml \ name_from_disk.ml \ vCenter.ml \ - domainxml.ml \ DOM.ml \ changeuid.ml \ OVF.ml \ @@ -175,9 +175,9 @@ virt_v2v_copy_to_local_CFLAGS = \ COPY_TO_LOCAL_BOBJECTS = \ uefi.cmo \ + domainxml.cmo \ utils.cmo \ vCenter.cmo \ - domainxml.cmo \ copy_to_local.cmo COPY_TO_LOCAL_XOBJECTS = $(COPY_TO_LOCAL_BOBJECTS:.cmo=.cmx) @@ -402,6 +402,7 @@ endif v2v_unit_tests_BOBJECTS = \ types.cmo \ uefi.cmo \ + domainxml.cmo \ utils.cmo \ DOM.cmo \ OVF.cmo \ diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml index 5e63b605e..7044a6bb8 100644 --- a/v2v/input_ova.ml +++ b/v2v/input_ova.ml @@ -91,7 +91,8 @@ object match detect_file_type ova with | `Tar -> (* Normal ovas are tar file (not compressed). *) - if qemu_img_supports_offset_and_size () then ( + if qemu_img_supports_offset_and_size () && + libvirt_supports_json_raw_driver () then ( (* In newer QEMU we don't have to extract everything. * We can access disks inside the tar archive directly. *) diff --git a/v2v/utils.ml b/v2v/utils.ml index 88c43eb63..20510208c 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -119,6 +119,20 @@ let qemu_img_supports_offset_and_size () = debug "qemu-img supports \"offset\" and \"size\" in json URLs: %b" r; r +(* Libvirt < 3.1.0 lacks enough support for json: pseudo-URLs we use as backing + * files, when importing OVAs directly without extracting them first. + *) +let libvirt_supports_json_raw_driver () = + let libguestfs_backend = (open_guestfs ())#get_backend () in + let libguestfs_backend, _ = String.split ":" libguestfs_backend in + if libguestfs_backend = "libvirt" then ( + let sup = Domainxml.libvirt_get_version () >= (3, 1, 0) in + debug "libvirt supports \"raw\" driver in json URL: %B" sup; + sup + ) + else + true + let find_file_in_tar tar filename = let lines = external_command (sprintf "tar tRvf %s" (Filename.quote tar)) in let rec loop lines = diff --git a/v2v/utils.mli b/v2v/utils.mli index b75baa7f6..77ff24ea5 100644 --- a/v2v/utils.mli +++ b/v2v/utils.mli @@ -55,6 +55,11 @@ val qemu_img_supports_offset_and_size : unit -> bool (** Return true iff [qemu-img] supports the ["offset"] and ["size"] parameters to open a subset of a file. *) +val libvirt_supports_json_raw_driver : unit -> bool +(** Return true if [libvirt] supports ["json:"] pseudo-URLs and accepts the + ["raw"] driver. Function also returns true if [libvirt] backend is not + used. *) + val find_file_in_tar : string -> string -> int64 * int64 (** [find_file_in_tar tar filename] looks up file in [tar] archive and returns a tuple containing at which byte it starts and how long the file is.