[Libguestfs] [PATCH] v2v: linux: improve archtecture detection from modules (RHBZ#1690574)
Richard W.M. Jones
rjones at redhat.com
Wed Mar 20 16:13:32 UTC 2019
On Wed, Mar 20, 2019 at 12:36:16PM +0100, Pino Toscano wrote:
> Try to look for a well known kernel module (so far only virtio, or kvm)
> to use for detecting the architecture of a kernel. This way, we can
> avoid picking 3rd party modules that cause troubles.
> ---
> v2v/linux_kernels.ml | 30 +++++++++++++++++++++++++++---
> 1 file changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml
> index 3313aabc7..f1b9bdd97 100644
> --- a/v2v/linux_kernels.ml
> +++ b/v2v/linux_kernels.ml
> @@ -185,11 +185,35 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
> assert (List.length modules > 0);
>
> (* Determine the kernel architecture by looking at the
> - * architecture of an arbitrary kernel module.
> + * architecture of a kernel module.
> + *
> + * To avoid architecture detection issues with 3rd party
> + * modules (RHBZ#1690574), try to pick one of the well
> + * known modules, if available. Otherwise, an arbitrary
> + * module is used.
> *)
> let arch =
> - let any_module = modpath ^ List.hd modules in
> - g#file_architecture any_module in
> + (* Well known kernel modules. *)
> + let candidates = [ "virtio"; "kvm" ] in
> + let all_candidates = List.flatten (
> + List.map (
> + fun f ->
> + [ "/" ^ f ^ ".o"; "/" ^ f ^ ".ko"; "/" ^ f ^ ".ko.xz" ]
> + ) candidates
> + ) in
> + let candidate =
> + try
> + List.find (
> + fun m ->
> + List.exists (String.is_suffix m) all_candidates
> + ) modules
> + with Not_found ->
> + (* No known module found, pick an arbitrary one
> + * (the first).
> + *)
> + List.hd modules in
> + let candidate = modpath ^ candidate in
> + g#file_architecture candidate in
>
> (* Just return the module names, without path or extension. *)
> let modules = List.filter_map (
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list