This is just code motion, but sets the ground-work for adding a second
mode (in-place image modification).
---
sparsify/cmdline.ml | 10 +++++++---
sparsify/sparsify.ml | 24 ++++++++++++++++--------
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index d803ab1..b714a9e 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -26,6 +26,10 @@ open Common_utils
let prog = Filename.basename Sys.executable_name
let error fs = error ~prog fs
+type mode_t =
+ Mode_copying of string * check_t * bool * string option * string option
+and check_t = [`Ignore|`Continue|`Warn|`Fail]
+
let parse_cmdline () =
let display_version () =
printf "virt-sparsify %s\n" Config.package_version;
@@ -155,6 +159,6 @@ read the man page virt-sparsify(1).
error (f_"output '%s' cannot be a character device, it must be a regular
file")
outdisk;
- indisk, outdisk, check_tmpdir, compress, convert,
- debug_gc, format, ignores, machine_readable,
- option, quiet, verbose, trace, zeroes
+ indisk, debug_gc, format, ignores, machine_readable,
+ quiet, verbose, trace, zeroes,
+ Mode_copying (outdisk, check_tmpdir, compress, convert, option)
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index c9692d4..0091d95 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -31,12 +31,23 @@ external statvfs_free_space : string -> int64 =
let () = Random.self_init ()
-let main () =
- let indisk, outdisk, check_tmpdir, compress, convert, debug_gc,
- format, ignores, machine_readable,
- option, quiet, verbose, trace, zeroes =
+let rec main () =
+ let indisk, debug_gc, format, ignores, machine_readable,
+ quiet, verbose, trace, zeroes, mode =
parse_cmdline () in
+ (match mode with
+ | Mode_copying (outdisk, check_tmpdir, compress, convert, option) ->
+ copying indisk outdisk check_tmpdir compress convert
+ format ignores machine_readable option quiet verbose trace zeroes
+ );
+
+ if debug_gc then
+ Gc.compact ()
+
+and copying indisk outdisk check_tmpdir compress convert
+ format ignores machine_readable option quiet verbose trace zeroes =
+
(* Once we have got past argument parsing and start to create
* temporary files (including the potentially massive overlay file), we
* need to catch SIGINT (^C) and exit cleanly so the temporary file
@@ -274,10 +285,7 @@ You can ignore this warning or change it to a hard failure using the
if not quiet then (
print_newline ();
wrap (s_"Sparsify operation completed with no errors. Before deleting the old
disk, carefully check that the target disk boots and works correctly.\n");
- );
-
- if debug_gc then
- Gc.compact ()
+ )
let () =
try main ()
--
1.8.5.3