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

Richard W.M. Jones rjones at redhat.com
Fri Aug 26 13:16:12 UTC 2016


On Fri, Aug 26, 2016 at 11:02:07AM +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.

Should we only check the config file?  Seems like a waste of time to
download the module names and check those, and I suppose in some
corner case might even be misleading.

Also the code as it stands makes the assumption that the name of the
CONFIG_* option is the same as the kernel module, which is not true
for some things we care about (virtio-scsi, I think?).

Rich.

>  v2v/convert_linux.ml | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
> index ce9a1e3..6f96073 100644
> --- a/v2v/convert_linux.ml
> +++ b/v2v/convert_linux.ml
> @@ -95,6 +95,21 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
>    (* 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
> +        | _ -> false
> +        )
> +    in
>      let rex_ko_extract = Str.regexp ".*/\\([^/]+\\)\\.k?o\\(\\.xz\\)?$" in
>      let rex_initrd = Str.regexp "^initr\\(d\\|amfs\\)-.*\\(\\.img\\)?$" in
>      filter_map (
> @@ -193,8 +208,11 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
>               ) modules in
>               assert (List.length modules > 0);
>  
> -             let supports_virtio = List.mem "virtio_net" modules in
> -             let is_xen_kernel = List.mem "xennet" modules in
> +             let kernel_supports what =
> +               List.mem what modules || check_config version what in
> +
> +             let supports_virtio = kernel_supports "virtio_net" in
> +             let is_xen_kernel = kernel_supports "xennet" in
>  
>               (* If the package name is like "kernel-debug", then it's
>                * a debug kernel.
> -- 
> 2.7.4
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
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




More information about the Libguestfs mailing list