Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 0/6] Bring support for virtio-scsi back to Windows
Discussion on v2: https://listman.redhat.com/archives/libguestfs/2023-March/030987.html v2 -> v3: * Patch 2/6 ("convert_windows: add Inject_virtio_win.Virtio_SCSI as a possible block type"): omit "Inject_virtio_win." prefix in favor of type inference. Add a short commit message body; * Add tests/test-v2v-block-driver.sh testing the new "--block-driver" option. Discussion on v1: https://listman.redhat.com/archives/libguestfs/2023-February/030849.html https://listman.redhat.com/archives/libguestfs/2023-March/030917.html v1 -> v2: * Adapt the patch suggested by Richard, splitting it up into 3: https://listman.redhat.com/archives/libguestfs/2023-March/030975.html Now we have "--block-driver" command line option which regulates the order in which block drivers are being searched for (and, as a consequence, the default driver). Andrey Drobyshev (3): Revert "Remove guestcaps_block_type Virtio_SCSI" convert_windows: add Inject_virtio_win.Virtio_SCSI as a possible block type tests: add --block-driver option test Richard W.M. Jones (3): convert: introduce "block_driver" convert option convert_windows: set block driver priority according to block_driver option v2v, in-place: introduce --block-driver command line option convert/convert.ml | 11 ++- convert/convert.mli | 1 + convert/convert_linux.ml | 11 ++- convert/convert_linux.mli | 3 +- convert/convert_windows.ml | 11 ++- convert/convert_windows.mli | 3 +- convert/target_bus_assignment.ml | 1 + docs/virt-v2v-in-place.pod | 10 ++ docs/virt-v2v.pod | 10 ++ in-place/in_place.ml | 12 ++- inspector/inspector.ml | 3 +- lib/create_ovf.ml | 1 + lib/types.ml | 3 +- lib/types.mli | 2 +- output/openstack_image_properties.ml | 7 ++ tests/Makefile.am | 2 + tests/test-v2v-block-driver.sh | 143 +++++++++++++++++++++++++++ v2v/v2v.ml | 12 ++- 18 files changed, 231 insertions(+), 15 deletions(-) create mode 100755 tests/test-v2v-block-driver.sh -- 2.31.1
Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 1/6] Revert "Remove guestcaps_block_type Virtio_SCSI"
This code is needed to check whether virtio-scsi driver was installed. This reverts commit f0afc439524853508938b2bfc758896f053462e3. --- convert/convert.ml | 2 +- convert/convert_linux.ml | 9 +++++++-- convert/target_bus_assignment.ml | 1 + lib/create_ovf.ml | 1 + lib/types.ml | 3 ++- lib/types.mli | 2 +- output/openstack_image_properties.ml | 7 +++++++ 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/convert/convert.ml b/convert/convert.ml index 0aa0e5cd..084619c8 100644 --- a/convert/convert.ml +++ b/convert/convert.ml @@ -252,7 +252,7 @@ and do_convert g source inspect i_firmware keep_serial_console interfaces (* Did we manage to install virtio drivers? *) if not (quiet ()) then ( match guestcaps.gcaps_block_bus with - | Virtio_blk -> + | Virtio_blk | Virtio_SCSI -> info (f_"This guest has virtio drivers installed.") | IDE -> info (f_"This guest does not have virtio drivers installed.") diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index d5c0f24d..dab4f36d 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -1068,8 +1068,12 @@ let convert (g : G.guestfs) source inspect i_firmware keep_serial_console _ (* Update 'alias scsi_hostadapter ...' *) let paths = augeas_modprobe ". =~ regexp('scsi_hostadapter.*')" in (match block_type with - | Virtio_blk -> - let block_module = "virtio_blk" in + | Virtio_blk | Virtio_SCSI -> + let block_module + match block_type with + | Virtio_blk -> "virtio_blk" + | Virtio_SCSI -> "virtio_scsi" + | IDE -> assert false in if paths <> [] then ( (* There's only 1 scsi controller in the converted guest. @@ -1142,6 +1146,7 @@ let convert (g : G.guestfs) source inspect i_firmware keep_serial_console _ let block_prefix_after_conversion match block_type with | Virtio_blk -> "vd" + | Virtio_SCSI -> "sd" | IDE -> ide_block_prefix in let map diff --git a/convert/target_bus_assignment.ml b/convert/target_bus_assignment.ml index 54c9516b..d13340c7 100644 --- a/convert/target_bus_assignment.ml +++ b/convert/target_bus_assignment.ml @@ -35,6 +35,7 @@ let rec target_bus_assignment source_disks source_removables guestcaps let bus match guestcaps.gcaps_block_bus with | Virtio_blk -> virtio_blk_bus + | Virtio_SCSI -> scsi_bus | IDE -> ide_bus in List.iteri ( fun i d -> diff --git a/lib/create_ovf.ml b/lib/create_ovf.ml index 5e444868..f0b32e01 100644 --- a/lib/create_ovf.ml +++ b/lib/create_ovf.ml @@ -920,6 +920,7 @@ and add_disks sizes guestcaps output_alloc output_format "ovf:disk-interface", (match guestcaps.gcaps_block_bus with | Virtio_blk -> "VirtIO" + | Virtio_SCSI -> "VirtIO_SCSI" | IDE -> "IDE"); "ovf:disk-type", "System"; (* RHBZ#744538 *) "ovf:boot", if is_bootable_drive then "True" else "False"; diff --git a/lib/types.ml b/lib/types.ml index e16da007..75c14fd4 100644 --- a/lib/types.ml +++ b/lib/types.ml @@ -400,12 +400,13 @@ type guestcaps = { gcaps_arch_min_version : int; gcaps_virtio_1_0 : bool; } -and guestcaps_block_type = Virtio_blk | IDE +and guestcaps_block_type = Virtio_blk | Virtio_SCSI | IDE and guestcaps_net_type = Virtio_net | E1000 | RTL8139 and guestcaps_machine = I440FX | Q35 | Virt let string_of_block_type = function | Virtio_blk -> "virtio-blk" + | Virtio_SCSI -> "virtio-scsi" | IDE -> "ide" let string_of_net_type = function | Virtio_net -> "virtio-net" diff --git a/lib/types.mli b/lib/types.mli index 4a183dd3..65ef2e35 100644 --- a/lib/types.mli +++ b/lib/types.mli @@ -280,7 +280,7 @@ type guestcaps = { } (** Guest capabilities after conversion. eg. Was virtio found or installed? *) -and guestcaps_block_type = Virtio_blk | IDE +and guestcaps_block_type = Virtio_blk | Virtio_SCSI | IDE and guestcaps_net_type = Virtio_net | E1000 | RTL8139 and guestcaps_machine = I440FX | Q35 | Virt diff --git a/output/openstack_image_properties.ml b/output/openstack_image_properties.ml index c75d72fe..c76ad913 100644 --- a/output/openstack_image_properties.ml +++ b/output/openstack_image_properties.ml @@ -35,6 +35,7 @@ let create source inspect { target_buses; guestcaps; target_firmware } "hw_disk_bus", (match guestcaps.gcaps_block_bus with | Virtio_blk -> "virtio" + | Virtio_SCSI -> "scsi" | IDE -> "ide"); "hw_vif_model", (match guestcaps.gcaps_net_bus with @@ -69,6 +70,12 @@ let create source inspect { target_buses; guestcaps; target_firmware } List.push_back properties ("hw_cpu_threads", string_of_int threads); ); + (match guestcaps.gcaps_block_bus with + | Virtio_SCSI -> + List.push_back properties ("hw_scsi_model", "virtio-scsi") + | Virtio_blk | IDE -> () + ); + (match inspect.i_major_version, inspect.i_minor_version with | 0, 0 -> () | x, 0 -> List.push_back properties ("os_version", string_of_int x) -- 2.31.1
Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 2/6] convert_windows: add Inject_virtio_win.Virtio_SCSI as a possible block type
It is needed to pass the proper guest capability in case we have virtio-scsi driver installed during conversion. Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com> --- convert/convert_windows.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 9d8d271d..bfe3ae13 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -273,6 +273,7 @@ let convert (g : G.guestfs) _ inspect i_firmware _ static_ips and of_virtio_win_block_type = function | Inject_virtio_win.Virtio_blk -> Virtio_blk + | Virtio_SCSI -> Virtio_SCSI | IDE -> IDE and of_virtio_win_net_type = function -- 2.31.1
Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 3/6] convert: introduce "block_driver" convert option
From: "Richard W.M. Jones" <rjones at redhat.com> When injecting a block VirtIO driver during conversion, we rely on the predefined list of names of such drivers. Order in this list denotes the priority (see common/mlcustomize/inject_virtio_win.ml). This commit introduces the "block_driver" convert option, setting its value to the default Virtio_blk and making sure it's being properly passed to the conversion functions. Along with the means of altering the drivers list (introduced in a separate commit in the common submodule), this option will be brought to command line, giving us the opportunity to choose the block driver to be used on conversion. Originally-by: Richard W.M. Jones <rjones at redhat.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com> --- convert/convert.ml | 9 ++++++--- convert/convert.mli | 1 + convert/convert_linux.ml | 2 +- convert/convert_linux.mli | 3 ++- convert/convert_windows.ml | 2 +- convert/convert_windows.mli | 3 ++- in-place/in_place.ml | 3 ++- inspector/inspector.ml | 3 ++- v2v/v2v.ml | 3 ++- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/convert/convert.ml b/convert/convert.ml index 084619c8..9c76f76d 100644 --- a/convert/convert.ml +++ b/convert/convert.ml @@ -31,6 +31,7 @@ open Utils module G = Guestfs type options = { + block_driver : guestcaps_block_type; keep_serial_console : bool; ks : key_store; network_map : Networks.t; @@ -88,7 +89,7 @@ let rec convert dir options source (* Conversion. *) let guestcaps do_convert g source inspect i_firmware - options.keep_serial_console options.static_ips in + options.block_driver options.keep_serial_console options.static_ips in g#umount_all (); @@ -221,7 +222,8 @@ and do_fstrim g inspect ) fses (* Conversion. *) -and do_convert g source inspect i_firmware keep_serial_console interfaces +and do_convert g source inspect i_firmware + block_driver keep_serial_console interfaces (match inspect.i_product_name with | "unknown" -> message (f_"Converting the guest to run on KVM") @@ -246,7 +248,8 @@ and do_convert g source inspect i_firmware keep_serial_console interfaces inspect.i_type inspect.i_distro in debug "picked conversion module %s" conversion_name; let guestcaps - convert g source inspect i_firmware keep_serial_console interfaces in + convert g source inspect i_firmware + block_driver keep_serial_console interfaces in debug "%s" (string_of_guestcaps guestcaps); (* Did we manage to install virtio drivers? *) diff --git a/convert/convert.mli b/convert/convert.mli index 3bd39e2d..c63bf6f0 100644 --- a/convert/convert.mli +++ b/convert/convert.mli @@ -17,6 +17,7 @@ *) type options = { + block_driver : Types.guestcaps_block_type; (** [--block-driver] option *) keep_serial_console : bool; ks : Tools_utils.key_store; (** [--key] option *) network_map : Networks.t; (** [-b] and [-n] options *) diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index dab4f36d..8d702084 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -34,7 +34,7 @@ open Linux_kernels module G = Guestfs (* The conversion function. *) -let convert (g : G.guestfs) source inspect i_firmware keep_serial_console _ +let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ (*----------------------------------------------------------------------*) (* Inspect the guest first. We already did some basic inspection in * the common v2v.ml code, but that has to deal with generic guests diff --git a/convert/convert_linux.mli b/convert/convert_linux.mli index 6eb272e9..dc6968fe 100644 --- a/convert/convert_linux.mli +++ b/convert/convert_linux.mli @@ -23,5 +23,6 @@ Mint and Kali are supported by this module. *) val convert : Guestfs.guestfs -> Types.source -> Types.inspect -> - Firmware.i_firmware -> bool -> Types.static_ip list -> + Firmware.i_firmware -> Types.guestcaps_block_type -> + bool -> Types.static_ip list -> Types.guestcaps diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index bfe3ae13..6c66869e 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -38,7 +38,7 @@ module G = Guestfs * time the Windows VM is booted on KVM. *) -let convert (g : G.guestfs) _ inspect i_firmware _ static_ips +let convert (g : G.guestfs) _ inspect i_firmware block_driver _ static_ips (*----------------------------------------------------------------------*) (* Inspect the Windows guest. *) diff --git a/convert/convert_windows.mli b/convert/convert_windows.mli index 42dac9f5..33a14f65 100644 --- a/convert/convert_windows.mli +++ b/convert/convert_windows.mli @@ -21,5 +21,6 @@ This module converts a Windows guest to run on KVM. *) val convert : Guestfs.guestfs -> Types.source -> Types.inspect -> - Firmware.i_firmware -> bool -> Types.static_ip list -> + Firmware.i_firmware -> Types.guestcaps_block_type -> + bool -> Types.static_ip list -> Types.guestcaps diff --git a/in-place/in_place.ml b/in-place/in_place.ml index 68ef9965..2049db16 100644 --- a/in-place/in_place.ml +++ b/in-place/in_place.ml @@ -294,7 +294,8 @@ read the man page virt-v2v-in-place(1). (* Get the conversion options. *) let conv_options = { - Convert.keep_serial_console = true; + Convert.block_driver = Virtio_blk; + keep_serial_console = true; ks = opthandle.ks; network_map; root_choice; diff --git a/inspector/inspector.ml b/inspector/inspector.ml index a6428946..02d1a0e7 100644 --- a/inspector/inspector.ml +++ b/inspector/inspector.ml @@ -324,7 +324,8 @@ read the man page virt-v2v-inspector(1). (* Get the conversion options. *) let conv_options = { - Convert.keep_serial_console = true; + Convert.block_driver = Virtio_blk; + keep_serial_console = true; ks = opthandle.ks; network_map; root_choice; diff --git a/v2v/v2v.ml b/v2v/v2v.ml index 13fe477a..22f7c631 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -524,7 +524,8 @@ read the man page virt-v2v(1). (* Get the conversion options. *) let conv_options = { - Convert.keep_serial_console = not remove_serial_console; + Convert.block_driver = Virtio_blk; + keep_serial_console = not remove_serial_console; ks = opthandle.ks; network_map; root_choice; -- 2.31.1
Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 4/6] convert_windows: set block driver priority according to block_driver option
From: "Richard W.M. Jones" <rjones at redhat.com> If "block_driver" option is set to Virtio_SCSI, prepend the block drivers priority list with "vioscsi" so that we first search for "vioscsi.sys" during the drivers injection phase. Originally-by: Richard W.M. Jones <rjones at redhat.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com> --- convert/convert_windows.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 6c66869e..b5dc06ed 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -47,6 +47,14 @@ let convert (g : G.guestfs) _ inspect i_firmware block_driver _ static_ips *) let virtio_win Inject_virtio_win.from_environment g inspect.i_root Config.datadir in + (match block_driver with + | Virtio_blk -> () (* the default, no need to do anything *) + | Virtio_SCSI -> + let drivers = Inject_virtio_win.get_block_driver_priority virtio_win in + let drivers = "vioscsi" :: drivers in + Inject_virtio_win.set_block_driver_priority virtio_win drivers + | IDE -> assert false (* not possible - but maybe ...? *) + ); (* If the Windows guest appears to be using group policy. * -- 2.31.1
Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 5/6] v2v, in-place: introduce --block-driver command line option
From: "Richard W.M. Jones" <rjones at redhat.com> The option takes values of "virtio-scsi", "virtio-blk" (with the latter being the default). It maps on the convert option with the same name introduced in the previous commits, thus allowing us to alter the order in which the VirtIO block drivers are going to be searched for. This is useful if we want the virtio-scsi driver to be installed during conversion instead of the default virtio-blk. Also update the docs accordingly. Originally-by: Richard W.M. Jones <rjones at redhat.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com> --- docs/virt-v2v-in-place.pod | 10 ++++++++++ docs/virt-v2v.pod | 10 ++++++++++ in-place/in_place.ml | 11 ++++++++++- v2v/v2v.ml | 11 ++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/virt-v2v-in-place.pod b/docs/virt-v2v-in-place.pod index 6e1c5363..1e993e8c 100644 --- a/docs/virt-v2v-in-place.pod +++ b/docs/virt-v2v-in-place.pod @@ -47,6 +47,16 @@ Display help. See I<--network> below. +=item B<--block-driver virtio-blk> + +=item B<--block-driver virtio-scsi> + +When choosing a block driver for Windows guests, prefer C<virtio-blk> or +C<virtio-scsi>. The default is C<virtio-blk>. + +Note this has no effect for Linux guests at the moment. That may be +added in future. + =item B<--colors> =item B<--colours> diff --git a/docs/virt-v2v.pod b/docs/virt-v2v.pod index b458607d..e096418b 100644 --- a/docs/virt-v2v.pod +++ b/docs/virt-v2v.pod @@ -207,6 +207,16 @@ The options are silently ignored for other input methods. See I<--network> below. +=item B<--block-driver virtio-blk> + +=item B<--block-driver virtio-scsi> + +When choosing a block driver for Windows guests, prefer C<virtio-blk> or +C<virtio-scsi>. The default is C<virtio-blk>. + +Note this has no effect for Linux guests at the moment. That may be +added in future. + =item B<--colors> =item B<--colours> diff --git a/in-place/in_place.ml b/in-place/in_place.ml index 2049db16..e8c260c2 100644 --- a/in-place/in_place.ml +++ b/in-place/in_place.ml @@ -43,6 +43,7 @@ let rec main () let bandwidth = ref None in let bandwidth_file = ref None in + let block_driver = ref None in let input_conn = ref None in let input_format = ref None in let input_password = ref None in @@ -156,6 +157,8 @@ let rec main () let argspec = [ [ S 'b'; L"bridge" ], Getopt.String ("in:out", add_bridge), s_"Map bridge ?in? to ?out?"; + [ L"block-driver" ], Getopt.String ("driver", set_string_option_once "--block-driver" block_driver), + s_"Prefer 'virtio-blk' or 'virtio-scsi'"; [ S 'i' ], Getopt.String ("disk|libvirt|libvirtxml|ova|vmx", set_input_mode), s_"Set input mode (default: libvirt)"; [ M"ic" ], Getopt.String ("uri", set_string_option_once "-ic" input_conn), @@ -211,6 +214,12 @@ read the man page virt-v2v-in-place(1). (* Dereference the arguments. *) let args = List.rev !args in + let block_driver + match !block_driver with + | None | Some "virtio-blk" -> Virtio_blk + | Some "virtio-scsi" -> Virtio_SCSI + | Some driver -> + error (f_"unknown block driver ?--block-driver %s?") driver in let input_conn = !input_conn in let input_mode = !input_mode in let print_source = !print_source in @@ -294,7 +303,7 @@ read the man page virt-v2v-in-place(1). (* Get the conversion options. *) let conv_options = { - Convert.block_driver = Virtio_blk; + Convert.block_driver = block_driver; keep_serial_console = true; ks = opthandle.ks; network_map; diff --git a/v2v/v2v.ml b/v2v/v2v.ml index 22f7c631..3b2eafbd 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -48,6 +48,7 @@ let rec main () let bandwidth = ref None in let bandwidth_file = ref None in + let block_driver = ref None in let input_conn = ref None in let input_format = ref None in let input_password = ref None in @@ -230,6 +231,8 @@ let rec main () s_"Set bandwidth dynamically from file"; [ S 'b'; L"bridge" ], Getopt.String ("in:out", add_bridge), s_"Map bridge ?in? to ?out?"; + [ L"block-driver" ], Getopt.String ("driver", set_string_option_once "--block-driver" block_driver), + s_"Prefer 'virtio-blk' or 'virtio-scsi'"; [ L"compressed" ], Getopt.Unit (fun () -> set_output_option_compat "compressed" ""), s_"Compress output file (-of qcow2 only)"; [ S 'i' ], Getopt.String ("disk|libvirt|libvirtxml|ova|vmx", set_input_mode), @@ -351,6 +354,12 @@ read the man page virt-v2v(1). (* Dereference the arguments. *) let args = List.rev !args in + let block_driver + match !block_driver with + | None | Some "virtio-blk" -> Virtio_blk + | Some "virtio-scsi" -> Virtio_SCSI + | Some driver -> + error (f_"unknown block driver ?--block-driver %s?") driver in let input_conn = !input_conn in let input_mode = !input_mode in let input_transport @@ -524,7 +533,7 @@ read the man page virt-v2v(1). (* Get the conversion options. *) let conv_options = { - Convert.block_driver = Virtio_blk; + Convert.block_driver = block_driver; keep_serial_console = not remove_serial_console; ks = opthandle.ks; network_map; -- 2.31.1
Andrey Drobyshev
2023-Mar-10 17:54 UTC
[Libguestfs] [V2V PATCH v3 6/6] tests: add --block-driver option test
The test checks that the newly introduced --block-driver option doesn't break conversion. Basically its logic somewhat repeats test-v2v-i-disk.sh and test-v2v-in-place.sh, but with the new option being set. The checks it performs are: 1. Run disk-sourced conversion (-i disk) based on the phony windows.img and check that it completes (i.e. produces converted disk and corresponding domain XML; 2. Run libvirt-sourced in-place conversion based on an XML with virtio vda disk specified (virtio-blk case) and check that the resulting image has the phony viostor driver installed. 3. Run libvirt-sourced in-place conversion based on an XML with scsi sda disk specified (virtio-scsi case) and check that the resulting image has the phony vioscsi driver installed. Note that the latter 2 cases aren't really comprehensive as v2v actually copies all the drivers present in $VIRTIO_WIN, regardless of the block driver specified. The real difference comes from the PCI ID values written into the registry. But since we can't test real Windows and evaluate those values, we're doing the best we can here, i.e. testing that conversion doesn't break and drivers are still present with --block-driver option being set explicitly. Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com> --- tests/Makefile.am | 2 + tests/test-v2v-block-driver.sh | 143 +++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100755 tests/test-v2v-block-driver.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index a4c87398..5c523204 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -78,6 +78,7 @@ TESTS = \ test-v2v-i-disk.sh \ test-v2v-i-ova.sh \ test-v2v-in-place.sh \ + test-v2v-block-driver.sh \ test-v2v-inspector.sh \ test-v2v-mac.sh \ test-v2v-machine-readable.sh \ @@ -236,6 +237,7 @@ EXTRA_DIST += \ test-v2v-i-vmx-6.vmx \ test-v2v-i-vmx-7.vmx \ test-v2v-in-place.sh \ + test-v2v-block-driver.sh \ test-v2v-inspector.sh \ test-v2v-it-vddk-io-query.sh \ test-v2v-machine-readable.sh \ diff --git a/tests/test-v2v-block-driver.sh b/tests/test-v2v-block-driver.sh new file mode 100755 index 00000000..db59a2cf --- /dev/null +++ b/tests/test-v2v-block-driver.sh @@ -0,0 +1,143 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2023 Virtuozzo International 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 --block-driver option. + +set -e + +source ./functions.sh +set -e +set -x + +skip_if_skipped +img_base="$abs_top_builddir/test-data/phony-guests/windows.img" +requires test -f $img_base + +export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" +export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" + +d=$PWD/test-v2v-block-driver.d +rm -rf $d +cleanup_fn rm -rf $d +mkdir $d + +viostor_img="$d/viostor.qcow2" +vioscsi_img="$d/vioscsi.qcow2" +qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $viostor_img +qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $vioscsi_img +base_md5="$(do_md5 $img_base)" + +viostor_xml="$d/windows-viostor.xml" +viostor_name=windows-viostor +cat > $viostor_xml <<EOF +<node> + <domain type='test'> + <name>$viostor_name</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='$viostor_img'/> + <target dev='vda' bus='virtio'/> + </disk> + </devices> + </domain> +</node> +EOF + +vioscsi_xml="$d/windows-vioscsi.xml" +vioscsi_name=windows-vioscsi +cat > $vioscsi_xml <<EOF +<node> + <domain type='test'> + <name>$vioscsi_name</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='$vioscsi_img'/> + <target dev='sda' bus='scsi'/> + </disk> + <controller type='scsi' index='0' model='virtio-scsi'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </controller> + </devices> + </domain> +</node> +EOF + +response="$d/response" +expected="$d/expected" + +echo -e "true\ntrue\ntrue\ntrue" >$expected + +check_driver_presence () +{ + local img="$1" drv="$2" + + local virtio_dir="/Windows/Drivers/VirtIO" + + guestfish --ro -a "$img" -i >$response <<-EOM + is-dir $virtio_dir + is-file $virtio_dir/$drv.cat + is-file $virtio_dir/$drv.inf + is-file $virtio_dir/$drv.sys +EOM + + diff -u $expected $response +} + +# Test that --block-driver option doesn't break basic "-i disk" conversion +$VG virt-v2v --debug-gc --block-driver virtio-scsi \ + -i disk $img_base -o local -os $d + +# Check that libvirt XML metadata and a disk was created. +test -f $d/windows.xml +test -f $d/windows-sda + +# Test in-place conversion with --block-driver specified +# +# Note that v2v actually copies all the drivers present in $VIRTIO_WIN, no +# matter which block driver we specify. The real difference comes from the +# PCI ID values written into the registry. Since we can't really test those +# values, we're doing the best we can here, i.e. testing that conversion +# doesn't break and drivers are still present with --block-driver option +# being set explicitly. + +# Check that in-place conversion works with --block-driver virtio-blk +$VG virt-v2v-in-place --debug-gc --block-driver virtio-blk \ + -i libvirt -ic "test://$viostor_xml" $viostor_name + +check_driver_presence $viostor_img "viostor" + +# Check that in-place conversion works with --block-driver virtio-scsi +$VG virt-v2v-in-place --debug-gc --block-driver virtio-scsi \ + -i libvirt -ic "test://$vioscsi_xml" $vioscsi_name + +check_driver_presence $vioscsi_img "vioscsi" + +# Finally check that the base image remained untouched +test "$base_md5" = "$(do_md5 $img_base)" -- 2.31.1
Laszlo Ersek
2023-Mar-14 13:00 UTC
[Libguestfs] [V2V PATCH v3 0/6] Bring support for virtio-scsi back to Windows
On 3/10/23 18:54, Andrey Drobyshev wrote:> Discussion on v2: > https://listman.redhat.com/archives/libguestfs/2023-March/030987.html > > v2 -> v3: > > * Patch 2/6 ("convert_windows: add Inject_virtio_win.Virtio_SCSI as a > possible block type"): omit "Inject_virtio_win." prefix in favor of type > inference. Add a short commit message body; > > * Add tests/test-v2v-block-driver.sh testing the new "--block-driver" > option. > > Discussion on v1: > https://listman.redhat.com/archives/libguestfs/2023-February/030849.html > https://listman.redhat.com/archives/libguestfs/2023-March/030917.html > > v1 -> v2: > > * Adapt the patch suggested by Richard, splitting it up into 3: > https://listman.redhat.com/archives/libguestfs/2023-March/030975.html > > Now we have "--block-driver" command line option which regulates the > order in which block drivers are being searched for (and, as a > consequence, the default driver). > > Andrey Drobyshev (3): > Revert "Remove guestcaps_block_type Virtio_SCSI" > convert_windows: add Inject_virtio_win.Virtio_SCSI as a possible block > type > tests: add --block-driver option test > > Richard W.M. Jones (3): > convert: introduce "block_driver" convert option > convert_windows: set block driver priority according to block_driver > option > v2v, in-place: introduce --block-driver command line option > > convert/convert.ml | 11 ++- > convert/convert.mli | 1 + > convert/convert_linux.ml | 11 ++- > convert/convert_linux.mli | 3 +- > convert/convert_windows.ml | 11 ++- > convert/convert_windows.mli | 3 +- > convert/target_bus_assignment.ml | 1 + > docs/virt-v2v-in-place.pod | 10 ++ > docs/virt-v2v.pod | 10 ++ > in-place/in_place.ml | 12 ++- > inspector/inspector.ml | 3 +- > lib/create_ovf.ml | 1 + > lib/types.ml | 3 +- > lib/types.mli | 2 +- > output/openstack_image_properties.ml | 7 ++ > tests/Makefile.am | 2 + > tests/test-v2v-block-driver.sh | 143 +++++++++++++++++++++++++++ > v2v/v2v.ml | 12 ++- > 18 files changed, 231 insertions(+), 15 deletions(-) > create mode 100755 tests/test-v2v-block-driver.sh >Merged as commit range cb792fef27ff..94b249b6e58b (including the required submodule update, prepended). Laszlo
Apparently Analagous Threads
- [V2V PATCH v2 0/5] Bring support for virtio-scsi back to Windows
- [V2V PATCH v2 3/5] convert: introduce "block_driver" convert option
- [V2V PATCH v3 3/6] convert: introduce "block_driver" convert option
- [PATCH v2v] convert: Allow preferred block driver to be specified on the command line
- [V2V PATCH 0/5] Bring support for virtio-scsi back to Windows