cgroup-util: when attaching/creating cgroups in multiple hierarchies, take jointly mounted controlelrs into account
If we create a cgroup in one controller it might already have been created in another too, if we have jointly mounted controllers. Take that into consideration.
This commit is contained in:
parent
fae9bc298a
commit
e353faa0d6
|
@ -2110,6 +2110,7 @@ done:
|
||||||
|
|
||||||
int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path) {
|
int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path) {
|
||||||
CGroupController c;
|
CGroupController c;
|
||||||
|
CGroupMask done;
|
||||||
bool created;
|
bool created;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -2134,20 +2135,28 @@ int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
return created;
|
return created;
|
||||||
|
|
||||||
|
supported &= CGROUP_MASK_V1;
|
||||||
|
mask = CGROUP_MASK_EXTEND_JOINED(mask);
|
||||||
|
done = 0;
|
||||||
|
|
||||||
/* Otherwise, do the same in the other hierarchies */
|
/* Otherwise, do the same in the other hierarchies */
|
||||||
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
||||||
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
||||||
const char *n;
|
const char *n;
|
||||||
|
|
||||||
if (!FLAGS_SET(CGROUP_MASK_V1, bit))
|
if (!FLAGS_SET(supported, bit))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (FLAGS_SET(done, bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
n = cgroup_controller_to_string(c);
|
n = cgroup_controller_to_string(c);
|
||||||
|
|
||||||
if (FLAGS_SET(mask, bit))
|
if (FLAGS_SET(mask, bit))
|
||||||
(void) cg_create(n, path);
|
(void) cg_create(n, path);
|
||||||
else if (FLAGS_SET(supported, bit))
|
else
|
||||||
(void) cg_trim(n, path, true);
|
(void) cg_trim(n, path, true);
|
||||||
|
|
||||||
|
done |= CGROUP_MASK_EXTEND_JOINED(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return created;
|
return created;
|
||||||
|
@ -2155,6 +2164,7 @@ int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path
|
||||||
|
|
||||||
int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid, cg_migrate_callback_t path_callback, void *userdata) {
|
int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid, cg_migrate_callback_t path_callback, void *userdata) {
|
||||||
CGroupController c;
|
CGroupController c;
|
||||||
|
CGroupMask done;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid);
|
r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid);
|
||||||
|
@ -2167,23 +2177,26 @@ int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid, cg_m
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
supported &= CGROUP_MASK_V1;
|
||||||
|
done = 0;
|
||||||
|
|
||||||
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
||||||
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
||||||
const char *p = NULL;
|
const char *p = NULL;
|
||||||
|
|
||||||
if (!FLAGS_SET(CGROUP_MASK_V1, bit))
|
if (!FLAGS_SET(supported, bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!FLAGS_SET(supported, bit))
|
if (FLAGS_SET(done, bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (path_callback)
|
if (path_callback)
|
||||||
p = path_callback(bit, userdata);
|
p = path_callback(bit, userdata);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
p = path;
|
p = path;
|
||||||
|
|
||||||
(void) cg_attach_fallback(cgroup_controller_to_string(c), p, pid);
|
(void) cg_attach_fallback(cgroup_controller_to_string(c), p, pid);
|
||||||
|
done |= CGROUP_MASK_EXTEND_JOINED(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2208,6 +2221,7 @@ int cg_attach_many_everywhere(CGroupMask supported, const char *path, Set* pids,
|
||||||
|
|
||||||
int cg_migrate_everywhere(CGroupMask supported, const char *from, const char *to, cg_migrate_callback_t to_callback, void *userdata) {
|
int cg_migrate_everywhere(CGroupMask supported, const char *from, const char *to, cg_migrate_callback_t to_callback, void *userdata) {
|
||||||
CGroupController c;
|
CGroupController c;
|
||||||
|
CGroupMask done;
|
||||||
int r = 0, q;
|
int r = 0, q;
|
||||||
|
|
||||||
if (!path_equal(from, to)) {
|
if (!path_equal(from, to)) {
|
||||||
|
@ -2222,30 +2236,34 @@ int cg_migrate_everywhere(CGroupMask supported, const char *from, const char *to
|
||||||
if (q > 0)
|
if (q > 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
supported &= CGROUP_MASK_V1;
|
||||||
|
done = 0;
|
||||||
|
|
||||||
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
||||||
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
||||||
const char *p = NULL;
|
const char *p = NULL;
|
||||||
|
|
||||||
if (!FLAGS_SET(CGROUP_MASK_V1, bit))
|
if (!FLAGS_SET(supported, bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!FLAGS_SET(supported, bit))
|
if (FLAGS_SET(done, bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (to_callback)
|
if (to_callback)
|
||||||
p = to_callback(bit, userdata);
|
p = to_callback(bit, userdata);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
p = to;
|
p = to;
|
||||||
|
|
||||||
(void) cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, cgroup_controller_to_string(c), p, 0);
|
(void) cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, cgroup_controller_to_string(c), p, 0);
|
||||||
|
done |= CGROUP_MASK_EXTEND_JOINED(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) {
|
int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) {
|
||||||
CGroupController c;
|
CGroupController c;
|
||||||
|
CGroupMask done;
|
||||||
int r, q;
|
int r, q;
|
||||||
|
|
||||||
r = cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root);
|
r = cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root);
|
||||||
|
@ -2258,19 +2276,23 @@ int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root)
|
||||||
if (q > 0)
|
if (q > 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
supported &= CGROUP_MASK_V1;
|
||||||
|
done = 0;
|
||||||
|
|
||||||
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
||||||
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
|
||||||
|
|
||||||
if (!FLAGS_SET(CGROUP_MASK_V1, bit))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!FLAGS_SET(supported, bit))
|
if (!FLAGS_SET(supported, bit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (FLAGS_SET(done, bit))
|
||||||
|
continue;
|
||||||
|
|
||||||
(void) cg_trim(cgroup_controller_to_string(c), path, delete_root);
|
(void) cg_trim(cgroup_controller_to_string(c), path, delete_root);
|
||||||
|
done |= CGROUP_MASK_EXTEND_JOINED(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cg_mask_to_string(CGroupMask mask, char **ret) {
|
int cg_mask_to_string(CGroupMask mask, char **ret) {
|
||||||
|
|
Loading…
Reference in New Issue