Laszlo Ersek
2023-Apr-05 15:08 UTC
[Libguestfs] [rhel-9.2 v2v PATCH 0/2] detect_kernels: deal with RHEL's kernel-core / kernel-modules-core split
https://bugzilla.redhat.com/show_bug.cgi?id=2175703
In RHEL-9.2, the "detect_kernels" function still exists in virt-v2v,
not
in the common submodule. Because we need to fix RHBZ#2175703 for
RHEL-9.2.z as well, port of the identically named libguestfs-common
patch series
<http://mid.mail-archive.com/20230320115301.43051-1-lersek at redhat.com>
to RHEL-9.2 virt-v2v.
This port is based on the current HEAD of the rhel-9.2 branch (see
"base-commit" below).
Thanks
Laszlo
Laszlo Ersek (2):
detect_kernels: tighten "try" scope
detect_kernels: deal with RHEL's kernel-core / kernel-modules-core
split
convert/linux_kernels.ml | 26 ++++++++++++++------
1 file changed, 19 insertions(+), 7 deletions(-)
base-commit: 86517b17be985cb234846c75680c144bf9ea2dd8
Laszlo Ersek
2023-Apr-05 15:08 UTC
[Libguestfs] [rhel-9.2 v2v PATCH 1/2] detect_kernels: tighten "try" scope
We want to catch Not_found from (our own implementation of)
"List.find_map". There's no need (and it makes no sense) to push
the
"prefix_len" calculation down into the "try" scope. Keep the
"try" scope
as narrow as possible.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2175703
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
Tested-by: Vera Wu <vwu at redhat.com>
(ported from libguestfs-common commit 4003815a994944cab38d48cfc96f16382de62987)
---
convert/linux_kernels.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/convert/linux_kernels.ml b/convert/linux_kernels.ml
index 6e9d2bdd89cc..75ab94c45551 100644
--- a/convert/linux_kernels.ml
+++ b/convert/linux_kernels.ml
@@ -122,8 +122,8 @@ let detect_kernels (g : G.guestfs) inspect family bootloader
*)
let modpath, version let prefix =
"/lib/modules/" in
+ let prefix_len = String.length prefix in
try
- let prefix_len = String.length prefix in
List.find_map (
fun filename ->
let filename_len = String.length filename in
Laszlo Ersek
2023-Apr-05 15:08 UTC
[Libguestfs] [rhel-9.2 v2v PATCH 2/2] detect_kernels: deal with RHEL's kernel-core / kernel-modules-core split
In "kernel-5.14.0-269.el9", the "kernel-modules-core"
subpackage got split
from the "kernel-core" subpackage. Therefore, a single binary RPM
containing *both* the "/boot/vmlinuz-5.14.0-269.el9.x86_64" file *and*
the
"/lib/modules/5.14.0-269.el9.x86_64" directory no longer exists. The
file
now belongs to "kernel-core", and the directory to
"kernel-modules-core".
As a result, when we investigate the file list of "kernel-core" (based
on
"kernel-core" providing
"/boot/vmlinuz-5.14.0-269.el9.x86_64"), the first
match against "/lib/modules/" is not the actual module root directory
"/lib/modules/5.14.0-269.el9.x86_64", but the nonsensical
"/lib/modules/5.14.0-269.el9.x86_64/.vmlinuz.hmac" regular file. This
latter file is never a directory, therefore we rule out "kernel-core"
as a
kernel package.
We also rule out "kernel-modules-core" (even earlier) because it does
not
contain "/boot/vmlinuz-5.14.0-269.el9.x86_64".
Now, the code already deals with the case if the prospective kernel
package *does not provide a match* for the "/lib/modules/" prefix: in
that
case, we construct the modpath manually, from said prefix, and the version
number found in "/boot/vmlinuz-<version>". This fallback is
good, but it's
unreachable if *there is* a candidate, it's just wrong (i.e., not a
directory).
Perform the "is_dir" check on the candidate modpath earlier, so that
we
can fall back to the manual modpath construction if the modpath candidate
exists, but is wrong.
With this, the original "is_dir" check becomes superfluous
(duplicated)
*except* when the "Not_found" branch is taken. Therefore, hoist the
original "is_dir" check into that branch.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2175703
Reported-by: Vera Wu <vwu at redhat.com>
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
Tested-by: Vera Wu <vwu at redhat.com>
(ported from libguestfs-common commit 70c10a079a30ff3a84f38596d725a6c5d46e2470)
---
convert/linux_kernels.ml | 24 +++++++++++++++-----
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/convert/linux_kernels.ml b/convert/linux_kernels.ml
index 75ab94c45551..d0b316437072 100644
--- a/convert/linux_kernels.ml
+++ b/convert/linux_kernels.ml
@@ -124,7 +124,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader
let prefix = "/lib/modules/" in
let prefix_len = String.length prefix in
try
- List.find_map (
+ let modpath, version = List.find_map (
fun filename ->
let filename_len = String.length filename in
if filename_len > prefix_len &&
@@ -134,17 +134,29 @@ let detect_kernels (g : G.guestfs) inspect family
bootloader Some (filename, version)
) else
None
- ) files
+ ) files in
+ (* Fall back to the version in the vmlinuz file name not only if
+ * a candidate pathname couldn't be found under
/lib/modules/,
+ * but also in case the candidate pathname doesn't reference
a
+ * directory. See RHBZ#2175703.
+ *
+ * Note that this "is_dir" check is deliberately kept
outside of
+ * the "find_map"'s mapper function above: we want
the first
+ * candidate *to be* a directory, and not the first candidate
+ * *that is* a directory.
+ *)
+ if not (g#is_dir ~followsymlinks:true modpath) then
+ raise Not_found;
+ modpath, version
with Not_found ->
let version String.sub vmlinuz 14
(String.length vmlinuz - 14) in
let modpath = prefix ^ version in
+ (* Check that the modpath exists. *)
+ if not (g#is_dir ~followsymlinks:true modpath) then
+ raise Not_found;
modpath, version in
- (* Check that the modpath exists. *)
- if not (g#is_dir ~followsymlinks:true modpath) then
- raise Not_found;
-
(* Find the initramfs which corresponds to the kernel.
* Since the initramfs is built at runtime, and doesn't have
* to be covered by the RPM file list, this is basically
Maybe Matching Threads
- [libguestfs-common PATCH 0/2] detect_kernels: deal with RHEL's kernel-core / kernel-modules-core split
- [PATCH v2] v2v: linux: fix kernel detection when split in different packages
- [v2v PATCH 1/3] linux: remove warning for packages with no files
- [PATCH] v2v: linux: Move kernel detection to a separate module.
- [PATCH] v2v: linux: fix kernel detection when split in different packages