Richard W.M. Jones
2015-Nov-10 09:00 UTC
[Libguestfs] [PATCH] v2v: Add --compressed option to produce compressed qcow2 files (RHBZ#1279273).
--- v2v/cmdline.ml | 5 ++++- v2v/v2v.ml | 21 ++++++++++++++------- v2v/virt-v2v.pod | 6 ++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml index d4bddce..f6e75ce 100644 --- a/v2v/cmdline.ml +++ b/v2v/cmdline.ml @@ -27,6 +27,7 @@ open Types open Utils let parse_cmdline () + let compressed = ref false in let debug_overlays = ref false in let do_copy = ref true in let machine_readable = ref false in @@ -147,6 +148,7 @@ let parse_cmdline () let argspec = [ "-b", Arg.String add_bridge, "in:out " ^ s_"Map bridge 'in' to 'out'"; "--bridge", Arg.String add_bridge, "in:out " ^ ditto; + "--compressed", Arg.Set compressed, " " ^ s_"Compress output file"; "--dcpath", Arg.String (set_string_option_once "--dcpath" dcpath), "path " ^ s_"Override dcPath (for vCenter)"; "--dcPath", Arg.String (set_string_option_once "--dcPath" dcpath), @@ -220,6 +222,7 @@ read the man page virt-v2v(1). (* Dereference the arguments. *) let args = List.rev !args in + let compressed = !compressed in let dcpath = !dcpath in let debug_overlays = !debug_overlays in let do_copy = !do_copy in @@ -414,6 +417,6 @@ read the man page virt-v2v(1). Output_vdsm.output_vdsm os vdsm_params vmtype output_alloc in input, output, - debug_overlays, do_copy, in_place, network_map, no_trim, + compressed, debug_overlays, do_copy, in_place, network_map, no_trim, output_alloc, output_format, output_name, print_source, root_choice diff --git a/v2v/v2v.ml b/v2v/v2v.ml index dabec7f..f1ebb45 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -50,7 +50,7 @@ let () = Random.self_init () let rec main () (* Handle the command line. *) let input, output, - debug_overlays, do_copy, in_place, network_map, no_trim, + compressed, debug_overlays, do_copy, in_place, network_map, no_trim, output_alloc, output_format, output_name, print_source, root_choice Cmdline.parse_cmdline () in @@ -65,7 +65,8 @@ let rec main () let conversion_mode if not in_place then ( let overlays = create_overlays source.s_disks in - let targets = init_targets overlays source output output_format in + let targets + init_targets overlays source output output_format compressed in Copying (overlays, targets) ) else In_place in @@ -132,7 +133,7 @@ let rec main () let targets if not do_copy then targets - else copy_targets targets input output output_alloc in + else copy_targets targets input output output_alloc compressed in (* Create output metadata. *) message (f_"Creating output metadata"); @@ -247,7 +248,7 @@ and create_overlays src_disks ov_virtual_size = vsize; ov_source = source } ) src_disks -and init_targets overlays source output output_format +and init_targets overlays source output output_format compressed (* 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. @@ -274,6 +275,10 @@ and init_targets overlays source output output_format if format <> "raw" && format <> "qcow2" then error (f_"output format should be 'raw' or 'qcow2'.\n\nUse the '-of <format>' option to select a different output format for the converted guest.\n\nOther output formats are not supported at the moment, although might be considered in future."); + (* Only allow compressed with qcow2. *) + if compressed && format <> "qcow2" then + error (f_"the --compressed flag is only allowed when the output format is qcow2 (-of qcow2)"); + (* output#prepare_targets will fill in the target_file field. * estimate_target_size will fill in the target_estimated_size field. * actual_target_size will fill in the target_actual_size field. @@ -757,7 +762,7 @@ and get_target_firmware inspect guestcaps source output and delete_target_on_exit = ref true -and copy_targets targets input output output_alloc +and copy_targets targets input output output_alloc compressed (* Copy the source to the output. *) at_exit (fun () -> if !delete_target_on_exit then ( @@ -813,9 +818,11 @@ and copy_targets targets input output output_alloc ?preallocation ?compat; let cmd - sprintf "qemu-img convert%s -n -f qcow2 -O %s %s %s" + sprintf "qemu-img convert%s -n -f qcow2 -O %s%s %s %s" (if not (quiet ()) then " -p" else "") - (quote t.target_format) (quote overlay_file) + (quote t.target_format) + (if compressed then " -c" else "") + (quote overlay_file) (quote t.target_file) in if verbose () then printf "%s\n%!" cmd; let start_time = gettimeofday () in diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod index 4370963..2e83168 100644 --- a/v2v/virt-v2v.pod +++ b/v2v/virt-v2v.pod @@ -255,6 +255,12 @@ Display help. See I<--network> below. +=item B<--compressed> + +Write a compressed output file. This is only allowed if the output +format is qcow2 (see I<-of> below), and is equivalent to the I<-c> +option of L<qemu-img(1)>. + =item B<--dcpath> Folder/Datacenter B<NB:> You don't need to use this parameter if you have -- 2.5.0
Pino Toscano
2015-Nov-10 10:21 UTC
Re: [Libguestfs] [PATCH] v2v: Add --compressed option to produce compressed qcow2 files (RHBZ#1279273).
On Tuesday 10 November 2015 09:00:37 Richard W.M. Jones wrote:> --- > v2v/cmdline.ml | 5 ++++- > v2v/v2v.ml | 21 ++++++++++++++------- > v2v/virt-v2v.pod | 6 ++++++ > 3 files changed, 24 insertions(+), 8 deletions(-)LGTM. -- Pino Toscano