Besides, it doesn't need guestfs handle open so move this step earlier
in the process.
Signed-off-by: Roman Kagan <rkagan(a)virtuozzo.com>
---
v2v/v2v.ml | 73 ++++++++++++++++++++++++++++++++------------------------------
1 file changed, 38 insertions(+), 35 deletions(-)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index b3dfa07..c20cbf0 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -144,40 +144,7 @@ let create_overlays src_disks =
ov_virtual_size = vsize; ov_source = source }
) src_disks
-let rec main () =
- (* Handle the command line. *)
- let input, output,
- debug_gc, debug_overlays, do_copy, network_map, no_trim,
- output_alloc, output_format, output_name, print_source, root_choice =
- Cmdline.parse_cmdline () in
-
- (* Print the version, easier than asking users to tell us. *)
- if verbose () then
- printf "%s: %s %s (%s)\n%!"
- prog Config.package_name Config.package_version Config.host_cpu;
-
- if debug_gc then
- at_exit (fun () -> Gc.compact());
-
- let source = open_source input print_source in
- let source = amend_source source output_name network_map in
- let overlays = create_overlays source.s_disks in
-
- (* Open the guestfs handle. *)
- message (f_"Opening the overlay");
- let g = new G.guestfs () in
- if trace () then g#set_trace true;
- if verbose () then g#set_verbose true;
- g#set_network true;
- List.iter (
- fun ({ov_overlay_file = overlay_file}) ->
- g#add_drive_opts overlay_file
- ~format:"qcow2" ~cachemode:"unsafe"
~discard:"besteffort"
- ~copyonread:true
- ) overlays;
-
- g#launch ();
-
+let init_targets overlays source output output_format =
(* 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.
@@ -213,7 +180,43 @@ let rec main () =
target_actual_size = None;
target_overlay = ov }
) overlays in
- let targets = output#prepare_targets source targets in
+
+ output#prepare_targets source targets
+
+let rec main () =
+ (* Handle the command line. *)
+ let input, output,
+ debug_gc, debug_overlays, do_copy, network_map, no_trim,
+ output_alloc, output_format, output_name, print_source, root_choice =
+ Cmdline.parse_cmdline () in
+
+ (* Print the version, easier than asking users to tell us. *)
+ if verbose () then
+ printf "%s: %s %s (%s)\n%!"
+ prog Config.package_name Config.package_version Config.host_cpu;
+
+ if debug_gc then
+ at_exit (fun () -> Gc.compact());
+
+ let source = open_source input print_source in
+ let source = amend_source source output_name network_map in
+ let overlays = create_overlays source.s_disks in
+ let targets = init_targets overlays source output output_format in
+
+ (* Open the guestfs handle. *)
+ message (f_"Opening the overlay");
+ let g = new G.guestfs () in
+ if trace () then g#set_trace true;
+ if verbose () then g#set_verbose true;
+ g#set_network true;
+ List.iter (
+ fun ({ov_overlay_file = overlay_file}) ->
+ g#add_drive_opts overlay_file
+ ~format:"qcow2" ~cachemode:"unsafe"
~discard:"besteffort"
+ ~copyonread:true
+ ) overlays;
+
+ g#launch ();
(* Inspection - this also mounts up the filesystems. *)
message (f_"Inspecting the overlay");
--
2.4.3