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

[Libguestfs] [PATCH v2 2/3] v2v: ova: check libvirt version before OVA import



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ý <tgolembi redhat com>
---
 v2v/Makefile.am  |  4 ++--
 v2v/input_ova.ml |  3 ++-
 v2v/utils.ml     | 14 ++++++++++++++
 v2v/utils.mli    |  5 +++++
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index ffd514426..29ce0ea72 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -63,10 +63,10 @@ SOURCES_MLI = \
 SOURCES_ML = \
 	types.ml \
 	uefi.ml \
-	utils.ml \
 	name_from_disk.ml \
 	vCenter.ml \
 	domainxml.ml \
+	utils.ml \
 	DOM.ml \
 	changeuid.ml \
 	OVF.ml \
@@ -175,9 +175,9 @@ virt_v2v_copy_to_local_CFLAGS = \
 
 COPY_TO_LOCAL_BOBJECTS = \
 	uefi.cmo \
-	utils.cmo \
 	vCenter.cmo \
 	domainxml.cmo \
+	utils.cmo \
 	copy_to_local.cmo
 COPY_TO_LOCAL_XOBJECTS = $(COPY_TO_LOCAL_BOBJECTS:.cmo=.cmx)
 
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.
-- 
2.11.1


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