Skip to content

Commit

Permalink
40ignition-ostree: add autosave-xfs transposefs unit
Browse files Browse the repository at this point in the history
Add a new transposefs unit: `autosave-xfs`. This unit runs after
`ignition-disks` and `ignition-ostree-growfs,` but before the `restore`
transposefs unit.

If the XFS root was grown, it checks if the allocation group count
(agcount) is within a reasonable amount (128 is chosen here). If
it isn't, it saves the rootfs and reformats the filesystem. The
`restore` unit will then restore it as usual. In the case of in-place
reprovisioning like LUKS (i.e. where the partition table isn't modified
by the Ignition config), the rootfs is still saved only once.

Ideally, instead of adding a new transposefs unit, we would make it
part of the initial `save` unit. But at that point, there's no way to
tell whether we should autosave without gazing even more deeply into the
Ignition config. We also don't want to unconditionally save the rootfs
when we may not need it.

Closes: coreos/fedora-coreos-tracker#1183
  • Loading branch information
jlebon committed Mar 22, 2023
1 parent 2613d99 commit 8c7d0cc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Expand Up @@ -145,5 +145,6 @@ case "${ROOTFS_TYPE}" in
btrfs) btrfs filesystem resize max ${path} ;;
esac

# this is useful for tests
# The ignition-ostree-transposefs-xfsauto.service unit needs to know if we
# actually run. This is also useful for tests.
touch /run/ignition-ostree-growfs.stamp
@@ -0,0 +1,19 @@
[Unit]
Description=Ignition OSTree: Autosave XFS Rootfs Partition
DefaultDependencies=false
After=ignition-disks.service
# Avoid racing with UUID regeneration
After=ignition-ostree-uuid-root.service
After=ignition-ostree-growfs.service
Before=ignition-ostree-transposefs-restore.service
OnFailure=emergency.target
OnFailureJobMode=isolate

ConditionKernelCommandLine=ostree
# only run if ignition-ostree-growfs ran since that's when pathological cases occur
ConditionPathExists=/run/ignition-ostree-growfs.stamp

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/ignition-ostree-transposefs autosave-xfs
Expand Up @@ -127,6 +127,27 @@ mount_and_save_filesystem_by_label() {
fi
}

# This implements https://github.com/coreos/fedora-coreos-tracker/issues/1183.
should_autosave_rootfs() {
local fstype
fstype=$(lsblk -no FSTYPE "${root_part}")
if [ "$fstype" != xfs ]; then
echo "Filesystem is not XFS (found $fstype); skipping"
return 1
fi
local agcount
eval $(xfs_info "${root_part}" | grep -o 'agcount=[0-9]*')
# Semi-arbitrarily chosen: this is roughly ~64G currently (based on initial
# ag sizing at build time) which seems like a good rootfs size at which to
# discriminate between "throwaway/short-lived systems" and "long-running
# workload systems". It's not like XFS performance is way worse at 128.
if [ "$agcount" -lt 128 ]; then
echo "Filesystem agcount is $agcount; skipping"
return 1
fi
return 0
}

ensure_zram_dev() {
if test -d "${saved_data}"; then
return 0
Expand Down Expand Up @@ -219,6 +240,22 @@ case "${1:-}" in
mkdir "${saved_prep}"
fi
;;
autosave-xfs)
if should_autosave_rootfs; then
wipes_root=1
ensure_zram_dev
# in the in-place reprovisioning case, the rootfs was already saved
if [ ! -d "${saved_root}" ]; then
mkdir "${saved_root}"
echo "Moving rootfs to RAM..."
mount_and_save_filesystem_by_label root "${saved_root}"
print_zram_mm_stat
fi
mkfs.xfs "${root_part}" -L root -f
# for tests
touch /run/ignition-ostree-autosaved-xfs.stamp
fi
;;
save)
# Mounts happen in a private mount namespace since we're not "offically" mounting
if [ -d "${saved_root}" ]; then
Expand Down
Expand Up @@ -28,6 +28,8 @@ install() {
systemd-sysusers \
systemd-tmpfiles \
sort \
xfs_info \
xfs_spaceman \
uniq

if [[ $(uname -m) = s390x ]]; then
Expand Down Expand Up @@ -81,7 +83,7 @@ install() {

inst_multiple jq chattr
inst_script "$moddir/ignition-ostree-transposefs.sh" "/usr/libexec/ignition-ostree-transposefs"
for x in detect save restore; do
for x in detect save autosave-xfs restore; do
install_ignition_unit ignition-ostree-transposefs-${x}.service
done

Expand Down

0 comments on commit 8c7d0cc

Please sign in to comment.