]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/core/scope.c
core: Rework recursive freeze/thaw
authorAdrian Vovk <adrianvovk@gmail.com>
Sun, 21 Jan 2024 20:05:20 +0000 (15:05 -0500)
committerAdrian Vovk <adrianvovk@gmail.com>
Tue, 30 Jan 2024 16:18:15 +0000 (11:18 -0500)
commit16b6af6adefa4068b10e1a04f46fc895cb9a3af7
tree457de2dafad6d6d4672dfd867f2cb6c4bca2f5fd
parent720c618397397f958caeb050a1528eb0d6f7a4a6
core: Rework recursive freeze/thaw

This commit overhauls the way freeze/thaw works recursively:

First, it introduces new FreezerActions that are like the existing
FREEZE and THAW but indicate that the action was initiated by a parent
unit. We also refactored the code to pass these FreezerActions through
the whole call stack so that we can make use of them. FreezerState was
extended similarly, to be able to differentiate between a unit that's
frozen manually and a unit that's frozen because a parent is frozen.

Next, slices were changed to check recursively that all their child
units can be frozen before it attempts to freeze them. This is different
from the previous behavior, that would just check if the unit's type
supported freezing at all. This cleans up the code, and also ensures
that the behavior of slices corresponds to the unit's actual ability
to be frozen

Next, we make it so that if you FREEZE a slice, it'll PARENT_FREEZE
all of its children. Similarly, if you THAW a slice it will PARENT_THAW
its children.

Finally, we use the new states available to us to refactor the code
that actually does the cgroup freezing. The code now looks at the unit's
existing freezer state and the action being requested, and decides what
next state is most appropriate. Then it puts the unit in that state.
For instance, a RUNNING unit with a request to PARENT_FREEZE will
put the unit into the PARENT_FREEZING state. As another example, a
FROZEN unit who's parent is also FROZEN will transition to
PARENT_FROZEN in response to a request to THAW.

Fixes https://github.com/systemd/systemd/issues/30640
Fixes https://github.com/systemd/systemd/issues/15850
src/basic/unit-def.c
src/basic/unit-def.h
src/core/cgroup.c
src/core/cgroup.h
src/core/dbus-unit.c
src/core/scope.c
src/core/service.c
src/core/slice.c
src/core/unit.c
src/core/unit.h
test/units/testsuite-38.sh