Blame SOURCES/0013-v2v-i-libvirt-Refactor-map_source-functions.patch

0d20ef
From 179e2fe32705ecc34759630f72dcfdbcf076e526 Mon Sep 17 00:00:00 2001
0d20ef
From: "Richard W.M. Jones" <rjones@redhat.com>
0d20ef
Date: Mon, 20 Oct 2014 18:02:57 +0100
0d20ef
Subject: [PATCH] v2v: -i libvirt: Refactor map_source* functions.
0d20ef
0d20ef
Get rid of the awkward map_source* functions, and replace it with
0d20ef
equivalent code which modifies the source disks objects coming back
0d20ef
from Input_libvirtxml.parse_libvirt_xml.
0d20ef
0d20ef
This is just code refactoring.  Apart from the order in which certain
0d20ef
tests are done, this should be equivalent to the previous code.
0d20ef
0d20ef
(cherry picked from commit 3596165282ccf2c5896894ec4e9a71c6da788463)
0d20ef
---
ffd6ed
 v2v/input_libvirt.ml     | 36 +++++++++++++++++++++++++-----------
0d20ef
 v2v/input_libvirtxml.ml  | 31 ++++++++++++-------------------
0d20ef
 v2v/input_libvirtxml.mli | 11 +----------
ffd6ed
 3 files changed, 38 insertions(+), 40 deletions(-)
0d20ef
0d20ef
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
0d20ef
index e8b1345..9d2869f 100644
0d20ef
--- a/v2v/input_libvirt.ml
0d20ef
+++ b/v2v/input_libvirt.ml
0d20ef
@@ -82,16 +82,23 @@ object
0d20ef
   method source () =
0d20ef
     if verbose then printf "input_libvirt_vcenter_https: source()\n%!";
0d20ef
 
0d20ef
+    error_if_libvirt_backend ();
0d20ef
+
0d20ef
     (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
      * that the domain is not running.  (RHBZ#1138586)
0d20ef
      *)
0d20ef
     let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
-
0d20ef
-    error_if_libvirt_backend ();
0d20ef
+    let { s_disks = disks } as source =
0d20ef
+      Input_libvirtxml.parse_libvirt_xml ~verbose xml in
0d20ef
 
0d20ef
     let mapf = VCenter.map_path_to_uri verbose parsed_uri scheme server in
0d20ef
-    Input_libvirtxml.parse_libvirt_xml ~verbose
0d20ef
-      ~map_source_file:mapf ~map_source_dev:mapf xml
0d20ef
+    let disks = List.map (
0d20ef
+      fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
+        let uri, format = mapf uri format in
0d20ef
+        { disk with s_qemu_uri = uri; s_format = format }
0d20ef
+    ) disks in
0d20ef
+
0d20ef
+    { source with s_disks = disks }
0d20ef
 end
0d20ef
 
0d20ef
 (* Subclass specialized for handling Xen over SSH. *)
0d20ef
@@ -103,17 +110,24 @@ object
0d20ef
   method source () =
0d20ef
     if verbose then printf "input_libvirt_xen_ssh: source()\n%!";
0d20ef
 
ffd6ed
-    (* Get the libvirt XML.  This also checks (as a side-effect)
ffd6ed
-     * that the domain is not running.  (RHBZ#1138586)
ffd6ed
-     *)
ffd6ed
-    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
-
ffd6ed
     error_if_libvirt_backend ();
ffd6ed
     error_if_no_ssh_agent ();
ffd6ed
 
ffd6ed
+    (* Get the libvirt XML.  This also checks (as a side-effect)
ffd6ed
+     * that the domain is not running.  (RHBZ#1138586)
ffd6ed
+     *)
ffd6ed
+    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
+    let { s_disks = disks } as source =
0d20ef
+      Input_libvirtxml.parse_libvirt_xml ~verbose xml in
ffd6ed
+
0d20ef
     let mapf = Xen.map_path_to_uri verbose parsed_uri scheme server in
0d20ef
-    Input_libvirtxml.parse_libvirt_xml ~verbose
0d20ef
-      ~map_source_file:mapf ~map_source_dev:mapf xml
0d20ef
+    let disks = List.map (
0d20ef
+      fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
+        let uri, format = mapf uri format in
0d20ef
+        { disk with s_qemu_uri = uri; s_format = format }
0d20ef
+    ) disks in
0d20ef
+
0d20ef
+    { source with s_disks = disks }
0d20ef
 end
0d20ef
 
0d20ef
 (* Choose the right subclass based on the URI. *)
0d20ef
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
0d20ef
index 984db18..3b19685 100644
0d20ef
--- a/v2v/input_libvirtxml.ml
0d20ef
+++ b/v2v/input_libvirtxml.ml
0d20ef
@@ -24,13 +24,7 @@ open Common_utils
0d20ef
 open Types
0d20ef
 open Utils
0d20ef
 
0d20ef
-type map_source = string -> string option -> string * string option
0d20ef
-
0d20ef
-let no_map : map_source = fun x y -> x, y
0d20ef
-
0d20ef
-let parse_libvirt_xml ~verbose
0d20ef
-    ?(map_source_file = no_map) ?(map_source_dev = no_map)
0d20ef
-    xml =
0d20ef
+let parse_libvirt_xml ~verbose xml =
0d20ef
   if verbose then
0d20ef
     printf "libvirt xml is:\n%s\n" xml;
0d20ef
 
0d20ef
@@ -144,16 +138,12 @@ let parse_libvirt_xml ~verbose
0d20ef
       match xpath_to_string "@type" "" with
0d20ef
       | "block" ->
0d20ef
         let path = xpath_to_string "source/@dev" "" in
0d20ef
-        if path <> "" then (
0d20ef
-          let path, format = map_source_dev path format in
0d20ef
+        if path <> "" then
0d20ef
           add_disk path format target_dev
0d20ef
-        )
0d20ef
       | "file" ->
0d20ef
         let path = xpath_to_string "source/@file" "" in
0d20ef
-        if path <> "" then (
0d20ef
-          let path, format = map_source_file path format in
0d20ef
+        if path <> "" then
0d20ef
           add_disk path format target_dev
0d20ef
-        )
0d20ef
       | "network" ->
0d20ef
         (* We only handle <source protocol="nbd"> here, and that is
0d20ef
          * intended only for virt-p2v.  Any other network disk is
0d20ef
@@ -265,6 +255,8 @@ object
0d20ef
   method source () =
0d20ef
     let xml = read_whole_file file in
0d20ef
 
0d20ef
+    let { s_disks = disks } as source = parse_libvirt_xml ~verbose xml in
0d20ef
+
0d20ef
     (* When reading libvirt XML from a file (-i libvirtxml) we allow
0d20ef
      * paths to disk images in the libvirt XML to be relative (to the XML
0d20ef
      * file).  Relative paths are in fact not permitted in real libvirt
0d20ef
@@ -272,13 +264,14 @@ object
0d20ef
      * when writing the XML by hand.
0d20ef
      *)
0d20ef
     let dir = Filename.dirname (absolute_path file) in
0d20ef
-    let map_source_file path format =
0d20ef
-      let path =
0d20ef
-        if not (Filename.is_relative path) then path else dir // path in
0d20ef
-      path, format
0d20ef
-    in
0d20ef
+    let disks = List.map (
0d20ef
+      fun ({ s_qemu_uri = path } as disk) ->
0d20ef
+        let path =
0d20ef
+          if not (Filename.is_relative path) then path else dir // path in
0d20ef
+        { disk with s_qemu_uri = path }
0d20ef
+    ) disks in
0d20ef
 
0d20ef
-    parse_libvirt_xml ~verbose ~map_source_file xml
0d20ef
+    { source with s_disks = disks }
0d20ef
 end
0d20ef
 
0d20ef
 let input_libvirtxml = new input_libvirtxml
0d20ef
diff --git a/v2v/input_libvirtxml.mli b/v2v/input_libvirtxml.mli
0d20ef
index d673150..5c10df0 100644
0d20ef
--- a/v2v/input_libvirtxml.mli
0d20ef
+++ b/v2v/input_libvirtxml.mli
0d20ef
@@ -18,18 +18,9 @@
0d20ef
 
0d20ef
 (** [-i libvirtxml] source. *)
0d20ef
 
0d20ef
-type map_source = string -> string option -> string * string option
0d20ef
-(** Map function that takes [path] and [format] parameters, and
0d20ef
-    returns the possibly rewritten [qemu_uri, format] pair. *)
0d20ef
-
0d20ef
-val parse_libvirt_xml : verbose:bool -> ?map_source_file:map_source -> ?map_source_dev:map_source -> string -> Types.source
0d20ef
+val parse_libvirt_xml : verbose:bool -> string -> Types.source
0d20ef
 (** Take libvirt XML and parse it into a {!Types.source} structure.
0d20ef
 
0d20ef
-    The optional [?map_source_file] and [?map_source_dev] functions
0d20ef
-    are used to map [<source file="..."/>] and [<source dev="..."/>]
0d20ef
-    from the XML into QEMU URIs.  If not given, then an identity
0d20ef
-    mapping is used.
0d20ef
-
0d20ef
     This function is also used by {!Input_libvirt}, hence it is
0d20ef
     exported. *)
0d20ef
 
0d20ef
-- 
0d20ef
1.8.3.1
0d20ef