Skip to content

Commit

Permalink
cgroup: do 'catchup' for unit cgroup inotify watch files
Browse files Browse the repository at this point in the history
While reexec/reload, we drop the inotify watch on cgroup file(s), so
we need to re-check them in case they changed and we missed the event.

Fixes: #20198
  • Loading branch information
Dan Streetman committed Jul 14, 2021
1 parent 534b5ab commit cdbfddc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,9 @@ static int unit_check_cgroup_events(Unit *u) {

assert(u);

if (!u->cgroup_path)
return 0;

r = cg_get_keyed_attribute_graceful(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, "cgroup.events",
STRV_MAKE("populated", "frozen"), values);
if (r < 0)
Expand Down Expand Up @@ -3863,6 +3866,21 @@ void unit_invalidate_cgroup_bpf(Unit *u) {
}
}

void unit_cgroup_catchup(Unit *u) {
assert(u);

if (!UNIT_HAS_CGROUP_CONTEXT(u))
return;

/* We dropped the inotify watch during reexec/reload, so we need to
* check these as they may have changed.
* Note that (currently) the kernel doesn't actually update cgroup
* file modification times, so we can't just serialize and then check
* the mtime for file(s) we are interested in. */
(void) unit_check_cgroup_events(u);
(void) unit_check_oom(u);
}

bool unit_cgroup_delegate(Unit *u) {
CGroupContext *c;

Expand Down
2 changes: 2 additions & 0 deletions src/core/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ void manager_invalidate_startup_units(Manager *m);
const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;

void unit_cgroup_catchup(Unit *u);

bool unit_cgroup_delegate(Unit *u);

int compare_job_priority(const void *a, const void *b);
Expand Down
2 changes: 2 additions & 0 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3611,6 +3611,8 @@ void unit_catchup(Unit *u) {

if (UNIT_VTABLE(u)->catchup)
UNIT_VTABLE(u)->catchup(u);

unit_cgroup_catchup(u);
}

static bool fragment_mtime_newer(const char *path, usec_t mtime, bool path_masked) {
Expand Down

0 comments on commit cdbfddc

Please sign in to comment.