summaryrefslogtreecommitdiff
path: root/0002-Add-unified-memory_swap_limit_in_bytes-fields-into-C.patch
blob: b492de19dd80e4ab155c02dce452171321438c9f (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
From 27c3d00f74c5641685d5781fe0c02c5eead92d23 Mon Sep 17 00:00:00 2001
From: "ilya.kuksenok" <ilya.kuksenok@huawei.com>
Date: Thu, 2 Feb 2023 14:41:16 +0300
Subject: [PATCH 02/53] Add unified, memory_swap_limit_in_bytes fields into
 ContainerStats; add unified and memory_swap_limit_in_bytes into
 UpdateCreateConfig add nullptr for unified.

---
 src/daemon/common/sysinfo.c                   |  3 +-
 .../cri/cri_container_manager_service.cc      | 19 ++++++++++++
 src/daemon/entry/cri/cri_helpers.cc           | 17 ++++++++++-
 src/daemon/modules/runtime/runtime.c          | 30 +++++++++----------
 4 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c
index 8b5768db..38416db4 100644
--- a/src/daemon/common/sysinfo.c
+++ b/src/daemon/common/sysinfo.c
@@ -743,7 +743,8 @@ static void check_cgroup_mem(struct layer **layers, bool quiet, cgroup_mem_info_
         return;
     }
 
-    meminfo->limit = true;
+    meminfo->limit = cgroup_enabled(mountpoint, CGROUP_MEMORY_LIMIT);
+    cgroup_do_log(quiet, !(meminfo->limit), "Your kernel does not support memory limit");
 
     meminfo->swap = cgroup_enabled(mountpoint, CGROUP_MEMORY_SWAP);
     cgroup_do_log(quiet, !(meminfo->swap), "Your kernel does not support swap memory limit");
diff --git a/src/daemon/entry/cri/cri_container_manager_service.cc b/src/daemon/entry/cri/cri_container_manager_service.cc
index d2f486cf..d044cca8 100644
--- a/src/daemon/entry/cri/cri_container_manager_service.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service.cc
@@ -1084,6 +1084,12 @@ void ContainerManagerService::UpdateContainerResources(const std::string &contai
     struct parser_context ctx {
         OPT_GEN_SIMPLIFY, 0
     };
+    json_map_string_string *unified = nullptr;
+    unified = (json_map_string_string *)util_common_calloc_s(sizeof(json_map_string_string));
+    if (unified == nullptr) {
+        error.SetError("Out of memory");
+        goto cleanup;
+    }
     request = (container_update_request *)util_common_calloc_s(sizeof(container_update_request));
     if (request == nullptr) {
         error.SetError("Out of memory");
@@ -1100,6 +1106,18 @@ void ContainerManagerService::UpdateContainerResources(const std::string &contai
     hostconfig->cpu_period = resources.cpu_period();
     hostconfig->cpu_quota = resources.cpu_quota();
     hostconfig->cpu_shares = resources.cpu_shares();
+    hostconfig->memory_swap_limit_in_bytes = resources.memory_swap_limit_in_bytes();
+
+    if (!resources.unified().empty()) {
+        for (auto &iter : resources.unified()) {
+            if (append_json_map_string_string(unified, iter.first.c_str(), iter.second.c_str()) != 0) {
+                error.SetError("Failed to append string");
+                goto cleanup;
+            }
+        }
+    }
+    hostconfig->unified = unified;
+    unified = nullptr;
     hostconfig->memory = resources.memory_limit_in_bytes();
     if (!resources.cpuset_cpus().empty()) {
         hostconfig->cpuset_cpus = util_strdup_s(resources.cpuset_cpus().c_str());
@@ -1126,6 +1144,7 @@ cleanup:
     free_container_update_request(request);
     free_container_update_response(response);
     free_host_config(hostconfig);
+    free_json_map_string_string(unified);
     free(perror);
 }
 
diff --git a/src/daemon/entry/cri/cri_helpers.cc b/src/daemon/entry/cri/cri_helpers.cc
index ddcc153f..2f6dcf78 100644
--- a/src/daemon/entry/cri/cri_helpers.cc
+++ b/src/daemon/entry/cri/cri_helpers.cc
@@ -445,8 +445,23 @@ void UpdateCreateConfig(container_config *createConfig, host_config *hc,
             hc->cpuset_mems = util_strdup_s(rOpts.cpuset_mems().c_str());
         }
         hc->oom_score_adj = rOpts.oom_score_adj();
+        hc->memory_swap_limit_in_bytes = rOpts.memory_swap_limit_in_bytes();
+        auto *unified = (json_map_string_string *)util_common_calloc_s(sizeof(json_map_string_string));
+        if (unified == nullptr) {
+            error.SetError("Out of memory");
+            return;
+        }
+        if (!rOpts.unified().empty()) {
+            for (auto &iter : rOpts.unified()) {
+                if (append_json_map_string_string(unified, iter.first.c_str(), iter.second.c_str()) != 0) {
+                    error.SetError("Failed to append string");
+                    free_json_map_string_string(unified);
+                    return;
+                }
+            }
+        }
+        hc->unified = unified;
     }
-
     createConfig->open_stdin = config.stdin();
     createConfig->tty = config.tty();
 }
diff --git a/src/daemon/modules/runtime/runtime.c b/src/daemon/modules/runtime/runtime.c
index 7a3ed87f..29a64ac1 100644
--- a/src/daemon/modules/runtime/runtime.c
+++ b/src/daemon/modules/runtime/runtime.c
@@ -122,7 +122,7 @@ int runtime_create(const char *name, const char *runtime, const rt_create_params
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL) {
-        ERROR("Invalide arguments for runtime create");
+        ERROR("Invalid arguments for runtime create");
         ret = -1;
         goto out;
     }
@@ -146,7 +146,7 @@ int runtime_start(const char *name, const char *runtime, const rt_start_params_t
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || pid_info == NULL) {
-        ERROR("Invalide arguments for runtime start");
+        ERROR("Invalid arguments for runtime start");
         ret = -1;
         goto out;
     }
@@ -194,7 +194,7 @@ int runtime_restart(const char *name, const char *runtime, const rt_restart_para
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL) {
-        ERROR("Invalide arguments for runtime restart");
+        ERROR("Invalid arguments for runtime restart");
         ret = -1;
         goto out;
     }
@@ -218,7 +218,7 @@ int runtime_clean_resource(const char *name, const char *runtime, const rt_clean
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL) {
-        ERROR("Invalide arguments for runtime clean");
+        ERROR("Invalid arguments for runtime clean");
         ret = -1;
         goto out;
     }
@@ -242,7 +242,7 @@ int runtime_rm(const char *name, const char *runtime, const rt_rm_params_t *para
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL) {
-        ERROR("Invalide arguments for runtime rm");
+        ERROR("Invalid arguments for runtime rm");
         ret = -1;
         goto out;
     }
@@ -267,7 +267,7 @@ int runtime_status(const char *name, const char *runtime, const rt_status_params
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || status == NULL) {
-        ERROR("Invalide arguments for runtime status");
+        ERROR("Invalid arguments for runtime status");
         ret = -1;
         goto out;
     }
@@ -292,7 +292,7 @@ int runtime_resources_stats(const char *name, const char *runtime, const rt_stat
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || rs_stats == NULL) {
-        ERROR("Invalide arguments for runtime stats");
+        ERROR("Invalid arguments for runtime stats");
         ret = -1;
         goto out;
     }
@@ -316,7 +316,7 @@ int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || exit_code == NULL) {
-        ERROR("Invalide arguments for runtime exec");
+        ERROR("Invalid arguments for runtime exec");
         ret = -1;
         goto out;
     }
@@ -340,7 +340,7 @@ int runtime_pause(const char *name, const char *runtime, const rt_pause_params_t
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL) {
-        ERROR("Invalide arguments for runtime pause");
+        ERROR("Invalid arguments for runtime pause");
         ret = -1;
         goto out;
     }
@@ -364,7 +364,7 @@ int runtime_resume(const char *name, const char *runtime, const rt_resume_params
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL) {
-        ERROR("Invalide arguments for runtime resume");
+        ERROR("Invalid arguments for runtime resume");
         ret = -1;
         goto out;
     }
@@ -388,7 +388,7 @@ int runtime_attach(const char *name, const char *runtime, const rt_attach_params
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL) {
-        ERROR("Invalide arguments for runtime attach");
+        ERROR("Invalid arguments for runtime attach");
         ret = -1;
         goto out;
     }
@@ -412,7 +412,7 @@ int runtime_update(const char *name, const char *runtime, const rt_update_params
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL) {
-        ERROR("Invalide arguments for runtime update");
+        ERROR("Invalid arguments for runtime update");
         ret = -1;
         goto out;
     }
@@ -447,7 +447,7 @@ int runtime_listpids(const char *name, const char *runtime, const rt_listpids_pa
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL || out == NULL) {
-        ERROR("Invalide arguments for runtime listpids");
+        ERROR("Invalid arguments for runtime listpids");
         ret = -1;
         goto out;
     }
@@ -471,7 +471,7 @@ int runtime_resize(const char *name, const char *runtime, const rt_resize_params
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL) {
-        ERROR("Invalide arguments for runtime resize");
+        ERROR("Invalid arguments for runtime resize");
         ret = -1;
         goto out;
     }
@@ -495,7 +495,7 @@ int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_res
     const struct rt_ops *ops = NULL;
 
     if (name == NULL || runtime == NULL || params == NULL) {
-        ERROR("Invalide arguments for runtime exec resize");
+        ERROR("Invalid arguments for runtime exec resize");
         ret = -1;
         goto out;
     }
-- 
2.25.1