summaryrefslogtreecommitdiff
path: root/0041-fix-cpurt-init-bug-for-systemd-cgroup.patch
blob: 1f5e9eb344d2974164cce7272b59506b57855d3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
From fe11b34a3c2843ea2198b310160b182d63aeb63b Mon Sep 17 00:00:00 2001
From: jikai <jikai11@huawei.com>
Date: Tue, 2 Apr 2024 11:22:09 +0800
Subject: [PATCH 41/69] fix cpurt init bug for systemd-cgroup

Signed-off-by: jikai <jikai11@huawei.com>
---
 src/daemon/common/cgroup/cgroup.c            | 13 +++++++------
 src/daemon/executor/container_cb/execution.c | 13 +++++++------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/daemon/common/cgroup/cgroup.c b/src/daemon/common/cgroup/cgroup.c
index d3f1445a..007dbb70 100644
--- a/src/daemon/common/cgroup/cgroup.c
+++ b/src/daemon/common/cgroup/cgroup.c
@@ -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;
     }
 
diff --git a/src/daemon/executor/container_cb/execution.c b/src/daemon/executor/container_cb/execution.c
index 88c6b354..4bf3621d 100644
--- a/src/daemon/executor/container_cb/execution.c
+++ b/src/daemon/executor/container_cb/execution.c
@@ -435,11 +435,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");
@@ -451,7 +452,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;
-- 
2.34.1