1
0
mirror of https://github.com/systemd/systemd synced 2025-11-21 01:34:44 +01:00

Compare commits

..

4 Commits

Author SHA1 Message Date
Mike Yuan
cb1c039fbc
core/service: properly handle freezer action -> watchdog propagation (#39222) 2025-10-14 00:49:12 +02:00
Mike Yuan
4f07ec2b65
core/service: properly handle freezer action -> watchdog propagation
Follow-up for 25178aadb2bd04ef9e63f48c1ef42fb309f9332e
2025-10-06 02:40:01 +02:00
Mike Yuan
b5381d76d5
core/service: drop "cgroup" part of service_cgroup_freezer_action()
This operates on more than cgroup, hence use generic naming,
which also aligns with slice_freezer_action().
2025-10-06 02:40:01 +02:00
Mike Yuan
1cbbb05bc7
unit-def: introduce freezer_state_objective()
No functional change, preparation for later commits.
2025-10-06 02:40:01 +02:00
4 changed files with 36 additions and 12 deletions

View File

@ -144,6 +144,16 @@ FreezerState freezer_state_finish(FreezerState state) {
return freezer_state_finish_table[state];
}
FreezerState freezer_state_objective(FreezerState state) {
FreezerState objective;
objective = freezer_state_finish(state);
if (objective == FREEZER_FROZEN_BY_PARENT)
objective = FREEZER_FROZEN;
return objective;
}
static const char* const unit_marker_table[_UNIT_MARKER_MAX] = {
[UNIT_MARKER_NEEDS_RELOAD] = "needs-reload",
[UNIT_MARKER_NEEDS_RESTART] = "needs-restart",

View File

@ -325,6 +325,7 @@ UnitActiveState unit_active_state_from_string(const char *s) _pure_;
const char* freezer_state_to_string(FreezerState i) _const_;
FreezerState freezer_state_from_string(const char *s) _pure_;
FreezerState freezer_state_finish(FreezerState i) _const_;
FreezerState freezer_state_objective(FreezerState state) _const_;
const char* unit_marker_to_string(UnitMarker m) _const_;
UnitMarker unit_marker_from_string(const char *s) _pure_;

View File

@ -414,7 +414,7 @@ static void service_extend_timeout(Service *s, usec_t extend_timeout_usec) {
static void service_reset_watchdog(Service *s) {
assert(s);
if (freezer_state_finish(UNIT(s)->freezer_state) != FREEZER_RUNNING) {
if (freezer_state_objective(UNIT(s)->freezer_state) != FREEZER_RUNNING) {
log_unit_debug(UNIT(s), "Service is currently %s, skipping resetting watchdog.",
freezer_state_to_string(UNIT(s)->freezer_state));
return;
@ -1425,7 +1425,7 @@ static int service_coldplug(Unit *u) {
(void) unit_setup_exec_runtime(u);
if (IN_SET(s->deserialized_state, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD, SERVICE_RELOAD_SIGNAL, SERVICE_RELOAD_NOTIFY, SERVICE_REFRESH_EXTENSIONS, SERVICE_MOUNTING) &&
freezer_state_finish(u->freezer_state) == FREEZER_RUNNING)
freezer_state_objective(u->freezer_state) == FREEZER_RUNNING)
service_start_watchdog(s);
if (UNIT_ISSET(s->accept_socket)) {
@ -5643,18 +5643,33 @@ int service_determine_exec_selinux_label(Service *s, char **ret) {
return 0;
}
static int service_cgroup_freezer_action(Unit *u, FreezerAction action) {
static int service_freezer_action(Unit *u, FreezerAction action) {
Service *s = ASSERT_PTR(SERVICE(u));
FreezerState old_objective, new_objective;
int r;
old_objective = freezer_state_objective(u->freezer_state);
r = unit_cgroup_freezer_action(u, action);
if (r <= 0)
if (r < 0)
return r;
if (action == FREEZER_FREEZE)
service_stop_watchdog(s);
else if (action == FREEZER_THAW)
service_reset_watchdog(s);
new_objective = freezer_state_objective(u->freezer_state);
/* Note that we cannot trivially check the retval of unit_cgroup_freezer_action() here, since
* that signals whether the operation is ongoing from *kernel's PoV*. If the freeze operation
* is aborted, the frozen attribute of the cgroup would never have been flipped in kernel,
* and unit_cgroup_freezer_action() will happily return 0, yet the watchdog still needs to be reset;
* vice versa. */
if (old_objective != new_objective) {
if (new_objective == FREEZER_FROZEN)
service_stop_watchdog(s);
else if (new_objective == FREEZER_RUNNING)
service_reset_watchdog(s);
else
assert_not_reached();
}
return r;
}
@ -5796,7 +5811,7 @@ const UnitVTable service_vtable = {
.live_mount = service_live_mount,
.can_live_mount = service_can_live_mount,
.freezer_action = service_cgroup_freezer_action,
.freezer_action = service_freezer_action,
.serialize = service_serialize,
.deserialize_item = service_deserialize_item,

View File

@ -6438,9 +6438,7 @@ void unit_next_freezer_state(Unit *u, FreezerAction action, FreezerState *ret_ne
assert_not_reached();
}
objective = freezer_state_finish(next);
if (objective == FREEZER_FROZEN_BY_PARENT)
objective = FREEZER_FROZEN;
objective = freezer_state_objective(next);
assert(IN_SET(objective, FREEZER_RUNNING, FREEZER_FROZEN));
*ret_next = next;