This series is an attempt to add a mode of virt-v2v operation where it leaves the config and disk image conversion, rollback on errors, registering with the destination hypervisor, etc. to a third-party toolset, and performs only tuning of the guest OS to run in the KVM-based hypervisor. Roman Kagan (3): v2v: add --in-place mode v2v: document --in-place v2v: add test for --in-place --- changes from v3: - drop already merged or rejected patches - revert incorrect keep_serial_console treatment - stylistic fixes - doc and test patches remain untouched changes from v2: - top-down arrangement of function defitinions - branching of scenarios using a dedicated type changes from v1: - include refactoring patches before the --in-place ones - split --in-place patches into code, doc, and test for easier review (bisectability maintained) v2v/Makefile.am | 1 + v2v/cmdline.ml | 7 ++- v2v/test-v2v-in-place.sh | 119 +++++++++++++++++++++++++++++++++++++++++++++++ v2v/v2v.ml | 82 +++++++++++++++++++++++--------- v2v/virt-v2v.pod | 17 +++++++ 5 files changed, 202 insertions(+), 24 deletions(-) create mode 100755 v2v/test-v2v-in-place.sh -- 2.4.3
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@virtuozzo.com>
---
v2v/cmdline.ml | 7 ++++-
v2v/v2v.ml | 82 ++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 65 insertions(+), 24 deletions(-)
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index 3e04c48..d4bddce 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -36,6 +36,7 @@ let parse_cmdline () let dcpath = ref None in
let input_conn = ref None in
let input_format = ref None in
+ let in_place = ref false in
let output_conn = ref None in
let output_format = ref None in
let output_name = ref None in
@@ -159,6 +160,7 @@ let parse_cmdline ()
"uri " ^ s_"Libvirt URI";
"-if", Arg.String (set_string_option_once "-if"
input_format),
"format " ^ s_"Input
format (for -i disk)";
+ "--in-place", Arg.Set in_place, " " ^
s_"Only tune the guest in the input VM";
"--machine-readable", Arg.Set machine_readable, " " ^
s_"Make output machine readable";
"-n", Arg.String add_network, "in:out " ^
s_"Map network 'in' to 'out'";
"--network", Arg.String add_network, "in:out " ^
ditto;
@@ -224,6 +226,7 @@ read the man page virt-v2v(1).
let input_conn = !input_conn in
let input_format = !input_format 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
@@ -313,6 +316,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 ->
@@ -409,6 +414,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, network_map, no_trim,
+ 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 ff4060d..333ece0 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -41,12 +41,16 @@ let print_mpstat chan { mp_dev = dev; mp_path = path;
fprintf chan " bsize=%Ld blocks=%Ld bfree=%Ld bavail=%Ld\n"
s.G.bsize s.G.blocks s.G.bfree s.G.bavail
+type conversion_mode + | Copying of overlay list * target list
+ | In_place
+
let () = Random.self_init ()
let rec main () (* Handle the command line. *)
let input, output,
- debug_overlays, do_copy, network_map, no_trim,
+ debug_overlays, do_copy, in_place, network_map, no_trim,
output_alloc, output_format, output_name, print_source, root_choice
Cmdline.parse_cmdline () in
@@ -57,12 +61,25 @@ let rec 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
- message (f_"Opening the overlay");
+ 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
+ Copying (overlays, targets)
+ )
+ else In_place in
+
+ (match conversion_mode with
+ | Copying _ -> message (f_"Opening the overlay")
+ | In_place -> message (f_"Opening the source VM")
+ );
+
let g = open_guestfs () in
- populate_overlays g overlays;
+ (match conversion_mode with
+ | Copying (overlays, _) -> populate_overlays g overlays
+ | In_place -> populate_disks g source.s_disks
+ );
g#launch ();
@@ -72,7 +89,11 @@ let rec main ()
let mpstats = get_mpstats g in
check_free_space mpstats;
- check_target_free_space mpstats source targets output;
+ (match conversion_mode with
+ | Copying (_, targets) ->
+ check_target_free_space mpstats source targets output
+ | In_place -> ()
+ );
let keep_serial_console = output#keep_serial_console in
let guestcaps = do_convert g inspect source keep_serial_console in
@@ -88,31 +109,39 @@ let rec main () do_fstrim g no_trim inspect;
);
- message (f_"Closing the overlay");
+ (match conversion_mode with
+ | Copying _ -> message (f_"Closing the overlay")
+ | In_place -> message (f_"Closing the source VM")
+ );
g#umount_all ();
g#shutdown ();
g#close ();
- let target_firmware = get_target_firmware inspect guestcaps source output in
+ (match conversion_mode with
+ | In_place -> ()
+ | Copying (overlays, targets) ->
+ let target_firmware + get_target_firmware inspect guestcaps
source output in
- message (f_"Assigning disks to buses");
- let target_buses = target_bus_assignment source targets guestcaps in
- if verbose () then
- printf "%s%!" (string_of_target_buses target_buses);
+ message (f_"Assigning disks to buses");
+ let target_buses = target_bus_assignment source targets guestcaps in
+ if verbose () then
+ printf "%s%!" (string_of_target_buses target_buses);
- let targets - if not do_copy then targets
- else copy_targets targets input output output_alloc 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;
+ (* 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;
+ 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. *)
+ delete_target_on_exit := false (* Don't delete target on exit. *)
+ );
+ message (f_"Finishing off")
and open_source input print_source message (f_"Opening the source
%s") input#as_options;
@@ -264,7 +293,7 @@ and open_guestfs () g#set_network true;
g
-and populate_overlays (g:G.guestfs) overlays +and populate_overlays g overlays
(* Populate guestfs handle with qcow2 overlays. *)
List.iter (
fun ({ov_overlay_file = overlay_file}) ->
@@ -273,6 +302,13 @@ and populate_overlays (g:G.guestfs) overlays
~copyonread:true
) overlays
+and populate_disks g src_disks + List.iter (
+ fun ({s_qemu_uri = qemu_uri; s_format = format}) ->
+ g#add_drive_opts qemu_uri ?format ~cachemode:"unsafe"
+ ~discard:"besteffort"
+ ) src_disks
+
and inspect_source g root_choice let roots = g#inspect_os () in
let roots = Array.to_list roots in
--
2.4.3
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> --- v2v/virt-v2v.pod | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod index ae87986..c45688d 100644 --- a/v2v/virt-v2v.pod +++ b/v2v/virt-v2v.pod @@ -15,6 +15,8 @@ virt-v2v - Convert a guest to use KVM virt-v2v -i disk disk.img -o glance + virt-v2v -ic qemu:///system qemu_guest --in-place + =head1 DESCRIPTION Virt-v2v converts guests from a foreign hypervisor to run on KVM. It @@ -75,6 +77,9 @@ booting the guest directly in qemu (mainly for testing). I<-o rhev> is used to write to a RHEV-M / oVirt target. I<-o vdsm> is only used when virt-v2v runs under VDSM control. +I<--in-place> instructs virt-v2v to customize the guest OS in the input +virtual machine, instead of creating a new VM in the target hypervisor. + =head1 EXAMPLES =head2 Convert from VMware vCenter server to local libvirt @@ -333,6 +338,18 @@ For I<-i disk> only, this specifies the format of the input disk image. For other input methods you should specify the input format in the metadata. +=item B<--in-place> + +Do not create an output virtual machine in the target hypervisor. +Instead, adjust the guest OS in the source VM to run in the input +hypervisor. + +This mode is meant for integration with other toolsets, which take the +responsibility of converting the VM configuration, providing for +rollback in case of errors, transforming the storage, etc. + +Conflicts with all I<-o *> options. + =item B<--machine-readable> This option is used to make the output more machine friendly -- 2.4.3
Roman Kagan
2015-Oct-20 16:07 UTC
[Libguestfs] [PATCH v4 3/3] v2v: add test for --in-place
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
v2v/Makefile.am | 1 +
v2v/test-v2v-in-place.sh | 119 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+)
create mode 100755 v2v/test-v2v-in-place.sh
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index b5becba..0ed1ace 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -256,6 +256,7 @@ TESTS += \
test-v2v-cdrom.sh \
test-v2v-i-ova.sh \
test-v2v-i-disk.sh \
+ test-v2v-in-place.sh \
test-v2v-machine-readable.sh \
test-v2v-networks-and-bridges.sh \
test-v2v-no-copy.sh \
diff --git a/v2v/test-v2v-in-place.sh b/v2v/test-v2v-in-place.sh
new file mode 100755
index 0000000..f685ddb
--- /dev/null
+++ b/v2v/test-v2v-in-place.sh
@@ -0,0 +1,119 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014 Red Hat Inc.
+# Copyright (C) 2015 Parallels IP Holdings GmbH.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test --in-place.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_IN_PLACE_SH" ]; then
+ echo "$0: test skipped because environment variable is set"
+ exit 77
+fi
+
+if [ "$(guestfish get-backend)" = "uml" ]; then
+ echo "$0: test skipped because UML backend does not support
network"
+ exit 77
+fi
+
+abs_top_builddir="$(cd ..; pwd)"
+
+img_base="$abs_top_builddir/tests/guests/windows.img"
+if ! test -f $img_base || ! test -s $img_base; then
+ echo "$0: test skipped because phony Windows image was not
created"
+ exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$PWD/fake-virt-tools"
+export VIRTIO_WIN="$PWD/fake-virtio-win"
+
+d=$PWD/test-v2v-in-place.d
+rm -rf $d
+mkdir $d
+
+img="$d/test.qcow2"
+rm -f $img
+qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $img
+md5="$(md5sum $img_base)"
+
+libvirt_xml="$d/test.xml"
+rm -f $libvirt_xml
+n=windows-overlay
+cat > $libvirt_xml <<EOF
+<node>
+ <domain type='test'>
+ <name>$n</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2'/>
+ <source file='$img'/>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ </devices>
+ </domain>
+</node>
+EOF
+
+$VG virt-v2v --debug-gc -i libvirt -ic "test://$libvirt_xml" $n
--in-place
+
+# Test that the drivers have been copied over into the guest
+script="$d/test.fish"
+expected="$d/expected"
+response="$d/response"
+
+mktest ()
+{
+ local cmd="$1" exp="$2"
+
+ echo "echo '$cmd'" >> "$script"
+ echo "$cmd" >> "$expected"
+
+ echo "$cmd" >> "$script"
+ echo "$exp" >> "$expected"
+}
+
+:> "$script"
+:> "$expected"
+
+firstboot_dir="/Program Files/Red Hat/Firstboot"
+mktest "is-dir \"$firstboot_dir\"" true
+mktest "is-file \"$firstboot_dir/firstboot.bat\"" true
+mktest "is-dir \"$firstboot_dir/scripts\"" true
+virtio_dir="/Windows/Drivers/VirtIO"
+mktest "is-dir \"$virtio_dir\"" true
+for drv in netkvm qxl vioscsi viostor; do
+ for sfx in cat inf sys; do
+ mktest "is-file \"$virtio_dir/$drv.$sfx\"" true
+ done
+done
+
+guestfish --ro -a "$img" -i < "$script" >
"$response"
+diff -u "$expected" "$response"
+
+# Test the base image remained untouched
+test "$md5" = "$(md5sum $img_base)"
+
+# Clean up.
+rm -r $d
--
2.4.3
Richard W.M. Jones
2015-Oct-20 16:31 UTC
Re: [Libguestfs] [PATCH v4 0/3] v2v: add --in-place mode
I'd be tempted just to roll these into a single commit TBH, since they all relate to a single feature. All the patches look fine. I'm just running tests + the full external test suite on it now, and I'll either have some more detailed comments or I'll push it depending on the results. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Roman Kagan
2015-Oct-20 16:56 UTC
Re: [Libguestfs] [PATCH v4 0/3] v2v: add --in-place mode
On Tue, Oct 20, 2015 at 05:31:19PM +0100, Richard W.M. Jones wrote:> I'd be tempted just to roll these into a single commit TBH, since > they all relate to a single feature.I thought it was easier to review separately. Want me to resubmit the combined patch?> I'm just running tests + the full external test suite on it now, andI'm curious if this external test suite is opensource (or open data, as it's probably mostly data-driven)? Thanks, Roman.