-
Notifications
You must be signed in to change notification settings - Fork 305
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
Sysroot auto cleanup #2511
base: main
Are you sure you want to change the base?
Sysroot auto cleanup #2511
Changes from all commits
0be7ef4
d32dd29
85dc35d
951d5d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright © 2022 Endless OS Foundation LLC | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2 of the License, or (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
[Unit] | ||
Description=OSTree Automatic Sysroot Cleanup | ||
Documentation=man:ostree-admin-cleanup(1) | ||
ConditionPathExists=/sysroot/.cleanup | ||
|
||
# We want this to be triggered by multi-user.target but not block it via | ||
# the default After added to target units since pruning the repo can be | ||
# slow. See the Default Dependencies sections in systemd.service(5) and | ||
# systemd.target(5). | ||
DefaultDependencies=no | ||
Requires=sysinit.target | ||
After=sysinit.target basic.target | ||
Conflicts=shutdown.target | ||
Before=shutdown.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStop=/usr/bin/ostree admin cleanup --auto | ||
ProtectSystem=strict | ||
ReadWritePaths=/sysroot /boot | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I like this. But don't we also have to touch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that happens when finalizing a deployment, not when cleaning up. See the comments in Over in endlessm/eos-updater#298 @wjt pointed out that having |
||
|
||
# This will be allowed to run in the background, so try to make it less | ||
# disruptive while it prunes the repo. | ||
IOSchedulingClass=idle | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,17 @@ | |
- uncomment the include in Makefile-libostree.am | ||
*/ | ||
|
||
LIBOSTREE_2022.2 { | ||
global: | ||
ostree_sysroot_auto_cleanup; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New public API feels overkill for this if the expectation is that it will be invoked by a separate systemd unit. Related below: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this was with an eye toward having the systemd unit disabled and letting the management daemon handle it itself. But I did do this in endlessm/eos-updater#298 without needing the API. I do think it's cleaner to have the semantics contained within libostree, though. |
||
} LIBOSTREE_2021.5; | ||
|
||
/* Stub section for the stable release *after* this development one; don't | ||
* edit this other than to update the year. This is just a copy/paste | ||
* source. Replace $LASTSTABLE with the last stable version, and $NEWVERSION | ||
* with whatever the next version with new symbols will be. | ||
LIBOSTREE_2021.$NEWVERSION { | ||
LIBOSTREE_2022.$NEWVERSION { | ||
global: | ||
someostree_symbol_deleteme; | ||
} LIBOSTREE_2021.$LASTSTABLE; | ||
} LIBOSTREE_2022.$LASTSTABLE; | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -555,6 +555,48 @@ ostree_sysroot_cleanup (OstreeSysroot *self, | |
return _ostree_sysroot_cleanup_internal (self, TRUE, cancellable, error); | ||
} | ||
|
||
/** | ||
* ostree_sysroot_auto_cleanup: | ||
* @self: Sysroot | ||
* @out_cleaned: (out): Whether a cleanup was performed | ||
* @cancellable: Cancellable | ||
* @error: Error | ||
* | ||
* Cleanup @self when needed. Whether to cleanup or not is determined by | ||
* the presence of the .cleanup file in the sysroot. When the .cleanup | ||
* file exists, ostree_sysroot_cleanup() will be called and the file | ||
* will be removed if it is successful. | ||
* | ||
* Locking: exclusive | ||
* Since: 2022.2 | ||
*/ | ||
gboolean | ||
ostree_sysroot_auto_cleanup (OstreeSysroot *self, | ||
gboolean *out_cleaned, | ||
GCancellable *cancellable, | ||
GError **error) | ||
{ | ||
struct stat stbuf; | ||
if (!glnx_fstatat_allow_noent (self->sysroot_fd, _OSTREE_SYSROOT_AUTOCLEANUP, &stbuf, AT_SYMLINK_NOFOLLOW, error)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the systemd unit is already doing this, do we need a new API at all versus simply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not. I think you could do this all in the CLI or via systemd unit settings. It felt cleaner to encapsulate it in libostree, but it's not necessary. I could go either way. |
||
return FALSE; | ||
if (errno == ENOENT) | ||
{ | ||
g_debug ("Did not find %s in sysroot; skipping auto cleanup", _OSTREE_SYSROOT_AUTOCLEANUP); | ||
return TRUE; | ||
} | ||
|
||
if (!ostree_sysroot_cleanup (self, cancellable, error)) | ||
return FALSE; | ||
|
||
if (!ot_ensure_unlinked_at (self->sysroot_fd, _OSTREE_SYSROOT_AUTOCLEANUP, error)) | ||
return FALSE; | ||
|
||
if (out_cleaned != NULL) | ||
*out_cleaned = TRUE; | ||
|
||
return TRUE; | ||
} | ||
|
||
/** | ||
* ostree_sysroot_prepare_cleanup: | ||
* @self: Sysroot | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, we do something similar, but with the condition inverted:
This made migration easier. If you're upgrading ostree with the deploy then the old version of ostree won't know to create this file, so when booting into the new deployment cleaning won't run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a nice property. However, doesn't that mean you're running a prune on every boot, even if you haven't made a new deployment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we delete .ostree-cleaned only just before ostree admin deploy.