mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

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