[Libguestfs] [PATCH v3 3/8] v2v: linux: Replace 'ki_supports_virtio' field.

Richard W.M. Jones rjones at redhat.com
Thu Apr 6 08:13:25 UTC 2017


Previously the kernel_info field 'ki_supports_virtio' really meant
that the kernel supports virtio-net.  That was used as a proxy to mean
the kernel supports virtio in general.

This change splits the field so we explicitly test for both virtio-blk
and virtio-net drivers, and store the results as separate fields.

The patch is straightforward, except for the change to the
'rebuild_initrd' function.  Instead of making the module list
conditional on whether virtio-net is available and using the old
(probably wrong) fallback if it happens to be unavailable, this now
tries to enable the common virtio kernel modules (just the ones needed
for virtio-blk and virtio-net to work).  The fallback is only used if
none of the common virtio modules can be found.
---
 v2v/convert_linux.ml  | 20 +++++++++++---------
 v2v/linux_kernels.ml  | 38 ++++++++++++++++++++++----------------
 v2v/linux_kernels.mli |  3 ++-
 3 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 5a83be625..46b989d5d 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -403,11 +403,12 @@ let rec convert (g : G.guestfs) inspect source output rcaps =
       error (f_"only Xen kernels are installed in this guest.\n\nRead the %s(1) manual, section \"XEN PARAVIRTUALIZED GUESTS\", to see what to do.") prog;
 
     (* Enable the best non-Xen kernel, where "best" means the one with
-     * the highest version which supports virtio.
+     * the highest version, preferring non-debug kernels which support
+     * virtio.
      *)
     let best_kernel =
       let compare_best_kernels k1 k2 =
-        let i = compare k1.ki_supports_virtio k2.ki_supports_virtio in
+        let i = compare k1.ki_supports_virtio_net k2.ki_supports_virtio_net in
         if i <> 0 then i
         else (
           let i = compare_app2_versions k1.ki_app k2.ki_app in
@@ -446,9 +447,9 @@ let rec convert (g : G.guestfs) inspect source output rcaps =
     match kernel.ki_initrd with
     | None -> ()
     | Some initrd ->
-      let virtio = kernel.ki_supports_virtio in
+      (* Enable the basic virtio modules in the kernel. *)
       let modules =
-        if virtio then
+        let modules =
           (* The order of modules here is deliberately the same as the
            * order specified in the postinstall script of kmod-virtio in
            * RHEL3. The reason is that the probing order determines the
@@ -457,9 +458,11 @@ let rec convert (g : G.guestfs) inspect source output rcaps =
            *)
           List.filter (fun m -> List.mem m kernel.ki_modules)
                       [ "virtio"; "virtio_ring"; "virtio_blk";
-                        "virtio_scsi"; "virtio_net"; "virtio_pci" ]
+                        "virtio_scsi"; "virtio_net"; "virtio_pci" ] in
+        if modules <> [] then modules
         else
-          [ "sym53c8xx" (* XXX why not "ide"? *) ] in
+          (* Fallback copied from old virt-v2v.  XXX Why not "ide"? *)
+          [ "sym53c8xx" ] in
 
       (* Move the old initrd file out of the way.  Note that dracut/mkinitrd
        * will refuse to overwrite an old file so we have to do this.
@@ -1002,7 +1005,6 @@ let rec convert (g : G.guestfs) inspect source output rcaps =
   unconfigure_prltools ();
 
   let kernel = configure_kernel () in
-  let virtio = kernel.ki_supports_virtio in
 
   if output#keep_serial_console then (
     configure_console ();
@@ -1021,12 +1023,12 @@ let rec convert (g : G.guestfs) inspect source output rcaps =
 
   let block_type =
     match rcaps.rcaps_block_bus with
-    | None -> if virtio then Virtio_blk else IDE
+    | None -> if kernel.ki_supports_virtio_blk then Virtio_blk else IDE
     | Some block_type -> block_type in
 
   let net_type =
     match rcaps.rcaps_net_bus with
-    | None -> if virtio then Virtio_net else E1000
+    | None -> if kernel.ki_supports_virtio_net then Virtio_net else E1000
     | Some net_type -> net_type in
 
   configure_display_driver video;
diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml
index 459dc06bd..37b281bb0 100644
--- a/v2v/linux_kernels.ml
+++ b/v2v/linux_kernels.ml
@@ -38,18 +38,25 @@ type kernel_info = {
   ki_initrd : string option;
   ki_modpath : string;
   ki_modules : string list;
-  ki_supports_virtio : bool;
+  ki_supports_virtio_blk : bool;
+  ki_supports_virtio_net : bool;
   ki_is_xen_pv_only_kernel : bool;
   ki_is_debug : bool;
   ki_config_file : string option;
 }
 
-let string_of_kernel_info ki =
-  sprintf "(%s, %s, %s, %s, %s, %s, virtio=%b, xen=%b, debug=%b)"
-    ki.ki_name ki.ki_version ki.ki_arch ki.ki_vmlinuz
-    (match ki.ki_initrd with None -> "None" | Some f -> f)
-    (match ki.ki_config_file with None -> "None" | Some f -> f)
-    ki.ki_supports_virtio ki.ki_is_xen_pv_only_kernel ki.ki_is_debug
+let print_kernel_info chan prefix ki =
+  let fpf fs = output_string chan prefix; fprintf chan fs in
+  fprintf chan "* %s %s (%s)\n" ki.ki_name ki.ki_version ki.ki_arch;
+  fpf "%s\n" ki.ki_vmlinuz;
+  fpf "%s\n" (match ki.ki_initrd with None -> "no initrd" | Some s -> s);
+  fpf "%s\n" (match ki.ki_config_file with None -> "no config" | Some s -> s);
+  fpf "%s\n" ki.ki_modpath;
+  fpf "%d modules found\n" (List.length ki.ki_modules);
+  fpf "virtio: blk=%b net=%b\n"
+      ki.ki_supports_virtio_blk ki.ki_supports_virtio_net;
+  fpf "xen=%b debug=%b\n"
+      ki.ki_is_xen_pv_only_kernel ki.ki_is_debug
 
 let detect_kernels (g : G.guestfs) inspect family bootloader =
   (* What kernel/kernel-like packages are installed on the current guest? *)
@@ -181,7 +188,10 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
              let kernel_supports what kconf =
                List.mem what modules || check_config kconf config_file in
 
-             let supports_virtio = kernel_supports "virtio_net" "VIRTIO_NET" in
+             let supports_virtio_blk =
+               kernel_supports "virtio_blk" "VIRTIO_BLK" in
+             let supports_virtio_net =
+               kernel_supports "virtio_net" "VIRTIO_NET" in
              let is_xen_pv_only_kernel =
                check_config "CONFIG_X86_XEN" config_file ||
                check_config "CONFIG_X86_64_XEN" config_file in
@@ -203,7 +213,8 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
                ki_initrd = initrd;
                ki_modpath = modpath;
                ki_modules = modules;
-               ki_supports_virtio = supports_virtio;
+               ki_supports_virtio_blk = supports_virtio_blk;
+               ki_supports_virtio_net = supports_virtio_net;
                ki_is_xen_pv_only_kernel = is_xen_pv_only_kernel;
                ki_is_debug = is_debug;
                ki_config_file = config_file;
@@ -218,9 +229,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
 
   if verbose () then (
     eprintf "installed kernel packages in this guest:\n";
-    List.iter (
-      fun kernel -> eprintf "\t%s\n" (string_of_kernel_info kernel)
-    ) installed_kernels;
+    List.iter (print_kernel_info stderr "\t") installed_kernels;
     flush stderr
   );
 
@@ -257,10 +266,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
 
   if verbose () then (
     eprintf "kernels offered by the bootloader in this guest (first in list is default):\n";
-    List.iter (
-      fun kernel ->
-        eprintf "\t%s\n" (string_of_kernel_info kernel)
-    ) bootloader_kernels;
+    List.iter (print_kernel_info stderr "\t") bootloader_kernels;
     flush stderr
   );
 
diff --git a/v2v/linux_kernels.mli b/v2v/linux_kernels.mli
index a56516233..f536583ca 100644
--- a/v2v/linux_kernels.mli
+++ b/v2v/linux_kernels.mli
@@ -28,7 +28,8 @@ type kernel_info = {
   ki_initrd : string option;       (** Path of initramfs, if found. *)
   ki_modpath : string;             (** The module path. *)
   ki_modules : string list;        (** The list of module names. *)
-  ki_supports_virtio : bool;       (** Kernel has virtio drivers? *)
+  ki_supports_virtio_blk : bool;   (** Kernel supports virtio-blk? *)
+  ki_supports_virtio_net : bool;   (** Kernel supports virtio-net? *)
   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. *)
-- 
2.12.0




More information about the Libguestfs mailing list