Blame SOURCES/0018-v2v-linux-improve-arch-detection-from-modules-RHBZ-1.patch

da373f
From de9ebcaf0784c464a3ca3b2686935ce2bddcc281 Mon Sep 17 00:00:00 2001
3efd08
From: Pino Toscano <ptoscano@redhat.com>
3efd08
Date: Wed, 20 Mar 2019 12:32:02 +0100
3efd08
Subject: [PATCH] v2v: linux: improve arch detection from modules
3efd08
 (RHBZ#1690574)
3efd08
3efd08
Try to look for a well known kernel module (so far only virtio, or kvm)
3efd08
to use for detecting the architecture of a kernel.  This way, we can
3efd08
avoid picking 3rd party modules that cause troubles.
3efd08
3efd08
(cherry picked from commit 363b5e0b4ecebe861a9aafe8bce5a8390b54571c)
3efd08
---
3efd08
 v2v/linux_kernels.ml | 30 +++++++++++++++++++++++++++---
3efd08
 1 file changed, 27 insertions(+), 3 deletions(-)
3efd08
3efd08
diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml
3efd08
index 889ec2f2a..30160f0da 100644
3efd08
--- a/v2v/linux_kernels.ml
3efd08
+++ b/v2v/linux_kernels.ml
3efd08
@@ -185,11 +185,35 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
3efd08
              assert (List.length modules > 0);
3efd08
 
3efd08
              (* Determine the kernel architecture by looking at the
3efd08
-              * architecture of an arbitrary kernel module.
3efd08
+              * architecture of a kernel module.
3efd08
+              *
3efd08
+              * To avoid architecture detection issues with 3rd party
3efd08
+              * modules (RHBZ#1690574), try to pick one of the well
3efd08
+              * known modules, if available.  Otherwise, an arbitrary
3efd08
+              * module is used.
3efd08
               *)
3efd08
              let arch =
3efd08
-               let any_module = modpath ^ List.hd modules in
3efd08
-               g#file_architecture (g#realpath any_module) in
3efd08
+               (* Well known kernel modules. *)
3efd08
+               let candidates = [ "virtio"; "kvm" ] in
3efd08
+               let all_candidates = List.flatten (
3efd08
+                 List.map (
3efd08
+                   fun f ->
3efd08
+                     [ "/" ^ f ^ ".o"; "/" ^ f ^ ".ko"; "/" ^ f ^ ".ko.xz" ]
3efd08
+                 ) candidates
3efd08
+               ) in
3efd08
+               let candidate =
3efd08
+                 try
3efd08
+                   List.find (
3efd08
+                     fun m ->
3efd08
+                       List.exists (String.is_suffix m) all_candidates
3efd08
+                   ) modules
3efd08
+                 with Not_found ->
3efd08
+                   (* No known module found, pick an arbitrary one
3efd08
+                    * (the first).
3efd08
+                    *)
3efd08
+                   List.hd modules in
3efd08
+               let candidate = modpath ^ candidate in
3efd08
+               g#file_architecture (g#realpath candidate) in
3efd08
 
3efd08
              (* Just return the module names, without path or extension. *)
3efd08
              let modules = List.filter_map (
3efd08
-- 
da373f
2.18.4
3efd08