[Libguestfs] [PATCH] v2v: support configuration of viosock driver

Valeriy Vdovin valeriy.vdovin at virtuozzo.com
Tue Feb 16 17:11:38 UTC 2021


Check that install_drivers function has copied viosock driver files to
the windows guest file system. If positive, this means the drivers have
passed minor/major version check and the guest is able to use them.
After we know that that the drivers are on the guest, we can enable
virtio sock option in configuration and starting script files.

Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
---
 v2v/convert_linux.ml      | 1 +
 v2v/convert_windows.ml    | 4 +++-
 v2v/create_json.ml        | 1 +
 v2v/create_libvirt_xml.ml | 6 ++++++
 v2v/linux_kernels.ml      | 4 ++++
 v2v/linux_kernels.mli     | 1 +
 v2v/output_qemu.ml        | 4 ++++
 v2v/types.ml              | 1 +
 v2v/types.mli             | 2 +-
 v2v/windows_virtio.ml     | 5 +++--
 v2v/windows_virtio.mli    | 2 +-
 11 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 86d387f1..9f22fe3c 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -154,6 +154,7 @@ let convert (g : G.guestfs) inspect source_disks output rcaps _ =
       gcaps_virtio_rng = kernel.ki_supports_virtio_rng;
       gcaps_virtio_balloon = kernel.ki_supports_virtio_balloon;
       gcaps_isa_pvpanic = kernel.ki_supports_isa_pvpanic;
+      gcaps_virtio_socket = kernel.ki_supports_virtio_socket;
       gcaps_machine = machine;
       gcaps_arch = Utils.kvm_arch inspect.i_arch;
       gcaps_acpi = acpi;
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index b452c09b..7842f443 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -214,7 +214,8 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
         video_driver,
         virtio_rng_supported,
         virtio_ballon_supported,
-        isa_pvpanic_supported =
+        isa_pvpanic_supported,
+        virtio_socket_supported =
       Registry.with_hive_write g inspect.i_windows_system_hive
                                update_system_hive in
 
@@ -256,6 +257,7 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
       gcaps_virtio_rng = virtio_rng_supported;
       gcaps_virtio_balloon = virtio_ballon_supported;
       gcaps_isa_pvpanic = isa_pvpanic_supported;
+      gcaps_virtio_socket = virtio_socket_supported;
       gcaps_machine = machine;
       gcaps_arch = Utils.kvm_arch inspect.i_arch;
       gcaps_acpi = true;
diff --git a/v2v/create_json.ml b/v2v/create_json.ml
index fdf7b12f..316a5536 100644
--- a/v2v/create_json.ml
+++ b/v2v/create_json.ml
@@ -229,6 +229,7 @@ let create_json_metadata source targets target_buses
       "virtio-rng", JSON.Bool guestcaps.gcaps_virtio_rng;
       "virtio-balloon", JSON.Bool guestcaps.gcaps_virtio_balloon;
       "isa-pvpanic", JSON.Bool guestcaps.gcaps_isa_pvpanic;
+      "virtio-socket", JSON.Bool guestcaps.gcaps_virtio_socket;
       "acpi", JSON.Bool guestcaps.gcaps_acpi;
     ] in
   List.push_back doc ("guestcaps", JSON.Dict guestcaps_dict);
diff --git a/v2v/create_libvirt_xml.ml b/v2v/create_libvirt_xml.ml
index 212ace2d..6a764cb2 100644
--- a/v2v/create_libvirt_xml.ml
+++ b/v2v/create_libvirt_xml.ml
@@ -521,6 +521,12 @@ let create_libvirt_xml ?pool source targets target_buses guestcaps
         e "address" ["type", "isa"; "iobase", "0x505"] []
       ]
     );
+  List.push_back devices (
+    e "viosock"
+      ["model",
+        if guestcaps.gcaps_virtio_socket then "virtio" else "none"]
+       []
+  );
 
   (* Standard devices added to every guest. *)
   List.push_back_list devices [
diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml
index 7e171eae..6dead217 100644
--- a/v2v/linux_kernels.ml
+++ b/v2v/linux_kernels.ml
@@ -44,6 +44,7 @@ type kernel_info = {
   ki_supports_virtio_rng : bool;
   ki_supports_virtio_balloon : bool;
   ki_supports_isa_pvpanic : bool;
+  ki_supports_virtio_socket : bool;
   ki_is_xen_pv_only_kernel : bool;
   ki_is_debug : bool;
   ki_config_file : string option;
@@ -246,6 +247,8 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
              kernel_supports "virtio_balloon" "VIRTIO_BALLOON" in
            let supports_isa_pvpanic =
              kernel_supports "pvpanic" "PVPANIC" in
+           let supports_virtio_socket =
+               kernel_supports "virtio_socket" "VIRTIO_SOCKET" in
            let is_xen_pv_only_kernel =
              check_config "X86_XEN" config_file ||
              check_config "X86_64_XEN" config_file in
@@ -272,6 +275,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
              ki_supports_virtio_rng = supports_virtio_rng;
              ki_supports_virtio_balloon = supports_virtio_balloon;
              ki_supports_isa_pvpanic = supports_isa_pvpanic;
+             ki_supports_virtio_socket = supports_virtio_socket;
              ki_is_xen_pv_only_kernel = is_xen_pv_only_kernel;
              ki_is_debug = is_debug;
              ki_config_file = config_file;
diff --git a/v2v/linux_kernels.mli b/v2v/linux_kernels.mli
index 028eba81..fe81a036 100644
--- a/v2v/linux_kernels.mli
+++ b/v2v/linux_kernels.mli
@@ -33,6 +33,7 @@ type kernel_info = {
   ki_supports_virtio_rng : bool;   (** Kernel supports virtio-rng? *)
   ki_supports_virtio_balloon : bool; (** Kernel supports memory balloon? *)
   ki_supports_isa_pvpanic : bool;  (** Kernel supports ISA pvpanic device? *)
+  ki_supports_virtio_socket : bool; (** Kernel supports virtio-socket? *)
   ki_is_xen_pv_only_kernel : bool; (** Is a Xen paravirt-only kernel? *)
   ki_is_debug : bool;              (** Is debug kernel? *)
   ki_config_file : string option;  (** Path of config file, if found. *)
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
index be3a3c5e..d6d70c23 100644
--- a/v2v/output_qemu.ml
+++ b/v2v/output_qemu.ml
@@ -247,6 +247,10 @@ object
       arg "-balloon" "none";
     if guestcaps.gcaps_isa_pvpanic then
       arg_list "-device" ["pvpanic"; "ioport=0x505"];
+    if guestcaps.gcaps_virtio_socket then
+      arg "-viosock" "virtio"
+    else
+      arg "-viosock" "none";
 
     (* Add a serial console to Linux guests. *)
     if inspect.i_type = "linux" then
diff --git a/v2v/types.ml b/v2v/types.ml
index a8949e4b..4c7ee864 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -411,6 +411,7 @@ type guestcaps = {
   gcaps_virtio_rng : bool;
   gcaps_virtio_balloon : bool;
   gcaps_isa_pvpanic : bool;
+  gcaps_virtio_socket : bool;
   gcaps_machine : guestcaps_machine;
   gcaps_arch : string;
   gcaps_acpi : bool;
diff --git a/v2v/types.mli b/v2v/types.mli
index f474dcaa..42a80d9d 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -252,7 +252,7 @@ type guestcaps = {
   gcaps_virtio_rng : bool;      (** Guest supports virtio-rng. *)
   gcaps_virtio_balloon : bool;  (** Guest supports virtio balloon. *)
   gcaps_isa_pvpanic : bool;     (** Guest supports ISA pvpanic device. *)
-
+  gcaps_virtio_socket : bool;   (** Guest supports virtio socket. *)
   gcaps_machine : guestcaps_machine; (** Machine model. *)
   gcaps_arch : string;          (** Architecture that KVM must emulate. *)
   gcaps_acpi : bool;            (** True if guest supports acpi. *)
diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
index 74a43cc7..cf417a45 100644
--- a/v2v/windows_virtio.ml
+++ b/v2v/windows_virtio.ml
@@ -68,7 +68,7 @@ let rec install_drivers ((g, _) as reg) inspect rcaps =
         match net_type with
         | Some model -> model
         | None -> RTL8139 in
-      (IDE, net_type, Cirrus, false, false, false)
+      (IDE, net_type, Cirrus, false, false, false, false)
   )
   else (
     (* Can we install the block driver? *)
@@ -178,9 +178,10 @@ let rec install_drivers ((g, _) as reg) inspect rcaps =
     let virtio_rng_supported = g#exists (driverdir // "viorng.inf") in
     let virtio_ballon_supported = g#exists (driverdir // "balloon.inf") in
     let isa_pvpanic_supported = g#exists (driverdir // "pvpanic.inf") in
+    let virtio_socket_supported = g#exists (driverdir // "viosock.inf") in
 
     (block, net, video,
-     virtio_rng_supported, virtio_ballon_supported, isa_pvpanic_supported)
+     virtio_rng_supported, virtio_ballon_supported, isa_pvpanic_supported, virtio_socket_supported)
   )
 
 and install_linux_tools g inspect =
diff --git a/v2v/windows_virtio.mli b/v2v/windows_virtio.mli
index c063af3f..642317b1 100644
--- a/v2v/windows_virtio.mli
+++ b/v2v/windows_virtio.mli
@@ -20,7 +20,7 @@
 
 val install_drivers
     : Registry.t -> Types.inspect -> Types.requested_guestcaps ->
-      Types.guestcaps_block_type * Types.guestcaps_net_type * Types.guestcaps_video_type * bool * bool * bool
+      Types.guestcaps_block_type * Types.guestcaps_net_type * Types.guestcaps_video_type * bool * bool * bool * bool
 (** [install_drivers reg inspect rcaps]
     installs virtio drivers from the driver directory or driver
     ISO into the guest driver directory and updates the registry
-- 
2.27.0




More information about the Libguestfs mailing list