[Pkg-libvirt-commits] [libguestfs] 06/14: v2v: Change source disk into a struct.
Hilko Bengen
bengen at moszumanska.debian.org
Sat Aug 30 08:29:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag upstream/1.27.20
in repository libguestfs.
commit 5cf5c3f1c79d66238de5ebe6dae57b5ff93cbe21
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Mon Jun 30 14:08:43 2014 +0100
v2v: Change source disk into a struct.
Simple code refactoring, allowing us to collect the target/@dev
attribute in this (now) structure.
---
v2v/source_libvirt.ml | 23 ++++++++++++++++++-----
v2v/types.ml | 19 ++++++++++++++-----
v2v/types.mli | 8 ++++++--
v2v/v2v.ml | 2 +-
4 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/v2v/source_libvirt.ml b/v2v/source_libvirt.ml
index d9c7b5e..236308b 100644
--- a/v2v/source_libvirt.ml
+++ b/v2v/source_libvirt.ml
@@ -83,7 +83,16 @@ let create_xml ?dir xml =
(* Non-removable disk devices. *)
let disks =
- let disks = ref [] in
+ let get_disks, add_disk =
+ let disks = ref [] in
+ let get_disks () = List.rev !disks in
+ let add_disk qemu_uri format target_dev =
+ disks :=
+ { s_qemu_uri = qemu_uri; s_format = format;
+ s_target_dev = target_dev } :: !disks
+ in
+ get_disks, add_disk
+ in
let obj =
Xml.xpath_eval_expression xpathctx
"/domain/devices/disk[@device='disk']" in
@@ -94,6 +103,10 @@ let create_xml ?dir xml =
let node = Xml.xpathobj_node doc obj i in
Xml.xpathctx_set_current_context xpathctx node;
+ let target_dev =
+ let target_dev = xpath_to_string "target/@dev" "" in
+ if target_dev <> "" then Some target_dev else None in
+
let format =
let format = xpath_to_string "driver[name='qemu']/@type" "" in
if format <> "" then Some format else None in
@@ -105,11 +118,11 @@ let create_xml ?dir xml =
| "block" ->
let path = xpath_to_string "source/@dev" "" in
if path <> "" then
- disks := (absolute_path_of_disk path, format) :: !disks
+ add_disk (absolute_path_of_disk path) format target_dev
| "file" ->
let path = xpath_to_string "source/@file" "" in
if path <> "" then
- disks := (absolute_path_of_disk path, format) :: !disks
+ add_disk (absolute_path_of_disk path) format target_dev
| "network" ->
(* We only handle <source protocol="nbd"> here, and that is
* intended only for virt-p2v. Any other network disk is
@@ -124,7 +137,7 @@ let create_xml ?dir xml =
* XXX Quoting, although it's not needed for virt-p2v.
*)
let path = sprintf "nbd:%s:%d" host port in
- disks := (path, format) :: !disks
+ add_disk path format target_dev
)
| "" -> ()
| protocol ->
@@ -134,7 +147,7 @@ let create_xml ?dir xml =
| disk_type ->
warning ~prog (f_"<disk type='%s'> was ignored") disk_type
done;
- List.rev !disks in
+ get_disks () in
(* XXX Much more metadata needs to be collected here:
* - graphics
diff --git a/v2v/types.ml b/v2v/types.ml
index a2ec59f..3d50bf3 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -38,7 +38,11 @@ type source = {
s_features : string list;
s_disks : source_disk list;
}
-and source_disk = string * string option
+and source_disk = {
+ s_qemu_uri : string;
+ s_format : string option;
+ s_target_dev : string option;
+}
let rec string_of_source s =
sprintf "\
@@ -58,11 +62,16 @@ s_disks = [%s]
(String.concat "," s.s_features)
(String.concat "," (List.map string_of_source_disk s.s_disks))
-and string_of_source_disk (path, format) =
- path ^
- match format with
+and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
+ s_target_dev = target_dev } =
+ sprintf "%s%s%s"
+ qemu_uri
+ (match format with
+ | None -> ""
+ | Some format -> " (" ^ format ^ ")")
+ (match target_dev with
| None -> ""
- | Some format -> " (" ^ format ^ ")"
+ | Some target_dev -> " [" ^ target_dev ^ "]")
type overlay = {
ov_overlay : string;
diff --git a/v2v/types.mli b/v2v/types.mli
index 1e35d82..42f3dbe 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -40,8 +40,12 @@ type source = {
}
(** The source: metadata, disk images. *)
-and source_disk = string * string option
-(** A source file is a qemu URI and a format. *)
+and source_disk = {
+ s_qemu_uri : string; (** QEMU URI of source disk. *)
+ s_format : string option; (** Format. *)
+ s_target_dev : string option; (** Target @dev from libvirt XML. *)
+}
+(** A source disk. *)
val string_of_source : source -> string
val string_of_source_disk : source_disk -> string
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 2676217..2a9fce4 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -57,7 +57,7 @@ let rec main () =
msg (f_"Creating an overlay to protect the source from being modified");
let overlays =
List.map (
- fun (qemu_uri, format) ->
+ fun { s_qemu_uri = qemu_uri; s_format = format } ->
let overlay = Filename.temp_file "v2vovl" ".qcow2" in
unlink_on_exit overlay;
--
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