Skip to content

Commit

Permalink
!2397 fix cpurt init bug for systemd-cgroup
Browse files Browse the repository at this point in the history
From: @jikai11 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
  • Loading branch information
openeuler-ci-bot authored and gitee-org committed Apr 2, 2024
2 parents 03c1cd8 + fe11b34 commit e45264c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/daemon/common/cgroup/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,18 @@ char *common_convert_cgroup_path(const char *cgroup_path)
return NULL;
}

// for cgroup fs cgroup path, return directly
if (!util_has_suffix(cgroup_path, ".slice")) {
return util_strdup_s(cgroup_path);
}

// for systemd cgroup, cgroup_path should have the form slice:prefix:id,
// convert it to a true path, such as from test-a.slice:isulad:id
// to test.slice/test-a.slice/isulad-id.scope
arr = util_string_split_n(cgroup_path, ':', 3);
if (arr == NULL || util_array_len((const char **)arr) != 3) {
ERROR("Invalid systemd cgroup parent");
// not a systemd cgroup, return cgroup path directly
return util_strdup_s(cgroup_path);
}

// for cgroup fs cgroup path, return directly
if (!util_has_suffix(arr[0], ".slice")) {
ERROR("Invalid systemd cgroup path: %s", cgroup_path);
return NULL;
}

Expand Down
13 changes: 7 additions & 6 deletions src/daemon/executor/container_cb/execution.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,12 @@ static int cpurt_controller_init(const char *id, const host_config *host_spec)
}

if (conf_get_systemd_cgroup()) {
// currently it is the same as docker, yet it is unclear that
// if systemd cgroup is used and cgroup parent is set to a slice rather than system.slice
// should iSulad set cpu.rt_runtime_us and cpu.rt_period_us for the parent path?
// in fact, even if system.slice is used,
// cpu.rt_runtime_us and cpu.rt_period_us might still needed to be set manually
__isula_auto_free char *converted_cgroup = common_convert_cgroup_path(cgroups_path);
if (converted_cgroup == NULL) {
ERROR("Failed to convert cgroup path");
return -1;
}

__isula_auto_free char *init_cgroup = common_get_init_cgroup_path("cpu");
if (init_cgroup == NULL) {
ERROR("Failed to get init cgroup");
Expand All @@ -452,7 +453,7 @@ static int cpurt_controller_init(const char *id, const host_config *host_spec)
ERROR("Failed to get own cgroup");
return -1;
}
char *new_cgroups_path = util_path_join(init_cgroup, cgroups_path);
char *new_cgroups_path = util_path_join(init_cgroup, converted_cgroup);
if (new_cgroups_path == NULL) {
ERROR("Failed to join path");
return -1;
Expand Down

0 comments on commit e45264c

Please sign in to comment.