[Libguestfs] [PATCH 4/4] v2v: start importing "volume" disk types (RHBZ#1146832)

Pino Toscano ptoscano at redhat.com
Tue Apr 14 15:05:42 UTC 2015


Import disks stored as "file"-type volumes.

Side effect: a guest converted to libvirt using virt-v2v can be
converted again using virt-v2v.
---
 v2v/input_libvirtxml.ml | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index ed850cd..5eea015 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -182,8 +182,8 @@ let parse_libvirt_xml ?conn ~verbose xml =
         | "" -> None
         | format -> Some format in
 
-      (* The <disk type='...'> attribute may be 'block', 'file' or
-       * 'network'.  We ignore any other types.
+      (* The <disk type='...'> attribute may be 'block', 'file',
+       * 'network' or 'volume'.  We ignore any other types.
        *)
       match xpath_to_string "@type" "" with
       | "block" ->
@@ -211,6 +211,36 @@ let parse_libvirt_xml ?conn ~verbose xml =
           warning (f_"<disk type='network'> with <source protocol='%s'> was ignored")
             protocol
         )
+      | "volume" ->
+        let pool = xpath_to_string "source/@pool" "" in
+        let vol = xpath_to_string "source/@volume" "" in
+        if pool <> "" && vol <> "" then (
+          let xml = Domainxml.vol_dumpxml ?conn pool vol in
+          let doc = Xml.parse_memory xml in
+          let xpathctx = Xml.xpath_new_context doc in
+
+          let xpath_to_string expr default =
+            let obj = Xml.xpath_eval_expression xpathctx expr in
+            if Xml.xpathobj_nr_nodes obj < 1 then default
+            else (
+              let node = Xml.xpathobj_node doc obj 0 in
+              Xml.node_as_string node
+            ) in
+
+          (* Use the format specified in the volume itself. *)
+          let format =
+            match xpath_to_string "/volume/target/format/@type" "" with
+            | "" -> None
+            | format -> Some format in
+
+          match xpath_to_string "/volume/@type" "" with
+          | "" | "file" ->
+            let path = xpath_to_string "/volume/target/path/text()" "" in
+            if path <> "" then
+              add_disk path format controller (P_source_file path)
+          | vol_type ->
+            warning (f_"<disk type='volume'> with <volume type='%s'> was ignored") vol_type
+        )
       | disk_type ->
         warning (f_"<disk type='%s'> was ignored") disk_type
     done;
-- 
2.1.0




More information about the Libguestfs mailing list