[Pkg-libvirt-commits] [libguestfs] 178/266: v2v: Split Types.overlay into Types.target and Types.overlay structures.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:41:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.
commit 97f634e5fbc57620172fee55c8e5aff5edc9b597
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Mon Aug 25 22:13:34 2014 +0100
v2v: Split Types.overlay into Types.target and Types.overlay structures.
Move the fields from Types.overlay which were related to the target
file out. Now Types.overlay is only concerned with the actual qcow2
overlay files, not with a mixture of both files.
For every guest disk, there is one chain which looks like this:
source_disk overlay target
+------------+ +----------------+ +---------------+
| s_qemu_uri |<------ ov_source |<------ target_overlay|
| etc | | ov_overlay_file| | target_file |
+------------+ | ov_sd | | target_format |
| ov_virtual_size| +---------------+
+----------------+
describes source describes temp. describes target
disk file overlay (qcow2) file
This is just refactoring.
---
v2v/output_RHEV.ml | 61 ++++++++++++++++++++++--------------------
v2v/output_libvirt.ml | 31 +++++++++++-----------
v2v/output_libvirt.mli | 2 +-
v2v/output_local.ml | 14 +++++-----
v2v/types.ml | 40 ++++++++++++++++++----------
v2v/types.mli | 24 +++++++++++------
v2v/v2v.ml | 72 ++++++++++++++++++++++++++++----------------------
7 files changed, 138 insertions(+), 106 deletions(-)
diff --git a/v2v/output_RHEV.ml b/v2v/output_RHEV.ml
index 2005ab9..2e09c77 100644
--- a/v2v/output_RHEV.ml
+++ b/v2v/output_RHEV.ml
@@ -196,7 +196,7 @@ object
(* Target VM UUID. *)
val mutable vm_uuid = ""
- (* Map overlay to volume UUID. Key is [ov.ov_sd] field which is unique. *)
+ (* Map overlay to volume UUID. Key is [ov_sd] field which is unique. *)
val vol_uuid = Hashtbl.create 13
(* Flag to indicate if the target image (image_dir) should be
@@ -210,7 +210,7 @@ object
* code.
*
* 'os' is the output storage (-os nfs:/export). 'source' contains a
- * few useful fields such as the guest name. 'overlays' describes the
+ * few useful fields such as the guest name. 'targets' describes the
* destination files. We modify and return this list.
*
* Note it's good to fail here (early) if there are any problems, since
@@ -218,7 +218,7 @@ object
* done the conversion and copy, and the user won't thank us for
* displaying errors there.
*)
- method prepare_output _ overlays =
+ method prepare_targets _ targets =
let rec mount_and_check_export_storage_domain () =
(* The user can either specify -os nfs:/export, or a local directory
* which is assumed to be the already-mounted NFS export. In either
@@ -318,22 +318,22 @@ object
(match rhev_params.vol_uuids with
| [] ->
- (* Generate random volume UUIDs for each overlay. *)
+ (* Generate random volume UUIDs for each target. *)
List.iter (
- fun ov ->
+ fun t ->
let uuid = uuidgen ~prog () in
- Hashtbl.replace vol_uuid ov.ov_sd uuid
- ) overlays
+ Hashtbl.replace vol_uuid t.target_overlay.ov_sd uuid
+ ) targets
| uuids ->
(* Use the volume UUIDs passed to us on the command line. *)
try
List.iter (
- fun (ov, uuid) ->
- Hashtbl.replace vol_uuid ov.ov_sd uuid
- ) (List.combine overlays uuids)
+ fun (t, uuid) ->
+ Hashtbl.replace vol_uuid t.target_overlay.ov_sd uuid
+ ) (List.combine targets uuids)
with Invalid_argument _ ->
error (f_"the number of '--rhev-vol-uuid' parameters passed on the command line has to match the number of guest disk images (for this guest: %d)")
- (List.length overlays)
+ (List.length targets)
)
in
@@ -371,21 +371,22 @@ object
* <VOL_UUID_3> # etc
* <VOL_UUID_3>.meta #
*)
- let overlays =
+ let targets =
let output_alloc_for_rhev =
match output_alloc with
| `Sparse -> "SPARSE"
| `Preallocated -> "PREALLOCATED" in
List.map (
- fun ov ->
+ fun ({ target_overlay = ov } as t) ->
+ let ov_sd = ov.ov_sd in
let vol_uuid =
- try Hashtbl.find vol_uuid ov.ov_sd
+ try Hashtbl.find vol_uuid ov_sd
with Not_found -> assert false in
let target_file = image_dir // vol_uuid in
if verbose then
- eprintf "RHEV: will export %s to %s\n%!" ov.ov_sd target_file;
+ eprintf "RHEV: will export %s to %s\n%!" ov_sd target_file;
(* Create the per-volume metadata (.meta files, in an oVirt-
* specific format).
@@ -394,15 +395,17 @@ object
let size_in_sectors =
if ov.ov_virtual_size &^ 511L <> 0L then
- error (f_"the virtual size of the input disk %s is not an exact multiple of 512 bytes. The virtual size is: %Ld.\n\nThis probably means something unexpected is going on, so please file a bug about this issue.") ov.ov_source_file ov.ov_virtual_size;
+ error (f_"the virtual size of the input disk %s is not an exact multiple of 512 bytes. The virtual size is: %Ld.\n\nThis probably means something unexpected is going on, so please file a bug about this issue.")
+ ov.ov_source.s_qemu_uri
+ ov.ov_virtual_size;
ov.ov_virtual_size /^ 512L in
let format_for_rhev =
- match ov.ov_target_format with
+ match t.target_format with
| "raw" -> "RAW"
| "qcow2" -> "COW"
| _ ->
- error (f_"RHEV does not support the output format '%s', only raw or qcow2") ov.ov_target_format in
+ error (f_"RHEV does not support the output format '%s', only raw or qcow2") t.target_format in
let chan = open_out vol_meta in
let fpf fs = fprintf chan fs in
@@ -422,14 +425,14 @@ object
fpf "EOF\n";
close_out chan;
- { ov with ov_target_file = target_file }
- ) overlays in
+ { t with target_file = target_file }
+ ) targets in
- (* Return the list of overlays. *)
- overlays
+ (* Return the list of targets. *)
+ targets
(* This is called after conversion to write the OVF metadata. *)
- method create_metadata source overlays guestcaps inspect =
+ method create_metadata source targets guestcaps inspect =
(* This modifies the OVF DOM, adding a section for each disk. *)
let rec add_disks ovf =
let references =
@@ -448,7 +451,7 @@ object
(* Iterate over the disks, adding them to the OVF document. *)
iteri (
- fun i ov ->
+ fun i ({ target_overlay = ov } as t) ->
let is_boot_drive = i == 0 in
let vol_uuid =
@@ -464,8 +467,8 @@ object
* does not exist. In that case we simply omit the
* ovf:actual_size attribute.
*)
- if Sys.file_exists ov.ov_target_file then (
- let usage_mb = du_m ov.ov_target_file in
+ if Sys.file_exists t.target_file then (
+ let usage_mb = du_m t.target_file in
if usage_mb > 0L then (
let usage_mb = Int64.to_float usage_mb /. 1024. in
Some usage_mb
@@ -473,11 +476,11 @@ object
) else None in
let format_for_rhev =
- match ov.ov_target_format with
+ match t.target_format with
| "raw" -> "RAW"
| "qcow2" -> "COW"
| _ ->
- error (f_"RHEV does not support the output format '%s', only raw or qcow2") ov.ov_target_format in
+ error (f_"RHEV does not support the output format '%s', only raw or qcow2") t.target_format in
let output_alloc_for_rhev =
match output_alloc with
@@ -535,7 +538,7 @@ object
e "rasd:last_modified_date" [] [PCData iso_time];
] in
append_child item virtualhardware_section;
- ) overlays
+ ) targets
and du_m filename =
(* There's no OCaml binding for st_blocks, so run coreutils 'du -m'
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index fbbd8d6..2ffb4da 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -33,7 +33,7 @@ let append_attr attr = function
| PCData _ | Comment _ -> assert false
| Element e -> e.e_attrs <- e.e_attrs @ [attr]
-let create_libvirt_xml ?pool source overlays guestcaps =
+let create_libvirt_xml ?pool source targets guestcaps =
let memory_k = source.s_memory /^ 1024L in
let features =
@@ -51,25 +51,25 @@ let create_libvirt_xml ?pool source overlays guestcaps =
match guestcaps.gcaps_block_bus with
| Virtio_blk -> "virtio" | IDE -> "ide" in
List.mapi (
- fun i ov ->
+ fun i t ->
e "disk" [
"type", if pool = None then "file" else "volume";
"device", "disk"
] [
e "driver" [
"name", "qemu";
- "type", ov.ov_target_format;
+ "type", t.target_format;
"cache", "none"
] [];
(match pool with
| None ->
e "source" [
- "file", absolute_path ov.ov_target_file;
+ "file", absolute_path t.target_file;
] []
| Some pool ->
e "source" [
"pool", pool;
- "volume", Filename.basename ov.ov_target_file;
+ "volume", Filename.basename t.target_file;
] []
);
e "target" [
@@ -77,7 +77,7 @@ let create_libvirt_xml ?pool source overlays guestcaps =
"bus", block_bus;
] [];
]
- ) overlays in
+ ) targets in
let removables =
(* CDs will be added as IDE devices if we're using virtio, else
@@ -87,7 +87,7 @@ let create_libvirt_xml ?pool source overlays guestcaps =
let cdrom_bus, cdrom_block_prefix, cdrom_index =
match guestcaps.gcaps_block_bus with
| Virtio_blk | IDE -> "ide", "hd", ref 0
- (* | bus -> bus, "sd", ref (List.length overlays) *) in
+ (* | bus -> bus, "sd", ref (List.length targets) *) in
(* Floppy disks always occupy their own virtual bus. *)
let fd_bus = "fdc" and fd_index = ref 0 in
@@ -207,7 +207,7 @@ class output_libvirt verbose oc output_pool = object
| None -> sprintf "-o libvirt -os %s" output_pool
| Some uri -> sprintf "-o libvirt -oc %s -os %s" uri output_pool
- method prepare_output source overlays =
+ method prepare_targets source targets =
(* Connect to output libvirt instance and check that the pool exists
* and dump out its XML.
*)
@@ -238,14 +238,15 @@ class output_libvirt verbose oc output_pool = object
if target_path = "" || not (is_directory target_path) then
error (f_"-o libvirt: output pool '%s' has type='dir' but the /pool/target/path element either does not exist or is not a local directory. See virt-v2v(1) section \"OUTPUT TO LIBVIRT\"") output_pool;
- (* Set up the overlays. *)
+ (* Set up the targets. *)
List.map (
- fun ov ->
- let target_file = target_path // source.s_name ^ "-" ^ ov.ov_sd in
- { ov with ov_target_file = target_file }
- ) overlays
+ fun t ->
+ let target_file =
+ target_path // source.s_name ^ "-" ^ t.target_overlay.ov_sd in
+ { t with target_file = target_file }
+ ) targets
- method create_metadata source overlays guestcaps _ =
+ method create_metadata source targets guestcaps _ =
(* We copied directly into the final pool directory. However we
* have to tell libvirt.
*)
@@ -259,7 +260,7 @@ class output_libvirt verbose oc output_pool = object
warning ~prog (f_"could not refresh libvirt pool %s") output_pool;
(* Create the metadata. *)
- let doc = create_libvirt_xml ~pool:output_pool source overlays guestcaps in
+ let doc = create_libvirt_xml ~pool:output_pool source targets guestcaps in
let tmpfile, chan = Filename.open_temp_file "v2vlibvirt" ".xml" in
DOM.doc_to_chan chan doc;
diff --git a/v2v/output_libvirt.mli b/v2v/output_libvirt.mli
index d341d5f..25d4690 100644
--- a/v2v/output_libvirt.mli
+++ b/v2v/output_libvirt.mli
@@ -23,5 +23,5 @@ val output_libvirt : bool -> string option -> string -> Types.output
{!Types.output} object specialized for writing output to
libvirt. *)
-val create_libvirt_xml : ?pool:string -> Types.source -> Types.overlay list -> Types.guestcaps -> DOM.doc
+val create_libvirt_xml : ?pool:string -> Types.source -> Types.target list -> Types.guestcaps -> DOM.doc
(** This is called from {!Output_local} to generate the libvirt XML. *)
diff --git a/v2v/output_local.ml b/v2v/output_local.ml
index a8719d3..c6e5992 100644
--- a/v2v/output_local.ml
+++ b/v2v/output_local.ml
@@ -29,15 +29,15 @@ class output_local verbose dir = object
method as_options = sprintf "-o local -os %s" dir
- method prepare_output source overlays =
+ method prepare_targets source targets =
List.map (
- fun ov ->
- let target_file = dir // source.s_name ^ "-" ^ ov.ov_sd in
- { ov with ov_target_file = target_file }
- ) overlays
+ fun t ->
+ let target_file = dir // source.s_name ^ "-" ^ t.target_overlay.ov_sd in
+ { t with target_file = target_file }
+ ) targets
- method create_metadata source overlays guestcaps _ =
- let doc = Output_libvirt.create_libvirt_xml source overlays guestcaps in
+ method create_metadata source targets guestcaps _ =
+ let doc = Output_libvirt.create_libvirt_xml source targets guestcaps in
let name = source.s_name in
let file = dir // name ^ ".xml" in
diff --git a/v2v/types.ml b/v2v/types.ml
index 8182aa1..8a1decc 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -118,29 +118,41 @@ and string_of_source_display { s_display_type = typ;
(match password with None -> "" | Some _ -> " with password")
type overlay = {
- ov_overlay : string;
- ov_target_file : string;
- ov_target_format : string;
+ ov_overlay_file : string;
ov_sd : string;
ov_virtual_size : int64;
- ov_source_file : string;
+ ov_source : source_disk;
}
let string_of_overlay ov =
sprintf "\
-ov_overlay = %s
-ov_target_file = %s
-ov_target_format = %s
+ov_overlay_file = %s
ov_sd = %s
ov_virtual_size = %Ld
-ov_source_file = %s
+ov_source = %s
"
- ov.ov_overlay
- ov.ov_target_file
- ov.ov_target_format
+ ov.ov_overlay_file
ov.ov_sd
ov.ov_virtual_size
- ov.ov_source_file
+ ov.ov_source.s_qemu_uri
+
+type target = {
+ target_file : string;
+ target_format : string;
+ target_overlay : overlay;
+}
+
+let string_of_target t =
+ sprintf "\
+target_file = %s
+target_format = %s
+target_overlay = %s
+target_overlay.ov_source = %s
+"
+ t.target_file
+ t.target_format
+ t.target_overlay.ov_overlay_file
+ t.target_overlay.ov_source.s_qemu_uri
type inspect = {
i_root : string;
@@ -181,7 +193,7 @@ end
class virtual output verbose = object
method virtual as_options : string
- method virtual prepare_output : source -> overlay list -> overlay list
- method virtual create_metadata : source -> overlay list -> guestcaps -> inspect -> unit
+ method virtual prepare_targets : source -> target list -> target list
+ method virtual create_metadata : source -> target list -> guestcaps -> inspect -> unit
method keep_serial_console = true
end
diff --git a/v2v/types.mli b/v2v/types.mli
index fca3f4a..9f6d2a9 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -68,21 +68,29 @@ val string_of_source : source -> string
val string_of_source_disk : source_disk -> string
type overlay = {
- ov_overlay : string; (** Local overlay file (qcow2 format). *)
- ov_target_file : string; (** Destination file. *)
- ov_target_format : string; (** Destination format (eg. -of option). *)
+ ov_overlay_file : string; (** Local overlay file (qcow2 format). *)
ov_sd : string; (** sdX libguestfs name of disk. *)
ov_virtual_size : int64; (** Virtual disk size in bytes. *)
- (* Note: The ov_source_file is for information ONLY (eg. printing
+ (* Note: The ov_source is for information ONLY (eg. printing
* error messages). It must NOT be opened/read/modified.
*)
- ov_source_file : string; (** qemu URI for source file. *)
+ ov_source : source_disk; (** Link back to the source disk. *)
}
-(** Disk overlays and destination disks. *)
+(** Overlay disk. *)
val string_of_overlay : overlay -> string
+type target = {
+ target_file : string; (** Destination file. *)
+ target_format : string; (** Destination format (eg. -of option). *)
+
+ target_overlay : overlay; (** Link back to the overlay disk. *)
+}
+(** Target disk. *)
+
+val string_of_target : target -> string
+
type inspect = {
i_root : string; (** Root device. *)
i_type : string; (** Usual inspection fields. *)
@@ -133,9 +141,9 @@ class virtual output : bool -> object
method virtual as_options : string
(** Converts the output object back to the equivalent command line options.
This is just used for pretty-printing log messages. *)
- method virtual prepare_output : source -> overlay list -> overlay list
+ method virtual prepare_targets : source -> target list -> target list
(** Called before conversion to prepare the output. *)
- method virtual create_metadata : source -> overlay list -> guestcaps -> inspect -> unit
+ method virtual create_metadata : source -> target list -> guestcaps -> inspect -> unit
(** Called after conversion to finish off and create metadata. *)
method keep_serial_console : bool
(** Whether this output supports serial consoles (RHEV does not). *)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 4f59ada..210589c 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -95,9 +95,9 @@ let rec main () =
msg (f_"Creating an overlay to protect the source from being modified");
let overlays =
List.map (
- fun { s_qemu_uri = qemu_uri; s_format = format } ->
- let overlay = Filename.temp_file "v2vovl" ".qcow2" in
- unlink_on_exit overlay;
+ fun ({ s_qemu_uri = qemu_uri; s_format = format } as source) ->
+ let overlay_file = Filename.temp_file "v2vovl" ".qcow2" in
+ unlink_on_exit overlay_file;
let options =
"compat=1.1,lazy_refcounts=on" ^
@@ -105,11 +105,11 @@ let rec main () =
| Some fmt -> ",backing_fmt=" ^ fmt) in
let cmd =
sprintf "qemu-img create -q -f qcow2 -b %s -o %s %s"
- (quote qemu_uri) (quote options) overlay in
+ (quote qemu_uri) (quote options) overlay_file in
if verbose then printf "%s\n%!" cmd;
if Sys.command cmd <> 0 then
error (f_"qemu-img command failed, see earlier errors");
- overlay, qemu_uri, format
+ overlay_file, source
) source.s_disks in
(* Open the guestfs handle. *)
@@ -119,38 +119,45 @@ let rec main () =
if verbose then g#set_verbose true;
g#set_network true;
List.iter (
- fun (overlay, _, _) ->
- g#add_drive_opts overlay
+ fun (overlay_file, _) ->
+ g#add_drive_opts overlay_file
~format:"qcow2" ~cachemode:"unsafe" ~discard:"besteffort"
) overlays;
g#launch ();
- (* Work out where we will write the final output. Do this early
- * just so we can display errors to the user before doing too much
- * work.
- *)
- msg (f_"Initializing the target %s") output#as_options;
let overlays =
mapi (
- fun i (overlay, qemu_uri, backing_format) ->
+ fun i (overlay_file, source) ->
(* Grab the virtual size of each disk. *)
let sd = "sd" ^ drive_name i in
let dev = "/dev/" ^ sd in
let vsize = g#blockdev_getsize64 dev in
+ { ov_overlay_file = overlay_file; ov_sd = sd;
+ ov_virtual_size = vsize; ov_source = source }
+ ) overlays in
+
+ (* Work out where we will write the final output. Do this early
+ * just so we can display errors to the user before doing too much
+ * work.
+ *)
+ msg (f_"Initializing the target %s") output#as_options;
+ let targets =
+ List.map (
+ fun ov ->
(* What output format should we use? *)
let format =
- match output_format, backing_format with
+ match output_format, ov.ov_source.s_format with
| Some format, _ -> format (* -of overrides everything *)
| None, Some format -> format (* same as backing format *)
| None, None ->
- error (f_"disk %s (%s) has no defined format, you have to either define the original format in the source metadata, or use the '-of' option to force the output format") sd qemu_uri in
+ error (f_"disk %s (%s) has no defined format, you have to either define the original format in the source metadata, or use the '-of' option to force the output format") ov.ov_sd ov.ov_source.s_qemu_uri in
- { ov_overlay = overlay; ov_target_file = ""; ov_target_format = format;
- ov_sd = sd; ov_virtual_size = vsize; ov_source_file = qemu_uri }
+ (* output#prepare_targets will fill in the target_file field. *)
+ { target_file = ""; target_format = format; target_overlay = ov }
) overlays in
- let overlays = output#prepare_output source overlays in
+ let targets = output#prepare_targets source targets in
(* Inspection - this also mounts up the filesystems. *)
msg (f_"Inspecting the overlay");
@@ -205,16 +212,16 @@ let rec main () =
at_exit (fun () ->
if !delete_target_on_exit then (
List.iter (
- fun ov -> try Unix.unlink ov.ov_target_file with _ -> ()
- ) overlays
+ fun t -> try Unix.unlink t.target_file with _ -> ()
+ ) targets
)
);
- let nr_overlays = List.length overlays in
+ let nr_disks = List.length targets in
iteri (
- fun i ov ->
+ fun i t ->
msg (f_"Copying disk %d/%d to %s (%s)")
- (i+1) nr_overlays ov.ov_target_file ov.ov_target_format;
- if verbose then printf "%s%!" (string_of_overlay ov);
+ (i+1) nr_disks t.target_file t.target_format;
+ if verbose then printf "%s%!" (string_of_target t);
(* It turns out that libguestfs's disk creation code is
* considerably more flexible and easier to use than qemu-img, so
@@ -223,30 +230,31 @@ let rec main () =
*)
(* What output preallocation mode should we use? *)
let preallocation =
- match ov.ov_target_format, output_alloc with
+ match t.target_format, output_alloc with
| "raw", `Sparse -> Some "sparse"
| "raw", `Preallocated -> Some "full"
| "qcow2", `Sparse -> Some "off" (* ? *)
| "qcow2", `Preallocated -> Some "metadata"
| _ -> None (* ignore -oa flag for other formats *) in
let compat =
- match ov.ov_target_format with "qcow2" -> Some "1.1" | _ -> None in
- (new G.guestfs ())#disk_create ov.ov_target_file
- ov.ov_target_format ov.ov_virtual_size ?preallocation ?compat;
+ match t.target_format with "qcow2" -> Some "1.1" | _ -> None in
+ (new G.guestfs ())#disk_create
+ t.target_file t.target_format t.target_overlay.ov_virtual_size
+ ?preallocation ?compat;
let cmd =
sprintf "qemu-img convert -n -f qcow2 -O %s %s %s"
- (quote ov.ov_target_format) (quote ov.ov_overlay)
- (quote ov.ov_target_file) in
+ (quote t.target_format) (quote t.target_overlay.ov_overlay_file)
+ (quote t.target_file) in
if verbose then printf "%s\n%!" cmd;
if Sys.command cmd <> 0 then
error (f_"qemu-img command failed, see earlier errors");
- ) overlays
+ ) targets
) (* do_copy *);
(* Create output metadata. *)
msg (f_"Creating output metadata");
- output#create_metadata source overlays guestcaps inspect;
+ output#create_metadata source targets guestcaps inspect;
msg (f_"Finishing off");
delete_target_on_exit := false; (* Don't delete target on exit. *)
--
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