Blame SOURCES/0138-v2v-start-importing-volume-disk-types-RHBZ-1146832.patch

ffd6ed
From 88d41fa8dd122a9f90430a4615497dcc29c10231 Mon Sep 17 00:00:00 2001
ffd6ed
From: Pino Toscano <ptoscano@redhat.com>
ffd6ed
Date: Tue, 14 Apr 2015 16:59:57 +0200
ffd6ed
Subject: [PATCH] v2v: start importing "volume" disk types (RHBZ#1146832)
ffd6ed
ffd6ed
Import disks stored as "file"-type volumes.
ffd6ed
ffd6ed
Side effect: a guest converted to libvirt using virt-v2v can be
ffd6ed
converted again using virt-v2v.
ffd6ed
ffd6ed
(cherry picked from commit 08b1ba35cfaa526982911fe9f355ed9c168d942d)
ffd6ed
---
ffd6ed
 v2v/input_libvirtxml.ml | 34 ++++++++++++++++++++++++++++++++--
ffd6ed
 1 file changed, 32 insertions(+), 2 deletions(-)
ffd6ed
ffd6ed
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
ffd6ed
index 357c46f..16a8115 100644
ffd6ed
--- a/v2v/input_libvirtxml.ml
ffd6ed
+++ b/v2v/input_libvirtxml.ml
ffd6ed
@@ -180,8 +180,8 @@ let parse_libvirt_xml ?conn ~verbose xml =
ffd6ed
         | "" -> None
ffd6ed
         | format -> Some format in
ffd6ed
 
ffd6ed
-      (* The <disk type='...'> attribute may be 'block', 'file' or
ffd6ed
-       * 'network'.  We ignore any other types.
ffd6ed
+      (* The <disk type='...'> attribute may be 'block', 'file',
ffd6ed
+       * 'network' or 'volume'.  We ignore any other types.
ffd6ed
        *)
ffd6ed
       match xpath_to_string "@type" "" with
ffd6ed
       | "block" ->
ffd6ed
@@ -213,6 +213,36 @@ let parse_libvirt_xml ?conn ~verbose xml =
ffd6ed
           warning ~prog (f_"network <disk> with <source protocol='%s'> was ignored")
ffd6ed
             protocol
ffd6ed
         )
ffd6ed
+      | "volume" ->
ffd6ed
+        let pool = xpath_to_string "source/@pool" "" in
ffd6ed
+        let vol = xpath_to_string "source/@volume" "" in
ffd6ed
+        if pool <> "" && vol <> "" then (
ffd6ed
+          let xml = Domainxml.vol_dumpxml ?conn pool vol in
ffd6ed
+          let doc = Xml.parse_memory xml in
ffd6ed
+          let xpathctx = Xml.xpath_new_context doc in
ffd6ed
+
ffd6ed
+          let xpath_to_string expr default =
ffd6ed
+            let obj = Xml.xpath_eval_expression xpathctx expr in
ffd6ed
+            if Xml.xpathobj_nr_nodes obj < 1 then default
ffd6ed
+            else (
ffd6ed
+              let node = Xml.xpathobj_node doc obj 0 in
ffd6ed
+              Xml.node_as_string node
ffd6ed
+            ) in
ffd6ed
+
ffd6ed
+          (* Use the format specified in the volume itself. *)
ffd6ed
+          let format =
ffd6ed
+            match xpath_to_string "/volume/target/format/@type" "" with
ffd6ed
+            | "" -> None
ffd6ed
+            | format -> Some format in
ffd6ed
+
ffd6ed
+          match xpath_to_string "/volume/@type" "" with
ffd6ed
+          | "" | "file" ->
ffd6ed
+            let path = xpath_to_string "/volume/target/path/text()" "" in
ffd6ed
+            if path <> "" then
ffd6ed
+              add_disk path format controller (P_source_file path)
ffd6ed
+          | vol_type ->
ffd6ed
+            warning ~prog (f_"<disk type='volume'> with <volume type='%s'> was ignored") vol_type
ffd6ed
+        )
ffd6ed
       | disk_type ->
ffd6ed
         warning ~prog (f_"<disk type='%s'> was ignored") disk_type
ffd6ed
     done;
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed