upgrade from upstream

Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
This commit is contained in:
zhangxiaoyu 2023-02-22 14:11:10 +08:00
parent 84e6f0c230
commit 70385f208a
22 changed files with 3922 additions and 1 deletions

View File

@ -0,0 +1,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/22] 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

View File

@ -0,0 +1,135 @@
From 466309bc0aafe61ebed5c71012e28b9912783b60 Mon Sep 17 00:00:00 2001
From: Xuepeng Xu <xuxuepeng1@huawei.com>
Date: Thu, 9 Feb 2023 14:32:59 +0800
Subject: [PATCH 03/22] Add macro for protoc cmake
Signed-off-by: Xuepeng Xu <xuxuepeng1@huawei.com>
---
cmake/protoc.cmake | 98 +++++++++++++---------------------------------
1 file changed, 28 insertions(+), 70 deletions(-)
diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake
index 5c433e5c..23b8c077 100644
--- a/cmake/protoc.cmake
+++ b/cmake/protoc.cmake
@@ -11,89 +11,47 @@ if (ENABLE_NATIVE_NETWORK)
set(NETWORK_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/services/network)
endif()
+macro(PROTOC_CPP_GEN proto_name cpp_out_path proto_path)
+ execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/${proto_name} --cpp_out=${cpp_out_path} ${proto_path} ERROR_VARIABLE cpp_err)
+ if (cpp_err)
+ message("Parse ${proto_path} failed: ")
+ message(FATAL_ERROR ${cpp_err})
+ endif()
+endmacro(PROTOC_CPP_GEN)
+
+macro(PROTOC_GRPC_GEN proto_name grpc_out_path proto_path)
+ execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/${proto_name} --grpc_out=${grpc_out_path} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${proto_path} ERROR_VARIABLE grpc_err)
+ if (grpc_err)
+ message("Parse ${proto_path} failed: ")
+ message(FATAL_ERROR ${grpc_err})
+ endif()
+endmacro(PROTOC_GRPC_GEN)
+
if (GRPC_CONNECTOR)
execute_process(COMMAND mkdir -p ${CONTAINER_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${IMAGE_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${VOLUME_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${CRI_PROTOS_OUT_PATH})
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/containers --cpp_out=${CONTAINER_PROTOS_OUT_PATH}
- ${PROTOS_PATH}/containers/container.proto ERROR_VARIABLE containers_err)
- if (containers_err)
- message("Parse ${PROTOS_PATH}/containers/container.proto failed: ")
- message(FATAL_ERROR ${containers_err})
- endif()
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/containers --grpc_out=${CONTAINER_PROTOS_OUT_PATH} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/containers/container.proto ERROR_VARIABLE containers_err)
- if (containers_err)
- message("Parse ${PROTOS_PATH}/containers/container.proto plugin failed: ")
- message(FATAL_ERROR ${containers_err})
- endif()
+ PROTOC_CPP_GEN(containers ${CONTAINER_PROTOS_OUT_PATH} ${PROTOS_PATH}/containers/container.proto)
+ PROTOC_GRPC_GEN(containers ${CONTAINER_PROTOS_OUT_PATH} ${PROTOS_PATH}/containers/container.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/images --cpp_out=${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto ERROR_VARIABLE images_err)
- if (images_err)
- message("Parse ${PROTOS_PATH}/images/images.proto failed: ")
- message(FATAL_ERROR ${images_err})
- endif()
+ PROTOC_CPP_GEN(images ${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto)
+ PROTOC_GRPC_GEN(images ${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/images --grpc_out=${IMAGE_PROTOS_OUT_PATH} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/images/images.proto ERROR_VARIABLE images_err)
- if (images_err)
- message("Parse ${PROTOS_PATH}/images/images.proto plugin failed: ")
- message(FATAL_ERROR ${images_err})
- endif()
+ PROTOC_CPP_GEN(volumes ${VOLUME_PROTOS_OUT_PATH} ${PROTOS_PATH}/volumes/volumes.proto)
+ PROTOC_GRPC_GEN(volumes ${VOLUME_PROTOS_OUT_PATH} ${PROTOS_PATH}/volumes/volumes.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/volumes --cpp_out=${VOLUME_PROTOS_OUT_PATH} ${PROTOS_PATH}/volumes/volumes.proto ERROR_VARIABLE volumes_err)
- if (volumes_err)
- message("Parse ${PROTOS_PATH}/volumes/volumes.proto failed: ")
- message(FATAL_ERROR ${volumes_err})
- endif()
+ PROTOC_CPP_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto)
+ PROTOC_GRPC_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/volumes --grpc_out=${VOLUME_PROTOS_OUT_PATH} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/volumes/volumes.proto ERROR_VARIABLE volumes_err)
- if (volumes_err)
- message("Parse ${PROTOS_PATH}/volumes/volumes.proto plugin failed: ")
- message(FATAL_ERROR ${volumes_err})
- endif()
-
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --cpp_out=${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto
- ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/api.proto failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
-
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --grpc_out=${CRI_PROTOS_OUT_PATH}
- --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/cri/api.proto ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/api.proto plugin failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --cpp_out=${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/gogo.proto
- ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/gogo.proto failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --grpc_out=${CRI_PROTOS_OUT_PATH}
- --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/cri/gogo.proto ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/gogo.proto plugin failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
+ PROTOC_CPP_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/gogo.proto)
+ PROTOC_GRPC_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/gogo.proto)
if (ENABLE_NATIVE_NETWORK)
execute_process(COMMAND mkdir -p ${NETWORK_PROTOS_OUT_PATH})
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/network
- --cpp_out=${NETWORK_PROTOS_OUT_PATH} ${PROTOS_PATH}/network/network.proto ERROR_VARIABLE network_err)
- if (network_err)
- message("Parse ${PROTOS_PATH}/network/network.proto failed: ")
- message(FATAL_ERROR ${network_err})
- endif()
-
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/network --grpc_out=${NETWORK_PROTOS_OUT_PATH}
- --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/network/network.proto ERROR_VARIABLE network_err)
- if (network_err)
- message("Parse ${PROTOS_PATH}/network/network.proto plugin failed: ")
- message(FATAL_ERROR ${network_err})
- endif()
+ PROTOC_CPP_GEN(network ${NETWORK_PROTOS_OUT_PATH} ${PROTOS_PATH}/network/network.proto)
+ PROTOC_GRPC_GEN(network ${NETWORK_PROTOS_OUT_PATH} ${PROTOS_PATH}/network/network.proto)
endif()
endif()
--
2.25.1

View File

@ -0,0 +1,25 @@
From a7df50dc3b51f961f3d2e48dd968cfb115c39fec Mon Sep 17 00:00:00 2001
From: zhushy <zhushangyuan@foxmail.com>
Date: Sat, 11 Feb 2023 00:05:53 +0800
Subject: [PATCH 04/22] fix design typo
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 3d1fc7cb..7e4b6de1 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ CRI interface is implemented based on gRPC. iSulad implemented CRI gRPC Server f
- [user manual](./docs/manual/README.md)
-- [desgin docs](./docs/design/README.md)
+- [design docs](./docs/design/README.md)
### Installing
--
2.25.1

View File

@ -0,0 +1,44 @@
From 257054b234debb7b1fcafce6f2ec3df828370aed Mon Sep 17 00:00:00 2001
From: songbuhuang <544824346@qq.com>
Date: Sun, 12 Feb 2023 15:23:37 +0800
Subject: [PATCH 05/22] fix cpu rt review comments
Signed-off-by: songbuhuang <544824346@qq.com>
---
src/daemon/executor/container_cb/execution_create.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index feaa3064..cc9ae716 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -1327,7 +1327,7 @@ static int save_container_config_before_create(const char *id, const char *runti
static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const char *path)
{
int ret;
- int fd = 0;
+ int fd = -1;
ssize_t nwrite;
char fpath[PATH_MAX] = { 0 };
char buf[ISULAD_NUMSTRLEN64] = { 0 };
@@ -1342,13 +1342,13 @@ static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const
return -1;
}
- int nret = snprintf(fpath, sizeof(fpath), "%s/%s", path, file);
- if (nret < 0 || nret >= sizeof(fpath)) {
+ ret = snprintf(fpath, sizeof(fpath), "%s/%s", path, file);
+ if (ret < 0 || ret >= sizeof(fpath)) {
ERROR("Failed to print string");
return -1;
}
- nret = snprintf(buf, sizeof(buf), "%lld", (long long int)value);
- if (nret < 0 || (size_t)nret >= sizeof(buf)) {
+ ret = snprintf(buf, sizeof(buf), "%lld", (long long int)value);
+ if (ret < 0 || (size_t)ret >= sizeof(buf)) {
ERROR("Failed to print string");
return -1;
}
--
2.25.1

View File

@ -0,0 +1,31 @@
From e4993d0e89ca853d74d8b23895de0967b4379441 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Mon, 13 Feb 2023 17:42:30 +0800
Subject: [PATCH 06/22] fix inspect.sh failed
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
CI/test_cases/container_cases/inspect.sh | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/CI/test_cases/container_cases/inspect.sh b/CI/test_cases/container_cases/inspect.sh
index 0d4ccb02..cde9ea1f 100755
--- a/CI/test_cases/container_cases/inspect.sh
+++ b/CI/test_cases/container_cases/inspect.sh
@@ -103,12 +103,7 @@ function test_inspect_spec()
isula inspect --format='{{.Image}}' $containername 2>&1 | grep "sha256:${image_id}"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++))
- if [ -d /sys/fs/cgroup/files ];then
- grepval="100"
- else
- grepval="0"
- fi
- isula inspect --format='{{json .HostConfig.FilesLimit}}' $containername 2>&1 | grep "$grepval"
+ isula inspect --format='{{json .HostConfig.FilesLimit}}' $containername 2>&1 | grep 0
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++))
isula inspect --format='{{json .Config.Env}}' $containername 2>&1 | grep "a=1"
--
2.25.1

View File

@ -0,0 +1,490 @@
From 9bd02c394110180ac7d7cbe80c1f4abe18146ebb Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Fri, 10 Feb 2023 17:43:11 +0800
Subject: [PATCH 07/22] add CRI ContainerStats Service
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
.../connect/grpc/runtime_image_service.cc | 12 ++---
.../connect/grpc/runtime_runtime_service.cc | 45 +++++++++++-----
.../connect/grpc/runtime_runtime_service.h | 3 ++
.../cri/cri_container_manager_service.cc | 54 +++++++++++++++++++
.../entry/cri/cri_container_manager_service.h | 3 ++
src/daemon/entry/cri/cri_runtime_service.h | 3 ++
.../entry/cri/cri_runtime_service_impl.cc | 6 +++
.../entry/cri/cri_runtime_service_impl.h | 3 ++
src/daemon/modules/events/collector.c | 4 +-
src/daemon/modules/image/image.c | 16 +++---
.../modules/image/oci/oci_common_operators.c | 8 +--
11 files changed, 125 insertions(+), 32 deletions(-)
diff --git a/src/daemon/entry/connect/grpc/runtime_image_service.cc b/src/daemon/entry/connect/grpc/runtime_image_service.cc
index 23447baf..e593a9c6 100644
--- a/src/daemon/entry/connect/grpc/runtime_image_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_image_service.cc
@@ -54,7 +54,7 @@ grpc::Status RuntimeImageServiceImpl::ListImages(grpc::ServerContext *context,
std::vector<std::unique_ptr<runtime::v1alpha2::Image>> images;
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all images}");
+ INFO("Event: {Object: CRI, Type: Listing all images}");
rService->ListImages(request->filter(), &images, error);
if (!error.Empty()) {
@@ -70,7 +70,7 @@ grpc::Status RuntimeImageServiceImpl::ListImages(grpc::ServerContext *context,
*image = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all images}");
+ INFO("Event: {Object: CRI, Type: Listed all images}");
return grpc::Status::OK;
}
@@ -82,7 +82,7 @@ grpc::Status RuntimeImageServiceImpl::ImageStatus(grpc::ServerContext *context,
std::unique_ptr<runtime::v1alpha2::Image> image_info = nullptr;
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing image %s}", request->image().image().c_str());
+ INFO("Event: {Object: CRI, Type: Statusing image %s}", request->image().image().c_str());
image_info = rService->ImageStatus(request->image(), error);
if (!error.Empty() && !CRIHelpers::IsImageNotFoundError(error.GetMessage())) {
@@ -96,7 +96,7 @@ grpc::Status RuntimeImageServiceImpl::ImageStatus(grpc::ServerContext *context,
*image = *image_info;
}
- WARN("Event: {Object: CRI, Type: Statused image %s}", request->image().image().c_str());
+ INFO("Event: {Object: CRI, Type: Statused image %s}", request->image().image().c_str());
return grpc::Status::OK;
}
@@ -108,7 +108,7 @@ grpc::Status RuntimeImageServiceImpl::ImageFsInfo(grpc::ServerContext *context,
std::vector<std::unique_ptr<runtime::v1alpha2::FilesystemUsage>> usages;
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing image fs info}");
+ INFO("Event: {Object: CRI, Type: Statusing image fs info}");
rService->ImageFsInfo(&usages, error);
if (!error.Empty()) {
@@ -125,7 +125,7 @@ grpc::Status RuntimeImageServiceImpl::ImageFsInfo(grpc::ServerContext *context,
*fs_info = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Statused image fs info}");
+ INFO("Event: {Object: CRI, Type: Statused image fs info}");
return grpc::Status::OK;
}
diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
index b6f9e751..8fed162b 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
@@ -171,7 +171,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainers(grpc::ServerContext *cont
{
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all Container}");
+ INFO("Event: {Object: CRI, Type: Listing all Container}");
std::vector<std::unique_ptr<runtime::v1alpha2::Container>> containers;
m_rService->ListContainers(request->has_filter() ? &request->filter() : nullptr, &containers, error);
@@ -189,7 +189,28 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainers(grpc::ServerContext *cont
*container = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all Container}");
+ INFO("Event: {Object: CRI, Type: Listed all Container}");
+
+ return grpc::Status::OK;
+}
+
+grpc::Status RuntimeRuntimeServiceImpl::ContainerStats(grpc::ServerContext *context,
+ const runtime::v1alpha2::ContainerStatsRequest *request,
+ runtime::v1alpha2::ContainerStatsResponse *reply)
+{
+ Errors error;
+
+ INFO("Event: {Object: CRI, Type: Getting Container Stats: %s}", request->container_id().c_str());
+
+ std::unique_ptr<runtime::v1alpha2::ContainerStats> contStats =
+ m_rService->ContainerStats(request->container_id(), error);
+ if (!error.Empty() || !contStats) {
+ ERROR("Object: CRI, Type: Failed to get container stats %s", request->container_id().c_str());
+ return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage());
+ }
+ *(reply->mutable_stats()) = *contStats;
+
+ INFO("Event: {Object: CRI, Type: Got Container stats: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
@@ -200,7 +221,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainerStats(grpc::ServerContext *
{
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all Container stats}");
+ INFO("Event: {Object: CRI, Type: Listing all Container stats}");
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> containers;
m_rService->ListContainerStats(request->has_filter() ? &request->filter() : nullptr, &containers, error);
@@ -218,7 +239,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainerStats(grpc::ServerContext *
*container = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all Container stats}");
+ INFO("Event: {Object: CRI, Type: Listed all Container stats}");
return grpc::Status::OK;
}
@@ -229,7 +250,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ContainerStatus(grpc::ServerContext *con
{
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing Container: %s}", request->container_id().c_str());
+ INFO("Event: {Object: CRI, Type: Statusing Container: %s}", request->container_id().c_str());
std::unique_ptr<runtime::v1alpha2::ContainerStatus> contStatus =
m_rService->ContainerStatus(request->container_id(), error);
@@ -239,7 +260,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ContainerStatus(grpc::ServerContext *con
}
*(reply->mutable_status()) = *contStatus;
- WARN("Event: {Object: CRI, Type: Statused Container: %s}", request->container_id().c_str());
+ INFO("Event: {Object: CRI, Type: Statused Container: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
@@ -329,7 +350,7 @@ grpc::Status RuntimeRuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *co
{
Errors error;
- WARN("Event: {Object: CRI, Type: Status Pod: %s}", request->pod_sandbox_id().c_str());
+ INFO("Event: {Object: CRI, Type: Status Pod: %s}", request->pod_sandbox_id().c_str());
std::unique_ptr<runtime::v1alpha2::PodSandboxStatus> podStatus;
podStatus = m_rService->PodSandboxStatus(request->pod_sandbox_id(), error);
@@ -340,7 +361,7 @@ grpc::Status RuntimeRuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *co
}
*(reply->mutable_status()) = *podStatus;
- WARN("Event: {Object: CRI, Type: Statused Pod: %s}", request->pod_sandbox_id().c_str());
+ INFO("Event: {Object: CRI, Type: Statused Pod: %s}", request->pod_sandbox_id().c_str());
return grpc::Status::OK;
}
@@ -351,7 +372,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *cont
{
Errors error;
- WARN("Event: {Object: CRI, Type: Listing all Pods}");
+ INFO("Event: {Object: CRI, Type: Listing all Pods}");
std::vector<std::unique_ptr<runtime::v1alpha2::PodSandbox>> pods;
m_rService->ListPodSandbox(request->has_filter() ? &request->filter() : nullptr, &pods, error);
@@ -368,7 +389,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *cont
*pod = *(iter->get());
}
- WARN("Event: {Object: CRI, Type: Listed all Pods}");
+ INFO("Event: {Object: CRI, Type: Listed all Pods}");
return grpc::Status::OK;
}
@@ -460,7 +481,7 @@ grpc::Status RuntimeRuntimeServiceImpl::Status(grpc::ServerContext *context,
{
Errors error;
- WARN("Event: {Object: CRI, Type: Statusing daemon}");
+ INFO("Event: {Object: CRI, Type: Statusing daemon}");
std::unique_ptr<runtime::v1alpha2::RuntimeStatus> status = m_rService->Status(error);
if (status == nullptr || error.NotEmpty()) {
@@ -469,7 +490,7 @@ grpc::Status RuntimeRuntimeServiceImpl::Status(grpc::ServerContext *context,
}
*(reply->mutable_status()) = *status;
- WARN("Event: {Object: CRI, Type: Statused daemon}");
+ INFO("Event: {Object: CRI, Type: Statused daemon}");
return grpc::Status::OK;
}
diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.h b/src/daemon/entry/connect/grpc/runtime_runtime_service.h
index 6e8c1009..cb3c5425 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.h
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.h
@@ -52,6 +52,9 @@ public:
const runtime::v1alpha2::ListContainerStatsRequest *request,
runtime::v1alpha2::ListContainerStatsResponse *reply) override;
+ grpc::Status ContainerStats(grpc::ServerContext *context, const runtime::v1alpha2::ContainerStatsRequest *request,
+ runtime::v1alpha2::ContainerStatsResponse *reply) override;
+
grpc::Status ContainerStatus(grpc::ServerContext *context, const runtime::v1alpha2::ContainerStatusRequest *request,
runtime::v1alpha2::ContainerStatusResponse *reply) override;
diff --git a/src/daemon/entry/cri/cri_container_manager_service.cc b/src/daemon/entry/cri/cri_container_manager_service.cc
index d044cca8..710556a3 100644
--- a/src/daemon/entry/cri/cri_container_manager_service.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service.cc
@@ -893,6 +893,60 @@ cleanup:
free_container_stats_response(response);
}
+auto ContainerManagerService::ContainerStats(const std::string &containerID, Errors &error)
+-> std::unique_ptr<runtime::v1alpha2::ContainerStats>
+{
+ container_stats_request *request { nullptr };
+ container_stats_response *response { nullptr };
+ std::unique_ptr<runtime::v1alpha2::ContainerStats> contStats { nullptr };
+ std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> contStatsVec;
+
+ if (containerID.empty()) {
+ error.SetError("Empty container id");
+ return nullptr;
+ }
+
+ if (m_cb == nullptr || m_cb->container.stats == nullptr) {
+ error.SetError("Unimplemented callback");
+ return nullptr;
+ }
+
+ request = (container_stats_request *)util_common_calloc_s(sizeof(container_stats_request));
+ if (request == nullptr) {
+ error.SetError("Out of memory");
+ return nullptr;
+ }
+
+ request->containers = (char **)util_smart_calloc_s(sizeof(char *), 1);
+ if (request->containers == nullptr) {
+ error.SetError("Out of memory");
+ goto cleanup;
+ }
+
+ request->containers[0] = util_strdup_s(containerID.c_str());
+ request->containers_len = 1;
+
+ if (m_cb->container.stats(request, &response) != 0) {
+ if (response != nullptr && response->errmsg != nullptr) {
+ error.SetError(response->errmsg);
+ } else {
+ error.SetError("Failed to call stats container callback");
+ }
+ goto cleanup;
+ }
+
+ ContainerStatsToGRPC(response, &contStatsVec, error);
+ if (error.NotEmpty()) {
+ goto cleanup;
+ }
+ contStats = std::move(contStatsVec[0]);
+
+cleanup:
+ free_container_stats_request(request);
+ free_container_stats_response(response);
+ return contStats;
+}
+
void ContainerManagerService::PackContainerImageToStatus(
container_inspect *inspect, std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus, Errors &error)
{
diff --git a/src/daemon/entry/cri/cri_container_manager_service.h b/src/daemon/entry/cri/cri_container_manager_service.h
index 8002b77d..6ec1f21d 100644
--- a/src/daemon/entry/cri/cri_container_manager_service.h
+++ b/src/daemon/entry/cri/cri_container_manager_service.h
@@ -53,6 +53,9 @@ public:
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats,
Errors &error);
+ auto ContainerStats(const std::string &containerID, Errors &error)
+ -> std::unique_ptr<runtime::v1alpha2::ContainerStats>;
+
auto ContainerStatus(const std::string &containerID, Errors &error)
-> std::unique_ptr<runtime::v1alpha2::ContainerStatus>;
diff --git a/src/daemon/entry/cri/cri_runtime_service.h b/src/daemon/entry/cri/cri_runtime_service.h
index 4727230f..5e4740cb 100644
--- a/src/daemon/entry/cri/cri_runtime_service.h
+++ b/src/daemon/entry/cri/cri_runtime_service.h
@@ -49,6 +49,9 @@ public:
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats,
Errors &error) = 0;
+ virtual auto ContainerStats(const std::string &containerID,
+ Errors &error) -> std::unique_ptr<runtime::v1alpha2::ContainerStats> = 0;
+
virtual auto ContainerStatus(const std::string &containerID,
Errors &error) -> std::unique_ptr<runtime::v1alpha2::ContainerStatus> = 0;
diff --git a/src/daemon/entry/cri/cri_runtime_service_impl.cc b/src/daemon/entry/cri/cri_runtime_service_impl.cc
index 241d4316..c4b84828 100644
--- a/src/daemon/entry/cri/cri_runtime_service_impl.cc
+++ b/src/daemon/entry/cri/cri_runtime_service_impl.cc
@@ -70,6 +70,12 @@ void CRIRuntimeServiceImpl::ListContainerStats(
m_containerManager->ListContainerStats(filter, containerstats, error);
}
+auto CRIRuntimeServiceImpl::ContainerStats(const std::string &containerID, Errors &error)
+-> std::unique_ptr<runtime::v1alpha2::ContainerStats>
+{
+ return m_containerManager->ContainerStats(containerID, error);
+}
+
auto CRIRuntimeServiceImpl::ContainerStatus(const std::string &containerID, Errors &error)
-> std::unique_ptr<runtime::v1alpha2::ContainerStatus>
{
diff --git a/src/daemon/entry/cri/cri_runtime_service_impl.h b/src/daemon/entry/cri/cri_runtime_service_impl.h
index f2e25e42..7355c5cb 100644
--- a/src/daemon/entry/cri/cri_runtime_service_impl.h
+++ b/src/daemon/entry/cri/cri_runtime_service_impl.h
@@ -51,6 +51,9 @@ public:
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats,
Errors &error) override;
+ auto ContainerStats(const std::string &containerID, Errors &error)
+ -> std::unique_ptr<runtime::v1alpha2::ContainerStats> override;
+
auto ContainerStatus(const std::string &containerID, Errors &error)
-> std::unique_ptr<runtime::v1alpha2::ContainerStatus> override;
diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c
index fb4e4a98..f53ad319 100644
--- a/src/daemon/modules/events/collector.c
+++ b/src/daemon/modules/events/collector.c
@@ -484,7 +484,7 @@ static int write_events_log(const struct isulad_events_format *events)
len = calculate_annaotation_info_len(events);
if (len == 1) {
- WARN("Event: {Object: %s, Type: %s}", events->id, events->opt);
+ INFO("Event: {Object: %s, Type: %s}", events->id, events->opt);
} else {
annotation = (char *)util_common_calloc_s(len);
if (annotation == NULL) {
@@ -502,7 +502,7 @@ static int write_events_log(const struct isulad_events_format *events)
}
(void)strcat(annotation, ")");
- WARN("Event: {Object: %s, Type: %s %s}", events->id, events->opt, annotation);
+ INFO("Event: {Object: %s, Type: %s %s}", events->id, events->opt, annotation);
}
out:
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
index d5fbc8dc..a9b9523e 100644
--- a/src/daemon/modules/image/image.c
+++ b/src/daemon/modules/image/image.c
@@ -416,7 +416,7 @@ int im_get_filesystem_info(const char *image_type, im_fs_info_response **respons
goto out;
}
- WARN("Event: {Object: get image filesystem info, Type: inspecting}");
+ INFO("Event: {Object: get image filesystem info, Type: inspecting}");
ret = q->ops->get_filesystem_info(response);
if (ret != 0) {
if (response != NULL && *response != NULL) {
@@ -426,7 +426,7 @@ int im_get_filesystem_info(const char *image_type, im_fs_info_response **respons
}
goto out;
}
- WARN("Event: {Object: get image filesystem info, Type: inspected}");
+ INFO("Event: {Object: get image filesystem info, Type: inspected}");
out:
return ret;
@@ -466,7 +466,7 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
request->name_id = util_strdup_s(id);
}
- WARN("Event: {Object: container \'%s\' filesystem info, Type: inspecting}", id != NULL ? id : "");
+ INFO("Event: {Object: container \'%s\' filesystem info, Type: inspecting}", id != NULL ? id : "");
ret = q->ops->container_fs_usage(request, &filesystemusage);
if (ret != 0) {
ERROR("Failed to get filesystem usage for container %s", id);
@@ -476,7 +476,7 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
*fs_usage = filesystemusage;
filesystemusage = NULL;
- WARN("Event: {Object: container \'%s\' filesystem info, Type: inspected}", id != NULL ? id : "");
+ INFO("Event: {Object: container \'%s\' filesystem info, Type: inspected}", id != NULL ? id : "");
out:
free_im_container_fs_usage_request(request);
@@ -916,7 +916,7 @@ int im_list_images(const im_list_request *ctx, im_list_response **response)
return -1;
}
- WARN("Event: {Object: list images, Type: listing}");
+ INFO("Event: {Object: list images, Type: listing}");
for (i = 0; i < g_numbims; i++) {
if (g_bims[i].ops->list_ims == NULL) {
@@ -936,7 +936,7 @@ int im_list_images(const im_list_request *ctx, im_list_response **response)
images_tmp = NULL;
}
- WARN("Event: {Object: list images, Type: listed}");
+ INFO("Event: {Object: list images, Type: listed}");
if (g_isulad_errmsg != NULL) {
(*response)->errmsg = util_strdup_s(g_isulad_errmsg);
@@ -1671,7 +1671,7 @@ int im_inspect_image(const im_inspect_request *request, im_inspect_response **re
image_ref = util_strdup_s(request->image.image);
- WARN("Event: {Object: %s, Type: image inspecting}", image_ref);
+ INFO("Event: {Object: %s, Type: image inspecting}", image_ref);
bim_type = bim_query(image_ref);
if (bim_type == NULL) {
@@ -1693,7 +1693,7 @@ int im_inspect_image(const im_inspect_request *request, im_inspect_response **re
goto pack_response;
}
- WARN("Event: {Object: %s, Type: image inspected}", image_ref);
+ INFO("Event: {Object: %s, Type: image inspected}", image_ref);
pack_response:
if (g_isulad_errmsg != NULL) {
diff --git a/src/daemon/modules/image/oci/oci_common_operators.c b/src/daemon/modules/image/oci/oci_common_operators.c
index 3d200e09..83cccbe6 100644
--- a/src/daemon/modules/image/oci/oci_common_operators.c
+++ b/src/daemon/modules/image/oci/oci_common_operators.c
@@ -429,7 +429,7 @@ int oci_summary_image(im_summary_request *request, im_summary_response *response
goto pack_response;
}
- WARN("Event: {Object: %s, Type: statusing image summary}", resolved_name);
+ INFO("Event: {Object: %s, Type: statusing image summary}", resolved_name);
image_summary = storage_img_get_summary(resolved_name);
if (image_summary == NULL) {
@@ -442,7 +442,7 @@ int oci_summary_image(im_summary_request *request, im_summary_response *response
response->image_summary = image_summary;
image_summary = NULL;
- WARN("Event: {Object: %s, Type: statused image summary}", resolved_name);
+ INFO("Event: {Object: %s, Type: statused image summary}", resolved_name);
pack_response:
free(resolved_name);
@@ -493,7 +493,7 @@ int oci_status_image(im_status_request *request, im_status_response *response)
goto pack_response;
}
- WARN("Event: {Object: %s, Type: statusing image}", resolved_name);
+ INFO("Event: {Object: %s, Type: statusing image}", resolved_name);
image_info = storage_img_get(resolved_name);
if (image_info == NULL) {
@@ -506,7 +506,7 @@ int oci_status_image(im_status_request *request, im_status_response *response)
response->image_info->image = image_info;
image_info = NULL;
- WARN("Event: {Object: %s, Type: statused image}", resolved_name);
+ INFO("Event: {Object: %s, Type: statused image}", resolved_name);
pack_response:
free(resolved_name);
--
2.25.1

View File

@ -0,0 +1,183 @@
From edef459d5052dc6d7c29e8a7a48ff4bf1b01bd78 Mon Sep 17 00:00:00 2001
From: songbuhuang <544824346@qq.com>
Date: Tue, 14 Feb 2023 14:08:01 +0800
Subject: [PATCH 08/22] fix isula cpu-rt CI
Signed-off-by: songbuhuang <544824346@qq.com>
---
CI/test_cases/container_cases/cpu_rt.sh | 102 +++++++++++++++++-------
1 file changed, 73 insertions(+), 29 deletions(-)
diff --git a/CI/test_cases/container_cases/cpu_rt.sh b/CI/test_cases/container_cases/cpu_rt.sh
index 3d70c840..353c2d71 100755
--- a/CI/test_cases/container_cases/cpu_rt.sh
+++ b/CI/test_cases/container_cases/cpu_rt.sh
@@ -21,12 +21,12 @@
declare -r curr_path=$(dirname $(readlink -f "$0"))
source ../helpers.sh
-function test_cpu_rt_isulad_spec()
+function test_cpurt_isulad_abnormal()
{
local ret=0
local test="isulad cpu realtime test => (${FUNCNAME[@]})"
- msg_info "${test} starting..."
+ msg_info "${test} starting..."
isulad --cpu-rt-period xx --cpu-rt-runtime 950000 /bin/sh 2>&1 | grep 'Invalid value "xx" for flag --cpu-rt-period: Invalid argument'
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-period" && ((ret++))
@@ -38,54 +38,64 @@ function test_cpu_rt_isulad_spec()
return ${ret}
}
-function test_cpu_rt_isula_spec()
+function test_isula_update_normal()
{
- local ret=0
- local image="busybox"
- local test="container cpu realtime test => (${FUNCNAME[@]})"
-
- msg_info "${test} starting..."
-
- #start isulad without cpu_rt
- start_isulad_without_valgrind
+ #start isulad with cpu_rt
+ isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
+ wait_isulad_running
+
+ c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 950000 ${image} sh`
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
- isula pull ${image}
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+ isula update --cpu-rt-period 900000 --cpu-rt-runtime 800000 $c_id
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to update container cpu-rt-runtime" && ((ret++))
- isula images | grep busybox
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
+ isula exec -it $c_id sh -c "cat /sys/fs/cgroup/cpu/cpu.rt_runtime_us" | grep "800000"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container cpu.rt_runtime_us: 800000" && ((ret++))
- test_isula_run_spec
+ isula exec -it $c_id sh -c "cat /sys/fs/cgroup/cpu/cpu.rt_period_us" | grep "900000"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container cpu.rt_period_us: 900000" && ((ret++))
- #start isulad without cpu_rt:isulad cpu.rt_period_us default value is the cpu.rt_period_us of the upper-layer directory,cpu.rt_runtime_us is 0.
- isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 10000 $image /bin/sh 2>&1 | grep "failed to write 10000" | grep "cpu.rt_runtime_us: Invalid argument"
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-runtime" && ((ret++))
+ isula rm -f $c_id
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container ${c_id}" && ((ret++))
stop_isulad_without_valgrind
+ #set cpu-rt to the initial state
+ isulad --cpu-rt-period 1000000 --cpu-rt-runtime 0 -l DEBUG > /dev/null 2>&1 &
+ wait_isulad_running
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_isula_update_abnormal()
+{
#start isulad with cpu_rt
isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
wait_isulad_running
-
- test_isula_run_spec
c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 950000 ${image} sh`
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
- isula update --cpu-rt-runtime 90000 $c_id
+ isula update --cpu-rt-period 800000 --cpu-rt-runtime 900000 $c_id | grep "Invalid --cpu-rt-runtime: rt runtime cannot be higher than rt period"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to update container cpu-rt-runtime" && ((ret++))
- isula exec -it $c_id sh -c "cat /sys/fs/cgroup/cpu/cpu.rt_runtime_us" | grep "90000"
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container cpu.rt_runtime_us: 90000" && ((ret++))
+ isula update --cpu-rt-runtime 1000000 $c_id | grep "updating cgroup cpu.rt_runtime_us to 1000000: Invalid argument"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to update container cpu-rt-runtime" && ((ret++))
isula rm -f $c_id
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container ${c_id}" && ((ret++))
+ stop_isulad_without_valgrind
+ #set cpu-rt to the initial state
+ isulad --cpu-rt-period 1000000 --cpu-rt-runtime 0 -l DEBUG > /dev/null 2>&1 &
+ wait_isulad_running
+
msg_info "${test} finished with return ${ret}..."
return ${ret}
}
-function test_kernel_without_cpu_rt_spec()
+function test_kernel_without_cpurt()
{
local ret=0
local image="busybox"
@@ -109,8 +119,24 @@ function test_kernel_without_cpu_rt_spec()
return ${ret}
}
-function test_isula_run_spec()
+function test_isula_run_abnormal()
{
+ local ret=0
+ local image="busybox"
+ local test="container cpu realtime test => (${FUNCNAME[@]})"
+
+ msg_info "${test} starting..."
+
+ #start isulad without cpu_rt
+ isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
+ wait_isulad_running
+
+ isula pull ${image}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+
+ isula images | grep busybox
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
+
isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime -1 $image /bin/sh 2>&1 | grep "failed to write -1" | grep "cpu.rt_runtime_us: Invalid argument"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-runtime" && ((ret++))
@@ -128,15 +154,33 @@ function test_isula_run_spec()
isula run -itd --cpu-rt-period 100 --cpu-rt-runtime 10000 $image /bin/sh 2>&1 | grep "Invalid --cpu-rt-runtime: rt runtime cannot be higher than rt period"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cpu-rt-runtime cannot be higher than cpu-rt-period" && ((ret++))
+
+ isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 960000 $image /bin/sh 2>&1 | grep "failed to write 960000" | grep "cpu.rt_runtime_us: Invalid argument"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-runtime" && ((ret++))
+
+ stop_isulad_without_valgrind
+}
+
+function test_isula_run_normal()
+{
+ isula run -itd -n box --cpu-rt-period 1000000 --cpu-rt-runtime 900000 $image /bin/sh 2>&1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container" && ((ret++))
+
+ isula rm -f box
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container ${c_id}" && ((ret++))
+
}
declare -i ans=0
if [ -f "/sys/fs/cgroup/cpu/cpu.rt_runtime_us" ];then
- test_cpu_rt_isulad_spec || ((ans++))
- test_cpu_rt_isula_spec || ((ans++))
+ test_isula_run_abnormal || ((ans++))
+ test_isula_run_normal || ((ans++))
+ test_cpurt_isulad_abnormal || ((ans++))
+ test_isula_update_normal || ((ans++))
+ test_isula_update_abnormal || ((ans++))
else
- test_kernel_without_cpu_rt_spec || ((ans++))
+ test_kernel_without_cpurt || ((ans++))
fi
show_result ${ans} "${curr_path}/${0}"
--
2.25.1

105
0009-fix-cpu-rt-CI.patch Normal file
View File

@ -0,0 +1,105 @@
From 0504a907def3efb4c0ad7eabd5921c97090430af Mon Sep 17 00:00:00 2001
From: songbuhuang <544824346@qq.com>
Date: Tue, 14 Feb 2023 15:55:56 +0800
Subject: [PATCH 09/22] fix cpu-rt CI
Signed-off-by: songbuhuang <544824346@qq.com>
---
CI/test_cases/container_cases/cpu_rt.sh | 32 +++++++++++++++++++------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/CI/test_cases/container_cases/cpu_rt.sh b/CI/test_cases/container_cases/cpu_rt.sh
index 353c2d71..42006bc8 100755
--- a/CI/test_cases/container_cases/cpu_rt.sh
+++ b/CI/test_cases/container_cases/cpu_rt.sh
@@ -24,14 +24,14 @@ source ../helpers.sh
function test_cpurt_isulad_abnormal()
{
local ret=0
- local test="isulad cpu realtime test => (${FUNCNAME[@]})"
+ local test="isulad cpu realtime abnormal test => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- isulad --cpu-rt-period xx --cpu-rt-runtime 950000 /bin/sh 2>&1 | grep 'Invalid value "xx" for flag --cpu-rt-period: Invalid argument'
+ isulad --cpu-rt-period xx --cpu-rt-runtime 950000 2>&1 | grep 'Invalid value "xx" for flag --cpu-rt-period: Invalid argument'
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-period" && ((ret++))
- isulad --cpu-rt-period 1000000 --cpu-rt-runtime xx /bin/sh 2>&1 | grep 'Invalid value "xx" for flag --cpu-rt-runtime: Invalid argument'
+ isulad --cpu-rt-period 1000000 --cpu-rt-runtime xx 2>&1 | grep 'Invalid value "xx" for flag --cpu-rt-runtime: Invalid argument'
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-runtime" && ((ret++))
msg_info "${test} finished with return ${ret}..."
@@ -40,6 +40,12 @@ function test_cpurt_isulad_abnormal()
function test_isula_update_normal()
{
+ local ret=0
+ local image="busybox"
+ local test="isulad update cpu realtime normal test => (${FUNCNAME[@]})"
+
+ msg_info "${test} starting..."
+
#start isulad with cpu_rt
isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
wait_isulad_running
@@ -70,6 +76,10 @@ function test_isula_update_normal()
function test_isula_update_abnormal()
{
+ local ret=0
+ local image="busybox"
+ local test="isulad update cpu realtime abnormal test => (${FUNCNAME[@]})"
+
#start isulad with cpu_rt
isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
wait_isulad_running
@@ -77,10 +87,10 @@ function test_isula_update_abnormal()
c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 950000 ${image} sh`
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
- isula update --cpu-rt-period 800000 --cpu-rt-runtime 900000 $c_id | grep "Invalid --cpu-rt-runtime: rt runtime cannot be higher than rt period"
+ isula update --cpu-rt-period 800000 --cpu-rt-runtime 900000 $c_id 2>&1 | grep "Invalid --cpu-rt-runtime: rt runtime cannot be higher than rt period"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to update container cpu-rt-runtime" && ((ret++))
- isula update --cpu-rt-runtime 1000000 $c_id | grep "updating cgroup cpu.rt_runtime_us to 1000000: Invalid argument"
+ isula update --cpu-rt-runtime 1000000 $c_id 2>&1 | grep "updating cgroup cpu.rt_runtime_us to 1000000: Invalid argument"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to update container cpu-rt-runtime" && ((ret++))
isula rm -f $c_id
@@ -158,17 +168,23 @@ function test_isula_run_abnormal()
isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 960000 $image /bin/sh 2>&1 | grep "failed to write 960000" | grep "cpu.rt_runtime_us: Invalid argument"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid argument for cpu-rt-runtime" && ((ret++))
- stop_isulad_without_valgrind
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
}
function test_isula_run_normal()
{
+ local ret=0
+ local image="busybox"
+
isula run -itd -n box --cpu-rt-period 1000000 --cpu-rt-runtime 900000 $image /bin/sh 2>&1
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container" && ((ret++))
isula rm -f box
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container ${c_id}" && ((ret++))
-
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
}
declare -i ans=0
@@ -183,4 +199,6 @@ else
test_kernel_without_cpurt || ((ans++))
fi
+isula rm -f $(isula ps -aq)
+
show_result ${ans} "${curr_path}/${0}"
--
2.25.1

54
0010-fix-cpu-rt-CI.patch Normal file
View File

@ -0,0 +1,54 @@
From 21dc648ef93cd0fb858a408bc843d25a5e20e320 Mon Sep 17 00:00:00 2001
From: songbuhuang <544824346@qq.com>
Date: Wed, 15 Feb 2023 16:09:38 +0800
Subject: [PATCH 10/22] fix cpu-rt CI
Signed-off-by: songbuhuang <544824346@qq.com>
---
CI/test_cases/container_cases/cpu_rt.sh | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/CI/test_cases/container_cases/cpu_rt.sh b/CI/test_cases/container_cases/cpu_rt.sh
index 42006bc8..39c0b427 100755
--- a/CI/test_cases/container_cases/cpu_rt.sh
+++ b/CI/test_cases/container_cases/cpu_rt.sh
@@ -50,14 +50,14 @@ function test_isula_update_normal()
isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
wait_isulad_running
- c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 950000 ${image} sh`
+ c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 1000 ${image} sh`
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
- isula update --cpu-rt-period 900000 --cpu-rt-runtime 800000 $c_id
+ isula update --cpu-rt-period 900000 --cpu-rt-runtime 2000 $c_id
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to update container cpu-rt-runtime" && ((ret++))
- isula exec -it $c_id sh -c "cat /sys/fs/cgroup/cpu/cpu.rt_runtime_us" | grep "800000"
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container cpu.rt_runtime_us: 800000" && ((ret++))
+ isula exec -it $c_id sh -c "cat /sys/fs/cgroup/cpu/cpu.rt_runtime_us" | grep "2000"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container cpu.rt_runtime_us: 2000" && ((ret++))
isula exec -it $c_id sh -c "cat /sys/fs/cgroup/cpu/cpu.rt_period_us" | grep "900000"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container cpu.rt_period_us: 900000" && ((ret++))
@@ -84,7 +84,7 @@ function test_isula_update_abnormal()
isulad --cpu-rt-period 1000000 --cpu-rt-runtime 950000 -l DEBUG > /dev/null 2>&1 &
wait_isulad_running
- c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 950000 ${image} sh`
+ c_id=`isula run -itd --cpu-rt-period 1000000 --cpu-rt-runtime 1000 ${image} sh`
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
isula update --cpu-rt-period 800000 --cpu-rt-runtime 900000 $c_id 2>&1 | grep "Invalid --cpu-rt-runtime: rt runtime cannot be higher than rt period"
@@ -177,7 +177,7 @@ function test_isula_run_normal()
local ret=0
local image="busybox"
- isula run -itd -n box --cpu-rt-period 1000000 --cpu-rt-runtime 900000 $image /bin/sh 2>&1
+ isula run -itd -n box --cpu-rt-period 1000000 --cpu-rt-runtime 1000 $image /bin/sh 2>&1
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container" && ((ret++))
isula rm -f box
--
2.25.1

View File

@ -0,0 +1,52 @@
From 933eceb4545a28dba44c72f183dc7104d0fea714 Mon Sep 17 00:00:00 2001
From: Xuepeng Xu <xuxuepeng1@huawei.com>
Date: Wed, 15 Feb 2023 12:19:40 +0800
Subject: [PATCH 11/22] Bugfix in config and executor
Signed-off-by: Xuepeng Xu <xuxuepeng1@huawei.com>
---
src/daemon/config/isulad_config.c | 2 +-
src/daemon/executor/container_cb/execution_create.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/daemon/config/isulad_config.c b/src/daemon/config/isulad_config.c
index 917e3eaa..38bf4bf9 100644
--- a/src/daemon/config/isulad_config.c
+++ b/src/daemon/config/isulad_config.c
@@ -314,7 +314,7 @@ char *conf_get_routine_rootdir(const char *runtime)
}
/* path = conf->rootpath + / + engines + / + runtime + /0 */
- if (strlen(conf->json_confs->graph) > (SIZE_MAX - strlen(ENGINE_ROOTPATH_NAME)) - 3) {
+ if (strlen(conf->json_confs->graph) > (SIZE_MAX - strlen(ENGINE_ROOTPATH_NAME) - strlen(runtime)) - 3) {
ERROR("Graph path is too long");
goto out;
}
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index cc9ae716..4cc333fd 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -533,7 +533,7 @@ static char *try_generate_id()
int i = 0;
int max_time = 10;
char *id = NULL;
- char *value = NULL;
+ container_t *value = NULL;
id = util_smart_calloc_s(sizeof(char), (CONTAINER_ID_MAX_LEN + 1));
if (id == NULL) {
@@ -547,9 +547,9 @@ static char *try_generate_id()
goto err_out;
}
- value = container_name_index_get(id);
+ value = containers_store_get(id);
if (value != NULL) {
- free(value);
+ container_unref(value);
value = NULL;
continue;
} else {
--
2.25.1

View File

@ -0,0 +1,823 @@
From 166edf2093b2c35fe4e479ca4b6568be8c98f907 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 15 Feb 2023 17:47:12 +0800
Subject: [PATCH 12/22] fix cpu-rt disable after reboot machine
1. ensure parent cgroup cpu-rt of container, should do in start container;
2. current do in create container, will cause failed of start container with cpu-rt after reboot machine
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/daemon/common/sysinfo.c | 46 +++-
src/daemon/common/sysinfo.h | 2 +
src/daemon/executor/container_cb/execution.c | 158 ++++++++++++-
.../executor/container_cb/execution_create.c | 222 +-----------------
src/daemon/modules/api/specs_api.h | 2 +-
src/daemon/modules/spec/specs.c | 84 ++++---
test/specs/specs/specs_ut.cc | 40 ++--
7 files changed, 280 insertions(+), 274 deletions(-)
diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c
index 38416db4..7559d653 100644
--- a/src/daemon/common/sysinfo.c
+++ b/src/daemon/common/sysinfo.c
@@ -24,8 +24,10 @@
#include <linux/magic.h>
#include <sys/stat.h>
+#include <isula_libutils/auto_cleanup.h>
+#include <isula_libutils/log.h>
+
#include "err_msg.h"
-#include "isula_libutils/log.h"
#include "utils.h"
#include "utils_array.h"
#include "utils_file.h"
@@ -1627,3 +1629,45 @@ free_out:
}
return minfos;
}
+
+char *sysinfo_cgroup_controller_cpurt_mnt_path()
+{
+ int nret = 0;
+ __isula_auto_free char *mnt = NULL;
+ __isula_auto_free char *root = NULL;
+ char fpath[PATH_MAX] = { 0 };
+ sysinfo_t *sysinfo = NULL;
+
+ sysinfo = get_sys_info(true);
+ if (sysinfo == NULL) {
+ ERROR("Can not get system info");
+ return NULL;
+ }
+
+ if (!(sysinfo->cgcpuinfo.cpu_rt_period)) {
+ ERROR("Daemon-scoped cpu-rt-period and cpu-rt-runtime are not supported by kernel");
+ isulad_set_error_message("Daemon-scoped cpu-rt-period and cpu-rt-runtime are not supported by kernel");
+ return NULL;
+ }
+
+ nret = find_cgroup_mountpoint_and_root("cpu", &mnt, &root);
+ if (nret != 0 || mnt == NULL || root == NULL) {
+ ERROR("Can not find cgroup mnt and root path for subsystem 'cpu'");
+ isulad_set_error_message("Can not find cgroup mnt and root path for subsystem 'cpu'");
+ return NULL;
+ }
+
+ // When iSulad is run inside docker, the root is based of the host cgroup.
+ // Replace root to "/"
+ if (strncmp(root, "/docker/", strlen("/docker/")) == 0) {
+ root[1] = '\0';
+ }
+
+ nret = snprintf(fpath, sizeof(fpath), "%s/%s", mnt, root);
+ if (nret < 0 || (size_t)nret >= sizeof(fpath)) {
+ ERROR("Failed to print string");
+ return NULL;
+ }
+
+ return util_strdup_s(fpath);
+}
\ No newline at end of file
diff --git a/src/daemon/common/sysinfo.h b/src/daemon/common/sysinfo.h
index 8468e00a..bbb3c6b5 100644
--- a/src/daemon/common/sysinfo.h
+++ b/src/daemon/common/sysinfo.h
@@ -139,6 +139,8 @@ mountinfo_t *find_mount_info(mountinfo_t **minfos, const char *dir);
void free_mounts_info(mountinfo_t **minfos);
+char *sysinfo_cgroup_controller_cpurt_mnt_path();
+
#ifdef __cplusplus
}
#endif
diff --git a/src/daemon/executor/container_cb/execution.c b/src/daemon/executor/container_cb/execution.c
index 7b18a8e1..ed70fc14 100644
--- a/src/daemon/executor/container_cb/execution.c
+++ b/src/daemon/executor/container_cb/execution.c
@@ -18,6 +18,12 @@
#include <pthread.h>
#include <malloc.h>
#include <sys/eventfd.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+
#include <isula_libutils/container_config.h>
#include <isula_libutils/container_config_v2.h>
#include <isula_libutils/container_delete_request.h>
@@ -34,13 +40,13 @@
#include <isula_libutils/container_stop_request.h>
#include <isula_libutils/container_stop_response.h>
#include <isula_libutils/json_common.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
+#include <isula_libutils/auto_cleanup.h>
+#include <isula_libutils/log.h>
-#include "isula_libutils/log.h"
+#include "isulad_config.h"
+#include "sysinfo.h"
#include "container_api.h"
+#include "specs_api.h"
#include "execution_extend.h"
#include "execution_information.h"
#include "execution_stream.h"
@@ -302,6 +308,135 @@ static void pack_start_response(container_start_response *response, uint32_t cc,
}
}
+static int do_init_cpurt_cgroups_path(const char *path, int recursive_depth, const char *mnt_root,
+ int64_t cpu_rt_period, int64_t cpu_rt_runtime);
+
+/* maybe create cpu realtime file */
+static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const char *path)
+{
+ int ret;
+ __isula_auto_close int fd = -1;
+ ssize_t nwrite;
+ char fpath[PATH_MAX] = { 0 };
+ char buf[ISULAD_NUMSTRLEN64] = { 0 };
+
+ if (value == 0) {
+ return 0;
+ }
+
+ ret = util_mkdir_p(path, CONFIG_DIRECTORY_MODE);
+ if (ret != 0) {
+ ERROR("Failed to mkdir: %s", path);
+ return -1;
+ }
+
+ ret = snprintf(fpath, sizeof(fpath), "%s/%s", path, file);
+ if (ret < 0 || ret >= sizeof(fpath)) {
+ ERROR("Failed to print string");
+ return -1;
+ }
+ ret = snprintf(buf, sizeof(buf), "%lld", (long long int)value);
+ if (ret < 0 || (size_t)ret >= sizeof(buf)) {
+ ERROR("Failed to print string");
+ return -1;
+ }
+
+ fd = util_open(fpath, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0700);
+ if (fd < 0) {
+ ERROR("Failed to open file: %s: %s", fpath, strerror(errno));
+ isulad_set_error_message("Failed to open file: %s: %s", fpath, strerror(errno));
+ return -1;
+ }
+ nwrite = util_write_nointr(fd, buf, strlen(buf));
+ if (nwrite < 0 || nwrite != strlen(buf)) {
+ ERROR("Failed to write %s to %s: %s", buf, fpath, strerror(errno));
+ isulad_set_error_message("Failed to write '%s' to '%s': %s", buf, fpath, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int recursively_create_cgroup(const char *path, const char *mnt_root, int recursive_depth, int64_t cpu_rt_period,
+ int64_t cpu_rt_runtime)
+{
+ int ret = 0;
+ __isula_auto_free char *dup = NULL;
+ char *dirpath = NULL;
+ char fpath[PATH_MAX] = { 0 };
+
+ dup = util_strdup_s(path);
+ dirpath = dirname(dup);
+ ret = do_init_cpurt_cgroups_path(dirpath, (recursive_depth + 1), mnt_root, cpu_rt_period, cpu_rt_runtime);
+ if (ret != 0) {
+ return ret;
+ }
+
+ int nret = snprintf(fpath, sizeof(fpath), "%s/%s", mnt_root, path);
+ if (nret < 0 || (size_t)nret >= sizeof(fpath)) {
+ ERROR("Failed to print string");
+ return ret;
+ }
+
+ ret = maybe_create_cpu_realtime_file(cpu_rt_period, "cpu.rt_period_us", fpath);
+ if (ret != 0) {
+ return ret;
+ }
+
+ return maybe_create_cpu_realtime_file(cpu_rt_runtime, "cpu.rt_runtime_us", fpath);
+}
+
+/* init cgroups path */
+static int do_init_cpurt_cgroups_path(const char *path, int recursive_depth, const char *mnt_root,
+ int64_t cpu_rt_period, int64_t cpu_rt_runtime)
+{
+ if ((recursive_depth + 1) > MAX_PATH_DEPTH) {
+ ERROR("Reach the max cgroup depth:%s", path);
+ return -1;
+ }
+
+ if (path == NULL || strcmp(path, "/") == 0 || strcmp(path, ".") == 0) {
+ return 0;
+ }
+
+ // Recursively create cgroup to ensure that the system and all parent cgroups have values set
+ // for the period and runtime as this limits what the children can be set to.
+ return recursively_create_cgroup(path, mnt_root, recursive_depth, cpu_rt_period, cpu_rt_runtime);
+}
+
+// TODO: maybe we should adapt to cgroup v2
+static int cpurt_controller_init(const char *id, const host_config *host_spec)
+{
+ __isula_auto_free char *mnt_root = NULL;
+ __isula_auto_free char *cgroups_path = NULL;
+ char *dirpath = NULL;
+ int64_t cpu_rt_period = 0;
+ int64_t cpu_rt_runtime = 0;
+
+ cgroups_path = merge_container_cgroups_path(id, host_spec);
+ if (cgroups_path == NULL || strcmp(cgroups_path, "/") == 0 || strcmp(cgroups_path, ".") == 0) {
+ return 0;
+ }
+
+ if (conf_get_cgroup_cpu_rt(&cpu_rt_period, &cpu_rt_runtime)) {
+ return -1;
+ }
+
+ if (cpu_rt_period == 0 && cpu_rt_runtime == 0) {
+ return 0;
+ }
+
+ mnt_root = sysinfo_cgroup_controller_cpurt_mnt_path();
+ if (mnt_root == NULL) {
+ ERROR("Failed to get cpu rt controller mnt root path");
+ return -1;
+ }
+
+ dirpath = dirname(cgroups_path);
+
+ return do_init_cpurt_cgroups_path(dirpath, 0, mnt_root, cpu_rt_period, cpu_rt_runtime);
+}
+
static int container_start_prepare(container_t *cont, const container_start_request *request, int stdinfd,
struct io_write_wrapper *stdout_handler, struct io_write_wrapper *stderr_handler,
char **fifopath, char *fifos[], int *sync_fd, pthread_t *thread_id)
@@ -314,6 +449,19 @@ static int container_start_prepare(container_t *cont, const container_start_requ
return -1;
}
+ // init cgroup path for cpu_rt_runtime and cpu_rt_period
+ // we should do this in start container, not create container
+ // because, in scenarios:
+ // 1. enable cpu-rt of isulad;
+ // 2. then run container with --cpu-rt-runtime
+ // 3. then reboot machine;
+ // 4. finally, start before container, it will failed...
+ // cause of no one to set value into cgroup/isulad/cpu-rt-runtime and cpu-rt-period.
+ if (cpurt_controller_init(id, cont->hostconfig) != 0) {
+ isulad_set_error_message("Failed to init controller of cpu-rt for container \"%s\".", id);
+ return -1;
+ }
+
if (prepare_start_io(cont, request, fifopath, fifos, stdinfd, stdout_handler, stderr_handler, sync_fd, thread_id) !=
0) {
return -1;
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index 4cc333fd..4abc89c7 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -19,6 +19,14 @@
#include <errno.h>
#include <sys/stat.h>
#include <malloc.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <isula_libutils/log.h>
+#include <isula_libutils/auto_cleanup.h>
#include <isula_libutils/container_config.h>
#include <isula_libutils/container_config_v2.h>
#include <isula_libutils/defs.h>
@@ -26,14 +34,7 @@
#include <isula_libutils/isulad_daemon_configs.h>
#include <isula_libutils/json_common.h>
#include <isula_libutils/oci_runtime_spec.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <libgen.h>
-#include "isula_libutils/log.h"
#include "isulad_config.h"
#include "specs_api.h"
#include "verify.h"
@@ -58,9 +59,6 @@
#include "opt_log.h"
#include "runtime_api.h"
-static int do_init_cpurt_cgroups_path(const char *path, int recursive_depth, const char *mnt_root,
- int64_t cpu_rt_period, int64_t cpu_rt_runtime);
-
static int create_request_check(const container_create_request *request)
{
int ret = 0;
@@ -1323,203 +1321,6 @@ static int save_container_config_before_create(const char *id, const char *runti
return 0;
}
-/* maybe create cpu realtime file */
-static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const char *path)
-{
- int ret;
- int fd = -1;
- ssize_t nwrite;
- char fpath[PATH_MAX] = { 0 };
- char buf[ISULAD_NUMSTRLEN64] = { 0 };
-
- if (value == 0) {
- return 0;
- }
-
- ret = util_mkdir_p(path, CONFIG_DIRECTORY_MODE);
- if (ret != 0) {
- ERROR("Failed to mkdir: %s", path);
- return -1;
- }
-
- ret = snprintf(fpath, sizeof(fpath), "%s/%s", path, file);
- if (ret < 0 || ret >= sizeof(fpath)) {
- ERROR("Failed to print string");
- return -1;
- }
- ret = snprintf(buf, sizeof(buf), "%lld", (long long int)value);
- if (ret < 0 || (size_t)ret >= sizeof(buf)) {
- ERROR("Failed to print string");
- return -1;
- }
-
- fd = util_open(fpath, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0700);
- if (fd < 0) {
- ERROR("Failed to open file: %s: %s", fpath, strerror(errno));
- isulad_set_error_message("Failed to open file: %s: %s", fpath, strerror(errno));
- return -1;
- }
- nwrite = util_write_nointr(fd, buf, strlen(buf));
- if (nwrite < 0) {
- ERROR("Failed to write %s to %s: %s", buf, fpath, strerror(errno));
- isulad_set_error_message("Failed to write '%s' to '%s': %s", buf, fpath, strerror(errno));
- close(fd);
- return -1;
- }
- close(fd);
-
- return 0;
-}
-
-static int recursively_create_cgroup(const char *path, const char *mnt_root, int recursive_depth, int64_t cpu_rt_period,
- int64_t cpu_rt_runtime)
-{
- int ret = 0;
- char *dup = NULL;
- char *dirpath = NULL;
- char fpath[PATH_MAX] = { 0 };
-
- dup = util_strdup_s(path);
- dirpath = dirname(dup);
- ret = do_init_cpurt_cgroups_path(dirpath, (recursive_depth + 1), mnt_root, cpu_rt_period, cpu_rt_runtime);
- free(dup);
- if (ret != 0) {
- return ret;
- }
-
- int nret = snprintf(fpath, sizeof(fpath), "%s/%s", mnt_root, path);
- if (nret < 0 || (size_t)nret >= sizeof(fpath)) {
- ERROR("Failed to print string");
- ret = -1;
- goto out;
- }
-
- ret = maybe_create_cpu_realtime_file(cpu_rt_period, "cpu.rt_period_us", fpath);
- if (ret != 0) {
- goto out;
- }
-
- ret = maybe_create_cpu_realtime_file(cpu_rt_runtime, "cpu.rt_runtime_us", fpath);
- if (ret != 0) {
- goto out;
- }
-
-out:
- return ret;
-}
-
-/* init cgroups path */
-static int do_init_cpurt_cgroups_path(const char *path, int recursive_depth, const char *mnt_root,
- int64_t cpu_rt_period, int64_t cpu_rt_runtime)
-{
- if ((recursive_depth + 1) > MAX_PATH_DEPTH) {
- ERROR("Reach the max cgroup depth:%s", path);
- return -1;
- }
-
- if (path == NULL || strcmp(path, "/") == 0 || strcmp(path, ".") == 0) {
- return 0;
- }
-
- // Recursively create cgroup to ensure that the system and all parent cgroups have values set
- // for the period and runtime as this limits what the children can be set to.
- if (recursively_create_cgroup(path, mnt_root, recursive_depth, cpu_rt_period, cpu_rt_runtime)) {
- return -1;
- }
-
- return 0;
-}
-
-static char *get_cpurt_controller_mnt_path()
-{
- char *res = NULL;
- int nret = 0;
- char *mnt = NULL;
- char *root = NULL;
- char fpath[PATH_MAX] = { 0 };
-
- nret = find_cgroup_mountpoint_and_root("cpu", &mnt, &root);
- if (nret != 0 || mnt == NULL || root == NULL) {
- ERROR("Can not find cgroup mnt and root path for subsystem 'cpu'");
- isulad_set_error_message("Can not find cgroup mnt and root path for subsystem 'cpu'");
- goto out;
- }
-
- // When iSulad is run inside docker, the root is based of the host cgroup.
- // Replace root to "/"
- if (strncmp(root, "/docker/", strlen("/docker/")) == 0) {
- root[1] = '\0';
- }
-
- nret = snprintf(fpath, sizeof(fpath), "%s/%s", mnt, root);
- if (nret < 0 || (size_t)nret >= sizeof(fpath)) {
- ERROR("Failed to print string");
- goto out;
- }
-
- res = util_strdup_s(fpath);
-
-out:
- free(mnt);
- free(root);
- return res;
-}
-
-static int cpurt_controller_init(const char *cgroups_path)
-{
- int ret = 0;
- char *dup = NULL;
- char *dirpath = NULL;
- int64_t cpu_rt_period = 0;
- int64_t cpu_rt_runtime = 0;
- sysinfo_t *sysinfo = NULL;
- char *mnt_root = NULL;
-
- if (cgroups_path == NULL || strcmp(cgroups_path, "/") == 0 || strcmp(cgroups_path, ".") == 0) {
- return 0;
- }
-
- if (conf_get_cgroup_cpu_rt(&cpu_rt_period, &cpu_rt_runtime)) {
- return -1;
- }
-
- if (cpu_rt_period == 0 && cpu_rt_runtime == 0) {
- return 0;
- }
-
- sysinfo = get_sys_info(true);
- if (sysinfo == NULL) {
- ERROR("Can not get system info");
- ret = -1;
- goto out;
- }
-
- if (!(sysinfo->cgcpuinfo.cpu_rt_period)) {
- ERROR("Daemon-scoped cpu-rt-period and cpu-rt-runtime are not supported by kernel");
- isulad_set_error_message("Daemon-scoped cpu-rt-period and cpu-rt-runtime are not supported by kernel");
- ret = -1;
- goto out;
- }
-
- mnt_root = get_cpurt_controller_mnt_path();
- if (mnt_root == NULL) {
- ERROR("Failed to get cpu rt controller mnt root path");
- isulad_set_error_message("Failed to get cpu rt controller mnt root path");
- ret = -1;
- goto out;
- }
-
- dup = util_strdup_s(cgroups_path);
- dirpath = dirname(dup);
-
- ret = do_init_cpurt_cgroups_path(dirpath, 0, mnt_root, cpu_rt_period, cpu_rt_runtime);
-
-out:
- free(mnt_root);
- free(dup);
- return ret;
-}
-
/*
* request -> host_spec + container_spec
* container_spec + image config
@@ -1680,13 +1481,6 @@ int container_create_cb(const container_create_request *request, container_creat
goto umount_channel;
}
- // init cgroup path for cpu_rt_runtime and cpu_rt_period
- if (cpurt_controller_init(oci_spec->linux->cgroups_path) != 0) {
- ERROR("Unable to init CPU RT controller %s", oci_spec->linux->cgroups_path);
- cc = ISULAD_ERR_EXEC;
- goto umount_channel;
- }
-
if (container_v2_spec_merge_contaner_spec(v2_spec) != 0) {
ERROR("Failed to merge container settings");
cc = ISULAD_ERR_EXEC;
diff --git a/src/daemon/modules/api/specs_api.h b/src/daemon/modules/api/specs_api.h
index 4c132108..e0a73f55 100644
--- a/src/daemon/modules/api/specs_api.h
+++ b/src/daemon/modules/api/specs_api.h
@@ -28,7 +28,7 @@ extern "C" {
int merge_all_specs(host_config *host_spec, const char *real_rootfs, container_config_v2_common_config *v2_spec,
oci_runtime_spec *oci_spec);
-int merge_oci_cgroups_path(const char *id, oci_runtime_spec *oci_spec, const host_config *host_spec);
+char *merge_container_cgroups_path(const char *id, const host_config *host_spec);
int merge_global_config(oci_runtime_spec *oci_spec);
oci_runtime_spec *load_oci_config(const char *rootpath, const char *name);
oci_runtime_spec *default_spec(bool system_container);
diff --git a/src/daemon/modules/spec/specs.c b/src/daemon/modules/spec/specs.c
index 12d9b96d..857fc3dc 100644
--- a/src/daemon/modules/spec/specs.c
+++ b/src/daemon/modules/spec/specs.c
@@ -26,6 +26,7 @@
#include <isula_libutils/oci_runtime_hooks.h>
#include <isula_libutils/host_config.h>
#include <isula_libutils/log.h>
+#include <isula_libutils/auto_cleanup.h>
#include <limits.h>
#include <stdint.h>
@@ -165,36 +166,43 @@ out:
return ret;
}
-static int make_annotations_cgroup_dir(const container_config *container_spec, const host_config *host_spec)
+static char *do_get_container_cgroup_path(const host_config *host_spec)
{
- int ret = 0;
- char cleaned[PATH_MAX] = { 0 };
- char *default_cgroup_parent = NULL;
char *path = NULL;
- default_cgroup_parent = conf_get_isulad_cgroup_parent();
if (host_spec->cgroup_parent != NULL) {
- path = host_spec->cgroup_parent;
- } else if (default_cgroup_parent != NULL) {
- path = default_cgroup_parent;
+ // first, use user setting
+ path = util_strdup_s(host_spec->cgroup_parent);
+ } else {
+ // second, if user donot set, use setting from daemon config
+ path = conf_get_isulad_cgroup_parent();
}
+
if (path == NULL) {
- path = "/isulad";
+ // third, all faild, just use default '/isulad'
+ path = util_strdup_s("/isulad");
}
+
+ return path;
+}
+
+static int make_annotations_cgroup_dir(const container_config *container_spec, const host_config *host_spec)
+{
+ char cleaned[PATH_MAX] = { 0 };
+ __isula_auto_free char *path = NULL;
+
+ path = do_get_container_cgroup_path(host_spec);
if (util_clean_path(path, cleaned, sizeof(cleaned)) == NULL) {
ERROR("Failed to clean path: %s", path);
- ret = -1;
- goto out;
+ return -1;
}
+
if (append_json_map_string_string(container_spec->annotations, "cgroup.dir", cleaned)) {
ERROR("Realloc annotations failed");
- ret = -1;
- goto out;
+ return -1;
}
-out:
- free(default_cgroup_parent);
- return ret;
+ return 0;
}
static int make_annotations_oom_score_adj(const container_config *container_spec, const host_config *host_spec)
@@ -2058,42 +2066,40 @@ out:
return ret;
}
-int merge_oci_cgroups_path(const char *id, oci_runtime_spec *oci_spec, const host_config *host_spec)
+char *merge_container_cgroups_path(const char *id, const host_config *host_spec)
{
- int ret = 0;
- char *default_cgroup_parent = NULL;
- char *path = NULL;
+ __isula_auto_free char *path = NULL;
+ if (id == NULL || host_spec == NULL) {
+ ERROR("Invalid arguments");
+ return NULL;
+ }
+
+ path = do_get_container_cgroup_path(host_spec);
+
+ return util_path_join(path, id);
+}
+
+static int merge_oci_cgroups_path(const char *id, oci_runtime_spec *oci_spec, const host_config *host_spec)
+{
if (id == NULL || oci_spec == NULL || host_spec == NULL) {
ERROR("Invalid arguments");
- ret = -1;
- goto out;
+ return -1;
}
if (make_sure_oci_spec_linux(oci_spec) != 0) {
ERROR("Failed to make oci spec linux");
- ret = -1;
- goto out;
+ return -1;
}
- default_cgroup_parent = conf_get_isulad_cgroup_parent();
- path = default_cgroup_parent;
- if (host_spec->cgroup_parent != NULL) {
- path = host_spec->cgroup_parent;
- }
+ free(oci_spec->linux->cgroups_path);
+ oci_spec->linux->cgroups_path = merge_container_cgroups_path(id, host_spec);
- if (path == NULL) {
- free(oci_spec->linux->cgroups_path);
- oci_spec->linux->cgroups_path = util_path_join("/isulad", id);
- return 0;
+ if (oci_spec->linux->cgroups_path == NULL) {
+ WARN("OCI spec cgroups path is NULL");
}
- free(oci_spec->linux->cgroups_path);
- oci_spec->linux->cgroups_path = util_path_join(path, id);
-
-out:
- free(default_cgroup_parent);
- return ret;
+ return 0;
}
int merge_all_specs(host_config *host_spec, const char *real_rootfs, container_config_v2_common_config *v2_spec,
diff --git a/test/specs/specs/specs_ut.cc b/test/specs/specs/specs_ut.cc
index c4014e2e..96aa1c63 100644
--- a/test/specs/specs/specs_ut.cc
+++ b/test/specs/specs/specs_ut.cc
@@ -232,15 +232,16 @@ char *invoke_conf_get_isulad_cgroup_parent()
return util_strdup_s("/var/lib/isulad/engines/lcr");
}
-TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_1)
+TEST_F(SpecsUnitTest, test_merge_container_cgroups_path_1)
{
- ASSERT_EQ(merge_oci_cgroups_path(nullptr, nullptr, nullptr), -1);
+ ASSERT_EQ(merge_container_cgroups_path(nullptr, nullptr), nullptr);
}
-TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_2)
+TEST_F(SpecsUnitTest, test_merge_container_cgroups_path_2)
{
oci_runtime_spec *oci_spec = nullptr;
host_config *host_spec = nullptr;
+ char *merged_cp = nullptr;
oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != nullptr);
@@ -250,20 +251,23 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_2)
EXPECT_CALL(m_isulad_conf, GetCgroupParent()).WillRepeatedly(Invoke(invoke_conf_get_isulad_cgroup_parent_null));
- ASSERT_EQ(merge_oci_cgroups_path("123", oci_spec, host_spec), 0);
+ merged_cp = merge_container_cgroups_path("123", host_spec);
+ ASSERT_NE(merged_cp, nullptr);
- ASSERT_STREQ(oci_spec->linux->cgroups_path, "/isulad/123");
+ ASSERT_STREQ(merged_cp, "/isulad/123");
free_oci_runtime_spec(oci_spec);
free_host_config(host_spec);
+ free(merged_cp);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
-TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_3)
+TEST_F(SpecsUnitTest, test_merge_container_cgroups_path_3)
{
oci_runtime_spec *oci_spec = nullptr;
host_config *host_spec = nullptr;
+ char *merged_cp = nullptr;
oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != nullptr);
@@ -275,20 +279,23 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_3)
EXPECT_CALL(m_isulad_conf, GetCgroupParent()).WillRepeatedly(Invoke(invoke_conf_get_isulad_cgroup_parent_null));
- ASSERT_EQ(merge_oci_cgroups_path("123", oci_spec, host_spec), 0);
+ merged_cp = merge_container_cgroups_path("123", host_spec);
+ ASSERT_NE(merged_cp, nullptr);
- ASSERT_STREQ(oci_spec->linux->cgroups_path, "/test/123");
+ ASSERT_STREQ(merged_cp, "/test/123");
free_oci_runtime_spec(oci_spec);
free_host_config(host_spec);
+ free(merged_cp);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
-TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_4)
+TEST_F(SpecsUnitTest, test_merge_container_cgroups_path_4)
{
oci_runtime_spec *oci_spec = nullptr;
host_config *host_spec = nullptr;
+ char *merged_cp = nullptr;
oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != nullptr);
@@ -298,20 +305,23 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_4)
EXPECT_CALL(m_isulad_conf, GetCgroupParent()).WillRepeatedly(Invoke(invoke_conf_get_isulad_cgroup_parent));
- ASSERT_EQ(merge_oci_cgroups_path("123", oci_spec, host_spec), 0);
+ merged_cp = merge_container_cgroups_path("123", host_spec);
+ ASSERT_NE(merged_cp, nullptr);
- ASSERT_STREQ(oci_spec->linux->cgroups_path, "/var/lib/isulad/engines/lcr/123");
+ ASSERT_STREQ(merged_cp, "/var/lib/isulad/engines/lcr/123");
free_oci_runtime_spec(oci_spec);
free_host_config(host_spec);
+ free(merged_cp);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
-TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_5)
+TEST_F(SpecsUnitTest, test_merge_container_cgroups_path_5)
{
oci_runtime_spec *oci_spec = nullptr;
host_config *host_spec = nullptr;
+ char *merged_cp = nullptr;
oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != nullptr);
@@ -323,12 +333,14 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_5)
EXPECT_CALL(m_isulad_conf, GetCgroupParent()).WillRepeatedly(Invoke(invoke_conf_get_isulad_cgroup_parent));
- ASSERT_EQ(merge_oci_cgroups_path("123", oci_spec, host_spec), 0);
+ merged_cp = merge_container_cgroups_path("123", host_spec);
+ ASSERT_NE(merged_cp, nullptr);
- ASSERT_STREQ(oci_spec->linux->cgroups_path, "/test/123");
+ ASSERT_STREQ(merged_cp, "/test/123");
free_oci_runtime_spec(oci_spec);
free_host_config(host_spec);
+ free(merged_cp);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
--
2.25.1

View File

@ -0,0 +1,465 @@
From af8fb9fcf604775f527b58e1b02f220dffd8ff35 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Thu, 16 Feb 2023 15:26:10 +0800
Subject: [PATCH 13/22] fix selinux_label_ut timeout and add timeout for all ut
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
test/cgroup/cpu/CMakeLists.txt | 1 +
test/cmd/isula/extend/pause/CMakeLists.txt | 1 +
test/cmd/isula/extend/resume/CMakeLists.txt | 2 +-
test/cmd/isula/information/info/CMakeLists.txt | 1 +
test/cmd/isula/information/ps/CMakeLists.txt | 1 +
test/cmd/isula/utils/client_show_format/CMakeLists.txt | 1 +
test/cmd/isula/utils/template_string_parse/CMakeLists.txt | 1 +
test/cmd/isulad-shim/CMakeLists.txt | 1 +
test/cutils/mainloop/CMakeLists.txt | 1 +
test/cutils/map/CMakeLists.txt | 1 +
test/cutils/path/CMakeLists.txt | 1 +
test/cutils/util_atomic/CMakeLists.txt | 1 +
test/cutils/utils_aes/CMakeLists.txt | 1 +
test/cutils/utils_array/CMakeLists.txt | 1 +
test/cutils/utils_base64/CMakeLists.txt | 1 +
test/cutils/utils_convert/CMakeLists.txt | 1 +
test/cutils/utils_error/CMakeLists.txt | 1 +
test/cutils/utils_file/CMakeLists.txt | 1 +
test/cutils/utils_filters/CMakeLists.txt | 1 +
test/cutils/utils_fs/CMakeLists.txt | 1 +
test/cutils/utils_mount_spec/CMakeLists.txt | 1 +
test/cutils/utils_namespace/CMakeLists.txt | 1 +
test/cutils/utils_network/CMakeLists.txt | 1 +
test/cutils/utils_pwgr/CMakeLists.txt | 1 +
test/cutils/utils_regex/CMakeLists.txt | 1 +
test/cutils/utils_string/CMakeLists.txt | 1 +
test/cutils/utils_timestamp/CMakeLists.txt | 1 +
test/cutils/utils_utils/CMakeLists.txt | 1 +
test/cutils/utils_verify/CMakeLists.txt | 1 +
test/image/oci/oci_config_merge/CMakeLists.txt | 1 +
test/image/oci/registry/CMakeLists.txt | 1 +
test/image/oci/storage/images/CMakeLists.txt | 1 +
test/image/oci/storage/layers/CMakeLists.txt | 2 ++
test/image/oci/storage/rootfs/CMakeLists.txt | 1 +
test/network/CMakeLists.txt | 1 +
test/runtime/isula/CMakeLists.txt | 1 +
test/runtime/lcr/CMakeLists.txt | 1 +
.../services/execution/execute/execution_extend/CMakeLists.txt | 1 +
test/services/execution/spec/CMakeLists.txt | 2 ++
test/services/execution/spec/selinux_label_ut.cc | 2 ++
test/specs/specs/CMakeLists.txt | 1 +
test/specs/specs_extend/CMakeLists.txt | 1 +
test/volume/CMakeLists.txt | 3 ++-
43 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/test/cgroup/cpu/CMakeLists.txt b/test/cgroup/cpu/CMakeLists.txt
index 159b0d85..6a8af719 100644
--- a/test/cgroup/cpu/CMakeLists.txt
+++ b/test/cgroup/cpu/CMakeLists.txt
@@ -26,3 +26,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isula/extend/pause/CMakeLists.txt b/test/cmd/isula/extend/pause/CMakeLists.txt
index af48c23f..6eab5172 100644
--- a/test/cmd/isula/extend/pause/CMakeLists.txt
+++ b/test/cmd/isula/extend/pause/CMakeLists.txt
@@ -47,3 +47,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isula/extend/resume/CMakeLists.txt b/test/cmd/isula/extend/resume/CMakeLists.txt
index 729c4d3b..0812a66e 100644
--- a/test/cmd/isula/extend/resume/CMakeLists.txt
+++ b/test/cmd/isula/extend/resume/CMakeLists.txt
@@ -48,4 +48,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
-
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isula/information/info/CMakeLists.txt b/test/cmd/isula/information/info/CMakeLists.txt
index 2f134986..d8d8ddb7 100644
--- a/test/cmd/isula/information/info/CMakeLists.txt
+++ b/test/cmd/isula/information/info/CMakeLists.txt
@@ -49,3 +49,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isula/information/ps/CMakeLists.txt b/test/cmd/isula/information/ps/CMakeLists.txt
index 81d4202c..436e611b 100644
--- a/test/cmd/isula/information/ps/CMakeLists.txt
+++ b/test/cmd/isula/information/ps/CMakeLists.txt
@@ -51,3 +51,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isula/utils/client_show_format/CMakeLists.txt b/test/cmd/isula/utils/client_show_format/CMakeLists.txt
index 60d538ad..e19332cf 100644
--- a/test/cmd/isula/utils/client_show_format/CMakeLists.txt
+++ b/test/cmd/isula/utils/client_show_format/CMakeLists.txt
@@ -19,3 +19,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isula/utils/template_string_parse/CMakeLists.txt b/test/cmd/isula/utils/template_string_parse/CMakeLists.txt
index 32256b6b..25efd25c 100644
--- a/test/cmd/isula/utils/template_string_parse/CMakeLists.txt
+++ b/test/cmd/isula/utils/template_string_parse/CMakeLists.txt
@@ -19,3 +19,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cmd/isulad-shim/CMakeLists.txt b/test/cmd/isulad-shim/CMakeLists.txt
index 1c2de232..dc293f6d 100644
--- a/test/cmd/isulad-shim/CMakeLists.txt
+++ b/test/cmd/isulad-shim/CMakeLists.txt
@@ -30,3 +30,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/mainloop/CMakeLists.txt b/test/cutils/mainloop/CMakeLists.txt
index 78e3f18d..61ea7ffc 100644
--- a/test/cutils/mainloop/CMakeLists.txt
+++ b/test/cutils/mainloop/CMakeLists.txt
@@ -25,3 +25,4 @@ target_link_libraries(${EXE}
libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/map/CMakeLists.txt b/test/cutils/map/CMakeLists.txt
index 4059559f..bd21ee3f 100644
--- a/test/cutils/map/CMakeLists.txt
+++ b/test/cutils/map/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/path/CMakeLists.txt b/test/cutils/path/CMakeLists.txt
index 745258a1..aa0c6c6e 100644
--- a/test/cutils/path/CMakeLists.txt
+++ b/test/cutils/path/CMakeLists.txt
@@ -15,3 +15,4 @@ target_include_directories(${EXE} PUBLIC
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,getcwd -Wl,--wrap,readlink")
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/util_atomic/CMakeLists.txt b/test/cutils/util_atomic/CMakeLists.txt
index 071b2a04..21b05c46 100644
--- a/test/cutils/util_atomic/CMakeLists.txt
+++ b/test/cutils/util_atomic/CMakeLists.txt
@@ -16,3 +16,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_aes/CMakeLists.txt b/test/cutils/utils_aes/CMakeLists.txt
index f7535bb3..c4d175c8 100644
--- a/test/cutils/utils_aes/CMakeLists.txt
+++ b/test/cutils/utils_aes/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_array/CMakeLists.txt b/test/cutils/utils_array/CMakeLists.txt
index 71733e31..afe564bf 100644
--- a/test/cutils/utils_array/CMakeLists.txt
+++ b/test/cutils/utils_array/CMakeLists.txt
@@ -16,3 +16,4 @@ target_include_directories(${EXE} PUBLIC
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc")
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_base64/CMakeLists.txt b/test/cutils/utils_base64/CMakeLists.txt
index d5b99361..35e6ba04 100644
--- a/test/cutils/utils_base64/CMakeLists.txt
+++ b/test/cutils/utils_base64/CMakeLists.txt
@@ -15,3 +15,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_convert/CMakeLists.txt b/test/cutils/utils_convert/CMakeLists.txt
index 30068208..fcf70a7c 100644
--- a/test/cutils/utils_convert/CMakeLists.txt
+++ b/test/cutils/utils_convert/CMakeLists.txt
@@ -15,3 +15,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_error/CMakeLists.txt b/test/cutils/utils_error/CMakeLists.txt
index 28016605..9607aeeb 100644
--- a/test/cutils/utils_error/CMakeLists.txt
+++ b/test/cutils/utils_error/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_file/CMakeLists.txt b/test/cutils/utils_file/CMakeLists.txt
index 20317e15..01b2ff47 100644
--- a/test/cutils/utils_file/CMakeLists.txt
+++ b/test/cutils/utils_file/CMakeLists.txt
@@ -16,3 +16,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_filters/CMakeLists.txt b/test/cutils/utils_filters/CMakeLists.txt
index 31d3ac25..561ff4ef 100644
--- a/test/cutils/utils_filters/CMakeLists.txt
+++ b/test/cutils/utils_filters/CMakeLists.txt
@@ -16,3 +16,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_fs/CMakeLists.txt b/test/cutils/utils_fs/CMakeLists.txt
index 7ff3176a..e909aee6 100644
--- a/test/cutils/utils_fs/CMakeLists.txt
+++ b/test/cutils/utils_fs/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_mount_spec/CMakeLists.txt b/test/cutils/utils_mount_spec/CMakeLists.txt
index 24fb5add..099805d2 100644
--- a/test/cutils/utils_mount_spec/CMakeLists.txt
+++ b/test/cutils/utils_mount_spec/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_namespace/CMakeLists.txt b/test/cutils/utils_namespace/CMakeLists.txt
index 8add4a71..fb535e71 100644
--- a/test/cutils/utils_namespace/CMakeLists.txt
+++ b/test/cutils/utils_namespace/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_network/CMakeLists.txt b/test/cutils/utils_network/CMakeLists.txt
index cf0fc481..22e421ab 100644
--- a/test/cutils/utils_network/CMakeLists.txt
+++ b/test/cutils/utils_network/CMakeLists.txt
@@ -20,3 +20,4 @@ target_link_libraries(${EXE}
libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_pwgr/CMakeLists.txt b/test/cutils/utils_pwgr/CMakeLists.txt
index 5938991e..34acb92a 100644
--- a/test/cutils/utils_pwgr/CMakeLists.txt
+++ b/test/cutils/utils_pwgr/CMakeLists.txt
@@ -15,3 +15,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_regex/CMakeLists.txt b/test/cutils/utils_regex/CMakeLists.txt
index 3f6410b2..45ba2604 100644
--- a/test/cutils/utils_regex/CMakeLists.txt
+++ b/test/cutils/utils_regex/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_string/CMakeLists.txt b/test/cutils/utils_string/CMakeLists.txt
index 1343f4e6..b9968c43 100644
--- a/test/cutils/utils_string/CMakeLists.txt
+++ b/test/cutils/utils_string/CMakeLists.txt
@@ -16,3 +16,4 @@ target_include_directories(${EXE} PUBLIC
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_strdup_s -Wl,--wrap,calloc -Wl,--wrap,strcat_s")
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_timestamp/CMakeLists.txt b/test/cutils/utils_timestamp/CMakeLists.txt
index 38aec640..6da3fcc9 100644
--- a/test/cutils/utils_timestamp/CMakeLists.txt
+++ b/test/cutils/utils_timestamp/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_utils/CMakeLists.txt b/test/cutils/utils_utils/CMakeLists.txt
index 7b3bd546..99a83e7a 100644
--- a/test/cutils/utils_utils/CMakeLists.txt
+++ b/test/cutils/utils_utils/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/cutils/utils_verify/CMakeLists.txt b/test/cutils/utils_verify/CMakeLists.txt
index abf9596f..dd9ef78b 100644
--- a/test/cutils/utils_verify/CMakeLists.txt
+++ b/test/cutils/utils_verify/CMakeLists.txt
@@ -14,3 +14,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/image/oci/oci_config_merge/CMakeLists.txt b/test/image/oci/oci_config_merge/CMakeLists.txt
index 88047fde..42cd2e78 100644
--- a/test/image/oci/oci_config_merge/CMakeLists.txt
+++ b/test/image/oci/oci_config_merge/CMakeLists.txt
@@ -73,3 +73,4 @@ target_include_directories(${EXE} PUBLIC
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_common_calloc_s -Wl,--wrap,util_smart_calloc_s -Wl,--wrap,merge_env")
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/image/oci/registry/CMakeLists.txt b/test/image/oci/registry/CMakeLists.txt
index 727a615a..13ed95b2 100644
--- a/test/image/oci/registry/CMakeLists.txt
+++ b/test/image/oci/registry/CMakeLists.txt
@@ -63,3 +63,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz libhttpclient)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/image/oci/storage/images/CMakeLists.txt b/test/image/oci/storage/images/CMakeLists.txt
index b00c5a0e..3e6b69a4 100644
--- a/test/image/oci/storage/images/CMakeLists.txt
+++ b/test/image/oci/storage/images/CMakeLists.txt
@@ -45,3 +45,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/image/oci/storage/layers/CMakeLists.txt b/test/image/oci/storage/layers/CMakeLists.txt
index 3fe8ab7c..952e9483 100644
--- a/test/image/oci/storage/layers/CMakeLists.txt
+++ b/test/image/oci/storage/layers/CMakeLists.txt
@@ -66,6 +66,7 @@ target_link_libraries(${DRIVER_EXE}
-lwebsockets -lcrypto -lyajl -larchive ${SELINUX_LIBRARY} -ldevmapper -lz)
add_test(NAME ${DRIVER_EXE} COMMAND ${DRIVER_EXE} --gtest_output=xml:${DRIVER_EXE}-Results.xml)
+set_tests_properties(${DRIVER_EXE} PROPERTIES TIMEOUT 120)
# storage_layers_ut
SET(LAYER_EXE storage_layers_ut)
@@ -141,3 +142,4 @@ target_link_libraries(${LAYER_EXE}
-lwebsockets -lcrypto -lyajl -larchive ${SELINUX_LIBRARY} -ldevmapper -lz)
add_test(NAME ${LAYER_EXE} COMMAND ${LAYER_EXE} --gtest_output=xml:${LAYER_EXE}-Results.xml)
+set_tests_properties(${LAYER_EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/image/oci/storage/rootfs/CMakeLists.txt b/test/image/oci/storage/rootfs/CMakeLists.txt
index 5bf568f9..4d7d3533 100644
--- a/test/image/oci/storage/rootfs/CMakeLists.txt
+++ b/test/image/oci/storage/rootfs/CMakeLists.txt
@@ -45,3 +45,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/network/CMakeLists.txt b/test/network/CMakeLists.txt
index e354bebc..be31fd0e 100644
--- a/test/network/CMakeLists.txt
+++ b/test/network/CMakeLists.txt
@@ -86,3 +86,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/runtime/isula/CMakeLists.txt b/test/runtime/isula/CMakeLists.txt
index 38a454b0..f5821953 100644
--- a/test/runtime/isula/CMakeLists.txt
+++ b/test/runtime/isula/CMakeLists.txt
@@ -58,3 +58,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lpthread -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/runtime/lcr/CMakeLists.txt b/test/runtime/lcr/CMakeLists.txt
index 6f8f784c..979cbe5a 100644
--- a/test/runtime/lcr/CMakeLists.txt
+++ b/test/runtime/lcr/CMakeLists.txt
@@ -58,3 +58,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/services/execution/execute/execution_extend/CMakeLists.txt b/test/services/execution/execute/execution_extend/CMakeLists.txt
index aaff39ef..8588fac3 100644
--- a/test/services/execution/execute/execution_extend/CMakeLists.txt
+++ b/test/services/execution/execute/execution_extend/CMakeLists.txt
@@ -76,3 +76,4 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/services/execution/spec/CMakeLists.txt b/test/services/execution/spec/CMakeLists.txt
index e1aa680e..d4a9d9b0 100644
--- a/test/services/execution/spec/CMakeLists.txt
+++ b/test/services/execution/spec/CMakeLists.txt
@@ -74,4 +74,6 @@ target_include_directories(${MOCK_EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${SELINUX_LIBRARY} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
target_link_libraries(${MOCK_EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${SELINUX_LIBRARY} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
add_test(NAME ${MOCK_EXE} COMMAND ${MOCK_EXE} --gtest_output=xml:${MOCK_EXE}-Results.xml)
+set_tests_properties(${MOCK_EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/services/execution/spec/selinux_label_ut.cc b/test/services/execution/spec/selinux_label_ut.cc
index c0e9ab1c..f9a73cca 100644
--- a/test/services/execution/spec/selinux_label_ut.cc
+++ b/test/services/execution/spec/selinux_label_ut.cc
@@ -179,11 +179,13 @@ protected:
void SetUp() override
{
CreateTestedObjects();
+ selinux_state_init();
}
void TearDown() override
{
ClearTestedObjects();
+ selinux_state_free();
}
private:
diff --git a/test/specs/specs/CMakeLists.txt b/test/specs/specs/CMakeLists.txt
index b730959c..c4b36c5f 100644
--- a/test/specs/specs/CMakeLists.txt
+++ b/test/specs/specs/CMakeLists.txt
@@ -83,3 +83,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/specs/specs_extend/CMakeLists.txt b/test/specs/specs_extend/CMakeLists.txt
index 7d05deb4..06f46a37 100644
--- a/test/specs/specs_extend/CMakeLists.txt
+++ b/test/specs/specs_extend/CMakeLists.txt
@@ -79,3 +79,4 @@ target_include_directories(${EXE} PUBLIC
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/volume/CMakeLists.txt b/test/volume/CMakeLists.txt
index 6eea3f76..e2045b19 100644
--- a/test/volume/CMakeLists.txt
+++ b/test/volume/CMakeLists.txt
@@ -39,4 +39,5 @@ target_include_directories(${EXE} PUBLIC
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
-add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
\ No newline at end of file
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
--
2.25.1

View File

@ -0,0 +1,360 @@
From 734fca150e1c5da2814a55e0315bde8e828e6e8a Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Fri, 17 Feb 2023 16:07:53 +0800
Subject: [PATCH 14/22] add retry for read/write
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/cmd/isulad-shim/common.c | 6 +++---
src/cmd/isulad-shim/process.c | 2 +-
src/cmd/isulad/main.c | 4 ++--
src/daemon/common/selinux_label.c | 2 +-
src/daemon/entry/connect/grpc/grpc_containers_service.cc | 9 ++++++---
src/daemon/entry/cri/sysctl_tools.c | 2 +-
src/daemon/executor/container_cb/execution.c | 4 ++--
.../modules/container/container_gc/containers_gc.c | 3 ++-
src/daemon/modules/events_sender/event_sender.c | 2 +-
src/daemon/modules/image/oci/storage/storage.c | 4 +++-
src/daemon/modules/log/log_gather.c | 6 +++---
src/daemon/modules/plugin/plugin.c | 2 +-
src/daemon/modules/runtime/isula/isula_rt_ops.c | 4 ++--
src/daemon/modules/service/io_handler.c | 2 +-
src/daemon/modules/service/service_container.c | 2 +-
src/utils/cutils/utils.c | 2 +-
src/utils/cutils/utils_aes.c | 2 +-
src/utils/cutils/utils_file.c | 2 +-
src/utils/tar/util_archive.c | 4 ++--
src/utils/tar/util_gzip.c | 2 +-
20 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c
index bb8464bb..0c345187 100644
--- a/src/cmd/isulad-shim/common.c
+++ b/src/cmd/isulad-shim/common.c
@@ -196,7 +196,7 @@ int generate_random_str(char *id, size_t len)
}
for (i = 0; i < len; i++) {
int nret;
- if (read(fd, &num, sizeof(int)) < 0) {
+ if (read_nointr(fd, &num, sizeof(int)) < 0) {
close(fd);
return SHIM_ERR;
}
@@ -232,8 +232,8 @@ void write_message(int fd, const char *level, const char *fmt, ...)
va_end(arg_list);
snprintf(msg, MAX_MESSAGE_LEN - 1, "{\"level\": \"%s\", \"msg\": \"%s\"}\n", level, buf);
- nwrite = write(fd, msg, strlen(msg));
- if (nwrite != strlen(msg)) {
+ nwrite = write_nointr_in_total(fd, msg, strlen(msg));
+ if (nwrite < 0 || (size_t)nwrite != strlen(msg)) {
return;
}
}
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
index 8a0aa142..02ce3c85 100644
--- a/src/cmd/isulad-shim/process.c
+++ b/src/cmd/isulad-shim/process.c
@@ -283,7 +283,7 @@ static void *do_io_copy(void *data)
break;
}
- int r_count = read(ioc->fd_from, buf, DEFAULT_IO_COPY_BUF);
+ int r_count = util_read_nointr(ioc->fd_from, buf, DEFAULT_IO_COPY_BUF);
if (r_count == -1) {
if (errno == EAGAIN || errno == EINTR) {
continue;
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index b17657c5..a75fb189 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -482,8 +482,8 @@ int check_and_save_pid(const char *fn)
goto out;
}
- len = (int)write(fd, pidbuf, strlen(pidbuf));
- if (len < 0) {
+ len = util_write_nointr(fd, pidbuf, strlen(pidbuf));
+ if (len < 0 || len != strlen(pidbuf)) {
ERROR("Failed to write pid to file:%s: %s", fn, strerror(errno));
ret = -1;
}
diff --git a/src/daemon/common/selinux_label.c b/src/daemon/common/selinux_label.c
index 24294780..173f3acb 100644
--- a/src/daemon/common/selinux_label.c
+++ b/src/daemon/common/selinux_label.c
@@ -310,7 +310,7 @@ static int get_random_value(unsigned int range, unsigned int *val)
return -1;
}
- if (read(fd, &num, sizeof(int)) < 0) {
+ if (util_read_nointr(fd, &num, sizeof(int)) < 0) {
ERROR("Failed to read urandom value\n");
ret = -1;
goto out;
diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.cc b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
index c0210ed9..eb79223b 100644
--- a/src/daemon/entry/connect/grpc/grpc_containers_service.cc
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
@@ -292,7 +292,8 @@ Status ContainerServiceImpl::RemoteStart(ServerContext *context,
break;
}
const std::string &command = request.stdin();
- if (write(read_pipe_fd[1], (void *)(command.c_str()), command.length()) < 0) {
+ int nret = util_write_nointr_in_total(read_pipe_fd[1], command.c_str(), command.length());
+ if (nret < 0 || (size_t)nret != command.length()) {
ERROR("sub write over!");
break;
}
@@ -407,7 +408,8 @@ public:
}
for (int i = 0; i < request.cmd_size(); i++) {
std::string command = request.cmd(i);
- if (write(m_read_pipe_fd, (void *)(command.c_str()), command.length()) < 0) {
+ int nret = util_write_nointr_in_total(m_read_pipe_fd, command.c_str(), command.length());
+ if (nret < 0 || (size_t)nret != command.length()) {
ERROR("sub write over!");
return;
}
@@ -629,7 +631,8 @@ Status ContainerServiceImpl::Attach(ServerContext *context, ServerReaderWriter<A
break;
}
std::string command = request.stdin();
- if (write(pipefd[1], (void *)(command.c_str()), command.length()) < 0) {
+ int nret = util_write_nointr_in_total(pipefd[1], command.c_str(), command.length());
+ if (nret < 0 || (size_t)nret != command.length()) {
ERROR("sub write over!");
break;
}
diff --git a/src/daemon/entry/cri/sysctl_tools.c b/src/daemon/entry/cri/sysctl_tools.c
index 257ccf8f..3c558fa1 100644
--- a/src/daemon/entry/cri/sysctl_tools.c
+++ b/src/daemon/entry/cri/sysctl_tools.c
@@ -99,7 +99,7 @@ int set_sysctl(const char *sysctl, int new_value, char **err)
goto free_out;
}
rsize = util_write_nointr(fd, buff, strlen(buff));
- if (rsize <= 0) {
+ if (rsize < 0 || (size_t)rsize != strlen(buff)) {
if (asprintf(err, "Write new value failed: %s", strerror(errno)) < 0) {
*err = util_strdup_s("Out of memory");
}
diff --git a/src/daemon/executor/container_cb/execution.c b/src/daemon/executor/container_cb/execution.c
index ed70fc14..198052d3 100644
--- a/src/daemon/executor/container_cb/execution.c
+++ b/src/daemon/executor/container_cb/execution.c
@@ -348,7 +348,7 @@ static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const
return -1;
}
nwrite = util_write_nointr(fd, buf, strlen(buf));
- if (nwrite < 0 || nwrite != strlen(buf)) {
+ if (nwrite < 0 || (size_t)nwrite != strlen(buf)) {
ERROR("Failed to write %s to %s: %s", buf, fpath, strerror(errno));
isulad_set_error_message("Failed to write '%s' to '%s': %s", buf, fpath, strerror(errno));
return -1;
@@ -451,7 +451,7 @@ static int container_start_prepare(container_t *cont, const container_start_requ
// init cgroup path for cpu_rt_runtime and cpu_rt_period
// we should do this in start container, not create container
- // because, in scenarios:
+ // because, in scenarios:
// 1. enable cpu-rt of isulad;
// 2. then run container with --cpu-rt-runtime
// 3. then reboot machine;
diff --git a/src/daemon/modules/container/container_gc/containers_gc.c b/src/daemon/modules/container/container_gc/containers_gc.c
index 8c858a96..9feb6d3c 100644
--- a/src/daemon/modules/container/container_gc/containers_gc.c
+++ b/src/daemon/modules/container/container_gc/containers_gc.c
@@ -88,7 +88,8 @@ static int save_gc_config(const char *json_gc_config)
goto out;
}
- if (write(fd, json_gc_config, strlen(json_gc_config)) == -1) {
+ nret = util_write_nointr(fd, json_gc_config, strlen(json_gc_config));
+ if (nret < 0 || (size_t)nret != strlen(json_gc_config)) {
ERROR("write %s failed: %s", filename, strerror(errno));
ret = -1;
}
diff --git a/src/daemon/modules/events_sender/event_sender.c b/src/daemon/modules/events_sender/event_sender.c
index 03dcbbf3..a3903f3e 100644
--- a/src/daemon/modules/events_sender/event_sender.c
+++ b/src/daemon/modules/events_sender/event_sender.c
@@ -58,7 +58,7 @@ static void isulad_monitor_fifo_send(const struct monitord_msg *msg)
do {
ret = util_write_nointr(fd, msg, sizeof(struct monitord_msg));
- if (ret != sizeof(struct monitord_msg)) {
+ if (ret < 0 || (size_t)ret != sizeof(struct monitord_msg)) {
util_usleep_nointerupt(1000);
}
} while (ret != sizeof(struct monitord_msg));
diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c
index 829ea8d0..2f4bdf5f 100644
--- a/src/daemon/modules/image/oci/storage/storage.c
+++ b/src/daemon/modules/image/oci/storage/storage.c
@@ -1429,6 +1429,7 @@ static int do_add_checked_layer(const char *lid, int fd, map_t *checked_layers)
bool default_value = true;
char buf[PATH_MAX] = { 0 };
int ret = 0;
+ int nret;
if (strlen(lid) >= PATH_MAX - 1) {
ERROR("Invalid layer id: %s", lid);
@@ -1438,7 +1439,8 @@ static int do_add_checked_layer(const char *lid, int fd, map_t *checked_layers)
(void)memcpy(buf, lid, strlen(lid));
buf[strlen(lid)] = '\n';
// save checked layer ids into file
- if (util_write_nointr(fd, buf, strlen(lid) + 1) < 0) {
+ nret = util_write_nointr(fd, buf, strlen(lid) + 1);
+ if (nret < 0 || (size_t)nret != strlen(lid) + 1) {
ERROR("Write checked layer data failed: %s", strerror(errno));
ret = -1;
goto out;
diff --git a/src/daemon/modules/log/log_gather.c b/src/daemon/modules/log/log_gather.c
index 49facaa2..414c9ad1 100644
--- a/src/daemon/modules/log/log_gather.c
+++ b/src/daemon/modules/log/log_gather.c
@@ -183,9 +183,9 @@ static int write_into_file(const void *buf, size_t g_log_size)
return -1;
}
}
- ret = (int)write(g_log_fd, buf, g_log_size);
- if (ret <= 0) {
- return ret;
+ ret = util_write_nointr_in_total(g_log_fd, buf, g_log_size);
+ if (ret < 0 || (size_t)ret != g_log_size) {
+ return -1;
}
write_size += ret;
diff --git a/src/daemon/modules/plugin/plugin.c b/src/daemon/modules/plugin/plugin.c
index 53afeeaf..1c0af368 100644
--- a/src/daemon/modules/plugin/plugin.c
+++ b/src/daemon/modules/plugin/plugin.c
@@ -618,7 +618,7 @@ static int process_plugin_events(int inotify_fd, const char *plugin_dir)
struct inotify_event *plugin_event = NULL;
char buffer[8192 + 1] = { 0 };
int action = 0;
- events_length = read(inotify_fd, buffer, 8192);
+ events_length = util_read_nointr(inotify_fd, buffer, 8192);
if (events_length <= 0) {
ERROR("Failed to wait events");
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
index 76e3bcb7..5463bb1b 100644
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
@@ -1363,8 +1363,8 @@ int rt_isula_exec_resize(const char *id, const char *runtime, const rt_exec_resi
goto out;
}
- count = write(fd, data, RESIZE_DATA_SIZE);
- if (count <= 0) {
+ count = util_write_nointr(fd, data, strlen(data));
+ if (count < 0 || (size_t)count != strlen(data)) {
ERROR("write exec resize data error");
ret = -1;
goto out;
diff --git a/src/daemon/modules/service/io_handler.c b/src/daemon/modules/service/io_handler.c
index 893733bc..98c763a4 100644
--- a/src/daemon/modules/service/io_handler.c
+++ b/src/daemon/modules/service/io_handler.c
@@ -340,7 +340,7 @@ static ssize_t write_to_fd(void *context, const void *data, size_t len)
{
ssize_t ret;
ret = util_write_nointr(*(int *)context, data, len);
- if ((ret <= 0) || (ret != (ssize_t)len)) {
+ if (ret < 0 || (size_t)ret != len) {
ERROR("Failed to write: %s", strerror(errno));
return -1;
}
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index eeb035a0..cc777411 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -345,7 +345,7 @@ static int write_env_content(const char *env_path, const char **env, size_t env_
goto out;
}
nret = util_write_nointr(fd, env_content, strlen(env_content));
- if (nret < 0 || nret != len - 1) {
+ if (nret < 0 || (size_t)nret != strlen(env_content)) {
SYSERROR("Write env file failed");
free(env_content);
ret = -1;
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
index de636bcb..f99b28e4 100644
--- a/src/utils/cutils/utils.c
+++ b/src/utils/cutils/utils.c
@@ -1251,7 +1251,7 @@ int util_generate_random_str(char *id, size_t len)
}
for (i = 0; i < len; i++) {
int nret;
- if (read(fd, &num, sizeof(int)) < 0) {
+ if (util_read_nointr(fd, &num, sizeof(int)) < 0) {
ERROR("Failed to read urandom value");
close(fd);
return -1;
diff --git a/src/utils/cutils/utils_aes.c b/src/utils/cutils/utils_aes.c
index 1e25ecd3..055a9538 100644
--- a/src/utils/cutils/utils_aes.c
+++ b/src/utils/cutils/utils_aes.c
@@ -77,7 +77,7 @@ int util_aes_key(const char *key_file, bool create, unsigned char *aeskey)
goto out;
}
- if (read(fd, aeskey, AES_256_CFB_KEY_LEN) != AES_256_CFB_KEY_LEN) {
+ if (util_read_nointr(fd, aeskey, AES_256_CFB_KEY_LEN) != AES_256_CFB_KEY_LEN) {
ERROR("read key file %s failed: %s", key_file, strerror(errno));
ret = -1;
goto out;
diff --git a/src/utils/cutils/utils_file.c b/src/utils/cutils/utils_file.c
index cdd712a7..34c5b060 100644
--- a/src/utils/cutils/utils_file.c
+++ b/src/utils/cutils/utils_file.c
@@ -998,7 +998,7 @@ int util_file2str(const char *filename, char *buf, size_t len)
if (fd == -1) {
return -1;
}
- num_read = (int)read(fd, buf, len - 1);
+ num_read = (int)util_read_nointr(fd, buf, len - 1);
if (num_read <= 0) {
num_read = -1;
} else {
diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c
index 2d56d8a7..7ace2924 100644
--- a/src/utils/tar/util_archive.c
+++ b/src/utils/tar/util_archive.c
@@ -662,7 +662,7 @@ child_out:
if (ret != 0) {
ERROR("Wait archive_untar_handler failed with error:%s", strerror(errno));
fcntl(pipe_stderr[0], F_SETFL, O_NONBLOCK);
- if (read(pipe_stderr[0], errbuf, BUFSIZ) < 0) {
+ if (util_read_nointr(pipe_stderr[0], errbuf, BUFSIZ) < 0) {
ERROR("read error message from child failed");
}
}
@@ -1057,7 +1057,7 @@ child_out:
if (ret != 0) {
ERROR("tar failed");
fcntl(pipe_for_read[0], F_SETFL, O_NONBLOCK);
- if (read(pipe_for_read[0], errbuf, BUFSIZ) < 0) {
+ if (util_read_nointr(pipe_for_read[0], errbuf, BUFSIZ) < 0) {
ERROR("read error message from child failed");
}
}
diff --git a/src/utils/tar/util_gzip.c b/src/utils/tar/util_gzip.c
index 5c34d719..2f4750be 100644
--- a/src/utils/tar/util_gzip.c
+++ b/src/utils/tar/util_gzip.c
@@ -212,7 +212,7 @@ int gzip(const char *filename, size_t len)
return -1;
}
- size_read = read(pipefd[0], buffer, BUFSIZ);
+ size_read = util_read_nointr(pipefd[0], buffer, BUFSIZ);
close(pipefd[0]);
if (size_read) {
--
2.25.1

View File

@ -0,0 +1,302 @@
From aaf8dec80eff5390404d7da66dbb229e44c76b12 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 16 Feb 2023 18:22:02 +0800
Subject: [PATCH 15/22] support pull image with digest
usage: isula pull busybox@sha256:907ca53d7e2947e849b839b1cd258c98fd3916c60f2e6e70c30edbf741ab6754
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/daemon/executor/image_cb/image_cb.c | 8 ++++
src/daemon/modules/image/oci/oci_pull.c | 23 ++++++----
.../modules/image/oci/registry/registry.c | 2 +-
.../oci/storage/image_store/image_store.c | 7 +++
src/daemon/modules/image/oci/utils_images.c | 45 +++++++++++++++----
src/daemon/modules/image/oci/utils_images.h | 2 +
src/utils/cutils/utils_verify.c | 25 ++++++++---
src/utils/cutils/utils_verify.h | 3 ++
8 files changed, 91 insertions(+), 24 deletions(-)
diff --git a/src/daemon/executor/image_cb/image_cb.c b/src/daemon/executor/image_cb/image_cb.c
index 06de7543..124feb21 100644
--- a/src/daemon/executor/image_cb/image_cb.c
+++ b/src/daemon/executor/image_cb/image_cb.c
@@ -561,6 +561,14 @@ static int trans_one_image(image_list_images_response *response, size_t image_in
out_image->name = util_strdup_s(im_image->repo_tags[repo_index]);
}
+ if (out_image->name == NULL && im_image->repo_digests != NULL && im_image->repo_digests_len > 0) {
+ // repo digest must valid, so just get lastest @
+ char *pod = strrchr(im_image->repo_digests[0], '@');
+ if (pod != NULL) {
+ out_image->name = util_sub_string(im_image->repo_digests[0], 0, (size_t)(pod - im_image->repo_digests[0]));
+ }
+ }
+
out_image->target = util_common_calloc_s(sizeof(image_descriptor));
if (out_image->target == NULL) {
ERROR("Out of memory");
diff --git a/src/daemon/modules/image/oci/oci_pull.c b/src/daemon/modules/image/oci/oci_pull.c
index 5e774c9e..5b35ca2b 100644
--- a/src/daemon/modules/image/oci/oci_pull.c
+++ b/src/daemon/modules/image/oci/oci_pull.c
@@ -117,10 +117,19 @@ static int pull_image(const im_pull_request *request, char **name)
options->skip_tls_verify = oci_image_data->insecure_skip_verify_enforce;
insecure_registries = oci_image_data->insecure_registries;
+ // key of image which save in image-store
+ options->dest_image_name = oci_normalize_image_name(request->image);
+
+ // add default tag if required
+ with_tag = oci_default_tag(request->image);
+
host = oci_get_host(request->image);
if (host != NULL) {
- options->image_name = oci_default_tag(request->image);
- options->dest_image_name = oci_normalize_image_name(request->image);
+ // 1. image_name use for split host/tag/name
+ // 2. user for tag of log
+ options->image_name = with_tag;
+ with_tag = NULL;
+
update_option_insecure_registry(options, insecure_registries, host);
ret = registry_pull(options);
if (ret != 0) {
@@ -141,13 +150,12 @@ static int pull_image(const im_pull_request *request, char **name)
}
host = oci_host_from_mirror(*mirror);
update_option_insecure_registry(options, insecure_registries, host);
- with_tag = oci_default_tag(request->image);
+ // add current mirror to image name
+ free(options->image_name);
options->image_name = oci_add_host(host, with_tag);
- free(with_tag);
- with_tag = NULL;
free(host);
host = NULL;
- options->dest_image_name = oci_normalize_image_name(request->image);
+
ret = registry_pull(options);
if (ret != 0) {
continue;
@@ -159,10 +167,9 @@ static int pull_image(const im_pull_request *request, char **name)
*name = util_strdup_s(options->dest_image_name);
out:
+ free(with_tag);
free(host);
- host = NULL;
free_registry_pull_options(options);
- options = NULL;
return ret;
}
diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c
index 143de6e4..62d0c35e 100644
--- a/src/daemon/modules/image/oci/registry/registry.c
+++ b/src/daemon/modules/image/oci/registry/registry.c
@@ -1861,7 +1861,7 @@ static int prepare_pull_desc(pull_descriptor *desc, registry_pull_options *optio
}
if (!util_valid_image_name(options->dest_image_name)) {
- ERROR("Invalid dest image name %s", options->image_name);
+ ERROR("Invalid dest image name %s", options->dest_image_name);
isulad_try_set_error_message("Invalid image name");
return -1;
}
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c
index 39bda87d..cf1e88ff 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c
@@ -1979,6 +1979,7 @@ static int resort_image_names(const char **names, size_t names_len, char **first
MAX_IMAGE_NAME_LENGTH - MAX_IMAGE_DIGEST_LENGTH);
}
+ // TODO: maybe should support other digest
if (prefix != NULL && strcmp(prefix, DIGEST_PREFIX) == 0) {
if (util_array_append(image_digests, names[i]) != 0) {
ERROR("Failed to append image to digest: %s", names[i]);
@@ -2172,6 +2173,7 @@ static int get_image_repo_digests(char ***old_repo_digests, char **image_tags, i
goto out;
}
+ // get repo digest from images which with tag
if (pack_repo_digest(old_repo_digests, (const char **)image_tags, digest, repo_digests) != 0) {
ERROR("Failed to pack repo digest");
ret = -1;
@@ -2194,12 +2196,17 @@ static int pack_image_tags_and_repo_digest(image_t *img, imagetool_image *info)
char *image_digest = NULL;
char **repo_digests = NULL;
+ // get names from image-store names:
+ // 1. image names with tag;
+ // 2. image names with digests;
+ // 3. get first image name, current unused;
if (resort_image_names((const char **)img->simage->names, img->simage->names_len, &name, &tags, &digests) != 0) {
ERROR("Failed to resort image names");
ret = -1;
goto out;
}
+ // update repo digests from tags
if (get_image_repo_digests(&digests, tags, img, &image_digest, &repo_digests) != 0) {
ERROR("Failed to get image repo digests");
ret = -1;
diff --git a/src/daemon/modules/image/oci/utils_images.c b/src/daemon/modules/image/oci/utils_images.c
index 9e7bb16f..ad7fe0f4 100644
--- a/src/daemon/modules/image/oci/utils_images.c
+++ b/src/daemon/modules/image/oci/utils_images.c
@@ -42,6 +42,26 @@
// nanos of 2038-01-19T03:14:07, the max valid linux time
#define MAX_NANOS 2147483647000000000
+char *oci_image_digest_pos(const char *name)
+{
+ char *pos = NULL;
+
+ if (name == NULL) {
+ return NULL;
+ }
+
+ pos = strrchr(name, '@');
+ if (pos == NULL) {
+ return NULL;
+ }
+
+ if (util_reg_match(__DIGESTPattern, pos) != 0) {
+ return NULL;
+ }
+
+ return pos;
+}
+
char *get_last_part(char **parts)
{
char *last_part = NULL;
@@ -98,6 +118,7 @@ char *oci_default_tag(const char *name)
}
last_part = get_last_part(parts);
+ // will pass image name with digest and with tag
if (last_part != NULL && strrchr(last_part, ':') == NULL) {
add_default_tag = DEFAULT_TAG;
}
@@ -181,9 +202,9 @@ char *oci_normalize_image_name(const char *name)
return result;
}
-int oci_split_image_name(const char *image_name, char **host, char **name, char **tag)
+int oci_split_image_name(const char *image_name, char **host, char **name, char **tag_digest)
{
- char *tag_pos = NULL;
+ char *tag_digest_pos = NULL;
char *name_pos = NULL;
char *tmp_image_name = NULL;
@@ -193,18 +214,24 @@ int oci_split_image_name(const char *image_name, char **host, char **name, char
}
tmp_image_name = util_strdup_s(image_name);
- tag_pos = util_tag_pos(tmp_image_name);
- if (tag_pos != NULL) {
- *tag_pos = 0;
- tag_pos++;
- if (tag != NULL) {
- *tag = util_strdup_s(tag_pos);
+
+ // check digest first
+ tag_digest_pos = oci_image_digest_pos(tmp_image_name);
+ if (tag_digest_pos == NULL) {
+ tag_digest_pos = util_tag_pos(tmp_image_name);
+ }
+
+ if (tag_digest_pos != NULL) {
+ *tag_digest_pos = '\0';
+ tag_digest_pos++;
+ if (tag_digest != NULL) {
+ *tag_digest = util_strdup_s(tag_digest_pos);
}
}
name_pos = strchr(tmp_image_name, '/');
if (name_pos != NULL) {
- *name_pos = 0;
+ *name_pos = '\0';
name_pos++;
if (name != NULL) {
*name = util_strdup_s(name_pos);
diff --git a/src/daemon/modules/image/oci/utils_images.h b/src/daemon/modules/image/oci/utils_images.h
index daa8c040..97879e41 100644
--- a/src/daemon/modules/image/oci/utils_images.h
+++ b/src/daemon/modules/image/oci/utils_images.h
@@ -59,6 +59,8 @@ char *oci_get_isulad_tmpdir(const char *root_dir);
int makesure_isulad_tmpdir_perm_right(const char *root_dir);
char *get_hostname_to_strip();
+char *oci_image_digest_pos(const char *name);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/utils/cutils/utils_verify.c b/src/utils/cutils/utils_verify.c
index d39d8da5..5868e890 100644
--- a/src/utils/cutils/utils_verify.c
+++ b/src/utils/cutils/utils_verify.c
@@ -359,7 +359,7 @@ cleanup:
bool util_valid_image_name(const char *name)
{
char *copy = NULL;
- char *tag_pos = NULL;
+ char *check_pos = NULL;
bool bret = false;
if (name == NULL) {
@@ -372,13 +372,26 @@ bool util_valid_image_name(const char *name)
}
copy = util_strdup_s(name);
- tag_pos = util_tag_pos(copy);
- if (tag_pos != NULL) {
- if (util_reg_match(__TagPattern, tag_pos)) {
+
+ // 1. first, check digest or not
+ check_pos = strrchr(copy, '@');
+ if (check_pos != NULL) {
+ // image name with digest
+ if (util_reg_match(__DIGESTPattern, check_pos)) {
goto cleanup;
}
-
- *tag_pos = '\0';
+ *check_pos = '\0';
+ } else {
+ // image name without digest
+ // 2. check tag or not
+ check_pos = util_tag_pos(copy);
+ if (check_pos != NULL) {
+ if (util_reg_match(__TagPattern, check_pos)) {
+ goto cleanup;
+ }
+
+ *check_pos = '\0';
+ }
}
if (util_reg_match(__NamePattern, copy)) {
diff --git a/src/utils/cutils/utils_verify.h b/src/utils/cutils/utils_verify.h
index a885250f..ad4466ef 100644
--- a/src/utils/cutils/utils_verify.h
+++ b/src/utils/cutils/utils_verify.h
@@ -33,6 +33,9 @@ extern "C" {
"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])" \
"((\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(:[0-9]+)?/)?[a-z0-9]" \
"+((([._]|__|[-]*)[a-z0-9]+)+)?((/[a-z0-9]+((([._]|__|[-]*)[a-z0-9]+)+)?)+)?$"
+
+#define __DIGESTPattern "@[a-z0-9]+:[a-z0-9]{32,}"
+
#define VALID_VOLUME_NAME "[a-zA-Z0-9][a-zA-Z0-9_.-]{1,63}"
extern const char *g_all_caps[];
--
2.25.1

View File

@ -0,0 +1,186 @@
From 32dbf764fd5b7f6941c49750b49dbba253bd3234 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Mon, 13 Feb 2023 15:36:58 +0800
Subject: [PATCH 16/22] isulad-shim support execSync with timeout
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
.../executor/container_cb/execution_stream.c | 2 +-
.../modules/runtime/isula/isula_rt_ops.c | 37 +++++++++++++++---
src/utils/cutils/utils.c | 39 +++++++++++++++++++
src/utils/cutils/utils.h | 5 +++
4 files changed, 77 insertions(+), 6 deletions(-)
diff --git a/src/daemon/executor/container_cb/execution_stream.c b/src/daemon/executor/container_cb/execution_stream.c
index fde0335e..1a7353b5 100644
--- a/src/daemon/executor/container_cb/execution_stream.c
+++ b/src/daemon/executor/container_cb/execution_stream.c
@@ -161,7 +161,7 @@ static int container_exec_cb(const container_exec_request *request, container_ex
if (exec_container(cont, request, *response, stdinfd, stdout_handler, stderr_handler) != 0) {
ret = -1;
- goto out;
+ goto pack_err_response;
}
goto out;
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
index 5463bb1b..6f2b4f7d 100644
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
@@ -205,6 +205,10 @@ static void show_shim_runtime_errlog(const char *workdir)
char buf1[SHIM_LOG_SIZE] = { 0 };
char buf2[SHIM_LOG_SIZE] = { 0 };
+ if (g_isulad_errmsg != NULL) {
+ return;
+ }
+
get_err_message(buf1, sizeof(buf1), workdir, "shim-log.json");
get_err_message(buf2, sizeof(buf2), workdir, "log.json");
ERROR("shim-log: %s", buf1);
@@ -686,8 +690,29 @@ static int status_to_exit_code(int status)
return exit_code;
}
+static int try_wait_pid(pid_t pid)
+{
+ if (waitpid(pid, NULL, WNOHANG) == pid) {
+ return 0;
+ }
+
+ return 1;
+}
+
+static void kill_and_show_err(pid_t pid)
+{
+ int nret = 0;
+ kill(pid, SIGKILL);
+ // wait atmost 0.5 seconds
+ DO_RETRY_CALL(5, 100000, nret, try_wait_pid, pid);
+ if (nret != 0) {
+ WARN("Fail to wait isulad-shim");
+ }
+ isulad_set_error_message("Exec container error;exec timeout");
+}
+
static int shim_create(bool fg, const char *id, const char *workdir, const char *bundle, const char *runtime_cmd,
- int *exit_code)
+ int *exit_code, const int64_t timeout)
{
pid_t pid = 0;
int exec_fd[2] = { -1, -1 };
@@ -778,7 +803,7 @@ realexec:
goto out;
}
- status = util_wait_for_pid_status(pid);
+ status = util_waitpid_with_timeout(pid, timeout, kill_and_show_err);
if (status < 0) {
ERROR("failed wait shim-parent %d exit %s", pid, strerror(errno));
ret = -1;
@@ -792,7 +817,9 @@ realexec:
out:
if (ret != 0) {
show_shim_runtime_errlog(workdir);
- kill(pid, SIGKILL); /* can kill other process? */
+ if (timeout <= 0) {
+ kill(pid, SIGKILL); /* can kill other process? */
+ }
}
return ret;
@@ -901,7 +928,7 @@ int rt_isula_create(const char *id, const char *runtime, const rt_create_params_
}
get_runtime_cmd(runtime, &cmd);
- ret = shim_create(false, id, workdir, params->bundle, cmd, NULL);
+ ret = shim_create(false, id, workdir, params->bundle, cmd, NULL, -1);
if (ret != 0) {
runtime_call_delete_force(workdir, runtime, id);
ERROR("%s: failed create shim process", id);
@@ -1173,7 +1200,7 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p
}
get_runtime_cmd(runtime, &cmd);
- ret = shim_create(fg_exec(params), id, workdir, bundle, cmd, exit_code);
+ ret = shim_create(fg_exec(params), id, workdir, bundle, cmd, exit_code, params->timeout);
if (ret != 0) {
ERROR("%s: failed create shim process for exec %s", id, exec_id);
goto errlog_out;
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
index f99b28e4..2c4c01e4 100644
--- a/src/utils/cutils/utils.c
+++ b/src/utils/cutils/utils.c
@@ -311,6 +311,45 @@ rep:
return 0;
}
+/*
+ * If timeout <= 0, blocking wait pid.
+ * If timeout > 0, non-blocking wait pid with timeout.
+ * When waitpid timeout, calling handle_timeout_callback_t.
+ */
+int util_waitpid_with_timeout(pid_t pid, const int64_t timeout, handle_timeout_callback_t cb)
+{
+ int nret = 0;
+ time_t start_time = time(NULL);
+ time_t end_time;
+ double interval;
+
+ if (timeout <= 0) {
+ return util_wait_for_pid_status(pid);
+ }
+
+ for (;;) {
+ nret = waitpid(pid, NULL, WNOHANG);
+ if (nret == pid) {
+ break;
+ }
+ if (nret == -1 && errno != EINTR) {
+ return -1;
+ }
+ end_time = time(NULL);
+ interval = difftime(end_time, start_time);
+ if (nret == 0 && interval >= timeout) {
+ INFO("Wait %d timeout", pid);
+ if (cb != NULL) {
+ cb(pid);
+ }
+ return -1;
+ }
+ // sleep some time instead to avoid cpu full running and then retry.
+ sleep(0.1);
+ }
+ return 0;
+}
+
int util_wait_for_pid_status(pid_t pid)
{
int st;
diff --git a/src/utils/cutils/utils.h b/src/utils/cutils/utils.h
index 6261dc05..01107605 100644
--- a/src/utils/cutils/utils.h
+++ b/src/utils/cutils/utils.h
@@ -302,6 +302,9 @@ typedef struct _proc_t {
processor; /* current (or most recent?) CPU */
} proc_t;
+// handle waitpid timeout.
+typedef void(*handle_timeout_callback_t)(pid_t pid);
+
struct signame {
int num;
const char *name;
@@ -329,6 +332,8 @@ char *util_strdup_s(const char *src);
int util_wait_for_pid(pid_t pid);
+int util_waitpid_with_timeout(pid_t pid, const int64_t timeout, handle_timeout_callback_t cb);
+
void util_contain_errmsg(const char *errmsg, int *exit_code);
char *util_short_digest(const char *digest);
--
2.25.1

View File

@ -0,0 +1,30 @@
From a1c06194fea99d1011551fd84b1fb1f28b974170 Mon Sep 17 00:00:00 2001
From: sailorvii <chenw66@chinaunicom.cn>
Date: Tue, 21 Feb 2023 02:40:50 +0000
Subject: [PATCH 17/22] Refine the commit info.
---
docs/design/detailed/Network/native_network_design_zh.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/design/detailed/Network/native_network_design_zh.md b/docs/design/detailed/Network/native_network_design_zh.md
index 0ca0f850..27c10c3e 100644
--- a/docs/design/detailed/Network/native_network_design_zh.md
+++ b/docs/design/detailed/Network/native_network_design_zh.md
@@ -299,10 +299,10 @@ cache:::unFinish
## 4.2 adaptor模块
-1. 查看 CRI adapter 模块的设计文档: [CRI_adapter_design](./cni_operator_design_zh.md) 。
+1. 查看 CRI adapter 模块的设计文档: [CRI_adapter_design](./CRI_adapter_design_zh.md) 。
2. 查看 native network adapter 模块的设计文档: [native_network_adapter_design](./native_network_adapter_design_zh.md) 。
## 4.3 cni-operator模块
-- 查看 cni operator 模块的设计文档: [cni_operator_design](./cni_operator_design_zh.md) 。
\ No newline at end of file
+- 查看 cni operator 模块的设计文档: [cni_operator_design](./cni_operator_design_zh.md) 。
--
2.25.1

View File

@ -0,0 +1,85 @@
From 53ec87b8c5224b1069bef50d09403c53fb48640f Mon Sep 17 00:00:00 2001
From: sailorvii <chenw66@chinaunicom.cn>
Date: Tue, 21 Feb 2023 06:50:21 +0000
Subject: [PATCH 18/22] Refine typo of word "container".
---
src/daemon/executor/container_cb/execution_create.c | 2 +-
src/daemon/modules/api/container_api.h | 2 +-
src/daemon/modules/container/container_unix.c | 2 +-
src/daemon/modules/service/service_network.c | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index 4abc89c7..e8f74f1b 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -1481,7 +1481,7 @@ int container_create_cb(const container_create_request *request, container_creat
goto umount_channel;
}
- if (container_v2_spec_merge_contaner_spec(v2_spec) != 0) {
+ if (container_v2_spec_merge_container_spec(v2_spec) != 0) {
ERROR("Failed to merge container settings");
cc = ISULAD_ERR_EXEC;
goto umount_channel;
diff --git a/src/daemon/modules/api/container_api.h b/src/daemon/modules/api/container_api.h
index 270d6da6..1511db78 100644
--- a/src/daemon/modules/api/container_api.h
+++ b/src/daemon/modules/api/container_api.h
@@ -175,7 +175,7 @@ void container_unlock(container_t *cont);
char *container_get_env_nolock(const container_t *cont, const char *key);
-int container_v2_spec_merge_contaner_spec(container_config_v2_common_config *v2_spec);
+int container_v2_spec_merge_container_spec(container_config_v2_common_config *v2_spec);
char *container_get_command(const container_t *cont);
diff --git a/src/daemon/modules/container/container_unix.c b/src/daemon/modules/container/container_unix.c
index adc11be7..1a252b92 100644
--- a/src/daemon/modules/container/container_unix.c
+++ b/src/daemon/modules/container/container_unix.c
@@ -470,7 +470,7 @@ out:
}
/* container merge basic v2 spec info */
-int container_v2_spec_merge_contaner_spec(container_config_v2_common_config *v2_spec)
+int container_v2_spec_merge_container_spec(container_config_v2_common_config *v2_spec)
{
int ret = 0;
int i = 0;
diff --git a/src/daemon/modules/service/service_network.c b/src/daemon/modules/service/service_network.c
index 2e7fa28c..2d5f2f6e 100644
--- a/src/daemon/modules/service/service_network.c
+++ b/src/daemon/modules/service/service_network.c
@@ -569,7 +569,7 @@ err_out:
return NULL;
}
-static container_network_settings *dup_contaner_network_settings(const container_network_settings *settings)
+static container_network_settings *dup_container_network_settings(const container_network_settings *settings)
{
char *jstr = NULL;
container_network_settings *res = NULL;
@@ -1278,7 +1278,7 @@ static int update_container_network_settings(container_t *cont, const cni_anno_p
bool to_disk = false;
container_network_settings *backup = NULL;
- backup = dup_contaner_network_settings(cont->network_settings);
+ backup = dup_container_network_settings(cont->network_settings);
if (backup == NULL) {
ERROR("Failed to dup container network settings");
return -1;
@@ -1509,7 +1509,7 @@ static int drop_container_network_settings(container_t *cont)
return -1;
}
- backup = dup_contaner_network_settings(cont->network_settings);
+ backup = dup_container_network_settings(cont->network_settings);
if (backup == NULL) {
ERROR("Failed to dup container network settings");
return -1;
--
2.25.1

View File

@ -0,0 +1,54 @@
From f9224d47ddc4193678f7ffe501be144fedff0102 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Mon, 20 Feb 2023 17:28:33 +0800
Subject: [PATCH 19/22] cleancode for read/write
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/cmd/isulad-shim/process.c | 2 +-
src/cmd/isulad/main.c | 2 +-
src/daemon/entry/connect/grpc/grpc_containers_service.cc | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
index 02ce3c85..8a0aa142 100644
--- a/src/cmd/isulad-shim/process.c
+++ b/src/cmd/isulad-shim/process.c
@@ -283,7 +283,7 @@ static void *do_io_copy(void *data)
break;
}
- int r_count = util_read_nointr(ioc->fd_from, buf, DEFAULT_IO_COPY_BUF);
+ int r_count = read(ioc->fd_from, buf, DEFAULT_IO_COPY_BUF);
if (r_count == -1) {
if (errno == EAGAIN || errno == EINTR) {
continue;
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index a75fb189..0cdbfb53 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -483,7 +483,7 @@ int check_and_save_pid(const char *fn)
}
len = util_write_nointr(fd, pidbuf, strlen(pidbuf));
- if (len < 0 || len != strlen(pidbuf)) {
+ if (len < 0 || (size_t)len != strlen(pidbuf)) {
ERROR("Failed to write pid to file:%s: %s", fn, strerror(errno));
ret = -1;
}
diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.cc b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
index eb79223b..7340c3ed 100644
--- a/src/daemon/entry/connect/grpc/grpc_containers_service.cc
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
@@ -409,7 +409,7 @@ public:
for (int i = 0; i < request.cmd_size(); i++) {
std::string command = request.cmd(i);
int nret = util_write_nointr_in_total(m_read_pipe_fd, command.c_str(), command.length());
- if (nret < 0 || (size_t)nret != command.length()) {
+ if (nret < 0 || (size_t)nret != command.length()) {
ERROR("sub write over!");
return;
}
--
2.25.1

View File

@ -0,0 +1,127 @@
From 7941e0fcd8d7b8edb303a1661233fd9688c46819 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Mon, 20 Feb 2023 15:42:40 +0800
Subject: [PATCH 20/22] add crictl timeout and sync for CI
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
CI/test_cases/container_cases/bigdata_stream.sh | 7 +++++++
CI/test_cases/container_cases/bigdata_stream_runc.sh | 4 ++++
CI/test_cases/helpers.sh | 5 ++++-
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/CI/test_cases/container_cases/bigdata_stream.sh b/CI/test_cases/container_cases/bigdata_stream.sh
index 7e74d700..3bfc2d50 100755
--- a/CI/test_cases/container_cases/bigdata_stream.sh
+++ b/CI/test_cases/container_cases/bigdata_stream.sh
@@ -124,6 +124,7 @@ function test_concurrent_bigdata_stream()
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
+ sync && sync
for index in $(seq 1 5); do
ls -l /home/iocopy_stream_data_500M_$index
@@ -151,6 +152,7 @@ function test_concurrent_bigdata_stream_without_pty()
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
+ sync && sync
for index in $(seq 1 5); do
ls -l /home/iocopy_stream_data_500M_$index
@@ -209,6 +211,7 @@ function test_stream_with_stop_client()
kill -18 $pid
wait $pid
+ sync && sync
ls -l /home/iocopy_stream_data_500M
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
@@ -254,6 +257,7 @@ function test_stream_with_stop_attach()
kill -18 $pid
wait $exec_pid
+ sync && sync
ls -l /home/iocopy_stream_data_500M
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
@@ -299,6 +303,7 @@ function test_stream_with_stop_lxc_monitor()
kill -18 $pid
wait $exec_pid
+ sync && sync
ls -l /home/iocopy_stream_data_500M
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
@@ -347,6 +352,7 @@ function test_stream_with_stop_isulad()
kill -18 $(cat /var/run/isulad.pid)
wait $pid
+ sync && sync
ls -l /home/iocopy_stream_data_500M
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
@@ -397,6 +403,7 @@ function test_stream_with_runc()
isula exec -it $RUNCID cat test_500M > /home/iocopy_stream_data_500M
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cat bigdata" && ((ret++))
+ sync && sync
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
diff --git a/CI/test_cases/container_cases/bigdata_stream_runc.sh b/CI/test_cases/container_cases/bigdata_stream_runc.sh
index 6933bef0..3a384cd8 100755
--- a/CI/test_cases/container_cases/bigdata_stream_runc.sh
+++ b/CI/test_cases/container_cases/bigdata_stream_runc.sh
@@ -117,6 +117,7 @@ function test_cat_bigdata()
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
+ sync && sync
for index in $(seq 1 5); do
ls -l /home/iocopy_stream_data_500M_$index
@@ -144,6 +145,7 @@ function test_cat_bigdata_without_pty()
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
+ sync && sync
for index in $(seq 1 5); do
ls -l /home/iocopy_stream_data_500M_$index
@@ -173,6 +175,7 @@ function test_stream_with_stop_client()
kill -18 $pid
wait $pid
+ sync && sync
ls -l /home/iocopy_stream_data_500M
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
@@ -217,6 +220,7 @@ function test_stream_with_stop_isulad()
kill -18 $(cat /var/run/isulad.pid)
wait $pid
+ sync && sync
ls -l /home/iocopy_stream_data_500M
total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
diff --git a/CI/test_cases/helpers.sh b/CI/test_cases/helpers.sh
index bba4e7e3..5ea4ff94 100755
--- a/CI/test_cases/helpers.sh
+++ b/CI/test_cases/helpers.sh
@@ -69,7 +69,10 @@ function testcontainer() {
function crictl() {
CRICTL=$(which crictl)
- "$CRICTL" -i unix:///var/run/isulad.sock -r unix:///var/run/isulad.sock "$@"
+ # Default timeout is 2s.
+ # In some high IO testcase, isulad handle CRI request time maybe more than 2s.
+ # And the crictl will print error message "context deadline exceeded"
+ "$CRICTL" -i unix:///var/run/isulad.sock -r unix:///var/run/isulad.sock --timeout 5s "$@"
}
function msg_ok()
--
2.25.1

View File

@ -0,0 +1,27 @@
From f6243bb672bca8fd2e32752480aa92dc8f97adc9 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Wed, 22 Feb 2023 10:43:52 +0800
Subject: [PATCH 21/22] unlock m_podsLock if new failed
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/daemon/entry/cri/network_plugin.cc | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/daemon/entry/cri/network_plugin.cc b/src/daemon/entry/cri/network_plugin.cc
index f6a155c3..4a119d6b 100644
--- a/src/daemon/entry/cri/network_plugin.cc
+++ b/src/daemon/entry/cri/network_plugin.cc
@@ -345,6 +345,9 @@ void PluginManager::Lock(const std::string &fullPodName, Errors &error)
auto tmpLock = std::unique_ptr<PodLock>(new (std::nothrow) PodLock());
if (tmpLock == nullptr) {
error.SetError("Out of memory");
+ if (pthread_mutex_unlock(&m_podsLock) != 0) {
+ error.SetError("plugin manager unlock failed");
+ }
return;
}
lock = tmpLock.get();
--
2.25.1

73
0022-Update-CRI.patch Normal file
View File

@ -0,0 +1,73 @@
From 65c3b3c803128f92113f9f21bf41da1ad56017c8 Mon Sep 17 00:00:00 2001
From: shijiaqi1 <jiaqi@isrc.iscas.ac.cn>
Date: Wed, 8 Feb 2023 13:31:36 +0800
Subject: [PATCH 22/22] Update-CRI
---
.../cri/cri_container_manager_service.cc | 19 +++++++++++++++++++
src/daemon/entry/cri/cri_helpers.cc | 19 +++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/src/daemon/entry/cri/cri_container_manager_service.cc b/src/daemon/entry/cri/cri_container_manager_service.cc
index 710556a3..b02367c8 100644
--- a/src/daemon/entry/cri/cri_container_manager_service.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service.cc
@@ -1179,6 +1179,25 @@ void ContainerManagerService::UpdateContainerResources(const std::string &contai
if (!resources.cpuset_mems().empty()) {
hostconfig->cpuset_mems = util_strdup_s(resources.cpuset_mems().c_str());
}
+ if (resources.hugepage_limits_size() != 0) {
+ hostconfig->hugetlbs = (host_config_hugetlbs_element **)util_smart_calloc_s(
+ sizeof(host_config_hugetlbs_element *), resources.hugepage_limits_size());
+ if (hostconfig->hugetlbs == nullptr) {
+ error.SetError("Out of memory");
+ return;
+ }
+ for (int i = 0; i < resources.hugepage_limits_size(); i++) {
+ hostconfig->hugetlbs[i] =
+ (host_config_hugetlbs_element *)util_common_calloc_s(sizeof(host_config_hugetlbs_element));
+ if (hostconfig->hugetlbs[i] == nullptr) {
+ error.SetError("Out of memory");
+ goto cleanup;
+ }
+ hostconfig->hugetlbs[i]->page_size = util_strdup_s(resources.hugepage_limits(i).page_size().c_str());
+ hostconfig->hugetlbs[i]->limit = resources.hugepage_limits(i).limit();
+ hostconfig->hugetlbs_len++;
+ }
+ }
request->host_config = host_config_generate_json(hostconfig, &ctx, &perror);
if (request->host_config == nullptr) {
diff --git a/src/daemon/entry/cri/cri_helpers.cc b/src/daemon/entry/cri/cri_helpers.cc
index 2f6dcf78..6d59ec11 100644
--- a/src/daemon/entry/cri/cri_helpers.cc
+++ b/src/daemon/entry/cri/cri_helpers.cc
@@ -461,6 +461,25 @@ void UpdateCreateConfig(container_config *createConfig, host_config *hc,
}
}
hc->unified = unified;
+ if (rOpts.hugepage_limits_size() != 0) {
+ hc->hugetlbs = (host_config_hugetlbs_element **)util_smart_calloc_s(sizeof(host_config_hugetlbs_element *),
+ rOpts.hugepage_limits_size());
+ if (hc->hugetlbs == nullptr) {
+ error.SetError("Out of memory");
+ return;
+ }
+ for (int i = 0; i < rOpts.hugepage_limits_size(); i++) {
+ hc->hugetlbs[i] =
+ (host_config_hugetlbs_element *)util_common_calloc_s(sizeof(host_config_hugetlbs_element));
+ if (hc->hugetlbs[i] == nullptr) {
+ error.SetError("Out of memory");
+ return;
+ }
+ hc->hugetlbs[i]->page_size = util_strdup_s(rOpts.hugepage_limits(i).page_size().c_str());
+ hc->hugetlbs[i]->limit = rOpts.hugepage_limits(i).limit();
+ hc->hugetlbs_len++;
+ }
+ }
}
createConfig->open_stdin = config.stdin();
createConfig->tty = config.tty();
--
2.25.1

View File

@ -1,5 +1,5 @@
%global _version 2.1.1 %global _version 2.1.1
%global _release 3 %global _release 4
%global is_systemd 1 %global is_systemd 1
%global enable_shimv2 1 %global enable_shimv2 1
%global is_embedded 1 %global is_embedded 1
@ -14,6 +14,27 @@ Source: https://gitee.com/openeuler/iSulad/repository/archive/v%{version}.tar
BuildRoot: {_tmppath}/iSulad-%{version} BuildRoot: {_tmppath}/iSulad-%{version}
Patch0001: 0001-modify-dependence-from-lcr-to-libisula.patch Patch0001: 0001-modify-dependence-from-lcr-to-libisula.patch
Patch0002: 0002-Add-unified-memory_swap_limit_in_bytes-fields-into-C.patch
Patch0003: 0003-Add-macro-for-protoc-cmake.patch
Patch0004: 0004-fix-design-typo.patch
Patch0005: 0005-fix-cpu-rt-review-comments.patch
Patch0006: 0006-fix-inspect.sh-failed.patch
Patch0007: 0007-add-CRI-ContainerStats-Service.patch
Patch0008: 0008-fix-isula-cpu-rt-CI.patch
Patch0009: 0009-fix-cpu-rt-CI.patch
Patch0010: 0010-fix-cpu-rt-CI.patch
Patch0011: 0011-Bugfix-in-config-and-executor.patch
Patch0012: 0012-fix-cpu-rt-disable-after-reboot-machine.patch
Patch0013: 0013-fix-selinux_label_ut-timeout-and-add-timeout-for-all.patch
Patch0014: 0014-add-retry-for-read-write.patch
Patch0015: 0015-support-pull-image-with-digest.patch
Patch0016: 0016-isulad-shim-support-execSync-with-timeout.patch
Patch0017: 0017-Refine-the-commit-info.patch
Patch0018: 0018-Refine-typo-of-word-container.patch
Patch0019: 0019-cleancode-for-read-write.patch
Patch0020: 0020-add-crictl-timeout-and-sync-for-CI.patch
Patch0021: 0021-unlock-m_podsLock-if-new-failed.patch
Patch0022: 0022-Update-CRI.patch
%ifarch x86_64 aarch64 %ifarch x86_64 aarch64
Provides: libhttpclient.so()(64bit) Provides: libhttpclient.so()(64bit)
@ -256,6 +277,12 @@ fi
%endif %endif
%changelog %changelog
* Wed Feb 22 2023 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.1.1-4
- Type: bugfix
- ID: NA
- SUG: NA
- DESC: upgrade from upstream
* Thu Feb 16 2023 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.1.1-3 * Thu Feb 16 2023 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.1.1-3
- Type: bugfix - Type: bugfix
- ID: NA - ID: NA