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

Richard W.M. Jones rjones at redhat.com
Tue Apr 14 16:18:51 UTC 2015


On Tue, Apr 14, 2015 at 05:05:42PM +0200, Pino Toscano wrote:
> 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

ACK 3/4 & 4/4.

Tests perhaps?  Not sure how easy it is to set up & test a libvirt
volume though.

Thanks,
Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list