[Pkg-libvirt-commits] [libguestfs] 49/65: v2v: start importing "volume" disk types (RHBZ#1146832)

Hilko Bengen bengen at moszumanska.debian.org
Tue Apr 21 12:11:09 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 08b1ba35cfaa526982911fe9f355ed9c168d942d
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Tue Apr 14 16:59:57 2015 +0200

    v2v: start importing "volume" disk types (RHBZ#1146832)
    
    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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list