core/cgroup: drop cgroup v1 specific code in unit_update_cgroup()
This commit is contained in:
+12
-62
@@ -2174,31 +2174,6 @@ void unit_invalidate_cgroup_members_masks(Unit *u) {
|
||||
unit_invalidate_cgroup_members_masks(slice);
|
||||
}
|
||||
|
||||
const char* unit_get_realized_cgroup_path(Unit *u, CGroupMask mask) {
|
||||
|
||||
/* Returns the realized cgroup path of the specified unit where all specified controllers are available. */
|
||||
|
||||
while (u) {
|
||||
CGroupRuntime *crt = unit_get_cgroup_runtime(u);
|
||||
if (crt &&
|
||||
crt->cgroup_path &&
|
||||
crt->cgroup_realized &&
|
||||
FLAGS_SET(crt->cgroup_realized_mask, mask))
|
||||
return crt->cgroup_path;
|
||||
|
||||
u = UNIT_GET_SLICE(u);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *migrate_callback(CGroupMask mask, void *userdata) {
|
||||
/* If not realized at all, migrate to root ("").
|
||||
* It may happen if we're upgrading from older version that didn't clean up.
|
||||
*/
|
||||
return strempty(unit_get_realized_cgroup_path(userdata, mask));
|
||||
}
|
||||
|
||||
int unit_default_cgroup_path(const Unit *u, char **ret) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
@@ -2415,8 +2390,7 @@ static int unit_update_cgroup(
|
||||
CGroupMask enable_mask,
|
||||
ManagerState state) {
|
||||
|
||||
bool created, is_root_slice;
|
||||
CGroupMask migrate_mask = 0;
|
||||
bool created;
|
||||
_cleanup_free_ char *cgroup_full_path = NULL;
|
||||
int r;
|
||||
|
||||
@@ -2441,27 +2415,23 @@ static int unit_update_cgroup(
|
||||
return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", empty_to_root(crt->cgroup_path));
|
||||
created = r;
|
||||
|
||||
if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0) {
|
||||
uint64_t cgroup_id = 0;
|
||||
uint64_t cgroup_id = 0;
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_full_path);
|
||||
if (r == 0) {
|
||||
r = cg_path_get_cgroupid(cgroup_full_path, &cgroup_id);
|
||||
if (r < 0)
|
||||
log_unit_full_errno(u, ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to get cgroup ID of cgroup %s, ignoring: %m", cgroup_full_path);
|
||||
} else
|
||||
log_unit_warning_errno(u, r, "Failed to get full cgroup path on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path));
|
||||
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_full_path);
|
||||
if (r == 0) {
|
||||
r = cg_path_get_cgroupid(cgroup_full_path, &cgroup_id);
|
||||
if (r < 0)
|
||||
log_unit_full_errno(u, ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to get cgroup ID of cgroup %s, ignoring: %m", cgroup_full_path);
|
||||
} else
|
||||
log_unit_warning_errno(u, r, "Failed to get full cgroup path on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path));
|
||||
|
||||
crt->cgroup_id = cgroup_id;
|
||||
}
|
||||
crt->cgroup_id = cgroup_id;
|
||||
|
||||
/* Start watching it */
|
||||
(void) unit_watch_cgroup(u);
|
||||
(void) unit_watch_cgroup_memory(u);
|
||||
|
||||
/* For v2 we preserve enabled controllers in delegated units, adjust others,
|
||||
* for v1 we figure out which controller hierarchies need migration. */
|
||||
/* For v2 we preserve enabled controllers in delegated units, adjust others, */
|
||||
if (created || !crt->cgroup_realized || !unit_cgroup_delegate(u)) {
|
||||
CGroupMask result_mask = 0;
|
||||
|
||||
@@ -2472,32 +2442,12 @@ static int unit_update_cgroup(
|
||||
|
||||
/* Remember what's actually enabled now */
|
||||
crt->cgroup_enabled_mask = result_mask;
|
||||
|
||||
migrate_mask = crt->cgroup_realized_mask ^ target_mask;
|
||||
}
|
||||
|
||||
/* Keep track that this is now realized */
|
||||
crt->cgroup_realized = true;
|
||||
crt->cgroup_realized_mask = target_mask;
|
||||
|
||||
/* Migrate processes in controller hierarchies both downwards (enabling) and upwards (disabling).
|
||||
*
|
||||
* Unnecessary controller cgroups are trimmed (after emptied by upward migration).
|
||||
* We perform migration also with whole slices for cases when users don't care about leave
|
||||
* granularity. Since delegated_mask is subset of target mask, we won't trim slice subtree containing
|
||||
* delegated units.
|
||||
*/
|
||||
if (cg_all_unified() == 0) {
|
||||
r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, crt->cgroup_path, migrate_callback, u);
|
||||
if (r < 0)
|
||||
log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", empty_to_root(crt->cgroup_path));
|
||||
|
||||
is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE);
|
||||
r = cg_trim_v1_controllers(u->manager->cgroup_supported, ~target_mask, crt->cgroup_path, !is_root_slice);
|
||||
if (r < 0)
|
||||
log_unit_warning_errno(u, r, "Failed to delete controller cgroups %s, ignoring: %m", empty_to_root(crt->cgroup_path));
|
||||
}
|
||||
|
||||
/* Set attributes */
|
||||
cgroup_context_apply(u, target_mask, state);
|
||||
cgroup_xattr_apply(u);
|
||||
|
||||
@@ -407,7 +407,6 @@ void unit_invalidate_cgroup_members_masks(Unit *u);
|
||||
|
||||
void unit_add_family_to_cgroup_realize_queue(Unit *u);
|
||||
|
||||
const char* unit_get_realized_cgroup_path(Unit *u, CGroupMask mask);
|
||||
int unit_default_cgroup_path(const Unit *u, char **ret);
|
||||
int unit_set_cgroup_path(Unit *u, const char *path);
|
||||
int unit_pick_cgroup_path(Unit *u);
|
||||
|
||||
Reference in New Issue
Block a user