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

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