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

Richard W.M. Jones rjones at redhat.com
Mon Oct 3 08:04:12 UTC 2016


On Tue, Sep 27, 2016 at 05:58:11PM +0200, Pino Toscano wrote:
> 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 (/boot/config-$kver)
> 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 | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml
> index b292921..c197f78 100644
> --- a/v2v/linux_kernels.ml
> +++ b/v2v/linux_kernels.ml
> @@ -53,6 +53,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 =
> +      let prefix = "^CONFIG_" ^ String.uppercase_ascii feature ^ "=" in
> +      let lines = g#grep ~extended:true prefix ("/boot/config-" ^ version) in
> +      let lines = Array.to_list lines in
> +      match lines with
> +      | [] -> false
> +      | line :: _ ->
> +        let kind = snd (String.split "=" line) in
> +        (match kind with
> +        | "m" (* Theoretically this should not be needed, since the module
> +               * would be found. *)
> +        | "y" -> true

I wouldn't bother with the long comment since it's stating the
obvious, and just do:

  | "m" | "y" -> true

> +        | _ -> false
> +        )
> +    in
>      let rex_ko_extract = Str.regexp ".*/\\([^/]+\\)\\.k?o\\(\\.xz\\)?$" in
>      let rex_initrd =
>        if family = `Debian_family then
> @@ -156,7 +171,10 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
>               ) modules in
>               assert (List.length modules > 0);
>  
> -             let supports_virtio = List.mem "virtio_net" modules in
> +             let kernel_supports what kconf =
> +               List.mem what modules || check_config version kconf 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

Yes this is something we should have been doing for a long time.

ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW




More information about the Libguestfs mailing list