Blame SOURCES/0041-v2v-Fix-kernel-detection-when-multiple-kernels-are-i.patch

0d20ef
From 76ebcac68d5e2da63494e94c6f6039677515ca7f Mon Sep 17 00:00:00 2001
0d20ef
From: "Richard W.M. Jones" <rjones@redhat.com>
0d20ef
Date: Thu, 6 Nov 2014 18:47:34 +0000
0d20ef
Subject: [PATCH] v2v: Fix kernel detection when multiple kernels are installed
0d20ef
 (RHBZ#1161250).
0d20ef
0d20ef
Previously we used to try to find the 'vmlinuz' file by running 'rpm
0d20ef
-ql kernel' and looking for any file called 'vmlinuz-*'.
0d20ef
0d20ef
If there were multiple 'kernel' packages installed, the rpm command
0d20ef
would list files from all of them, resulting in a random 'vmlinuz-*'
0d20ef
being chosen, not necessarily the one corresponding to the kernel
0d20ef
package we were looking at.
0d20ef
0d20ef
Use 'rpm -ql kernel-<VERSION>-<RELEASE>' instead so that we only look
0d20ef
for files in the right kernel package.
0d20ef
0d20ef
Thanks: James Mighion
0d20ef
(cherry picked from commit 377bc302f11db3da4263f894c76a7d280fb25dbd)
0d20ef
---
0d20ef
 v2v/convert_linux.ml |  2 +-
0d20ef
 v2v/linux.ml         | 17 +++++++++++++++--
0d20ef
 v2v/linux.mli        |  2 +-
0d20ef
 3 files changed, 17 insertions(+), 4 deletions(-)
0d20ef
0d20ef
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
0d20ef
index 6c0c903..b6335d9 100644
0d20ef
--- a/v2v/convert_linux.ml
0d20ef
+++ b/v2v/convert_linux.ml
0d20ef
@@ -148,7 +148,7 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
0d20ef
           when name = "kernel" || string_prefix name "kernel-" ->
0d20ef
         (try
0d20ef
            (* For each kernel, list the files directly owned by the kernel. *)
0d20ef
-           let files = Linux.file_list_of_package verbose g inspect name in
0d20ef
+           let files = Linux.file_list_of_package verbose g inspect app in
0d20ef
 
0d20ef
            (* Which of these is the kernel itself? *)
0d20ef
            let vmlinuz = List.find (
0d20ef
diff --git a/v2v/linux.ml b/v2v/linux.ml
0d20ef
index 2c743e3..4287a4f 100644
0d20ef
--- a/v2v/linux.ml
0d20ef
+++ b/v2v/linux.ml
0d20ef
@@ -24,6 +24,8 @@ open Common_utils
0d20ef
 open Types
0d20ef
 open Utils
0d20ef
 
0d20ef
+module G = Guestfs
0d20ef
+
0d20ef
 (* Wrappers around aug_init & aug_load which can dump out full Augeas
0d20ef
  * parsing problems when debugging is enabled.
0d20ef
  *)
0d20ef
@@ -115,12 +117,23 @@ let remove verbose g inspect packages =
0d20ef
         format (String.concat " " packages)
0d20ef
   )
0d20ef
 
0d20ef
-let file_list_of_package verbose (g : Guestfs.guestfs) inspect name =
0d20ef
+let file_list_of_package verbose (g : Guestfs.guestfs) inspect app =
0d20ef
   let package_format = inspect.i_package_format in
0d20ef
 
0d20ef
   match package_format with
0d20ef
   | "rpm" ->
0d20ef
-    let cmd = [| "rpm"; "-ql"; name |] in
0d20ef
+    (* Since RPM allows multiple packages installed with the same
0d20ef
+     * name, always check the full ENVR here (RHBZ#1161250).
0d20ef
+     *)
0d20ef
+    let pkg_name =
0d20ef
+      sprintf "%s-%s-%s" app.G.app2_name
0d20ef
+        app.G.app2_version app.G.app2_release in
0d20ef
+    let pkg_name =
0d20ef
+      if app.G.app2_epoch > 0_l then
0d20ef
+        sprintf "%ld:%s" app.G.app2_epoch pkg_name
0d20ef
+      else
0d20ef
+        pkg_name in
0d20ef
+    let cmd = [| "rpm"; "-ql"; pkg_name |] in
0d20ef
     if verbose then eprintf "%s\n%!" (String.concat " " (Array.to_list cmd));
0d20ef
     let files = g#command_lines cmd in
0d20ef
     let files = Array.to_list files in
0d20ef
diff --git a/v2v/linux.mli b/v2v/linux.mli
0d20ef
index e5a3025..14e757b 100644
0d20ef
--- a/v2v/linux.mli
0d20ef
+++ b/v2v/linux.mli
0d20ef
@@ -31,7 +31,7 @@ val install : bool -> Guestfs.guestfs -> Types.inspect -> string list -> unit
0d20ef
 val remove : bool -> Guestfs.guestfs -> Types.inspect -> string list -> unit
0d20ef
 (** Uninstall package(s). *)
0d20ef
 
0d20ef
-val file_list_of_package : bool -> Guestfs.guestfs -> Types.inspect -> string -> string list
0d20ef
+val file_list_of_package : bool -> Guestfs.guestfs -> Types.inspect -> Guestfs.application2 -> string list
0d20ef
 (** Return list of files owned by package. *)
0d20ef
 
0d20ef
 val file_owner : bool -> Guestfs.guestfs -> Types.inspect -> string -> string
0d20ef
-- 
0d20ef
1.8.3.1
0d20ef