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>
This commit is contained in:
Tomáš Golembiovský
2017-02-23 16:02:24 +01:00
committed by Richard W.M. Jones
parent 2dbf6bd7b7
commit 90521da5d4
4 changed files with 24 additions and 3 deletions

View File

@@ -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 \

View File

@@ -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.
*)

View File

@@ -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 =

View File

@@ -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.