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

Treecompose kernel cleanup #959

Closed
wants to merge 6 commits into from
Closed

Conversation

cgwalters
Copy link
Member

No description provided.

@cgwalters cgwalters changed the title treecompose kernel cleanup WIP: treecompose kernel cleanup Aug 28, 2017
@cgwalters cgwalters added the WIP label Aug 28, 2017
@cgwalters
Copy link
Member Author

Mmm...this is even messier than I thought. Marking WIP.

@cgwalters
Copy link
Member Author

Updated 🆕. There was a lot of internal churn here as I settled on things...there may be some artifacts from intermediate state.

One thing that clearly sucks is:

# ostree --repo=repo-build ls -X fedora/26/x86_64/atomic-host /usr/lib/modules/4.12.8-300.fc26.x86_64/vmlinuz /boot/vmlinuz-4.12.8-300.fc26.x86_64-c28965ed30a8c8d597f21dd47f854147a94720ed821aff6be56af3a4c7d82393 /usr/lib/ostree-boot/vmlinuz-4.12.8-300.fc26.x86_64-c28965ed30a8c8d597f21dd47f854147a94720ed821aff6be56af3a4c7d82393
-00755 0 0 7373400 { [(b'security.selinux', b'system_u:object_r:modules_object_t:s0')] } /usr/lib/modules/4.12.8-300.fc26.x86_64/vmlinuz
-00755 0 0 7373400 { [(b'security.selinux', b'system_u:object_r:boot_t:s0')] } /boot/vmlinuz-4.12.8-300.fc26.x86_64-c28965ed30a8c8d597f21dd47f854147a94720ed821aff6be56af3a4c7d82393
-00755 0 0 7373400 { [(b'security.selinux', b'system_u:object_r:lib_t:s0')] } /usr/lib/ostree-boot/vmlinuz-4.12.8-300.fc26.x86_64-c28965ed30a8c8d597f21dd47f854147a94720ed821aff6be56af3a4c7d82393

This means we now get 3 copies of both the kernel and initramfs due to separate SELinux labels 😿. It's tempting to just do usr_t for all of this.

Anyways, we now with boot_location: both (the default), we inject the kernel in all 3 places; the logic treats the other two as legacy. And /boot is always cloned/updated from /usr/lib/ostree-boot.

@cgwalters
Copy link
Member Author

Folded #927 into this

@cgwalters
Copy link
Member Author

bot, retest this please

@cgwalters cgwalters changed the title WIP: treecompose kernel cleanup Treecompose kernel cleanup Sep 1, 2017
@cgwalters cgwalters removed the WIP label Sep 1, 2017
@cgwalters
Copy link
Member Author

Lifting WIP, should be ready for review 👁.

if (!old_machine_id)
return FALSE;
}
if (strlen (old_machine_id) != 33)
Copy link
Member

Choose a reason for hiding this comment

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

This will segfault in the ENOENT case, right? Seems like this one and the trimming should be under the != NULL check.

int upto_index;
switch (dest)
{
case RPMOSTREE_FINALIZE_KERNEL_AUTO:
Copy link
Member

Choose a reason for hiding this comment

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

This confuses me; don't we always want to put the kernel in /usr/lib/ostree-boot as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes; we do/should - this was more about "update /boot only if we find a kernel there".

Copy link
Member

Choose a reason for hiding this comment

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

Ahh gotcha. OK, the implementation here is really tricky. Can we just drop the loop approach, factor out the unlink & linkat bits and just go through the two locations one at a time? Also, maybe a comment where the enum is declared for AUTO?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, reworked, and fixed some bugs along the way. Also did a git add of a test case I'd written that had been sitting in my tree for a while without me doing a git clean -dfx (lucky!).

We have 3 locations to find kernels now; I can't think of
a reason to support placing kernels *only* in `/boot`.  The
original commit
15ecaac
doesn't give a reason, and I certainly can't think of one now.

This makes `legacy` be an alias for `both`, which should be fully compatible.

Prep for further refactoring towards changing `new` to mean both
`/usr/lib/ostree-boot` *and* `/usr/lib/modules`.
This helped me debug/fix the tests faster.
Prep for changing `boot_location: new` to use `/usr/lib/ostree-boot`
and `/usr/lib/modules`.  Rework our kernel postprocessing
so that we unify the `boot_location` handling with initramfs generation.

Instead of doing the initramfs first in postprocessing, we do it nearly last,
after e.g. `etc` is renamed to `usr/etc`. This has some consequences, such as
the fact that `run_bwrap_mutably()` is now called in both situations. In
general, our handling of `etc` is inconsistent, although understandably so.

As part of this, I finally got around to implementing the bit from
systemd/systemd#4174 however suboptimal it is; need the
unified core so we can cleanly ignore the posttrans like we do others.  We
intentionally keep the file around in the generated tree so that installing a
kernel RPM per client doesn't try to do any of this either.

This all gets folded together so that the logic for handling the bootloader gets
simpler - in the Fedora case, we now know to find kernels in `/usr/lib/modules`
and can ignore `/boot`.
/* Given a @rootfs_dfd and path to kernel/initramfs that live in
* usr/lib/modules/$kver, possibly update @bootdir to use them.
* @bootdir should be one of either /usr/lib/ostree-boot or /boot.
* If @copy_if_not_found is set, we do the copy unconditionally,
Copy link
Member

Choose a reason for hiding this comment

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

The parameter is still called is_auto, though I prefer copy_if_not_found as well. :) Or maybe keep it reversed and name it something like only_if_found?

/* This gets called both by treecompose, where in the non-unified path we just
* have /etc, and in kernel postprocessing where we have usr/etc.
*/
if (fstatat (rootfs_fd, "etc", &stbuf, 0) < 0)
Copy link
Member

Choose a reason for hiding this comment

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

glnx_fstatat_allow_noent ?

if (rebuild_from_initramfs)
bwrap = rpmostree_bwrap_new (rootfs_dfd, RPMOSTREE_BWRAP_IMMUTABLE, error,
"--ro-bind", "/etc", "/etc",
NULL);
else
bwrap = rpmostree_bwrap_new (rootfs_dfd, RPMOSTREE_BWRAP_IMMUTABLE, error,
"--ro-bind", "./usr/etc", "/etc",
Copy link
Member

Choose a reason for hiding this comment

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

Minor/optional: this can just be usr/etc, right? (To be more consistent with other relative bindings we do elsewhere).

return FALSE;

/* If the boot location includes /boot, we also need to copy /usr/lib/ostree-boot there */
switch (boot_location)
Copy link
Member

Choose a reason for hiding this comment

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

This can just be if (boot_location == RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH) right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but I usually like doing an explicit switch over enums so one gets warnings when adding a new case (and down the line we'll probably add a LOCATION_MODULES or so).

@cgwalters
Copy link
Member Author

cgwalters commented Sep 12, 2017

Saw this in testing with initramfs --enable and rebasing:

Generating initramfs... error: linkat: File exists

@jlebon
Copy link
Member

jlebon commented Sep 12, 2017

LGTM! We might have to wait until the CentOS repos settle down though.
@rh-atomic-bot r+ 2974c67

rh-atomic-bot pushed a commit that referenced this pull request Sep 12, 2017
We have 3 locations to find kernels now; I can't think of
a reason to support placing kernels *only* in `/boot`.  The
original commit
15ecaac
doesn't give a reason, and I certainly can't think of one now.

This makes `legacy` be an alias for `both`, which should be fully compatible.

Prep for further refactoring towards changing `new` to mean both
`/usr/lib/ostree-boot` *and* `/usr/lib/modules`.

Closes: #959
Approved by: jlebon
rh-atomic-bot pushed a commit that referenced this pull request Sep 12, 2017
This helped me debug/fix the tests faster.

Closes: #959
Approved by: jlebon
rh-atomic-bot pushed a commit that referenced this pull request Sep 12, 2017
Prep for changing `boot_location: new` to use `/usr/lib/ostree-boot`
and `/usr/lib/modules`.  Rework our kernel postprocessing
so that we unify the `boot_location` handling with initramfs generation.

Instead of doing the initramfs first in postprocessing, we do it nearly last,
after e.g. `etc` is renamed to `usr/etc`. This has some consequences, such as
the fact that `run_bwrap_mutably()` is now called in both situations. In
general, our handling of `etc` is inconsistent, although understandably so.

As part of this, I finally got around to implementing the bit from
systemd/systemd#4174 however suboptimal it is; need the
unified core so we can cleanly ignore the posttrans like we do others.  We
intentionally keep the file around in the generated tree so that installing a
kernel RPM per client doesn't try to do any of this either.

This all gets folded together so that the logic for handling the bootloader gets
simpler - in the Fedora case, we now know to find kernels in `/usr/lib/modules`
and can ignore `/boot`.

Closes: #959
Approved by: jlebon
@rh-atomic-bot
Copy link

⌛ Testing commit 2974c67 with merge 5335b92...

@rh-atomic-bot
Copy link

💔 Test failed - status-atomicjenkins

@cgwalters
Copy link
Member Author

@rh-atomic-bot retry

rh-atomic-bot pushed a commit that referenced this pull request Sep 12, 2017
This helped me debug/fix the tests faster.

Closes: #959
Approved by: jlebon
rh-atomic-bot pushed a commit that referenced this pull request Sep 12, 2017
Prep for changing `boot_location: new` to use `/usr/lib/ostree-boot`
and `/usr/lib/modules`.  Rework our kernel postprocessing
so that we unify the `boot_location` handling with initramfs generation.

Instead of doing the initramfs first in postprocessing, we do it nearly last,
after e.g. `etc` is renamed to `usr/etc`. This has some consequences, such as
the fact that `run_bwrap_mutably()` is now called in both situations. In
general, our handling of `etc` is inconsistent, although understandably so.

As part of this, I finally got around to implementing the bit from
systemd/systemd#4174 however suboptimal it is; need the
unified core so we can cleanly ignore the posttrans like we do others.  We
intentionally keep the file around in the generated tree so that installing a
kernel RPM per client doesn't try to do any of this either.

This all gets folded together so that the logic for handling the bootloader gets
simpler - in the Fedora case, we now know to find kernels in `/usr/lib/modules`
and can ignore `/boot`.

Closes: #959
Approved by: jlebon
@rh-atomic-bot
Copy link

⌛ Testing commit 2974c67 with merge f113fc5...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing f113fc5 to master...

@cgwalters
Copy link
Member Author

This breaks with anaconda UEFI: https://github.com/rhinstaller/anaconda/issues/1188

@cgwalters
Copy link
Member Author

(with boot_location: new i mean)

@cgwalters
Copy link
Member Author

Followup in https://pagure.io/fedora-atomic/issue/94

cgwalters added a commit to cgwalters/selinux-policy-contrib that referenced this pull request Jan 8, 2018
cgwalters added a commit to cgwalters/selinux-policy that referenced this pull request Jan 23, 2018
Moved from: fedora-selinux/selinux-policy-contrib#43

This ensures that hardlinking works with `/usr/share/rpm` (once the
contrib patch to make it `usr_t` is merged too).

See https://bugzilla.redhat.com/show_bug.cgi?id=1526191
coreos/rpm-ostree#959 (comment)
coreos/rpm-ostree#1142
cgwalters added a commit to cgwalters/selinux-policy-contrib that referenced this pull request Jan 23, 2018
wrabcak pushed a commit to fedora-selinux/selinux-policy-contrib that referenced this pull request Jan 24, 2018
wrabcak pushed a commit to fedora-selinux/selinux-policy that referenced this pull request Jan 24, 2018
Moved from: fedora-selinux/selinux-policy-contrib#43

This ensures that hardlinking works with `/usr/share/rpm` (once the
contrib patch to make it `usr_t` is merged too).

See https://bugzilla.redhat.com/show_bug.cgi?id=1526191
coreos/rpm-ostree#959 (comment)
coreos/rpm-ostree#1142
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