Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Get the kernel version from the kernel path #4038

Merged
merged 1 commit into from
Sep 29, 2022

Conversation

akihikodaki
Copy link
Contributor

Before commit 80bb67c, rpm-ostree required there is only one directory in /usr/lib/modules and the directory represents the installed kernel. However, it was revealed that 3rd-party RPMs can have pre-built modules for several kernel versions, and the requirement prevented from installing them. The commit was intended to solve the problem by ignoring directories which do not contain a file named vmlinuz.

However, the upstream kernel actually produces RPMs without vmlinuz in /usr/lib/modules, and the logic introduced by the commit prevented them from being installed.

This change replaces the logic with yet another alternative that retrieves the kernel version from the kernel file name in the boot directory. The kernel version can be used to identify the kernel module directory without requiring that there is only one directory in /usr/lib/modules or that the directory contains vmlinuz.

An old comment in find_kernel_and_initramfs_in_bootdir says the kernel installed in Fedora 23 does not contain the version in the path, but it should not be a problem; looking at the source code, the path has always contained the version since Fedora 12.

@openshift-ci
Copy link

openshift-ci bot commented Sep 24, 2022

Hi @akihikodaki. Thanks for your PR.

I'm waiting for a coreos member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cgwalters
Copy link
Member

However, the upstream kernel actually produces RPMs ...

Ah, neat. I am really happy to help the workflow of testing out direct local/upstream kernel builds. Supporting the upstream RPM flow is great. I'd eventually like to take it a step farther and support directly adding a local kernel build without going through RPM at all (it's silly and inefficient to make a compressed RPM, only to immediately decompress it to install).

That said though...hmm, ideally we could convince the upstream mkspec flow to do what the Fedora kernel package does and ship the vmlinuz in /usr/lib/modules.

(I had to go look, the relevant code is https://github.com/torvalds/linux/blob/master/scripts/package/mkspec for reference)

Anyways on the actual code changes here...it's not at all your fault but this code was a mess before...I'd been actually planning to replace it with https://github.com/ostreedev/ostree-rs-ext/blob/main/lib/src/bootabletree.rs relatively soon.

without vmlinuz in /usr/lib/modules

So what's going on here I believe is we're moving the files from /boot/vmlinuz into /usr/lib/ostree-boot/vmlinuz. I think it might be cleaner to "canonicalize" this instead in a first pass by moving it into the corresponding modules directory or so?

(Not opposed to merging this patch as is to be clear)

Also thank you so much for the contribution!

@akihikodaki
Copy link
Contributor Author

@cgwalters I believe that "canonicalization" actually happens. That's why I left the logic to find the kernel in rpmostree_kernel_remove as is.

return glnx_throw (error, "Multiple vmlinuz- in %s", bootdir);
return glnx_throw (error, "Multiple vmlinuz%s in %s", out_ksuffix ? "-" : "", bootdir);
if (out_ksuffix)
ret_ksuffix = g_strdup (name + (sizeof ("vmlinuz-") - 1));
Copy link
Member

@cgwalters cgwalters Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd spell this as just strlen ("vmlinuz-") which is less obscure; sizeof ("vmlinuz-") - 1 requires C programmers to remember that sizeof includes the NUL character and you're subtracting it off. strlen will be constant folded by all decent compilers in the same way as sizeof.

@lucab
Copy link
Contributor

lucab commented Sep 28, 2022

/ok-to-test

Before commit 80bb67c, rpm-ostree
required there is only one directory in /usr/lib/modules and the
directory represents the installed kernel. However, it was revealed that
3rd-party RPMs can have pre-built modules for several kernel versions,
and the requirement prevented from installing them. The commit was
intended to solve the problem by ignoring directories which do not
contain a file named vmlinuz.

However, the upstream kernel actually produces RPMs without vmlinuz in
/usr/lib/modules, and the logic introduced by the commit prevented them
from being installed.

This change replaces the logic with yet another alternative that
retrieves the kernel version from the kernel file name in the boot
directory. The kernel version can be used to identify the kernel module
directory without requiring that there is only one directory in
/usr/lib/modules or that the directory contains vmlinuz.

An old comment in find_kernel_and_initramfs_in_bootdir says the kernel
installed in Fedora 23 does not contain the version in the path, but
it should not be a problem; looking at the source code, the path
has always contained the version since Fedora 12.
Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some lingering uncertainty about this because it's complex code and we don't have unit tests directly covering it, but we do cover all this in integration tests - our CI is pretty good here.

I'd still like to move this logic to Rust at some point soon.

At some point we can look at adding an upstream-built kernel RPM to our CI flow.

Thanks again for the patch!

@cgwalters cgwalters merged commit c2cd14f into coreos:main Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants