This makes it easier to navigate within the file (a tribute to C).
Signed-off-by: Roman Kagan <rkagan(a)virtuozzo.com>
---
v2v/v2v.ml | 160 ++++++++++++++++++++++++++++++-------------------------------
1 file changed, 80 insertions(+), 80 deletions(-)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 7888f0e..554b30d 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -646,85 +646,7 @@ let preserve_overlays overlays src_name =
printf (f_"Overlay saved as %s [--debug-overlays]\n") saved_filename
) overlays
-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");
- let inspect = inspect_source g root_choice in
-
- let mpstats = get_mpstats g in
- check_free_space mpstats;
- check_target_free_space mpstats source targets output;
-
- let keep_serial_console = output#keep_serial_console in
- let guestcaps = do_convert g inspect source keep_serial_console in
-
- g#umount_all ();
-
- if no_trim <> ["*"] && (do_copy || debug_overlays) then (
- (* Doing fstrim on all the filesystems reduces the transfer size
- * because unused blocks are marked in the overlay and thus do
- * not have to be copied.
- *)
- message (f_"Mapping filesystem data to avoid copying unused and blank
areas");
- do_fstrim g no_trim inspect;
- );
-
- message (f_"Closing the overlay");
- g#umount_all ();
- g#shutdown ();
- g#close ();
-
- let target_firmware = get_target_firmware inspect guestcaps source output in
- let target_buses = target_bus_assignment source targets guestcaps in
- let targets =
- if not do_copy then targets
- else copy_targets targets input output output_alloc in
-
- (* Create output metadata. *)
- message (f_"Creating output metadata");
- output#create_metadata source targets target_buses guestcaps inspect
- target_firmware;
-
- if debug_overlays then preserve_overlays overlays source.s_name;
-
- message (f_"Finishing off");
- delete_target_on_exit := false; (* Don't delete target on exit. *)
-
-and inspect_source g root_choice =
+let inspect_source g root_choice =
let roots = g#inspect_os () in
let roots = Array.to_list roots in
@@ -865,7 +787,7 @@ and inspect_source g root_choice =
(* Perform the fstrim. The trimming bit is easy. Dealing with the
* [--no-trim] parameter .. not so much.
*)
-and do_fstrim g no_trim inspect =
+let do_fstrim (g:G.guestfs) no_trim inspect =
(* Get all filesystems. *)
let fses = g#list_filesystems () in
@@ -921,4 +843,82 @@ and do_fstrim g no_trim inspect =
)
) fses
+let 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");
+ let inspect = inspect_source g root_choice in
+
+ let mpstats = get_mpstats g in
+ check_free_space mpstats;
+ check_target_free_space mpstats source targets output;
+
+ let keep_serial_console = output#keep_serial_console in
+ let guestcaps = do_convert g inspect source keep_serial_console in
+
+ g#umount_all ();
+
+ if no_trim <> ["*"] && (do_copy || debug_overlays) then (
+ (* Doing fstrim on all the filesystems reduces the transfer size
+ * because unused blocks are marked in the overlay and thus do
+ * not have to be copied.
+ *)
+ message (f_"Mapping filesystem data to avoid copying unused and blank
areas");
+ do_fstrim g no_trim inspect;
+ );
+
+ message (f_"Closing the overlay");
+ g#umount_all ();
+ g#shutdown ();
+ g#close ();
+
+ let target_firmware = get_target_firmware inspect guestcaps source output in
+ let target_buses = target_bus_assignment source targets guestcaps in
+ let targets =
+ if not do_copy then targets
+ else copy_targets targets input output output_alloc in
+
+ (* Create output metadata. *)
+ message (f_"Creating output metadata");
+ output#create_metadata source targets target_buses guestcaps inspect
+ target_firmware;
+
+ if debug_overlays then preserve_overlays overlays source.s_name;
+
+ message (f_"Finishing off");
+ delete_target_on_exit := false (* Don't delete target on exit. *)
+
let () = run_main_and_handle_errors main
--
2.4.3