[Libguestfs] [PATCH v2 15/17] v2v: add --in-place mode

Roman Kagan rkagan at virtuozzo.com
Tue Aug 11 17:00:34 UTC 2015


In this mode, converting of the VM configuration, setting up the
rollback path for error cases, transforming the VM storage and so on is
taken care of by a third-party toolset, and virt-v2v is only supposed to
tune up the guest OS directly inside the source VM, to enable it to boot
and run under the input hypervisor.

Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
changes from v1:
 - make use of the preceding refactoring to simplify this patch, and
   avoid using possibly undefined objects on in_place paths.
   Note that I did *not* make it a totally separate scenario to avoid
   marginalizing it and because it shares a lot with the original one.
 - split out doc and test
 - put the new option in alphabetical order WRT others

 v2v/cmdline.ml |  7 ++++++-
 v2v/v2v.ml     | 45 ++++++++++++++++++++++++++++++++++++---------
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index eaf57dc..8383ce8 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -32,6 +32,7 @@ let parse_cmdline () =
   let do_copy = ref true in
   let input_conn = ref "" in
   let input_format = ref "" in
+  let in_place = ref false in
   let machine_readable = ref false in
   let output_conn = ref "" in
   let output_format = ref "" in
@@ -147,6 +148,7 @@ let parse_cmdline () =
     "-ic",       Arg.Set_string input_conn, "uri " ^ s_"Libvirt URI";
     "-if",       Arg.Set_string input_format,
     "format " ^ s_"Input format (for -i disk)";
+    "--in-place", Arg.Set in_place,         " " ^ s_"Only tune the guest in the input VM";
     "--short-options", Arg.Unit display_short_options, " " ^ s_"List short options";
     "--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
     "--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable";
@@ -217,6 +219,7 @@ read the man page virt-v2v(1).
   let input_conn = match !input_conn with "" -> None | s -> Some s in
   let input_format = match !input_format with "" -> None | s -> Some s in
   let input_mode = !input_mode in
+  let in_place = !in_place in
   let machine_readable = !machine_readable in
   let network_map = !network_map in
   let no_trim = !no_trim in
@@ -305,6 +308,8 @@ read the man page virt-v2v(1).
       Input_ova.input_ova filename in
 
   (* Parse the output mode. *)
+  if output_mode <> `Not_set && in_place then
+      error (f_"-o and --in-place cannot be used at the same time");
   let output =
     match output_mode with
     | `Glance ->
@@ -385,6 +390,6 @@ read the man page virt-v2v(1).
         vmtype output_alloc in
 
   input, output,
-  debug_gc, debug_overlays, do_copy, network_map, no_trim,
+  debug_gc, 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 1228316..88bbbaa 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -860,10 +860,21 @@ let populate_overlays (g:G.guestfs) overlays =
         ~copyonread:true
   ) overlays
 
+let populate_disks (g:G.guestfs) src_disks =
+  List.iter (
+    fun ({s_qemu_uri = qemu_uri; s_format = format}) ->
+      match format with
+        | None ->
+            g#add_drive_opts qemu_uri ~cachemode:"unsafe" ~discard:"besteffort"
+        | Some fmt ->
+            g#add_drive_opts qemu_uri ~format:fmt ~cachemode:"unsafe"
+              ~discard:"besteffort"
+  ) src_disks
+
 let main () =
   (* Handle the command line. *)
   let input, output,
-    debug_gc, debug_overlays, do_copy, network_map, no_trim,
+    debug_gc, debug_overlays, do_copy, in_place, network_map, no_trim,
     output_alloc, output_format, output_name, print_source, root_choice =
     Cmdline.parse_cmdline () in
 
@@ -877,24 +888,35 @@ let main () =
 
   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
+  let overlays =
+    if not in_place then create_overlays source.s_disks
+    else [] in
+  let targets =
+    if not in_place then init_targets overlays source output output_format
+    else [] in
 
-  message (f_"Opening the overlay");
+  let guestfs_kind =
+    if not in_place then "overlay" else "source VM" in
+  message (f_"Opening the %s") guestfs_kind;
   let g = open_guestfs () in
-  populate_overlays g overlays;
+
+  if not in_place then populate_overlays g overlays
+  else populate_disks g source.s_disks;
 
   g#launch ();
 
   (* Inspection - this also mounts up the filesystems. *)
-  message (f_"Inspecting the overlay");
+  message (f_"Inspecting the %s") guestfs_kind;
   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;
+  if not in_place then
+    check_target_free_space mpstats source targets output;
 
-  let keep_serial_console = output#keep_serial_console in
+  let keep_serial_console =
+    if not in_place then output#keep_serial_console
+    else true in
   let guestcaps = do_convert g inspect source keep_serial_console in
 
   if no_trim <> ["*"] && (do_copy || debug_overlays) then (
@@ -906,9 +928,14 @@ let main () =
     do_fstrim g no_trim inspect;
   );
 
-  message (f_"Closing the overlay");
+  message (f_"Closing the %s") guestfs_kind;
   g#close ();
 
+  if in_place then (
+    message (f_"Finishing off");
+    exit 0
+  );
+
   let target_firmware = get_target_firmware inspect guestcaps source output in
   let target_buses = target_bus_assignment source targets guestcaps in
   let targets =
-- 
2.4.3




More information about the Libguestfs mailing list