[COMMON PATCH v2 0/4] Bring support for virtio-scsi back to Windows
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: * Drop the logic where default is switched to "vioscsi". Keep virtio-blk as default. * Adapt the patch suggested by Richard: https://listman.redhat.com/archives/libguestfs/2023-March/030974.html This introduces API for changing the order in which drivers are being searched for. This API is used by v2v. Andrey Drobyshev (2): inject_virtio_win: add Virtio_SCSI to block_type inject_virtio_win: write the proper block controller PCI ID to Win registry Richard W.M. Jones (1): mlcustomize: Add accessors for block driver priority list Roman Kagan (1): inject_virtio_win: match only vendor/device mlcustomize/inject_virtio_win.ml | 34 +++++++++++++++++++++---------- mlcustomize/inject_virtio_win.mli | 12 ++++++++++- 2 files changed, 34 insertions(+), 12 deletions(-) -- 2.31.1
From: Roman Kagan <rkagan@virtuozzo.com> Since different hypervisor vendors are allowed to use their own vendor-id as PCI subsystem-vendor-id for virtio devices, during v2v conversion it makes sense to only match the vendor/device and not the full device "path" in the Windows registry. This way the code will remain universal but will work for different hypervisor vendors. Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> Originally-by: Roman Kagan <rkagan@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 4e977b3..8d72c5d 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -110,10 +110,10 @@ and get_inspection g root = virtio_win = ""; was_set = false } let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" -let viostor_legacy_pciid = "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" -let viostor_modern_pciid = "VEN_1AF4&DEV_1042&SUBSYS_11001AF4&REV_01" -let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004&SUBSYS_00081AF4&REV_00" -let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048&SUBSYS_11001AF4&REV_01" +let viostor_legacy_pciid = "VEN_1AF4&DEV_1001" +let viostor_modern_pciid = "VEN_1AF4&DEV_1042" +let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004" +let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048" let rec inject_virtio_win_drivers ({ g } as t) reg = (* Copy the virtio drivers to the guest. *) -- 2.31.1
On 3/7/23 20:40, Andrey Drobyshev wrote:
From: Roman Kagan <rkagan@virtuozzo.com>
Since different hypervisor vendors are allowed to use their own vendor-id as PCI subsystem-vendor-id for virtio devices, during v2v conversion it makes sense to only match the vendor/device and not the full device "path" in the Windows registry. This way the code will remain universal but will work for different hypervisor vendors.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> Originally-by: Roman Kagan <rkagan@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 4e977b3..8d72c5d 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -110,10 +110,10 @@ and get_inspection g root = virtio_win = ""; was_set = false }
let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" -let viostor_legacy_pciid = "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" -let viostor_modern_pciid = "VEN_1AF4&DEV_1042&SUBSYS_11001AF4&REV_01" -let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004&SUBSYS_00081AF4&REV_00" -let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048&SUBSYS_11001AF4&REV_01" +let viostor_legacy_pciid = "VEN_1AF4&DEV_1001" +let viostor_modern_pciid = "VEN_1AF4&DEV_1042" +let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004" +let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048"
let rec inject_virtio_win_drivers ({ g } as t) reg = (* Copy the virtio drivers to the guest. *)
I wonder whether dropping the revision ID as well is a good idea. In the virtio-1.0 spec, we have under 4.1.2.1 Device Requirements: PCI Device Discovery: The PCI Subsystem Vendor ID and the PCI Subsystem Device ID MAY reflect the PCI Vendor and Device ID of the environment (for informational purposes by the driver). Non-transitional devices SHOULD have a PCI Device ID in the range 0x1040 to 0x107f. Non-transitional devices SHOULD have a PCI Revision ID of 1 or higher. Non-transitional devices SHOULD have a PCI Subsystem Device ID of 0x40 or higher. And in virtio-0.9.5, we have under 2.1 PCI Discovery: [...] The device must also have a Revision ID of 0 to match this specication. [...] So I think relaxing the PCI Revision ID is not necessary. But, it shouldn't cause problems in practice either, I think. It won't allow for cross-binding (the PCI Device IDs remain distinct). Acked-by: Laszlo Ersek <lersek@redhat.com>
On 3/8/23 12:47, Laszlo Ersek wrote:
On 3/7/23 20:40, Andrey Drobyshev wrote:
From: Roman Kagan <rkagan@virtuozzo.com>
Since different hypervisor vendors are allowed to use their own vendor-id as PCI subsystem-vendor-id for virtio devices, during v2v conversion it makes sense to only match the vendor/device and not the full device "path" in the Windows registry. This way the code will remain universal but will work for different hypervisor vendors.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> Originally-by: Roman Kagan <rkagan@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 4e977b3..8d72c5d 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -110,10 +110,10 @@ and get_inspection g root = virtio_win = ""; was_set = false }
let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" -let viostor_legacy_pciid = "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" -let viostor_modern_pciid = "VEN_1AF4&DEV_1042&SUBSYS_11001AF4&REV_01" -let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004&SUBSYS_00081AF4&REV_00" -let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048&SUBSYS_11001AF4&REV_01" +let viostor_legacy_pciid = "VEN_1AF4&DEV_1001" +let viostor_modern_pciid = "VEN_1AF4&DEV_1042" +let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004" +let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048"
let rec inject_virtio_win_drivers ({ g } as t) reg = (* Copy the virtio drivers to the guest. *)
I wonder whether dropping the revision ID as well is a good idea. In the virtio-1.0 spec, we have under 4.1.2.1 Device Requirements: PCI Device Discovery:
The PCI Subsystem Vendor ID and the PCI Subsystem Device ID MAY reflect the PCI Vendor and Device ID of the environment (for informational purposes by the driver).
Non-transitional devices SHOULD have a PCI Device ID in the range 0x1040 to 0x107f. Non-transitional devices SHOULD have a PCI Revision ID of 1 or higher. Non-transitional devices SHOULD have a PCI Subsystem Device ID of 0x40 or higher.
And in virtio-0.9.5, we have under 2.1 PCI Discovery:
[...] The device must also have a Revision ID of 0 to match this specication. [...]
So I think relaxing the PCI Revision ID is not necessary. But, it shouldn't cause problems in practice either, I think. It won't allow for cross-binding (the PCI Device IDs remain distinct).
Acked-by: Laszlo Ersek <lersek@redhat.com>
I agree that omitting both Subsystem Vendor ID and Revision ID isn't an obvious solution. Since each subsystem is allowed to have its own Vendor ID, an alternative would be to determine on the fly which hypervisor we're dealing with, and choose one of the predefined Vendor IDs accordingly. I figured that skipping them entirely shouldn't do any harm, and thus this solution is more practical. As for the Revision IDs, relaxing them indeed doesn't seem to be necessary. I have now tried leaving them there as is, and VM is still able to boot off that controller as expected. Like so:
@@ -110,10 +110,10 @@ and get_inspection g root = virtio_win = ""; was_set = false }
let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" -let viostor_legacy_pciid = "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" -let viostor_modern_pciid = "VEN_1AF4&DEV_1042&SUBSYS_11001AF4&REV_01" -let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004&SUBSYS_00081AF4&REV_00" -let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048&SUBSYS_11001AF4&REV_01" +let viostor_legacy_pciid = "VEN_1AF4&DEV_1001&REV_00" +let viostor_modern_pciid = "VEN_1AF4&DEV_1042&REV_01" +let vioscsi_legacy_pciid = "VEN_1AF4&DEV_1004&REV_00" +let vioscsi_modern_pciid = "VEN_1AF4&DEV_1048&REV_01"
let rec inject_virtio_win_drivers ({ g } as t) reg = (* Copy the virtio drivers to the guest. *)
So we may as well not omit them, if you prefer.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 2 +- mlcustomize/inject_virtio_win.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 8d72c5d..cf078c0 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -51,7 +51,7 @@ type t = { the user to select where they want to get drivers from. XXX *) } -type block_type = Virtio_blk | IDE +type block_type = Virtio_blk | Virtio_SCSI | IDE and net_type = Virtio_net | E1000 | RTL8139 and machine_type = I440FX | Q35 | Virt diff --git a/mlcustomize/inject_virtio_win.mli b/mlcustomize/inject_virtio_win.mli index 0ced02e..58169e1 100644 --- a/mlcustomize/inject_virtio_win.mli +++ b/mlcustomize/inject_virtio_win.mli @@ -20,7 +20,7 @@ type t (** Handle *) -type block_type = Virtio_blk | IDE +type block_type = Virtio_blk | Virtio_SCSI | IDE and net_type = Virtio_net | E1000 | RTL8139 and machine_type = I440FX | Q35 | Virt -- 2.31.1
On 3/7/23 20:40, Andrey Drobyshev wrote:
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 2 +- mlcustomize/inject_virtio_win.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 8d72c5d..cf078c0 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -51,7 +51,7 @@ type t = { the user to select where they want to get drivers from. XXX *) }
-type block_type = Virtio_blk | IDE +type block_type = Virtio_blk | Virtio_SCSI | IDE and net_type = Virtio_net | E1000 | RTL8139 and machine_type = I440FX | Q35 | Virt
diff --git a/mlcustomize/inject_virtio_win.mli b/mlcustomize/inject_virtio_win.mli index 0ced02e..58169e1 100644 --- a/mlcustomize/inject_virtio_win.mli +++ b/mlcustomize/inject_virtio_win.mli @@ -20,7 +20,7 @@
type t (** Handle *)
-type block_type = Virtio_blk | IDE +type block_type = Virtio_blk | Virtio_SCSI | IDE and net_type = Virtio_net | E1000 | RTL8139 and machine_type = I440FX | Q35 | Virt
I seriously dislike empty commit message bodies. Please include at least a single-sentence hint there *why* this change is good. With that: Acked-by: Laszlo Ersek <lersek@redhat.com>
On 3/8/23 12:48, Laszlo Ersek wrote:
On 3/7/23 20:40, Andrey Drobyshev wrote:
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 2 +- mlcustomize/inject_virtio_win.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 8d72c5d..cf078c0 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -51,7 +51,7 @@ type t = { the user to select where they want to get drivers from. XXX *) }
-type block_type = Virtio_blk | IDE +type block_type = Virtio_blk | Virtio_SCSI | IDE and net_type = Virtio_net | E1000 | RTL8139 and machine_type = I440FX | Q35 | Virt
diff --git a/mlcustomize/inject_virtio_win.mli b/mlcustomize/inject_virtio_win.mli index 0ced02e..58169e1 100644 --- a/mlcustomize/inject_virtio_win.mli +++ b/mlcustomize/inject_virtio_win.mli @@ -20,7 +20,7 @@
type t (** Handle *)
-type block_type = Virtio_blk | IDE +type block_type = Virtio_blk | Virtio_SCSI | IDE and net_type = Virtio_net | E1000 | RTL8139 and machine_type = I440FX | Q35 | Virt
I seriously dislike empty commit message bodies. Please include at least a single-sentence hint there *why* this change is good.
With that:
Acked-by: Laszlo Ersek <lersek@redhat.com>
Sure, thanks for pointing out. Will do as soon as Richard leaves his notes on the series.
On Wed, Mar 08, 2023 at 04:00:10PM +0200, Andrey Drobyshev wrote:
Sure, thanks for pointing out. Will do as soon as Richard leaves his notes on the series.
I'm giving a talk this afternoon, but I should be able to look at it later. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
From: "Richard W.M. Jones" <rjones@redhat.com> When injecting virtio-win drivers, allow the list of block drivers that we search to be modified. This functionality will be used when we introduce an option for changing the default block driver in virt-v2v. Originally-by: Richard W.M. Jones <rjones@redhat.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- mlcustomize/inject_virtio_win.mli | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index cf078c0..345fe32 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -49,6 +49,9 @@ type t = { of libosinfo. Although this behaviour is documented, IMHO it has always been a bad idea. We should change this in future to allow the user to select where they want to get drivers from. XXX *) + + mutable block_driver_priority : string list + (** List of block drivers *) } type block_type = Virtio_blk | Virtio_SCSI | IDE @@ -107,7 +110,11 @@ and get_inspection g root = { g; root; i_arch; i_major_version; i_minor_version; i_osinfo; i_product_variant; i_windows_current_control_set; i_windows_systemroot; - virtio_win = ""; was_set = false } + virtio_win = ""; was_set = false; + block_driver_priority = ["virtio_blk"; "vrtioblk"; "viostor"] } + +let get_block_driver_priority t = t.block_driver_priority +let set_block_driver_priority t v = t.block_driver_priority <- v let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" let viostor_legacy_pciid = "VEN_1AF4&DEV_1001" @@ -176,14 +183,13 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = else ( (* Can we install the block driver? *) let block : block_type = - let filenames = ["virtio_blk"; "vrtioblk"; "viostor"] in let viostor_driver = try ( Some ( List.find ( fun driver_file -> let source = driverdir // driver_file ^ ".sys" in g#exists source - ) filenames + ) t.block_driver_priority ) ) with Not_found -> None in match viostor_driver with diff --git a/mlcustomize/inject_virtio_win.mli b/mlcustomize/inject_virtio_win.mli index 58169e1..d14f049 100644 --- a/mlcustomize/inject_virtio_win.mli +++ b/mlcustomize/inject_virtio_win.mli @@ -64,6 +64,16 @@ val from_environment : Guestfs.guestfs -> string -> string -> t This should only be used by [virt-v2v] and is considered a legacy method. *) +val get_block_driver_priority : t -> string list +val set_block_driver_priority : t -> string list -> unit +(** Get or set the current block driver priority list. This is + a list of virtio-win block driver names (eg. ["viostor"]) that + we search until we come to the first [name ^ ".sys"] that + we find, and that is the block driver which gets installed. + + This module contains a default priority list which should + be suitable for most use cases. *) + val inject_virtio_win_drivers : t -> Registry.t -> virtio_win_installed (** [inject_virtio_win_drivers t reg] installs virtio drivers from the driver directory or driver -- 2.31.1
On 3/7/23 20:40, Andrey Drobyshev wrote:
From: "Richard W.M. Jones" <rjones@redhat.com>
When injecting virtio-win drivers, allow the list of block drivers that we search to be modified. This functionality will be used when we introduce an option for changing the default block driver in virt-v2v.
Originally-by: Richard W.M. Jones <rjones@redhat.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- mlcustomize/inject_virtio_win.mli | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index cf078c0..345fe32 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -49,6 +49,9 @@ type t = { of libosinfo. Although this behaviour is documented, IMHO it has always been a bad idea. We should change this in future to allow the user to select where they want to get drivers from. XXX *) + + mutable block_driver_priority : string list + (** List of block drivers *) }
type block_type = Virtio_blk | Virtio_SCSI | IDE @@ -107,7 +110,11 @@ and get_inspection g root = { g; root; i_arch; i_major_version; i_minor_version; i_osinfo; i_product_variant; i_windows_current_control_set; i_windows_systemroot; - virtio_win = ""; was_set = false } + virtio_win = ""; was_set = false; + block_driver_priority = ["virtio_blk"; "vrtioblk"; "viostor"] } + +let get_block_driver_priority t = t.block_driver_priority +let set_block_driver_priority t v = t.block_driver_priority <- v
let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" let viostor_legacy_pciid = "VEN_1AF4&DEV_1001" @@ -176,14 +183,13 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = else ( (* Can we install the block driver? *) let block : block_type = - let filenames = ["virtio_blk"; "vrtioblk"; "viostor"] in let viostor_driver = try ( Some ( List.find ( fun driver_file -> let source = driverdir // driver_file ^ ".sys" in g#exists source - ) filenames + ) t.block_driver_priority ) ) with Not_found -> None in match viostor_driver with diff --git a/mlcustomize/inject_virtio_win.mli b/mlcustomize/inject_virtio_win.mli index 58169e1..d14f049 100644 --- a/mlcustomize/inject_virtio_win.mli +++ b/mlcustomize/inject_virtio_win.mli @@ -64,6 +64,16 @@ val from_environment : Guestfs.guestfs -> string -> string -> t
This should only be used by [virt-v2v] and is considered a legacy method. *)
+val get_block_driver_priority : t -> string list +val set_block_driver_priority : t -> string list -> unit +(** Get or set the current block driver priority list. This is + a list of virtio-win block driver names (eg. ["viostor"]) that + we search until we come to the first [name ^ ".sys"] that + we find, and that is the block driver which gets installed. + + This module contains a default priority list which should + be suitable for most use cases. *) + val inject_virtio_win_drivers : t -> Registry.t -> virtio_win_installed (** [inject_virtio_win_drivers t reg] installs virtio drivers from the driver directory or driver
Changes in this patch on top of Rich's: - the commit message has been extended with the sentence "This functionality will be used when we introduce an option for changing the default block driver in virt-v2v." - context difference in "type block_type" (Virtio_SCSI) - context difference in "viostor_legacy_pciid" (VEN_1AF4&DEV_1001) So I'm repeating my R-b from under Rich's patch. Reviewed-by: Laszlo Ersek <lersek@redhat.com>
In case when we are injecting virtio-scsi device driver into the guest (rather than the default virtio-blk), make sure we write the right PCI ID value into the Windows guest registry. This is essential for the guest to be bootable afterwards. Originally-by: Roman Kagan <rkagan@virtuozzo.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 345fe32..922c1ab 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -207,10 +207,16 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in + let installed_block_type, legacy_pciid, modern_pciid = ( + if driver_name = "vioscsi" then + Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid + else + Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid + ) in g#cp source target; - add_guestor_to_registry t reg driver_name viostor_legacy_pciid; - add_guestor_to_registry t reg driver_name viostor_modern_pciid; - Virtio_blk in + add_guestor_to_registry t reg driver_name legacy_pciid; + add_guestor_to_registry t reg driver_name modern_pciid; + installed_block_type in (* Can we install the virtio-net driver? *) let net : net_type = -- 2.31.1
On Tue, Mar 07, 2023 at 09:40:26PM +0200, Andrey Drobyshev wrote:
In case when we are injecting virtio-scsi device driver into the guest (rather than the default virtio-blk), make sure we write the right PCI ID value into the Windows guest registry. This is essential for the guest to be bootable afterwards.
Originally-by: Roman Kagan <rkagan@virtuozzo.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 345fe32..922c1ab 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -207,10 +207,16 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in + let installed_block_type, legacy_pciid, modern_pciid = ( + if driver_name = "vioscsi" then + Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid + else + Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid + ) in g#cp source target; - add_guestor_to_registry t reg driver_name viostor_legacy_pciid; - add_guestor_to_registry t reg driver_name viostor_modern_pciid; - Virtio_blk in + add_guestor_to_registry t reg driver_name legacy_pciid; + add_guestor_to_registry t reg driver_name modern_pciid; + installed_block_type in
(* Can we install the virtio-net driver? *) let net : net_type =
Could we make this look more like the code before it was reverted here? https://github.com/libguestfs/virt-v2v/commit/b28cd1dcfeb40e7002e8d0b0ce9dcc... See the lines starting: | Some Virtio_SCSI, _, true -> (* Block driver needs tweaks to allow booting; the rest is set up by PnP ... So the change would look like: - | Some driver_name -> + | Some "viostor" -> (* Block driver needs tweaks to allow booting; * the rest is set up by PnP manager. *) let source = driverdir // (driver_name ^ ".sys") in let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in g#cp source target; add_guestor_to_registry t reg driver_name viostor_legacy_pciid; add_guestor_to_registry t reg driver_name viostor_modern_pciid; Virtio_blk in + | Some "vioscsi" -> + [... new code for the virtio-scsi case ...] The old code was a bit clearer don't you think? Even if there's a little bit more duplication. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
On 3/8/23 22:45, Richard W.M. Jones wrote:
On Tue, Mar 07, 2023 at 09:40:26PM +0200, Andrey Drobyshev wrote:
In case when we are injecting virtio-scsi device driver into the guest (rather than the default virtio-blk), make sure we write the right PCI ID value into the Windows guest registry. This is essential for the guest to be bootable afterwards.
Originally-by: Roman Kagan <rkagan@virtuozzo.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 345fe32..922c1ab 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -207,10 +207,16 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in + let installed_block_type, legacy_pciid, modern_pciid = ( + if driver_name = "vioscsi" then + Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid + else + Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid + ) in g#cp source target; - add_guestor_to_registry t reg driver_name viostor_legacy_pciid; - add_guestor_to_registry t reg driver_name viostor_modern_pciid; - Virtio_blk in + add_guestor_to_registry t reg driver_name legacy_pciid; + add_guestor_to_registry t reg driver_name modern_pciid; + installed_block_type in
(* Can we install the virtio-net driver? *) let net : net_type =
Could we make this look more like the code before it was reverted here?
https://github.com/libguestfs/virt-v2v/commit/b28cd1dcfeb40e7002e8d0b0ce9dcc...
See the lines starting: | Some Virtio_SCSI, _, true -> (* Block driver needs tweaks to allow booting; the rest is set up by PnP ...
So the change would look like:
- | Some driver_name -> + | Some "viostor" -> (* Block driver needs tweaks to allow booting; * the rest is set up by PnP manager. *) let source = driverdir // (driver_name ^ ".sys") in let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in g#cp source target; add_guestor_to_registry t reg driver_name viostor_legacy_pciid; add_guestor_to_registry t reg driver_name viostor_modern_pciid; Virtio_blk in
+ | Some "vioscsi" -> + [... new code for the virtio-scsi case ...]
The old code was a bit clearer don't you think? Even if there's a little bit more duplication.
IMO evaluating driver path and adding registry value separately for each and every case seems like too much duplication. If you think string comparison looks a bit clumsy here, how about nesting another level of matching, like so:
| Some driver_name -> (* Block driver needs tweaks to allow booting; * the rest is set up by PnP manager. *) let source = driverdir // (driver_name ^ ".sys") in let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in let installed_block_type, legacy_pciid, modern_pciid = match driver_name with | "vioscsi" -> Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid | _ -> Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid in g#cp source target; add_guestor_to_registry t reg driver_name legacy_pciid; add_guestor_to_registry t reg driver_name modern_pciid; installed_block_type in
Rich.
On Thu, Mar 09, 2023 at 04:38:44PM +0200, Andrey Drobyshev wrote:
On 3/8/23 22:45, Richard W.M. Jones wrote:
On Tue, Mar 07, 2023 at 09:40:26PM +0200, Andrey Drobyshev wrote:
In case when we are injecting virtio-scsi device driver into the guest (rather than the default virtio-blk), make sure we write the right PCI ID value into the Windows guest registry. This is essential for the guest to be bootable afterwards.
Originally-by: Roman Kagan <rkagan@virtuozzo.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 345fe32..922c1ab 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -207,10 +207,16 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in + let installed_block_type, legacy_pciid, modern_pciid = ( + if driver_name = "vioscsi" then + Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid + else + Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid + ) in g#cp source target; - add_guestor_to_registry t reg driver_name viostor_legacy_pciid; - add_guestor_to_registry t reg driver_name viostor_modern_pciid; - Virtio_blk in + add_guestor_to_registry t reg driver_name legacy_pciid; + add_guestor_to_registry t reg driver_name modern_pciid; + installed_block_type in
(* Can we install the virtio-net driver? *) let net : net_type =
Could we make this look more like the code before it was reverted here?
https://github.com/libguestfs/virt-v2v/commit/b28cd1dcfeb40e7002e8d0b0ce9dcc...
See the lines starting: | Some Virtio_SCSI, _, true -> (* Block driver needs tweaks to allow booting; the rest is set up by PnP ...
So the change would look like:
- | Some driver_name -> + | Some "viostor" -> (* Block driver needs tweaks to allow booting; * the rest is set up by PnP manager. *) let source = driverdir // (driver_name ^ ".sys") in let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in g#cp source target; add_guestor_to_registry t reg driver_name viostor_legacy_pciid; add_guestor_to_registry t reg driver_name viostor_modern_pciid; Virtio_blk in
+ | Some "vioscsi" -> + [... new code for the virtio-scsi case ...]
The old code was a bit clearer don't you think? Even if there's a little bit more duplication.
IMO evaluating driver path and adding registry value separately for each and every case seems like too much duplication. If you think string comparison looks a bit clumsy here, how about nesting another level of matching, like so:
| Some driver_name -> (* Block driver needs tweaks to allow booting; * the rest is set up by PnP manager. *) let source = driverdir // (driver_name ^ ".sys") in let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in let installed_block_type, legacy_pciid, modern_pciid = match driver_name with | "vioscsi" -> Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid | _ -> Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid in g#cp source target; add_guestor_to_registry t reg driver_name legacy_pciid; add_guestor_to_registry t reg driver_name modern_pciid; installed_block_type in
Seems about the same as the original patch really. But yes, your choice here. You could leave it as in the original version. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com nbdkit - Flexible, fast NBD server with plugins https://gitlab.com/nbdkit/nbdkit
On 3/7/23 20:40, Andrey Drobyshev wrote:
In case when we are injecting virtio-scsi device driver into the guest (rather than the default virtio-blk), make sure we write the right PCI ID value into the Windows guest registry. This is essential for the guest to be bootable afterwards.
Originally-by: Roman Kagan <rkagan@virtuozzo.com> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> --- mlcustomize/inject_virtio_win.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml index 345fe32..922c1ab 100644 --- a/mlcustomize/inject_virtio_win.ml +++ b/mlcustomize/inject_virtio_win.ml @@ -207,10 +207,16 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = let target = sprintf "%s/system32/drivers/%s.sys" t.i_windows_systemroot driver_name in let target = g#case_sensitive_path target in + let installed_block_type, legacy_pciid, modern_pciid = ( + if driver_name = "vioscsi" then + Virtio_SCSI, vioscsi_legacy_pciid, vioscsi_modern_pciid + else + Virtio_blk, viostor_legacy_pciid, viostor_modern_pciid + ) in
I *think* Rich prefers not adding parens in such cases. (I think they are indeed not required, but I understand how they can be perceived as helping with indentation.) FWIW Reviewed-by: Laszlo Ersek <lersek@redhat.com>
g#cp source target; - add_guestor_to_registry t reg driver_name viostor_legacy_pciid; - add_guestor_to_registry t reg driver_name viostor_modern_pciid; - Virtio_blk in + add_guestor_to_registry t reg driver_name legacy_pciid; + add_guestor_to_registry t reg driver_name modern_pciid; + installed_block_type in
(* Can we install the virtio-net driver? *) let net : net_type =
participants (3)
-
Andrey Drobyshev -
Laszlo Ersek -
Richard W.M. Jones