[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@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
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@redhat.com> Tested-by: Vera Wu <vwu@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
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@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Vera Wu <vwu@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
For the series, since this is a straight backport of the upstream patch with the filenames changed: Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Looks like we're going to do this as a 0-day z-stream backport? You are assignee so I'll leave it alone unless you need any help with it. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com nbdkit - Flexible, fast NBD server with plugins https://gitlab.com/nbdkit/nbdkit
On 4/6/23 09:39, Richard W.M. Jones wrote:
For the series, since this is a straight backport of the upstream patch with the filenames changed:
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
I've committed these patches as e7aa456e26e5 and 9449d21eeae8 respectively, on the rhel-9.2 branch. I've rebased (non-fast-forwardably) the same branch, in order to keep the "RHEL*" patches clustered near HEAD, as follows: 1: e8c61da73b62 = 1: e8c61da73b62 Translated using Weblate (Ukrainian) 2: fd9694a3a2ea = 2: fd9694a3a2ea convert: windows: Remove extraneous blank lines in source 3: 9a5c900fdb53 = 3: 9a5c900fdb53 convert: windows: Document what copy_qemu_ga function returns 4: 48f15935cff5 = 4: 48f15935cff5 convert: windows: Remove unused 'open Utils' 5: 4623b2aab891 = 5: 4623b2aab891 -o kubevirt: Fix mistake in error message 6: 6b7ef3efe748 = 6: 6b7ef3efe748 -o kubevirt: Move "cpu" element under "domain" 7: 8009825c3963 = 7: 8009825c3963 -o kubevirt: Error on invalid output guest names 8: bcd60820de12 = 8: bcd60820de12 Split long lines in messages 9: 64a86bb9ef02 = 9: 64a86bb9ef02 -o kubevirt: Implement -oo compressed for qcow2 files 10: 8802e8b4135c = 10: 8802e8b4135c v2v: Remove use of ~anchored 11: 628ee708464e = 11: 628ee708464e -o kubevirt: Replace PCRE ~anchored with ^...$ 12: a9630d3981cb = 12: a9630d3981cb -o libvirt: Add correct xmlns:libosinfo for Rocky Linux 13: 227313ca73d2 = 13: 227313ca73d2 convert: linux: Require host cpu for all RHEL-alike >= 9 -: ------------ > 14: e7aa456e26e5 detect_kernels: tighten "try" scope -: ------------ > 15: 9449d21eeae8 detect_kernels: deal with RHEL's kernel-core / kernel-modules-core split 14: 6633c5ca0fe4 = 16: da3ae25bdd18 RHEL: v2v: Select correct qemu binary for -o qemu mode (RHBZ#1147313). 15: cf636bf489fd = 17: b638c2083ee9 RHEL: v2v: Disable the --qemu-boot / -oo qemu-boot option (RHBZ#1147313). 16: a4ed97d92b38 = 18: d8a6a0577f0a RHEL: Fix list of supported sound cards to match RHEL qemu (RHBZ#1176493). 17: ef9a020874b8 = 19: 94f4aaeea12a RHEL: Fixes for libguestfs-winsupport. 18: 5703bf73a706 = 20: ffcd5358b8f6 RHEL: v2v: -i disk: force VNC as display (RHBZ#1372671) 19: 4cc16f9bdf58 = 21: 907b8c0f9f0a RHEL: v2v: do not mention SUSE Xen hosts (RHBZ#1430203) 20: f00e06aecd8e = 22: ee2bf7286e96 RHEL: point to KB for supported v2v hypervisors/guests 21: 5ef909eb4d65 = 23: 2d85522fe7b0 RHEL: Disable -o glance 22: ade0fd71c59b = 24: 8fbfb57de81e RHEL: Remove the --in-place option 23: d6fc11c3f99f = 25: b04577d80b89 RHEL 9: -oo compressed: Remove nbdcopy version check and test 24: 86517b17be98 = 26: 462f9b9eb810 RHEL 9: tests: Remove btrfs test The test suite passes at 462f9b9eb810. Thanks! Laszlo
participants (2)
-
Laszlo Ersek -
Richard W.M. Jones