[Libguestfs] [PATCH v2 3/3] v2v: linux: check also kernel config for modules

Pino Toscano ptoscano at redhat.com
Mon Oct 3 09:44:01 UTC 2016


When checking whether a kernel supports virtio or it is Xen-based, it is
assumed that the feature has the kernel module for it; this will fail if
the feature is built-in in the kernel, misrepresenting it.

The solution is to check the kernel configuration whether the feature
is built-in, in case there is no module available.

This fixes the virtio detection on Ubuntu kernels, where virtio is
built in and not as module.
---
 v2v/linux_kernels.ml | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml
index df093d0..f15e82a 100644
--- a/v2v/linux_kernels.ml
+++ b/v2v/linux_kernels.ml
@@ -55,6 +55,21 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
   (* What kernel/kernel-like packages are installed on the current guest? *)
   let installed_kernels : kernel_info list =
     let rex_ko = Str.regexp ".*\\.k?o\\(\\.xz\\)?$" in
+    let check_config version feature = function
+      | None -> false
+      | Some config ->
+        let prefix = "^CONFIG_" ^ String.uppercase_ascii feature ^ "=" in
+        let lines = g#grep ~extended:true prefix config in
+        let lines = Array.to_list lines in
+        match lines with
+        | [] -> false
+        | line :: _ ->
+          let kind = snd (String.split "=" line) in
+          (match kind with
+          | "m" | "y" -> true
+          | _ -> false
+          )
+    in
     let rex_ko_extract = Str.regexp ".*/\\([^/]+\\)\\.k?o\\(\\.xz\\)?$" in
     let rex_initrd =
       if family = `Debian_family then
@@ -163,7 +178,11 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
                if List.mem cfg files then Some cfg
                else None in
 
-             let supports_virtio = List.mem "virtio_net" modules in
+             let kernel_supports what kconf =
+               List.mem what modules
+               || check_config version kconf config_file in
+
+             let supports_virtio = kernel_supports "virtio_net" "VIRTIO_NET" in
              let is_xen_kernel = List.mem "xennet" modules in
 
              (* If the package name is like "kernel-debug", then it's
-- 
2.7.4




More information about the Libguestfs mailing list