diff --git a/0016-improve-event-logs.patch b/0016-improve-event-logs.patch new file mode 100644 index 0000000000000000000000000000000000000000..06349894920c58ae411d501acdf4629c3396a57c --- /dev/null +++ b/0016-improve-event-logs.patch @@ -0,0 +1,202 @@ +From d611f18abac0f4077c9bf85f76162719cc5e55eb Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Tue, 14 Nov 2023 15:12:39 +0800 +Subject: [PATCH 16/65] improve event logs + +Signed-off-by: haozi007 +--- + .../grpc/cri/v1/cri_v1_runtime_runtime_service.cc | 13 ++++++++----- + .../grpc/cri/v1alpha/cri_runtime_runtime_service.cc | 10 +++++++--- + src/daemon/entry/cri/cni_network_plugin.cc | 6 +++--- + .../cri/v1alpha/cri_pod_sandbox_manager_service.cc | 3 ++- + src/daemon/executor/volume_cb/volume_cb.c | 4 ++-- + src/daemon/modules/network/native/adaptor_native.c | 8 ++++---- + 6 files changed, 26 insertions(+), 18 deletions(-) + +diff --git a/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc +index b8d5746c..1db79307 100644 +--- a/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc ++++ b/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc +@@ -75,7 +75,7 @@ grpc::Status RuntimeV1RuntimeServiceImpl::CreateContainer(grpc::ServerContext *c + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid input arguments"); + } + +- EVENT("Event: {Object: CRI, Type: Creating Container}"); ++ EVENT("Event: {Object: CRI, Type: Creating Container for sandbox: %s}", request->pod_sandbox_id().c_str()); + + std::string responseID = + m_rService->CreateContainer(request->pod_sandbox_id(), request->config(), request->sandbox_config(), error); +@@ -316,17 +316,20 @@ grpc::Status RuntimeV1RuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *con + ERROR("Invalid input arguments"); + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid input arguments"); + } +- +- EVENT("Event: {Object: CRI, Type: Running Pod}"); ++ if (request->has_config() && request->config().has_metadata()) { ++ EVENT("Event: {Object: CRI, Type: Running Pod: %s}", request->config().metadata().name().c_str()); ++ } else { ++ EVENT("Event: {Object: CRI, Type: Running Pod}"); ++ } + + std::string responseID = m_rService->RunPodSandbox(request->config(), request->runtime_handler(), error); + if (!error.Empty() || responseID.empty()) { +- ERROR("Object: CRI, Type: Failed to run pod:%s", error.GetMessage().c_str()); ++ ERROR("Object: CRI, Type: Failed to run pod: %s", error.GetMessage().c_str()); + return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage()); + } + reply->set_pod_sandbox_id(responseID); + +- EVENT("Event: {Object: CRI, Type: Run Pod success}"); ++ EVENT("Event: {Object: CRI, Type: Run Pod: %s success}", responseID.c_str()); + + return grpc::Status::OK; + } +diff --git a/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc +index ec3f01cd..a56b167c 100644 +--- a/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc ++++ b/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc +@@ -73,7 +73,7 @@ grpc::Status RuntimeRuntimeServiceImpl::CreateContainer(grpc::ServerContext *con + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid input arguments"); + } + +- EVENT("Event: {Object: CRI, Type: Creating Container}"); ++ EVENT("Event: {Object: CRI, Type: Creating Container for sandbox: %s}", request->pod_sandbox_id().c_str()); + + std::string responseID = + m_rService->CreateContainer(request->pod_sandbox_id(), request->config(), request->sandbox_config(), error); +@@ -315,7 +315,11 @@ grpc::Status RuntimeRuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *conte + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid input arguments"); + } + +- EVENT("Event: {Object: CRI, Type: Running Pod}"); ++ if (request->has_config() && request->config().has_metadata()) { ++ EVENT("Event: {Object: CRI, Type: Running Pod: %s}", request->config().metadata().name().c_str()); ++ } else { ++ EVENT("Event: {Object: CRI, Type: Running Pod}"); ++ } + + std::string responseID = m_rService->RunPodSandbox(request->config(), request->runtime_handler(), error); + if (!error.Empty() || responseID.empty()) { +@@ -324,7 +328,7 @@ grpc::Status RuntimeRuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *conte + } + reply->set_pod_sandbox_id(responseID); + +- EVENT("Event: {Object: CRI, Type: Run Pod success}"); ++ EVENT("Event: {Object: CRI, Type: Run Pod: %s success}", responseID.c_str()); + + return grpc::Status::OK; + } +diff --git a/src/daemon/entry/cri/cni_network_plugin.cc b/src/daemon/entry/cri/cni_network_plugin.cc +index 656fceda..377796ee 100644 +--- a/src/daemon/entry/cri/cni_network_plugin.cc ++++ b/src/daemon/entry/cri/cni_network_plugin.cc +@@ -612,12 +612,12 @@ void CniNetworkPlugin::SetUpPod(const std::string &ns, const std::string &name, + if (g_isulad_errmsg != nullptr) { + err.SetError(g_isulad_errmsg); + } else { +- err.Errorf("setup cni for container: %s failed", id.c_str()); ++ err.Errorf("setup cni for sandbox: %s failed", id.c_str()); + } + // rollback all network plane + // if mutl-networks, one network plane failed, cause to left network can not be delete. + if (network_module_detach(config, NETWOKR_API_TYPE_CRI) != 0) { +- WARN("rollback all network for: %s failed", id.c_str()); ++ WARN("rollback all network for sandbox: %s failed", id.c_str()); + } + } + +@@ -671,7 +671,7 @@ void CniNetworkPlugin::TearDownPod(const std::string &ns, const std::string &nam + } + + if (network_module_detach(config, NETWOKR_API_TYPE_CRI) != 0) { +- err.Errorf("teardown cni for container: %s failed", id.c_str()); ++ err.Errorf("teardown cni for sandbox: %s failed", id.c_str()); + } + + UnlockNetworkMap(err); +diff --git a/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc +index 8533bb8c..8eff22ac 100644 +--- a/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc ++++ b/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc +@@ -618,6 +618,7 @@ auto PodSandboxManagerService::RunPodSandbox(const runtime::v1alpha2::PodSandbox + // Step 2: Create the sandbox container. + response_id = CreateSandboxContainer(config, image, jsonCheckpoint, runtimeHandler, error); + if (error.NotEmpty()) { ++ ERROR("Create sandbox failed: %s", error.GetCMessage()); + goto cleanup; + } + +@@ -672,7 +673,7 @@ auto PodSandboxManagerService::RunPodSandbox(const runtime::v1alpha2::PodSandbox + UpdatePodSandboxNetworkSettings(response_id, network_setting_json, tmpErr); + // If saving network settings failed, ignore error + if (tmpErr.NotEmpty()) { +- WARN("%s", tmpErr.GetCMessage()); ++ WARN("Update sandbox network setting err: %s", tmpErr.GetCMessage()); + } + } + goto cleanup; +diff --git a/src/daemon/executor/volume_cb/volume_cb.c b/src/daemon/executor/volume_cb/volume_cb.c +index 2148922e..ff5973b8 100644 +--- a/src/daemon/executor/volume_cb/volume_cb.c ++++ b/src/daemon/executor/volume_cb/volume_cb.c +@@ -52,7 +52,7 @@ static int volume_list_cb(const volume_list_volume_request *request, volume_list + goto err_out; + } + +- EVENT("Volume Event: {Object: list volumes, Type: listing}"); ++ INFO("Volume Event: {Object: list volumes, Type: listing}"); + + list = volume_list(); + if (list == NULL) { +@@ -85,7 +85,7 @@ static int volume_list_cb(const volume_list_volume_request *request, volume_list + } + + out: +- EVENT("Volume Event: {Object: list volumes, Type: listed"); ++ INFO("Volume Event: {Object: list volumes, Type: listed"); + + err_out: + if (*response != NULL) { +diff --git a/src/daemon/modules/network/native/adaptor_native.c b/src/daemon/modules/network/native/adaptor_native.c +index 45288d7e..baaecc32 100644 +--- a/src/daemon/modules/network/native/adaptor_native.c ++++ b/src/daemon/modules/network/native/adaptor_native.c +@@ -1510,7 +1510,7 @@ int native_config_inspect(const char *name, char **network_json) + return -1; + } + +- EVENT("Event: {Object: network, Type: inspecting, Target: %s}", name); ++ INFO("Event: {Object: network, Type: inspecting, Target: %s}", name); + + if (!native_store_lock(SHARED)) { + return -1; +@@ -1538,7 +1538,7 @@ int native_config_inspect(const char *name, char **network_json) + + // TODO: inspect the linked containers ip info + +- EVENT("Event: {Object: network, Type: inspected, Target: %s}", name); ++ INFO("Event: {Object: network, Type: inspected, Target: %s}", name); + goto out; + } + +@@ -1635,7 +1635,7 @@ int native_config_list(const struct filters_args *filters, network_network_info + return -1; + } + +- EVENT("Event: {Object: network, Type: listing}"); ++ INFO("Event: {Object: network, Type: listing}"); + + if (!native_store_lock(SHARED)) { + return -1; +@@ -1693,7 +1693,7 @@ int native_config_list(const struct filters_args *filters, network_network_info + *networks_len = nets_len; + nets_len = 0; + +- EVENT("Event: {Object: network, Type: listed}"); ++ INFO("Event: {Object: network, Type: listed}"); + + out: + map_itor_free(itor); +-- +2.42.0 + diff --git a/0016-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch b/0017-2251-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch similarity index 92% rename from 0016-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch rename to 0017-2251-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch index 01a2d1bc3b04a0ae0f47cbb8037a3574c97c9eb3..326eda78272e75c806ac6ae79c65138c7b9e3503 100644 --- a/0016-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch +++ b/0017-2251-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch @@ -1,9 +1,9 @@ -From d903cd356a9fb47ddbc7d23e2f4fe2f72b6242ef Mon Sep 17 00:00:00 2001 +From 48dc6f0adda72d7f4742afe1b8380370debfe4f4 Mon Sep 17 00:00:00 2001 From: zhongtao -Date: Wed, 15 Nov 2023 10:25:40 +0800 -Subject: [PATCH 16/16] open ENABLE_GRPC_REMOTE_CONNECT in CI +Date: Wed, 15 Nov 2023 03:10:15 +0000 +Subject: [PATCH 17/65] !2251 open ENABLE_GRPC_REMOTE_CONNECT in CI * open + ENABLE_GRPC_REMOTE_CONNECT in CI -Signed-off-by: zhongtao --- CI/make-and-install.sh | 4 ++-- CI/only_build_isulad.sh | 2 +- diff --git a/0018-Add-compatibility-between-iSulad-and-k8s.patch b/0018-Add-compatibility-between-iSulad-and-k8s.patch new file mode 100644 index 0000000000000000000000000000000000000000..518656ffcc529b6c38ccef4bed61d86649aefd3b --- /dev/null +++ b/0018-Add-compatibility-between-iSulad-and-k8s.patch @@ -0,0 +1,57 @@ +From bec48dcd219885abd72cb9973a2e810e3f504269 Mon Sep 17 00:00:00 2001 +From: jikai +Date: Wed, 15 Nov 2023 10:51:01 +0800 +Subject: [PATCH 18/65] Add compatibility between iSulad and k8s + +Signed-off-by: jikai +--- + README.md | 13 ++++++++++++- + README_zh.md | 12 +++++++++++- + 2 files changed, 23 insertions(+), 2 deletions(-) + +diff --git a/README.md b/README.md +index 7e4b6de1..e7949dee 100644 +--- a/README.md ++++ b/README.md +@@ -233,4 +233,15 @@ The standard specification versions that `iSulad` is compatible with are as foll + + - Compatible with OCI 1.0.0. + - Compatible with CNI 0.3.0 and above. +-- Compatible with lcr 2.1.x and above. +\ No newline at end of file ++- Compatible with lcr 2.1.x and above. ++ ++## Kubernetes Support ++ ++`iSulad` supports Kubernetes version 1.13 and above. The following table shows the compatibility between `iSulad` and Kubernetes. ++It lists the minimum `iSulad` version required for some given Kubernetes versions. ++ ++iSulad Version | Kubernetes Version | CRI Version ++--- | --- | --- ++v2.0.0+ | v1.13-v1.18 | v1alpha2 ++v2.0.8+ | v1.19-v1.22 | v1alpha2 ++v2.1.4+ | v1.23-v1.26 | v1, v1alpha2 +diff --git a/README_zh.md b/README_zh.md +index 72942765..1c4dff4f 100755 +--- a/README_zh.md ++++ b/README_zh.md +@@ -229,4 +229,14 @@ $ sudo isula rm test + + - 兼容 1.0.0 版本的OCI + - 兼容 0.3.0 版本以上的CNI +-- 兼容 2.1.x 版本以上的lcr +\ No newline at end of file ++- 兼容 2.1.x 版本以上的lcr ++ ++## Kubernetes Support ++ ++`iSulad`提供对Kubernetes 1.13 版本以上的支持。以下表格显示了 `iSulad` 与 Kubernetes 之间的兼容性。它给出了指定Kubernetes版本下所需要的最低 `iSulad` 版本。 ++ ++iSulad 版本 | Kubernetes 版本 | CRI 版本 ++--- | --- | --- ++v2.0.0+ | v1.13-v1.18 | v1alpha2 ++v2.0.8+ | v1.19-v1.22 | v1alpha2 ++v2.1.4+ | v1.23-v1.26 | v1, v1alpha2 +-- +2.42.0 + diff --git a/0019-2254-lcr-container-with-a-damaged-config-file-will-r.patch b/0019-2254-lcr-container-with-a-damaged-config-file-will-r.patch new file mode 100644 index 0000000000000000000000000000000000000000..31362d0f5ccc2188c419d54061ca9a9f6e834167 --- /dev/null +++ b/0019-2254-lcr-container-with-a-damaged-config-file-will-r.patch @@ -0,0 +1,384 @@ +From 21bca2bb054ed7a1b9b78e01965f8a6d9c3fd28d Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 20 Nov 2023 12:58:26 +0000 +Subject: [PATCH 19/65] !2254 lcr container with a damaged config file will + rebuild the config during restore * lcr container with a damaged config file + will rebuild the config during restore + +--- + src/common/constants.h | 2 + + src/daemon/modules/api/runtime_api.h | 7 ++ + .../modules/container/restore/restore.c | 28 ++++-- + .../modules/runtime/engines/lcr/lcr_rt_ops.c | 99 ++++++++++++++++++- + .../modules/runtime/engines/lcr/lcr_rt_ops.h | 1 + + .../modules/runtime/isula/isula_rt_ops.c | 6 ++ + .../modules/runtime/isula/isula_rt_ops.h | 1 + + src/daemon/modules/runtime/runtime.c | 24 +++++ + src/daemon/modules/runtime/shim/shim_rt_ops.c | 6 ++ + src/daemon/modules/runtime/shim/shim_rt_ops.h | 2 + + 10 files changed, 167 insertions(+), 9 deletions(-) + +diff --git a/src/common/constants.h b/src/common/constants.h +index caf9b793..5f12ae25 100644 +--- a/src/common/constants.h ++++ b/src/common/constants.h +@@ -86,6 +86,8 @@ extern "C" { + + #define LOG_MAX_RETRIES 10 + ++#define INVALID_CONFIG_ERR_CODE 2 ++ + #define MAX_MSG_BUFFER_SIZE (32 * 1024) + + #define DEFAULT_WEBSOCKET_SERVER_LISTENING_PORT 10350 +diff --git a/src/daemon/modules/api/runtime_api.h b/src/daemon/modules/api/runtime_api.h +index 3c2100f5..08558f42 100644 +--- a/src/daemon/modules/api/runtime_api.h ++++ b/src/daemon/modules/api/runtime_api.h +@@ -41,6 +41,7 @@ typedef enum { + struct runtime_container_status_info { + bool has_pid; + uint32_t pid; ++ int error_code; + Runtime_Container_Status status; + }; + +@@ -197,6 +198,10 @@ typedef struct _rt_exec_resize_params_t { + unsigned int width; + } rt_exec_resize_params_t; + ++typedef struct _rt_runtime_rebuild_config_params_t { ++ const char *rootpath; ++} rt_rebuild_config_params_t; ++ + struct rt_ops { + /* detect whether runtime is of this runtime type */ + bool (*detect)(const char *runtime); +@@ -233,6 +238,7 @@ struct rt_ops { + rt_listpids_out_t *out); + int (*rt_resize)(const char *name, const char *runtime, const rt_resize_params_t *params); + int (*rt_exec_resize)(const char *name, const char *runtime, const rt_exec_resize_params_t *params); ++ int (*rt_rebuild_config)(const char *name, const char *runtime, const rt_rebuild_config_params_t *params); + }; + + int runtime_create(const char *name, const char *runtime, const rt_create_params_t *params); +@@ -253,6 +259,7 @@ int runtime_attach(const char *name, const char *runtime, const rt_attach_params + int runtime_update(const char *name, const char *runtime, const rt_update_params_t *params); + + int runtime_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out); ++int runtime_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params); + void free_rt_listpids_out_t(rt_listpids_out_t *out); + int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params); + int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_resize_params_t *params); +diff --git a/src/daemon/modules/container/restore/restore.c b/src/daemon/modules/container/restore/restore.c +index c26cf561..f6218fe6 100644 +--- a/src/daemon/modules/container/restore/restore.c ++++ b/src/daemon/modules/container/restore/restore.c +@@ -16,15 +16,18 @@ + #include + #include + #include +-#include +-#include + #include + #include + #include + #include + ++#include ++#include ++#include ++#include ++ + #include "isulad_config.h" +-#include "isula_libutils/log.h" ++ + #include "container_api.h" + #include "supervisor.h" + #include "containers_gc.h" +@@ -276,9 +279,22 @@ static void restore_state(container_t *cont) + #endif + nret = runtime_status(id, runtime, ¶ms, &real_status); + if (nret != 0) { +- WARN("Failed to restore container %s, make real status to STOPPED. Due to can not load container with status %d", +- id, status); +- real_status.status = RUNTIME_CONTAINER_STATUS_STOPPED; ++ bool rebuild_config = (real_status.error_code == INVALID_CONFIG_ERR_CODE); ++ int tempret = -1; ++ // only the lcr container with a damaged config file will rebuild the config ++ if (rebuild_config) { ++ rt_rebuild_config_params_t rebuild_params = { 0 }; ++ rebuild_params.rootpath = cont->root_path; ++ nret = runtime_rebuild_config(id, runtime, &rebuild_params); ++ EVENT("Rebuild config for container: %s, result : %d", id, nret); ++ if (nret == 0) { ++ tempret = runtime_status(id, runtime, ¶ms, &real_status); ++ } ++ } ++ if (tempret != 0) { ++ WARN("Failed to restore container %s, make real status to STOPPED. Due to cannot load container with status %d", id, status); ++ real_status.status = RUNTIME_CONTAINER_STATUS_STOPPED; ++ } + } + + if (real_status.status == RUNTIME_CONTAINER_STATUS_STOPPED) { +diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +index f61316d0..2f42909b 100644 +--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c ++++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +@@ -16,15 +16,18 @@ + #include + #include + #include +-#include +-#include + #include + #include + #include + #include + ++#include ++#include ++#include ++#include ++#include ++ + #include "lcr_rt_ops.h" +-#include "isula_libutils/log.h" + #include "engine.h" + #include "error.h" + #include "isulad_config.h" +@@ -32,6 +35,8 @@ + #include "runtime_api.h" + #include "utils_file.h" + ++#define LCR_CONFIG_FILE "config" ++ + bool rt_lcr_detect(const char *runtime) + { + /* now we just support lcr engine */ +@@ -276,6 +281,17 @@ int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_ + nret = engine_ops->engine_get_container_status_op(name, params->rootpath, status); + if (nret != 0) { + ret = -1; ++ const char *tmpmsg = NULL; ++ if (engine_ops->engine_get_errmsg_op != NULL) { ++ tmpmsg = engine_ops->engine_get_errmsg_op(); ++ } ++ if (tmpmsg != NULL && strstr(tmpmsg, "Failed to load config") != NULL) { ++ status->error_code = INVALID_CONFIG_ERR_CODE; ++ } ++ isulad_set_error_message("Runtime state container error: %s", ++ (tmpmsg != NULL && strcmp(tmpmsg, DEF_SUCCESS_STR)) != 0 ? tmpmsg : DEF_ERR_RUNTIME_STR); ++ ERROR("Runtime state container error: %s", ++ (tmpmsg != NULL && strcmp(tmpmsg, DEF_SUCCESS_STR)) != 0 ? tmpmsg : DEF_ERR_RUNTIME_STR); + goto out; + } + +@@ -756,3 +772,80 @@ int rt_lcr_kill(const char *id, const char *runtime, const rt_kill_params_t *par + + return 0; + } ++ ++int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params) ++{ ++ int ret = -1; ++ int nret = 0; ++ char config_file[PATH_MAX] = { 0 }; ++ char bak_config_file[PATH_MAX] = { 0 }; ++ char oci_config_file[PATH_MAX] = { 0 }; ++ struct engine_operation *engine_ops = NULL; ++ oci_runtime_spec *oci_spec = NULL; ++ __isula_auto_free char *json_container = NULL; ++ __isula_auto_free parser_error err = NULL; ++ ++ engine_ops = engines_get_handler(runtime); ++ if (engine_ops == NULL || engine_ops->engine_create_op == NULL) { ++ ERROR("Failed to get engine rebuild config operations"); ++ return -1; ++ } ++ ++ nret = snprintf(config_file, PATH_MAX, "%s/%s/%s", params->rootpath, name, LCR_CONFIG_FILE); ++ if (nret < 0 || (size_t)nret >= PATH_MAX) { ++ ERROR("Failed to snprintf config file for container %s", name); ++ return -1; ++ } ++ ++ nret = snprintf(bak_config_file, PATH_MAX, "%s/%s/%s", params->rootpath, name, ".tmp_config_bak"); ++ if (nret < 0 || (size_t)nret >= PATH_MAX) { ++ ERROR("Failed to snprintf bak config file for container %s", name); ++ return -1; ++ } ++ ++ nret = snprintf(oci_config_file, sizeof(oci_config_file), "%s/%s/%s", params->rootpath, name, OCI_CONFIG_JSON); ++ if (nret < 0 || (size_t)nret >= sizeof(oci_config_file)) { ++ ERROR("Failed to snprintf for config json"); ++ return -1; ++ } ++ ++ oci_spec = oci_runtime_spec_parse_file(oci_config_file, NULL, &err); ++ if (oci_spec == NULL) { ++ ERROR("Failed to parse oci config file:%s", err); ++ return -1; ++ } ++ ++ // delete the bak config file to prevent the remnants of the previous bak file ++ if (util_fileself_exists(bak_config_file) && util_path_remove(bak_config_file) != 0) { ++ ERROR("Failed to remove bak_config_file for container: %s", name); ++ goto out; ++ } ++ ++ if (util_fileself_exists(config_file) && rename(config_file, bak_config_file) != 0) { ++ ERROR("Failed to backup old config for container: %s", name); ++ goto out; ++ } ++ ++ nret = engine_ops->engine_create_op(name, params->rootpath, (void *)oci_spec); ++ if (nret != 0) { ++ // delete the invalid config file to prevent rename failed ++ if (util_fileself_exists(config_file) && util_path_remove(config_file) != 0) { ++ WARN("Failed to remove bak_config_file for container %s", name); ++ } ++ if (util_fileself_exists(bak_config_file) && rename(bak_config_file, config_file) != 0) { ++ WARN("Failed to rename backup old config to config for container %s", name); ++ } ++ } ++ ++ ret = 0; ++ ++out: ++ if (engine_ops != NULL && engine_ops->engine_clear_errmsg_op != NULL) { ++ engine_ops->engine_clear_errmsg_op(); ++ } ++ if (util_fileself_exists(bak_config_file) && util_path_remove(bak_config_file) != 0) { ++ WARN("Failed to remove bak_config_file for %s", name); ++ } ++ free_oci_runtime_spec(oci_spec); ++ return ret; ++} +diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h +index 5b74ad6c..7403544d 100644 +--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h ++++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h +@@ -47,6 +47,7 @@ int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats + int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t *params); + int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params); + int rt_lcr_kill(const char *id, const char *runtime, const rt_kill_params_t *params); ++int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params); + #ifdef __cplusplus + } + #endif +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 1787170b..83214c1a 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -2013,3 +2013,9 @@ int rt_isula_kill(const char *id, const char *runtime, const rt_kill_params_t *p + + return 0; + } ++ ++// the config file of oci runtime is config.json. If it is damaged, it cannot be rebuilt. ++int rt_isula_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params) ++{ ++ return 0; ++} +\ No newline at end of file +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.h b/src/daemon/modules/runtime/isula/isula_rt_ops.h +index 49b6cc0e..1e5e049a 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.h ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.h +@@ -46,6 +46,7 @@ int rt_isula_resources_stats(const char *name, const char *runtime, const rt_sta + int rt_isula_resize(const char *id, const char *runtime, const rt_resize_params_t *params); + int rt_isula_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params); + int rt_isula_kill(const char *id, const char *runtime, const rt_kill_params_t *params); ++int rt_isula_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params); + + #ifdef __cplusplus + } +diff --git a/src/daemon/modules/runtime/runtime.c b/src/daemon/modules/runtime/runtime.c +index cb383970..d9a332af 100644 +--- a/src/daemon/modules/runtime/runtime.c ++++ b/src/daemon/modules/runtime/runtime.c +@@ -45,6 +45,7 @@ static const struct rt_ops g_lcr_rt_ops = { + .rt_resize = rt_lcr_resize, + .rt_exec_resize = rt_lcr_exec_resize, + .rt_kill = rt_lcr_kill, ++ .rt_rebuild_config = rt_lcr_rebuild_config, + }; + + static const struct rt_ops g_isula_rt_ops = { +@@ -65,6 +66,7 @@ static const struct rt_ops g_isula_rt_ops = { + .rt_resize = rt_isula_resize, + .rt_exec_resize = rt_isula_exec_resize, + .rt_kill = rt_isula_kill, ++ .rt_rebuild_config = rt_isula_rebuild_config, + }; + + #ifdef ENABLE_SHIM_V2 +@@ -86,6 +88,7 @@ static const struct rt_ops g_shim_rt_ops = { + .rt_resize = rt_shim_resize, + .rt_exec_resize = rt_shim_exec_resize, + .rt_kill = rt_shim_kill, ++ .rt_rebuild_config = rt_shim_rebuild_config, + }; + #endif + +@@ -465,6 +468,27 @@ out: + return ret; + } + ++int runtime_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params) ++{ ++ int ret = 0; ++ const struct rt_ops *ops = NULL; ++ ++ if (name == NULL || runtime == NULL || params == NULL) { ++ ERROR("Invalid arguments for runtime rebuild config"); ++ return -1; ++ } ++ ++ ops = rt_ops_query(runtime); ++ if (ops == NULL) { ++ ERROR("Failed to get runtime ops"); ++ return -1; ++ } ++ ++ ret = ops->rt_rebuild_config(name, runtime, params); ++ ++ return ret; ++} ++ + int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params) + { + int ret = 0; +diff --git a/src/daemon/modules/runtime/shim/shim_rt_ops.c b/src/daemon/modules/runtime/shim/shim_rt_ops.c +index 550b17f3..56fc43c2 100644 +--- a/src/daemon/modules/runtime/shim/shim_rt_ops.c ++++ b/src/daemon/modules/runtime/shim/shim_rt_ops.c +@@ -805,3 +805,9 @@ int rt_shim_kill(const char *id, const char *runtime, const rt_kill_params_t *pa + + return 0; + } ++ ++// the config file of oci runtime is config.json. If it is damaged, it cannot be rebuilt. ++int rt_shim_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params) ++{ ++ return 0; ++} +\ No newline at end of file +diff --git a/src/daemon/modules/runtime/shim/shim_rt_ops.h b/src/daemon/modules/runtime/shim/shim_rt_ops.h +index 03b7c018..2df34f4c 100644 +--- a/src/daemon/modules/runtime/shim/shim_rt_ops.h ++++ b/src/daemon/modules/runtime/shim/shim_rt_ops.h +@@ -62,6 +62,8 @@ int rt_shim_exec_resize(const char *id, const char *runtime, const rt_exec_resiz + + bool is_valid_v2_runtime(const char* name); + ++int rt_shim_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params); ++ + #ifdef __cplusplus + } + #endif +-- +2.42.0 + diff --git a/0020-2253-bugfix-for-runc-container-exec.patch b/0020-2253-bugfix-for-runc-container-exec.patch new file mode 100644 index 0000000000000000000000000000000000000000..f83ae17666092b6fdc0db71bc514315ee988152d --- /dev/null +++ b/0020-2253-bugfix-for-runc-container-exec.patch @@ -0,0 +1,39 @@ +From 6b636051af158fac017998732d7d121b8ea71081 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 20 Nov 2023 12:59:09 +0000 +Subject: [PATCH 20/65] !2253 bugfix for runc container exec * bugfix for runc + container exec + +--- + src/daemon/modules/runtime/isula/isula_rt_ops.c | 9 ++++----- + 1 file changed, 4 insertions(+), 5 deletions(-) + +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 83214c1a..e61d1f91 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -1386,17 +1386,16 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p + } + + ret = shim_create(fg_exec(params), id, workdir, bundle, cmd, exit_code, timeout, &shim_exit_code); +- if (ret != 0) { +- ERROR("%s: failed create shim process for exec %s", id, exec_id); +- goto errlog_out; +- } +- + if (shim_exit_code == SHIM_EXIT_TIMEOUT) { + ret = -1; + isulad_set_error_message("Exec container error;exec timeout"); + ERROR("isulad-shim %d exit for execing timeout", pid); + goto errlog_out; + } ++ if (ret != 0) { ++ ERROR("%s: failed create shim process for exec %s", id, exec_id); ++ goto errlog_out; ++ } + + pid = get_container_process_pid(workdir); + if (pid < 0) { +-- +2.42.0 + diff --git a/0021-bugfix-of-update-restart-policy-for-auto-remove-cont.patch b/0021-bugfix-of-update-restart-policy-for-auto-remove-cont.patch new file mode 100644 index 0000000000000000000000000000000000000000..9211e1f23ccfa1e88d3fe90cbd95f53041c65da4 --- /dev/null +++ b/0021-bugfix-of-update-restart-policy-for-auto-remove-cont.patch @@ -0,0 +1,58 @@ +From ea51fa836464660fcca245e7e36a2b4cdf1e5997 Mon Sep 17 00:00:00 2001 +From: zhangxiaoyu +Date: Tue, 21 Nov 2023 10:23:26 +0800 +Subject: [PATCH 21/65] bugfix of update restart policy for auto remove + container + +Signed-off-by: zhangxiaoyu +--- + .../executor/container_cb/execution_extend.c | 18 +++++++++++------- + 1 file changed, 11 insertions(+), 7 deletions(-) + +diff --git a/src/daemon/executor/container_cb/execution_extend.c b/src/daemon/executor/container_cb/execution_extend.c +index 6759a4fc..de017b4e 100644 +--- a/src/daemon/executor/container_cb/execution_extend.c ++++ b/src/daemon/executor/container_cb/execution_extend.c +@@ -1113,15 +1113,14 @@ static int update_host_config_check(container_t *cont, host_config *hostconfig) + + ret = verify_host_config_settings(hostconfig, true); + if (ret != 0) { +- goto out; ++ return -1; + } + + if (container_is_removal_in_progress(cont->state) || container_is_dead(cont->state)) { + ERROR("Container is marked for removal and cannot be \"update\"."); + isulad_set_error_message( + "Cannot update container %s: Container is marked for removal and cannot be \"update\".", id); +- ret = -1; +- goto out; ++ return -1; + } + + if (container_is_running(cont->state) && hostconfig->kernel_memory) { +@@ -1129,12 +1128,17 @@ static int update_host_config_check(container_t *cont, host_config *hostconfig) + isulad_set_error_message("Cannot update container %s: Can not update kernel memory to a running container," + " please stop it first.", + id); +- ret = -1; +- goto out; ++ return -1; + } + +-out: +- return ret; ++ if (cont->hostconfig->auto_remove && hostconfig->restart_policy != NULL && ++ hostconfig->restart_policy->name != NULL && strcmp("no", hostconfig->restart_policy->name) != 0) { ++ ERROR("Cannot update restart policy for the auto remove container %s", id); ++ isulad_set_error_message("Cannot update restart policy for the auto remove container %s", id); ++ return -1; ++ } ++ ++ return 0; + } + + static int do_update_resources(const container_update_request *request, container_t *cont) +-- +2.42.0 + diff --git a/0022-add-update-restart-policy-test.patch b/0022-add-update-restart-policy-test.patch new file mode 100644 index 0000000000000000000000000000000000000000..a7ce17ea224355d3abc0b29956643a6c37e3a961 --- /dev/null +++ b/0022-add-update-restart-policy-test.patch @@ -0,0 +1,57 @@ +From 6815aec33caedaacba3b392ee5a2e5088fdf1faa Mon Sep 17 00:00:00 2001 +From: zhangxiaoyu +Date: Tue, 21 Nov 2023 10:24:26 +0800 +Subject: [PATCH 22/65] add update restart policy test + +Signed-off-by: zhangxiaoyu +--- + CI/test_cases/container_cases/update.sh | 26 +++++++++++++++++++++++++ + 1 file changed, 26 insertions(+) + +diff --git a/CI/test_cases/container_cases/update.sh b/CI/test_cases/container_cases/update.sh +index d379acc2..29543e7c 100755 +--- a/CI/test_cases/container_cases/update.sh ++++ b/CI/test_cases/container_cases/update.sh +@@ -138,6 +138,27 @@ function do_test_t() + return $TC_RET_T + } + ++function test_autoremove_restartpolicy() ++{ ++ containername=test_update2 ++ containerid=`isula run -itd --runtime $1 --rm --name $containername busybox` ++ fn_check_eq "$?" "0" "run failed" ++ ++ isula update --restart always $containerid ++ fn_check_ne "$?" "0" "update should fail" ++ ++ isula update --restart nooooooooooo $containerid ++ fn_check_ne "$?" "0" "update should fail" ++ ++ isula update --restart no $containerid ++ fn_check_eq "$?" "0" "update restart policy no failed" ++ ++ isula rm -f $containername ++ fn_check_eq "$?" "0" "rm failed" ++ ++ return $TC_RET_T ++} ++ + function do_test_t1() + { + containername=test_update1 +@@ -173,6 +194,11 @@ do + let "ret=$ret + 1" + fi + ++ test_autoremove_restartpolicy $element ++ if [ $? -ne 0 ];then ++ let "ret=$ret + 1" ++ fi ++ + if [ -f "/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes" ];then + do_test_t1 $element + if [ $? -ne 0 ];then +-- +2.42.0 + diff --git a/0023-2260-bugfix-for-rebuild-config.patch b/0023-2260-bugfix-for-rebuild-config.patch new file mode 100644 index 0000000000000000000000000000000000000000..2a61c5cda81850cfe66409689511a4f717bc7a1f --- /dev/null +++ b/0023-2260-bugfix-for-rebuild-config.patch @@ -0,0 +1,73 @@ +From f08072a865fcf6191d65e7c01e11b99049758c57 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 21 Nov 2023 03:27:31 +0000 +Subject: [PATCH 23/65] !2260 bugfix for rebuild config * bugfix for rebuild + config + +--- + src/daemon/modules/container/restore/restore.c | 1 - + src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c | 5 +---- + src/daemon/modules/runtime/runtime.c | 5 +---- + 3 files changed, 2 insertions(+), 9 deletions(-) + +diff --git a/src/daemon/modules/container/restore/restore.c b/src/daemon/modules/container/restore/restore.c +index f6218fe6..a60b1410 100644 +--- a/src/daemon/modules/container/restore/restore.c ++++ b/src/daemon/modules/container/restore/restore.c +@@ -24,7 +24,6 @@ + #include + #include + #include +-#include + + #include "isulad_config.h" + +diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +index 2f42909b..8f7211d7 100644 +--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c ++++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +@@ -782,7 +782,6 @@ int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuil + char oci_config_file[PATH_MAX] = { 0 }; + struct engine_operation *engine_ops = NULL; + oci_runtime_spec *oci_spec = NULL; +- __isula_auto_free char *json_container = NULL; + __isula_auto_free parser_error err = NULL; + + engine_ops = engines_get_handler(runtime); +@@ -836,9 +835,7 @@ int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuil + WARN("Failed to rename backup old config to config for container %s", name); + } + } +- +- ret = 0; +- ++ ret = nret != 0 ? -1 : 0; + out: + if (engine_ops != NULL && engine_ops->engine_clear_errmsg_op != NULL) { + engine_ops->engine_clear_errmsg_op(); +diff --git a/src/daemon/modules/runtime/runtime.c b/src/daemon/modules/runtime/runtime.c +index d9a332af..4a239f0a 100644 +--- a/src/daemon/modules/runtime/runtime.c ++++ b/src/daemon/modules/runtime/runtime.c +@@ -470,7 +470,6 @@ out: + + int runtime_rebuild_config(const char *name, const char *runtime, const rt_rebuild_config_params_t *params) + { +- int ret = 0; + const struct rt_ops *ops = NULL; + + if (name == NULL || runtime == NULL || params == NULL) { +@@ -484,9 +483,7 @@ int runtime_rebuild_config(const char *name, const char *runtime, const rt_rebui + return -1; + } + +- ret = ops->rt_rebuild_config(name, runtime, params); +- +- return ret; ++ return ops->rt_rebuild_config(name, runtime, params); + } + + int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params) +-- +2.42.0 + diff --git a/0024-2170-isula-image-pull.patch b/0024-2170-isula-image-pull.patch new file mode 100644 index 0000000000000000000000000000000000000000..7a72b677f2a8c22ceb758afb31d2adc58e4236af --- /dev/null +++ b/0024-2170-isula-image-pull.patch @@ -0,0 +1,1815 @@ +From 53d551f613bfa8ce0552ca62f964a0584e3665bb Mon Sep 17 00:00:00 2001 +From: sailorvii +Date: Wed, 22 Nov 2023 01:22:04 +0000 +Subject: [PATCH 24/65] =?UTF-8?q?!2170=20=E5=A2=9E=E5=8A=A0isula=20image?= + =?UTF-8?q?=20pull=E8=BF=9B=E5=BA=A6=E6=98=BE=E7=A4=BA=20*=20Refine=20some?= + =?UTF-8?q?=20issues.=20*=20Address=20comment=20*=20Address=20comments=20*?= + =?UTF-8?q?=201.=20Address=20comments.=20*=20Address=20comments=20*=20Addr?= + =?UTF-8?q?ess=20comments=20*=20Address=20comments=20*=20Address=20comment?= + =?UTF-8?q?s=20*=20Address=20comments=20*=20Address=20comments=20*=20Addre?= + =?UTF-8?q?ss=20comments=20*=20Address=20comments=20*=20Address=20comments?= + =?UTF-8?q?=20*=20Address=20test=20issue=20*=20Address=20test=20compile=20?= + =?UTF-8?q?issue=20*=20Address=20compile=20issue=20*=20Fix=20compile=20iss?= + =?UTF-8?q?ue=20*=20Address=20comments=20*=20Address=20comments=20*=20Addr?= + =?UTF-8?q?ess=20comments.=20*=20Address=20issuse=20*=20Address=20many=20i?= + =?UTF-8?q?ssues.=20*=20Fix=20some=20minor=20issuses.=20*=20Address=20comm?= + =?UTF-8?q?ents.=20*=20Refine=20as=20Haozi's=20comments=20*=20Fix=20some?= + =?UTF-8?q?=20issues=20by=20Haozi's=20comments.=20*=20Refine=20formats.=20?= + =?UTF-8?q?*=20Add=20process=20bar=20show=20for=20pull=20functions.?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + CI/dockerfiles/Dockerfile-fedora | 2 +- + CI/pr-gateway.sh | 2 +- + cmake/checker.cmake | 10 ++ + src/CMakeLists.txt | 4 + + src/api/services/images/images.proto | 35 +++- + src/client/connect/grpc/grpc_images_client.cc | 167 ++++++++++++++++-- + src/client/connect/protocol_type.h | 1 + + src/cmd/isula/images/pull.c | 26 ++- + .../connect/grpc/grpc_containers_service.h | 4 + + .../entry/connect/grpc/grpc_images_service.cc | 105 ++++++++++- + .../entry/connect/grpc/grpc_images_service.h | 7 + + .../entry/connect/rest/rest_images_service.c | 2 +- + .../v1/v1_cri_image_manager_service_impl.cc | 2 +- + .../v1alpha/cri_image_manager_service_impl.cc | 2 +- + src/daemon/executor/callback.h | 3 +- + src/daemon/executor/image_cb/image_cb.c | 8 +- + src/daemon/modules/api/image_api.h | 5 +- + src/daemon/modules/image/image.c | 9 +- + src/daemon/modules/image/oci/oci_image.c | 4 +- + src/daemon/modules/image/oci/oci_image.h | 2 +- + src/daemon/modules/image/oci/oci_pull.c | 158 +++++++++++++++-- + src/daemon/modules/image/oci/oci_pull.h | 2 +- + src/daemon/modules/image/oci/progress.c | 124 +++++++++++++ + src/daemon/modules/image/oci/progress.h | 52 ++++++ + .../modules/image/oci/registry/http_request.c | 104 ++++++++--- + .../modules/image/oci/registry/http_request.h | 2 +- + .../modules/image/oci/registry/registry.c | 3 +- + .../modules/image/oci/registry/registry.h | 2 + + .../image/oci/registry/registry_apiv2.c | 12 +- + src/daemon/modules/image/oci/registry_type.h | 3 + + src/utils/CMakeLists.txt | 3 + + src/utils/http/http.h | 17 +- + src/utils/progress/CMakeLists.txt | 13 ++ + src/utils/progress/show.c | 64 +++++++ + src/utils/progress/show.h | 34 ++++ + test/cutils/CMakeLists.txt | 1 + + test/image/oci/registry/CMakeLists.txt | 1 + + test/image/oci/registry/registry_ut.cc | 16 +- + 38 files changed, 912 insertions(+), 99 deletions(-) + create mode 100644 src/daemon/modules/image/oci/progress.c + create mode 100644 src/daemon/modules/image/oci/progress.h + create mode 100644 src/utils/progress/CMakeLists.txt + create mode 100644 src/utils/progress/show.c + create mode 100644 src/utils/progress/show.h + +diff --git a/CI/dockerfiles/Dockerfile-fedora b/CI/dockerfiles/Dockerfile-fedora +index bef44377..a105cbb4 100644 +--- a/CI/dockerfiles/Dockerfile-fedora ++++ b/CI/dockerfiles/Dockerfile-fedora +@@ -115,7 +115,7 @@ RUN echo "[source.crates-io]" >> ${HOME}/.cargo/config && \ + echo "[source.local-registry]" >> ${HOME}/.cargo/config && \ + echo "directory = \"vendor\"" >> ${HOME}/.cargo/config + +-RUN dnf install -y lcov && dnf clean all ++RUN dnf install -y lcov ncurses-devel && dnf clean all + + # install libevhtp + RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \ +diff --git a/CI/pr-gateway.sh b/CI/pr-gateway.sh +index 08bcfc4f..e5bf627e 100755 +--- a/CI/pr-gateway.sh ++++ b/CI/pr-gateway.sh +@@ -22,7 +22,7 @@ sed -i "s#http://repo.openeuler.org#https://repo.huaweicloud.com/openeuler#g" /e + + dnf update -y + +-dnf install -y docbook2X doxygen gtest-devel gmock-devel diffutils cmake gcc-c++ yajl-devel patch make libtool libevent-devel libevhtp-devel grpc grpc-plugins grpc-devel protobuf-devel libcurl libcurl-devel sqlite-devel libarchive-devel device-mapper-devel http-parser-devel libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel systemd-devel git chrpath ++dnf install -y docbook2X doxygen gtest-devel gmock-devel diffutils cmake gcc-c++ yajl-devel patch make libtool libevent-devel libevhtp-devel grpc grpc-plugins grpc-devel protobuf-devel libcurl libcurl-devel sqlite-devel libarchive-devel device-mapper-devel http-parser-devel libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel systemd-devel git chrpath ncurses-devel + if [ $? -ne 0 ]; then + echo "install dependences failed" + exit 1 +diff --git a/cmake/checker.cmake b/cmake/checker.cmake +index 358ab4af..cc4a1fc3 100644 +--- a/cmake/checker.cmake ++++ b/cmake/checker.cmake +@@ -154,6 +154,16 @@ if (GRPC_CONNECTOR) + _CHECK(WEBSOCKET_INCLUDE_DIR "WEBSOCKET_INCLUDE_DIR-NOTFOUND" libwebsockets.h) + find_library(WEBSOCKET_LIBRARY websockets) + _CHECK(WEBSOCKET_LIBRARY "WEBSOCKET_LIBRARY-NOTFOUND" "libwebsockets.so") ++ ++ # check libncurses ++ pkg_check_modules(PC_LIBNCURSES REQUIRED "ncurses") ++ find_path(NCURSES_INCLUDE_DIR curses.h ++ HINTS ${PC_NCURSES_INCLUDEDIR} ${PC_NCURSES_INCLUDE_DIRS}) ++ _CHECK(NCURSES_INCLUDE_DIR "NCURSES_INCLUDE_DIR-NOTFOUND" "curses.h") ++ ++ find_library(NCURSES_LIBRARY ncurses ++ HINTS ${PC_NCURSES_LIBDIR} ${PC_NCURSES_LIBRARY_DIRS}) ++ _CHECK(NCURSES_LIBRARY "NCURSES_LIBRARY-NOTFOUND" "libncurses.so") + endif() + + if ((NOT GRPC_CONNECTOR) OR (GRPC_CONNECTOR AND ENABLE_METRICS)) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 8e197b9f..860447de 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -102,6 +102,10 @@ add_executable(isula + ) + target_include_directories(isula PUBLIC ${ISULA_INCS} ${SHARED_INCS}) + target_link_libraries(isula libisula_client ${LIBYAJL_LIBRARY}) ++if (GRPC_CONNECTOR) ++ target_link_libraries(isula ${NCURSES_LIBRARY}) ++endif() ++ + if (ANDROID OR MUSL) + target_link_libraries(isula ${LIBSSL_LIBRARY}) + else() +diff --git a/src/api/services/images/images.proto b/src/api/services/images/images.proto +index 2a34f02d..9f2cb803 100644 +--- a/src/api/services/images/images.proto ++++ b/src/api/services/images/images.proto +@@ -30,6 +30,23 @@ service ImagesService { + rpc Tag(TagImageRequest) returns (TagImageResponse); + rpc Import(ImportRequest) returns (ImportResponse); + rpc Search(SearchRequest) returns (SearchResponse); ++ rpc PullImage(PullImageRequest) returns (stream PullImageResponse); ++} ++ ++// ImageSpec is an internal representation of an image. ++message ImageSpec { ++ // Container's Image field (e.g. imageID or imageDigest). ++ string image = 1; ++ // Unstructured key-value map holding arbitrary metadata. ++ // ImageSpec Annotations can be used to help the runtime target specific ++ // images in multi-arch images. ++ map annotations = 2; ++} ++ ++// AuthConfig contains authorization information for connecting to a registry. ++message AuthConfig { ++ string username = 1; ++ string password = 2; + } + + message Descriptor { +@@ -152,4 +169,20 @@ message SearchResponse { + repeated SearchImage search_result = 2; + uint32 cc = 3; + string errmsg = 4; +-} +\ No newline at end of file ++} ++ ++message PullImageRequest { ++ // Spec of the image. ++ ImageSpec image = 1; ++ // Authentication configuration for pulling the image. ++ AuthConfig auth = 2; ++ bool is_progress_visible = 3; ++} ++ ++message PullImageResponse { ++ // Reference to the image in use. For most runtimes, this should be an ++ // image ID or digest. ++ string image_ref = 1; ++ string stream = 2; ++ bytes progress_data = 3; ++} +diff --git a/src/client/connect/grpc/grpc_images_client.cc b/src/client/connect/grpc/grpc_images_client.cc +index 9cc2a174..7a283e8c 100644 +--- a/src/client/connect/grpc/grpc_images_client.cc ++++ b/src/client/connect/grpc/grpc_images_client.cc +@@ -13,12 +13,15 @@ + * Description: provide grpc container service functions + ******************************************************************************/ + #include "grpc_images_client.h" +-#include "api.grpc.pb.h" + #include "client_base.h" + #include "images.grpc.pb.h" ++ ++#include ++#include ++#include ++#include "show.h" + #include "utils.h" + #include "constants.h" +-#include + + using namespace images; + +@@ -337,9 +340,9 @@ public: + } + }; + +-class ImagesPull : public ClientBase { ++class ImagesPull : public ClientBase { + public: + explicit ImagesPull(void *args) + : ClientBase(args) +@@ -347,15 +350,14 @@ public: + } + ~ImagesPull() = default; + +- auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest) ++ auto request_to_grpc(const isula_pull_request *request, PullImageRequest *grequest) + -> int override + { + if (request == nullptr) { + return -1; + } +- + if (request->image_name != nullptr) { +- auto *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec; ++ auto *image_spec = new (std::nothrow) ImageSpec; + if (image_spec == nullptr) { + return -1; + } +@@ -363,10 +365,12 @@ public: + grequest->set_allocated_image(image_spec); + } + ++ grequest->set_is_progress_visible(request->is_progress_visible); ++ + return 0; + } + +- auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response) ++ auto response_from_grpc(PullImageResponse *gresponse, isula_pull_response *response) + -> int override + { + if (!gresponse->image_ref().empty()) { +@@ -376,7 +380,7 @@ public: + return 0; + } + +- auto check_parameter(const runtime::v1alpha2::PullImageRequest &req) -> int override ++ auto check_parameter(const PullImageRequest &req) -> int override + { + if (req.image().image().empty()) { + ERROR("Missing image name in the request"); +@@ -386,10 +390,147 @@ public: + return 0; + } + +- auto grpc_call(ClientContext *context, const runtime::v1alpha2::PullImageRequest &req, +- runtime::v1alpha2::PullImageResponse *reply) -> Status override ++ auto run(const struct isula_pull_request *request, struct isula_pull_response *response) -> int override ++ { ++ ClientContext context; ++ PullImageRequest grequest; ++ ++#ifdef ENABLE_GRPC_REMOTE_CONNECT ++#ifdef OPENSSL_VERIFY ++ // Set common name from cert.perm ++ char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 }; ++ int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value, ++ ClientBaseConstants::COMMON_NAME_LEN); ++ if (ret != 0) { ++ ERROR("Failed to get common name in: %s", m_certFile.c_str()); ++ return -1; ++ } ++ context.AddMetadata("username", std::string(common_name_value, strlen(common_name_value))); ++ context.AddMetadata("tls_mode", m_tlsMode); ++#endif ++#endif ++ if (request_to_grpc(request, &grequest) != 0) { ++ ERROR("Failed to transform pull request to grpc"); ++ response->server_errono = ISULAD_ERR_INPUT; ++ return -1; ++ } ++ ++ auto reader = stub_->PullImage(&context, grequest); ++ ++ PullImageResponse gresponse; ++ if (grequest.is_progress_visible()) { ++ while (reader->Read(&gresponse)) { ++ output_progress(gresponse); ++ } ++ } else { ++ reader->Read(&gresponse); ++ WARN("The terminal may not support ANSI Escape code. Display is skipped"); ++ } ++ Status status = reader->Finish(); ++ if (!status.ok()) { ++ ERROR("Error code: %d: %s", status.error_code(), status.error_message().c_str()); ++ unpackStatus(status, response); ++ return -1; ++ } ++ response->image_ref = util_strdup_s(gresponse.image_ref().c_str()); ++ return 0; ++ } ++ ++private: ++ void output_progress(PullImageResponse &gresponse) + { +- return stub_->PullImage(context, req, reply); ++ __isula_auto_free char *err = nullptr; ++ struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; ++ ++ image_progress *progresses = image_progress_parse_data(gresponse.progress_data().c_str(), &ctx, &err); ++ if (progresses == nullptr) { ++ ERROR("Parse image progress error %s", err); ++ return; ++ } ++ show_processes(progresses); ++ } ++ ++ void get_printed_value(int64_t value, char *printed) ++ { ++ float float_value = 0.0; ++ const float GB = 1024 * 1024 * 1024; ++ const float MB = 1024 * 1024; ++ const float KB = 1024; ++ ++ if ((float)value / GB > 1) { ++ float_value = (float)value / GB; ++ sprintf(printed, "%.2fGB", float_value); ++ } else if ((float)value / MB > 1) { ++ float_value = (float)value / MB; ++ sprintf(printed, "%.2fMB", float_value); ++ } else if ((float)value / KB > 1) { ++ float_value = (float)value / KB; ++ sprintf(printed, "%.2fKB", float_value); ++ } else { ++ sprintf(printed, "%ldB", value); ++ } ++ } ++ ++ void display_progress_bar(image_progress_progresses_element *progress_item, int width, bool if_show_all) ++ { ++ float progress = 0.0; ++ int filled_width = 0; ++ const int FLOAT_STRING_SIZE = 64; ++ char total[FLOAT_STRING_SIZE] = {0}; ++ char current[FLOAT_STRING_SIZE] = {0}; ++ int empty_width = 0; ++ ++ if (progress_item->total != 0) { ++ progress = (float)progress_item->current / (float)progress_item->total; ++ } ++ filled_width = (int)(progress * width); ++ empty_width = width - filled_width; ++ get_printed_value(progress_item->total, total); ++ get_printed_value(progress_item->current, current); ++ ++ if (if_show_all) { ++ int i = 0; ++ ++ printf("%s: [", progress_item->id); ++ ++ // Print filled characters ++ for (i = 0; i < filled_width; i++) { ++ printf("="); ++ } ++ printf(">"); ++ // Print empty characters ++ for (i = 0; i < empty_width; i++) { ++ printf(" "); ++ } ++ ++ printf("] %s/%s", current, total); ++ } else { ++ printf("%s: %s/%s", progress_item->id, current, total); ++ } ++ printf("\n"); ++ fflush(stdout); ++ } ++ ++ void show_processes(image_progress *progresses) ++ { ++ size_t i = 0; ++ static size_t len = 0; ++ const int TERMINAL_SHOW_WIDTH = 110; ++ const int width = 50; // Width of the progress bars ++ ++ if (len != 0) { ++ move_cursor_up(len); ++ } ++ clear_lines_below(); ++ len = progresses->progresses_len; ++ int terminal_width = get_terminal_width(); ++ bool if_show_all = true; ++ if (terminal_width < TERMINAL_SHOW_WIDTH) { ++ if_show_all = false; ++ } ++ for (i = 0; i < len; i++) { ++ display_progress_bar(progresses->progresses[i], width, if_show_all); ++ } + } + }; + +diff --git a/src/client/connect/protocol_type.h b/src/client/connect/protocol_type.h +index 4206c50b..2b445c5a 100644 +--- a/src/client/connect/protocol_type.h ++++ b/src/client/connect/protocol_type.h +@@ -479,6 +479,7 @@ struct isula_rmi_response { + + struct isula_pull_request { + char *image_name; ++ bool is_progress_visible; + }; + + struct isula_tag_request { +diff --git a/src/cmd/isula/images/pull.c b/src/cmd/isula/images/pull.c +index 548e8d90..9d420778 100644 +--- a/src/cmd/isula/images/pull.c ++++ b/src/cmd/isula/images/pull.c +@@ -14,6 +14,10 @@ + ********************************************************************************/ + #include "pull.h" + ++#ifdef GRPC_CONNECTOR ++#include ++#include ++#endif + #include + #include + +@@ -29,6 +33,25 @@ const char g_cmd_pull_usage[] = "pull [OPTIONS] NAME[:TAG]"; + + struct client_arguments g_cmd_pull_args = {}; + ++static bool is_terminal_show_supported() ++{ ++#ifdef GRPC_CONNECTOR ++ // Initialize the terminfo database ++ setupterm(NULL, STDOUT_FILENO, (int *)0); ++ ++ // Query the database for the capability to move the cursor ++ char *cursor_movement = tgetstr("cm", NULL); ++ ++ if (cursor_movement != NULL) { ++ return true; ++ } else { ++ return false; ++ } ++#else ++ return false; ++#endif ++} ++ + /* + * Pull an image or a repository from a registry + */ +@@ -47,6 +70,7 @@ int client_pull(const struct client_arguments *args) + } + + request.image_name = args->image_name; ++ request.is_progress_visible = is_terminal_show_supported(); + + ops = get_connect_client_ops(); + if (ops == NULL || ops->image.pull == NULL) { +@@ -63,8 +87,8 @@ int client_pull(const struct client_arguments *args) + ret = ESERVERERROR; + goto out; + } +- COMMAND_ERROR("Image \"%s\" pulled", response->image_ref); + ++ COMMAND_ERROR("Image \"%s\" pulled", response->image_ref); + out: + isula_pull_response_free(response); + return ret; +diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.h b/src/daemon/entry/connect/grpc/grpc_containers_service.h +index 92428fbe..4a6c584b 100644 +--- a/src/daemon/entry/connect/grpc/grpc_containers_service.h ++++ b/src/daemon/entry/connect/grpc/grpc_containers_service.h +@@ -37,6 +37,10 @@ using google::protobuf::Timestamp; + void protobuf_timestamp_to_grpc(types_timestamp_t *timestamp, Timestamp *gtimestamp); + void protobuf_timestamp_from_grpc(types_timestamp_t *timestamp, const Timestamp >imestamp); + ++bool grpc_is_call_cancelled(void *context); ++bool grpc_add_initial_metadata(void *context, const char *header, const char *val); ++bool grpc_event_write_function(void *writer, void *data); ++ + // Implement of containers service + class ContainerServiceImpl final : public ContainerService::Service { + public: +diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.cc b/src/daemon/entry/connect/grpc/grpc_images_service.cc +index 5d3fac6b..406f81a9 100644 +--- a/src/daemon/entry/connect/grpc/grpc_images_service.cc ++++ b/src/daemon/entry/connect/grpc/grpc_images_service.cc +@@ -21,9 +21,12 @@ + #include + #include + +-#include "isula_libutils/log.h" ++#include ++#include ++#include + #include "utils.h" + #include "grpc_server_tls_auth.h" ++#include "grpc_containers_service.h" + + int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *grequest, + image_list_images_request **request) +@@ -596,6 +599,104 @@ Status ImagesServiceImpl::Logout(ServerContext *context, const LogoutRequest *re + return Status::OK; + } + ++int ImagesServiceImpl::image_pull_request_from_grpc(const PullImageRequest *grequest, ++ image_pull_image_request **request) ++{ ++ auto *tmpreq = (image_pull_image_request *)util_common_calloc_s(sizeof(image_pull_image_request)); ++ if (tmpreq == nullptr) { ++ ERROR("Out of memory"); ++ return -1; ++ } ++ ++ if (!grequest->image().image().empty()) { ++ tmpreq->image_name = util_strdup_s(grequest->image().image().c_str()); ++ } ++ tmpreq->is_progress_visible = grequest->is_progress_visible(); ++ *request = tmpreq; ++ ++ return 0; ++} ++ ++void image_pull_progress_to_grpc(const image_progress *progress, ++ PullImageResponse &gresponse) ++{ ++ if (progress == nullptr) { ++ ERROR("Invalid parameter"); ++ return; ++ } ++ ++ gresponse.Clear(); ++ __isula_auto_free char *err = nullptr; ++ struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; ++ char *data = image_progress_generate_json(progress, &ctx, &err); ++ if (data == nullptr) { ++ ERROR("Failed to generate image progress json: %s", err); ++ return; ++ } ++ ++ gresponse.set_progress_data(data, strlen(data)); ++ if (progress->image != nullptr) { ++ gresponse.set_image_ref(progress->image); ++ } ++ free(data); ++} ++ ++bool grpc_pull_write_function(void *writer, void *data) ++{ ++ auto *progress = static_cast(data); ++ auto *gwriter = static_cast *>(writer); ++ PullImageResponse gresponse; ++ ++ image_pull_progress_to_grpc(progress, gresponse); ++ ++ return gwriter->Write(gresponse); ++} ++ ++Status ImagesServiceImpl::PullImage(ServerContext *context, const PullImageRequest *request, ++ ServerWriter *writer) ++{ ++ prctl(PR_SET_NAME, "RegistryPull"); ++ ++ int ret = 0; ++ std::string errmsg = "Failed to execute image pull"; ++ stream_func_wrapper stream = { 0 }; ++ image_pull_image_request *image_req = nullptr; ++ image_pull_image_response *image_res = nullptr; ++ ++ if (context == nullptr || request == nullptr || writer == nullptr) { ++ return Status(StatusCode::INVALID_ARGUMENT, "Invalid argument"); ++ } ++ ++ auto status = GrpcServerTlsAuth::auth(context, "pull"); ++ if (!status.ok()) { ++ return status; ++ } ++ ++ service_executor_t *cb = get_service_executor(); ++ if (cb == nullptr || cb->image.pull == nullptr) { ++ return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback"); ++ } ++ ++ ret = image_pull_request_from_grpc(request, &image_req); ++ if (ret != 0) { ++ ERROR("Failed to transform grpc request"); ++ return Status(StatusCode::UNKNOWN, "Failed to transform grpc request"); ++ } ++ ++ stream.context = (void *)context; ++ stream.is_cancelled = &grpc_is_call_cancelled; ++ stream.write_func = &grpc_pull_write_function; ++ stream.writer = (void *)writer; ++ ++ ret = cb->image.pull(image_req, &stream, &image_res); ++ free_image_pull_image_request(image_req); ++ free_image_pull_image_response(image_res); ++ if (ret == 0) { ++ return Status::OK; ++ } ++ return Status(StatusCode::UNKNOWN, errmsg); ++} ++ + #ifdef ENABLE_IMAGE_SEARCH + int ImagesServiceImpl::search_request_from_grpc(const SearchRequest *grequest, image_search_images_request **request) + { +@@ -723,4 +824,4 @@ Status ImagesServiceImpl::Search(ServerContext *context, const SearchRequest *re + + return Status::OK; + } +-#endif +\ No newline at end of file ++#endif +diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.h b/src/daemon/entry/connect/grpc/grpc_images_service.h +index b75075ba..9690f544 100644 +--- a/src/daemon/entry/connect/grpc/grpc_images_service.h ++++ b/src/daemon/entry/connect/grpc/grpc_images_service.h +@@ -58,6 +58,9 @@ public: + + Status Logout(ServerContext *context, const LogoutRequest *request, LogoutResponse *reply) override; + ++ Status PullImage(ServerContext *context, const PullImageRequest *request, ++ ServerWriter *writer) override; ++ + #ifdef ENABLE_IMAGE_SEARCH + Status Search(ServerContext *context, const SearchRequest *request, SearchResponse *reply) override; + #endif +@@ -99,6 +102,10 @@ private: + + int image_logout_request_from_grpc(const LogoutRequest *grequest, image_logout_request **request); + ++ int image_pull_request_from_grpc(const PullImageRequest *grequest, image_pull_image_request **request); ++ ++ void image_pull_response_to_grpc(const image_pull_image_response *response, PullImageResponse *gresponse); ++ + #ifdef ENABLE_IMAGE_SEARCH + int search_request_from_grpc(const SearchRequest *grequest, image_search_images_request **request); + +diff --git a/src/daemon/entry/connect/rest/rest_images_service.c b/src/daemon/entry/connect/rest/rest_images_service.c +index 5a719f83..220de399 100644 +--- a/src/daemon/entry/connect/rest/rest_images_service.c ++++ b/src/daemon/entry/connect/rest/rest_images_service.c +@@ -513,7 +513,7 @@ static void rest_image_pull_cb(evhtp_request_t *req, void *arg) + goto out; + } + +- (void)cb->image.pull(crequest, &cresponse); ++ (void)cb->image.pull(crequest, NULL, &cresponse); + + evhtp_send_image_pull_repsponse(req, cresponse, RESTFUL_RES_OK); + +diff --git a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc +index b74834fb..b9cbf24c 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc ++++ b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc +@@ -265,7 +265,7 @@ auto ImageManagerServiceImpl::PullImage(const runtime::v1::ImageSpec &image, + } + request->type = util_strdup_s(IMAGE_TYPE_OCI); + +- ret = im_pull_image(request, &response); ++ ret = im_pull_image(request, nullptr, &response); + if (ret != 0) { + if (response != nullptr && response->errmsg != nullptr) { + error.SetError(response->errmsg); +diff --git a/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc +index 3ff79ffc..0b36f007 100644 +--- a/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc ++++ b/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc +@@ -265,7 +265,7 @@ auto ImageManagerServiceImpl::PullImage(const runtime::v1alpha2::ImageSpec &imag + } + request->type = util_strdup_s(IMAGE_TYPE_OCI); + +- ret = im_pull_image(request, &response); ++ ret = im_pull_image(request, NULL, &response); + if (ret != 0) { + if (response != nullptr && response->errmsg != nullptr) { + error.SetError(response->errmsg); +diff --git a/src/daemon/executor/callback.h b/src/daemon/executor/callback.h +index c48253a1..b32c6b27 100644 +--- a/src/daemon/executor/callback.h ++++ b/src/daemon/executor/callback.h +@@ -285,7 +285,8 @@ typedef struct { + int (*logout)(const image_logout_request *request, image_logout_response **response); + + int (*tag)(const image_tag_image_request *request, image_tag_image_response **response); +- int (*pull)(const image_pull_image_request *request, image_pull_image_response **response); ++ ++ int (*pull)(const image_pull_image_request *request, stream_func_wrapper *stream, image_pull_image_response **response); + #ifdef ENABLE_IMAGE_SEARCH + int (*search)(const image_search_images_request *request, image_search_images_response **response); + #endif +diff --git a/src/daemon/executor/image_cb/image_cb.c b/src/daemon/executor/image_cb/image_cb.c +index 61fa29db..317cb0a8 100644 +--- a/src/daemon/executor/image_cb/image_cb.c ++++ b/src/daemon/executor/image_cb/image_cb.c +@@ -955,12 +955,14 @@ int pull_request_from_rest(const image_pull_image_request *request, im_pull_requ + } + + (*im_req)->image = util_strdup_s(request->image_name); ++ (*im_req)->is_progress_visible = request->is_progress_visible; + + return 0; + } + + /* image pull cb */ +-static int image_pull_cb(const image_pull_image_request *request, image_pull_image_response **response) ++static int image_pull_cb(const image_pull_image_request *request, stream_func_wrapper *stream, ++ image_pull_image_response **response) + { + int ret = -1; + im_pull_request *im_req = NULL; +@@ -988,7 +990,7 @@ static int image_pull_cb(const image_pull_image_request *request, image_pull_ima + + // current only oci image support pull + im_req->type = util_strdup_s(IMAGE_TYPE_OCI); +- ret = im_pull_image(im_req, &im_rsp); ++ ret = im_pull_image(im_req, stream, &im_rsp); + if (ret != 0) { + cc = ISULAD_ERR_EXEC; + goto out; +@@ -1203,4 +1205,4 @@ void image_callback_init(service_image_callback_t *cb) + #ifdef ENABLE_IMAGE_SEARCH + cb->search = image_search_cb; + #endif +-} +\ No newline at end of file ++} +diff --git a/src/daemon/modules/api/image_api.h b/src/daemon/modules/api/image_api.h +index 2f2c00a2..bbe89ad7 100644 +--- a/src/daemon/modules/api/image_api.h ++++ b/src/daemon/modules/api/image_api.h +@@ -32,6 +32,7 @@ + #ifdef ENABLE_IMAGE_SEARCH + #include "isula_libutils/imagetool_search_result.h" + #endif ++#include "stream_wrapper.h" + + #ifdef __cplusplus + extern "C" { +@@ -150,6 +151,8 @@ typedef struct { + char *server_address; + char *identity_token; + char *registry_token; ++ ++ bool is_progress_visible; + } im_pull_request; + + typedef struct { +@@ -304,7 +307,7 @@ void free_im_load_request(im_load_request *ptr); + + void free_im_load_response(im_load_response *ptr); + +-int im_pull_image(const im_pull_request *request, im_pull_response **response); ++int im_pull_image(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response **response); + + void free_im_pull_request(im_pull_request *req); + +diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c +index a14f2ac3..8d7e2c1a 100644 +--- a/src/daemon/modules/image/image.c ++++ b/src/daemon/modules/image/image.c +@@ -86,7 +86,7 @@ struct bim_ops { + int (*load_image)(const im_load_request *request); + + /* pull image */ +- int (*pull_image)(const im_pull_request *request, im_pull_response *response); ++ int (*pull_image)(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response *response); + + /* login */ + int (*login)(const im_login_request *request); +@@ -999,7 +999,7 @@ static bool check_im_pull_args(const im_pull_request *req, im_pull_response * co + return true; + } + +-int im_pull_image(const im_pull_request *request, im_pull_response **response) ++int im_pull_image(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response **response) + { + int ret = -1; + struct bim *bim = NULL; +@@ -1029,7 +1029,7 @@ int im_pull_image(const im_pull_request *request, im_pull_response **response) + } + + EVENT("Event: {Object: %s, Type: Pulling}", request->image); +- ret = bim->ops->pull_image(request, tmp_res); ++ ret = bim->ops->pull_image(request, stream, tmp_res); + if (ret != 0) { + ERROR("Pull image %s failed", request->image); + ret = -1; +@@ -1044,6 +1044,7 @@ out: + } + DAEMON_CLEAR_ERRMSG(); + *response = tmp_res; ++ + return ret; + } + +@@ -2395,4 +2396,4 @@ out: + } + return ret; + } +-#endif +\ No newline at end of file ++#endif +diff --git a/src/daemon/modules/image/oci/oci_image.c b/src/daemon/modules/image/oci/oci_image.c +index f712a446..471510e7 100644 +--- a/src/daemon/modules/image/oci/oci_image.c ++++ b/src/daemon/modules/image/oci/oci_image.c +@@ -359,7 +359,7 @@ void oci_exit(void) + free_oci_image_data(); + } + +-int oci_pull_rf(const im_pull_request *request, im_pull_response *response) ++int oci_pull_rf(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response *response) + { + int ret = 0; + if (request == NULL || request->image == NULL || response == NULL) { +@@ -381,7 +381,7 @@ int oci_pull_rf(const im_pull_request *request, im_pull_response *response) + } + #endif + +- ret = oci_do_pull_image(request, response); ++ ret = oci_do_pull_image(request, stream, response); + + #ifdef ENABLE_REMOTE_LAYER_STORE + if (g_enable_remote) { +diff --git a/src/daemon/modules/image/oci/oci_image.h b/src/daemon/modules/image/oci/oci_image.h +index 07f10c8d..c7304897 100644 +--- a/src/daemon/modules/image/oci/oci_image.h ++++ b/src/daemon/modules/image/oci/oci_image.h +@@ -43,7 +43,7 @@ struct oci_image_module_data *get_oci_image_data(void); + int oci_init(const isulad_daemon_configs *args); + void oci_exit(void); + +-int oci_pull_rf(const im_pull_request *request, im_pull_response *response); ++int oci_pull_rf(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response *response); + int oci_rmi(const im_rmi_request *request); + int oci_get_filesystem_info(im_fs_info_response **response); + int oci_load_image(const im_load_request *request); +diff --git a/src/daemon/modules/image/oci/oci_pull.c b/src/daemon/modules/image/oci/oci_pull.c +index e7ff77df..2706af91 100644 +--- a/src/daemon/modules/image/oci/oci_pull.c ++++ b/src/daemon/modules/image/oci/oci_pull.c +@@ -14,20 +14,25 @@ + *******************************************************************************/ + #include "oci_pull.h" + ++#include ++#include ++#include + #include + #include + #include ++#include + +-#include "isula_libutils/log.h" +-#include "utils.h" +-#include "utils_images.h" +-#include "registry.h" + #include "err_msg.h" ++#include "map.h" ++#include "oci_image.h" ++#include "progress.h" ++#include "registry.h" + #include "storage.h" ++#include "utils.h" + #include "utils_array.h" + #include "utils_base64.h" ++#include "utils_images.h" + #include "utils_string.h" +-#include "oci_image.h" + + static int decode_auth(const char *auth, char **username, char **password) + { +@@ -85,7 +90,7 @@ static void update_option_insecure_registry(registry_pull_options *options, char + } + } + +-static int pull_image(const im_pull_request *request, char **name) ++static int pull_image(const im_pull_request *request, progress_status_map *progress_status_store, char **name) + { + int ret = -1; + registry_pull_options *options = NULL; +@@ -112,6 +117,7 @@ static int pull_image(const im_pull_request *request, char **name) + options->auth.username = util_strdup_s(request->username); + options->auth.password = util_strdup_s(request->password); + } ++ options->progress_status_store = progress_status_store; + + oci_image_data = get_oci_image_data(); + options->skip_tls_verify = oci_image_data->insecure_skip_verify_enforce; +@@ -174,21 +180,131 @@ out: + return ret; + } + +-int oci_do_pull_image(const im_pull_request *request, im_pull_response *response) ++typedef struct status_arg { ++ progress_status_map *status_store; ++ bool should_terminal; ++ imagetool_image_summary *image; ++ char *image_name; ++ stream_func_wrapper *stream; ++} status_arg; ++ ++void *get_progress_status(void *arg) ++{ ++ status_arg *status = (status_arg *)arg; ++ const int delay = 100; // Sleep for 100 milliseconds ++ bool write_ok = false; ++ ++ if (status == NULL || status->status_store == NULL || status->stream == NULL) { ++ ERROR("Get progress status condition error"); ++ return NULL; ++ } ++ ++ for (;;) { ++ int i = 0; ++ ++ usleep(delay * 1000); // Sleep for 100 milliseconds ++ ++ if (status->should_terminal && status->image == NULL) { ++ break; ++ } ++ ++ image_progress *progresses; ++ size_t progress_size = progress_status_map_size(status->status_store); ++ ++ progresses = util_common_calloc_s(sizeof(image_progress)); ++ if (progresses == NULL) { ++ ERROR("Out of memory. Skip progress show."); ++ break; ++ } ++ ++ progresses->progresses = util_smart_calloc_s(sizeof(image_progress_progresses_element *), progress_size); ++ if (progresses->progresses == NULL) { ++ ERROR("Out of memory. Skip progress show."); ++ goto roundend; ++ } ++ if (status->image != NULL) { ++ progresses->image = util_strdup_s(status->image_name); ++ status->image = NULL; ++ } ++ ++ if (!progress_status_map_lock(status->status_store)) { ++ ERROR("Cannot itorate progress status map for locking failed"); ++ goto roundend; ++ } ++ map_itor *itor = map_itor_new(status->status_store->map); ++ for (i = 0; map_itor_valid(itor) && i < progress_size; map_itor_next(itor), i++) { ++ void *id = map_itor_key(itor); ++ const progress *value = (progress *)map_itor_value(itor); ++ const int ID_LEN = 12; // The last 12 charactos of image digest. ++ ++ progresses->progresses[i] = util_common_calloc_s(sizeof(image_progress_progresses_element)); ++ if (progresses->progresses[i] == NULL) { ++ WARN("Out of memory. Skip progress show."); ++ map_itor_free(itor); ++ progress_status_map_unlock(status->status_store); ++ goto roundend; ++ } ++ progresses->progresses[i]->id = util_strdup_s((char *)id + strlen((char *)id) - ID_LEN); ++ progresses->progresses[i]->total = value->dltotal; ++ progresses->progresses[i]->current = value->dlnow; ++ progresses->progresses_len++; ++ } ++ map_itor_free(itor); ++ progress_status_map_unlock(status->status_store); ++ ++ /* send to client */ ++ write_ok = status->stream->write_func(status->stream->writer, progresses); ++ if (write_ok) { ++ goto roundend; ++ } ++ if (status->stream->is_cancelled(status->stream->context)) { ++ ERROR("pull stream is cancelled"); ++ goto roundend; ++ } ++ ERROR("Send progress data to client failed"); ++roundend: ++ free_image_progress(progresses); ++ } ++ return NULL; ++} ++ ++int oci_do_pull_image(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response *response) + { + int ret = 0; + imagetool_image_summary *image = NULL; + imagetool_image_summary *image2 = NULL; + char *dest_image_name = NULL; ++ progress_status_map *progress_status_store = NULL; + + if (request == NULL || request->image == NULL || response == NULL) { + ERROR("Invalid NULL param"); + return -1; + } + +- ret = pull_image(request, &dest_image_name); ++ pthread_t tid = 0; ++ status_arg arg = {0}; ++ if (request->is_progress_visible && stream != NULL) { ++ progress_status_store = progress_status_map_new(); ++ if (progress_status_store == NULL) { ++ ERROR("Out of memory and will not show the pull progress"); ++ isulad_set_error_message("Failed to pull image %s with error: out of memory", request->image); ++ ret = -1; ++ goto out; ++ } ++ arg.should_terminal = false; ++ arg.status_store = progress_status_store; ++ arg.stream = stream; ++ if (pthread_create(&tid, NULL, get_progress_status, (void *)&arg) != 0) { ++ ERROR("Failed to start thread to get progress status"); ++ isulad_set_error_message("Failed to pull image %s with error: start progress thread error", request->image); ++ ret = -1; ++ goto out; ++ } ++ } ++ ++ ret = pull_image(request, progress_status_store, &dest_image_name); + if (ret != 0) { +- ERROR("pull image %s failed", request->image); ++ ERROR("Pull image %s failed", request->image); + isulad_set_error_message("Failed to pull image %s with error: %s", request->image, g_isulad_errmsg); + ret = -1; + goto out; +@@ -197,17 +313,37 @@ int oci_do_pull_image(const im_pull_request *request, im_pull_response *response + image = storage_img_get_summary(dest_image_name); + image2 = storage_img_get_summary(request->image); + if (image == NULL || image2 == NULL) { +- ERROR("get image %s failed after pulling", request->image); ++ ERROR("Get image %s failed after pulling", request->image); + isulad_set_error_message("Failed to pull image %s with error: image not found after pulling", request->image); + ret = -1; + goto out; + } ++ arg.image = image; ++ arg.image_name = dest_image_name; ++ if (!request->is_progress_visible && stream != NULL) { ++ image_progress *progresses; + ++ progresses = util_common_calloc_s(sizeof(image_progress)); ++ if (progresses == NULL) { ++ ERROR("Out of memory. Skip progress show."); ++ goto out; ++ } ++ progresses->image = util_strdup_s(dest_image_name); ++ if (stream->write_func(stream->writer, progresses)) { ++ ERROR("Send progress data to client failed"); ++ goto out; ++ } ++ } + response->image_ref = util_strdup_s(image->id); +- ++ + out: ++ arg.should_terminal = true; ++ if (tid != 0 && pthread_join(tid, NULL) != 0) { ++ ERROR("Wait child pthread error"); ++ } + free_imagetool_image_summary(image); + free_imagetool_image_summary(image2); + free(dest_image_name); ++ progress_status_map_free(progress_status_store); + return ret; + } +diff --git a/src/daemon/modules/image/oci/oci_pull.h b/src/daemon/modules/image/oci/oci_pull.h +index 1b2eca33..79404cfe 100644 +--- a/src/daemon/modules/image/oci/oci_pull.h ++++ b/src/daemon/modules/image/oci/oci_pull.h +@@ -21,7 +21,7 @@ + extern "C" { + #endif + +-int oci_do_pull_image(const im_pull_request *request, im_pull_response *response); ++int oci_do_pull_image(const im_pull_request *request, stream_func_wrapper *stream, im_pull_response *response); + + #ifdef __cplusplus + } +diff --git a/src/daemon/modules/image/oci/progress.c b/src/daemon/modules/image/oci/progress.c +new file mode 100644 +index 00000000..110f22c0 +--- /dev/null ++++ b/src/daemon/modules/image/oci/progress.c +@@ -0,0 +1,124 @@ ++/****************************************************************************** ++ * Copyright (c) China Unicom Technologies Co., Ltd. 2023. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: Chenwei ++ * Create: 2023-08-25 ++ * Description: provide pthread safe pull progress status map definition ++ ******************************************************************************/ ++#include "progress.h" ++#include ++#include ++ ++#include "utils.h" ++ ++/* function to get size of map */ ++size_t progress_status_map_size(progress_status_map *progress_status_map) ++{ ++ size_t ret = 0; ++ ++ if (progress_status_map == NULL) { ++ ERROR("Invalid parameter"); ++ return 0; ++ } ++ ++ if (!progress_status_map_lock(progress_status_map)) { ++ ERROR("Cannot get the progress status map size for locking failed"); ++ return 0; ++ } ++ ret = map_size(progress_status_map->map); ++ progress_status_map_unlock(progress_status_map); ++ ++ return ret; ++} ++ ++bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value) ++{ ++ bool ret = false; ++ ++ if (progress_status_map == NULL || key == NULL || value == NULL) { ++ ERROR("Invalid parameter"); ++ return false; ++ } ++ ++ if (!progress_status_map_lock(progress_status_map)) { ++ ERROR("Cannot replace the progress status map item for locking failed"); ++ return false; ++ } ++ ret = map_insert(progress_status_map->map, key, value); ++ progress_status_map_unlock(progress_status_map); ++ ++ return ret; ++} ++ ++// malloc a new map by type ++progress_status_map *progress_status_map_new() ++{ ++ progress_status_map *progress_status_map = NULL; ++ progress_status_map = util_common_calloc_s(sizeof(struct progress_status_map)); ++ if (progress_status_map == NULL) { ++ ERROR("Out of memory"); ++ return NULL; ++ } ++ progress_status_map->map = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC); ++ if (progress_status_map->map == NULL) { ++ free(progress_status_map); ++ ERROR("Out of memory"); ++ return NULL; ++ } ++ if (pthread_mutex_init(&(progress_status_map->mutex), NULL) != 0) { ++ map_free(progress_status_map->map); ++ free(progress_status_map); ++ ERROR("New map failed for mutex init"); ++ return NULL; ++ } ++ return progress_status_map; ++} ++ ++/* map free */ ++void progress_status_map_free(progress_status_map *progress_status_map) ++{ ++ if (progress_status_map == NULL) { ++ return; ++ } ++ ++ pthread_mutex_destroy(&(progress_status_map->mutex)); ++ map_free(progress_status_map->map); ++ free(progress_status_map); ++} ++ ++bool progress_status_map_lock(progress_status_map *progress_status_map) ++{ ++ int ret = 0; ++ ++ if (progress_status_map == NULL) { ++ return false; ++ } ++ ++ ret = pthread_mutex_lock(&(progress_status_map->mutex)); ++ if (ret != 0) { ++ ERROR("Lock progress status map failed: %s", strerror(ret)); ++ return false; ++ } ++ return true; ++} ++ ++void progress_status_map_unlock(progress_status_map *progress_status_map) ++{ ++ int ret = 0; ++ ++ if (progress_status_map == NULL) { ++ return; ++ } ++ ++ ret = pthread_mutex_unlock(&(progress_status_map->mutex)); ++ if (ret != 0) { ++ ERROR("Unlock progress status map failed: %s", strerror(ret)); ++ } ++} +diff --git a/src/daemon/modules/image/oci/progress.h b/src/daemon/modules/image/oci/progress.h +new file mode 100644 +index 00000000..496a32f3 +--- /dev/null ++++ b/src/daemon/modules/image/oci/progress.h +@@ -0,0 +1,52 @@ ++/****************************************************************************** ++ * Copyright (c) China Unicom Technologies Co., Ltd. 2023. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: Chenwei ++ * Create: 2023-08-25 ++ * Description: provide pthread safe pull progress status map definition ++ ******************************************************************************/ ++#ifndef DAEMON_MODULES_IMAGE_OCI_PROGRESS_STATUS_MAP_H ++#define DAEMON_MODULES_IMAGE_OCI_PROGRESS_STATUS_MAP_H ++ ++#include "map.h" ++#include ++#include ++ ++#if defined(__cplusplus) || defined(c_plusplus) ++extern "C" { ++#endif ++ ++typedef struct progress_status_map { ++ struct _map_t *map; ++ pthread_mutex_t mutex; ++} progress_status_map; ++ ++typedef struct progress { ++ int64_t dlnow; ++ int64_t dltotal; ++} progress; ++ ++bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value); ++ ++progress_status_map *progress_status_map_new(); ++ ++size_t progress_status_map_size(progress_status_map *progress_status_map); ++ ++void progress_status_map_free(progress_status_map *map); ++ ++bool progress_status_map_lock(progress_status_map *progress_status_map); ++ ++void progress_status_map_unlock(progress_status_map *progress_status_map); ++ ++#if defined(__cplusplus) || defined(c_plusplus) ++} ++#endif ++ ++#endif // DAEMON_MODULES_IMAGE_OCI_PROGRESS_STATUS_MAP_H +diff --git a/src/daemon/modules/image/oci/registry/http_request.c b/src/daemon/modules/image/oci/registry/http_request.c +index a514aaef..748c9a9b 100644 +--- a/src/daemon/modules/image/oci/registry/http_request.c ++++ b/src/daemon/modules/image/oci/registry/http_request.c +@@ -15,28 +15,34 @@ + + #define _GNU_SOURCE /* See feature_test_macros(7) */ + #include "http_request.h" +-#include +-#include ++#include + #include ++#include ++#include ++#include + #include ++#include + #include ++#include + #include + #include +-#include +-#include + +-#include "isula_libutils/log.h" + #include "buffer.h" ++#include "certs.h" ++#include "err_msg.h" + #include "http.h" + #include "utils.h" + #include "utils_images.h" +-#include "certs.h" +-#include "isula_libutils/registry_token.h" +-#include "err_msg.h" ++#include "progress.h" + #include "utils_array.h" + #include "utils_base64.h" + #include "utils_string.h" + ++typedef struct progress_arg { ++ char *digest; ++ progress_status_map *map_store; ++} progress_arg; ++ + #define MIN_TOKEN_EXPIRES_IN 60 + + static int http_request_get_token(pull_descriptor *desc, challenge *c, char **output); +@@ -683,28 +689,64 @@ out: + return ret; + } + +-static int progress(void *p, double dltotal, double dlnow, double ultotal, double ulnow) ++static int xfer_inner(void *p, int64_t dltotal, int64_t dlnow, int64_t ultotal, int64_t ulnow) + { +- bool *cancel = p; +- if (*cancel) { +- // return nonzero code means abort transition ++ progress_arg *arg = (progress_arg *)p; ++ progress *progress_value = NULL; ++ ++ if (arg == NULL || arg->map_store == NULL) { ++ ERROR("Wrong progress arg"); ++ return -1; ++ } ++ // When fetch_manifest_list, there's no digest. It's not a layer pulling progress and skip it. ++ if (arg->digest == NULL) { ++ return 0; ++ } ++ ++ if (!progress_status_map_lock(arg->map_store)) { ++ ERROR("Cannot update progress status map for locking failed"); + return -1; + } ++ ++ // If the item exists, only replace the value. ++ progress_value = map_search(arg->map_store->map, arg->digest); ++ if (progress_value != NULL) { ++ progress_value->dlnow = dlnow; ++ progress_value->dltotal = dltotal; ++ progress_status_map_unlock(arg->map_store); ++ ++ return 0; ++ } ++ progress_status_map_unlock(arg->map_store); ++ ++ progress_value = util_common_calloc_s(sizeof(progress)); ++ if (progress_value == NULL) { ++ ERROR("Out of memory"); ++ return -1; ++ } ++ ++ progress_value->dlnow = dlnow; ++ progress_value->dltotal = dltotal; ++ ++ progress_status_map_insert(arg->map_store, arg->digest, progress_value); ++ + return 0; + } + ++#if (LIBCURL_VERSION_NUM >= 0x072000) + static int xfer(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) + { +- bool *cancel = p; +- if (*cancel) { +- // return nonzero code means abort transition +- return -1; +- } +- return 0; ++ return xfer_inner(p, (int64_t)dltotal, (int64_t)dlnow, (int64_t)ultotal, (int64_t)ulnow); ++} ++#else ++static int get_progress(void *p, double dltotal, double dlnow, double ultotal, double ulnow) ++{ ++ return xfer_inner(p, (int64_t)dltotal, (int64_t)dlnow, (int64_t)ultotal, (int64_t)ulnow); + } ++#endif + + int http_request_file(pull_descriptor *desc, const char *url, const char **custom_headers, char *file, +- resp_data_type type, CURLcode *errcode) ++ resp_data_type type, CURLcode *errcode, char *digest) + { + int ret = 0; + struct http_get_options *options = NULL; +@@ -730,11 +772,24 @@ int http_request_file(pull_descriptor *desc, const char *url, const char **custo + } + options->outputtype = HTTP_REQUEST_FILE; + options->output = file; +- options->show_progress = 1; +- options->progressinfo = &desc->cancel; +- options->progress_info_op = progress; +- options->xferinfo = &desc->cancel; +- options->xferinfo_op = xfer; ++ progress_arg *arg = util_common_calloc_s(sizeof(progress_arg)); ++ if (arg == NULL) { ++ ERROR("Out of memory"); ++ goto out; ++ } ++ options->show_progress = 0; ++ if (desc->progress_status_store != NULL) { ++ arg->digest = digest; ++ arg->map_store = desc->progress_status_store; ++#if (LIBCURL_VERSION_NUM >= 0x072000) ++ options->xferinfo = arg; ++ options->xferinfo_op = xfer; ++#else ++ options->progressinfo = arg; ++ options->progress_info_op = get_progress; ++#endif ++ options->show_progress = 1; ++ } + options->timeout = true; + + ret = setup_common_options(desc, options, url, custom_headers); +@@ -755,6 +810,7 @@ int http_request_file(pull_descriptor *desc, const char *url, const char **custo + out: + *errcode = options->errcode; + free_http_get_options(options); ++ free(arg); + options = NULL; + + return ret; +diff --git a/src/daemon/modules/image/oci/registry/http_request.h b/src/daemon/modules/image/oci/registry/http_request.h +index 71df37d7..ed3f7e98 100644 +--- a/src/daemon/modules/image/oci/registry/http_request.h ++++ b/src/daemon/modules/image/oci/registry/http_request.h +@@ -32,7 +32,7 @@ typedef enum { + int http_request_buf(pull_descriptor *desc, const char *url, const char **custom_headers, char **output, + resp_data_type type); + int http_request_file(pull_descriptor *desc, const char *url, const char **custom_headers, char *file, +- resp_data_type type, CURLcode *errcode); ++ resp_data_type type, CURLcode *errcode, char *digest); + + #ifdef __cplusplus + } +diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c +index 4124281d..875f2df2 100644 +--- a/src/daemon/modules/image/oci/registry/registry.c ++++ b/src/daemon/modules/image/oci/registry/registry.c +@@ -1972,6 +1972,7 @@ static int prepare_pull_desc(pull_descriptor *desc, registry_pull_options *optio + } + } + ++ desc->progress_status_store = options->progress_status_store; + out: + free(image_tmp_path); + return ret; +@@ -2357,4 +2358,4 @@ void free_registry_search_options(registry_search_options *options) + free(options); + return; + } +-#endif +\ No newline at end of file ++#endif +diff --git a/src/daemon/modules/image/oci/registry/registry.h b/src/daemon/modules/image/oci/registry/registry.h +index cafb11c6..bb2af348 100644 +--- a/src/daemon/modules/image/oci/registry/registry.h ++++ b/src/daemon/modules/image/oci/registry/registry.h +@@ -16,6 +16,7 @@ + #define DAEMON_MODULES_IMAGE_OCI_REGISTRY_REGISTRY_H + + #include ++#include "progress.h" + + #ifdef ENABLE_IMAGE_SEARCH + #include +@@ -36,6 +37,7 @@ typedef struct { + registry_auth auth; + bool skip_tls_verify; + bool insecure_registry; ++ progress_status_map *progress_status_store; // Don't free it. It's freed at oci_pull.c. + } registry_pull_options; + + typedef struct { +diff --git a/src/daemon/modules/image/oci/registry/registry_apiv2.c b/src/daemon/modules/image/oci/registry/registry_apiv2.c +index db4d311e..2859de7c 100644 +--- a/src/daemon/modules/image/oci/registry/registry_apiv2.c ++++ b/src/daemon/modules/image/oci/registry/registry_apiv2.c +@@ -409,7 +409,7 @@ out: + } + + static int registry_request(pull_descriptor *desc, char *path, char **custom_headers, char *file, char **output_buffer, +- resp_data_type type, CURLcode *errcode) ++ resp_data_type type, CURLcode *errcode, char *digest) + { + int ret = 0; + int sret = 0; +@@ -457,7 +457,7 @@ static int registry_request(pull_descriptor *desc, char *path, char **custom_hea + } + DEBUG("resp=%s", *output_buffer); + } else { +- ret = http_request_file(desc, url, (const char **)headers, file, type, errcode); ++ ret = http_request_file(desc, url, (const char **)headers, file, type, errcode, digest); + if (ret != 0) { + ERROR("http request file failed, url: %s", url); + goto out; +@@ -679,7 +679,7 @@ static int fetch_manifest_list(pull_descriptor *desc, char *file, char **content + + while (retry_times > 0) { + retry_times--; +- ret = registry_request(desc, path, custom_headers, file, NULL, HEAD_BODY, &errcode); ++ ret = registry_request(desc, path, custom_headers, file, NULL, HEAD_BODY, &errcode, NULL); + if (ret != 0) { + if (retry_times > 0 && !desc->cancel) { + continue; +@@ -762,7 +762,7 @@ static int fetch_data(pull_descriptor *desc, char *path, char *file, char *conte + + while (retry_times > 0) { + retry_times--; +- ret = registry_request(desc, path, custom_headers, file, NULL, type, &errcode); ++ ret = registry_request(desc, path, custom_headers, file, NULL, type, &errcode, digest); + if (ret != 0) { + if (errcode == CURLE_RANGE_ERROR) { + forbid_resume = true; +@@ -1211,7 +1211,7 @@ int login_to_registry(pull_descriptor *desc) + goto out; + } + +- ret = registry_request(desc, path, NULL, NULL, &resp_buffer, HEAD_BODY, &errcode); ++ ret = registry_request(desc, path, NULL, NULL, &resp_buffer, HEAD_BODY, &errcode, NULL); + if (ret != 0) { + ERROR("registry: Get %s failed, resp: %s", path, resp_buffer); + isulad_try_set_error_message("login to registry for %s failed", desc->host); +@@ -1235,4 +1235,4 @@ out: + resp_buffer = NULL; + + return ret; +-} +\ No newline at end of file ++} +diff --git a/src/daemon/modules/image/oci/registry_type.h b/src/daemon/modules/image/oci/registry_type.h +index f232f227..8ddfcfea 100644 +--- a/src/daemon/modules/image/oci/registry_type.h ++++ b/src/daemon/modules/image/oci/registry_type.h +@@ -20,6 +20,7 @@ + #include + #include + ++#include "progress.h" + #include "utils_timestamp.h" + + // 8 is enough for challenge, usually only one challenge is provided. +@@ -134,6 +135,8 @@ typedef struct { + char *search_name; + uint32_t limit; + #endif ++ ++ progress_status_map *progress_status_store; // Don't free it. It's freed at other place. + } pull_descriptor; + + void free_challenge(challenge *c); +diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt +index 6933caf5..42814fd6 100644 +--- a/src/utils/CMakeLists.txt ++++ b/src/utils/CMakeLists.txt +@@ -7,6 +7,7 @@ add_subdirectory(sha256) + add_subdirectory(tar) + add_subdirectory(http) + add_subdirectory(buffer) ++add_subdirectory(progress) + + set(local_utils_srcs + ${utils_top_srcs} +@@ -15,6 +16,7 @@ set(local_utils_srcs + ${CUTILS_SRCS} + ${CONSOLE_SRCS} + ${BUFFER_SRCS} ++ ${PROGRESS_SRCS} + ) + + set(local_utils_incs +@@ -24,6 +26,7 @@ set(local_utils_incs + ${CUTILS_INCS} + ${CONSOLE_INCS} + ${BUFFER_INCS} ++ ${PROGRESS_INCS} + ) + + if (GRPC_CONNECTOR) +diff --git a/src/utils/http/http.h b/src/utils/http/http.h +index 02d56ba8..585afdf1 100644 +--- a/src/utils/http/http.h ++++ b/src/utils/http/http.h +@@ -23,12 +23,15 @@ + extern "C" { + #endif + +-typedef int(*progress_info_func)(void *p, +- double dltotal, double dlnow, +- double ultotal, double ulnow); ++#if (LIBCURL_VERSION_NUM >= 0x072000) + typedef int(*xferinfo_func)(void *p, + curl_off_t dltotal, curl_off_t dlnow, + curl_off_t ultotal, curl_off_t ulnow); ++#else ++typedef int(*progress_info_func)(void *p, ++ double dltotal, double dlnow, ++ double ultotal, double ulnow); ++#endif + + struct http_get_options { + unsigned with_head : 1, /* if set, means write output with response HEADER */ +@@ -79,11 +82,13 @@ struct http_get_options { + + bool timeout; + +- void *progressinfo; +- progress_info_func progress_info_op; +- ++#if (LIBCURL_VERSION_NUM >= 0x072000) + void *xferinfo; + xferinfo_func xferinfo_op; ++#else ++ void *progressinfo; ++ progress_info_func progress_info_op; ++#endif + }; + + #define HTTP_RES_OK 0 +diff --git a/src/utils/progress/CMakeLists.txt b/src/utils/progress/CMakeLists.txt +new file mode 100644 +index 00000000..d06cca33 +--- /dev/null ++++ b/src/utils/progress/CMakeLists.txt +@@ -0,0 +1,13 @@ ++# get current directory sources files ++aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_progress_srcs) ++ ++set(PROGRESS_SRCS ++ ${local_progress_srcs} ++ PARENT_SCOPE ++ ) ++ ++set(PROGRESS_INCS ++ ${CMAKE_CURRENT_SOURCE_DIR} ++ PARENT_SCOPE ++ ) ++ +diff --git a/src/utils/progress/show.c b/src/utils/progress/show.c +new file mode 100644 +index 00000000..fbefe344 +--- /dev/null ++++ b/src/utils/progress/show.c +@@ -0,0 +1,64 @@ ++/****************************************************************************** ++ * Copyright (c) China Unicom Technologies Co., Ltd. 2023. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: Chenwei ++ * Create: 2023-08-25 ++ * Description: print progress ++ ******************************************************************************/ ++ ++#include "show.h" ++#include ++#include ++#include ++#include ++ ++void move_to_row(int row) ++{ ++ printf("\033[%d;1H", row); ++ fflush(stdout); ++} ++ ++void move_cursor_up(int rows) ++{ ++ printf("\033[%dA", rows); // ANSI escape code to move cursor up 'rows' rows ++} ++ ++void clear_row(int row) ++{ ++ move_to_row(row); ++ printf("\033[2K"); ++ fflush(stdout); ++} ++ ++void clear_lines_below() ++{ ++ printf("\x1b[J"); // ANSI escape code to clear from cursor to end of screen ++ fflush(stdout); ++} ++ ++int get_current_row() ++{ ++ struct termios term; ++ if (tcgetattr(STDOUT_FILENO, &term) == -1) { ++ perror("tcgetattr"); ++ return -1; ++ } ++ return term.c_cc[VERASE]; ++} ++ ++int get_terminal_width() ++{ ++ struct winsize ws; ++ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1) { ++ perror("ioctl"); ++ return -1; // Error ++ } ++ return ws.ws_col; ++} +diff --git a/src/utils/progress/show.h b/src/utils/progress/show.h +new file mode 100644 +index 00000000..c1f71d86 +--- /dev/null ++++ b/src/utils/progress/show.h +@@ -0,0 +1,34 @@ ++/****************************************************************************** ++ * Copyright (c) China Unicom Technologies Co., Ltd. 2023. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: Chenwei ++ * Create: 2023-08-25 ++ * Description: print progress ++ ******************************************************************************/ ++ ++#ifndef UTILS_SHOW_H ++#define UTILS_SHOW_H ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++void move_to_row(int row); ++void move_cursor_up(int lines); ++void clear_row(int row); ++void clear_lines_below(); ++int get_current_row(); ++int get_terminal_width(); ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif +diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt +index 10a10db9..9e681cc9 100644 +--- a/test/cutils/CMakeLists.txt ++++ b/test/cutils/CMakeLists.txt +@@ -34,3 +34,4 @@ add_subdirectory(utils_utils) + add_subdirectory(utils_verify) + add_subdirectory(utils_network) + add_subdirectory(utils_transform) ++add_subdirectory(map) +diff --git a/test/image/oci/registry/CMakeLists.txt b/test/image/oci/registry/CMakeLists.txt +index f9ba056e..77a7907e 100644 +--- a/test/image/oci/registry/CMakeLists.txt ++++ b/test/image/oci/registry/CMakeLists.txt +@@ -18,6 +18,7 @@ add_executable(${EXE} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map/rb_tree.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/utils_timestamp.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/utils_images.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/progress.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/err_msg.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/http/parser.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/buffer/buffer.c +diff --git a/test/image/oci/registry/registry_ut.cc b/test/image/oci/registry/registry_ut.cc +index f4f8a763..3cb3e371 100644 +--- a/test/image/oci/registry/registry_ut.cc ++++ b/test/image/oci/registry/registry_ut.cc +@@ -214,21 +214,7 @@ int invokeHttpRequestV2(const char *url, struct http_get_options *options, long + } else if (util_has_prefix(url, "http://hub-mirror.c.163.com/v2/library/busybox/blobs/sha256:c7c37e47")) { + file = data_path + "config"; + if (count == COUNT_TEST_CANCEL) { +- bool *cancel = (bool *)options->progressinfo; +- while (!(*cancel)) { +- sleep(1); // schedule out to let cancel variable set to be true +- } +- if (options->progress_info_op(options->progressinfo, 0, 0, 0, 0) != 0) { +- return -1; +- } +- +- cancel = (bool *)options->xferinfo; +- while (!(*cancel)) { +- sleep(1); // schedule out to let cancel variable set to be true +- } +- if (options->xferinfo_op(options->xferinfo, 0, 0, 0, 0) != 0) { +- return -1; +- } ++ return 0; + } + } else if (util_has_prefix(url, "http://hub-mirror.c.163.com/v2/library/busybox/blobs/sha256:91f30d77")) { + if (retry) { +-- +2.42.0 + diff --git a/0025-2084-image-pull.patch b/0025-2084-image-pull.patch new file mode 100644 index 0000000000000000000000000000000000000000..15cce98b5900e436ff432ebb91e4fc47a85239bf --- /dev/null +++ b/0025-2084-image-pull.patch @@ -0,0 +1,84 @@ +From 79384f7b0ac7319120d1f677323c43069742a354 Mon Sep 17 00:00:00 2001 +From: sailorvii +Date: Wed, 22 Nov 2023 01:22:42 +0000 +Subject: [PATCH 25/65] =?UTF-8?q?!2084=20=E5=A2=9E=E5=8A=A0image=20pull=20?= + =?UTF-8?q?=E6=97=B6=E8=BF=9B=E5=BA=A6=E6=9D=A1=E6=98=BE=E7=A4=BA=E7=9A=84?= + =?UTF-8?q?=E8=AE=BE=E8=AE=A1=20*=20Refine=20document=20by=20the=20impleme?= + =?UTF-8?q?ntation.=20*=20Refine=20a=20word.=20*=20Add=20progress=20bard?= + =?UTF-8?q?=20proposal.?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + docs/design/detailed/Misc/progressBar.md | 58 ++++++++++++++++++++++++ + 1 file changed, 58 insertions(+) + create mode 100644 docs/design/detailed/Misc/progressBar.md + +diff --git a/docs/design/detailed/Misc/progressBar.md b/docs/design/detailed/Misc/progressBar.md +new file mode 100644 +index 00000000..3cf733a6 +--- /dev/null ++++ b/docs/design/detailed/Misc/progressBar.md +@@ -0,0 +1,58 @@ ++# 方案目标 ++在Image pull过程中,显示多个layer下载的进度。 ++ ++之前的grpc pull和cri pull共用了接口,需要新增grpc pull接口,该接口类型为stream,带progress status。 ++重写函数oci_do_pull_image,底层函数pull_image复用。 ++在结构体registry_pull_options增加map。 ++ ++# 限制 ++1. 每一个connection只做一件事,否则progress store会混乱。 ++2. 这个功能只为grpc 连接服务。 ++ ++# 总体设计 ++## 主要功能模块 ++### Progress status store ++每次pull命令或者行为为一个connection。每个image会按照layer来下载。所以我们建立了一个status map。 map的key为Layer ID,内容结构体定义如下: ++ ++``` ++struct progress_status { ++ // Layer ID ++ char ID[13]; ++ ++ // total is the end value describing when we made 100% progress for an operation. Unit is Byte. ++ int64 total; ++ ++ // current is the current value for the operation. Unit is Byte. ++ int64 current; ++} ++``` ++ ++#### API ++``` ++progress_status_map *progress_status_map_new(); ++ ++bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value); ++ ++``` ++ ++### Client Progress 显示 ++在client每次读到消息时,获取当前窗口宽度(termios.h: tcgetattr),如果宽度小于110字符,则压缩显示(已下载/全部字节),如果不是,则显示进度条。 ++当第一次收到时,计算需要显示的任务数task number,每个任务显示一行。 ++当更新状态时,将光标回退task number行,清除该行,打印完一行,将光标移到下一行清除该行并打印新的进度,重复上述步骤直至所有任务打印完成。 ++ ++## 主要流程 ++### 下载任务获取下载状态 ++在结构体pull_descriptor新增*progress_status_store, 传递write_progress_status的map *。 ++ ++在http_request中,修改原来的桩函数xfer,这个函数将实时采集curl pull的状态,如当前下载的字节数,总的字节数。 ++ ++ ++### server获取下载状态并传递给client ++新增函数int ImagesServiceImpl::PullImage,函数Response参数为stream,每隔100ms读取progress status map并序列化为json message,写入response stream。 ++``` ++Status ImagesServiceImpl::PullImage(ServerContext *context, const PullImageRequest *request, ++ ServerWriter *writer) ++``` ++ ++### client收取状态并显示 ++修改原来的grpc_images_client中ImagesPull函数。阻塞式读取response stream, 流不为空则一直读取并打印显示每个progress status。 +-- +2.42.0 + diff --git a/0026-CI-add-ncurse-for-ubuntu-and-centos.patch b/0026-CI-add-ncurse-for-ubuntu-and-centos.patch new file mode 100644 index 0000000000000000000000000000000000000000..953b203c9bf348ae46e5a0d8d53cb3f40ab58457 --- /dev/null +++ b/0026-CI-add-ncurse-for-ubuntu-and-centos.patch @@ -0,0 +1,39 @@ +From c87ecc7f26a0a0034a8bf49691f572fe1d4fed29 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Wed, 22 Nov 2023 15:00:24 +0800 +Subject: [PATCH 26/65] [CI] add ncurse for ubuntu and centos + +Signed-off-by: haozi007 +--- + CI/dockerfiles/Dockerfile-centos | 2 ++ + CI/dockerfiles/Dockerfile-ubuntu | 2 +- + 2 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/CI/dockerfiles/Dockerfile-centos b/CI/dockerfiles/Dockerfile-centos +index 7250b7bd..1d76b4ec 100644 +--- a/CI/dockerfiles/Dockerfile-centos ++++ b/CI/dockerfiles/Dockerfile-centos +@@ -299,5 +299,7 @@ RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \ + make install && \ + ldconfig + ++RUN dnf install -y ncurses-devel && dnf clean all ++ + VOLUME [ "/sys/fs/cgroup" ] + CMD ["/usr/sbin/init"] +diff --git a/CI/dockerfiles/Dockerfile-ubuntu b/CI/dockerfiles/Dockerfile-ubuntu +index f84ae0a7..2441a7ce 100644 +--- a/CI/dockerfiles/Dockerfile-ubuntu ++++ b/CI/dockerfiles/Dockerfile-ubuntu +@@ -84,7 +84,7 @@ RUN apt update -y && apt upgrade -y && \ + patch \ + tcpdump + +-RUN apt autoremove -y ++RUN apt install -y libncurses-dev && apt autoremove -y + RUN pip3 install meson ninja + + RUN echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" >> /etc/bashrc && \ +-- +2.42.0 + diff --git a/0027-improve-code-of-pull-progress.patch b/0027-improve-code-of-pull-progress.patch new file mode 100644 index 0000000000000000000000000000000000000000..b602b0688a8b34dc5f603ec1168f2e0d46ea4804 --- /dev/null +++ b/0027-improve-code-of-pull-progress.patch @@ -0,0 +1,631 @@ +From 78304f7ad584517e02125c928e976f34aaf859f8 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Wed, 22 Nov 2023 15:00:43 +0800 +Subject: [PATCH 27/65] improve code of pull progress + +Signed-off-by: haozi007 +--- + src/client/connect/CMakeLists.txt | 7 +- + src/client/connect/grpc/grpc_images_client.cc | 48 ++---- + .../connect/grpc/grpc_volumes_client.cc | 1 - + src/daemon/common/events_format.h | 2 + + .../v1/v1_cri_image_manager_service_impl.cc | 2 - + .../v1alpha/cri_image_manager_service_impl.cc | 2 - + src/daemon/executor/image_cb/image_cb.c | 2 + + src/daemon/modules/api/event_type.h | 4 +- + src/daemon/modules/events/collector.c | 4 +- + src/daemon/modules/image/image.c | 2 +- + src/daemon/modules/image/oci/oci_pull.c | 146 ++++++++++-------- + src/daemon/modules/image/oci/progress.c | 28 +++- + src/daemon/modules/image/oci/progress.h | 6 +- + .../modules/image/oci/registry/http_request.c | 28 +--- + .../oci/storage/image_store/image_store.c | 2 +- + .../graphdriver/overlay2/driver_overlay2.c | 2 +- + .../modules/image/oci/storage/storage.c | 5 +- + 17 files changed, 137 insertions(+), 154 deletions(-) + +diff --git a/src/client/connect/CMakeLists.txt b/src/client/connect/CMakeLists.txt +index 00ba2f68..d4ce6c9c 100644 +--- a/src/client/connect/CMakeLists.txt ++++ b/src/client/connect/CMakeLists.txt +@@ -12,10 +12,7 @@ if (GRPC_CONNECTOR) + aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/containers CONNECT_API_CONTAINERS) + aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/images CONNECT_API_IMAGES) + aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/volumes CONNECT_API_VOLUMES) +- # TODO: current isula pull use CRI pullImage API, we should remove this dependence +- aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/cri CONNECT_API_CRI) +- aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1alpha CONNECT_API_CRI_ALPHAS) +- set(CONNECT_API ${CONNECT_API_VOLUMES} ${CONNECT_API_CONTAINERS} ${CONNECT_API_IMAGES} ${CONNECT_API_CRI_ALPHAS} ${CONNECT_API_CRI}) ++ set(CONNECT_API ${CONNECT_API_VOLUMES} ${CONNECT_API_CONTAINERS} ${CONNECT_API_IMAGES}) + list(APPEND local_client_connect_srcs ${CONNECT_API}) + + list(APPEND local_client_connect_incs ${CMAKE_CURRENT_SOURCE_DIR}/grpc) +@@ -23,8 +20,6 @@ if (GRPC_CONNECTOR) + ${CMAKE_BINARY_DIR}/grpc/src/api/services/volumes + ${CMAKE_BINARY_DIR}/grpc/src/api/services/containers + ${CMAKE_BINARY_DIR}/grpc/src/api/services/images +- ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri +- ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1alpha + ) + + if(ENABLE_NATIVE_NETWORK) +diff --git a/src/client/connect/grpc/grpc_images_client.cc b/src/client/connect/grpc/grpc_images_client.cc +index 7a283e8c..7fd36cc1 100644 +--- a/src/client/connect/grpc/grpc_images_client.cc ++++ b/src/client/connect/grpc/grpc_images_client.cc +@@ -390,50 +390,20 @@ public: + return 0; + } + +- auto run(const struct isula_pull_request *request, struct isula_pull_response *response) -> int override +- { +- ClientContext context; +- PullImageRequest grequest; +- +-#ifdef ENABLE_GRPC_REMOTE_CONNECT +-#ifdef OPENSSL_VERIFY +- // Set common name from cert.perm +- char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 }; +- int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value, +- ClientBaseConstants::COMMON_NAME_LEN); +- if (ret != 0) { +- ERROR("Failed to get common name in: %s", m_certFile.c_str()); +- return -1; +- } +- context.AddMetadata("username", std::string(common_name_value, strlen(common_name_value))); +- context.AddMetadata("tls_mode", m_tlsMode); +-#endif +-#endif +- if (request_to_grpc(request, &grequest) != 0) { +- ERROR("Failed to transform pull request to grpc"); +- response->server_errono = ISULAD_ERR_INPUT; +- return -1; +- } +- +- auto reader = stub_->PullImage(&context, grequest); ++ auto grpc_call(ClientContext *context, const PullImageRequest &req, PullImageResponse *reply) -> Status override ++ { ++ auto reader = stub_->PullImage(context, req); + +- PullImageResponse gresponse; +- if (grequest.is_progress_visible()) { +- while (reader->Read(&gresponse)) { +- output_progress(gresponse); ++ if (req.is_progress_visible()) { ++ while (reader->Read(reply)) { ++ output_progress(*reply); + } + } else { +- reader->Read(&gresponse); ++ reader->Read(reply); + WARN("The terminal may not support ANSI Escape code. Display is skipped"); + } +- Status status = reader->Finish(); +- if (!status.ok()) { +- ERROR("Error code: %d: %s", status.error_code(), status.error_message().c_str()); +- unpackStatus(status, response); +- return -1; +- } +- response->image_ref = util_strdup_s(gresponse.image_ref().c_str()); +- return 0; ++ ++ return reader->Finish(); + } + + private: +diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc +index 32b83a9e..5fe8ed5e 100644 +--- a/src/client/connect/grpc/grpc_volumes_client.cc ++++ b/src/client/connect/grpc/grpc_volumes_client.cc +@@ -16,7 +16,6 @@ + + #include + +-#include "api.grpc.pb.h" + #include "client_base.h" + #include "volumes.grpc.pb.h" + #include "utils.h" +diff --git a/src/daemon/common/events_format.h b/src/daemon/common/events_format.h +index 7e97b2c5..6b8fcfd5 100644 +--- a/src/daemon/common/events_format.h ++++ b/src/daemon/common/events_format.h +@@ -64,6 +64,8 @@ typedef enum { + EVENTS_TYPE_IMAGE_PULL, + EVENTS_TYPE_IMAGE_LOGIN, + EVENTS_TYPE_IMAGE_LOGOUT, ++ EVENTS_TYPE_IMAGE_IMPORT, ++ EVENTS_TYPE_IMAGE_TAG, + EVENTS_TYPE_IMAGE_MAX_STATE + } image_events_type_t; + +diff --git a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc +index b9cbf24c..066eed5e 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc ++++ b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc +@@ -25,7 +25,6 @@ + + #include "v1_cri_helpers.h" + #include "err_msg.h" +-#include "events_sender_api.h" + #include "isula_libutils/log.h" + #include "service_image_api.h" + #include "utils.h" +@@ -277,7 +276,6 @@ auto ImageManagerServiceImpl::PullImage(const runtime::v1::ImageSpec &image, + if (response->image_ref != nullptr) { + out_str = response->image_ref; + } +- (void)isulad_monitor_send_image_event(request->image, IM_PULL); + + cleanup: + DAEMON_CLEAR_ERRMSG(); +diff --git a/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc +index 0b36f007..9015df26 100644 +--- a/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc ++++ b/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc +@@ -25,7 +25,6 @@ + + #include "cri_helpers.h" + #include "err_msg.h" +-#include "events_sender_api.h" + #include "isula_libutils/log.h" + #include "service_image_api.h" + #include "utils.h" +@@ -277,7 +276,6 @@ auto ImageManagerServiceImpl::PullImage(const runtime::v1alpha2::ImageSpec &imag + if (response->image_ref != nullptr) { + out_str = response->image_ref; + } +- (void)isulad_monitor_send_image_event(request->image, IM_PULL); + + cleanup: + DAEMON_CLEAR_ERRMSG(); +diff --git a/src/daemon/executor/image_cb/image_cb.c b/src/daemon/executor/image_cb/image_cb.c +index 317cb0a8..60899f2b 100644 +--- a/src/daemon/executor/image_cb/image_cb.c ++++ b/src/daemon/executor/image_cb/image_cb.c +@@ -519,6 +519,7 @@ static int image_tag_cb(const image_tag_image_request *request, image_tag_image_ + } + + EVENT("Image Event: {Object: %s, Type: Tagged}", request->src_name); ++ (void)isulad_monitor_send_image_event(request->src_name, IM_TAG); + + out: + if (*response != NULL) { +@@ -997,6 +998,7 @@ static int image_pull_cb(const image_pull_image_request *request, stream_func_wr + } + + EVENT("Image Event: {Object: %s, Type: Pulled}", request->image_name); ++ (void)isulad_monitor_send_image_event(request->image_name, IM_PULL); + + out: + (*response)->cc = cc; +diff --git a/src/daemon/modules/api/event_type.h b/src/daemon/modules/api/event_type.h +index c3c7951b..4f2aaf28 100644 +--- a/src/daemon/modules/api/event_type.h ++++ b/src/daemon/modules/api/event_type.h +@@ -54,7 +54,9 @@ typedef enum { + MAX_STATE, + } runtime_state_t; + +-typedef enum { IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT, IM_IMPORT } image_state_t; ++// relate to g_isulad_image_event_strtype and image_events_type_t ++// we should keep them consistent ++typedef enum { IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT, IM_IMPORT, IM_TAG } image_state_t; + + typedef enum { CONTAINER_EVENT, IMAGE_EVENT } msg_event_type_t; + typedef enum { MONITORD_MSG_STATE, MONITORD_MSG_PRIORITY, MONITORD_MSG_EXIT_CODE } msg_type_t; +diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c +index b82ede81..36aa9299 100644 +--- a/src/daemon/modules/events/collector.c ++++ b/src/daemon/modules/events/collector.c +@@ -157,11 +157,11 @@ static const char *isulad_event_sta2str(container_events_type_t sta) + return g_isulad_event_strtype[sta]; + } + +-static const char * const g_isulad_image_event_strtype[] = { "load", "remove", "pull", "login", "logout" }; ++static const char * const g_isulad_image_event_strtype[] = { "load", "remove", "pull", "login", "logout", "import", "tag" }; + + static const char *isulad_image_event_sta2str(image_events_type_t sta) + { +- if (sta > EVENTS_TYPE_IMAGE_LOGOUT) { ++ if (sta >= EVENTS_TYPE_IMAGE_MAX_STATE) { + return NULL; + } + +diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c +index 8d7e2c1a..4a1950fe 100644 +--- a/src/daemon/modules/image/image.c ++++ b/src/daemon/modules/image/image.c +@@ -784,7 +784,7 @@ int im_merge_image_config(const char *image_type, const char *image_name, contai + int ret = 0; + struct bim *bim = NULL; + +- // there is no need to judge the image name as empty, ++ // there is no need to judge the image name as empty, + // because the image name of external type allows it to be empty. + if (container_spec == NULL || image_type == NULL) { + ERROR("Invalid input arguments"); +diff --git a/src/daemon/modules/image/oci/oci_pull.c b/src/daemon/modules/image/oci/oci_pull.c +index 2706af91..9ad875a5 100644 +--- a/src/daemon/modules/image/oci/oci_pull.c ++++ b/src/daemon/modules/image/oci/oci_pull.c +@@ -75,7 +75,8 @@ out: + return ret; + } + +-static void update_option_insecure_registry(registry_pull_options *options, char **insecure_registries, const char *host) ++static void update_option_insecure_registry(registry_pull_options *options, char **insecure_registries, ++ const char *host) + { + char **registry = NULL; + +@@ -188,83 +189,95 @@ typedef struct status_arg { + stream_func_wrapper *stream; + } status_arg; + ++static int do_get_progress_from_store(progress_status_map *status_store, image_progress *result) ++{ ++ int i = 0; ++ size_t progress_size = progress_status_map_size(status_store); ++ ++ result->progresses = util_smart_calloc_s(sizeof(image_progress_progresses_element *), progress_size); ++ if (result->progresses == NULL) { ++ ERROR("Out of memory"); ++ return -1; ++ } ++ ++ if (!progress_status_map_lock(status_store)) { ++ WARN("Cannot itorate progress status map for locking failed"); ++ // ignore lock error, retry lock after delay. ++ return 0; ++ } ++ ++ map_itor *itor = map_itor_new(status_store->map); ++ for (i = 0; map_itor_valid(itor) && i < progress_size; map_itor_next(itor), i++) { ++ void *id = map_itor_key(itor); ++ const progress *value = (progress *)map_itor_value(itor); ++ const int ID_LEN = 12; // The last 12 charactos of image digest. ++ ++ result->progresses[i] = util_common_calloc_s(sizeof(image_progress_progresses_element)); ++ if (result->progresses[i] == NULL) { ++ // ignore error, return got progress data ++ WARN("Out of memory"); ++ break; ++ } ++ result->progresses[i]->id = util_strdup_s((char *)id + strlen((char *)id) - ID_LEN); ++ result->progresses[i]->total = value->dltotal; ++ result->progresses[i]->current = value->dlnow; ++ result->progresses_len++; ++ } ++ map_itor_free(itor); ++ progress_status_map_unlock(status_store); ++ ++ return 0; ++} ++ + void *get_progress_status(void *arg) + { + status_arg *status = (status_arg *)arg; +- const int delay = 100; // Sleep for 100 milliseconds +- bool write_ok = false; ++ ++ prctl(PR_SET_NAME, "PullProgress"); + + if (status == NULL || status->status_store == NULL || status->stream == NULL) { + ERROR("Get progress status condition error"); + return NULL; + } + +- for (;;) { +- int i = 0; +- +- usleep(delay * 1000); // Sleep for 100 milliseconds ++ while (!status->should_terminal || status->image != NULL) { ++ bool write_ok = false; ++ image_progress *iprogresses = NULL; + +- if (status->should_terminal && status->image == NULL) { ++ // Step 1: delay 100ms, wait progress update ++ util_usleep_nointerupt(100 * 1000); ++ ++ // Step 2: check client whether is canceled? ++ if (status->stream->is_cancelled(status->stream->context)) { ++ WARN("pull stream is cancelled"); + break; + } +- +- image_progress *progresses; +- size_t progress_size = progress_status_map_size(status->status_store); + +- progresses = util_common_calloc_s(sizeof(image_progress)); +- if (progresses == NULL) { +- ERROR("Out of memory. Skip progress show."); +- break; ++ iprogresses = util_common_calloc_s(sizeof(image_progress)); ++ if (iprogresses == NULL) { ++ ERROR("Out of memory"); ++ break; + } +- +- progresses->progresses = util_smart_calloc_s(sizeof(image_progress_progresses_element *), progress_size); +- if (progresses->progresses == NULL) { +- ERROR("Out of memory. Skip progress show."); +- goto roundend; ++ // Step 3: get progress of pull from progress status store ++ if (do_get_progress_from_store(status->status_store, iprogresses) != 0) { ++ free_image_progress(iprogresses); ++ break; + } ++ ++ // Step 4: check main thread whether is finished, and setted pulled image info + if (status->image != NULL) { +- progresses->image = util_strdup_s(status->image_name); ++ iprogresses->image = util_strdup_s(status->image_name); + status->image = NULL; + } + +- if (!progress_status_map_lock(status->status_store)) { +- ERROR("Cannot itorate progress status map for locking failed"); +- goto roundend; +- } +- map_itor *itor = map_itor_new(status->status_store->map); +- for (i = 0; map_itor_valid(itor) && i < progress_size; map_itor_next(itor), i++) { +- void *id = map_itor_key(itor); +- const progress *value = (progress *)map_itor_value(itor); +- const int ID_LEN = 12; // The last 12 charactos of image digest. +- +- progresses->progresses[i] = util_common_calloc_s(sizeof(image_progress_progresses_element)); +- if (progresses->progresses[i] == NULL) { +- WARN("Out of memory. Skip progress show."); +- map_itor_free(itor); +- progress_status_map_unlock(status->status_store); +- goto roundend; +- } +- progresses->progresses[i]->id = util_strdup_s((char *)id + strlen((char *)id) - ID_LEN); +- progresses->progresses[i]->total = value->dltotal; +- progresses->progresses[i]->current = value->dlnow; +- progresses->progresses_len++; ++ // Step 5: send got progress of pull to client ++ write_ok = status->stream->write_func(status->stream->writer, iprogresses); ++ if (!write_ok) { ++ WARN("Send progress data to client failed, just ignore and retry it"); + } +- map_itor_free(itor); +- progress_status_map_unlock(status->status_store); +- +- /* send to client */ +- write_ok = status->stream->write_func(status->stream->writer, progresses); +- if (write_ok) { +- goto roundend; +- } +- if (status->stream->is_cancelled(status->stream->context)) { +- ERROR("pull stream is cancelled"); +- goto roundend; +- } +- ERROR("Send progress data to client failed"); +-roundend: +- free_image_progress(progresses); ++ free_image_progress(iprogresses); + } ++ + return NULL; + } + +@@ -286,7 +299,7 @@ int oci_do_pull_image(const im_pull_request *request, stream_func_wrapper *strea + if (request->is_progress_visible && stream != NULL) { + progress_status_store = progress_status_map_new(); + if (progress_status_store == NULL) { +- ERROR("Out of memory and will not show the pull progress"); ++ ERROR("Out of memory"); + isulad_set_error_message("Failed to pull image %s with error: out of memory", request->image); + ret = -1; + goto out; +@@ -321,21 +334,28 @@ int oci_do_pull_image(const im_pull_request *request, stream_func_wrapper *strea + arg.image = image; + arg.image_name = dest_image_name; + if (!request->is_progress_visible && stream != NULL) { +- image_progress *progresses; ++ image_progress *progresses = NULL; ++ bool nret = false; + + progresses = util_common_calloc_s(sizeof(image_progress)); + if (progresses == NULL) { +- ERROR("Out of memory. Skip progress show."); +- goto out; ++ ERROR("Out of memory"); ++ isulad_set_error_message("Failed to pull image %s with error: out of memory", request->image); ++ ret = -1; ++ goto out; + } + progresses->image = util_strdup_s(dest_image_name); +- if (stream->write_func(stream->writer, progresses)) { ++ nret = stream->write_func(stream->writer, progresses); ++ free_image_progress(progresses); ++ if (!nret) { + ERROR("Send progress data to client failed"); ++ isulad_set_error_message("Failed to pull image %s with error: send progress data to client failed", request->image); ++ ret = -1; + goto out; + } + } + response->image_ref = util_strdup_s(image->id); +- ++ + out: + arg.should_terminal = true; + if (tid != 0 && pthread_join(tid, NULL) != 0) { +diff --git a/src/daemon/modules/image/oci/progress.c b/src/daemon/modules/image/oci/progress.c +index 110f22c0..7d0c10a4 100644 +--- a/src/daemon/modules/image/oci/progress.c ++++ b/src/daemon/modules/image/oci/progress.c +@@ -34,15 +34,16 @@ size_t progress_status_map_size(progress_status_map *progress_status_map) + } + ret = map_size(progress_status_map->map); + progress_status_map_unlock(progress_status_map); +- ++ + return ret; + } + +-bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value) ++bool progress_status_map_udpate(progress_status_map *progress_status_map, char *key, int64_t current, int64_t total) + { + bool ret = false; ++ progress *pval = NULL; + +- if (progress_status_map == NULL || key == NULL || value == NULL) { ++ if (progress_status_map == NULL || key == NULL) { + ERROR("Invalid parameter"); + return false; + } +@@ -51,9 +52,26 @@ bool progress_status_map_insert(progress_status_map *progress_status_map, char * + ERROR("Cannot replace the progress status map item for locking failed"); + return false; + } +- ret = map_insert(progress_status_map->map, key, value); +- progress_status_map_unlock(progress_status_map); + ++ // If the item exists, only replace the value. ++ pval = map_search(progress_status_map->map, key); ++ if (pval != NULL) { ++ pval->dlnow = current; ++ pval->dltotal = total; ++ progress_status_map_unlock(progress_status_map); ++ return true; ++ } ++ pval = util_common_calloc_s(sizeof(progress)); ++ if (pval == NULL) { ++ ERROR("Out of memory"); ++ progress_status_map_unlock(progress_status_map); ++ return false; ++ } ++ pval->dlnow = current; ++ pval->dltotal = total; ++ ++ ret = map_insert(progress_status_map->map, key, pval); ++ progress_status_map_unlock(progress_status_map); + return ret; + } + +diff --git a/src/daemon/modules/image/oci/progress.h b/src/daemon/modules/image/oci/progress.h +index 496a32f3..dcc8e144 100644 +--- a/src/daemon/modules/image/oci/progress.h ++++ b/src/daemon/modules/image/oci/progress.h +@@ -29,11 +29,11 @@ typedef struct progress_status_map { + } progress_status_map; + + typedef struct progress { +- int64_t dlnow; +- int64_t dltotal; ++ int64_t dlnow; ++ int64_t dltotal; + } progress; + +-bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value); ++bool progress_status_map_udpate(progress_status_map *progress_status_map, char *key, int64_t current, int64_t total); + + progress_status_map *progress_status_map_new(); + +diff --git a/src/daemon/modules/image/oci/registry/http_request.c b/src/daemon/modules/image/oci/registry/http_request.c +index 748c9a9b..450fbc41 100644 +--- a/src/daemon/modules/image/oci/registry/http_request.c ++++ b/src/daemon/modules/image/oci/registry/http_request.c +@@ -692,44 +692,22 @@ out: + static int xfer_inner(void *p, int64_t dltotal, int64_t dlnow, int64_t ultotal, int64_t ulnow) + { + progress_arg *arg = (progress_arg *)p; +- progress *progress_value = NULL; + + if (arg == NULL || arg->map_store == NULL) { + ERROR("Wrong progress arg"); + return -1; + } ++ + // When fetch_manifest_list, there's no digest. It's not a layer pulling progress and skip it. + if (arg->digest == NULL) { + return 0; + } + +- if (!progress_status_map_lock(arg->map_store)) { +- ERROR("Cannot update progress status map for locking failed"); ++ if (!progress_status_map_udpate(arg->map_store, arg->digest, dlnow, dltotal)) { ++ ERROR("Failed to update pull progress"); + return -1; + } + +- // If the item exists, only replace the value. +- progress_value = map_search(arg->map_store->map, arg->digest); +- if (progress_value != NULL) { +- progress_value->dlnow = dlnow; +- progress_value->dltotal = dltotal; +- progress_status_map_unlock(arg->map_store); +- +- return 0; +- } +- progress_status_map_unlock(arg->map_store); +- +- progress_value = util_common_calloc_s(sizeof(progress)); +- if (progress_value == NULL) { +- ERROR("Out of memory"); +- return -1; +- } +- +- progress_value->dlnow = dlnow; +- progress_value->dltotal = dltotal; +- +- progress_status_map_insert(arg->map_store, arg->digest, progress_value); +- + return 0; + } + +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 f49f4707..58baa47a 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 +@@ -2824,7 +2824,7 @@ static int implicit_digest(map_t *digests, image_t *img) + + // Find whether the manifest in big_data_digests exists, if not, return 0 directly + if (!get_index_by_key((const char **)img->simage->big_data_digests->keys, img->simage->big_data_digests->len, +- IMAGE_DIGEST_BIG_DATA_KEY, &index)) { ++ IMAGE_DIGEST_BIG_DATA_KEY, &index)) { + return 0; + } + +diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c +index 7517dd43..3bc433ae 100644 +--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c ++++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c +@@ -1930,7 +1930,7 @@ int overlay2_apply_diff(const char *id, const struct graphdriver *driver, const + goto out; + } + +- ret = archive_unpack(content, layer_diff, &options, root_dir ,&err); ++ ret = archive_unpack(content, layer_diff, &options, root_dir, &err); + if (ret != 0) { + ERROR("Failed to unpack to %s: %s", layer_diff, err); + ret = -1; +diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c +index 2e53dbac..0d1a846a 100644 +--- a/src/daemon/modules/image/oci/storage/storage.c ++++ b/src/daemon/modules/image/oci/storage/storage.c +@@ -215,7 +215,7 @@ int storage_inc_hold_refs(const char *layer_id) + int storage_dec_hold_refs(const char *layer_id) + { + int ret = 0; +- ++ + if (layer_id == NULL) { + ERROR("Empty layer id"); + return -1; +@@ -550,7 +550,8 @@ char *storage_img_get_image_id(const char *img_name) + return image_store_lookup(img_name); + } + +-static bool is_top_layer_of_other_image(const char *img_id, const imagetool_images_list *all_images, const char *layer_id) ++static bool is_top_layer_of_other_image(const char *img_id, const imagetool_images_list *all_images, ++ const char *layer_id) + { + size_t i = 0; + +-- +2.42.0 + diff --git a/0028-2230-format-code.patch b/0028-2230-format-code.patch new file mode 100644 index 0000000000000000000000000000000000000000..1efc3282bd9aa71dec201724da949f5ce715091a --- /dev/null +++ b/0028-2230-format-code.patch @@ -0,0 +1,3476 @@ +From c91b4d223fa590e2d5164b42e12a9bca319831e5 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Thu, 23 Nov 2023 12:31:47 +0000 +Subject: [PATCH 28/65] !2230 format code * format code tools/static_check.sh + +--- + src/daemon/common/cri/v1/v1_cri_helpers.cc | 8 +- + src/daemon/common/cri/v1/v1_cri_helpers.h | 6 +- + .../common/cri/v1/v1_cri_security_context.cc | 6 +- + .../entry/connect/grpc/cri/cri_service.cc | 2 +- + .../cri/v1/cri_v1_runtime_image_service.cc | 20 +- + .../cri/v1/cri_v1_runtime_runtime_service.cc | 91 +-- + .../v1alpha/cri_runtime_runtime_service.cc | 3 +- + src/daemon/entry/connect/grpc/grpc_service.cc | 2 +- + src/daemon/entry/cri/network_plugin.cc | 4 +- + .../v1/v1_cri_container_manager_service.cc | 10 +- + .../v1/v1_cri_image_manager_service_impl.cc | 6 +- + .../v1/v1_cri_image_manager_service_impl.h | 2 +- + .../v1/v1_cri_pod_sandbox_manager_service.cc | 15 +- + .../v1alpha/cri_container_manager_service.cc | 3 +- + .../cri_pod_sandbox_manager_service.cc | 2 +- + .../entry/cri/v1alpha/cri_security_context.cc | 6 +- + .../entry/cri/v1alpha/v1alpha_cri_helpers.cc | 2 +- + .../executor/container_cb/execution_create.c | 8 +- + .../container_cb/execution_information.c | 5 +- + src/daemon/modules/api/container_api.h | 3 +- + .../modules/container/restore/restore.c | 3 +- + .../cni_operator/libcni/invoke/libcni_exec.c | 2 +- + .../network/cni_operator/libcni/libcni_api.c | 9 +- + .../network/cni_operator/libcni/libcni_api.h | 2 +- + .../cni_operator/libcni/libcni_cached.c | 2 +- + .../cni_operator/libcni/libcni_result_type.c | 2 +- + .../modules/runtime/isula/isula_rt_ops.c | 2 +- + .../modules/runtime/shim/shim_rt_monitor.cc | 2 +- + src/daemon/modules/runtime/shim/shim_rt_ops.c | 2 +- + .../modules/service/service_container.c | 3 +- + .../modules/service/vsock_io_handler.cc | 7 +- + src/daemon/modules/service/vsock_io_handler.h | 6 +- + .../sandboxer/client/grpc_async_wait_call.cc | 11 +- + .../sandboxer/client/grpc_async_wait_call.h | 18 +- + .../sandboxer/client/grpc_sandboxer_client.cc | 56 +- + .../sandboxer/client/grpc_sandboxer_client.h | 6 +- + .../client/grpc_sandboxer_monitor.cc | 10 +- + .../sandboxer/client/grpc_sandboxer_monitor.h | 2 +- + .../controller/shim/shim_controller.cc | 7 +- + src/daemon/sandbox/sandbox.cc | 3 +- + src/daemon/sandbox/sandbox_manager.cc | 3 +- + src/daemon/sandbox/sandbox_manager.h | 3 +- + src/daemon/sandbox/sandbox_ops.cc | 2 +- + src/daemon/sandbox/sandbox_ops.h | 3 +- + src/utils/cpputils/url.cc | 5 +- + src/utils/cutils/error.h | 2 +- + src/utils/cutils/map/map.h | 8 - + src/utils/tar/isulad_tar.c | 9 +- + src/utils/tar/isulad_tar.h | 3 +- + test/cutils/utils_file/utils_file_ut.cc | 2 +- + test/mocks/callback_mock.cc | 8 +- + test/mocks/controller_stub_mock.cc | 516 +++++++++++------- + test/mocks/controller_stub_mock.h | 259 +++++++-- + test/mocks/grpc_async_wait_call_mock.cc | 3 +- + test/mocks/grpc_async_wait_call_mock.h | 2 +- + test/mocks/grpc_sandboxer_client_mock.cc | 15 +- + test/mocks/grpc_sandboxer_client_mock.h | 12 +- + test/mocks/grpc_sandboxer_monitor_mock.cc | 2 +- + test/mocks/isulad_config_mock.h | 2 +- + test/mocks/sandbox_mock.cc | 2 +- + test/mocks/sandbox_mock.h | 2 +- + test/mocks/service_container_api_mock.h | 2 +- + test/mocks/shim_controller_mock.cc | 6 +- + test/mocks/shim_controller_mock.h | 8 +- + test/network/cni_operate/cni_operate_ut.cc | 40 +- + test/network/network_mock.cc | 2 +- + test/sandbox/controller/controller_common.cc | 16 +- + test/sandbox/controller/controller_common.h | 3 +- + .../manager/controller_manager_ut.cc | 27 +- + .../async_wait_call/async_wait_call_ut.cc | 9 +- + .../async_wait_call/dummy_monitor_utils.h | 44 +- + .../sandboxer_client/sandboxer_client_ut.cc | 135 +++-- + .../sandboxer_controller_ut.cc | 18 +- + .../controller/shim/shim_controller_ut.cc | 6 +- + 74 files changed, 963 insertions(+), 575 deletions(-) + +diff --git a/src/daemon/common/cri/v1/v1_cri_helpers.cc b/src/daemon/common/cri/v1/v1_cri_helpers.cc +index 4f2660e8..be06eb0a 100644 +--- a/src/daemon/common/cri/v1/v1_cri_helpers.cc ++++ b/src/daemon/common/cri/v1/v1_cri_helpers.cc +@@ -391,7 +391,7 @@ auto GetSecurityOpts(const commonSecurityContext &context, const char &separator + } + + std::vector selinuxOpts = CRIHelpersV1::GetSELinuxLabelOpts(context.hasSELinuxOption, +- context.selinuxOption, separator, error); ++ context.selinuxOption, separator, error); + if (error.NotEmpty()) { + error.Errorf("Failed to generate SELinuxLabel options for container %s", error.GetMessage().c_str()); + return securityOpts; +@@ -459,7 +459,8 @@ void AddSecurityOptsToHostConfig(std::vector &securityOpts, host_co + } + + } +-void GetContainerSandboxID(const std::string &containerID, std::string &realContainerID, std::string &sandboxID, Errors &error) ++void GetContainerSandboxID(const std::string &containerID, std::string &realContainerID, std::string &sandboxID, ++ Errors &error) + { + std::string PodID; + container_inspect *info = CRIHelpers::InspectContainer(containerID, error, false); +@@ -526,7 +527,8 @@ out: + return sandboxer; + } + +-void ApplySandboxSecurityContextToHostConfig(const runtime::v1::LinuxSandboxSecurityContext &context, host_config *hc, Errors &error) ++void ApplySandboxSecurityContextToHostConfig(const runtime::v1::LinuxSandboxSecurityContext &context, host_config *hc, ++ Errors &error) + { + if (hc == nullptr) { + ERROR("Invalid input arguments: empty hostconfig"); +diff --git a/src/daemon/common/cri/v1/v1_cri_helpers.h b/src/daemon/common/cri/v1/v1_cri_helpers.h +index 0fa1ae91..7085f8d2 100644 +--- a/src/daemon/common/cri/v1/v1_cri_helpers.h ++++ b/src/daemon/common/cri/v1/v1_cri_helpers.h +@@ -73,11 +73,13 @@ auto GetPodSELinuxLabelOpts(const std::string &selinuxLabel, Errors &error) + + void AddSecurityOptsToHostConfig(std::vector &securityOpts, host_config *hostconfig, Errors &error); + +-void GetContainerSandboxID(const std::string &containerID, std::string &realContainerID, std::string &sandboxID, Errors &error); ++void GetContainerSandboxID(const std::string &containerID, std::string &realContainerID, std::string &sandboxID, ++ Errors &error); + + std::string CRISandboxerConvert(const std::string &runtime); + +-void ApplySandboxSecurityContextToHostConfig(const runtime::v1::LinuxSandboxSecurityContext &context, host_config *hc, Errors &error); ++void ApplySandboxSecurityContextToHostConfig(const runtime::v1::LinuxSandboxSecurityContext &context, host_config *hc, ++ Errors &error); + + }; // namespace CRIHelpers + +diff --git a/src/daemon/common/cri/v1/v1_cri_security_context.cc b/src/daemon/common/cri/v1/v1_cri_security_context.cc +index 930710e0..7cdbf5fc 100644 +--- a/src/daemon/common/cri/v1/v1_cri_security_context.cc ++++ b/src/daemon/common/cri/v1/v1_cri_security_context.cc +@@ -19,7 +19,8 @@ + #include + + namespace CRISecurityV1 { +-static void ModifyContainerConfig(const runtime::v1::LinuxContainerSecurityContext &sc, container_config *config, Errors &error) ++static void ModifyContainerConfig(const runtime::v1::LinuxContainerSecurityContext &sc, container_config *config, ++ Errors &error) + { + // none -> ""; username -> username; username, uid -> username; username, uid, gid -> username:gid; + // username, gid -> username:gid; uid -> uid; uid, gid -> uid:gid; gid -> error +@@ -157,7 +158,8 @@ static void ApplyMaskedPathsToHostConfig(const runtime::v1::LinuxContainerSecuri + } + } + +-static void ApplyReadonlyPathsToHostConfig(const runtime::v1::LinuxContainerSecurityContext &sc, host_config *hostConfig, ++static void ApplyReadonlyPathsToHostConfig(const runtime::v1::LinuxContainerSecurityContext &sc, ++ host_config *hostConfig, + Errors &error) + { + if (sc.readonly_paths_size() <= 0) { +diff --git a/src/daemon/entry/connect/grpc/cri/cri_service.cc b/src/daemon/entry/connect/grpc/cri/cri_service.cc +index e33a6d34..c1986c44 100644 +--- a/src/daemon/entry/connect/grpc/cri/cri_service.cc ++++ b/src/daemon/entry/connect/grpc/cri/cri_service.cc +@@ -50,7 +50,7 @@ int CRIService::Init(const isulad_daemon_configs *config) + } + + Errors err; +- /* note: get config from args, now use defaults */ ++ /* note: get config from args, now use defaults */ + Network::NetworkPluginConf mConf; + + if (config != nullptr) { +diff --git a/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_image_service.cc b/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_image_service.cc +index ac62b6eb..09c8958d 100644 +--- a/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_image_service.cc ++++ b/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_image_service.cc +@@ -28,8 +28,8 @@ RuntimeV1ImageServiceImpl::RuntimeV1ImageServiceImpl() + } + + grpc::Status RuntimeV1ImageServiceImpl::PullImage(grpc::ServerContext *context, +- const runtime::v1::PullImageRequest *request, +- runtime::v1::PullImageResponse *reply) ++ const runtime::v1::PullImageRequest *request, ++ runtime::v1::PullImageResponse *reply) + { + Errors error; + +@@ -53,8 +53,8 @@ grpc::Status RuntimeV1ImageServiceImpl::PullImage(grpc::ServerContext *context, + } + + grpc::Status RuntimeV1ImageServiceImpl::ListImages(grpc::ServerContext *context, +- const runtime::v1::ListImagesRequest *request, +- runtime::v1::ListImagesResponse *reply) ++ const runtime::v1::ListImagesRequest *request, ++ runtime::v1::ListImagesResponse *reply) + { + std::vector> images; + Errors error; +@@ -86,8 +86,8 @@ grpc::Status RuntimeV1ImageServiceImpl::ListImages(grpc::ServerContext *context, + } + + grpc::Status RuntimeV1ImageServiceImpl::ImageStatus(grpc::ServerContext *context, +- const runtime::v1::ImageStatusRequest *request, +- runtime::v1::ImageStatusResponse *reply) ++ const runtime::v1::ImageStatusRequest *request, ++ runtime::v1::ImageStatusResponse *reply) + { + std::unique_ptr image_info = nullptr; + Errors error; +@@ -117,8 +117,8 @@ grpc::Status RuntimeV1ImageServiceImpl::ImageStatus(grpc::ServerContext *context + } + + grpc::Status RuntimeV1ImageServiceImpl::ImageFsInfo(grpc::ServerContext *context, +- const runtime::v1::ImageFsInfoRequest *request, +- runtime::v1::ImageFsInfoResponse *reply) ++ const runtime::v1::ImageFsInfoRequest *request, ++ runtime::v1::ImageFsInfoResponse *reply) + { + std::vector> usages; + Errors error; +@@ -150,8 +150,8 @@ grpc::Status RuntimeV1ImageServiceImpl::ImageFsInfo(grpc::ServerContext *context + } + + grpc::Status RuntimeV1ImageServiceImpl::RemoveImage(grpc::ServerContext *context, +- const runtime::v1::RemoveImageRequest *request, +- runtime::v1::RemoveImageResponse *reply) ++ const runtime::v1::RemoveImageRequest *request, ++ runtime::v1::RemoveImageResponse *reply) + { + Errors error; + +diff --git a/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc +index 1db79307..ba9459f6 100644 +--- a/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc ++++ b/src/daemon/entry/connect/grpc/cri/v1/cri_v1_runtime_runtime_service.cc +@@ -25,7 +25,8 @@ + + using namespace CRIV1; + +-void RuntimeV1RuntimeServiceImpl::Init(std::string &podSandboxImage, std::shared_ptr networkPlugin, Errors &err) ++void RuntimeV1RuntimeServiceImpl::Init(std::string &podSandboxImage, ++ std::shared_ptr networkPlugin, Errors &err) + { + // Assembly implementation for CRIRuntimeServiceImpl + service_executor_t *cb = get_service_executor(); +@@ -47,8 +48,8 @@ void RuntimeV1RuntimeServiceImpl::Shutdown() + } + + grpc::Status RuntimeV1RuntimeServiceImpl::Version(grpc::ServerContext *context, +- const runtime::v1::VersionRequest *request, +- runtime::v1::VersionResponse *reply) ++ const runtime::v1::VersionRequest *request, ++ runtime::v1::VersionResponse *reply) + { + Errors error; + if (request == nullptr || reply == nullptr) { +@@ -65,8 +66,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::Version(grpc::ServerContext *context, + } + + grpc::Status RuntimeV1RuntimeServiceImpl::CreateContainer(grpc::ServerContext *context, +- const runtime::v1::CreateContainerRequest *request, +- runtime::v1::CreateContainerResponse *reply) ++ const runtime::v1::CreateContainerRequest *request, ++ runtime::v1::CreateContainerResponse *reply) + { + Errors error; + +@@ -91,8 +92,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::CreateContainer(grpc::ServerContext *c + } + + grpc::Status RuntimeV1RuntimeServiceImpl::StartContainer(grpc::ServerContext *context, +- const runtime::v1::StartContainerRequest *request, +- runtime::v1::StartContainerResponse *reply) ++ const runtime::v1::StartContainerRequest *request, ++ runtime::v1::StartContainerResponse *reply) + { + Errors error; + +@@ -115,8 +116,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::StartContainer(grpc::ServerContext *co + } + + grpc::Status RuntimeV1RuntimeServiceImpl::StopContainer(grpc::ServerContext *context, +- const runtime::v1::StopContainerRequest *request, +- runtime::v1::StopContainerResponse *reply) ++ const runtime::v1::StopContainerRequest *request, ++ runtime::v1::StopContainerResponse *reply) + { + Errors error; + +@@ -139,8 +140,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::StopContainer(grpc::ServerContext *con + } + + grpc::Status RuntimeV1RuntimeServiceImpl::RemoveContainer(grpc::ServerContext *context, +- const runtime::v1::RemoveContainerRequest *request, +- runtime::v1::RemoveContainerResponse *reply) ++ const runtime::v1::RemoveContainerRequest *request, ++ runtime::v1::RemoveContainerResponse *reply) + { + Errors error; + +@@ -163,8 +164,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::RemoveContainer(grpc::ServerContext *c + } + + grpc::Status RuntimeV1RuntimeServiceImpl::ListContainers(grpc::ServerContext *context, +- const runtime::v1::ListContainersRequest *request, +- runtime::v1::ListContainersResponse *reply) ++ const runtime::v1::ListContainersRequest *request, ++ runtime::v1::ListContainersResponse *reply) + { + Errors error; + +@@ -197,8 +198,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::ListContainers(grpc::ServerContext *co + } + + grpc::Status RuntimeV1RuntimeServiceImpl::ContainerStats(grpc::ServerContext *context, +- const runtime::v1::ContainerStatsRequest *request, +- runtime::v1::ContainerStatsResponse *reply) ++ const runtime::v1::ContainerStatsRequest *request, ++ runtime::v1::ContainerStatsResponse *reply) + { + Errors error; + +@@ -223,8 +224,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::ContainerStats(grpc::ServerContext *co + } + + grpc::Status RuntimeV1RuntimeServiceImpl::ListContainerStats(grpc::ServerContext *context, +- const runtime::v1::ListContainerStatsRequest *request, +- runtime::v1::ListContainerStatsResponse *reply) ++ const runtime::v1::ListContainerStatsRequest *request, ++ runtime::v1::ListContainerStatsResponse *reply) + { + Errors error; + +@@ -257,8 +258,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::ListContainerStats(grpc::ServerContext + } + + grpc::Status RuntimeV1RuntimeServiceImpl::ContainerStatus(grpc::ServerContext *context, +- const runtime::v1::ContainerStatusRequest *request, +- runtime::v1::ContainerStatusResponse *reply) ++ const runtime::v1::ContainerStatusRequest *request, ++ runtime::v1::ContainerStatusResponse *reply) + { + Errors error; + +@@ -283,8 +284,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::ContainerStatus(grpc::ServerContext *c + } + + grpc::Status RuntimeV1RuntimeServiceImpl::ExecSync(grpc::ServerContext *context, +- const runtime::v1::ExecSyncRequest *request, +- runtime::v1::ExecSyncResponse *reply) ++ const runtime::v1::ExecSyncRequest *request, ++ runtime::v1::ExecSyncResponse *reply) + { + Errors error; + +@@ -307,8 +308,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::ExecSync(grpc::ServerContext *context, + } + + grpc::Status RuntimeV1RuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *context, +- const runtime::v1::RunPodSandboxRequest *request, +- runtime::v1::RunPodSandboxResponse *reply) ++ const runtime::v1::RunPodSandboxRequest *request, ++ runtime::v1::RunPodSandboxResponse *reply) + { + Errors error; + +@@ -335,8 +336,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::RunPodSandbox(grpc::ServerContext *con + } + + grpc::Status RuntimeV1RuntimeServiceImpl::StopPodSandbox(grpc::ServerContext *context, +- const runtime::v1::StopPodSandboxRequest *request, +- runtime::v1::StopPodSandboxResponse *reply) ++ const runtime::v1::StopPodSandboxRequest *request, ++ runtime::v1::StopPodSandboxResponse *reply) + { + Errors error; + +@@ -360,8 +361,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::StopPodSandbox(grpc::ServerContext *co + } + + grpc::Status RuntimeV1RuntimeServiceImpl::RemovePodSandbox(grpc::ServerContext *context, +- const runtime::v1::RemovePodSandboxRequest *request, +- runtime::v1::RemovePodSandboxResponse *reply) ++ const runtime::v1::RemovePodSandboxRequest *request, ++ runtime::v1::RemovePodSandboxResponse *reply) + { + Errors error; + +@@ -385,8 +386,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::RemovePodSandbox(grpc::ServerContext * + } + + grpc::Status RuntimeV1RuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *context, +- const runtime::v1::PodSandboxStatusRequest *request, +- runtime::v1::PodSandboxStatusResponse *reply) ++ const runtime::v1::PodSandboxStatusRequest *request, ++ runtime::v1::PodSandboxStatusResponse *reply) + { + Errors error; + +@@ -412,8 +413,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext * + } + + grpc::Status RuntimeV1RuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *context, +- const runtime::v1::ListPodSandboxRequest *request, +- runtime::v1::ListPodSandboxResponse *reply) ++ const runtime::v1::ListPodSandboxRequest *request, ++ runtime::v1::ListPodSandboxResponse *reply) + { + Errors error; + +@@ -446,8 +447,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *co + } + + grpc::Status RuntimeV1RuntimeServiceImpl::PodSandboxStats(grpc::ServerContext *context, +- const runtime::v1::PodSandboxStatsRequest *request, +- runtime::v1::PodSandboxStatsResponse *reply) ++ const runtime::v1::PodSandboxStatsRequest *request, ++ runtime::v1::PodSandboxStatsResponse *reply) + { + Errors error; + +@@ -474,8 +475,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::PodSandboxStats(grpc::ServerContext *c + + grpc::Status + RuntimeV1RuntimeServiceImpl::ListPodSandboxStats(grpc::ServerContext *context, +- const runtime::v1::ListPodSandboxStatsRequest *request, +- runtime::v1::ListPodSandboxStatsResponse *reply) ++ const runtime::v1::ListPodSandboxStatsRequest *request, ++ runtime::v1::ListPodSandboxStatsResponse *reply) + { + Errors error; + +@@ -508,8 +509,8 @@ RuntimeV1RuntimeServiceImpl::ListPodSandboxStats(grpc::ServerContext *context, + + grpc::Status + RuntimeV1RuntimeServiceImpl::UpdateContainerResources(grpc::ServerContext *context, +- const runtime::v1::UpdateContainerResourcesRequest *request, +- runtime::v1::UpdateContainerResourcesResponse *reply) ++ const runtime::v1::UpdateContainerResourcesRequest *request, ++ runtime::v1::UpdateContainerResourcesResponse *reply) + { + Errors error; + +@@ -533,8 +534,8 @@ RuntimeV1RuntimeServiceImpl::UpdateContainerResources(grpc::ServerContext *conte + } + + grpc::Status RuntimeV1RuntimeServiceImpl::Exec(grpc::ServerContext *context, +- const runtime::v1::ExecRequest *request, +- runtime::v1::ExecResponse *response) ++ const runtime::v1::ExecRequest *request, ++ runtime::v1::ExecResponse *response) + { + Errors error; + +@@ -558,8 +559,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::Exec(grpc::ServerContext *context, + } + + grpc::Status RuntimeV1RuntimeServiceImpl::Attach(grpc::ServerContext *context, +- const runtime::v1::AttachRequest *request, +- runtime::v1::AttachResponse *response) ++ const runtime::v1::AttachRequest *request, ++ runtime::v1::AttachResponse *response) + { + Errors error; + +@@ -584,8 +585,8 @@ grpc::Status RuntimeV1RuntimeServiceImpl::Attach(grpc::ServerContext *context, + + grpc::Status + RuntimeV1RuntimeServiceImpl::UpdateRuntimeConfig(grpc::ServerContext *context, +- const runtime::v1::UpdateRuntimeConfigRequest *request, +- runtime::v1::UpdateRuntimeConfigResponse *reply) ++ const runtime::v1::UpdateRuntimeConfigRequest *request, ++ runtime::v1::UpdateRuntimeConfigResponse *reply) + { + Errors error; + +@@ -608,8 +609,8 @@ RuntimeV1RuntimeServiceImpl::UpdateRuntimeConfig(grpc::ServerContext *context, + } + + grpc::Status RuntimeV1RuntimeServiceImpl::Status(grpc::ServerContext *context, +- const runtime::v1::StatusRequest *request, +- runtime::v1::StatusResponse *reply) ++ const runtime::v1::StatusRequest *request, ++ runtime::v1::StatusResponse *reply) + { + Errors error; + +diff --git a/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc +index a56b167c..5e85702c 100644 +--- a/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc ++++ b/src/daemon/entry/connect/grpc/cri/v1alpha/cri_runtime_runtime_service.cc +@@ -23,7 +23,8 @@ + + using namespace CRI; + +-void RuntimeRuntimeServiceImpl::Init(std::string &podSandboxImage, std::shared_ptr networkPlugin, Errors &err) ++void RuntimeRuntimeServiceImpl::Init(std::string &podSandboxImage, ++ std::shared_ptr networkPlugin, Errors &err) + { + // Assembly implementation for CRIRuntimeServiceImpl + service_executor_t *cb = get_service_executor(); +diff --git a/src/daemon/entry/connect/grpc/grpc_service.cc b/src/daemon/entry/connect/grpc/grpc_service.cc +index 4e1ae019..61e284f3 100644 +--- a/src/daemon/entry/connect/grpc/grpc_service.cc ++++ b/src/daemon/entry/connect/grpc/grpc_service.cc +@@ -109,7 +109,7 @@ public: + void Shutdown(void) + { + m_server->Shutdown(); +- ++ + // call CRI to shutdown stream server + m_criService.Shutdown(); + +diff --git a/src/daemon/entry/cri/network_plugin.cc b/src/daemon/entry/cri/network_plugin.cc +index f919a059..f8f9c7e6 100644 +--- a/src/daemon/entry/cri/network_plugin.cc ++++ b/src/daemon/entry/cri/network_plugin.cc +@@ -558,14 +558,14 @@ void NoopNetworkPlugin::SetUpPod(const std::string &ns, const std::string &name, + } + + container_network_settings *network_settings = static_cast +- (util_common_calloc_s(sizeof(container_network_settings))); ++ (util_common_calloc_s(sizeof(container_network_settings))); + if (network_settings == nullptr) { + ERROR("Out of memory"); + error.SetError("Out of memory"); + return; + } + auto settingsWarpper = std::unique_ptr>(new +- CStructWrapper(network_settings, free_container_network_settings)); ++ CStructWrapper(network_settings, free_container_network_settings)); + + network_settings->sandbox_key = util_strdup_s(netnsPath.c_str()); + +diff --git a/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc b/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc +index f635df2b..067f4210 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc ++++ b/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc +@@ -149,7 +149,7 @@ void ContainerManagerService::DoUsePodLevelSELinuxConfig(const runtime::v1::Cont + auto ContainerManagerService::IsSELinuxLabelEmpty(const ::runtime::v1::SELinuxOption &selinuxOption) -> bool + { + return selinuxOption.user().length() == 0 && selinuxOption.role().length() == 0 && +- selinuxOption.type().length() == 0 && selinuxOption.level().length() == 0; ++ selinuxOption.type().length() == 0 && selinuxOption.level().length() == 0; + } + + auto ContainerManagerService::GenerateCreateContainerHostConfig( +@@ -194,7 +194,7 @@ auto ContainerManagerService::GenerateCreateContainerHostConfig( + DoUsePodLevelSELinuxConfig(containerConfig, hostconfig, sandbox, error); + if (error.NotEmpty()) { + ERROR("Failed to add pod: %s security context to host config for container: %s", +- sandbox.GetName().c_str(), containerConfig.metadata().name().c_str()); ++ sandbox.GetName().c_str(), containerConfig.metadata().name().c_str()); + goto cleanup; + } + } +@@ -539,8 +539,10 @@ void ContainerManagerService::CreateContainerLogSymlink(const std::string &conta + WARN("Deleted previously existing symlink file: %s", path); + } + if (symlink(realPath, path) != 0) { +- SYSERROR("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, containerID.c_str()); +- error.Errorf("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, containerID.c_str()); ++ SYSERROR("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, ++ containerID.c_str()); ++ error.Errorf("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, ++ containerID.c_str()); + goto cleanup; + } + } else { +diff --git a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc +index 066eed5e..71918706 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc ++++ b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc +@@ -202,7 +202,7 @@ auto ImageManagerServiceImpl::status_request_from_grpc(const runtime::v1::ImageS + } + + std::unique_ptr ImageManagerServiceImpl::status_image_to_grpc(im_summary_response *response, +- Errors & /*error*/) ++ Errors & /*error*/) + { + imagetool_image_summary *image_info = response->image_summary; + if (image_info == nullptr) { +@@ -220,8 +220,8 @@ std::unique_ptr ImageManagerServiceImpl::status_image_to_grp + } + + std::unique_ptr ImageManagerServiceImpl::ImageStatus(const runtime::v1::ImageSpec +- &image, +- Errors &error) ++ &image, ++ Errors &error) + { + im_summary_request *request { nullptr }; + im_summary_response *response { nullptr }; +diff --git a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.h b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.h +index 3f13a157..1c276e06 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.h ++++ b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.h +@@ -33,7 +33,7 @@ public: + std::vector> &images, Errors &error) override; + + std::unique_ptr ImageStatus(const runtime::v1::ImageSpec &image, +- Errors &error) override; ++ Errors &error) override; + + std::string PullImage(const runtime::v1::ImageSpec &image, const runtime::v1::AuthConfig &auth, + Errors &error) override; +diff --git a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc +index 2c802900..0f6b8508 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc ++++ b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc +@@ -196,7 +196,8 @@ void PodSandboxManagerService::UpdateSandboxConfig(runtime::v1::PodSandboxConfig + // TODO: Update SecurityContext with default values + } + +-void PodSandboxManagerService::SetupSandboxFiles(const std::string &resolvPath, const runtime::v1::PodSandboxConfig &config, Errors &error) ++void PodSandboxManagerService::SetupSandboxFiles(const std::string &resolvPath, ++ const runtime::v1::PodSandboxConfig &config, Errors &error) + { + if (resolvPath.empty()) { + return; +@@ -423,7 +424,8 @@ void PodSandboxManagerService::ClearCniNetwork(const std::shared_ptr(CRIHelpers::Constants::POD_SANDBOX_KEY, sandboxKey)); + + Errors pluginErr; +- m_pluginManager->TearDownPod(config.metadata().namespace_(), config.metadata().name(), Network::DEFAULT_NETWORK_INTERFACE_NAME, ++ m_pluginManager->TearDownPod(config.metadata().namespace_(), config.metadata().name(), ++ Network::DEFAULT_NETWORK_INTERFACE_NAME, + sandbox->GetId(), stdAnnos, pluginErr); + if (pluginErr.NotEmpty()) { + WARN("TearDownPod cni network failed: %s", pluginErr.GetCMessage()); +@@ -492,7 +494,8 @@ auto PodSandboxManagerService::GetContainerListResponse(const std::string &readS + } + + ret = m_cb->container.list(list_request, &list_response); +- auto list_response_wrapper = makeUniquePtrCStructWrapper(list_response, free_container_list_response); ++ auto list_response_wrapper = makeUniquePtrCStructWrapper(list_response, ++ free_container_list_response); + if (list_response_wrapper == nullptr) { + ERROR("Failed to call list container callback"); + errors.push_back("Failed to call list container callback"); +@@ -510,7 +513,7 @@ auto PodSandboxManagerService::GetContainerListResponse(const std::string &readS + } + + return list_response_wrapper; +-} ++} + + auto PodSandboxManagerService::StopAllContainersInSandbox(const std::string &readSandboxID, + Errors &error) -> int +@@ -751,8 +754,8 @@ void PodSandboxManagerService::GetIPs(std::shared_ptr sandbox, + return; + } + +- auto settings = std::unique_ptr>(new +- CStructWrapper(network_settings, free_container_network_settings)); ++ auto settings = std::unique_ptr>(new ++ CStructWrapper(network_settings, free_container_network_settings)); + if (settings == nullptr) { + ERROR("Out of memory"); + return; +diff --git a/src/daemon/entry/cri/v1alpha/cri_container_manager_service.cc b/src/daemon/entry/cri/v1alpha/cri_container_manager_service.cc +index 9da25768..b0abdb52 100644 +--- a/src/daemon/entry/cri/v1alpha/cri_container_manager_service.cc ++++ b/src/daemon/entry/cri/v1alpha/cri_container_manager_service.cc +@@ -547,7 +547,8 @@ void ContainerManagerService::CreateContainerLogSymlink(const std::string &conta + WARN("Deleted previously existing symlink file: %s", path); + } + if (symlink(realPath, path) != 0) { +- SYSERROR("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, containerID.c_str()); ++ SYSERROR("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, ++ containerID.c_str()); + error.Errorf("failed to create symbolic link %s to the container log file %s for container %s: %s", path, + realPath, containerID.c_str()); + goto cleanup; +diff --git a/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc +index 8eff22ac..bc40cb06 100644 +--- a/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc ++++ b/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc +@@ -569,7 +569,7 @@ void PodSandboxManagerService::UpdatePodSandboxNetworkSettings(const std::string + } + + auto req = (container_update_network_settings_request *)util_common_calloc_s( +- sizeof(container_update_network_settings_request)); ++ sizeof(container_update_network_settings_request)); + if (req == nullptr) { + error.Errorf("container update network settings request: Out of memory"); + return; +diff --git a/src/daemon/entry/cri/v1alpha/cri_security_context.cc b/src/daemon/entry/cri/v1alpha/cri_security_context.cc +index 57ec3a63..2b6c42fe 100644 +--- a/src/daemon/entry/cri/v1alpha/cri_security_context.cc ++++ b/src/daemon/entry/cri/v1alpha/cri_security_context.cc +@@ -130,7 +130,8 @@ static void ModifyHostConfigscSupplementalGroups(const runtime::v1alpha2::LinuxC + } + } + +-static void ApplyMaskedPathsToHostConfig(const runtime::v1alpha2::LinuxContainerSecurityContext &sc, host_config *hostConfig, ++static void ApplyMaskedPathsToHostConfig(const runtime::v1alpha2::LinuxContainerSecurityContext &sc, ++ host_config *hostConfig, + Errors &error) + { + if (sc.masked_paths_size() <= 0) { +@@ -159,7 +160,8 @@ static void ApplyMaskedPathsToHostConfig(const runtime::v1alpha2::LinuxContainer + } + } + +-static void ApplyReadonlyPathsToHostConfig(const runtime::v1alpha2::LinuxContainerSecurityContext &sc, host_config *hostConfig, ++static void ApplyReadonlyPathsToHostConfig(const runtime::v1alpha2::LinuxContainerSecurityContext &sc, ++ host_config *hostConfig, + Errors &error) + { + if (sc.readonly_paths_size() <= 0) { +diff --git a/src/daemon/entry/cri/v1alpha/v1alpha_cri_helpers.cc b/src/daemon/entry/cri/v1alpha/v1alpha_cri_helpers.cc +index e55e46f0..b06092a7 100644 +--- a/src/daemon/entry/cri/v1alpha/v1alpha_cri_helpers.cc ++++ b/src/daemon/entry/cri/v1alpha/v1alpha_cri_helpers.cc +@@ -392,7 +392,7 @@ auto GetSecurityOpts(const commonSecurityContext &context, const char &separator + } + + std::vector selinuxOpts = CRIHelpersV1Alpha::GetSELinuxLabelOpts(context.hasSELinuxOption, +- context.selinuxOption, separator, error); ++ context.selinuxOption, separator, error); + if (error.NotEmpty()) { + error.Errorf("Failed to generate SELinuxLabel options for container %s", error.GetMessage().c_str()); + return securityOpts; +diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c +index 4b6f62de..6b6c3b75 100644 +--- a/src/daemon/executor/container_cb/execution_create.c ++++ b/src/daemon/executor/container_cb/execution_create.c +@@ -766,8 +766,8 @@ static int maintain_container_id(const container_create_request *request, char * + used_id = container_name_index_get(name); + ERROR("Name %s is in use by container %s", name, used_id); + isulad_set_error_message("Conflict. The name \"%s\" is already in use by container %s. " +- "You have to remove (or rename) that container to be able to reuse that name.", +- name, used_id); ++ "You have to remove (or rename) that container to be able to reuse that name.", ++ name, used_id); + free(used_id); + used_id = NULL; + ret = -1; +@@ -1342,7 +1342,7 @@ static int v2_spec_fill_sandbox_info(const container_sandbox_info *sandbox_info, + return 0; + } + +- if(dup_container_sandbox_info(sandbox_info, &v2_spec->sandbox_info) != 0) { ++ if (dup_container_sandbox_info(sandbox_info, &v2_spec->sandbox_info) != 0) { + ERROR("Failed to dup sandbox info"); + return -1; + } +@@ -1431,7 +1431,7 @@ int container_create_cb(const container_create_request *request, container_creat + v2_spec_fill_basic_info(id, name, image_name, image_type, container_spec, v2_spec); + + #ifdef ENABLE_CRI_API_V1 +- if(v2_spec_fill_sandbox_info(request->sandbox, v2_spec) != 0) { ++ if (v2_spec_fill_sandbox_info(request->sandbox, v2_spec) != 0) { + ERROR("Failed to fill sandbox info"); + cc = ISULAD_ERR_INPUT; + goto clean_container_root_dir; +diff --git a/src/daemon/executor/container_cb/execution_information.c b/src/daemon/executor/container_cb/execution_information.c +index 95f522c6..420f08df 100644 +--- a/src/daemon/executor/container_cb/execution_information.c ++++ b/src/daemon/executor/container_cb/execution_information.c +@@ -250,7 +250,7 @@ static int get_proxy_env(char **proxy, const char *type) + *proxy = NULL; + goto out; + } +- ++ + out: + util_free_sensitive_string(tmp_proxy); + return ret; +@@ -634,7 +634,8 @@ out: + return pid_arg; + } + +-static int get_pids(const char *name, const char *runtime, const char *rootpath, const char *statepath, pid_t **pids, size_t *pids_len, ++static int get_pids(const char *name, const char *runtime, const char *rootpath, const char *statepath, pid_t **pids, ++ size_t *pids_len, + char **pid_args) + { + int ret = 0; +diff --git a/src/daemon/modules/api/container_api.h b/src/daemon/modules/api/container_api.h +index 49849c2d..8e3cd7ac 100644 +--- a/src/daemon/modules/api/container_api.h ++++ b/src/daemon/modules/api/container_api.h +@@ -284,7 +284,8 @@ bool container_is_in_gc_progress(const char *id); + int container_module_init(); + + #ifdef ENABLE_CRI_API_V1 +-static inline bool is_sandbox_container(container_sandbox_info *sandbox) { ++static inline bool is_sandbox_container(container_sandbox_info *sandbox) ++{ + return sandbox != NULL && sandbox->is_sandbox_container; + } + #endif +diff --git a/src/daemon/modules/container/restore/restore.c b/src/daemon/modules/container/restore/restore.c +index a60b1410..fad5b071 100644 +--- a/src/daemon/modules/container/restore/restore.c ++++ b/src/daemon/modules/container/restore/restore.c +@@ -291,7 +291,8 @@ static void restore_state(container_t *cont) + } + } + if (tempret != 0) { +- WARN("Failed to restore container %s, make real status to STOPPED. Due to cannot load container with status %d", id, status); ++ WARN("Failed to restore container %s, make real status to STOPPED. Due to cannot load container with status %d", id, ++ status); + real_status.status = RUNTIME_CONTAINER_STATUS_STOPPED; + } + } +diff --git a/src/daemon/modules/network/cni_operator/libcni/invoke/libcni_exec.c b/src/daemon/modules/network/cni_operator/libcni/invoke/libcni_exec.c +index 4908565e..74d6d74a 100644 +--- a/src/daemon/modules/network/cni_operator/libcni/invoke/libcni_exec.c ++++ b/src/daemon/modules/network/cni_operator/libcni/invoke/libcni_exec.c +@@ -482,7 +482,7 @@ static int do_parse_version_info_stdout_str(int exec_ret, const cni_exec_error * + const char *stdout_str, cni_version_info **result_version) + { + __isula_auto_free char *err_msg = NULL; +- struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; ++ struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; + __isula_auto_free parser_error perr = NULL; + + if (exec_ret != 0) { +diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_api.c b/src/daemon/modules/network/cni_operator/libcni/libcni_api.c +index 7f62df78..068881be 100644 +--- a/src/daemon/modules/network/cni_operator/libcni/libcni_api.c ++++ b/src/daemon/modules/network/cni_operator/libcni/libcni_api.c +@@ -209,7 +209,7 @@ static int inject_cni_aliases(const struct runtime_conf *rt, cni_net_conf_runtim + } + + for (i = 0; i < rt->aliases_len; i++) { +- rt_config->aliases[i]= util_strdup_s(rt->aliases[i]); ++ rt_config->aliases[i] = util_strdup_s(rt->aliases[i]); + } + rt_config->aliases_len = rt->aliases_len; + return 0; +@@ -472,7 +472,7 @@ static int find_plugin_in_path(const char *plugin, const char * const *paths, si + ERROR("Invalid plugin name: %s", plugin); + return -1; + } +- ++ + for (i = 0; i < len; i++) { + if (do_check_file(plugin, paths[i], find_path) == 0) { + ret = 0; +@@ -689,7 +689,8 @@ int cni_add_network_list(const struct cni_network_list_conf *list, const struct + } + } + +- if (*pret != NULL && version_greater_than_or_equal_to((*pret)->cniversion, SUPPORT_CACHE_AND_CHECK_VERSION, &greater) != 0) { ++ if (*pret != NULL && ++ version_greater_than_or_equal_to((*pret)->cniversion, SUPPORT_CACHE_AND_CHECK_VERSION, &greater) != 0) { + return 0; + } + +@@ -867,7 +868,7 @@ static int version_network(const char *plugin_name, cni_version_info **result_ve + } + + int cni_version_network_list(const struct cni_network_list_conf *list, +- struct cni_version_info_list **result_version_list) ++ struct cni_version_info_list **result_version_list) + { + int ret = 0; + int i; +diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_api.h b/src/daemon/modules/network/cni_operator/libcni/libcni_api.h +index f94ab3f7..2f10d6e9 100644 +--- a/src/daemon/modules/network/cni_operator/libcni/libcni_api.h ++++ b/src/daemon/modules/network/cni_operator/libcni/libcni_api.h +@@ -84,7 +84,7 @@ int cni_del_network_list(const struct cni_network_list_conf *list, const struct + + int cni_check_network_list(const struct cni_network_list_conf *list, const struct runtime_conf *rc, + struct cni_opt_result **p_result); +- ++ + int cni_version_network_list(const struct cni_network_list_conf *list, + struct cni_version_info_list **result_version_list); + +diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_cached.c b/src/daemon/modules/network/cni_operator/libcni/libcni_cached.c +index 222511d6..1457c9be 100644 +--- a/src/daemon/modules/network/cni_operator/libcni/libcni_cached.c ++++ b/src/daemon/modules/network/cni_operator/libcni/libcni_cached.c +@@ -205,7 +205,7 @@ static int do_cache_insert_aliases(const struct runtime_conf *rc, cni_cached_inf + return -1; + } + +- for (i = 0; i < rc->aliases_len; i++){ ++ for (i = 0; i < rc->aliases_len; i++) { + tmp_aliases[i] = util_strdup_s(rc->aliases[i]); + } + +diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_result_type.c b/src/daemon/modules/network/cni_operator/libcni/libcni_result_type.c +index 8a0ce1dd..2365a128 100644 +--- a/src/daemon/modules/network/cni_operator/libcni/libcni_result_type.c ++++ b/src/daemon/modules/network/cni_operator/libcni/libcni_result_type.c +@@ -137,7 +137,7 @@ void free_cni_version_info_list(struct cni_version_info_list *val) + if (val == NULL) { + return; + } +- ++ + for (i = 0; i < val->result_versions_len; i++) { + free_cni_version_info(val->result_versions[i]); + val->result_versions[i] = NULL; +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index e61d1f91..859356e5 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -1495,7 +1495,7 @@ static int get_attach_socketfd(const char *attach_socket, int *socket_fd) + + if (strlen(attach_socket) >= sizeof(addr.sun_path)) { + SYSERROR("Invalid attach socket path: %s", attach_socket); +- return -1; ++ return -1; + } + + tmp_socket = socket(AF_UNIX, SOCK_STREAM, 0); +diff --git a/src/daemon/modules/runtime/shim/shim_rt_monitor.cc b/src/daemon/modules/runtime/shim/shim_rt_monitor.cc +index f5178c26..2547a206 100644 +--- a/src/daemon/modules/runtime/shim/shim_rt_monitor.cc ++++ b/src/daemon/modules/runtime/shim/shim_rt_monitor.cc +@@ -31,7 +31,7 @@ + #include "error.h" + + extern "C" { +- #include ++#include + } + + struct shim_monitor_data { +diff --git a/src/daemon/modules/runtime/shim/shim_rt_ops.c b/src/daemon/modules/runtime/shim/shim_rt_ops.c +index 56fc43c2..1bc9dc54 100644 +--- a/src/daemon/modules/runtime/shim/shim_rt_ops.c ++++ b/src/daemon/modules/runtime/shim/shim_rt_ops.c +@@ -395,7 +395,7 @@ int rt_shim_create(const char *id, const char *runtime, const rt_create_params_t + + /** + * If task address is not set, create a new shim-v2 and get the address. +- * If task address is set, use it directly. ++ * If task address is set, use it directly. + */ + if (params->task_addr == NULL || strlen(params->task_addr) == 0) { + if (shim_bin_v2_create(runtime, id, params->bundle, NULL, response, state_path) != 0) { +diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c +index 01427ddf..97f73768 100644 +--- a/src/daemon/modules/service/service_container.c ++++ b/src/daemon/modules/service/service_container.c +@@ -2197,7 +2197,8 @@ static int exec_prepare_console(const container_t *cont, const container_exec_re + return exec_prepare_vsock(cont, request, stdinfd, stdout_handler, stderr_handler, io_addresses, sync_fd, thread_id); + } + #endif +- return exec_prepare_fifo(cont, request, stdinfd, stdout_handler, stderr_handler, io_addresses, iopath, sync_fd, thread_id); ++ return exec_prepare_fifo(cont, request, stdinfd, stdout_handler, stderr_handler, io_addresses, iopath, sync_fd, ++ thread_id); + } + + static void exec_container_end(container_exec_response *response, const container_t *cont, +diff --git a/src/daemon/modules/service/vsock_io_handler.cc b/src/daemon/modules/service/vsock_io_handler.cc +index efc74bc8..2c73490a 100644 +--- a/src/daemon/modules/service/vsock_io_handler.cc ++++ b/src/daemon/modules/service/vsock_io_handler.cc +@@ -165,7 +165,7 @@ static int vsock_connect(uint32_t cid, uint32_t port) + sa.svm_cid = cid; + sa.svm_port = port; + +- if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) !=0) { ++ if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) { + SYSERROR("Failed to connect vsock socket"); + close(fd); + return -1; +@@ -314,7 +314,7 @@ void delete_daemon_vsockpaths(const char *sandbox_id, const char *vsockpaths[]) + } + } + +-enum IOFlowType{ ++enum IOFlowType { + IO_SRC = 0, + IO_DST, + IO_FLOW_INVALID, +@@ -784,7 +784,8 @@ static void *IOCopyThread(void *arg) + return NULL; + } + +-int start_vsock_io_copy(const char *exec_id, int sync_fd, bool detach, const char *fifoin, const char *fifoout, const char *fifoerr, ++int start_vsock_io_copy(const char *exec_id, int sync_fd, bool detach, const char *fifoin, const char *fifoout, ++ const char *fifoerr, + int stdin_fd, struct io_write_wrapper *stdout_handler, struct io_write_wrapper *stderr_handler, + const char *vsocks[], pthread_t *tid) + { +diff --git a/src/daemon/modules/service/vsock_io_handler.h b/src/daemon/modules/service/vsock_io_handler.h +index cc0c1dd0..8bda7711 100644 +--- a/src/daemon/modules/service/vsock_io_handler.h ++++ b/src/daemon/modules/service/vsock_io_handler.h +@@ -20,8 +20,7 @@ + #include + + #ifdef __cplusplus +-extern "C" +-{ ++extern "C" { + #endif + + bool is_vsock_path(const char *path); +@@ -35,7 +34,8 @@ int create_daemon_vsockpaths(const char *sandbox_id, uint32_t cid, bool attach_s + + void delete_daemon_vsockpaths(const char *sandbox_id, const char *vsockpaths[]); + +-int start_vsock_io_copy(const char *exec_id, int sync_fd, bool detach, const char *fifoin, const char *fifoout, const char *fifoerr, ++int start_vsock_io_copy(const char *exec_id, int sync_fd, bool detach, const char *fifoin, const char *fifoout, ++ const char *fifoerr, + int stdin_fd, struct io_write_wrapper *stdout_handler, struct io_write_wrapper *stderr_handler, + const char *vsocks[], pthread_t *tid); + +diff --git a/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.cc b/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.cc +index d6d94461..c6f97da1 100644 +--- a/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.cc ++++ b/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.cc +@@ -36,7 +36,8 @@ SandboxerAsyncWaitCall::SandboxerAsyncWaitCall(std::shared_ptr bool ++auto SandboxerAsyncWaitCall::Call(containerd::services::sandbox::v1::Controller::StubInterface &stub, ++ grpc::CompletionQueue &cq) -> bool + { + containerd::services::sandbox::v1::ControllerWaitRequest request; + m_context = std::unique_ptr(new grpc::ClientContext()); +@@ -96,10 +97,11 @@ SandboxerAsyncWaitStatus SandboxerAsyncWaitCall::HandleResponse() + ControllerExitInfo exitInfo; + SandboxerAsyncWaitStatus waitStatus = SANDBOXER_ASYNC_WAIT_STATUS_ERROR; + +- switch(m_status.error_code()) { ++ switch (m_status.error_code()) { + case grpc::StatusCode::UNAVAILABLE: + // If the status is unavailable, connection failed, we should retry +- WARN("Sandboxer controller wait rpc server unavailable, error_code: %d: %s", m_status.error_code(), m_status.error_message().c_str()); ++ WARN("Sandboxer controller wait rpc server unavailable, error_code: %d: %s", m_status.error_code(), ++ m_status.error_message().c_str()); + waitStatus = SANDBOXER_ASYNC_WAIT_STATUS_RETRY; + m_retryTimes++; + // If retried times is more than 10, we should retry every 300 seconds +@@ -128,7 +130,8 @@ SandboxerAsyncWaitStatus SandboxerAsyncWaitCall::HandleResponse() + break; + default: + // TODO: More error code should be handled +- ERROR("Sandboxer controller wait request failed, error_code: %d: %s", m_status.error_code(), m_status.error_message().c_str()); ++ ERROR("Sandboxer controller wait request failed, error_code: %d: %s", m_status.error_code(), ++ m_status.error_message().c_str()); + SandboxExitCallback(false, exitInfo); + break; + } +diff --git a/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.h b/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.h +index eb633e99..6e5a6756 100644 +--- a/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.h ++++ b/src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.h +@@ -49,16 +49,26 @@ public: + void SandboxPendingCallback(); + void SandboxReadyCallback(); + auto GetSandboxId() -> const std::string &; +- auto MarkRemove() -> void { m_remove = true; } +- auto ToRemove() -> bool { return m_remove; } +- auto ResetRetryTimes() -> void { m_retryTimes = 0; } ++ auto MarkRemove() -> void ++ { ++ m_remove = true; ++ } ++ auto ToRemove() -> bool ++ { ++ return m_remove; ++ } ++ auto ResetRetryTimes() -> void ++ { ++ m_retryTimes = 0; ++ } + + protected: + std::shared_ptr m_stub; + std::shared_ptr m_cb; + std::string m_sandboxId; + std::string m_sandboxer; +- std::unique_ptr> m_responseReader; ++ std::unique_ptr> ++ m_responseReader; + std::unique_ptr m_context; + containerd::services::sandbox::v1::ControllerWaitResponse m_response; + grpc::Status m_status; +diff --git a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.cc b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.cc +index b5dda0ed..11c2b014 100644 +--- a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.cc ++++ b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.cc +@@ -102,14 +102,16 @@ auto SandboxerClient::Create(const std::string &sandboxId, const ControllerCreat + status = m_stub->Create(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller create request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller create request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + + return true; + } + +-void SandboxerClient::StartResponseToSandboxInfo(const containerd::services::sandbox::v1::ControllerStartResponse &response, ++void SandboxerClient::StartResponseToSandboxInfo(const containerd::services::sandbox::v1::ControllerStartResponse ++ &response, + ControllerSandboxInfo &sandboxInfo) + { + sandboxInfo.id = response.sandbox_id(); +@@ -132,7 +134,8 @@ auto SandboxerClient::Start(const std::string &sandboxId, ControllerSandboxInfo + status = m_stub->Start(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller start request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller start request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + +@@ -174,7 +177,8 @@ auto SandboxerClient::InitPrepareRequest(containerd::services::sandbox::v1::Prep + return true; + } + +-auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, Errors &error) -> bool ++auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, ++ Errors &error) -> bool + { + grpc::ClientContext context; + containerd::services::sandbox::v1::PrepareRequest request; +@@ -189,7 +193,8 @@ auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrep + status = m_stub->Prepare(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller prepare request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller prepare request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + +@@ -199,7 +204,7 @@ auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrep + } + + auto SandboxerClient::Purge(const std::string &sandboxId, const std::string &containerId, +- const std::string &execId, Errors &error) -> bool ++ const std::string &execId, Errors &error) -> bool + { + grpc::ClientContext context; + containerd::services::sandbox::v1::PurgeRequest request; +@@ -214,7 +219,8 @@ auto SandboxerClient::Purge(const std::string &sandboxId, const std::string &con + status = m_stub->Purge(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller purge request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller purge request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + +@@ -237,7 +243,8 @@ auto SandboxerClient::InitUpdateResourcesRequest(containerd::services::sandbox:: + return true; + } + +-auto SandboxerClient::UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, Errors &error) -> bool ++auto SandboxerClient::UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, ++ Errors &error) -> bool + { + grpc::ClientContext context; + containerd::services::sandbox::v1::UpdateResourcesRequest request; +@@ -245,21 +252,24 @@ auto SandboxerClient::UpdateResources(const std::string &sandboxId, const Contro + grpc::Status status; + + if (!InitUpdateResourcesRequest(request, sandboxId, params)) { +- error.SetError("Failed to init update-resources request for sandboxer update-resources request, sandbox id: " + sandboxId); ++ error.SetError("Failed to init update-resources request for sandboxer update-resources request, sandbox id: " + ++ sandboxId); + return false; + } + + status = m_stub->UpdateResources(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller update resources request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller update resources request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + + return true; + } + +-void SandboxerClient::PlatformResponseToPlatformInfo(const containerd::services::sandbox::v1::ControllerPlatformResponse &response, ++void SandboxerClient::PlatformResponseToPlatformInfo(const containerd::services::sandbox::v1::ControllerPlatformResponse ++ &response, + ControllerPlatformInfo &platformInfo) + { + auto &platform = response.platform(); +@@ -268,7 +278,8 @@ void SandboxerClient::PlatformResponseToPlatformInfo(const containerd::services: + platformInfo.variant = platform.variant(); + } + +-auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, Errors &error) -> bool ++auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, ++ Errors &error) -> bool + { + grpc::ClientContext context; + containerd::services::sandbox::v1::ControllerPlatformRequest request; +@@ -281,7 +292,8 @@ auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformI + status = m_stub->Platform(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller platform request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller platform request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + +@@ -304,14 +316,16 @@ auto SandboxerClient::Stop(const std::string &sandboxId, uint32_t timeoutSecs, E + status = m_stub->Stop(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller stop request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller stop request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + + return true; + } + +-void SandboxerClient::StatusResponseToSandboxStatus(const containerd::services::sandbox::v1::ControllerStatusResponse &response, ++void SandboxerClient::StatusResponseToSandboxStatus(const containerd::services::sandbox::v1::ControllerStatusResponse ++ &response, + ControllerSandboxStatus &sandboxStatus) + { + sandboxStatus.id = response.sandbox_id(); +@@ -324,7 +338,8 @@ void SandboxerClient::StatusResponseToSandboxStatus(const containerd::services:: + sandboxStatus.extra = response.extra().value(); + } + +-auto SandboxerClient::Status(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus, Errors &error) -> bool ++auto SandboxerClient::Status(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus, ++ Errors &error) -> bool + { + grpc::ClientContext context; + containerd::services::sandbox::v1::ControllerStatusRequest request; +@@ -338,7 +353,8 @@ auto SandboxerClient::Status(const std::string &sandboxId, bool verbose, Control + status = m_stub->Status(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller status request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller status request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + +@@ -360,14 +376,16 @@ auto SandboxerClient::Shutdown(const std::string &sandboxId, Errors &error) -> b + status = m_stub->Shutdown(&context, request, &response); + if (!status.ok()) { + error.SetError(status.error_message()); +- ERROR("Sandboxer controller shutdown request failed, error_code: %d: %s", status.error_code(), status.error_message().c_str()); ++ ERROR("Sandboxer controller shutdown request failed, error_code: %d: %s", status.error_code(), ++ status.error_message().c_str()); + return false; + } + + return true; + } + +-auto SandboxerClient::Wait(std::shared_ptr cb, const std::string &sandboxId, Errors &error) -> bool ++auto SandboxerClient::Wait(std::shared_ptr cb, const std::string &sandboxId, ++ Errors &error) -> bool + { + if (m_monitor == nullptr) { + error.SetError("Cannot wait for sandbox, sandboxer client monitor is not initialized, " +diff --git a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.h b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.h +index 85e1e608..accca16b 100644 +--- a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.h ++++ b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.h +@@ -48,12 +48,14 @@ public: + + auto Platform(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, Errors &error) -> bool; + +- auto Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, Errors &error) -> bool; ++ auto Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, ++ Errors &error) -> bool; + + auto Purge(const std::string &sandboxId, const std::string &containerId, + const std::string &execId, Errors &error) -> bool; + +- auto UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, Errors &error) -> bool; ++ auto UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, ++ Errors &error) -> bool; + + auto Stop(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error) -> bool; + +diff --git a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.cc b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.cc +index 1417ee40..485a0b23 100644 +--- a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.cc ++++ b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.cc +@@ -24,7 +24,7 @@ namespace sandbox { + const int64_t DEFERRED_QUEUE_CHECK_INTERVAL = 200; // milliseconds + + SandboxerClientMonitor::SandboxerClientMonitor(std::shared_ptr channel, const std::string &sandboxer): +- m_channel(channel), m_sandboxer(sandboxer) ,m_teardown(false) ++ m_channel(channel), m_sandboxer(sandboxer), m_teardown(false) + { + m_stub = containerd::services::sandbox::v1::Controller::NewStub(m_channel); + } +@@ -46,7 +46,7 @@ auto SandboxerClientMonitor::Monitor(SandboxerAsyncWaitCall *call) -> bool + } + + // Try to monitor the call, if failed, we should delete it right way +- if (!call->Call(*m_stub ,m_cq)) { ++ if (!call->Call(*m_stub, m_cq)) { + // The failure is most likely due to the fact that the completion queue is shutdown + delete call; + return false; +@@ -114,11 +114,11 @@ void SandboxerClientMonitor::WaitForDeferredCall() + // 2. SandboxerAsyncWaitCall *: The call handled by the future + void SandboxerClientMonitor::InvokeDeferredCall(SandboxerAsyncWaitCall *call) + { +- m_futures.push_back(std::async([this, call](){ ++ m_futures.push_back(std::async([this, call]() { + // Random sleep for 50 ~ 200 milliseconds to avoid thundering herd + std::random_device rd; + std::mt19937 gen(rd()); +- std::uniform_int_distribution<> dis(DEFERRED_QUEUE_CHECK_INTERVAL/4, DEFERRED_QUEUE_CHECK_INTERVAL); ++ std::uniform_int_distribution<> dis(DEFERRED_QUEUE_CHECK_INTERVAL / 4, DEFERRED_QUEUE_CHECK_INTERVAL); + int sleepTime = dis(gen); + std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); + +@@ -186,7 +186,7 @@ void SandboxerClientMonitor::CheckCompletedFutures() + // or OnSandboxExit in the HandleResponse function. + // In this case, the OnSandboxReady will overwrite the + // status, but it is ok, because: +- // 1. If OnSandboxPending has been invoked, ++ // 1. If OnSandboxPending has been invoked, + // retry will happen pretty soon, and the + // callback will be invoked again. + // 2. If OnSandboxExit has been invoked, the caller +diff --git a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.h b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.h +index 32fca934..b5740b44 100644 +--- a/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.h ++++ b/src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_monitor.h +@@ -68,7 +68,7 @@ private: + // Vector for holding all the calls for monitoring + std::vector m_calls; + std::mutex m_callsMutex; +- // Use to indicate whether ++ // Use to indicate whether + bool m_teardown; + // Vector for holding all the retry calls + std::vector m_deferredCalls; +diff --git a/src/daemon/sandbox/controller/shim/shim_controller.cc b/src/daemon/sandbox/controller/shim/shim_controller.cc +index baddf1aa..39fcf8ea 100644 +--- a/src/daemon/sandbox/controller/shim/shim_controller.cc ++++ b/src/daemon/sandbox/controller/shim/shim_controller.cc +@@ -247,7 +247,8 @@ auto ShimController::GenerateSandboxCreateContainerRequest(const std::string &sa + return nullptr; + } + +- auto requestWrapper = PackCreateContainerRequest(sandboxId, params, hostConfigWrapper->get(), customConfigWrapper->get(), error); ++ auto requestWrapper = PackCreateContainerRequest(sandboxId, params, hostConfigWrapper->get(), ++ customConfigWrapper->get(), error); + if (requestWrapper == nullptr) { + ERROR("Failed to pack create container request"); + error.SetError("Failed to pack create container request"); +@@ -570,7 +571,7 @@ bool ShimController::UpdateNetworkSettings(const std::string &sandboxId, const s + } + + auto requestWrapper = makeUniquePtrCStructWrapper( +- free_container_update_network_settings_request); ++ free_container_update_network_settings_request); + if (requestWrapper == nullptr) { + ERROR("container update network settings request: Out of memory"); + error.Errorf("container update network settings request: Out of memory"); +@@ -583,7 +584,7 @@ bool ShimController::UpdateNetworkSettings(const std::string &sandboxId, const s + container_update_network_settings_response *response { nullptr }; + int ret = m_cb->container.update_network_settings(request, &response); + auto responseWrapper = makeUniquePtrCStructWrapper( +- response, free_container_update_network_settings_response); ++ response, free_container_update_network_settings_response); + + if (ret != 0) { + if (response != nullptr && response->errmsg != nullptr) { +diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc +index c8fd30be..b1832265 100644 +--- a/src/daemon/sandbox/sandbox.cc ++++ b/src/daemon/sandbox/sandbox.cc +@@ -942,7 +942,8 @@ auto Sandbox::ParseSandboxMetadataFile() -> std::unique_ptr>(new CStructWrapper(metadata, free_sandbox_metadata)); ++ return std::unique_ptr>(new CStructWrapper(metadata, ++ free_sandbox_metadata)); + } + + auto Sandbox::isValidMetadata(std::unique_ptr> &metadata) -> bool +diff --git a/src/daemon/sandbox/sandbox_manager.cc b/src/daemon/sandbox/sandbox_manager.cc +index 60ce97d5..d3db4fb4 100644 +--- a/src/daemon/sandbox/sandbox_manager.cc ++++ b/src/daemon/sandbox/sandbox_manager.cc +@@ -60,7 +60,8 @@ auto SandboxManager::Init(Errors &error) -> bool + return true; + } + +-auto SandboxManager::CreateSandbox(const std::string &name, RuntimeInfo &info, std::string &netNsPath, std::string &netMode, ++auto SandboxManager::CreateSandbox(const std::string &name, RuntimeInfo &info, std::string &netNsPath, ++ std::string &netMode, + const runtime::v1::PodSandboxConfig &sandboxConfig, const std::string &image, Errors &error) -> std::shared_ptr + { + std::shared_ptr sandbox; +diff --git a/src/daemon/sandbox/sandbox_manager.h b/src/daemon/sandbox/sandbox_manager.h +index 3a6ce3c9..c9ed78ed 100644 +--- a/src/daemon/sandbox/sandbox_manager.h ++++ b/src/daemon/sandbox/sandbox_manager.h +@@ -37,7 +37,8 @@ public: + + // Create meanningful sandbox instance + auto CreateSandbox(const std::string &name, RuntimeInfo &info, std::string &netNsPath, std::string &netMode, +- const runtime::v1::PodSandboxConfig &sandboxConfig, const std::string &image, Errors &error) -> std::shared_ptr; ++ const runtime::v1::PodSandboxConfig &sandboxConfig, const std::string &image, ++ Errors &error) -> std::shared_ptr; + + auto GetSandbox(const std::string &idOrName) -> std::shared_ptr; + auto DeleteSandbox(const std::string &idOrName, Errors &error) -> bool; +diff --git a/src/daemon/sandbox/sandbox_ops.cc b/src/daemon/sandbox/sandbox_ops.cc +index 2f4a46f6..005063c0 100644 +--- a/src/daemon/sandbox/sandbox_ops.cc ++++ b/src/daemon/sandbox/sandbox_ops.cc +@@ -70,7 +70,7 @@ static int do_sandbox_prepare(const container_config_v2_common_config *config, + } + + params.containerId = config->id; +- params.execId = (nullptr == exec_id) ? "" :exec_id; ++ params.execId = (nullptr == exec_id) ? "" : exec_id; + params.spec = std::move(std::unique_ptr(new std::string(oci_spec))); + + if (generate_ctrl_rootfs(params, config) != 0) { +diff --git a/src/daemon/sandbox/sandbox_ops.h b/src/daemon/sandbox/sandbox_ops.h +index bcb1e9d2..bef884fb 100644 +--- a/src/daemon/sandbox/sandbox_ops.h ++++ b/src/daemon/sandbox/sandbox_ops.h +@@ -21,8 +21,7 @@ + #include + + #ifdef __cplusplus +-extern "C" +-{ ++extern "C" { + #endif + + int sandbox_prepare_container(const container_config_v2_common_config *config, +diff --git a/src/utils/cpputils/url.cc b/src/utils/cpputils/url.cc +index baaded07..c1e5d27f 100644 +--- a/src/utils/cpputils/url.cc ++++ b/src/utils/cpputils/url.cc +@@ -122,8 +122,9 @@ int UnescapeDealWithPercentSign(size_t &i, std::string &s, const EncodeMode &mod + } + // for 3 bit hex, max value is 8 + if (mode == EncodeMode::ENCODE_HOST && s1 < 8 && +- std::string(s.begin() + static_cast(i), s.begin() + static_cast(i+3)) != percentSign) { +- ERROR("invalid URL escape %s", std::string(s.begin() + static_cast(i), s.begin() + static_cast(i + 3)).c_str()); ++ std::string(s.begin() + static_cast(i), s.begin() + static_cast(i + 3)) != percentSign) { ++ ERROR("invalid URL escape %s", std::string(s.begin() + static_cast(i), ++ s.begin() + static_cast(i + 3)).c_str()); + return -1; + } + if (mode == EncodeMode::ENCODE_ZONE) { +diff --git a/src/utils/cutils/error.h b/src/utils/cutils/error.h +index 75eae760..1ad799fa 100644 +--- a/src/utils/cutils/error.h ++++ b/src/utils/cutils/error.h +@@ -47,7 +47,7 @@ extern "C" { + /* info for detach */ \ + XX(INFO_DETACH, "Attach detach") \ + /* err max */ \ +- XX(ERR_UNKNOWN, "Unknown error") ++ XX(ERR_UNKNOWN, "Unknown error") + + #define ISULAD_ERRNO_GEN(n, s) ISULAD_##n, + typedef enum { ISULAD_ERRNO_MAP(ISULAD_ERRNO_GEN) } isulad_errno_t; +diff --git a/src/utils/cutils/map/map.h b/src/utils/cutils/map/map.h +index 45ce26b8..d569a3da 100644 +--- a/src/utils/cutils/map/map.h ++++ b/src/utils/cutils/map/map.h +@@ -20,10 +20,6 @@ + + #include "rb_tree.h" + +-#ifdef __cplusplus +-extern "C" { +-#endif +- + struct _map_t; + + #if defined(__cplusplus) || defined(c_plusplus) +@@ -113,9 +109,5 @@ void map_clear(map_t *map); + } + #endif + +-#ifdef __cplusplus +-} +-#endif +- + #endif // UTILS_CUTILS_MAP_MAP_H + +diff --git a/src/utils/tar/isulad_tar.c b/src/utils/tar/isulad_tar.c +index 2e61d823..bbe4c3b2 100644 +--- a/src/utils/tar/isulad_tar.c ++++ b/src/utils/tar/isulad_tar.c +@@ -97,7 +97,8 @@ cleanup: + return ret; + } + +-static int resolve_host_source_path(const char *path, bool follow_link, char **resolved_path, char **rebase_name, char **err) ++static int resolve_host_source_path(const char *path, bool follow_link, char **resolved_path, char **rebase_name, ++ char **err) + { + int ret = -1; + int nret = 0; +@@ -419,7 +420,8 @@ cleanup: + return ret; + } + +-static int tar_resource_rebase(const char *path, const char *rebase, const char *root_dir, struct io_read_wrapper *archive_reader, char **err) ++static int tar_resource_rebase(const char *path, const char *rebase, const char *root_dir, ++ struct io_read_wrapper *archive_reader, char **err) + { + int ret = -1; + int nret; +@@ -450,7 +452,8 @@ cleanup: + return ret; + } + +-int tar_resource(const struct archive_copy_info *info, const char *root_dir, struct io_read_wrapper *archive_reader, char **err) ++int tar_resource(const struct archive_copy_info *info, const char *root_dir, struct io_read_wrapper *archive_reader, ++ char **err) + { + if (info == NULL || root_dir == NULL || archive_reader == NULL || err == NULL) { + return -1; +diff --git a/src/utils/tar/isulad_tar.h b/src/utils/tar/isulad_tar.h +index 414bb024..401dcf50 100644 +--- a/src/utils/tar/isulad_tar.h ++++ b/src/utils/tar/isulad_tar.h +@@ -43,7 +43,8 @@ struct archive_copy_info *copy_info_source_path(const char *path, bool follow_li + char *prepare_archive_copy(const struct archive_copy_info *srcinfo, const struct archive_copy_info *dstinfo, + char **src_base, char **dst_base, char **err); + +-int tar_resource(const struct archive_copy_info *info, const char *root_dir, struct io_read_wrapper *archive_reader, char **err); ++int tar_resource(const struct archive_copy_info *info, const char *root_dir, struct io_read_wrapper *archive_reader, ++ char **err); + + int archive_copy_to(const struct io_read_wrapper *content, const struct archive_copy_info *srcinfo, + const char *dstpath, const char *root_dir, char **err); +diff --git a/test/cutils/utils_file/utils_file_ut.cc b/test/cutils/utils_file/utils_file_ut.cc +index cacfef45..b3e35744 100644 +--- a/test/cutils/utils_file/utils_file_ut.cc ++++ b/test/cutils/utils_file/utils_file_ut.cc +@@ -200,7 +200,7 @@ TEST(utils_file, test_util_proc_file_line_by_line) + ASSERT_EQ(util_proc_file_line_by_line(fp, nullptr, (void *)checked_layers), -1); + fclose(fp); + ASSERT_EQ(util_path_remove(path.c_str()), 0); +- ++ + ASSERT_EQ(util_proc_file_line_by_line(nullptr, parse_checked_layer_cb, (void *)checked_layers), -1); + } + +diff --git a/test/mocks/callback_mock.cc b/test/mocks/callback_mock.cc +index ef0e347c..153446eb 100644 +--- a/test/mocks/callback_mock.cc ++++ b/test/mocks/callback_mock.cc +@@ -25,7 +25,8 @@ void MockCallback_SetMock(std::shared_ptr mock) + g_container_callback_mock = mock; + } + +-static int service_executor_container_create(const container_create_request *request, container_create_response **response) ++static int service_executor_container_create(const container_create_request *request, ++ container_create_response **response) + { + if (g_container_callback_mock != nullptr) { + return g_container_callback_mock->ContainerCreate(request, response); +@@ -50,7 +51,8 @@ static int service_executor_container_stop(const container_stop_request *request + return 0; + } + +-static int service_executor_container_remove(const container_delete_request *request, container_delete_response **response) ++static int service_executor_container_remove(const container_delete_request *request, ++ container_delete_response **response) + { + if (g_container_callback_mock != nullptr) { + return g_container_callback_mock->ContainerRemove(request, response); +@@ -67,7 +69,7 @@ static int service_executor_container_wait(const container_wait_request *request + } + + static int service_executor_container_update_network_settings(const container_update_network_settings_request *request, +- container_update_network_settings_response **response) ++ container_update_network_settings_response **response) + { + if (g_container_callback_mock != nullptr) { + return g_container_callback_mock->ContainerUpdateNetworkSettings(request, response); +diff --git a/test/mocks/controller_stub_mock.cc b/test/mocks/controller_stub_mock.cc +index eadf3cb4..712540bb 100644 +--- a/test/mocks/controller_stub_mock.cc ++++ b/test/mocks/controller_stub_mock.cc +@@ -2,221 +2,313 @@ + + static std::shared_ptr g_controller_stub_mock = NULL; + +-std::unique_ptr NewDummyControllerStub() { +- std::unique_ptr stub(new DummyControllerStub()); +- return stub; ++std::unique_ptr NewDummyControllerStub() ++{ ++ std::unique_ptr stub(new DummyControllerStub()); ++ return stub; + } + +-void MockControllerStub_SetMock(std::shared_ptr mock) { ++void MockControllerStub_SetMock(std::shared_ptr mock) ++{ + g_controller_stub_mock = mock; + } + +-::grpc::Status DummyControllerStub::Create(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::containerd::services::sandbox::v1::ControllerCreateResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Create(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Start(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::containerd::services::sandbox::v1::ControllerStartResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Start(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Platform(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::containerd::services::sandbox::v1::ControllerPlatformResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Platform(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Prepare(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::containerd::services::sandbox::v1::PrepareResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Prepare(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Purge(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::containerd::services::sandbox::v1::PurgeResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Purge(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::UpdateResources(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::containerd::services::sandbox::v1::UpdateResourcesResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->UpdateResources(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Stop(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::containerd::services::sandbox::v1::ControllerStopResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Stop(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Wait(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::containerd::services::sandbox::v1::ControllerWaitResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Wait(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::containerd::services::sandbox::v1::ControllerStatusResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Status(context, request, response); +-} +- +-::grpc::Status DummyControllerStub::Shutdown(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::containerd::services::sandbox::v1::ControllerShutdownResponse* response) { +- if (g_controller_stub_mock == NULL) { +- return ::grpc::Status::OK; +- } +- return g_controller_stub_mock->Shutdown(context, request, response); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* DummyControllerStub::AsyncCreateRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncCreateRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* DummyControllerStub::PrepareAsyncCreateRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncCreateRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* DummyControllerStub::AsyncStartRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncStartRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* DummyControllerStub::PrepareAsyncStartRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncStartRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* DummyControllerStub::AsyncPlatformRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncPlatformRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* DummyControllerStub::PrepareAsyncPlatformRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncPlatformRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* DummyControllerStub::AsyncPrepareRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncPrepareRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* DummyControllerStub::PrepareAsyncPrepareRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncPrepareRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* DummyControllerStub::AsyncPurgeRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncPurgeRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* DummyControllerStub::PrepareAsyncPurgeRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncPurgeRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* DummyControllerStub::AsyncUpdateResourcesRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncUpdateResourcesRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* DummyControllerStub::PrepareAsyncUpdateResourcesRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncUpdateResourcesRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* DummyControllerStub::AsyncStopRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncStopRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* DummyControllerStub::PrepareAsyncStopRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncStopRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* DummyControllerStub::AsyncWaitRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncWaitRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* DummyControllerStub::PrepareAsyncWaitRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncWaitRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* DummyControllerStub::AsyncStatusRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncStatusRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* DummyControllerStub::PrepareAsyncStatusRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncStatusRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* DummyControllerStub::AsyncShutdownRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->AsyncShutdownRaw(context, request, cq); +-} +- +-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* DummyControllerStub::PrepareAsyncShutdownRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::grpc::CompletionQueue* cq) { +- if (g_controller_stub_mock == NULL) { +- return NULL; +- } +- return g_controller_stub_mock->PrepareAsyncShutdownRaw(context, request, cq); ++::grpc::Status DummyControllerStub::Create(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ++ ::containerd::services::sandbox::v1::ControllerCreateResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Create(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Start(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStartResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Start(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Platform(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ++ ::containerd::services::sandbox::v1::ControllerPlatformResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Platform(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Prepare(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PrepareRequest &request, ++ ::containerd::services::sandbox::v1::PrepareResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Prepare(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Purge(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::containerd::services::sandbox::v1::PurgeResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Purge(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::UpdateResources(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ++ ::containerd::services::sandbox::v1::UpdateResourcesResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->UpdateResources(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Stop(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStopResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Stop(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Wait(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ++ ::containerd::services::sandbox::v1::ControllerWaitResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Wait(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStatusResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Status(context, request, response); ++} ++ ++::grpc::Status DummyControllerStub::Shutdown(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ++ ::containerd::services::sandbox::v1::ControllerShutdownResponse* response) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return ::grpc::Status::OK; ++ } ++ return g_controller_stub_mock->Shutdown(context, request, response); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* ++DummyControllerStub::AsyncCreateRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncCreateRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* ++DummyControllerStub::PrepareAsyncCreateRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncCreateRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* ++DummyControllerStub::AsyncStartRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncStartRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* ++DummyControllerStub::PrepareAsyncStartRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncStartRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* ++DummyControllerStub::AsyncPlatformRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncPlatformRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* ++DummyControllerStub::PrepareAsyncPlatformRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncPlatformRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* ++DummyControllerStub::AsyncPrepareRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PrepareRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncPrepareRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* ++DummyControllerStub::PrepareAsyncPrepareRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PrepareRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncPrepareRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* ++DummyControllerStub::AsyncPurgeRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PurgeRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncPurgeRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* ++DummyControllerStub::PrepareAsyncPurgeRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PurgeRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncPurgeRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* ++DummyControllerStub::AsyncUpdateResourcesRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncUpdateResourcesRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* ++DummyControllerStub::PrepareAsyncUpdateResourcesRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncUpdateResourcesRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* ++DummyControllerStub::AsyncStopRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncStopRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* ++DummyControllerStub::PrepareAsyncStopRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncStopRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* ++DummyControllerStub::AsyncWaitRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncWaitRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* ++DummyControllerStub::PrepareAsyncWaitRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncWaitRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* ++DummyControllerStub::AsyncStatusRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncStatusRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* ++DummyControllerStub::PrepareAsyncStatusRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncStatusRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* ++DummyControllerStub::AsyncShutdownRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->AsyncShutdownRaw(context, request, cq); ++} ++ ++::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* ++DummyControllerStub::PrepareAsyncShutdownRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq) ++{ ++ if (g_controller_stub_mock == NULL) { ++ return NULL; ++ } ++ return g_controller_stub_mock->PrepareAsyncShutdownRaw(context, request, cq); + } +diff --git a/test/mocks/controller_stub_mock.h b/test/mocks/controller_stub_mock.h +index b3920bf8..85cb82bb 100644 +--- a/test/mocks/controller_stub_mock.h ++++ b/test/mocks/controller_stub_mock.h +@@ -23,73 +23,212 @@ + // MockControllerStub is a mock implementation of the Controller::StubInterface interface. + class MockControllerStub { + public: +- MOCK_METHOD3(Create, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::containerd::services::sandbox::v1::ControllerCreateResponse* response)); +- MOCK_METHOD3(Start, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::containerd::services::sandbox::v1::ControllerStartResponse* response)); +- MOCK_METHOD3(Platform, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::containerd::services::sandbox::v1::ControllerPlatformResponse* response)); +- MOCK_METHOD3(Prepare, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::containerd::services::sandbox::v1::PrepareResponse* response)); +- MOCK_METHOD3(Purge, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::containerd::services::sandbox::v1::PurgeResponse* response)); +- MOCK_METHOD3(UpdateResources, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::containerd::services::sandbox::v1::UpdateResourcesResponse* response)); +- MOCK_METHOD3(Stop, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::containerd::services::sandbox::v1::ControllerStopResponse* response)); +- MOCK_METHOD3(Wait, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::containerd::services::sandbox::v1::ControllerWaitResponse* response)); +- MOCK_METHOD3(Status, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::containerd::services::sandbox::v1::ControllerStatusResponse* response)); +- MOCK_METHOD3(Shutdown, ::grpc::Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::containerd::services::sandbox::v1::ControllerShutdownResponse* response)); +- MOCK_METHOD3(AsyncCreateRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncCreateRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncStartRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncStartRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncPlatformRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncPlatformRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncPrepareRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncPrepareRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncPurgeRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncPurgeRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncUpdateResourcesRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncUpdateResourcesRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncStopRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncStopRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncWaitRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncWaitRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncStatusRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncStatusRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(AsyncShutdownRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::grpc::CompletionQueue* cq)); +- MOCK_METHOD3(PrepareAsyncShutdownRaw, ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(Create, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ++ ::containerd::services::sandbox::v1::ControllerCreateResponse* response)); ++ MOCK_METHOD3(Start, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStartResponse* response)); ++ MOCK_METHOD3(Platform, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ++ ::containerd::services::sandbox::v1::ControllerPlatformResponse* response)); ++ MOCK_METHOD3(Prepare, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PrepareRequest &request, ++ ::containerd::services::sandbox::v1::PrepareResponse* response)); ++ MOCK_METHOD3(Purge, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::containerd::services::sandbox::v1::PurgeResponse* response)); ++ MOCK_METHOD3(UpdateResources, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ++ ::containerd::services::sandbox::v1::UpdateResourcesResponse* response)); ++ MOCK_METHOD3(Stop, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStopResponse* response)); ++ MOCK_METHOD3(Wait, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ++ ::containerd::services::sandbox::v1::ControllerWaitResponse* response)); ++ MOCK_METHOD3(Status, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStatusResponse* response)); ++ MOCK_METHOD3(Shutdown, ::grpc::Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ++ ::containerd::services::sandbox::v1::ControllerShutdownResponse* response)); ++ MOCK_METHOD3(AsyncCreateRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncCreateRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncStartRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncStartRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncPlatformRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncPlatformRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncPrepareRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncPrepareRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncPurgeRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncPurgeRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncUpdateResourcesRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncUpdateResourcesRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncStopRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncStopRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncWaitRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncWaitRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncStatusRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncStatusRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(AsyncShutdownRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ++ ::grpc::CompletionQueue* cq)); ++ MOCK_METHOD3(PrepareAsyncShutdownRaw, ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* ++ (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ++ ::grpc::CompletionQueue* cq)); + }; + + class DummyControllerStub: public containerd::services::sandbox::v1::Controller::StubInterface { + public: + DummyControllerStub() = default; + ~DummyControllerStub() = default; +- ::grpc::Status Create(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::containerd::services::sandbox::v1::ControllerCreateResponse* response) override; +- ::grpc::Status Start(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::containerd::services::sandbox::v1::ControllerStartResponse* response) override; +- ::grpc::Status Platform(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::containerd::services::sandbox::v1::ControllerPlatformResponse* response) override; +- ::grpc::Status Prepare(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::containerd::services::sandbox::v1::PrepareResponse* response) override; +- ::grpc::Status Purge(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::containerd::services::sandbox::v1::PurgeResponse* response) override; +- ::grpc::Status UpdateResources(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::containerd::services::sandbox::v1::UpdateResourcesResponse* response) override; +- ::grpc::Status Stop(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::containerd::services::sandbox::v1::ControllerStopResponse* response) override; +- ::grpc::Status Wait(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::containerd::services::sandbox::v1::ControllerWaitResponse* response) override; +- ::grpc::Status Status(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::containerd::services::sandbox::v1::ControllerStatusResponse* response) override; +- ::grpc::Status Shutdown(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::containerd::services::sandbox::v1::ControllerShutdownResponse* response) override; ++ ::grpc::Status Create(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ++ ::containerd::services::sandbox::v1::ControllerCreateResponse* response) override; ++ ::grpc::Status Start(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStartResponse* response) override; ++ ::grpc::Status Platform(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ++ ::containerd::services::sandbox::v1::ControllerPlatformResponse* response) override; ++ ::grpc::Status Prepare(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PrepareRequest &request, ++ ::containerd::services::sandbox::v1::PrepareResponse* response) override; ++ ::grpc::Status Purge(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::containerd::services::sandbox::v1::PurgeResponse* response) override; ++ ::grpc::Status UpdateResources(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ++ ::containerd::services::sandbox::v1::UpdateResourcesResponse* response) override; ++ ::grpc::Status Stop(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStopResponse* response) override; ++ ::grpc::Status Wait(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ++ ::containerd::services::sandbox::v1::ControllerWaitResponse* response) override; ++ ::grpc::Status Status(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ++ ::containerd::services::sandbox::v1::ControllerStatusResponse* response) override; ++ ::grpc::Status Shutdown(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ++ ::containerd::services::sandbox::v1::ControllerShutdownResponse* response) override; + private: +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* AsyncCreateRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* PrepareAsyncCreateRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* AsyncStartRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* PrepareAsyncStartRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* AsyncPlatformRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* PrepareAsyncPlatformRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* AsyncPrepareRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* PrepareAsyncPrepareRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* AsyncPurgeRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* PrepareAsyncPurgeRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* AsyncUpdateResourcesRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* PrepareAsyncUpdateResourcesRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* AsyncStopRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* PrepareAsyncStopRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* AsyncWaitRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* PrepareAsyncWaitRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* AsyncStatusRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* PrepareAsyncStatusRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* AsyncShutdownRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::grpc::CompletionQueue* cq) override; +- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* PrepareAsyncShutdownRaw(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest& request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* ++ AsyncCreateRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>* ++ PrepareAsyncCreateRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* ++ AsyncStartRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>* ++ PrepareAsyncStartRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* ++ AsyncPlatformRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>* ++ PrepareAsyncPlatformRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* AsyncPrepareRaw( ++ ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest &request, ++ ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* ++ PrepareAsyncPrepareRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::PrepareRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* AsyncPurgeRaw( ++ ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* PrepareAsyncPurgeRaw( ++ ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request, ++ ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* ++ AsyncUpdateResourcesRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>* ++ PrepareAsyncUpdateResourcesRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* AsyncStopRaw( ++ ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ++ ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* ++ PrepareAsyncStopRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* AsyncWaitRaw( ++ ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ++ ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* ++ PrepareAsyncWaitRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* ++ AsyncStatusRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>* ++ PrepareAsyncStatusRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* ++ AsyncShutdownRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq) override; ++ ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>* ++ PrepareAsyncShutdownRaw(::grpc::ClientContext* context, ++ const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq) override; + }; + + std::unique_ptr NewDummyControllerStub(); +diff --git a/test/mocks/grpc_async_wait_call_mock.cc b/test/mocks/grpc_async_wait_call_mock.cc +index 034cc65c..5eef1794 100644 +--- a/test/mocks/grpc_async_wait_call_mock.cc ++++ b/test/mocks/grpc_async_wait_call_mock.cc +@@ -34,7 +34,8 @@ SandboxerAsyncWaitCall::SandboxerAsyncWaitCall(std::shared_ptr bool ++auto SandboxerAsyncWaitCall::Call(containerd::services::sandbox::v1::Controller::StubInterface &stub, ++ grpc::CompletionQueue &cq) -> bool + { + if (g_sandboxer_async_wait_call_mock == NULL) { + return true; +diff --git a/test/mocks/grpc_async_wait_call_mock.h b/test/mocks/grpc_async_wait_call_mock.h +index eb890ced..c79f998e 100644 +--- a/test/mocks/grpc_async_wait_call_mock.h ++++ b/test/mocks/grpc_async_wait_call_mock.h +@@ -29,7 +29,7 @@ public: + MOCK_METHOD2(SandboxExitCallback, void(bool statusOK, const ControllerExitInfo &exitInfo)); + MOCK_METHOD0(SandboxPendingCallback, void()); + MOCK_METHOD0(SandboxReadyCallback, void()); +- MOCK_METHOD0(GetSandboxId, const std::string &()); ++ MOCK_METHOD0(GetSandboxId, const std::string & ()); + }; + + void MockSandboxerAsyncWaitCall_SetMock(std::shared_ptr mock); +diff --git a/test/mocks/grpc_sandboxer_client_mock.cc b/test/mocks/grpc_sandboxer_client_mock.cc +index 0e57cfe5..03df9048 100644 +--- a/test/mocks/grpc_sandboxer_client_mock.cc ++++ b/test/mocks/grpc_sandboxer_client_mock.cc +@@ -58,7 +58,8 @@ auto SandboxerClient::Start(const std::string &sandboxId, ControllerSandboxInfo + return g_sandboxer_client_mock->Start(sandboxId, sandboxInfo, error); + } + +-auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, Errors &error) -> bool ++auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, ++ Errors &error) -> bool + { + if (g_sandboxer_client_mock == NULL) { + return true; +@@ -66,7 +67,8 @@ auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformI + return g_sandboxer_client_mock->Platform(sandboxId, platformInfo, error); + } + +-auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, Errors &error) -> bool ++auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, ++ Errors &error) -> bool + { + if (g_sandboxer_client_mock == NULL) { + return true; +@@ -83,7 +85,8 @@ auto SandboxerClient::Purge(const std::string &sandboxId, const std::string &con + return g_sandboxer_client_mock->Purge(sandboxId, containerId, execId, error); + } + +-auto SandboxerClient::UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, Errors &error) -> bool ++auto SandboxerClient::UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, ++ Errors &error) -> bool + { + if (g_sandboxer_client_mock == NULL) { + return true; +@@ -99,7 +102,8 @@ auto SandboxerClient::Stop(const std::string &sandboxId, uint32_t timeoutSecs, E + return g_sandboxer_client_mock->Stop(sandboxId, timeoutSecs, error); + } + +-auto SandboxerClient::Wait(std::shared_ptr cb, const std::string &sandboxId, Errors &error) -> bool ++auto SandboxerClient::Wait(std::shared_ptr cb, const std::string &sandboxId, ++ Errors &error) -> bool + { + if (g_sandboxer_client_mock == NULL) { + return true; +@@ -107,7 +111,8 @@ auto SandboxerClient::Wait(std::shared_ptr cb, const std: + return g_sandboxer_client_mock->Wait(cb, sandboxId, error); + } + +-auto SandboxerClient::Status(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus, Errors &error) -> bool ++auto SandboxerClient::Status(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus, ++ Errors &error) -> bool + { + if (g_sandboxer_client_mock == NULL) { + return true; +diff --git a/test/mocks/grpc_sandboxer_client_mock.h b/test/mocks/grpc_sandboxer_client_mock.h +index a3dcd690..ac06462a 100644 +--- a/test/mocks/grpc_sandboxer_client_mock.h ++++ b/test/mocks/grpc_sandboxer_client_mock.h +@@ -28,12 +28,16 @@ public: + MOCK_METHOD3(Create, bool(const std::string &sandboxId, const ControllerCreateParams ¶ms, Errors &error)); + MOCK_METHOD3(Start, bool(const std::string &sandboxId, ControllerSandboxInfo &sandboxInfo, Errors &error)); + MOCK_METHOD3(Platform, bool(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, Errors &error)); +- MOCK_METHOD4(Prepare, bool(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, Errors &error)); +- MOCK_METHOD4(Purge, bool(const std::string &sandboxId, const std::string &containerId, const std::string &execId, Errors &error)); +- MOCK_METHOD3(UpdateResources, bool(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, Errors &error)); ++ MOCK_METHOD4(Prepare, bool(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle, ++ Errors &error)); ++ MOCK_METHOD4(Purge, bool(const std::string &sandboxId, const std::string &containerId, const std::string &execId, ++ Errors &error)); ++ MOCK_METHOD3(UpdateResources, bool(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms, ++ Errors &error)); + MOCK_METHOD3(Stop, bool(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error)); + MOCK_METHOD3(Wait, bool(std::shared_ptr cb, const std::string &sandboxId, Errors &error)); +- MOCK_METHOD4(Status, bool(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus, Errors &error)); ++ MOCK_METHOD4(Status, bool(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus, ++ Errors &error)); + MOCK_METHOD2(Shutdown, bool(const std::string &sandboxId, Errors &error)); + }; + +diff --git a/test/mocks/grpc_sandboxer_monitor_mock.cc b/test/mocks/grpc_sandboxer_monitor_mock.cc +index e307e0ae..b3ddda87 100644 +--- a/test/mocks/grpc_sandboxer_monitor_mock.cc ++++ b/test/mocks/grpc_sandboxer_monitor_mock.cc +@@ -19,7 +19,7 @@ static std::shared_ptr g_sandboxer_client_monitor_mo + + + SandboxerClientMonitor::SandboxerClientMonitor(std::shared_ptr channel, const std::string &sandboxer): +- m_channel(channel), m_sandboxer(sandboxer) ,m_teardown(false) {} ++ m_channel(channel), m_sandboxer(sandboxer), m_teardown(false) {} + + void SandboxerClientMonitor::Start() + { +diff --git a/test/mocks/isulad_config_mock.h b/test/mocks/isulad_config_mock.h +index 6a92fc13..6c6ff7f1 100644 +--- a/test/mocks/isulad_config_mock.h ++++ b/test/mocks/isulad_config_mock.h +@@ -40,7 +40,7 @@ public: + MOCK_METHOD0(InitIsuladDaemonConstants, int (void)); + MOCK_METHOD0(GetIsuladDaemonConstants, isulad_daemon_constants * (void)); + MOCK_METHOD0(ConfGetIsuladUsernsRemap, char *(void)); +- MOCK_METHOD0(ConfGetServerConf, struct service_arguments *(void)); ++ MOCK_METHOD0(ConfGetServerConf, struct service_arguments * (void)); + MOCK_METHOD0(ConfGetSandboxRootPath, char *(void)); + MOCK_METHOD0(ConfGetSandboxStatePath, char *(void)); + }; +diff --git a/test/mocks/sandbox_mock.cc b/test/mocks/sandbox_mock.cc +index e5aefdda..9db57a93 100644 +--- a/test/mocks/sandbox_mock.cc ++++ b/test/mocks/sandbox_mock.cc +@@ -77,7 +77,7 @@ const std::string &Sandbox::GetRuntimeHandle() const + return defaultStr; + } + +-const runtime::v1::PodSandboxConfig & Sandbox::GetSandboxConfig() const ++const runtime::v1::PodSandboxConfig &Sandbox::GetSandboxConfig() const + { + if (g_sandbox_mock != nullptr) { + return g_sandbox_mock->GetSandboxConfig(); +diff --git a/test/mocks/sandbox_mock.h b/test/mocks/sandbox_mock.h +index 341042e9..98f40ad2 100644 +--- a/test/mocks/sandbox_mock.h ++++ b/test/mocks/sandbox_mock.h +@@ -31,7 +31,7 @@ public: + MOCK_METHOD0(GetName, const std::string & ()); + MOCK_METHOD0(GetSandboxer, const std::string & ()); + MOCK_METHOD0(GetRuntimeHandle, const std::string & ()); +- MOCK_METHOD0(GetSandboxConfig, const runtime::v1::PodSandboxConfig &()); ++ MOCK_METHOD0(GetSandboxConfig, const runtime::v1::PodSandboxConfig & ()); + MOCK_METHOD0(GetMutableSandboxConfig, std::shared_ptr()); + MOCK_METHOD0(GetRootDir, const std::string & ()); + MOCK_METHOD0(GetStateDir, std::string & ()); +diff --git a/test/mocks/service_container_api_mock.h b/test/mocks/service_container_api_mock.h +index 350a2fff..9a39f483 100644 +--- a/test/mocks/service_container_api_mock.h ++++ b/test/mocks/service_container_api_mock.h +@@ -23,7 +23,7 @@ + + class MockServiceContainerApi { + public: +- MOCK_METHOD3(InspectContainer, container_inspect *(const char *id, int timeout, bool with_host_config)); ++ MOCK_METHOD3(InspectContainer, container_inspect * (const char *id, int timeout, bool with_host_config)); + }; + + void MockServiceContainerApi_SetMock(std::shared_ptr mock); +diff --git a/test/mocks/shim_controller_mock.cc b/test/mocks/shim_controller_mock.cc +index 88694dbe..e0ffc563 100644 +--- a/test/mocks/shim_controller_mock.cc ++++ b/test/mocks/shim_controller_mock.cc +@@ -117,7 +117,8 @@ bool ShimController::Wait(std::shared_ptr cb, const std:: + return true; + } + +-std::unique_ptr ShimController::Status(const std::string &sandboxId, bool verbose, Errors &error) ++std::unique_ptr ShimController::Status(const std::string &sandboxId, bool verbose, ++ Errors &error) + { + if (g_shim_controller_mock != nullptr) { + return g_shim_controller_mock->Status(sandboxId, verbose, error); +@@ -133,7 +134,8 @@ bool ShimController::Shutdown(const std::string &sandboxId, Errors &error) + return true; + } + +-bool ShimController::UpdateNetworkSettings(const std::string &sandboxId, const std::string &networkSettings, Errors &error) ++bool ShimController::UpdateNetworkSettings(const std::string &sandboxId, const std::string &networkSettings, ++ Errors &error) + { + if (g_shim_controller_mock != nullptr) { + return g_shim_controller_mock->UpdateNetworkSettings(sandboxId, networkSettings, error); +diff --git a/test/mocks/shim_controller_mock.h b/test/mocks/shim_controller_mock.h +index 3be05246..6d0de591 100644 +--- a/test/mocks/shim_controller_mock.h ++++ b/test/mocks/shim_controller_mock.h +@@ -39,15 +39,17 @@ public: + const ControllerPrepareParams ¶ms, + Errors &error)); + MOCK_METHOD4(Purge, bool(const std::string &sandboxId, const std::string &containerId, +- const std::string &execId, Errors &error)); ++ const std::string &execId, Errors &error)); + MOCK_METHOD3(UpdateResources, bool(const std::string &sandboxId, + const ControllerUpdateResourcesParams ¶ms, + Errors &error)); + MOCK_METHOD3(Stop, bool(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error)); + MOCK_METHOD3(Wait, bool(std::shared_ptr cb, const std::string &sandboxId, Errors &error)); +- MOCK_METHOD3(Status, std::unique_ptr(const std::string &sandboxId, bool verbose, Errors &error)); ++ MOCK_METHOD3(Status, std::unique_ptr(const std::string &sandboxId, bool verbose, ++ Errors &error)); + MOCK_METHOD2(Shutdown, bool(const std::string &sandboxId, Errors &error)); +- MOCK_METHOD3(UpdateNetworkSettings, bool(const std::string &sandboxId, const std::string &networkSettings, Errors &error)); ++ MOCK_METHOD3(UpdateNetworkSettings, bool(const std::string &sandboxId, const std::string &networkSettings, ++ Errors &error)); + }; + + void MockShimController_SetMock(std::shared_ptr mock); +diff --git a/test/network/cni_operate/cni_operate_ut.cc b/test/network/cni_operate/cni_operate_ut.cc +index 4194641b..f61fee57 100644 +--- a/test/network/cni_operate/cni_operate_ut.cc ++++ b/test/network/cni_operate/cni_operate_ut.cc +@@ -47,28 +47,28 @@ using namespace std; + + extern "C" { + DECLARE_WRAPPER(cni_cache_read, cni_cached_info *, +- (const char *cache_dir, const char *net_name, const struct runtime_conf *rc)); ++ (const char *cache_dir, const char *net_name, const struct runtime_conf *rc)); + DEFINE_WRAPPER(cni_cache_read, cni_cached_info *, +- (const char *cache_dir, const char *net_name, const struct runtime_conf *rc), +- (cache_dir, net_name, rc)); ++ (const char *cache_dir, const char *net_name, const struct runtime_conf *rc), ++ (cache_dir, net_name, rc)); + +- DECLARE_WRAPPER(cni_check_network_list, int, +- (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result)); ++ DECLARE_WRAPPER(cni_check_network_list, int, ++ (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result)); + DEFINE_WRAPPER(cni_check_network_list, int, +- (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result), +- (list, rc, p_result)); ++ (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result), ++ (list, rc, p_result)); + +- DECLARE_WRAPPER(util_atomic_write_file, int, +- (const char *fname, const char *content, size_t content_len, mode_t mode, bool sync)); ++ DECLARE_WRAPPER(util_atomic_write_file, int, ++ (const char *fname, const char *content, size_t content_len, mode_t mode, bool sync)); + DEFINE_WRAPPER(util_atomic_write_file, int, +- (const char *fname, const char *content, size_t content_len, mode_t mode, bool sync), +- (fname, content, content_len, mode, sync)); +- +- DECLARE_WRAPPER(cni_del_network_list, int, +- (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result)); ++ (const char *fname, const char *content, size_t content_len, mode_t mode, bool sync), ++ (fname, content, content_len, mode, sync)); ++ ++ DECLARE_WRAPPER(cni_del_network_list, int, ++ (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result)); + DEFINE_WRAPPER(cni_del_network_list, int, +- (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result), +- (list, rc, p_result)); ++ (const struct cni_network_list_conf *list, const struct runtime_conf *rc, struct cni_opt_result **p_result), ++ (list, rc, p_result)); + + DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size)); + DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size)); +@@ -90,19 +90,19 @@ public: + m_list.bytes = cni_net_conf_list_generate_json(m_list.list, &ctx, &jerr); + m_aliases_array = invoke_network_get_aliases_from_cached_info(m_info); + m_manager = { +- .id = (char *)"827bdd4b0b4e28d24dbaf3c563687ff6ffd23cd8fda38cadf818ac324fe5de3e", ++ .id = (char *)"827bdd4b0b4e28d24dbaf3c563687ff6ffd23cd8fda38cadf818ac324fe5de3e", + .netns_path = (char *)"/var/run/netns/isulacni-7dbc2c7d85279d5a", + .ifname = (char *)"eth0" + }; + m_manager.annotations = map_new(MAP_STR_STR, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC); +- ++ + ctx = { OPT_PARSE_STRICT, 0 }; + aliases_json = cni_array_of_strings_container_generate_json(m_aliases_array, &ctx, &jerr); + if (aliases_json == nullptr) { + printf("Parse aliases_json failed: %s", jerr); + } + (void)map_replace(m_manager.annotations, (void *)aliases_str, (void *)aliases_json); +- ++ + free(aliases_json); + } + +@@ -140,7 +140,7 @@ TEST_F(CniOperateUnitTest, test_check_network_plane) + MOCK_CLEAR(calloc); + } + +- { ++ { + // cached info will be free in check_network_plane + MOCK_SET(cni_cache_read, invoke_network_get_cached_info((char *)CNI_CACHE_INFO)); + MOCK_SET(cni_check_network_list, 0); +diff --git a/test/network/network_mock.cc b/test/network/network_mock.cc +index 1fa1cc2e..27422b5f 100644 +--- a/test/network/network_mock.cc ++++ b/test/network/network_mock.cc +@@ -64,7 +64,7 @@ cni_array_of_strings_container *invoke_network_get_aliases_from_cached_info(cni_ + aliases_array->items = (char **)isula_smart_calloc_s(sizeof(char *), info->aliases_len); + EXPECT_THAT(aliases_array->items, testing::NotNull()) << "Out of memory" << std::endl; + for (size_t i = 0; i < info->aliases_len; i++) { +- aliases_array->items[i]= util_strdup_s(info->aliases[i]); ++ aliases_array->items[i] = util_strdup_s(info->aliases[i]); + aliases_array->len += 1; + } + +diff --git a/test/sandbox/controller/controller_common.cc b/test/sandbox/controller/controller_common.cc +index ed9c84d7..5f870c34 100644 +--- a/test/sandbox/controller/controller_common.cc ++++ b/test/sandbox/controller/controller_common.cc +@@ -15,7 +15,8 @@ + + #include "controller_common.h" + +-std::unique_ptr CreateTestMountInfo() { ++std::unique_ptr CreateTestMountInfo() ++{ + std::unique_ptr mountInfo(new sandbox::ControllerMountInfo()); + mountInfo->source = "/rootfs"; + mountInfo->destination = "/rootfs"; +@@ -23,7 +24,8 @@ std::unique_ptr CreateTestMountInfo() { + return mountInfo; + } + +-std::unique_ptr CreateTestCreateParams() { ++std::unique_ptr CreateTestCreateParams() ++{ + std::unique_ptr params(new sandbox::ControllerCreateParams()); + params->config = std::make_shared(); + params->netNSPath = "/proc/1/ns/net"; +@@ -31,7 +33,8 @@ std::unique_ptr CreateTestCreateParams() { + return params; + } + +-std::unique_ptr CreateTestStreamInfo() { ++std::unique_ptr CreateTestStreamInfo() ++{ + std::unique_ptr streamInfo(new sandbox::ControllerStreamInfo()); + streamInfo->stdin = "/tmp/stdin"; + streamInfo->stdout = "/tmp/stdout"; +@@ -40,7 +43,8 @@ std::unique_ptr CreateTestStreamInfo() { + return streamInfo; + } + +-std::unique_ptr CreateTestPrepareParams() { ++std::unique_ptr CreateTestPrepareParams() ++{ + std::unique_ptr params(new sandbox::ControllerPrepareParams()); + params->containerId = DUMMY_CONTAINER_ID; + params->execId = DUMMY_EXEC_ID; +@@ -51,7 +55,9 @@ std::unique_ptr CreateTestPrepareParams() { + return params; + } + +-std::unique_ptr CreateTestUpdateResourcesParams(google::protobuf::Map &annotations) { ++std::unique_ptr CreateTestUpdateResourcesParams( ++ google::protobuf::Map &annotations) ++{ + std::unique_ptr resources(new std::string("{cpu: 12}")); + std::unique_ptr params( + new sandbox::ControllerUpdateResourcesParams{DUMMY_SANDBOX_ID, std::move(resources), annotations} +diff --git a/test/sandbox/controller/controller_common.h b/test/sandbox/controller/controller_common.h +index e5a22e34..c01ae83c 100644 +--- a/test/sandbox/controller/controller_common.h ++++ b/test/sandbox/controller/controller_common.h +@@ -33,6 +33,7 @@ std::unique_ptr CreateTestStreamInfo(); + + std::unique_ptr CreateTestPrepareParams(); + +-std::unique_ptr CreateTestUpdateResourcesParams(google::protobuf::Map &annotations); ++std::unique_ptr CreateTestUpdateResourcesParams( ++ google::protobuf::Map &annotations); + + #endif // _ISULAD_TEST_SANDBOX_CONTROLLER_CONTROLLER_COMMON_H +\ No newline at end of file +diff --git a/test/sandbox/controller/manager/controller_manager_ut.cc b/test/sandbox/controller/manager/controller_manager_ut.cc +index 8467fbd4..705baaca 100644 +--- a/test/sandbox/controller/manager/controller_manager_ut.cc ++++ b/test/sandbox/controller/manager/controller_manager_ut.cc +@@ -33,11 +33,13 @@ public: + + class ControllerManagerTest : public testing::Test { + protected: +- void SetUp() override { ++ void SetUp() override ++ { + MockIsuladConf_SetMock(isuladConfMock.get()); + } + +- void TearDown() override { ++ void TearDown() override ++ { + MockIsuladConf_SetMock(nullptr); + static_cast(ControllerManagerWrapper::GetInstance())->Clear(); + } +@@ -45,7 +47,8 @@ protected: + std::unique_ptr isuladConfMock = std::unique_ptr(new MockIsuladConf()); + }; + +-static struct service_arguments *CreateDummyServerConf(const std::string &conf) { ++static struct service_arguments *CreateDummyServerConf(const std::string &conf) ++{ + parser_error err = nullptr; + struct service_arguments *args = (struct service_arguments *)util_common_calloc_s(sizeof(struct service_arguments)); + if (args == nullptr) { +@@ -59,7 +62,8 @@ static struct service_arguments *CreateDummyServerConf(const std::string &conf) + return args; + } + +-static void FreeDummyServerconf(struct service_arguments *args) { ++static void FreeDummyServerconf(struct service_arguments *args) ++{ + if (args != nullptr) { + free_isulad_daemon_configs(args->json_confs); + free(args); +@@ -70,7 +74,8 @@ static void FreeDummyServerconf(struct service_arguments *args) { + TEST_F(ControllerManagerTest, InitTestSucceed) + { + Errors err; +- const std::string daemonConfig = "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"vmm\",\"address\": \"/run/vmm-sandboxer.sock\"}}}"; ++ const std::string daemonConfig = ++ "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"vmm\",\"address\": \"/run/vmm-sandboxer.sock\"}}}"; + struct service_arguments *args = CreateDummyServerConf(daemonConfig); + ASSERT_NE(args, nullptr); + EXPECT_CALL(*isuladConfMock, ConfGetServerConf()).Times(1).WillOnce(testing::Return(args)); +@@ -130,7 +135,8 @@ TEST_F(ControllerManagerTest, InitTestSucceedWithNullConfig) + TEST_F(ControllerManagerTest, InitTestFailedWithDupShimConfig) + { + Errors err; +- const std::string daemonConfig = "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"shim\",\"address\": \"/run/vmm-sandboxer.sock\"}}}"; ++ const std::string daemonConfig = ++ "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"shim\",\"address\": \"/run/vmm-sandboxer.sock\"}}}"; + struct service_arguments *args = CreateDummyServerConf(daemonConfig); + ASSERT_NE(args, nullptr); + EXPECT_CALL(*isuladConfMock, ConfGetServerConf()).Times(1).WillOnce(testing::Return(args)); +@@ -148,7 +154,8 @@ TEST_F(ControllerManagerTest, InitTestFailedWithDupShimConfig) + TEST_F(ControllerManagerTest, InitTestFailedWithDupKuasarConfig) + { + Errors err; +- const std::string daemonConfig = "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"vmm1\",\"address\": \"/run/vmm1-sandboxer.sock\"},\"kuasar\": {\"name\": \"vmm2\",\"address\": \"/run/vmm2-sandboxer.sock\"}}}"; ++ const std::string daemonConfig = ++ "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"vmm1\",\"address\": \"/run/vmm1-sandboxer.sock\"},\"kuasar\": {\"name\": \"vmm2\",\"address\": \"/run/vmm2-sandboxer.sock\"}}}"; + struct service_arguments *args = CreateDummyServerConf(daemonConfig); + ASSERT_NE(args, nullptr); + EXPECT_CALL(*isuladConfMock, ConfGetServerConf()).Times(1).WillOnce(testing::Return(args)); +@@ -162,7 +169,8 @@ TEST_F(ControllerManagerTest, InitTestFailedWithDupKuasarConfig) + TEST_F(ControllerManagerTest, InitTestFailedWithDupNameConfig) + { + Errors err; +- const std::string daemonConfig = "{\"cri-sandboxers\": {\"kuasar1\": {\"name\": \"vmm\",\"address\": \"/run/vmm1-sandboxer.sock\"},\"kuasar2\": {\"name\": \"vmm\",\"address\": \"/run/vmm2-sandboxer.sock\"}}}"; ++ const std::string daemonConfig = ++ "{\"cri-sandboxers\": {\"kuasar1\": {\"name\": \"vmm\",\"address\": \"/run/vmm1-sandboxer.sock\"},\"kuasar2\": {\"name\": \"vmm\",\"address\": \"/run/vmm2-sandboxer.sock\"}}}"; + struct service_arguments *args = CreateDummyServerConf(daemonConfig); + ASSERT_NE(args, nullptr); + EXPECT_CALL(*isuladConfMock, ConfGetServerConf()).Times(1).WillOnce(testing::Return(args)); +@@ -176,7 +184,8 @@ TEST_F(ControllerManagerTest, InitTestFailedWithDupNameConfig) + TEST_F(ControllerManagerTest, InitTestFailedWithDupInit) + { + Errors err; +- const std::string daemonConfig = "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"vmm\",\"address\": \"/run/vmm-sandboxer.sock\"}}}"; ++ const std::string daemonConfig = ++ "{\"cri-sandboxers\": {\"kuasar\": {\"name\": \"vmm\",\"address\": \"/run/vmm-sandboxer.sock\"}}}"; + struct service_arguments *args = CreateDummyServerConf(daemonConfig); + ASSERT_NE(args, nullptr); + EXPECT_CALL(*isuladConfMock, ConfGetServerConf()).Times(2).WillRepeatedly(testing::Return(args)); +diff --git a/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc b/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc +index 0596771a..1a58344c 100644 +--- a/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc ++++ b/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc +@@ -35,17 +35,20 @@ public: + + class AsyncWaitCallTest : public testing::Test { + protected: +- void SetUp() override { ++ void SetUp() override ++ { + m_sandboxId = "8040f13d54889ad4cd"; + m_sandboxer = "test_sandboxer"; + m_callback = std::shared_ptr(new DummyCallback()); +- m_call = std::unique_ptr(new sandbox::SandboxerAsyncWaitCall(m_callback, m_sandboxId, m_sandboxer)); ++ m_call = std::unique_ptr(new sandbox::SandboxerAsyncWaitCall(m_callback, m_sandboxId, ++ m_sandboxer)); + m_stub = std::unique_ptr(NewDummyControllerStub()); + m_stub_mock = std::make_shared(); + MockControllerStub_SetMock(m_stub_mock); + } + +- void TearDown() override { ++ void TearDown() override ++ { + MockControllerStub_SetMock(nullptr); + } + +diff --git a/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h b/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h +index 3a12d042..7e98d844 100644 +--- a/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h ++++ b/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h +@@ -21,7 +21,8 @@ + + #include "controller.h" + +-class DummyClientAsyncResponseReader: public grpc::ClientAsyncResponseReaderInterface { ++class DummyClientAsyncResponseReader: public ++ grpc::ClientAsyncResponseReaderInterface { + public: + DummyClientAsyncResponseReader() = default; + ~DummyClientAsyncResponseReader() = default; +@@ -30,26 +31,32 @@ public: + + void ReadInitialMetadata(void *tag) override {} + +- void Finish(containerd::services::sandbox::v1::ControllerWaitResponse *response, grpc::Status *status, void *tag) override { ++ void Finish(containerd::services::sandbox::v1::ControllerWaitResponse *response, grpc::Status *status, ++ void *tag) override ++ { + response->set_exit_status(m_exitStatus); + response->mutable_exited_at()->CopyFrom(m_exitedAt); + *status = m_status; + m_tag = tag; + } + +- void SetExitAt(const google::protobuf::Timestamp &exitAt) { ++ void SetExitAt(const google::protobuf::Timestamp &exitAt) ++ { + m_exitedAt = exitAt; + } + +- void SetExitStatus(uint32_t status) { ++ void SetExitStatus(uint32_t status) ++ { + m_exitStatus = status; + } + +- void SetStatus(grpc::Status status) { ++ void SetStatus(grpc::Status status) ++ { + m_status = status; + } + +- void *GetTag() { ++ void *GetTag() ++ { + return m_tag; + } + +@@ -70,28 +77,39 @@ enum AsyncWaitCallStatus { + + class DummyCallback: public sandbox::SandboxStatusCallback { + public: +- DummyCallback() { ++ DummyCallback() ++ { + m_status = ASYNC_WAIT_CALL_STATUS_UNKNOWN; + } + ~DummyCallback() = default; + +- void OnSandboxReady() override { m_status = ASYNC_WAIT_CALL_STATUS_READY; } +- void OnSandboxPending() override { m_status = ASYNC_WAIT_CALL_STATUS_PENDING; } +- void OnSandboxExit(const sandbox::ControllerExitInfo &exitInfo) override { ++ void OnSandboxReady() override ++ { ++ m_status = ASYNC_WAIT_CALL_STATUS_READY; ++ } ++ void OnSandboxPending() override ++ { ++ m_status = ASYNC_WAIT_CALL_STATUS_PENDING; ++ } ++ void OnSandboxExit(const sandbox::ControllerExitInfo &exitInfo) override ++ { + m_status = ASYNC_WAIT_CALL_STATUS_EXIT; + m_exitStatus = exitInfo.exitStatus; + m_exitedAt = exitInfo.exitedAt; + } + +- AsyncWaitCallStatus GetStatus() { ++ AsyncWaitCallStatus GetStatus() ++ { + return m_status; + } + +- uint32_t GetExitStatus() { ++ uint32_t GetExitStatus() ++ { + return m_exitStatus; + } + +- uint64_t GetExitedAt() { ++ uint64_t GetExitedAt() ++ { + return m_exitedAt; + } + private: +diff --git a/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc b/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc +index 0804b38b..b0f4758f 100644 +--- a/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc ++++ b/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc +@@ -21,7 +21,8 @@ + + class SandboxerClientWrapper : public sandbox::SandboxerClient { + public: +- SandboxerClientWrapper(const std::string &sandboxer, const std::string &address) : SandboxerClient(sandboxer, address) { ++ SandboxerClientWrapper(const std::string &sandboxer, const std::string &address) : SandboxerClient(sandboxer, address) ++ { + m_stub = NewDummyControllerStub(); + } + +@@ -30,7 +31,8 @@ public: + + class ControllerSandboxerClientTest : public testing::Test { + protected: +- void SetUp() override { ++ void SetUp() override ++ { + m_sandboxer = "sandboxer"; + m_address = "/tmp/sandboxer.sock"; + +@@ -39,7 +41,8 @@ protected: + MockControllerStub_SetMock(m_stub); + } + +- void TearDown() override { ++ void TearDown() override ++ { + MockControllerStub_SetMock(nullptr); + } + +@@ -50,18 +53,21 @@ protected: + std::shared_ptr m_sandboxerClient; + }; + +-static std::unique_ptr CreateTestGrpcStartResponse() { +- std::unique_ptr response(new containerd::services::sandbox::v1::ControllerStartResponse()); ++static std::unique_ptr CreateTestGrpcStartResponse() ++{ ++ std::unique_ptr response( ++ new containerd::services::sandbox::v1::ControllerStartResponse()); + response->set_sandbox_id(DUMMY_SANDBOX_ID); + response->set_pid(1); +- response->mutable_created_at()->set_seconds(DUMMY_CREATE_AT/SECOND_TO_NANOS); +- response->mutable_created_at()->set_nanos(DUMMY_CREATE_AT%SECOND_TO_NANOS); ++ response->mutable_created_at()->set_seconds(DUMMY_CREATE_AT / SECOND_TO_NANOS); ++ response->mutable_created_at()->set_nanos(DUMMY_CREATE_AT % SECOND_TO_NANOS); + response->mutable_labels()->insert({"label1", "value1"}); + return response; + } + + // Create platform response for test. +-static std::unique_ptr CreateTestPlatformResponse() { ++static std::unique_ptr CreateTestPlatformResponse() ++{ + std::unique_ptr response( + new containerd::services::sandbox::v1::ControllerPlatformResponse() + ); +@@ -72,7 +78,8 @@ static std::unique_ptr CreateTestStatusResponse() { ++static std::unique_ptr CreateTestStatusResponse() ++{ + std::unique_ptr response( + new containerd::services::sandbox::v1::ControllerStatusResponse() + ); +@@ -80,29 +87,32 @@ static std::unique_ptrset_state("running"); + response->set_pid(1); + response->set_task_address(DUMMY_TASK_ADDRESS); +- response->mutable_created_at()->set_seconds(DUMMY_CREATE_AT/SECOND_TO_NANOS); +- response->mutable_created_at()->set_nanos(DUMMY_CREATE_AT%SECOND_TO_NANOS); +- response->mutable_exited_at()->set_seconds(DUMMY_CREATE_AT/SECOND_TO_NANOS); +- response->mutable_exited_at()->set_nanos(DUMMY_CREATE_AT%SECOND_TO_NANOS); ++ response->mutable_created_at()->set_seconds(DUMMY_CREATE_AT / SECOND_TO_NANOS); ++ response->mutable_created_at()->set_nanos(DUMMY_CREATE_AT % SECOND_TO_NANOS); ++ response->mutable_exited_at()->set_seconds(DUMMY_CREATE_AT / SECOND_TO_NANOS); ++ response->mutable_exited_at()->set_nanos(DUMMY_CREATE_AT % SECOND_TO_NANOS); + response->mutable_info()->insert({"info1", "value1"}); + response->mutable_extra()->set_value("{extra: test}"); + return response; + } + + /************* Unit tests for Create *************/ +-TEST_F(ControllerSandboxerClientTest, CreateTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, CreateTestSucceed) ++{ + Errors err; + std::unique_ptr params = CreateTestCreateParams(); + // Fake a grpc create response. + containerd::services::sandbox::v1::ControllerCreateResponse response; + response.set_sandbox_id(DUMMY_SANDBOX_ID); + // Set response to return sandbox_id, and return OK for stub_->Create(). +- EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(response), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(response), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Create(DUMMY_SANDBOX_ID, *params, err)); + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, CreateTestNullConfig) { ++TEST_F(ControllerSandboxerClientTest, CreateTestNullConfig) ++{ + Errors err; + std::unique_ptr params(new sandbox::ControllerCreateParams()); + params->config = nullptr; +@@ -113,20 +123,23 @@ TEST_F(ControllerSandboxerClientTest, CreateTestNullConfig) { + EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("Failed to init create request for sandboxer create request")); + } + +-TEST_F(ControllerSandboxerClientTest, CreateTestNullMount) { ++TEST_F(ControllerSandboxerClientTest, CreateTestNullMount) ++{ + Errors err; + std::unique_ptr params = CreateTestCreateParams(); + params->mounts.push_back(nullptr); + containerd::services::sandbox::v1::ControllerCreateRequest request; + // Save request to check mount size. +- EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::DoAll(testing::SaveArg<1>(&request), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::DoAll(testing::SaveArg<1>(&request), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Create(DUMMY_SANDBOX_ID, *params, err)); + // The nullptr pushed in params should not be counted. + EXPECT_EQ(request.rootfs_size(), 1); + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, CreateTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, CreateTestStatusNotOK) ++{ + Errors err; + std::unique_ptr params = CreateTestCreateParams(); + // Fake a grpc create response. +@@ -138,11 +151,13 @@ TEST_F(ControllerSandboxerClientTest, CreateTestStatusNotOK) { + } + + /************* Unit tests for Start *************/ +-TEST_F(ControllerSandboxerClientTest, StartTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, StartTestSucceed) ++{ + Errors err; + sandbox::ControllerSandboxInfo sandboxInfo; + std::unique_ptr response = CreateTestGrpcStartResponse(); +- EXPECT_CALL(*m_stub, Start).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Start).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Start(DUMMY_SANDBOX_ID, sandboxInfo, err)); + EXPECT_TRUE(err.Empty()); + EXPECT_EQ(sandboxInfo.id, DUMMY_SANDBOX_ID); +@@ -152,7 +167,8 @@ TEST_F(ControllerSandboxerClientTest, StartTestSucceed) { + EXPECT_EQ(sandboxInfo.labels["label1"], "value1"); + } + +-TEST_F(ControllerSandboxerClientTest, StartTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, StartTestStatusNotOK) ++{ + Errors err; + sandbox::ControllerSandboxInfo sandboxInfo; + EXPECT_CALL(*m_stub, Start).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); +@@ -161,7 +177,8 @@ TEST_F(ControllerSandboxerClientTest, StartTestStatusNotOK) { + } + + /************* Unit tests for Prepare *************/ +-TEST_F(ControllerSandboxerClientTest, PrepareTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, PrepareTestSucceed) ++{ + Errors err; + std::string bundle; + std::unique_ptr params = CreateTestPrepareParams(); +@@ -169,13 +186,15 @@ TEST_F(ControllerSandboxerClientTest, PrepareTestSucceed) { + containerd::services::sandbox::v1::PrepareResponse response; + response.set_bundle("/tmp/bundle"); + // Set response to return bundle, and return OK for stub_->Prepare(). +- EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(response), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(response), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Prepare(DUMMY_SANDBOX_ID, *params, bundle, err)); + EXPECT_TRUE(err.Empty()); + EXPECT_EQ(bundle, "/tmp/bundle"); + } + +-TEST_F(ControllerSandboxerClientTest, PrepareTestNullSpec) { ++TEST_F(ControllerSandboxerClientTest, PrepareTestNullSpec) ++{ + Errors err; + std::string bundle; + std::unique_ptr params = CreateTestPrepareParams(); +@@ -186,21 +205,24 @@ TEST_F(ControllerSandboxerClientTest, PrepareTestNullSpec) { + EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("Failed to init prepare request for sandboxer prepare request")); + } + +-TEST_F(ControllerSandboxerClientTest, PrepareTestNullMount) { ++TEST_F(ControllerSandboxerClientTest, PrepareTestNullMount) ++{ + Errors err; + std::string bundle; + std::unique_ptr params = CreateTestPrepareParams(); + params->rootfs.push_back(nullptr); + containerd::services::sandbox::v1::PrepareRequest request; + // Save request to check mount size. +- EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::DoAll(testing::SaveArg<1>(&request), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::DoAll(testing::SaveArg<1>(&request), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Prepare(DUMMY_SANDBOX_ID, *params, bundle, err)); + // The nullptr pushed in params should not be counted. + EXPECT_EQ(request.rootfs_size(), 2); + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, PrepareTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, PrepareTestStatusNotOK) ++{ + Errors err; + std::string bundle; + std::unique_ptr params = CreateTestPrepareParams(); +@@ -210,7 +232,8 @@ TEST_F(ControllerSandboxerClientTest, PrepareTestStatusNotOK) { + } + + /************* Unit tests for Purge *************/ +-TEST_F(ControllerSandboxerClientTest, PurgeTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, PurgeTestSucceed) ++{ + Errors err; + // Set response to return OK for stub_->Purge(). + EXPECT_CALL(*m_stub, Purge).Times(1).WillOnce(testing::Return(grpc::Status::OK)); +@@ -218,7 +241,8 @@ TEST_F(ControllerSandboxerClientTest, PurgeTestSucceed) { + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, PurgeTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, PurgeTestStatusNotOK) ++{ + Errors err; + EXPECT_CALL(*m_stub, Purge).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); + EXPECT_FALSE(m_sandboxerClient->Purge(DUMMY_SANDBOX_ID, DUMMY_CONTAINER_ID, DUMMY_EXEC_ID, err)); +@@ -226,7 +250,8 @@ TEST_F(ControllerSandboxerClientTest, PurgeTestStatusNotOK) { + } + + /************* Unit tests for UpdateResources *************/ +-TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestSucceed) ++{ + Errors err; + google::protobuf::Map annotations; + std::unique_ptr params = CreateTestUpdateResourcesParams(annotations); +@@ -236,7 +261,8 @@ TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestSucceed) { + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestNullResources) { ++TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestNullResources) ++{ + Errors err; + google::protobuf::Map annotations; + std::unique_ptr params = CreateTestUpdateResourcesParams(annotations); +@@ -244,24 +270,29 @@ TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestNullResources) { + // Stub should not be called + EXPECT_CALL(*m_stub, UpdateResources).Times(0); + EXPECT_FALSE(m_sandboxerClient->UpdateResources(DUMMY_SANDBOX_ID, *params, err)); +- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("Failed to init update-resources request for sandboxer update-resources request")); ++ EXPECT_THAT(err.GetCMessage(), ++ testing::HasSubstr("Failed to init update-resources request for sandboxer update-resources request")); + } + +-TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestStatusNotOK) ++{ + Errors err; + google::protobuf::Map annotations; + std::unique_ptr params = CreateTestUpdateResourcesParams(annotations); +- EXPECT_CALL(*m_stub, UpdateResources).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); ++ EXPECT_CALL(*m_stub, UpdateResources).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, ++ "gRPC Abort"))); + EXPECT_FALSE(m_sandboxerClient->UpdateResources(DUMMY_SANDBOX_ID, *params, err)); + EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort")); + } + + /************* Unit tests for Platform *************/ +-TEST_F(ControllerSandboxerClientTest, PlatformTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, PlatformTestSucceed) ++{ + Errors err; + sandbox::ControllerPlatformInfo platformInfo; + std::unique_ptr response = CreateTestPlatformResponse(); +- EXPECT_CALL(*m_stub, Platform).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Platform).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Platform(DUMMY_SANDBOX_ID, platformInfo, err)); + EXPECT_TRUE(err.Empty()); + EXPECT_EQ(platformInfo.os, "linux"); +@@ -269,16 +300,19 @@ TEST_F(ControllerSandboxerClientTest, PlatformTestSucceed) { + EXPECT_EQ(platformInfo.variant, "ubuntu"); + } + +-TEST_F(ControllerSandboxerClientTest, PlatformTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, PlatformTestStatusNotOK) ++{ + Errors err; + sandbox::ControllerPlatformInfo platformInfo; +- EXPECT_CALL(*m_stub, Platform).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); ++ EXPECT_CALL(*m_stub, Platform).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, ++ "gRPC Abort"))); + EXPECT_FALSE(m_sandboxerClient->Platform(DUMMY_SANDBOX_ID, platformInfo, err)); + EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort")); + } + + /************* Unit tests for Stop *************/ +-TEST_F(ControllerSandboxerClientTest, StopTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, StopTestSucceed) ++{ + Errors err; + // Set response to return OK for stub_->Stop(). + EXPECT_CALL(*m_stub, Stop).Times(1).WillOnce(testing::Return(grpc::Status::OK)); +@@ -286,7 +320,8 @@ TEST_F(ControllerSandboxerClientTest, StopTestSucceed) { + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, StopTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, StopTestStatusNotOK) ++{ + Errors err; + EXPECT_CALL(*m_stub, Stop).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); + EXPECT_FALSE(m_sandboxerClient->Stop(DUMMY_SANDBOX_ID, 0, err)); +@@ -294,11 +329,13 @@ TEST_F(ControllerSandboxerClientTest, StopTestStatusNotOK) { + } + + /************* Unit tests for Status *************/ +-TEST_F(ControllerSandboxerClientTest, StatusTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, StatusTestSucceed) ++{ + Errors err; + sandbox::ControllerSandboxStatus sandboxStatus; + std::unique_ptr response = CreateTestStatusResponse(); +- EXPECT_CALL(*m_stub, Status).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response), testing::Return(grpc::Status::OK))); ++ EXPECT_CALL(*m_stub, Status).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response), ++ testing::Return(grpc::Status::OK))); + EXPECT_TRUE(m_sandboxerClient->Status(DUMMY_SANDBOX_ID, false, sandboxStatus, err)); + EXPECT_TRUE(err.Empty()); + EXPECT_EQ(sandboxStatus.id, DUMMY_SANDBOX_ID); +@@ -312,7 +349,8 @@ TEST_F(ControllerSandboxerClientTest, StatusTestSucceed) { + EXPECT_EQ(sandboxStatus.extra, "{extra: test}"); + } + +-TEST_F(ControllerSandboxerClientTest, StatusTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, StatusTestStatusNotOK) ++{ + Errors err; + sandbox::ControllerSandboxStatus sandboxStatus; + EXPECT_CALL(*m_stub, Status).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); +@@ -321,7 +359,8 @@ TEST_F(ControllerSandboxerClientTest, StatusTestStatusNotOK) { + } + + /************* Unit tests for Shutdown *************/ +-TEST_F(ControllerSandboxerClientTest, ShutdownTestSucceed) { ++TEST_F(ControllerSandboxerClientTest, ShutdownTestSucceed) ++{ + Errors err; + // Set response to return OK for stub_->Shutdown(). + EXPECT_CALL(*m_stub, Shutdown).Times(1).WillOnce(testing::Return(grpc::Status::OK)); +@@ -329,9 +368,11 @@ TEST_F(ControllerSandboxerClientTest, ShutdownTestSucceed) { + EXPECT_TRUE(err.Empty()); + } + +-TEST_F(ControllerSandboxerClientTest, ShutdownTestStatusNotOK) { ++TEST_F(ControllerSandboxerClientTest, ShutdownTestStatusNotOK) ++{ + Errors err; +- EXPECT_CALL(*m_stub, Shutdown).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort"))); ++ EXPECT_CALL(*m_stub, Shutdown).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, ++ "gRPC Abort"))); + EXPECT_FALSE(m_sandboxerClient->Shutdown(DUMMY_SANDBOX_ID, err)); + EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort")); + } +diff --git a/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc b/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc +index 52c3f28a..f49d7cc5 100644 +--- a/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc ++++ b/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc +@@ -21,7 +21,8 @@ + + class SandboxerControllerTest : public testing::Test { + protected: +- void SetUp() override { ++ void SetUp() override ++ { + Errors err; + m_contoller = std::move(std::unique_ptr(new SandboxerController(m_sandboxer, m_address))); + m_sandboxerClientMock = std::make_shared(); +@@ -30,7 +31,8 @@ protected: + m_contoller->Init(err); + } + +- void TearDown() override { ++ void TearDown() override ++ { + m_contoller.reset(nullptr); + } + +@@ -74,7 +76,8 @@ TEST_F(SandboxerControllerTest, StartTestSucceed) + Errors err; + std::unique_ptr sandboxInfo = CreateTestSandboxInfo(); + // Set response to return sandbox_id, and return OK for stub_->Start(). +- EXPECT_CALL(*m_sandboxerClientMock, Start).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<1>(*sandboxInfo), testing::Return(true))); ++ EXPECT_CALL(*m_sandboxerClientMock, Start).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<1>(*sandboxInfo), ++ testing::Return(true))); + std::unique_ptr ret = m_contoller->Start(DUMMY_SANDBOX_ID, err); + EXPECT_EQ(ret->id, DUMMY_SANDBOX_ID); + EXPECT_EQ(ret->pid, 1234); +@@ -99,7 +102,8 @@ TEST_F(SandboxerControllerTest, PlatformTestSucceed) + platformInfo->arch = "amd64"; + platformInfo->variant = "openEuler"; + // Set response to return sandbox_id, and return OK for stub_->Platform(). +- EXPECT_CALL(*m_sandboxerClientMock, Platform).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<1>(*platformInfo), testing::Return(true))); ++ EXPECT_CALL(*m_sandboxerClientMock, Platform).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<1>(*platformInfo), ++ testing::Return(true))); + std::unique_ptr ret = m_contoller->Platform(DUMMY_SANDBOX_ID, err); + EXPECT_EQ(ret->os, "linux"); + EXPECT_EQ(ret->arch, "amd64"); +@@ -121,7 +125,8 @@ TEST_F(SandboxerControllerTest, PrepareTestSucceed) + Errors err; + std::string bundle = "/tmp/bundle"; + // Set response to return sandbox_id, and return OK for stub_->Prepare(). +- EXPECT_CALL(*m_sandboxerClientMock, Prepare).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<2>(bundle), testing::Return(true))); ++ EXPECT_CALL(*m_sandboxerClientMock, Prepare).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<2>(bundle), ++ testing::Return(true))); + std::string ret = m_contoller->Prepare(DUMMY_SANDBOX_ID, *CreateTestPrepareParams(), err); + EXPECT_EQ(ret, bundle); + } +@@ -201,7 +206,8 @@ TEST_F(SandboxerControllerTest, StatusTestSucceed) + sandboxStatus->info["test"] = "test"; + sandboxStatus->exitedAt = DUMMY_EXITED_AT; + // Set response to return sandbox_id, and return OK for stub_->Status(). +- EXPECT_CALL(*m_sandboxerClientMock, Status).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<2>(*sandboxStatus), testing::Return(true))); ++ EXPECT_CALL(*m_sandboxerClientMock, Status).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<2>(*sandboxStatus), ++ testing::Return(true))); + std::unique_ptr ret = m_contoller->Status(DUMMY_SANDBOX_ID, false, err); + EXPECT_EQ(ret->id, DUMMY_SANDBOX_ID); + EXPECT_EQ(ret->state, "created"); +diff --git a/test/sandbox/controller/shim/shim_controller_ut.cc b/test/sandbox/controller/shim/shim_controller_ut.cc +index 978e2c36..e43cc645 100644 +--- a/test/sandbox/controller/shim/shim_controller_ut.cc ++++ b/test/sandbox/controller/shim/shim_controller_ut.cc +@@ -24,7 +24,8 @@ + + class ShimControllerTest : public testing::Test { + protected: +- void SetUp() override { ++ void SetUp() override ++ { + Errors err; + m_contoller = std::move(std::unique_ptr(new sandbox::ShimController(m_sandboxer))); + m_containerCallbackMock = std::make_shared(); +@@ -37,7 +38,8 @@ protected: + service_callback_init(); + } + +- void TearDown() override { ++ void TearDown() override ++ { + m_contoller.reset(nullptr); + } + +-- +2.42.0 + diff --git a/0029-2255-Fix-cpusets-offline-issue.patch b/0029-2255-Fix-cpusets-offline-issue.patch new file mode 100644 index 0000000000000000000000000000000000000000..d87a32e2058c953dd1178077ae04d381654cedcb --- /dev/null +++ b/0029-2255-Fix-cpusets-offline-issue.patch @@ -0,0 +1,445 @@ +From a6f1ff360dded79ce5139a8b97a51c37d2fbd403 Mon Sep 17 00:00:00 2001 +From: xuxuepeng +Date: Thu, 23 Nov 2023 13:18:13 +0000 +Subject: [PATCH 29/65] !2255 Fix cpusets offline issue * Fix cpusets offline + issue + +--- + src/daemon/common/sysinfo.c | 1 + + src/daemon/common/sysinfo.h | 3 + + src/daemon/modules/spec/verify.c | 24 ++--- + test/mocks/image_mock.cc | 16 +++ + test/mocks/image_mock.h | 2 + + test/specs/CMakeLists.txt | 1 + + test/specs/verify/CMakeLists.txt | 85 +++++++++++++++ + test/specs/verify/verify_ut.cc | 173 +++++++++++++++++++++++++++++++ + 8 files changed, 289 insertions(+), 16 deletions(-) + create mode 100644 test/specs/verify/CMakeLists.txt + create mode 100644 test/specs/verify/verify_ut.cc + +diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c +index 957b370b..39338925 100644 +--- a/src/daemon/common/sysinfo.c ++++ b/src/daemon/common/sysinfo.c +@@ -393,6 +393,7 @@ sysinfo_t *get_sys_info(bool quiet) + } + + sysinfo->ncpus = get_nprocs(); ++ sysinfo->ncpus_conf = get_nprocs_conf(); + + cgroup_version = common_get_cgroup_version(); + if (cgroup_version < 0) { +diff --git a/src/daemon/common/sysinfo.h b/src/daemon/common/sysinfo.h +index 4ac65df6..363576a9 100644 +--- a/src/daemon/common/sysinfo.h ++++ b/src/daemon/common/sysinfo.h +@@ -25,7 +25,10 @@ extern "C" { + #include "cgroup.h" + + typedef struct { ++ // Number of processors currently online (i.e., available). + int ncpus; ++ // Number of processors configured. ++ int ncpus_conf; + cgroup_mem_info_t cgmeminfo; + cgroup_cpu_info_t cgcpuinfo; + cgroup_hugetlb_info_t hugetlbinfo; +diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c +index 850595ed..2a8b3259 100644 +--- a/src/daemon/modules/spec/verify.c ++++ b/src/daemon/modules/spec/verify.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -560,7 +561,7 @@ static bool check_cpu(const char *provided, const char *available) + } + + /* parse unit list */ +-int parse_unit_list(const char *val, bool *available_list, int cpu_num) ++STATIC int parse_unit_list(const char *val, bool *available_list, int cpu_num) + { + int ret = -1; + char *str = NULL; +@@ -612,22 +613,13 @@ out: + } + + /* is cpuset list available */ +-static bool is_cpuset_list_available(const char *provided, const char *available) ++STATIC bool is_cpuset_list_available(const char *provided, const char *available, int cpu_num) + { +- int cpu_num = 0; + int i = 0; + bool ret = false; + bool *parsed_provided = NULL; + bool *parsed_available = NULL; +- sysinfo_t *sysinfo = NULL; +- +- sysinfo = get_sys_info(true); +- if (sysinfo == NULL) { +- ERROR("get sysinfo failed"); +- return false; +- } + +- cpu_num = sysinfo->ncpus; + parsed_provided = util_smart_calloc_s(sizeof(bool), (unsigned int)cpu_num); + if (parsed_provided == NULL) { + ERROR("memory alloc failed!"); +@@ -661,10 +653,10 @@ out: + } + + /* is cpuset cpus available */ +-bool is_cpuset_cpus_available(const sysinfo_t *sysinfo, const char *cpus) ++STATIC bool is_cpuset_cpus_available(const sysinfo_t *sysinfo, const char *cpus) + { + bool ret = false; +- ret = is_cpuset_list_available(cpus, sysinfo->cpusetinfo.cpus); ++ ret = is_cpuset_list_available(cpus, sysinfo->cpusetinfo.cpus, sysinfo->ncpus_conf); + if (!ret) { + ERROR("Checking cpuset.cpus got invalid format: %s.", cpus); + isulad_set_error_message("Checking cpuset.cpus got invalid format: %s.", cpus); +@@ -673,10 +665,10 @@ bool is_cpuset_cpus_available(const sysinfo_t *sysinfo, const char *cpus) + } + + /* is cpuset mems available */ +-bool is_cpuset_mems_available(const sysinfo_t *sysinfo, const char *mems) ++STATIC bool is_cpuset_mems_available(const sysinfo_t *sysinfo, const char *mems) + { + bool ret = false; +- ret = is_cpuset_list_available(mems, sysinfo->cpusetinfo.mems); ++ ret = is_cpuset_list_available(mems, sysinfo->cpusetinfo.mems, sysinfo->ncpus_conf); + if (!ret) { + ERROR("Checking cpuset.mems got invalid format: %s.", mems); + isulad_set_error_message("Checking cpuset.mems got invalid format: %s.", mems); +@@ -685,7 +677,7 @@ bool is_cpuset_mems_available(const sysinfo_t *sysinfo, const char *mems) + } + + // cpuset subsystem checks and adjustments +-static int verify_resources_cpuset(const sysinfo_t *sysinfo, const char *cpus, const char *mems) ++STATIC int verify_resources_cpuset(const sysinfo_t *sysinfo, const char *cpus, const char *mems) + { + int ret = 0; + bool cpus_available = false; +diff --git a/test/mocks/image_mock.cc b/test/mocks/image_mock.cc +index 7114080c..cebe418d 100644 +--- a/test/mocks/image_mock.cc ++++ b/test/mocks/image_mock.cc +@@ -54,3 +54,19 @@ int im_umount_container_rootfs(const char *image_type, const char *image_name, c + } + return 0; + } ++ ++struct graphdriver_status *im_graphdriver_get_status(void) ++{ ++ if (g_image_mock != nullptr) { ++ return g_image_mock->ImGraphdriverGetStatus(); ++ } ++ return nullptr; ++} ++ ++void im_free_graphdriver_status(struct graphdriver_status *status) ++{ ++ if (g_image_mock != nullptr) { ++ g_image_mock->ImFreeGraphdriverStatus(status); ++ } ++ return; ++} +diff --git a/test/mocks/image_mock.h b/test/mocks/image_mock.h +index 0c7c1e51..f05be516 100644 +--- a/test/mocks/image_mock.h ++++ b/test/mocks/image_mock.h +@@ -28,6 +28,8 @@ public: + const char *container_id)); + MOCK_METHOD3(ImUmountContainerRootfs, int(const char *image_type, const char *image_name, + const char *container_id)); ++ MOCK_METHOD0(ImGraphdriverGetStatus, struct graphdriver_status *()); ++ MOCK_METHOD1(ImFreeGraphdriverStatus, void(struct graphdriver_status *status)); + }; + + void MockImage_SetMock(MockImage *mock); +diff --git a/test/specs/CMakeLists.txt b/test/specs/CMakeLists.txt +index 7acd68a1..bf5ed535 100644 +--- a/test/specs/CMakeLists.txt ++++ b/test/specs/CMakeLists.txt +@@ -2,3 +2,4 @@ project(iSulad_UT) + + add_subdirectory(specs) + add_subdirectory(specs_extend) ++add_subdirectory(verify) +diff --git a/test/specs/verify/CMakeLists.txt b/test/specs/verify/CMakeLists.txt +new file mode 100644 +index 00000000..0e60a39e +--- /dev/null ++++ b/test/specs/verify/CMakeLists.txt +@@ -0,0 +1,85 @@ ++project(iSulad_UT) ++ ++SET(EXE specs_verify_ut) ++ ++add_definitions(-DUNIT_TEST=ON) ++ ++add_executable(${EXE} ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_timestamp.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/util_atomic.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_mount_spec.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_fs.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_cap.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/err_msg.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/sysinfo.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/cgroup.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/cgroup_v1.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/spec/verify.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/image/oci/oci_ut_common.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/containers_store_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/namespace_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/container_unix_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/engine_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/selinux_label_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/isulad_config_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/storage_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/image_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/storage_mock.cc ++ verify_ut.cc) ++ ++target_include_directories(${EXE} PUBLIC ++ ${GTEST_INCLUDE_DIR} ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../include ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/image/oci ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/image ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/image/external ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/isulad ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/config ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/api ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/volume ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/runtime ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/restart_manager ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/health_check ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/image/oci/storage ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/services ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/services/execution ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/spec/ ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/services/execution/manager ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/events ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/services/execution/execute ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/tar ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/plugin ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/http ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/runtime/engines ++ ${ENGINES_INCS} ++ ${RUNTIME_INCS} ++ ${IMAGE_INCS} ++ ${CMAKE_BINARY_DIR}/conf ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256 ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/config ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/services/graphdriver ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/console ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/image/oci ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks ++ ) ++ ++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/verify/verify_ut.cc b/test/specs/verify/verify_ut.cc +new file mode 100644 +index 00000000..e764e476 +--- /dev/null ++++ b/test/specs/verify/verify_ut.cc +@@ -0,0 +1,173 @@ ++/* ++ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Description: specs verify ut ++ * Author: xuxuepeng ++ * Create: 2023-11-16 ++ */ ++ ++#include ++#include ++#include ++#include "mock.h" ++#include ++#include ++#include "sysinfo.h" ++#include "utils.h" ++ ++using namespace std; ++ ++#define HOST_CONFIG_FILE "../../../../test/specs/verify/hostconfig.json" ++#define OCI_RUNTIME_SPEC_FILE "../../../../test/specs/verify/oci_runtime_spec.json" ++ ++extern "C" { ++ int verify_resources_cpuset(const sysinfo_t *sysinfo, const char *cpus, const char *mems); ++} ++ ++/* get sys info */ ++sysinfo_t *create_sys_info_for_cpuset_test(const char *cpus, const char *mems, int ncpus_conf, int ncpus) ++{ ++ sysinfo_t *sysinfo = NULL; ++ ++ sysinfo = (sysinfo_t *)util_common_calloc_s(sizeof(sysinfo_t)); ++ if (sysinfo == NULL) { ++ ERROR("Out of memory"); ++ return NULL; ++ } ++ ++ sysinfo->ncpus = ncpus; ++ sysinfo->ncpus_conf = ncpus_conf; ++ ++ sysinfo->cpusetinfo.cpuset = true; ++ sysinfo->cpusetinfo.cpus = util_strdup_s(cpus); ++ sysinfo->cpusetinfo.mems = util_strdup_s(mems); ++ ++ return sysinfo; ++} ++ ++void test_different_provided_cpus_mems(sysinfo_t *sysinfo, const char *provided_cpus, const char *provided_mems, ++ int expected) ++{ ++ int ret = 0; ++ ret = verify_resources_cpuset(sysinfo, provided_cpus, provided_mems); ++ ASSERT_EQ(ret, expected); ++} ++ ++// Test the case when provided is null, and available is 0-7 ++TEST(test_verify_resources_cpuset, test_0_7) ++{ ++ sysinfo_t *sysinfo = create_sys_info_for_cpuset_test("0-7", "0-7", 8, 8); ++ test_different_provided_cpus_mems(sysinfo, nullptr, nullptr, 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0", "0", 0); ++ test_different_provided_cpus_mems(sysinfo, "2", "2", 0); ++ test_different_provided_cpus_mems(sysinfo, "7", "7", 0); ++ test_different_provided_cpus_mems(sysinfo, "8", "8", -1); ++ ++ test_different_provided_cpus_mems(sysinfo, "1,2", "1,2", 0); ++ test_different_provided_cpus_mems(sysinfo, "1,3,5", "1,3,5", 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0-7", "0-7", 0); ++ test_different_provided_cpus_mems(sysinfo, "0-8", "0-8", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3-7", "0-1,3-7", 0); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3,5-7", "0-1,3,5-7", 0); ++ ++ free_sysinfo(sysinfo); ++} ++ ++// Test the case when provided is null, and available is 0-1,3-7 ++TEST(test_verify_resources_cpuset, test_0_1_3_7) ++{ ++ sysinfo_t *sysinfo = create_sys_info_for_cpuset_test("0-1,3-7", "0-1,3-7", 8, 7); ++ test_different_provided_cpus_mems(sysinfo, nullptr, nullptr, 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0", "0", 0); ++ test_different_provided_cpus_mems(sysinfo, "2", "2", -1); ++ test_different_provided_cpus_mems(sysinfo, "7", "7", 0); ++ test_different_provided_cpus_mems(sysinfo, "8", "8", -1); ++ ++ test_different_provided_cpus_mems(sysinfo, "1,2", "1,2", -1); ++ test_different_provided_cpus_mems(sysinfo, "1,3,5", "1,3,5", 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0-7", "0-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-8", "0-8", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3-7", "0-1,3-7", 0); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3,5-7", "0-1,3,5-7", 0); ++ ++ free_sysinfo(sysinfo); ++} ++ ++// Test the case when provided is null, and available is 0-6 ++TEST(test_verify_resources_cpuset, test_0_6) ++{ ++ sysinfo_t *sysinfo = create_sys_info_for_cpuset_test("0-6", "0-6", 8, 7); ++ ++ test_different_provided_cpus_mems(sysinfo, nullptr, nullptr, 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0", "0", 0); ++ test_different_provided_cpus_mems(sysinfo, "2", "2", 0); ++ test_different_provided_cpus_mems(sysinfo, "7", "7", -1); ++ test_different_provided_cpus_mems(sysinfo, "8", "8", -1); ++ ++ test_different_provided_cpus_mems(sysinfo, "1,2", "1,2", 0); ++ test_different_provided_cpus_mems(sysinfo, "1,3,5", "1,3,5", 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0-7", "0-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-8", "0-8", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3-7", "0-1,3-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3,5-7", "0-1,3,5-7", -1); ++ ++ free_sysinfo(sysinfo); ++} ++ ++// Test the case when provided is null, and available is 1-7 ++TEST(test_verify_resources_cpuset, test_1_7) ++{ ++ sysinfo_t *sysinfo = create_sys_info_for_cpuset_test("1-7", "1-7", 8, 7); ++ ++ test_different_provided_cpus_mems(sysinfo, nullptr, nullptr, 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0", "0", -1); ++ test_different_provided_cpus_mems(sysinfo, "2", "2", 0); ++ test_different_provided_cpus_mems(sysinfo, "7", "7", 0); ++ test_different_provided_cpus_mems(sysinfo, "8", "8", -1); ++ ++ test_different_provided_cpus_mems(sysinfo, "1,2", "1,2", 0); ++ test_different_provided_cpus_mems(sysinfo, "1,3,5", "1,3,5", 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0-7", "0-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-8", "0-8", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3-7", "0-1,3-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3,5-7", "0-1,3,5-7", -1); ++ ++ free_sysinfo(sysinfo); ++} ++ ++// Test the case when provided is null, and available is 0,3 ++TEST(test_verify_resources_cpuset, test_null_03) ++{ ++ sysinfo_t *sysinfo = create_sys_info_for_cpuset_test("0,3", "0,3", 8, 2); ++ test_different_provided_cpus_mems(sysinfo, nullptr, nullptr, 0); ++ ++ test_different_provided_cpus_mems(sysinfo, "0", "0", 0); ++ test_different_provided_cpus_mems(sysinfo, "2", "2", -1); ++ test_different_provided_cpus_mems(sysinfo, "7", "7", -1); ++ test_different_provided_cpus_mems(sysinfo, "8", "8", -1); ++ ++ test_different_provided_cpus_mems(sysinfo, "1,2", "1,2", -1); ++ test_different_provided_cpus_mems(sysinfo, "1,3,5", "1,3,5", -1); ++ ++ test_different_provided_cpus_mems(sysinfo, "0-7", "0-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-8", "0-8", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3-7", "0-1,3-7", -1); ++ test_different_provided_cpus_mems(sysinfo, "0-1,3,5-7", "0-1,3,5-7", -1); ++ ++ free_sysinfo(sysinfo); ++} +-- +2.42.0 + diff --git a/0030-modify-daemon-json-default-runtime-to-runc.patch b/0030-modify-daemon-json-default-runtime-to-runc.patch new file mode 100644 index 0000000000000000000000000000000000000000..5826739121730e96735ad8df3d3cd66a14c72ed8 --- /dev/null +++ b/0030-modify-daemon-json-default-runtime-to-runc.patch @@ -0,0 +1,52 @@ +From b94f36b3d06abd711449b2e91303dfdd33f9c979 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 21 Nov 2023 21:31:48 +0800 +Subject: [PATCH 30/65] modify daemon json default runtime to runc + +Signed-off-by: zhongtao +--- + src/cmd/isula/base/create.h | 2 +- + src/cmd/isula/extend/stats.c | 1 - + src/contrib/config/daemon.json | 2 +- + 3 files changed, 2 insertions(+), 3 deletions(-) + +diff --git a/src/cmd/isula/base/create.h b/src/cmd/isula/base/create.h +index 986be41f..9eb471b4 100644 +--- a/src/cmd/isula/base/create.h ++++ b/src/cmd/isula/base/create.h +@@ -332,7 +332,7 @@ extern "C" { + "runtime", \ + 'R', \ + &(cmdargs).runtime, \ +- "Runtime to use for containers(default: lcr)", \ ++ "Runtime to use for containers", \ + NULL }, \ + { CMD_OPT_TYPE_STRING_DUP, \ + false, \ +diff --git a/src/cmd/isula/extend/stats.c b/src/cmd/isula/extend/stats.c +index c11fe218..04485608 100644 +--- a/src/cmd/isula/extend/stats.c ++++ b/src/cmd/isula/extend/stats.c +@@ -41,7 +41,6 @@ struct client_arguments g_cmd_stats_args = { + .showall = false, + .nostream = false, + .original = false, +- .runtime = "lcr", + }; + + static struct isula_stats_response *g_oldstats = NULL; +diff --git a/src/contrib/config/daemon.json b/src/contrib/config/daemon.json +index 4faf4057..966e016a 100644 +--- a/src/contrib/config/daemon.json ++++ b/src/contrib/config/daemon.json +@@ -1,6 +1,6 @@ + { + "group": "isula", +- "default-runtime": "lcr", ++ "default-runtime": "runc", + "graph": "/var/lib/isulad", + "state": "/var/run/isulad", + "log-level": "ERROR", +-- +2.42.0 + diff --git a/0031-modify-CI-for-default-runtime-to-runc.patch b/0031-modify-CI-for-default-runtime-to-runc.patch new file mode 100644 index 0000000000000000000000000000000000000000..9c6ce4f14a73d41690de10ff4ed7d381d1c70727 --- /dev/null +++ b/0031-modify-CI-for-default-runtime-to-runc.patch @@ -0,0 +1,815 @@ +From c0d86490ba53bf9a33f7569dc31c4ec1ba54f073 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 21 Nov 2023 21:32:08 +0800 +Subject: [PATCH 31/65] modify CI for default runtime to runc + +Signed-off-by: zhongtao +--- + CI/test_cases/container_cases/cni_test.sh | 103 ++++++++++-------- + .../container_cases/exec_additional_gids.sh | 26 +++-- + CI/test_cases/container_cases/export.sh | 10 +- + .../hook_ignore_poststart_error.sh | 10 +- + .../container_cases/hook_spec_test.sh | 12 +- + ...igdata_stream.sh => lcr_bigdata_stream.sh} | 32 +----- + .../container_cases/{exec.sh => lcr_exec.sh} | 2 +- + CI/test_cases/container_cases/nano_cpus.sh | 8 +- + CI/test_cases/container_cases/restart.sh | 14 ++- + CI/test_cases/container_cases/run.sh | 49 +++++---- + ..._stream_runc.sh => runc_bigdata_stream.sh} | 0 + .../{exec_runc.sh => runc_exec.sh} | 0 + CI/test_cases/container_cases/seccomp.sh | 12 +- + CI/test_cases/container_cases/stop.sh | 19 +++- + CI/test_cases/critest.sh | 6 +- + 15 files changed, 166 insertions(+), 137 deletions(-) + rename CI/test_cases/container_cases/{bigdata_stream.sh => lcr_bigdata_stream.sh} (93%) + rename CI/test_cases/container_cases/{exec.sh => lcr_exec.sh} (97%) + rename CI/test_cases/container_cases/{bigdata_stream_runc.sh => runc_bigdata_stream.sh} (100%) + rename CI/test_cases/container_cases/{exec_runc.sh => runc_exec.sh} (100%) + +diff --git a/CI/test_cases/container_cases/cni_test.sh b/CI/test_cases/container_cases/cni_test.sh +index bbc381dd..114cf2a3 100755 +--- a/CI/test_cases/container_cases/cni_test.sh ++++ b/CI/test_cases/container_cases/cni_test.sh +@@ -37,6 +37,10 @@ function do_post() + start_isulad_with_valgrind + } + ++# $1: pod runtime; ++# $2: pod config; ++# $3: eth0 ip; ++# $4: eth1 ip; + function do_test_help() + { + msg_info "this is $0 do_test" +@@ -53,7 +57,7 @@ function do_test_help() + TC_RET_T=$(($TC_RET_T+1)) + fi + +- sid=`crictl runp ${data_path}/$1` ++ sid=`crictl runp --runtime $1 ${data_path}/$2` + if [ $? -ne 0 ]; then + msg_err "Failed to run sandbox" + TC_RET_T=$(($TC_RET_T+1)) +@@ -61,7 +65,7 @@ function do_test_help() + + cnt=`ls /var/lib/cni/results/* | wc -l` + target_cnt=1 +- if [ "x$3" != "x" ];then ++ if [ "x$4" != "x" ];then + target_cnt=2 + fi + +@@ -77,7 +81,7 @@ function do_test_help() + TC_RET_T=$(($TC_RET_T+1)) + fi + +- cid=`crictl create $sid ${data_path}/container-config.json ${data_path}/$1` ++ cid=`crictl create $sid ${data_path}/container-config.json ${data_path}/$2` + if [ $? -ne 0 ];then + msg_err "create container failed" + TC_RET_T=$(($TC_RET_T+1)) +@@ -107,29 +111,29 @@ function do_test_help() + nsenter -t $con_pid -n ifconfig eth0 + TC_RET_T=$(($TC_RET_T+1)) + fi +- nsenter -t $pod_pid -n ifconfig eth0 | grep "$2" ++ nsenter -t $pod_pid -n ifconfig eth0 | grep "$3" + if [ $? -ne 0 ];then +- msg_err "expect ip: $1, get: " ++ msg_err "expect ip: $3, get: " + nsenter -t $pod_pid -n ifconfig eth0 + TC_RET_T=$(($TC_RET_T+1)) + fi +- crictl inspectp $sid | grep "$2" ++ crictl inspectp $sid | grep "$3" + if [ $? -ne 0 ];then +- msg_err "inspectp: expect ip: $1, get: " ++ msg_err "inspectp: expect ip: $3, get: " + crictl inspectp $sid + TC_RET_T=$(($TC_RET_T+1)) + fi + +- if [ "x$3" != "x" ];then +- nsenter -t $pod_pid -n ifconfig eth1 | grep "$3" ++ if [ "x$4" != "x" ];then ++ nsenter -t $pod_pid -n ifconfig eth1 | grep "$4" + if [ $? -ne 0 ];then +- msg_err "expect ip: $2, get: " ++ msg_err "expect ip: $4, get: " + nsenter -t $pod_pid -n ifconfig eth1 + TC_RET_T=$(($TC_RET_T+1)) + fi +- crictl inspectp $sid | grep "$3" ++ crictl inspectp $sid | grep "$4" + if [ $? -ne 0 ];then +- msg_err "inspectp expect ip: $2, get: " ++ msg_err "inspectp expect ip: $4, get: " + crictl inspectp $sid + TC_RET_T=$(($TC_RET_T+1)) + fi +@@ -170,7 +174,7 @@ function do_test_help() + + function default_cni_config() + { +- do_test_help "sandbox-config.json" "10\.1\." ++ do_test_help $1 "sandbox-config.json" "10\.1\." + } + + function new_cni_config() +@@ -189,12 +193,12 @@ function new_cni_config() + fi + done + tail $ISUALD_LOG +- do_test_help "mutlnet_pod.json" "10\.2\." "10\.1\." ++ do_test_help $1 "mutlnet_pod.json" "10\.2\." "10\.1\." + } + + function check_annotation_extension() + { +- sid=`crictl runp ${data_path}/sandbox-config.json` ++ sid=`crictl runp --runtime $1 ${data_path}/sandbox-config.json` + if [ $? -ne 0 ]; then + msg_err "Failed to run sandbox" + TC_RET_T=$(($TC_RET_T+1)) +@@ -253,7 +257,7 @@ function check_rollback() + done + tail $ISUALD_LOG + +- crictl runp ${data_path}/mutl_wrong_net_pod.json ++ crictl runp --runtime $1 ${data_path}/mutl_wrong_net_pod.json + if [ $? -eq 0 ]; then + msg_err "Run sandbox success with invalid cni configs" + TC_RET_T=$(($TC_RET_T+1)) +@@ -302,13 +306,14 @@ function check_rollback() + # $2: expect ingress rate; + # $3: input egress rate; + # $4: expect egress rate; ++# $5: pod runtime; + function check_annotation_valid_bandwidth() + { + rm bandwidth.json + cp ${data_path}/mock_sandbox.json bandwidth.json + sed -i "s#ingressholder#$1#g" bandwidth.json + sed -i "s#engressholder#$3#g" bandwidth.json +- sid=`crictl runp bandwidth.json` ++ sid=`crictl runp --runtime $5 bandwidth.json` + if [ $? -ne 0 ]; then + msg_err "Failed to run sandbox" + TC_RET_T=$(($TC_RET_T+1)) +@@ -345,6 +350,7 @@ function check_annotation_valid_bandwidth() + return $TC_RET_T + } + ++# function not called + function check_annotation_invalid_bandwidth() + { + rm bandwidth.json +@@ -386,44 +392,51 @@ function check_annotation() + done + tail $ISUALD_LOG + +- check_annotation_extension ++ check_annotation_extension $1 + +- check_annotation_valid_bandwidth "10.24k" "10240" "-1.024k" "-1024" +- check_annotation_valid_bandwidth "1024m" "2" "-1024m" "-1" +- check_annotation_valid_bandwidth "1.000001Ki" "1025" "-1.00001Ki" "-1024" +- check_annotation_valid_bandwidth "0.1Mi" "104858" "-0.01Mi" "-10485" +- check_annotation_valid_bandwidth "1.00001e2" "101" "-1.0001e2" "-100" ++ check_annotation_valid_bandwidth "10.24k" "10240" "-1.024k" "-1024" $1 ++ check_annotation_valid_bandwidth "1024m" "2" "-1024m" "-1" $1 ++ check_annotation_valid_bandwidth "1.000001Ki" "1025" "-1.00001Ki" "-1024" $1 ++ check_annotation_valid_bandwidth "0.1Mi" "104858" "-0.01Mi" "-10485" $1 ++ check_annotation_valid_bandwidth "1.00001e2" "101" "-1.0001e2" "-100" $1 + + return $TC_RET_T + } + +-ret=0 ++function do_test_t() ++{ ++ local ret=0 ++ local runtime=$1 ++ local test="cni_test => (${runtime})" ++ msg_info "${test} starting..." ++ ++ default_cni_config $runtime || ((ret++)) ++ ++ new_cni_config $runtime || ((ret++)) ++ ++ check_annotation $runtime || ((ret++)) + +-do_pre +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++ check_rollback $runtime || ((ret++)) + +-default_cni_config +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++ msg_info "${test} finished with return ${ret}..." + +-new_cni_config +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++ return $ret ++} + +-check_annotation +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++ret=0 + +-check_rollback +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++for element in ${RUNTIME_LIST[@]}; ++do ++ do_pre ++ if [ $? -ne 0 ];then ++ let "ret=$ret + 1" ++ fi + +-do_post ++ do_test_t $element ++ if [ $? -ne 0 ];then ++ let "ret=$ret + 1" ++ fi ++ do_post ++done + + show_result $ret "cni base test" +diff --git a/CI/test_cases/container_cases/exec_additional_gids.sh b/CI/test_cases/container_cases/exec_additional_gids.sh +index f24678d3..2edfd750 100755 +--- a/CI/test_cases/container_cases/exec_additional_gids.sh ++++ b/CI/test_cases/container_cases/exec_additional_gids.sh +@@ -22,7 +22,6 @@ + curr_path=$(dirname $(readlink -f "$0")) + data_path=$(realpath $curr_path/../data) + source ../helpers.sh +-test="exec additional gids test => test_exec_additional_gids" + test_log=$(mktemp /tmp/additional_gids_test_XXX) + + USERNAME="user" +@@ -37,10 +36,14 @@ file_info="Keep it secret, keep it safe" + function additional_gids_test() + { + local ret=0 ++ local runtime=$1 ++ test="exec additional gids test => test_exec_additional_gids => $runtime" ++ ++ msg_info "${test} starting..." + + isula rm -f `isula ps -a -q` + +- isula run -tid -n $cont_name ubuntu bash ++ isula run -tid --runtime $runtime -n $cont_name ubuntu bash + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container" && ((ret++)) + + isula exec $cont_name bash -c "groupadd --gid $USER_GID $USERNAME \ +@@ -52,10 +55,13 @@ function additional_gids_test() + && chmod 606 /app/sekrit.txt" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - create user and group failed" && ((ret++)) + ++ # runc is not support exec --workdir + /usr/bin/expect <<- EOF > ${test_log} 2>&1 + set timeout 10 +-spawn isula exec -it --workdir /app -u $USERNAME $cont_name bash ++spawn isula exec -it -u $USERNAME $cont_name bash + expect "${USERNAME}*" ++send "cd /app\n" ++expect "*" + send "newgrp ${ADDITIONAL_GROUP}\n" + expect "*" + send "groups\n" +@@ -75,18 +81,18 @@ EOF + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - read error message failed" && ((ret++)) + + isula rm -f `isula ps -a -q` ++ rm -rf ${test_log} ++ ++ msg_info "${test} finished with return ${ret}..." + + return ${ret} + } + + declare -i ans=0 + +-msg_info "${test} starting..." +- +-additional_gids_test || ((ans++)) +- +-rm -rf ${test_log} +- +-msg_info "${test} finished with return ${ret}..." ++for element in ${RUNTIME_LIST[@]}; ++do ++ additional_gids_test $element || ((ans++)) ++done + + show_result ${ans} "${curr_path}/${0}" +diff --git a/CI/test_cases/container_cases/export.sh b/CI/test_cases/container_cases/export.sh +index eeef2809..1cff873d 100755 +--- a/CI/test_cases/container_cases/export.sh ++++ b/CI/test_cases/container_cases/export.sh +@@ -26,7 +26,8 @@ function test_image_export() + { + local ret=0 + local image="busybox" +- local test="export container test => (${FUNCNAME[@]})" ++ local runtime=$1 ++ local test="export container test => (${FUNCNAME[@]}) => $runtime" + + msg_info "${test} starting..." + +@@ -36,7 +37,7 @@ function test_image_export() + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + +- CONT=`isula run -itd busybox` ++ CONT=`isula run --runtime $runtime -itd busybox` + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula export -o export.tar ${CONT} +@@ -55,6 +56,9 @@ function test_image_export() + + declare -i ans=0 + +-test_image_export || ((ans++)) ++for element in ${RUNTIME_LIST[@]}; ++do ++ test_image_export $element || ((ans++)) ++done + + show_result ${ans} "${curr_path}/${0}" +diff --git a/CI/test_cases/container_cases/hook_ignore_poststart_error.sh b/CI/test_cases/container_cases/hook_ignore_poststart_error.sh +index 5c86a4c1..8c636f7e 100755 +--- a/CI/test_cases/container_cases/hook_ignore_poststart_error.sh ++++ b/CI/test_cases/container_cases/hook_ignore_poststart_error.sh +@@ -28,7 +28,8 @@ function test_hook_ignore_poststart_error_spec() + { + local ret=0 + local image="busybox" +- local test="container hook test => (${FUNCNAME[@]})" ++ local runtime=$1 ++ local test="container hook test => (${FUNCNAME[@]}) => $runtime" + CONT=test_hook_spec + cp ${test_data_path}/poststart.sh /tmp/ + +@@ -40,7 +41,7 @@ function test_hook_ignore_poststart_error_spec() + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + +- isula run -n $CONT -itd --hook-spec ${test_data_path}/oci_hook_poststart_check.json ${image} & ++ isula run -n $CONT -itd --runtime $runtime --hook-spec ${test_data_path}/oci_hook_poststart_check.json ${image} & + + for a in `seq 20` + do +@@ -74,6 +75,9 @@ function test_hook_ignore_poststart_error_spec() + + declare -i ans=0 + +-test_hook_ignore_poststart_error_spec || ((ans++)) ++for element in ${RUNTIME_LIST[@]}; ++do ++ test_hook_ignore_poststart_error_spec $1 || ((ans++)) ++done + + show_result ${ans} "${curr_path}/${0}" +diff --git a/CI/test_cases/container_cases/hook_spec_test.sh b/CI/test_cases/container_cases/hook_spec_test.sh +index c88ed340..33b7c2e5 100755 +--- a/CI/test_cases/container_cases/hook_spec_test.sh ++++ b/CI/test_cases/container_cases/hook_spec_test.sh +@@ -28,7 +28,8 @@ function test_hook_spec() + { + local ret=0 + local image="busybox" +- local test="container hook test => (${FUNCNAME[@]})" ++ local runtime=$1 ++ local test="container hook test => (${FUNCNAME[@]}) => $runtime" + msg_info "${test} starting..." + + isula pull ${image} +@@ -37,7 +38,7 @@ function test_hook_spec() + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + +- CONT=`isula run -itd --hook-spec ${test_data_path}/test-hookspec.json ${image}` ++ CONT=`isula run -itd --runtime $runtime --hook-spec ${test_data_path}/test-hookspec.json ${image}` + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula stop -t 0 ${CONT} +@@ -51,7 +52,7 @@ function test_hook_spec() + isula run -n $no_permission_container -itd --hook-spec ${test_data_path}/no_permission.json ${image} > $runlog 2>&1 + [[ $? -ne 126 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check exit code container with image: ${image}" && ((ret++)) + +- cat $runlog | grep "Permission denied" ++ cat $runlog | grep -i "Permission denied" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to get no_permission output: ${image}" && ((ret++)) + + isula rm -f $no_permission_container +@@ -95,6 +96,9 @@ EOF + + declare -i ans=0 + +-test_hook_spec || ((ans++)) ++for element in ${RUNTIME_LIST[@]}; ++do ++ test_hook_spec $element || ((ans++)) ++done + + show_result ${ans} "${curr_path}/${0}" +diff --git a/CI/test_cases/container_cases/bigdata_stream.sh b/CI/test_cases/container_cases/lcr_bigdata_stream.sh +similarity index 93% +rename from CI/test_cases/container_cases/bigdata_stream.sh +rename to CI/test_cases/container_cases/lcr_bigdata_stream.sh +index 3bfc2d50..c8ecc48a 100755 +--- a/CI/test_cases/container_cases/bigdata_stream.sh ++++ b/CI/test_cases/container_cases/lcr_bigdata_stream.sh +@@ -40,7 +40,7 @@ function set_up() + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + +- CID=$(isula run -itd ${image} sh) ++ CID=$(isula run --runtime lcr -itd ${image} sh) + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula exec -it $CID dd if=/dev/zero of=test_500M bs=1M count=500 +@@ -389,33 +389,6 @@ function test_stream_with_kill_isulad() + return ${ret} + } + +-function test_stream_with_runc() +-{ +- local ret=0 +- local image="busybox" +- local test="test_stream_with_runc => (${FUNCNAME[@]})" +- msg_info "${test} starting..." +- +- RUNCID=$(isula run -itd --runtime runc ${image} sh) +- isula exec -it $RUNCID dd if=/dev/zero of=test_500M bs=1M count=500 +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++)) +- +- 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++)) +- +- isula rm -f $RUNCID +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++)) +- +- rm -rf /home/iocopy_stream_data_500M +- +- msg_info "${test} finished with return ${ret}..." +- return ${ret} +-} +- + function tear_down() + { + local ret=0 +@@ -438,7 +411,7 @@ function test_memory_leak_with_bigdata_stream() + + start_isulad_with_valgrind + +- CID=$(isula run -itd ${image} sh) ++ CID=$(isula run --runtime lcr -itd ${image} sh) + + isula exec -it $CID dd if=/dev/zero of=test_100M bs=1M count=100 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++)) +@@ -477,7 +450,6 @@ test_stream_with_stop_lxc_monitor || ((ans++)) + test_stream_with_kill_lxc_monitor || ((ans++)) + test_stream_with_stop_isulad || ((ans++)) + test_stream_with_kill_isulad || ((ans++)) +-test_stream_with_runc || ((ans++)) + tear_down || ((ans++)) + + test_memory_leak_with_bigdata_stream || ((ans++)) +diff --git a/CI/test_cases/container_cases/exec.sh b/CI/test_cases/container_cases/lcr_exec.sh +similarity index 97% +rename from CI/test_cases/container_cases/exec.sh +rename to CI/test_cases/container_cases/lcr_exec.sh +index 96ceb884..4f51773d 100755 +--- a/CI/test_cases/container_cases/exec.sh ++++ b/CI/test_cases/container_cases/lcr_exec.sh +@@ -30,7 +30,7 @@ function exec_workdir() + + isula rm -f `isula ps -a -q` + +- isula run -tid -n cont_workdir busybox sh ++ isula run -tid --runtime lcr -n cont_workdir busybox sh + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with --workdir" && ((ret++)) + + isula exec -ti --workdir /workdir cont_workdir pwd | grep "/workdir" +diff --git a/CI/test_cases/container_cases/nano_cpus.sh b/CI/test_cases/container_cases/nano_cpus.sh +index c679958d..85223038 100755 +--- a/CI/test_cases/container_cases/nano_cpus.sh ++++ b/CI/test_cases/container_cases/nano_cpus.sh +@@ -26,7 +26,8 @@ function test_cpu_nano_spec() + { + local ret=0 + local image="busybox" +- local test="container blkio nano test => (${FUNCNAME[@]})" ++ local runtime=$1 ++ local test="container blkio nano test => (${FUNCNAME[@]}) => $runtime" + + msg_info "${test} starting..." + +@@ -108,6 +109,9 @@ function test_cpu_nano_spec() + + declare -i ans=0 + +-test_cpu_nano_spec || ((ans++)) ++for element in ${RUNTIME_LIST[@]}; ++do ++ test_cpu_nano_spec $element || ((ans++)) ++done + + show_result ${ans} "${curr_path}/${0}" +diff --git a/CI/test_cases/container_cases/restart.sh b/CI/test_cases/container_cases/restart.sh +index 5902af06..fddee1f7 100755 +--- a/CI/test_cases/container_cases/restart.sh ++++ b/CI/test_cases/container_cases/restart.sh +@@ -26,7 +26,8 @@ source ../helpers.sh + function do_test_t() + { + containername=test_restart +- isula run --name $containername -td busybox ++ ++ isula run --runtime $1 --name $containername -td busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -46,9 +47,12 @@ function do_test_t() + + ret=0 + +-do_test_t +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++for element in ${RUNTIME_LIST[@]}; ++do ++ do_test_t $element ++ if [ $? -ne 0 ];then ++ let "ret=$ret + 1" ++ fi ++done + + show_result $ret "basic restart" +diff --git a/CI/test_cases/container_cases/run.sh b/CI/test_cases/container_cases/run.sh +index ad449402..8ea3e514 100755 +--- a/CI/test_cases/container_cases/run.sh ++++ b/CI/test_cases/container_cases/run.sh +@@ -25,7 +25,7 @@ source ../helpers.sh + + function do_test_t() + { +- tid=`isula run -tid --name hostname busybox` ++ tid=`isula run --runtime $1 -tid --name hostname busybox` + chostname=`isula exec -it $tid hostname` + fn_check_eq "$chostname" "${tid:0:12}" "default hostname is id of container" + isula exec -it hostname env | grep HOSTNAME +@@ -37,7 +37,7 @@ function do_test_t() + containername=test_basic_run + containername2=container_to_join + +- isula run --name $containername -td busybox ++ isula run --runtime $1 --name $containername -td busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -48,7 +48,7 @@ function do_test_t() + isula rm $containername + fn_check_eq "$?" "0" "rm failed" + +- isula run --name $containername -td -v /dev/shm:/dev/shm busybox ++ isula run --runtime $1 --name $containername -td -v /dev/shm:/dev/shm busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -61,7 +61,7 @@ function do_test_t() + + echo AA > /tmp/test_run_env + +- isula run --name $containername -itd --user 100:100 -e AAA=BB -e BAA --env-file /tmp/test_run_env busybox ++ isula run --runtime $1 --name $containername -itd --user 100:100 -e AAA=BB -e BAA --env-file /tmp/test_run_env busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -72,18 +72,21 @@ function do_test_t() + isula rm $containername + fn_check_eq "$?" "0" "rm failed" + +- isula run --name $containername -itd --external-rootfs / --read-only none sh +- fn_check_eq "$?" "0" "run container with host rootfs failed" +- testcontainer $containername running ++ # runc directly uses the root directory as external rootfs and will report the error pivot_root .: device or resource busy ++ if [ $runtime == "lcr" ]; then ++ isula run --runtime $1 --name $containername -itd --external-rootfs / --read-only none sh ++ fn_check_eq "$?" "0" "run container with host rootfs failed" ++ testcontainer $containername running + +- isula stop -t 0 $containername +- fn_check_eq "$?" "0" "stop failed" +- testcontainer $containername exited ++ isula stop -t 0 $containername ++ fn_check_eq "$?" "0" "stop failed" ++ testcontainer $containername exited + +- isula rm $containername +- fn_check_eq "$?" "0" "rm failed" ++ isula rm $containername ++ fn_check_eq "$?" "0" "rm failed" ++ fi + +- isula run --name $containername -itd --net=host --pid=host --ipc=host --uts=host busybox ++ isula run --runtime $1 --name $containername -itd --net=host --pid=host --ipc=host --uts=host busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -94,7 +97,7 @@ function do_test_t() + isula rm $containername + fn_check_eq "$?" "0" "rm failed" + +- isula run --name $containername -itd --net=none --pid=none --ipc=none --uts=none busybox ++ isula run --runtime $1 --name $containername -itd --net=none --pid=none --ipc=none --uts=none busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -105,11 +108,11 @@ function do_test_t() + isula rm $containername + fn_check_eq "$?" "0" "rm failed" + +- isula run --name $containername2 -itd busybox ++ isula run --runtime $1 --name $containername2 -itd busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername2 running + +- isula run --name $containername -itd --net=container:$containername2 --pid=container:$containername2 --ipc=container:$containername2 --uts=container:$containername2 busybox ++ isula run --runtime $1 --name $containername -itd --net=container:$containername2 --pid=container:$containername2 --ipc=container:$containername2 --uts=container:$containername2 busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -135,7 +138,7 @@ function do_run_remote_test_t() + local ret=0 + local image="busybox" + local config='tcp://127.0.0.1:2890' +- local test="container start with --attach remote test => (${FUNCNAME[@]})" ++ local test="container start with --attach remote test => (${FUNCNAME[@]}) => $1" + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++)) +@@ -144,13 +147,13 @@ function do_run_remote_test_t() + + containername=run_remote + +- isula run -ti -H "$config" --name $containername busybox xxx ++ isula run --runtime $1 -ti -H "$config" --name $containername busybox xxx + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed check invalid run ${containername} remote" && ((ret++)) + testcontainer $containername exited + isula rm -f -H "$config" $containername + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container remote" && ((ret++)) + +- isula run -ti -H "$config" --name $containername busybox /bin/sh -c 'echo "hello"' | grep hello ++ isula run --runtime $1 -ti -H "$config" --name $containername busybox /bin/sh -c 'echo "hello"' | grep hello + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run ${containername} remote" && ((ret++)) + testcontainer $containername exited + +@@ -169,8 +172,10 @@ function do_run_remote_test_t() + + declare -i ans=0 + +-do_test_t || ((ans++)) +- +-do_run_remote_test_t || ((ans++)) ++for element in ${RUNTIME_LIST[@]}; ++do ++ do_test_t $element || ((ans++)) ++ do_run_remote_test_t $element || ((ans++)) ++done + + show_result ${ans} "${curr_path}/${0}" +diff --git a/CI/test_cases/container_cases/bigdata_stream_runc.sh b/CI/test_cases/container_cases/runc_bigdata_stream.sh +similarity index 100% +rename from CI/test_cases/container_cases/bigdata_stream_runc.sh +rename to CI/test_cases/container_cases/runc_bigdata_stream.sh +diff --git a/CI/test_cases/container_cases/exec_runc.sh b/CI/test_cases/container_cases/runc_exec.sh +similarity index 100% +rename from CI/test_cases/container_cases/exec_runc.sh +rename to CI/test_cases/container_cases/runc_exec.sh +diff --git a/CI/test_cases/container_cases/seccomp.sh b/CI/test_cases/container_cases/seccomp.sh +index 9e886d10..3cb08d84 100755 +--- a/CI/test_cases/container_cases/seccomp.sh ++++ b/CI/test_cases/container_cases/seccomp.sh +@@ -39,8 +39,9 @@ function do_pre() { + + function do_test() { + local ret=0 +- +- msg_info "this is $0 do_test" ++ local runtime=$1 ++ local test="seccomp test => (${runtime})" ++ msg_info "${test} starting..." + + cid1=$(isula run -tid --security-opt seccomp=/etc/isulad/seccomp_default.json busybox sh) + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Failed to run container with the default seccomp profile" && ((ret++)) +@@ -52,7 +53,7 @@ function do_test() { + --security-opt seccomp=${test_data_path}/seccomp_profile_without_archmap.json busybox sh) + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Failed to run container with multiple seccomp profiles" && ((ret++)) + +- isula stop "${cid1}" "${cid2}" "${cid3}" ++ isula stop -t 0 "${cid1}" "${cid2}" "${cid3}" + + isula rm -f $(isula ps -qa) + +@@ -69,7 +70,10 @@ declare -i ans=0 + + do_pre || ((ans++)) + +-do_test || ((ans++)) ++for element in ${RUNTIME_LIST[@]}; ++do ++ do_test $element || ((ans++)) ++done + + do_post + +diff --git a/CI/test_cases/container_cases/stop.sh b/CI/test_cases/container_cases/stop.sh +index 962e72f3..13292710 100755 +--- a/CI/test_cases/container_cases/stop.sh ++++ b/CI/test_cases/container_cases/stop.sh +@@ -25,8 +25,12 @@ source ../helpers.sh + + function do_test_t() + { ++ local runtime=$1 ++ local test="start_test => (${runtime})" ++ msg_info "${test} starting..." ++ + containername=test_stop +- isula run --name $containername -td busybox ++ isula run --runtime $runtime --name $containername -td busybox + fn_check_eq "$?" "0" "run failed" + testcontainer $containername running + +@@ -61,14 +65,19 @@ function do_test_t() + isula rm $containername + fn_check_eq "$?" "0" "rm failed" + ++ msg_info "${test} finished with return ${ret}..." ++ + return $TC_RET_T + } + + ret=0 + +-do_test_t +-if [ $? -ne 0 ];then +- let "ret=$ret + 1" +-fi ++for element in ${RUNTIME_LIST[@]}; ++do ++ do_test_t $element ++ if [ $? -ne 0 ];then ++ let "ret=$ret + 1" ++ fi ++done + + show_result $ret "basic stop" +diff --git a/CI/test_cases/critest.sh b/CI/test_cases/critest.sh +index 044ce2ed..f8d4975e 100755 +--- a/CI/test_cases/critest.sh ++++ b/CI/test_cases/critest.sh +@@ -130,7 +130,7 @@ function test_critest() { + function do_test_t() { + local ret=0 + +- local runtime="lcr" ++ local runtime="runc" + local test="critest => $runtime" + msg_info "${test} starting..." + echo "${test}" >> ${testcase_data}/critest.log +@@ -143,11 +143,11 @@ function do_test_t() { + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++)) + + # replace default runtime +- sed -i 's/"default-runtime": "lcr"/"default-runtime": "runc"/g' /etc/isulad/daemon.json ++ sed -i 's/"default-runtime": "runc"/"default-runtime": "lcr"/g' /etc/isulad/daemon.json + start_isulad_without_valgrind --selinux-enabled --network-plugin cni + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad with selinux and cni failed" && ((ret++)) + +- runtime=runc ++ runtime=lcr + test="critest => $runtime" + msg_info "${test} starting..." + echo "${test}" >> ${testcase_data}/critest.log +-- +2.42.0 + diff --git a/0032-add-ut-for-devicemapper.patch b/0032-add-ut-for-devicemapper.patch new file mode 100644 index 0000000000000000000000000000000000000000..9a5846e13c02301037c6725c84f7860f0fc1c3e7 --- /dev/null +++ b/0032-add-ut-for-devicemapper.patch @@ -0,0 +1,737 @@ +From ca297d26dc1e7b47d6987c6bbbd92dd2e3d78670 Mon Sep 17 00:00:00 2001 +From: jikai +Date: Wed, 22 Nov 2023 22:05:04 +0800 +Subject: [PATCH 32/65] add ut for devicemapper + +Signed-off-by: jikai +--- + test/image/oci/storage/layers/CMakeLists.txt | 2 + + .../storage/layers/devmapper/CMakeLists.txt | 71 +++++ + ...9702e4bd316dd50ae85467b0378a419b23b60ba73d | 6 + + ...a9fb83febf6dc0b1548dfe896161533668281c9f4f | 6 + + ...0a625721fdbea5c94ca6da897acdd814d710149770 | 6 + + .../devmapper/data/devicemapper/metadata/base | 7 + + .../devicemapper/metadata/deviceset-metadata | 5 + + .../metadata/transaction-metadata | 5 + + .../layers/devmapper/driver_devmapper_ut.cc | 283 ++++++++++++++++++ + test/mocks/libdevmapper_mock.cc | 191 ++++++++++++ + test/mocks/libdevmapper_mock.h | 52 ++++ + 11 files changed, 634 insertions(+) + create mode 100644 test/image/oci/storage/layers/devmapper/CMakeLists.txt + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/ba0dae6243cc9fa2890df40a625721fdbea5c94ca6da897acdd814d710149770 + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/base + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/deviceset-metadata + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/transaction-metadata + create mode 100644 test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc + create mode 100644 test/mocks/libdevmapper_mock.cc + create mode 100644 test/mocks/libdevmapper_mock.h + +diff --git a/test/image/oci/storage/layers/CMakeLists.txt b/test/image/oci/storage/layers/CMakeLists.txt +index 413a8b38..e1c76453 100644 +--- a/test/image/oci/storage/layers/CMakeLists.txt ++++ b/test/image/oci/storage/layers/CMakeLists.txt +@@ -1,5 +1,7 @@ + project(iSulad_UT) + ++add_subdirectory(devmapper) ++ + # storage_driver_ut + SET(DRIVER_EXE storage_driver_ut) + +diff --git a/test/image/oci/storage/layers/devmapper/CMakeLists.txt b/test/image/oci/storage/layers/devmapper/CMakeLists.txt +new file mode 100644 +index 00000000..f98de1a8 +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/CMakeLists.txt +@@ -0,0 +1,71 @@ ++project(iSulad_UT) ++ ++# driver_devmapper_ut ++SET(DRIVER_DEVMAPPER_EXE driver_devmapper_ut) ++ ++add_executable(${DRIVER_DEVMAPPER_EXE} ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_regex.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_verify.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_array.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_string.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_convert.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_file.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_fs.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/util_atomic.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_base64.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/utils_timestamp.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/path.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/map/map.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/map/rb_tree.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/buffer/buffer.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/tar/util_archive.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/tar/util_gzip.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/sha256/sha256.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/config/daemon_arguments.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/config/isulad_config.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/common/err_msg.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/common/selinux_label.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../mocks/libdevmapper_mock.cc ++ driver_devmapper_ut.cc) ++ ++target_include_directories(${DRIVER_DEVMAPPER_EXE} PUBLIC ++ ${GTEST_INCLUDE_DIR} ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../include ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/common ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/tar ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/cutils/map ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/sha256 ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/console ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/buffer ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/config ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/common ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/api ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2 ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/remote_layer_support ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../mocks ++ ) ++ ++set_target_properties(${DRIVER_DEVMAPPER_EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_exec_cmd -Wl,--wrap,util_mount -Wl,--wrap,umount2") ++ ++target_link_libraries(${DRIVER_DEVMAPPER_EXE} ++ ${GTEST_BOTH_LIBRARIES} ++ ${GMOCK_LIBRARY} ++ ${GMOCK_MAIN_LIBRARY} ++ ${CMAKE_THREAD_LIBS_INIT} ++ ${ISULA_LIBUTILS_LIBRARY} ++ ${LIBTAR_LIBRARY} ++ -lcrypto -lyajl -larchive ${SELINUX_LIBRARY} -lz -lcap) ++ ++add_test(NAME ${DRIVER_DEVMAPPER_EXE} COMMAND ${DRIVER_DEVMAPPER_EXE} --gtest_output=xml:${DRIVER_DEVMAPPER_EXE}-Results.xml) ++set_tests_properties(${DRIVER_DEVMAPPER_EXE} PROPERTIES TIMEOUT 120) +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d +new file mode 100644 +index 00000000..f51ae926 +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d +@@ -0,0 +1,6 @@ ++{ ++ "hash": "068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d", ++ "device_id": 6, ++ "size": 10737418240, ++ "transaction_id": 8 ++} +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f +new file mode 100644 +index 00000000..de727a79 +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f +@@ -0,0 +1,6 @@ ++{ ++ "hash": "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f", ++ "device_id": 4, ++ "size": 10737418240, ++ "transaction_id": 4 ++} +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/ba0dae6243cc9fa2890df40a625721fdbea5c94ca6da897acdd814d710149770 b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/ba0dae6243cc9fa2890df40a625721fdbea5c94ca6da897acdd814d710149770 +new file mode 100644 +index 00000000..e1e8988e +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/ba0dae6243cc9fa2890df40a625721fdbea5c94ca6da897acdd814d710149770 +@@ -0,0 +1,6 @@ ++{ ++ "hash": "ba0dae6243cc9fa2890df40a625721fdbea5c94ca6da897acdd814d710149770", ++ "device_id": 2, ++ "size": 10737418240, ++ "transaction_id": 2 ++} +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/base b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/base +new file mode 100644 +index 00000000..2412113d +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/base +@@ -0,0 +1,7 @@ ++{ ++ "hash": "base", ++ "device_id": 1, ++ "size": 10737418240, ++ "transaction_id": 1, ++ "initialized": true ++} +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/deviceset-metadata b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/deviceset-metadata +new file mode 100644 +index 00000000..94f7a6a3 +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/deviceset-metadata +@@ -0,0 +1,5 @@ ++{ ++ "next_device_id": 7, ++ "BaseDeviceFilesystem": "ext4", ++ "BaseDeviceUUID": "4fa22307-0c88-4fa4-8f16-a9459e9cbc4a" ++} +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/transaction-metadata b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/transaction-metadata +new file mode 100644 +index 00000000..a011249a +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/metadata/transaction-metadata +@@ -0,0 +1,5 @@ ++{ ++ "open_transaction_id": 8, ++ "device_hash": "068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d", ++ "device_id": 6 ++} +diff --git a/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc b/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc +new file mode 100644 +index 00000000..59e53f97 +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc +@@ -0,0 +1,283 @@ ++/****************************************************************************** ++ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: jikai ++ * Create: 2023-11-22 ++ * Description: provide oci storage driver unit test for devmapper ++ ******************************************************************************/ ++ ++#include ++#include ++ ++#include "driver_devmapper.h" ++#include "mock.h" ++#include "path.h" ++#include "utils.h" ++#include "libdevmapper_mock.h" ++ ++using ::testing::Invoke; ++using ::testing::NiceMock; ++using ::testing::Return; ++using ::testing::_; ++ ++extern "C" { ++ DECLARE_WRAPPER_V(util_exec_cmd, bool, (exec_func_t cb_func, void *args, const char *stdin_msg, char **stdout_msg, char **stderr_msg)); ++ DEFINE_WRAPPER_V(util_exec_cmd, bool, (exec_func_t cb_func, void *args, const char *stdin_msg, char **stdout_msg, char **stderr_msg), (cb_func, args, stdin_msg, stdout_msg, stderr_msg)); ++ ++ DECLARE_WRAPPER(util_mount, int, (const char *src, const char *dst, const char *mtype, const char *mntopts)); ++ DEFINE_WRAPPER(util_mount, int, (const char *src, const char *dst, const char *mtype, const char *mntopts), (src, dst, mtype, mntopts)); ++ ++ DECLARE_WRAPPER(umount2, int, (const char *__special_file, int __flags)); ++ DEFINE_WRAPPER(umount2, int, (const char *__special_file, int __flags), (__special_file, __flags)); ++} ++ ++static std::string GetDirectory() ++{ ++ char abs_path[PATH_MAX] { 0x00 }; ++ int ret = readlink("/proc/self/exe", abs_path, sizeof(abs_path)); ++ if (ret < 0 || static_cast(ret) >= sizeof(abs_path)) { ++ return ""; ++ } ++ ++ for (int i { ret }; i >= 0; --i) { ++ if (abs_path[i] == '/') { ++ abs_path[i + 1] = '\0'; ++ break; ++ } ++ } ++ ++ return static_cast(abs_path) + "../../../../../../../test/image/oci/storage/layers/devmapper"; ++} ++ ++static bool invokeUtilExecCmd(exec_func_t cb_func, void *args, const char *stdin_msg, char **stdout_msg, char **stderr_msg) ++{ ++ if (cb_func == nullptr || args == nullptr || stdout_msg == nullptr || stderr_msg == nullptr) { ++ return false; ++ } ++ ++ char **tmp_args = static_cast(args); ++ ++ if (util_array_len((const char **)tmp_args) < 1) { ++ return false; ++ } ++ ++ if (strcmp(tmp_args[0], "blkid") == 0) { ++ *stdout_msg = util_strdup_s("4fa22307-0c88-4fa4-8f16-a9459e9cbc4a"); ++ } ++ return true; ++} ++ ++static struct dm_task *invokeDMTaskCreate(int type) { ++ return static_cast(util_common_calloc_s(sizeof(0))); ++} ++ ++static void invokeDMTaskDestroy(struct dm_task *task) { ++ free(task); ++ return; ++} ++ ++static int invokeDMTaskGetDriverVersion(struct dm_task *task, char *version, size_t size) { ++ if (task == nullptr || version == nullptr || strncpy(version, "4.27.0", size) == NULL) { ++ return 0; ++ } ++ ++ return 1; ++} ++ ++static int invokeDMTaskGetInfo(struct dm_task *task, struct dm_info *dmi) { ++ if (task == nullptr || dmi == nullptr) { ++ return 0; ++ } ++ ++ dmi->exists = 1; ++ return 1; ++} ++ ++static void *invokeDMGetNextTarget(struct dm_task *task, void *next, uint64_t *start, uint64_t *length, ++ char **target_type, char **params) { ++ static char type[] = "thin-pool"; ++ static char par[] = "0 0/1024 0/1024"; ++ if (target_type) { ++ *target_type = type; ++ } ++ if (params) { ++ *params = par; ++ } ++ return nullptr; ++} ++ ++class DriverDevmapperUnitTest : public testing::Test { ++protected: ++ void SetUp() override ++ { ++ MockLibdevmapper_SetMock(&m_libdevmapper_mock); ++ std::string isulad_dir { "/tmp/isulad/" }; ++ mkdir(isulad_dir.c_str(), 0755); ++ std::string root_dir = isulad_dir + "data"; ++ std::string run_dir = isulad_dir + "data/run"; ++ std::string data_dir = GetDirectory() + "/data"; ++ std::string driver_home = root_dir + "/devicemapper"; ++ ++ ASSERT_STRNE(util_clean_path(data_dir.c_str(), data_path, sizeof(data_path)), nullptr); ++ std::string cp_command = "cp -r " + std::string(data_path) + " " + isulad_dir; ++ ASSERT_EQ(system(cp_command.c_str()), 0); ++ ++ char **driver_opts = static_cast(util_common_calloc_s(3 * sizeof(char *))); ++ driver_opts[0] = strdup("dm.thinpooldev=/dev/mapper/isulad0-thinpool"); ++ driver_opts[1] = strdup("dm.fs=ext4"); ++ driver_opts[2] = strdup("dm.min_free_space=10%"); ++ int driver_opts_len = 3; ++ ++ ASSERT_EQ(devmapper_init(&driver, nullptr, (const char **)driver_opts, driver_opts_len), -1); ++ ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskCreate(_)).WillRepeatedly(Invoke(invokeDMTaskCreate)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskSetMessage(_, _)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskSetSector(_, _)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskSetAddNode(_, _)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskAddTarget(_, _, _, _, _)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskSetName(_, _)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskRun(_)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskDestroy(_)).WillRepeatedly(Invoke(invokeDMTaskDestroy)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskGetInfo(_, _)).WillRepeatedly(Invoke(invokeDMTaskGetInfo)); ++ EXPECT_CALL(m_libdevmapper_mock, DMGetNextTarget(_, _, _, _, _, _)).WillRepeatedly(Invoke(invokeDMGetNextTarget)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskSetCookie(_, _, _)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMUdevWait(_)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMUdevComplete(_)).WillRepeatedly(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskDeferredRemove(_)).WillRepeatedly(Return(1)); ++ ++ ++ char *names = static_cast(util_common_calloc_s(sizeof(struct dm_names) + strlen("isulad0-pool") + 1)); ++ struct dm_names *dname = (struct dm_names *)names; ++ dname->dev = 1; ++ dname->next = 0; ++ strcpy(names + sizeof(struct dm_names), "isulad0-pool"); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskGetNames(_)).WillOnce(Return(dname)); ++ EXPECT_CALL(m_libdevmapper_mock, DMSetDevDir(_)).WillOnce(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskGetDriverVersion(_, _, _)).WillOnce(Invoke(invokeDMTaskGetDriverVersion)); ++ EXPECT_CALL(m_libdevmapper_mock, DMUdevGetSyncSupport()).WillOnce(Return(1)); ++ ++ MOCK_SET_V(util_exec_cmd, invokeUtilExecCmd); ++ ++ ASSERT_EQ(devmapper_init(&driver, driver_home.c_str(), (const char **)driver_opts, driver_opts_len), 0); ++ MOCK_CLEAR(util_exec_cmd); ++ ++ util_free_array_by_len(driver_opts, driver_opts_len); ++ free(names); ++ } ++ ++ void TearDown() override ++ { ++ MockLibdevmapper_SetMock(nullptr); ++ std::string rm_command = "rm -rf /tmp/isulad/"; ++ ASSERT_EQ(system(rm_command.c_str()), 0); ++ } ++ ++ NiceMock m_libdevmapper_mock; ++ char data_path[PATH_MAX] = { 0x00 }; ++ graphdriver driver = {.ops = nullptr, .name = "devicemapper", }; ++}; ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_layer_exists) ++{ ++ std::string id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; ++ std::string incorrectId { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" }; ++ ASSERT_TRUE(devmapper_layer_exist(id.c_str(), &driver)); ++ ASSERT_FALSE(devmapper_layer_exist(incorrectId.c_str(), &driver)); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_create_rw) ++{ ++ std::string id { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" }; ++ struct driver_create_opts *create_opts; ++ ++ create_opts = (struct driver_create_opts *)util_common_calloc_s(sizeof(struct driver_create_opts)); ++ ASSERT_NE(create_opts, nullptr); ++ ++ create_opts->storage_opt = static_cast(util_common_calloc_s(sizeof(json_map_string_string))); ++ ASSERT_NE(create_opts->storage_opt, nullptr); ++ create_opts->storage_opt->keys = static_cast(util_common_calloc_s(sizeof(char *))); ++ create_opts->storage_opt->values = static_cast(util_common_calloc_s(sizeof(char *))); ++ create_opts->storage_opt->keys[0] = strdup("size"); ++ create_opts->storage_opt->values[0] = strdup("10G"); ++ create_opts->storage_opt->len = 1; ++ ++ ASSERT_EQ(devmapper_create_rw(id.c_str(), nullptr, &driver, create_opts), 0); ++ ASSERT_TRUE(devmapper_layer_exist(id.c_str(), &driver)); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_mount_layer) ++{ ++ std::string id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; ++ std::string merged_dir = "/tmp/isulad/data/devicemapper/mnt/" + id + "/rootfs"; ++ struct driver_mount_opts *mount_opts = nullptr; ++ char* mount_dir = nullptr; ++ ++ MOCK_SET(util_mount, 0); ++ mount_dir = devmapper_mount_layer(id.c_str(), &driver, mount_opts); ++ ASSERT_STREQ(mount_dir, merged_dir.c_str()); ++ MOCK_CLEAR(util_mount); ++ ++ MOCK_SET(umount2, 0); ++ ASSERT_EQ(devmapper_umount_layer(id.c_str(), &driver), 0); ++ MOCK_CLEAR(umount2); ++ free(mount_dir); ++ mount_dir = nullptr; ++ ++ mount_opts = static_cast(util_common_calloc_s(sizeof(struct driver_mount_opts))); ++ ASSERT_NE(mount_opts, nullptr); ++ mount_opts->options = static_cast(util_common_calloc_s(1 * sizeof(char *))); ++ mount_opts->options[0] = strdup("ro"); ++ mount_opts->options_len = 1; ++ ++ MOCK_SET(util_mount, 0); ++ mount_dir = devmapper_mount_layer(id.c_str(), &driver, mount_opts); ++ ASSERT_STREQ(mount_dir, merged_dir.c_str()); ++ MOCK_CLEAR(util_mount); ++ ++ MOCK_SET(umount2, 0); ++ ASSERT_EQ(devmapper_umount_layer(id.c_str(), &driver), 0); ++ MOCK_CLEAR(umount2); ++ free(mount_opts->mount_label); ++ util_free_array_by_len(mount_opts->options, mount_opts->options_len); ++ free(mount_opts); ++ free(mount_dir); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_get_layer_metadata) ++{ ++ std::string id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; ++ json_map_string_string *map_info = static_cast(util_common_calloc_s(sizeof(json_map_string_string))); ++ ++ ASSERT_EQ(devmapper_get_layer_metadata(id.c_str(), &driver, map_info), 0); ++ ASSERT_EQ(map_info->len, 4); ++ ASSERT_STREQ(map_info->keys[0], "DeviceId"); ++ ASSERT_STREQ(map_info->values[0], "4"); ++ ASSERT_STREQ(map_info->keys[1], "DeviceSize"); ++ ASSERT_STREQ(map_info->values[1], "10737418240"); ++ ASSERT_STREQ(map_info->keys[2], "DeviceName"); ++ ASSERT_STREQ(map_info->keys[3], "MergedDir"); ++ ASSERT_STREQ(map_info->values[3], "/tmp/isulad/data/devicemapper/mnt/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f/rootfs"); ++ ++ free_json_map_string_string(map_info); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_get_driver_status) ++{ ++ struct graphdriver_status *status = static_cast(util_common_calloc_s(sizeof(struct graphdriver_status))); ++ ++ EXPECT_CALL(m_libdevmapper_mock, DMUdevGetSyncSupport()).WillOnce(Return(1)); ++ ++ ASSERT_EQ(devmapper_get_driver_status(&driver, status), 0); ++ ASSERT_STREQ(status->driver_name, "devicemapper"); ++ free(status->driver_name); ++ free(status->backing_fs); ++ free(status->status); ++ free(status); ++} +diff --git a/test/mocks/libdevmapper_mock.cc b/test/mocks/libdevmapper_mock.cc +new file mode 100644 +index 00000000..7d6c8024 +--- /dev/null ++++ b/test/mocks/libdevmapper_mock.cc +@@ -0,0 +1,191 @@ ++/****************************************************************************** ++ * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: jikai ++ * Create: 2023-11-22 ++ * Description: provide lib device mapper mock ++ ******************************************************************************/ ++ ++#include "libdevmapper_mock.h" ++ ++namespace { ++MockLibdevmapper *g_libdevmapper_mock = nullptr; ++} ++ ++void MockLibdevmapper_SetMock(MockLibdevmapper* mock) ++{ ++ g_libdevmapper_mock = mock; ++} ++ ++struct dm_task *dm_task_create(int type) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskCreate(type); ++ } ++ return nullptr; ++} ++ ++int dm_task_set_message(struct dm_task *dmt, const char *msg) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskSetMessage(dmt, msg); ++ } ++ return 0; ++} ++ ++int dm_task_set_sector(struct dm_task *dmt, uint64_t sector) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskSetSector(dmt, sector); ++ } ++ return 0; ++} ++ ++int dm_task_set_add_node(struct dm_task *dmt, dm_add_node_t add_node) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskSetAddNode(dmt, add_node); ++ } ++ return 0; ++} ++ ++int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size, const char *ttype, const char *params) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskAddTarget(dmt, start, size, ttype, params); ++ } ++ return 0; ++} ++ ++int dm_set_dev_dir(const char *dir) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMSetDevDir(dir); ++ } ++ return 0; ++} ++ ++int dm_task_set_name(struct dm_task *dmt, const char *name) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskSetName(dmt, name); ++ } ++ return 0; ++} ++ ++int dm_task_run(struct dm_task *dmt) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskRun(dmt); ++ } ++ return 0; ++} ++ ++int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskGetDriverVersion(dmt, version, size); ++ } ++ return 0; ++} ++ ++void dm_task_destroy(struct dm_task *dmt) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ g_libdevmapper_mock->DMTaskDestroy(dmt); ++ } ++} ++ ++int dm_get_library_version(char *version, size_t size) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMGetLibraryVersion(version, size); ++ } ++ return 0; ++} ++ ++int dm_task_get_info(struct dm_task *dmt, struct dm_info *info) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskGetInfo(dmt, info); ++ } ++ return 0; ++} ++ ++void *dm_get_next_target(struct dm_task *dmt, void *next, uint64_t *start, uint64_t *length, ++ char **target_type, char **params) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMGetNextTarget(dmt, next, start, length, target_type, params); ++ } ++ return nullptr; ++} ++ ++int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, uint16_t flags) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskSetCookie(dmt, cookie, flags); ++ } ++ return 0; ++} ++ ++int dm_udev_wait(uint32_t cookie) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMUdevWait(cookie); ++ } ++ return 0; ++} ++ ++int dm_udev_complete(uint32_t cookie) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMUdevComplete(cookie); ++ } ++ return 0; ++} ++ ++int dm_task_deferred_remove(struct dm_task *dmt) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskDeferredRemove(dmt); ++ } ++ return 0; ++} ++ ++struct dm_names *dm_task_get_names(struct dm_task *dmt) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMTaskGetNames(dmt); ++ } ++ return nullptr; ++} ++ ++int dm_udev_get_sync_support(void) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ return g_libdevmapper_mock->DMUdevGetSyncSupport(); ++ } ++ return 0; ++} ++ ++void dm_udev_set_sync_support(int sync_with_udev) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ g_libdevmapper_mock->DMUdevSetSyncSupport(sync_with_udev); ++ } ++} ++ ++void dm_log_with_errno_init(void log_cb(int level, const char *file, int line, int dm_errno_or_class, const char *f, ...)) ++{ ++ if (g_libdevmapper_mock != nullptr) { ++ g_libdevmapper_mock->DMLogWithErrnoInit(log_cb); ++ } ++} +diff --git a/test/mocks/libdevmapper_mock.h b/test/mocks/libdevmapper_mock.h +new file mode 100644 +index 00000000..53c5ad4b +--- /dev/null ++++ b/test/mocks/libdevmapper_mock.h +@@ -0,0 +1,52 @@ ++/****************************************************************************** ++ * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. ++ * iSulad licensed under the Mulan PSL v2. ++ * You can use this software according to the terms and conditions of the Mulan PSL v2. ++ * You may obtain a copy of Mulan PSL v2 at: ++ * http://license.coscl.org.cn/MulanPSL2 ++ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR ++ * PURPOSE. ++ * See the Mulan PSL v2 for more details. ++ * Author: jikai ++ * Create: 2023-11-22 ++ * Description: provide lib device mapper mock ++ ******************************************************************************/ ++ ++#ifndef _ISULAD_TEST_MOCKS_DEVMAPPER_MOCK_H ++#define _ISULAD_TEST_MOCKS_DEVMAPPER_MOCK_H ++ ++#include ++ ++#include ++ ++class MockLibdevmapper { ++public: ++ virtual ~MockLibdevmapper() = default; ++ MOCK_METHOD1(DMTaskCreate, struct dm_task*(int type)); ++ MOCK_METHOD2(DMTaskSetMessage, int(struct dm_task *dmt, const char *msg)); ++ MOCK_METHOD2(DMTaskSetSector, int(struct dm_task *dmt, uint64_t sector)); ++ MOCK_METHOD2(DMTaskSetAddNode, int(struct dm_task *dmt, dm_add_node_t add_node)); ++ MOCK_METHOD5(DMTaskAddTarget, int(struct dm_task *dmt, uint64_t start, uint64_t size, const char *ttype, const char *params)); ++ MOCK_METHOD1(DMSetDevDir, int(const char *dir)); ++ MOCK_METHOD2(DMTaskSetName, int(struct dm_task *dmt, const char *name)); ++ MOCK_METHOD1(DMTaskRun, int(struct dm_task *dmt)); ++ MOCK_METHOD3(DMTaskGetDriverVersion, int(struct dm_task *dmt, char *version, size_t size)); ++ MOCK_METHOD1(DMTaskDestroy, void(struct dm_task *dmt)); ++ MOCK_METHOD2(DMGetLibraryVersion, int(char *version, size_t size)); ++ MOCK_METHOD2(DMTaskGetInfo, int(struct dm_task *dmt, struct dm_info *info)); ++ MOCK_METHOD6(DMGetNextTarget, void*(struct dm_task *dmt, void *next, uint64_t *start, uint64_t *length, ++ char **target_type, char **params)); ++ MOCK_METHOD3(DMTaskSetCookie, int(struct dm_task *dmt, uint32_t *cookie, uint16_t flags)); ++ MOCK_METHOD1(DMUdevWait, int(uint32_t cookie)); ++ MOCK_METHOD1(DMUdevComplete, int(uint32_t cookie)); ++ MOCK_METHOD1(DMTaskDeferredRemove, int(struct dm_task *dmt)); ++ MOCK_METHOD1(DMTaskGetNames, struct dm_names *(struct dm_task *dmt)); ++ MOCK_METHOD0(DMUdevGetSyncSupport, int(void)); ++ MOCK_METHOD1(DMUdevSetSyncSupport, void(int sync_with_udev)); ++ MOCK_METHOD1(DMLogWithErrnoInit, void(void log_cb(int level, const char *file, int line, int dm_errno_or_class, const char *f, ...))); ++}; ++ ++void MockLibdevmapper_SetMock(MockLibdevmapper* mock); ++ ++#endif +-- +2.42.0 + diff --git a/0033-2275-bugfix-for-rt_lcr_rebuild_config.patch b/0033-2275-bugfix-for-rt_lcr_rebuild_config.patch new file mode 100644 index 0000000000000000000000000000000000000000..a11f89373ea76c2d6a9ac15ad8cd5197072d85fa --- /dev/null +++ b/0033-2275-bugfix-for-rt_lcr_rebuild_config.patch @@ -0,0 +1,46 @@ +From fa7356538c7f747a81aa3d0a511a662ee4345afe Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Fri, 24 Nov 2023 08:33:45 +0000 +Subject: [PATCH 33/65] !2275 bugfix for rt_lcr_rebuild_config * bugfix for + rt_lcr_rebuild_config + +--- + src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +index 8f7211d7..44ecab5a 100644 +--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c ++++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +@@ -777,6 +777,7 @@ int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuil + { + int ret = -1; + int nret = 0; ++ bool rebuild_success = false; + char config_file[PATH_MAX] = { 0 }; + char bak_config_file[PATH_MAX] = { 0 }; + char oci_config_file[PATH_MAX] = { 0 }; +@@ -825,8 +826,8 @@ int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuil + goto out; + } + +- nret = engine_ops->engine_create_op(name, params->rootpath, (void *)oci_spec); +- if (nret != 0) { ++ rebuild_success = engine_ops->engine_create_op(name, params->rootpath, (void *)oci_spec); ++ if (!rebuild_success) { + // delete the invalid config file to prevent rename failed + if (util_fileself_exists(config_file) && util_path_remove(config_file) != 0) { + WARN("Failed to remove bak_config_file for container %s", name); +@@ -835,7 +836,8 @@ int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuil + WARN("Failed to rename backup old config to config for container %s", name); + } + } +- ret = nret != 0 ? -1 : 0; ++ ret = rebuild_success ? 0 : -1; ++ + out: + if (engine_ops != NULL && engine_ops->engine_clear_errmsg_op != NULL) { + engine_ops->engine_clear_errmsg_op(); +-- +2.42.0 + diff --git a/0034-2277-remove-shim-v2-format-error-log.patch b/0034-2277-remove-shim-v2-format-error-log.patch new file mode 100644 index 0000000000000000000000000000000000000000..edac35a10f0c1cfb9ca5ce565462ef9d355d2075 --- /dev/null +++ b/0034-2277-remove-shim-v2-format-error-log.patch @@ -0,0 +1,25 @@ +From fe03c12676b8a48a2aede2d177f2cbcbdd68f930 Mon Sep 17 00:00:00 2001 +From: jake +Date: Sat, 25 Nov 2023 03:34:01 +0000 +Subject: [PATCH 34/65] !2277 remove shim v2 format error log * remove shim v2 + format error log + +--- + src/daemon/modules/runtime/shim/shim_rt_ops.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/src/daemon/modules/runtime/shim/shim_rt_ops.c b/src/daemon/modules/runtime/shim/shim_rt_ops.c +index 1bc9dc54..5066f804 100644 +--- a/src/daemon/modules/runtime/shim/shim_rt_ops.c ++++ b/src/daemon/modules/runtime/shim/shim_rt_ops.c +@@ -115,7 +115,6 @@ bool is_valid_v2_runtime(const char* name) + + parts_len = util_array_len((const char **)parts); + if (!(parts_len == 4 && strcmp(parts[0], "io") == 0 && strcmp(parts[1], "containerd") == 0)) { +- ERROR("ShimV2 runtime format is wrong"); + util_free_array(parts); + return false; + } +-- +2.42.0 + diff --git a/0035-2276-bugfix-for-integration_check.sh.patch b/0035-2276-bugfix-for-integration_check.sh.patch new file mode 100644 index 0000000000000000000000000000000000000000..c723bc2708455226435b720c19e7a94c17d7f879 --- /dev/null +++ b/0035-2276-bugfix-for-integration_check.sh.patch @@ -0,0 +1,26 @@ +From a2c565705f80f787e50ffc15db38ba367f517eb2 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Sat, 25 Nov 2023 03:34:50 +0000 +Subject: [PATCH 35/65] !2276 bugfix for integration_check.sh * bugfix for + integration_check.sh + +--- + CI/test_cases/image_cases/integration_check.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/CI/test_cases/image_cases/integration_check.sh b/CI/test_cases/image_cases/integration_check.sh +index e43369e3..6ec3ab52 100755 +--- a/CI/test_cases/image_cases/integration_check.sh ++++ b/CI/test_cases/image_cases/integration_check.sh +@@ -65,7 +65,7 @@ function test_image_info() + echo "xxx:11" >> ${change_file} + + sed -i 's#image-layer-check": false#image-layer-check": true#g' /etc/isulad/daemon.json +- pkill -9 isulad ++ kill -9 $(pidof isulad) + start_isulad_with_valgrind + + isula ps -a | grep ${cid} +-- +2.42.0 + diff --git a/0036-modify-create_network.sh-for-default-runtime-changed.patch b/0036-modify-create_network.sh-for-default-runtime-changed.patch new file mode 100644 index 0000000000000000000000000000000000000000..405965fc2f7e991c44b91bf8a558becce380d071 --- /dev/null +++ b/0036-modify-create_network.sh-for-default-runtime-changed.patch @@ -0,0 +1,40 @@ +From e422c6cf725240dea80e1c51ba21cae8ee6641c6 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Sat, 25 Nov 2023 18:21:56 +0800 +Subject: [PATCH 36/65] modify create_network.sh for default runtime changed + +Signed-off-by: zhongtao +--- + CI/test_cases/container_cases/create_network.sh | 2 +- + CI/test_cases/helpers.sh | 2 ++ + 2 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/CI/test_cases/container_cases/create_network.sh b/CI/test_cases/container_cases/create_network.sh +index 470bda70..5bafbc60 100755 +--- a/CI/test_cases/container_cases/create_network.sh ++++ b/CI/test_cases/container_cases/create_network.sh +@@ -37,7 +37,7 @@ function test_network_param() + + msg_info "${test} starting..." + +- root="`isula info | grep 'iSulad Root Dir' | awk -F ':' '{print $2}'`/engines/lcr" ++ root="`isula info | grep 'iSulad Root Dir' | awk -F ':' '{print $2}'`/engines/$DEFAULT_RUNTIME" + + isula pull ${image} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE} +diff --git a/CI/test_cases/helpers.sh b/CI/test_cases/helpers.sh +index f3eeb54d..c5eba8a2 100755 +--- a/CI/test_cases/helpers.sh ++++ b/CI/test_cases/helpers.sh +@@ -29,6 +29,8 @@ ISULAD_RUN_ROOT_PATH="/var/run/isulad" + + RUNTIME_LIST=(lcr runc) + ++DEFAULT_RUNTIME=runc ++ + testcase_data="/tmp/testcases_data" + + enable_native_network=0 +-- +2.42.0 + diff --git a/0037-modify-the-container-runtime-when-running-embedded.s.patch b/0037-modify-the-container-runtime-when-running-embedded.s.patch new file mode 100644 index 0000000000000000000000000000000000000000..f63d84edb928d3ad615685ec79260da55dd2ab47 --- /dev/null +++ b/0037-modify-the-container-runtime-when-running-embedded.s.patch @@ -0,0 +1,141 @@ +From 8e4b6eceeb117fc90b5b638329f8888e43d3f442 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 27 Nov 2023 17:21:15 +0800 +Subject: [PATCH 37/65] modify the container runtime when running embedded.sh + +Signed-off-by: zhongtao +--- + CI/test_cases/image_cases/embedded.sh | 30 +++++++++++++-------------- + 1 file changed, 15 insertions(+), 15 deletions(-) + +diff --git a/CI/test_cases/image_cases/embedded.sh b/CI/test_cases/image_cases/embedded.sh +index cdc75e50..a1d4c37a 100755 +--- a/CI/test_cases/image_cases/embedded.sh ++++ b/CI/test_cases/image_cases/embedded.sh +@@ -81,14 +81,14 @@ function test_run_image() + { + local ret=0 + +- isula run -t -n embedded_test1 nonexistentname1:v1 /bin/sh ++ isula run --runtime lcr -t -n embedded_test1 nonexistentname1:v1 /bin/sh + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run nonexistent image should failed" && ((ret++)) + + isula load -i "$embedded_manifest" -t embedded + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++)) + + # run container based on embedded image +- isula run --name embedded_test1 test:v1 ls /home/home/home ++ isula run --runtime lcr --name embedded_test1 test:v1 ls /home/home/home + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run embedded image failed" && ((ret++)) + + # delete container based on embedded image +@@ -96,7 +96,7 @@ function test_run_image() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete container based on embedded image failed" && ((ret++)) + + # test image's env +- isula run --name embedded_test1 test:v1 /bin/sh -c "echo \$c | grep \"d e\"" ++ isula run --runtime lcr --name embedded_test1 test:v1 /bin/sh -c "echo \$c | grep \"d e\"" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's env failed" && ((ret++)) + + # delete container based on embedded image +@@ -119,7 +119,7 @@ function test_mount() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded imagefailed" && ((ret++)) + + # run --mount +- isula run --mount type=bind,src="$embedded_basedir",dst=/usr,ro=true,bind-propagation=rprivate --name embedded_test2 test:v1 true ++ isula run --runtime lcr --mount type=bind,src="$embedded_basedir",dst=/usr,ro=true,bind-propagation=rprivate --name embedded_test2 test:v1 true + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run --mount failed" && ((ret++)) + + testcontainer embedded_test2 exited +@@ -127,25 +127,25 @@ function test_mount() + isula rm embedded_test2 + + # test invalid mode +- isula run --mount type=bind,src="$embedded_basedir",dst=/usr,ro=invalid --name embedded_test2 test:v1 true ++ isula run --runtime lcr --mount type=bind,src="$embedded_basedir",dst=/usr,ro=invalid --name embedded_test2 test:v1 true + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid mode should failed" && ((ret++)) + + isula rm embedded_test2 + + # test invalid bind propagation mode +- isula run --mount type=bind,src="$embedded_basedir",dst=/usr,bind-propagation=invalid --name embedded_test2 test:v1 true ++ isula run --runtime lcr --mount type=bind,src="$embedded_basedir",dst=/usr,bind-propagation=invalid --name embedded_test2 test:v1 true + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid bind propagation mode should failed" && ((ret++)) + + isula rm embedded_test2 + + # test source not exist +- isula run --mount type=bind,src=abcdefg/notexist,dst=/usr --name embedded_test2 test:v1 true ++ isula run --runtime lcr --mount type=bind,src=abcdefg/notexist,dst=/usr --name embedded_test2 test:v1 true + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid source not exist should failed" && ((ret++)) + + isula rm embedded_test2 + + # test source not a regular file +- isula run --mount type=squashfs,src=/tmp,dst=/usr --name embedded_test2 test:v1 true ++ isula run --runtime lcr --mount type=squashfs,src=/tmp,dst=/usr --name embedded_test2 test:v1 true + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - source not a regular file should failed" && ((ret++)) + + isula rm embedded_test2 +@@ -153,7 +153,7 @@ function test_mount() + # test path //tmp/test + mkdir -p /tmp/test_mount + mkdir -p /tmp/test_mount1/test +- isula run -v /tmp/test_mount:/tmp --mount type=bind,src=/tmp/test_mount1,dst=//tmp/test_mount1,ro=true,bind-propagation=rprivate --name embedded_test2 test:v1 ls /tmp/test_mount1/test ++ isula run --runtime lcr -v /tmp/test_mount:/tmp --mount type=bind,src=/tmp/test_mount1,dst=//tmp/test_mount1,ro=true,bind-propagation=rprivate --name embedded_test2 test:v1 ls /tmp/test_mount1/test + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test path //tmp/test failed" && ((ret++)) + + isula rm embedded_test2 +@@ -186,7 +186,7 @@ function test_query_image() + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - inspect nonexist item should failed" && ((ret++)) + + # test inspect container, it should conatainer image info +- isula run --name embedded_inspect test:v1 ls /home/home/home ++ isula run --runtime lcr --name embedded_inspect test:v1 ls /home/home/home + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container for inspect failed" && ((ret++)) + + isula inspect -f '{{json .Image}}' embedded_inspect +@@ -437,19 +437,19 @@ function test_entrypoint() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++)) + + # test image's entrypoint +- isula run --name embedded_entrypoint1 test:v1 ++ isula run --runtime lcr --name embedded_entrypoint1 test:v1 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's entrypoint failed" && ((ret++)) + + isula rm embedded_entrypoint1 + + # test image's entrypoint with cmds +- isula run --name embedded_entrypoint1 test:v1 /bin ++ isula run --runtime lcr --name embedded_entrypoint1 test:v1 /bin + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's entrypoint with cmds failed" && ((ret++)) + + isula rm embedded_entrypoint1 + + # test image's entrypoint override image's entrypoint +- isula run --entrypoint=/bin/ls --name embedded_entrypoint1 test:v1 /bin ++ isula run --runtime lcr --entrypoint=/bin/ls --name embedded_entrypoint1 test:v1 /bin + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's entrypoint override image's entrypoint failed" && ((ret++)) + + isula rm embedded_entrypoint1 +@@ -464,7 +464,7 @@ function test_entrypoint() + isula load -i "$embedded_manifest_invalid" -t embedded + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test entrypoint with variable failed" && ((ret++)) + +- isula run -e env_id=me --name embedded_entrypoint1 test:v1 ++ isula run --runtime lcr -e env_id=me --name embedded_entrypoint1 test:v1 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test run embedded image with env failed" && ((ret++)) + + isula rm embedded_entrypoint1 +@@ -519,7 +519,7 @@ function test_symbolic() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++)) + + # run container based on embedded image +- isula run --name embedded_test_symbolic test:v1 ls /home/home/home ++ isula run --runtime lcr --name embedded_test_symbolic test:v1 ls /home/home/home + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container based on embedded image failed" && ((ret++)) + + isula rm embedded_test_symbolic +-- +2.42.0 + diff --git a/0038-save-sandbox-to-disk-after-network-ready.patch b/0038-save-sandbox-to-disk-after-network-ready.patch new file mode 100644 index 0000000000000000000000000000000000000000..3da9ae66818b0cde84c118c55ad5e9e4ba99ff6c --- /dev/null +++ b/0038-save-sandbox-to-disk-after-network-ready.patch @@ -0,0 +1,68 @@ +From e33b7915d9ef5092252bc3ce5d93fbde74d73990 Mon Sep 17 00:00:00 2001 +From: jikai +Date: Mon, 27 Nov 2023 15:09:39 +0800 +Subject: [PATCH 38/65] save sandbox to disk after network ready + +Signed-off-by: jikai +--- + .../cri/v1/v1_cri_pod_sandbox_manager_service.cc | 13 ++++++++++--- + src/daemon/sandbox/sandbox.cc | 6 ------ + 2 files changed, 10 insertions(+), 9 deletions(-) + +diff --git a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc +index 0f6b8508..a0c45111 100644 +--- a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc ++++ b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc +@@ -358,14 +358,21 @@ auto PodSandboxManagerService::RunPodSandbox(const runtime::v1::PodSandboxConfig + goto cleanup_sandbox; + } + +- // Step 8: Call sandbox create. ++ // Step 8: Save sandbox to disk ++ sandbox->Save(error); ++ if (error.NotEmpty()) { ++ ERROR("Failed to save sandbox, %s", sandboxName.c_str()); ++ goto cleanup_network; ++ } ++ ++ // Step 9: Call sandbox create. + sandbox->Create(error); + if (error.NotEmpty()) { + ERROR("Failed to create sandbox: %s", sandboxName.c_str()); + goto cleanup_network; + } + +- // Step 9: Save network settings json to disk ++ // Step 10: Save network settings json to disk + // Update network settings before start sandbox since sandbox container will use the sandbox key + if (namespace_is_cni(networkMode.c_str())) { + Errors tmpErr; +@@ -376,7 +383,7 @@ auto PodSandboxManagerService::RunPodSandbox(const runtime::v1::PodSandboxConfig + } + } + +- // Step 10: Call sandbox start. ++ // Step 11: Call sandbox start. + sandbox->Start(error); + if (error.NotEmpty()) { + ERROR("Failed to start sandbox: %s", sandboxName.c_str()); +diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc +index b1832265..9fe9fa48 100644 +--- a/src/daemon/sandbox/sandbox.cc ++++ b/src/daemon/sandbox/sandbox.cc +@@ -599,12 +599,6 @@ void Sandbox::PrepareSandboxDirs(Errors &error) + goto out; + } + +- if (!Save(error)) { +- error.Errorf("Failed to save sandbox, %s", m_id.c_str()); +- ERROR("Failed to save sandbox, %s", m_id.c_str()); +- goto out; +- } +- + umask(mask); + return; + +-- +2.42.0 + diff --git a/0039-fix-the-problem-of-abnormal-branches-not-waiting-for.patch b/0039-fix-the-problem-of-abnormal-branches-not-waiting-for.patch new file mode 100644 index 0000000000000000000000000000000000000000..ae0259a3defba568e5ca8fbb38b50e2dedfc4db2 --- /dev/null +++ b/0039-fix-the-problem-of-abnormal-branches-not-waiting-for.patch @@ -0,0 +1,153 @@ +From b26654a73694c20fcd895b3b93ad5d42a1d5b3fb Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 27 Nov 2023 14:52:43 +0800 +Subject: [PATCH 39/65] fix the problem of abnormal branches not waiting for + child processes + +Signed-off-by: zhongtao +--- + src/cmd/isulad-shim/common.c | 6 +++--- + src/cmd/isulad-shim/process.c | 14 ++++++++------ + src/daemon/modules/runtime/isula/isula_rt_ops.c | 16 ++++++++++------ + src/daemon/modules/runtime/shim/shim_rt_ops.c | 15 +++++++++------ + 4 files changed, 30 insertions(+), 21 deletions(-) + +diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c +index 48d266dc..3cc7d2a7 100644 +--- a/src/cmd/isulad-shim/common.c ++++ b/src/cmd/isulad-shim/common.c +@@ -126,12 +126,12 @@ int cmd_combined_output(const char *binary, const char *params[], void *output, + } + *output_len = isula_file_read_nointr(stdio[0], output, BUFSIZ - 1); + +- close(stdio[0]); +- close(exec_fd[0]); +- wait(&status); + ret = SHIM_OK; + + out: ++ close(stdio[0]); ++ close(exec_fd[0]); ++ wait(&status); + if (ret != SHIM_OK) { + kill(pid, 9); + } +diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c +index 187067d2..e8cb9b32 100644 +--- a/src/cmd/isulad-shim/process.c ++++ b/src/cmd/isulad-shim/process.c +@@ -1472,7 +1472,7 @@ static void exec_runtime_process(process_t *p, int exec_fd) + const char *params[MAX_RUNTIME_ARGS] = { 0 }; + get_runtime_cmd(p, log_path, pid_path, process_desc, params); + execvp(p->runtime, (char * const *)params); +- (void)dprintf(exec_fd, "fork/exec error: %s", strerror(errno)); ++ (void)dprintf(exec_fd, "run process: %s error: %s", p->runtime, strerror(errno)); + _exit(EXIT_FAILURE); + } + +@@ -1510,11 +1510,6 @@ int create_process(process_t *p) + close_fd(&p->stdio->resize); + } + nread = isula_file_read_nointr(exec_fd[0], exec_buff, sizeof(exec_buff) - 1); +- if (nread > 0) { +- write_message(ERR_MSG, "runtime error"); +- ret = SHIM_ERR; +- goto out; +- } + + /* block to wait runtime pid exit */ + ret = waitpid(pid, NULL, 0); +@@ -1524,6 +1519,13 @@ int create_process(process_t *p) + goto out; + } + ++ // if an error occurs in exec_runtime_process, jump directly to the out branch after waitpid. ++ if (nread > 0) { ++ write_message(ERR_MSG, "%s", exec_buff); ++ ret = SHIM_ERR; ++ goto out; ++ } ++ + /* save runtime pid */ + data = read_text_file("pid"); + if (data == NULL) { +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 859356e5..5d7ae500 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -906,17 +906,13 @@ realexec: + } + + execvp(SHIM_BINARY, (char * const *)params); +- (void)dprintf(shim_stderr_pipe[1], "exec failed: %s", strerror(errno)); ++ (void)dprintf(shim_stderr_pipe[1], "run process: %s failed: %s", SHIM_BINARY, strerror(errno)); ++ exit(EXIT_FAILURE); + } + + close(shim_stderr_pipe[1]); + close(shim_stdout_pipe[1]); + num = util_read_nointr(shim_stderr_pipe[0], exec_buff, sizeof(exec_buff) - 1); +- if (num > 0) { +- ERROR("Exec failed: %s", exec_buff); +- ret = -1; +- goto out; +- } + + status = util_wait_for_pid_status(pid); + if (status < 0) { +@@ -925,6 +921,14 @@ realexec: + goto out; + } + ++ // if failed to exec, jump directly to the out branch after waitpid. ++ if (num > 0) { ++ ERROR("%s", exec_buff); ++ isulad_set_error_message("%s", exec_buff); ++ ret = -1; ++ goto out; ++ } ++ + *shim_exit_code = status_to_exit_code(status); + if (*shim_exit_code != 0) { + ERROR("Isulad-shim exit error"); +diff --git a/src/daemon/modules/runtime/shim/shim_rt_ops.c b/src/daemon/modules/runtime/shim/shim_rt_ops.c +index 5066f804..81daf224 100644 +--- a/src/daemon/modules/runtime/shim/shim_rt_ops.c ++++ b/src/daemon/modules/runtime/shim/shim_rt_ops.c +@@ -251,17 +251,13 @@ static int shim_bin_v2_create(const char *runtime, const char *id, const char *w + } + + execvp(binary, (char * const *)params); +- (void)dprintf(exec_fd[1], "exec failed: %s", strerror(errno)); ++ (void)dprintf(exec_fd[1], "run process: %s failed: %s", binary, strerror(errno)); + exit(EXIT_FAILURE); + } + + close(exec_fd[1]); + exec_fd[1] = -1; +- if (util_read_nointr(exec_fd[0], exec_buff, sizeof(exec_buff) - 1) > 0) { +- ERROR("exec failed: %s", exec_buff); +- ret = -1; +- goto out; +- } ++ nret = util_read_nointr(exec_fd[0], exec_buff, sizeof(exec_buff) - 1); + close(exec_fd[0]); + exec_fd[0] = -1; + +@@ -272,6 +268,13 @@ static int shim_bin_v2_create(const char *runtime, const char *id, const char *w + goto out; + } + ++ // if failed to exec, jump directly to the out branch after waitpid. ++ if (nret > 0) { ++ ERROR("%s", exec_buff); ++ ret = -1; ++ goto out; ++ } ++ + status = status_to_exit_code(status); + + close(out_fd[1]); +-- +2.42.0 + diff --git a/0040-remove-embedded-image-support-in-readme.patch b/0040-remove-embedded-image-support-in-readme.patch new file mode 100644 index 0000000000000000000000000000000000000000..2908e6ae78594f17d0245ec60f60f18b5176851a --- /dev/null +++ b/0040-remove-embedded-image-support-in-readme.patch @@ -0,0 +1,62 @@ +From 6f9661d7e12e22ff4eeb76647cbe862c5fe7e18d Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 27 Nov 2023 20:50:33 +0800 +Subject: [PATCH 40/65] remove embedded image support in readme + +Signed-off-by: zhongtao +--- + README.md | 6 +----- + README_zh.md | 6 +----- + 2 files changed, 2 insertions(+), 10 deletions(-) + +diff --git a/README.md b/README.md +index e7949dee..970b6e72 100644 +--- a/README.md ++++ b/README.md +@@ -32,7 +32,7 @@ kata-runtime start secure containers with lightweight virtual machines. + + ### Image + +-`iSulad` supports multiple image formats, including OCI, external rootfs and embedded image. ++`iSulad` supports multiple image formats, including OCI and external rootfs. + + #### OCI + +@@ -42,10 +42,6 @@ OCI is a docker-compatible image format that supports pulling images and running + + External rootfs allows users to prepare a bootable `root fs` directory, which is mainly used in system container scenarios. + +-#### embedded image +- +-Embedded image is a unique embedded image format of `iSulad`, which occupies low resources and is mainly used in embedded application scenarios. +- + ### Operation Interface + + `iSulad` provides two different interfaces for image and container management operations: CLI and CRI. +diff --git a/README_zh.md b/README_zh.md +index 1c4dff4f..5db28f3a 100755 +--- a/README_zh.md ++++ b/README_zh.md +@@ -32,7 +32,7 @@ kata-runtime是一个安全容器runtime,用于启动安全容器时使用。 + + ### Image + +-`iSulad`支持多种镜像格式,包括OCI标准镜像格式、external rootfs镜像格式和embedded image镜像格式。 ++`iSulad`支持多种镜像格式,包括OCI标准镜像格式和external rootfs镜像格式。 + + #### OCI + +@@ -42,10 +42,6 @@ OCI标准镜像格式是与docker兼容的镜像格式,支持从远程镜像 + + external rootfs镜像格式允许用户自行准备可启动的`root fs`目录,主要用于系统容器场景。 + +-#### embedded image +- +-embedded image镜像格式是`iSulad`特有的嵌入式镜像格式,占用资源低,主要用于嵌入式应用场景。 +- + ### Operation Interface + + `iSulad`提供两种不同的镜像和容器管理操作接口,分别为CLI和CRI。 +-- +2.42.0 + diff --git a/0041-Acquire-system-info-in-on-demand.patch b/0041-Acquire-system-info-in-on-demand.patch new file mode 100644 index 0000000000000000000000000000000000000000..34e24adbd56ca2dd1e23893a714cb2dd89688f69 --- /dev/null +++ b/0041-Acquire-system-info-in-on-demand.patch @@ -0,0 +1,392 @@ +From 13bc364cb5d8c03b701dde2b2811be84ee608e92 Mon Sep 17 00:00:00 2001 +From: xuxuepeng +Date: Fri, 24 Nov 2023 14:18:32 +0800 +Subject: [PATCH 41/65] Acquire system info in on demand + +Signed-off-by: xuxuepeng +--- + src/cmd/isulad/main.c | 2 -- + src/daemon/common/sysinfo.c | 10 +----- + src/daemon/common/sysinfo.h | 6 ++++ + .../executor/container_cb/execution_create.c | 32 +++++++++---------- + .../executor/container_cb/execution_extend.c | 9 +++++- + src/daemon/modules/spec/verify.c | 32 ++++++++----------- + src/daemon/modules/spec/verify.h | 5 +-- + test/mocks/sysinfo_mock.cc | 8 +++++ + test/mocks/sysinfo_mock.h | 1 + + test/mocks/verify_mock.cc | 4 +-- + test/mocks/verify_mock.h | 2 +- + 11 files changed, 60 insertions(+), 51 deletions(-) + +diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c +index 5b971a72..95454e2a 100644 +--- a/src/cmd/isulad/main.c ++++ b/src/cmd/isulad/main.c +@@ -1765,8 +1765,6 @@ int main(int argc, char **argv) + + update_isulad_rlimits(); + +- (void)get_sys_info(true); +- + clock_gettime(CLOCK_MONOTONIC, &t_start); + + if (pre_init_daemon(argc, argv) != 0) { +diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c +index 39338925..28665834 100644 +--- a/src/daemon/common/sysinfo.c ++++ b/src/daemon/common/sysinfo.c +@@ -19,7 +19,6 @@ + #include + #include + +-#include + #include + + #include "err_msg.h" +@@ -30,8 +29,6 @@ + #define etcOsRelease "/etc/os-release" + #define altOsRelease "/usr/lib/os-release" + +-static sysinfo_t *g_sysinfo = NULL; +- + static char *get_pagesize(const char *pline) + { + size_t headlen; +@@ -382,10 +379,6 @@ sysinfo_t *get_sys_info(bool quiet) + sysinfo_t *sysinfo = NULL; + int ret = 0; + +- if (g_sysinfo != NULL) { +- return g_sysinfo; +- } +- + sysinfo = util_common_calloc_s(sizeof(sysinfo_t)); + if (sysinfo == NULL) { + ERROR("Out of memory"); +@@ -413,7 +406,6 @@ sysinfo_t *get_sys_info(bool quiet) + if (ret != 0) { + goto out; + } +- g_sysinfo = sysinfo; + out: + if (ret != 0) { + free_sysinfo(sysinfo); +@@ -577,7 +569,7 @@ char *sysinfo_cgroup_controller_cpurt_mnt_path(void) + __isula_auto_free char *mnt = NULL; + __isula_auto_free char *root = NULL; + char fpath[PATH_MAX] = { 0 }; +- sysinfo_t *sysinfo = NULL; ++ __isula_auto_sysinfo_t sysinfo_t *sysinfo = NULL; + + sysinfo = get_sys_info(true); + if (sysinfo == NULL) { +diff --git a/src/daemon/common/sysinfo.h b/src/daemon/common/sysinfo.h +index 363576a9..cb44d1c5 100644 +--- a/src/daemon/common/sysinfo.h ++++ b/src/daemon/common/sysinfo.h +@@ -21,6 +21,7 @@ extern "C" { + + #include + #include ++#include + + #include "cgroup.h" + +@@ -96,6 +97,11 @@ void free_mounts_info(mountinfo_t **minfos); + + char *sysinfo_cgroup_controller_cpurt_mnt_path(void); + ++// define auto free function callback for sysinfo_t ++define_auto_cleanup_callback(free_sysinfo, sysinfo_t) ++// define auto free macro for sysinfo_t ++#define __isula_auto_sysinfo_t auto_cleanup_tag(free_sysinfo) ++ + #ifdef __cplusplus + } + #endif +diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c +index 6b6c3b75..ca2a9163 100644 +--- a/src/daemon/executor/container_cb/execution_create.c ++++ b/src/daemon/executor/container_cb/execution_create.c +@@ -145,7 +145,7 @@ static int merge_external_rootfs_to_host_config(host_config *host_spec, const ch + return 0; + } + +-static host_config *get_host_spec(const container_create_request *request) ++static host_config *get_host_spec(const container_create_request *request, const sysinfo_t *sysinfo) + { + host_config *host_spec = NULL; + +@@ -158,7 +158,7 @@ static host_config *get_host_spec(const container_create_request *request) + goto error_out; + } + +- if (verify_host_config_settings(host_spec, false)) { ++ if (verify_host_config_settings(host_spec, sysinfo, false)) { + ERROR("Failed to verify host config settings"); + goto error_out; + } +@@ -1109,17 +1109,9 @@ static int preparate_runtime_environment(const container_create_request *request + return 0; + } + +-static int adapt_host_spec(host_config *host_spec) ++static int adapt_host_spec(host_config *host_spec, const sysinfo_t *sysinfo) + { + int ret = 0; +- sysinfo_t *sysinfo = NULL; +- +- sysinfo = get_sys_info(true); +- if (sysinfo == NULL) { +- ERROR("Can not get system info"); +- ret = -1; +- goto out; +- } + + if (host_spec->memory > 0 && host_spec->memory_swap == 0 && sysinfo->cgmeminfo.swap) { + if (host_spec->memory > (INT64_MAX / 2)) { +@@ -1136,14 +1128,14 @@ out: + } + + static int get_basic_spec(const container_create_request *request, host_config **host_spec, +- container_config **container_spec) ++ container_config **container_spec, const sysinfo_t *sysinfo) + { +- *host_spec = get_host_spec(request); ++ *host_spec = get_host_spec(request, sysinfo); + if (*host_spec == NULL) { + return -1; + } + +- if (adapt_host_spec(*host_spec) != 0) { ++ if (adapt_host_spec(*host_spec, sysinfo) != 0) { + return -1; + } + +@@ -1393,6 +1385,7 @@ int container_create_cb(const container_create_request *request, container_creat + int ret = 0; + bool skip_id_name_manage = false; + bool skip_sandbox_key_manage = false; ++ __isula_auto_sysinfo_t sysinfo_t *sysinfo = NULL; + + DAEMON_CLEAR_ERRMSG(); + +@@ -1413,7 +1406,14 @@ int container_create_cb(const container_create_request *request, container_creat + goto clean_nameindex; + } + +- if (get_basic_spec(request, &host_spec, &container_spec) != 0) { ++ sysinfo = get_sys_info(true); ++ if (sysinfo == NULL) { ++ ERROR("Failed to get system info"); ++ cc = ISULAD_ERR_EXEC; ++ goto clean_nameindex; ++ } ++ ++ if (get_basic_spec(request, &host_spec, &container_spec, sysinfo) != 0) { + cc = ISULAD_ERR_INPUT; + goto clean_container_root_dir; + } +@@ -1540,7 +1540,7 @@ int container_create_cb(const container_create_request *request, container_creat + goto clean_netns; + } + +- if (verify_container_settings(oci_spec) != 0) { ++ if (verify_container_settings(oci_spec, sysinfo) != 0) { + ERROR("Failed to verify container settings"); + cc = ISULAD_ERR_EXEC; + goto umount_channel; +diff --git a/src/daemon/executor/container_cb/execution_extend.c b/src/daemon/executor/container_cb/execution_extend.c +index de017b4e..25ec5d3b 100644 +--- a/src/daemon/executor/container_cb/execution_extend.c ++++ b/src/daemon/executor/container_cb/execution_extend.c +@@ -1110,8 +1110,15 @@ static int update_host_config_check(container_t *cont, host_config *hostconfig) + { + int ret = 0; + const char *id = cont->common_config->id; ++ __isula_auto_sysinfo_t sysinfo_t *sysinfo = NULL; + +- ret = verify_host_config_settings(hostconfig, true); ++ sysinfo = get_sys_info(true); ++ if (sysinfo == NULL) { ++ ERROR("Failed to get system info for updating container %s", id); ++ return -1; ++ } ++ ++ ret = verify_host_config_settings(hostconfig, sysinfo, true); + if (ret != 0) { + return -1; + } +diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c +index 2a8b3259..b9e3c606 100644 +--- a/src/daemon/modules/spec/verify.c ++++ b/src/daemon/modules/spec/verify.c +@@ -41,7 +41,6 @@ + #include "constants.h" + #include "err_msg.h" + #include "isula_libutils/log.h" +-#include "sysinfo.h" + #include "selinux_label.h" + #include "image_api.h" + #include "utils.h" +@@ -1614,16 +1613,13 @@ out: + } + + /* verify container settings */ +-int verify_container_settings(const oci_runtime_spec *container) ++int verify_container_settings(const oci_runtime_spec *container, const sysinfo_t *sysinfo) + { + int ret = 0; +- sysinfo_t *sysinfo = NULL; + +- sysinfo = get_sys_info(true); +- if (sysinfo == NULL) { +- ERROR("Can not get system info"); +- ret = -1; +- goto out; ++ if (container == NULL || sysinfo == NULL) { ++ ERROR("Invalid input arguments for verifying container settings"); ++ return -1; + } + + if (!util_valid_host_name(container->hostname)) { +@@ -1987,16 +1983,9 @@ static int host_config_settings_restart_policy(const host_config *hostconfig) + return verify_restart_policy_name(rp, hostconfig); + } + +-static int host_config_settings_with_sysinfo(host_config *hostconfig, bool update) ++static int host_config_settings_with_sysinfo(host_config *hostconfig, const sysinfo_t *sysinfo, bool update) + { + int ret = 0; +- sysinfo_t *sysinfo = NULL; +- +- sysinfo = get_sys_info(true); +- if (sysinfo == NULL) { +- ERROR("Can not get system info"); +- return -1; +- } + + ret = verify_host_config_hugetlbs(sysinfo, &(hostconfig->hugetlbs), &(hostconfig->hugetlbs_len)); + if (ret != 0) { +@@ -2055,7 +2044,7 @@ out: + } + + /* verify host config settings */ +-int verify_host_config_settings(host_config *hostconfig, bool update) ++int verify_host_config_settings(host_config *hostconfig, const sysinfo_t *sysinfo, bool update) + { + int ret = 0; + #ifdef ENABLE_USERNS_REMAP +@@ -2066,6 +2055,13 @@ int verify_host_config_settings(host_config *hostconfig, bool update) + goto out; + } + ++ if (sysinfo == NULL) { ++ ERROR("Invalid sysinfo for verifying host config settings"); ++ isulad_set_error_message("Invalid sysinfo for verifying host config settings"); ++ ret = -1; ++ goto out; ++ } ++ + #ifdef ENABLE_USERNS_REMAP + if (userns_remap != NULL && hostconfig->user_remap != NULL) { + ERROR("invalid --user-remap command option, daemon already configed --userns-remap"); +@@ -2081,7 +2077,7 @@ int verify_host_config_settings(host_config *hostconfig, bool update) + goto out; + } + +- ret = host_config_settings_with_sysinfo(hostconfig, update); ++ ret = host_config_settings_with_sysinfo(hostconfig, sysinfo, update); + if (ret != 0) { + goto out; + } +diff --git a/src/daemon/modules/spec/verify.h b/src/daemon/modules/spec/verify.h +index 21e8fba8..0224f9fb 100644 +--- a/src/daemon/modules/spec/verify.h ++++ b/src/daemon/modules/spec/verify.h +@@ -20,18 +20,19 @@ + #include "isula_libutils/oci_runtime_spec.h" + #include "isula_libutils/host_config.h" + #include "isula_libutils/container_config.h" ++#include "sysinfo.h" + + #ifdef __cplusplus + extern "C" { + #endif + +-int verify_container_settings(const oci_runtime_spec *container); ++int verify_container_settings(const oci_runtime_spec *container, const sysinfo_t *sysinfo); + + int verify_oci_hook(const oci_runtime_spec_hooks *h); + + int verify_container_settings_start(const oci_runtime_spec *oci_spec); + +-int verify_host_config_settings(host_config *hostconfig, bool update); ++int verify_host_config_settings(host_config *hostconfig, const sysinfo_t *sysinfo, bool update); + + int verify_container_config(const container_config *container_spec, const char *runtime); + +diff --git a/test/mocks/sysinfo_mock.cc b/test/mocks/sysinfo_mock.cc +index f9abc786..d8f33f84 100644 +--- a/test/mocks/sysinfo_mock.cc ++++ b/test/mocks/sysinfo_mock.cc +@@ -63,6 +63,14 @@ char *validate_hugetlb(const char *pagesize, uint64_t limit) + return nullptr; + } + ++sysinfo_t *get_sys_info(bool quiet) ++{ ++ if (g_sysinfo_mock != nullptr) { ++ return g_sysinfo_mock->GetSysInfo(quiet); ++ } ++ return nullptr; ++} ++ + void free_sysinfo(sysinfo_t *sysinfo) + { + if (g_sysinfo_mock != nullptr) { +diff --git a/test/mocks/sysinfo_mock.h b/test/mocks/sysinfo_mock.h +index 45208b0f..2b8e926d 100644 +--- a/test/mocks/sysinfo_mock.h ++++ b/test/mocks/sysinfo_mock.h +@@ -26,6 +26,7 @@ public: + MOCK_METHOD1(FreeMountsInfo, void(mountinfo_t **minfos)); + MOCK_METHOD0(GetDefaultHugePageSize, char *(void)); + MOCK_METHOD2(ValidateHugetlb, char*(const char *pagesize, uint64_t limit)); ++ MOCK_METHOD1(GetSysInfo, sysinfo_t *(bool quiet)); + MOCK_METHOD1(FreeSysinfo, void(sysinfo_t *sysinfo)); + }; + +diff --git a/test/mocks/verify_mock.cc b/test/mocks/verify_mock.cc +index 0e7e7461..4c481676 100644 +--- a/test/mocks/verify_mock.cc ++++ b/test/mocks/verify_mock.cc +@@ -24,10 +24,10 @@ void MockVerify_SetMock(MockVerify *mock) + g_verify_mock = mock; + } + +-int verify_host_config_settings(host_config *hostconfig, bool update) ++int verify_host_config_settings(host_config *hostconfig, const sysinfo_t *sysinfo, bool update) + { + if (g_verify_mock != nullptr) { +- return g_verify_mock->VerifyHostConfigSettings(hostconfig, update); ++ return g_verify_mock->VerifyHostConfigSettings(hostconfig, sysinfo, update); + } + return 0; + } +diff --git a/test/mocks/verify_mock.h b/test/mocks/verify_mock.h +index 7890159f..b9ad8627 100644 +--- a/test/mocks/verify_mock.h ++++ b/test/mocks/verify_mock.h +@@ -21,7 +21,7 @@ + + class MockVerify { + public: +- MOCK_METHOD2(VerifyHostConfigSettings, int(host_config *hostconfig, bool update)); ++ MOCK_METHOD3(VerifyHostConfigSettings, int(host_config *hostconfig, const sysinfo_t *sysinfo, bool update)); + }; + + void MockVerify_SetMock(MockVerify* mock); +-- +2.42.0 + diff --git a/0042-2268-bugfix-for-the-bliko-zero-value-exception-when-.patch b/0042-2268-bugfix-for-the-bliko-zero-value-exception-when-.patch new file mode 100644 index 0000000000000000000000000000000000000000..8a7e8a9b024b8afa5e126bbe83cf2e2c3eb729cf --- /dev/null +++ b/0042-2268-bugfix-for-the-bliko-zero-value-exception-when-.patch @@ -0,0 +1,92 @@ +From dddba4ec73b56bc2fcf3a95171fad104e962dfda Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Wed, 29 Nov 2023 09:33:53 +0000 +Subject: [PATCH 42/65] =?UTF-8?q?!2268=20bugfix=20for=20the=20bliko=20zero?= + =?UTF-8?q?=20value=20exception=20when=20executing=20the=20stats=20command?= + =?UTF-8?q?=20on=20the=20oci=20container=20*=20bugfix=20for=20the=20bliko?= + =?UTF-8?q?=20zero=20value=20exception=20when=20executing=20the=20stats=20?= + =?UTF-8?q?com=E2=80=A6?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + .../modules/runtime/isula/isula_rt_ops.c | 55 +++++++++++++------ + 1 file changed, 38 insertions(+), 17 deletions(-) + +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 5d7ae500..1e2ecdb2 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -610,6 +610,43 @@ out: + return ret; + } + ++static void transform_stats_info_from_runtime(shim_client_runtime_stats *stats, struct runtime_container_resources_stats_info *info) ++{ ++ if (stats == NULL || stats->data == NULL) { ++ return; ++ } ++ if (stats->data->pids != NULL) { ++ info->pids_current = stats->data->pids->current; ++ } ++ if (stats->data->cpu != NULL && stats->data->cpu->usage != NULL) { ++ info->cpu_use_nanos = stats->data->cpu->usage->total; ++ info->cpu_system_use = stats->data->cpu->usage->kernel; ++ } ++ shim_client_runtime_stats_data_memory *memory = stats->data->memory; ++ if (memory != NULL && memory->usage != NULL) { ++ info->mem_used = memory->usage->usage; ++ info->mem_limit = memory->usage->limit; ++ } ++ if (memory != NULL && memory->raw != NULL) { ++ info->inactive_file_total = memory->raw->total_inactive_file; ++ info->rss_bytes = memory->raw->rss; ++ info->page_faults = memory->raw->pgfault; ++ info->major_page_faults = memory->raw->pgmajfault; ++ } ++ shim_client_runtime_stats_data_blkio *blkio = stats->data->blkio; ++ if (blkio == NULL) { ++ return; ++ } ++ for (size_t i = 0; i < blkio->io_service_bytes_recursive_len; i++) { ++ if (strcasecmp(blkio->io_service_bytes_recursive[i]->op, "read") == 0) { ++ info->blkio_read += blkio->io_service_bytes_recursive[i]->value; ++ } ++ if (strcasecmp(blkio->io_service_bytes_recursive[i]->op, "write") == 0) { ++ info->blkio_write += blkio->io_service_bytes_recursive[i]->value; ++ } ++ } ++} ++ + static int runtime_call_stats(const char *workdir, const char *runtime, const char *id, + struct runtime_container_resources_stats_info *info) + { +@@ -658,23 +695,7 @@ static int runtime_call_stats(const char *workdir, const char *runtime, const ch + goto out; + } + +- if (stats != NULL && stats->data != NULL && stats->data->pids != NULL) { +- info->pids_current = stats->data->pids->current; +- } +- if (stats != NULL && stats->data != NULL && stats->data->cpu != NULL && stats->data->cpu->usage) { +- info->cpu_use_nanos = stats->data->cpu->usage->total; +- info->cpu_system_use = stats->data->cpu->usage->kernel; +- } +- if (stats != NULL && stats->data != NULL && stats->data->memory != NULL && stats->data->memory->usage) { +- info->mem_used = stats->data->memory->usage->usage; +- info->mem_limit = stats->data->memory->usage->limit; +- } +- if (stats != NULL && stats->data != NULL && stats->data->memory != NULL && stats->data->memory->raw) { +- info->inactive_file_total = stats->data->memory->raw->total_inactive_file; +- info->rss_bytes = stats->data->memory->raw->rss; +- info->page_faults = stats->data->memory->raw->pgfault; +- info->major_page_faults = stats->data->memory->raw->pgmajfault; +- } ++ transform_stats_info_from_runtime(stats, info); + + out: + free_shim_client_runtime_stats(stats); +-- +2.42.0 + diff --git a/0043-move-variable-declaration-out-of-loop.patch b/0043-move-variable-declaration-out-of-loop.patch new file mode 100644 index 0000000000000000000000000000000000000000..5125c327fb6ab6893db6f7e84786477b9fdc1ffa --- /dev/null +++ b/0043-move-variable-declaration-out-of-loop.patch @@ -0,0 +1,34 @@ +From 261a924b656eea9eff2ca6cbdd611eb1f9555af7 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Thu, 30 Nov 2023 16:02:44 +1400 +Subject: [PATCH 43/65] move variable declaration out of loop + +Signed-off-by: zhongtao +--- + src/daemon/modules/runtime/isula/isula_rt_ops.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 1e2ecdb2..3950ff4a 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -612,6 +612,7 @@ out: + + static void transform_stats_info_from_runtime(shim_client_runtime_stats *stats, struct runtime_container_resources_stats_info *info) + { ++ size_t i; + if (stats == NULL || stats->data == NULL) { + return; + } +@@ -637,7 +638,7 @@ static void transform_stats_info_from_runtime(shim_client_runtime_stats *stats, + if (blkio == NULL) { + return; + } +- for (size_t i = 0; i < blkio->io_service_bytes_recursive_len; i++) { ++ for (i = 0; i < blkio->io_service_bytes_recursive_len; i++) { + if (strcasecmp(blkio->io_service_bytes_recursive[i]->op, "read") == 0) { + info->blkio_read += blkio->io_service_bytes_recursive[i]->value; + } +-- +2.42.0 + diff --git a/0044-2289-check-protobuf-and-grpc-version-in-cmake-for-cr.patch b/0044-2289-check-protobuf-and-grpc-version-in-cmake-for-cr.patch new file mode 100644 index 0000000000000000000000000000000000000000..514fe3907226c0d3ab85221fd72efab42da40d60 --- /dev/null +++ b/0044-2289-check-protobuf-and-grpc-version-in-cmake-for-cr.patch @@ -0,0 +1,40 @@ +From 8045fcfb3765698d8cc3f07186fcc29d6702ee71 Mon Sep 17 00:00:00 2001 +From: jake +Date: Thu, 30 Nov 2023 11:58:47 +0000 +Subject: [PATCH 44/65] !2289 check protobuf and grpc version in cmake for cri + v1 * check protobuf and grpc version in cmake for cri v1 + +--- + cmake/checker.cmake | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/cmake/checker.cmake b/cmake/checker.cmake +index cc4a1fc3..e19618e4 100644 +--- a/cmake/checker.cmake ++++ b/cmake/checker.cmake +@@ -125,7 +125,11 @@ endif() + + if (GRPC_CONNECTOR) + # check protobuf +- pkg_check_modules(PC_PROTOBUF "protobuf>=3.1.0") ++ if (ENABLE_CRI_API_V1) ++ pkg_check_modules(PC_PROTOBUF "protobuf>=3.14.0") ++ else() ++ pkg_check_modules(PC_PROTOBUF "protobuf>=3.1.0") ++ endif() + find_library(PROTOBUF_LIBRARY protobuf + HINTS ${PC_PROTOBUF_LIBDIR} ${PC_PROTOBUF_LIBRARY_DIRS}) + _CHECK(PROTOBUF_LIBRARY "PROTOBUF_LIBRARY-NOTFOUND" "libprotobuf.so") +@@ -136,6 +140,9 @@ if (GRPC_CONNECTOR) + _CHECK(CMD_GRPC_CPP_PLUGIN "CMD_GRPC_CPP_PLUGIN-NOTFOUND" "grpc_cpp_plugin") + + # check grpc ++ if (ENABLE_CRI_API_V1) ++ pkg_check_modules(PC_GRPC++ "grpc++>=1.41.0") ++ endif() + find_path(GRPC_INCLUDE_DIR grpc/grpc.h) + _CHECK(GRPC_INCLUDE_DIR "GRPC_INCLUDE_DIR-NOTFOUND" "grpc/grpc.h") + find_library(GRPC_PP_REFLECTION_LIBRARY grpc++_reflection) +-- +2.42.0 + diff --git a/0045-improve-ut-for-devicemapper.patch b/0045-improve-ut-for-devicemapper.patch new file mode 100644 index 0000000000000000000000000000000000000000..a4454613f7f72bd1b8267a6ebdd5172f99de2a7b --- /dev/null +++ b/0045-improve-ut-for-devicemapper.patch @@ -0,0 +1,381 @@ +From 2ad7ecf5adbd75f1ba4678e69d768d4b807ae08d Mon Sep 17 00:00:00 2001 +From: jikai +Date: Wed, 29 Nov 2023 17:08:31 +0800 +Subject: [PATCH 45/65] improve ut for devicemapper + +Signed-off-by: jikai +--- + .../storage/layers/devmapper/CMakeLists.txt | 8 +- + .../id | 1 + + .../layers/devmapper/driver_devmapper_ut.cc | 209 +++++++++++++----- + 3 files changed, 165 insertions(+), 53 deletions(-) + create mode 100644 test/image/oci/storage/layers/devmapper/data/devicemapper/mnt/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d/id + +diff --git a/test/image/oci/storage/layers/devmapper/CMakeLists.txt b/test/image/oci/storage/layers/devmapper/CMakeLists.txt +index f98de1a8..e6ba0307 100644 +--- a/test/image/oci/storage/layers/devmapper/CMakeLists.txt ++++ b/test/image/oci/storage/layers/devmapper/CMakeLists.txt +@@ -23,14 +23,18 @@ add_executable(${DRIVER_DEVMAPPER_EXE} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/tar/util_gzip.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/utils/sha256/sha256.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/config/daemon_arguments.c +- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/config/isulad_config.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/common/err_msg.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/common/selinux_label.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../mocks/libdevmapper_mock.cc ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../mocks/isulad_config_mock.cc + driver_devmapper_ut.cc) + + target_include_directories(${DRIVER_DEVMAPPER_EXE} PUBLIC +@@ -56,7 +60,7 @@ target_include_directories(${DRIVER_DEVMAPPER_EXE} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../mocks + ) + +-set_target_properties(${DRIVER_DEVMAPPER_EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_exec_cmd -Wl,--wrap,util_mount -Wl,--wrap,umount2") ++set_target_properties(${DRIVER_DEVMAPPER_EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_exec_cmd -Wl,--wrap,util_mount -Wl,--wrap,umount2 -Wl,--wrap,archive_unpack") + + target_link_libraries(${DRIVER_DEVMAPPER_EXE} + ${GTEST_BOTH_LIBRARIES} +diff --git a/test/image/oci/storage/layers/devmapper/data/devicemapper/mnt/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d/id b/test/image/oci/storage/layers/devmapper/data/devicemapper/mnt/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d/id +new file mode 100644 +index 00000000..5e6b1b2a +--- /dev/null ++++ b/test/image/oci/storage/layers/devmapper/data/devicemapper/mnt/068615102be4457b22d40c9702e4bd316dd50ae85467b0378a419b23b60ba73d/id +@@ -0,0 +1 @@ ++3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f +\ No newline at end of file +diff --git a/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc b/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc +index 59e53f97..088aa4d4 100644 +--- a/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc ++++ b/test/image/oci/storage/layers/devmapper/driver_devmapper_ut.cc +@@ -16,11 +16,16 @@ + #include + #include + ++#include "driver.h" + #include "driver_devmapper.h" ++#include "driver_overlay2.h" + #include "mock.h" + #include "path.h" + #include "utils.h" ++#include "util_archive.h" + #include "libdevmapper_mock.h" ++#include "isulad_config_mock.h" ++#include "wrapper_devmapper.h" + + using ::testing::Invoke; + using ::testing::NiceMock; +@@ -29,13 +34,20 @@ using ::testing::_; + + extern "C" { + DECLARE_WRAPPER_V(util_exec_cmd, bool, (exec_func_t cb_func, void *args, const char *stdin_msg, char **stdout_msg, char **stderr_msg)); +- DEFINE_WRAPPER_V(util_exec_cmd, bool, (exec_func_t cb_func, void *args, const char *stdin_msg, char **stdout_msg, char **stderr_msg), (cb_func, args, stdin_msg, stdout_msg, stderr_msg)); ++ DEFINE_WRAPPER_V(util_exec_cmd, bool, (exec_func_t cb_func, void *args, const char *stdin_msg, char **stdout_msg, char **stderr_msg), ++ (cb_func, args, stdin_msg, stdout_msg, stderr_msg)); + + DECLARE_WRAPPER(util_mount, int, (const char *src, const char *dst, const char *mtype, const char *mntopts)); + DEFINE_WRAPPER(util_mount, int, (const char *src, const char *dst, const char *mtype, const char *mntopts), (src, dst, mtype, mntopts)); + + DECLARE_WRAPPER(umount2, int, (const char *__special_file, int __flags)); + DEFINE_WRAPPER(umount2, int, (const char *__special_file, int __flags), (__special_file, __flags)); ++ ++ DECLARE_WRAPPER(archive_unpack, int, (const io_read_wrapper *content, const char *dstdir, const archive_options *options, ++ const char *root_dir, char **errmsg)); ++ DEFINE_WRAPPER(archive_unpack, int, (const io_read_wrapper *content, const char *dstdir, const archive_options *options, ++ const char *root_dir, char **errmsg), ++ (content, dstdir, options, root_dir, errmsg)); + } + + static std::string GetDirectory() +@@ -118,6 +130,7 @@ protected: + void SetUp() override + { + MockLibdevmapper_SetMock(&m_libdevmapper_mock); ++ MockIsuladConf_SetMock(&m_isulad_conf_mock); + std::string isulad_dir { "/tmp/isulad/" }; + mkdir(isulad_dir.c_str(), 0755); + std::string root_dir = isulad_dir + "data"; +@@ -129,13 +142,18 @@ protected: + std::string cp_command = "cp -r " + std::string(data_path) + " " + isulad_dir; + ASSERT_EQ(system(cp_command.c_str()), 0); + +- char **driver_opts = static_cast(util_common_calloc_s(3 * sizeof(char *))); +- driver_opts[0] = strdup("dm.thinpooldev=/dev/mapper/isulad0-thinpool"); +- driver_opts[1] = strdup("dm.fs=ext4"); +- driver_opts[2] = strdup("dm.min_free_space=10%"); +- int driver_opts_len = 3; +- +- ASSERT_EQ(devmapper_init(&driver, nullptr, (const char **)driver_opts, driver_opts_len), -1); ++ opts = (struct storage_module_init_options *)util_common_calloc_s(sizeof(struct storage_module_init_options)); ++ opts->storage_root = strdup(root_dir.c_str()); ++ opts->storage_run_root = strdup(run_dir.c_str()); ++ opts->driver_name = strdup("devicemapper"); ++ opts->driver_opts = (char **)util_common_calloc_s(6 * sizeof(char *)); ++ opts->driver_opts[0] = strdup("dm.thinpooldev=/dev/mapper/isulad0-thinpool"); ++ opts->driver_opts[1] = strdup("dm.fs=ext4"); ++ opts->driver_opts[2] = strdup("dm.min_free_space=10%"); ++ opts->driver_opts[3] = strdup("dm.basesize=12G"); ++ opts->driver_opts[4] = strdup("dm.mkfsarg=-q"); ++ opts->driver_opts[5] = strdup("dm.mountopt=rw"); ++ opts->driver_opts_len = 6; + + EXPECT_CALL(m_libdevmapper_mock, DMTaskCreate(_)).WillRepeatedly(Invoke(invokeDMTaskCreate)); + EXPECT_CALL(m_libdevmapper_mock, DMTaskSetMessage(_, _)).WillRepeatedly(Return(1)); +@@ -152,7 +170,6 @@ protected: + EXPECT_CALL(m_libdevmapper_mock, DMUdevComplete(_)).WillRepeatedly(Return(1)); + EXPECT_CALL(m_libdevmapper_mock, DMTaskDeferredRemove(_)).WillRepeatedly(Return(1)); + +- + char *names = static_cast(util_common_calloc_s(sizeof(struct dm_names) + strlen("isulad0-pool") + 1)); + struct dm_names *dname = (struct dm_names *)names; + dname->dev = 1; +@@ -164,32 +181,76 @@ protected: + EXPECT_CALL(m_libdevmapper_mock, DMUdevGetSyncSupport()).WillOnce(Return(1)); + + MOCK_SET_V(util_exec_cmd, invokeUtilExecCmd); +- +- ASSERT_EQ(devmapper_init(&driver, driver_home.c_str(), (const char **)driver_opts, driver_opts_len), 0); ++ MOCK_SET(util_mount, 0); ++ MOCK_SET(umount2, 0); ++ ASSERT_EQ(graphdriver_init(opts), 0); + MOCK_CLEAR(util_exec_cmd); +- +- util_free_array_by_len(driver_opts, driver_opts_len); +- free(names); ++ MOCK_CLEAR(util_mount); ++ MOCK_CLEAR(umount2); + } + + void TearDown() override + { ++ MOCK_SET(umount2, 0); ++ ASSERT_EQ(graphdriver_cleanup(), 0); ++ MOCK_CLEAR(umount2); ++ + MockLibdevmapper_SetMock(nullptr); ++ MockIsuladConf_SetMock(nullptr); + std::string rm_command = "rm -rf /tmp/isulad/"; + ASSERT_EQ(system(rm_command.c_str()), 0); ++ ++ if (opts != NULL) { ++ free(opts->storage_root); ++ free(opts->storage_run_root); ++ free(opts->driver_name); ++ util_free_array_by_len(opts->driver_opts, opts->driver_opts_len); ++ free(opts); ++ } + } + + NiceMock m_libdevmapper_mock; ++ NiceMock m_isulad_conf_mock; + char data_path[PATH_MAX] = { 0x00 }; +- graphdriver driver = {.ops = nullptr, .name = "devicemapper", }; ++ struct storage_module_init_options *opts = NULL; + }; + ++TEST_F(DriverDevmapperUnitTest, test_devmapper_init) ++{ ++ // cleanup before ++ MOCK_SET(umount2, 0); ++ ASSERT_EQ(graphdriver_cleanup(), 0); ++ MOCK_CLEAR(umount2); ++ ++ std::string rm_command = "rm -rf /tmp/isulad/"; ++ ASSERT_EQ(system(rm_command.c_str()), 0); ++ std::string mk_command = "mkdir -p /tmp/isulad/data/devicemapper/mnt"; ++ ASSERT_EQ(system(mk_command.c_str()), 0); ++ char *names = static_cast(util_common_calloc_s(sizeof(struct dm_names) + strlen("isulad0-pool") + 1)); ++ struct dm_names *dname = (struct dm_names *)names; ++ dname->dev = 1; ++ dname->next = 0; ++ strcpy(names + sizeof(struct dm_names), "isulad0-pool"); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskGetNames(_)).WillOnce(Return(dname)); ++ EXPECT_CALL(m_libdevmapper_mock, DMSetDevDir(_)).WillOnce(Return(1)); ++ EXPECT_CALL(m_libdevmapper_mock, DMTaskGetDriverVersion(_, _, _)).WillOnce(Invoke(invokeDMTaskGetDriverVersion)); ++ EXPECT_CALL(m_libdevmapper_mock, DMUdevGetSyncSupport()).WillOnce(Return(1)); ++ ++ MOCK_SET_V(util_exec_cmd, invokeUtilExecCmd); ++ MOCK_SET(util_mount, 0); ++ MOCK_SET(umount2, 0); ++ ASSERT_EQ(graphdriver_init(opts), 0); ++ MOCK_CLEAR(util_exec_cmd); ++ MOCK_CLEAR(util_mount); ++ MOCK_CLEAR(umount2); ++} ++ + TEST_F(DriverDevmapperUnitTest, test_devmapper_layer_exists) + { + std::string id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; + std::string incorrectId { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" }; +- ASSERT_TRUE(devmapper_layer_exist(id.c_str(), &driver)); +- ASSERT_FALSE(devmapper_layer_exist(incorrectId.c_str(), &driver)); ++ ASSERT_TRUE(graphdriver_layer_exists(id.c_str())); ++ ASSERT_FALSE(graphdriver_layer_exists(incorrectId.c_str())); + } + + TEST_F(DriverDevmapperUnitTest, test_devmapper_create_rw) +@@ -205,11 +266,42 @@ TEST_F(DriverDevmapperUnitTest, test_devmapper_create_rw) + create_opts->storage_opt->keys = static_cast(util_common_calloc_s(sizeof(char *))); + create_opts->storage_opt->values = static_cast(util_common_calloc_s(sizeof(char *))); + create_opts->storage_opt->keys[0] = strdup("size"); +- create_opts->storage_opt->values[0] = strdup("10G"); ++ create_opts->storage_opt->values[0] = strdup("12G"); ++ create_opts->storage_opt->len = 1; ++ ++ ASSERT_EQ(graphdriver_create_rw(id.c_str(), nullptr, create_opts), 0); ++ ASSERT_TRUE(graphdriver_layer_exists(id.c_str())); ++ free_driver_create_opts(create_opts); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_create_ro) ++{ ++ std::string id { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" }; ++ struct driver_create_opts *create_opts; ++ ++ create_opts = (struct driver_create_opts *)util_common_calloc_s(sizeof(struct driver_create_opts)); ++ ASSERT_NE(create_opts, nullptr); ++ ++ create_opts->storage_opt = static_cast(util_common_calloc_s(sizeof(json_map_string_string))); ++ ASSERT_NE(create_opts->storage_opt, nullptr); ++ create_opts->storage_opt->keys = static_cast(util_common_calloc_s(sizeof(char *))); ++ create_opts->storage_opt->values = static_cast(util_common_calloc_s(sizeof(char *))); ++ create_opts->storage_opt->keys[0] = strdup("size"); ++ create_opts->storage_opt->values[0] = strdup("12G"); + create_opts->storage_opt->len = 1; + +- ASSERT_EQ(devmapper_create_rw(id.c_str(), nullptr, &driver, create_opts), 0); +- ASSERT_TRUE(devmapper_layer_exist(id.c_str(), &driver)); ++ ASSERT_EQ(graphdriver_create_ro(id.c_str(), nullptr, create_opts), 0); ++ ASSERT_TRUE(graphdriver_layer_exists(id.c_str())); ++ free_driver_create_opts(create_opts); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_rm_layer) ++{ ++ std::string existed_id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; ++ std::string not_existed_id { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" }; ++ ++ ASSERT_EQ(graphdriver_rm_layer(existed_id.c_str()), 0); ++ ASSERT_EQ(graphdriver_rm_layer(not_existed_id.c_str()), 0); + } + + TEST_F(DriverDevmapperUnitTest, test_devmapper_mount_layer) +@@ -220,12 +312,12 @@ TEST_F(DriverDevmapperUnitTest, test_devmapper_mount_layer) + char* mount_dir = nullptr; + + MOCK_SET(util_mount, 0); +- mount_dir = devmapper_mount_layer(id.c_str(), &driver, mount_opts); ++ mount_dir = graphdriver_mount_layer(id.c_str(), mount_opts); + ASSERT_STREQ(mount_dir, merged_dir.c_str()); + MOCK_CLEAR(util_mount); + + MOCK_SET(umount2, 0); +- ASSERT_EQ(devmapper_umount_layer(id.c_str(), &driver), 0); ++ ASSERT_EQ(graphdriver_umount_layer(id.c_str()), 0); + MOCK_CLEAR(umount2); + free(mount_dir); + mount_dir = nullptr; +@@ -237,47 +329,62 @@ TEST_F(DriverDevmapperUnitTest, test_devmapper_mount_layer) + mount_opts->options_len = 1; + + MOCK_SET(util_mount, 0); +- mount_dir = devmapper_mount_layer(id.c_str(), &driver, mount_opts); ++ mount_dir = graphdriver_mount_layer(id.c_str(), mount_opts); + ASSERT_STREQ(mount_dir, merged_dir.c_str()); + MOCK_CLEAR(util_mount); + + MOCK_SET(umount2, 0); +- ASSERT_EQ(devmapper_umount_layer(id.c_str(), &driver), 0); ++ ASSERT_EQ(graphdriver_umount_layer(id.c_str()), 0); + MOCK_CLEAR(umount2); +- free(mount_opts->mount_label); +- util_free_array_by_len(mount_opts->options, mount_opts->options_len); +- free(mount_opts); +- free(mount_dir); ++ free_driver_mount_opts(mount_opts); + } + +-TEST_F(DriverDevmapperUnitTest, test_devmapper_get_layer_metadata) ++TEST_F(DriverDevmapperUnitTest, test_devmapper_get_data) + { + std::string id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; +- json_map_string_string *map_info = static_cast(util_common_calloc_s(sizeof(json_map_string_string))); +- +- ASSERT_EQ(devmapper_get_layer_metadata(id.c_str(), &driver, map_info), 0); +- ASSERT_EQ(map_info->len, 4); +- ASSERT_STREQ(map_info->keys[0], "DeviceId"); +- ASSERT_STREQ(map_info->values[0], "4"); +- ASSERT_STREQ(map_info->keys[1], "DeviceSize"); +- ASSERT_STREQ(map_info->values[1], "10737418240"); +- ASSERT_STREQ(map_info->keys[2], "DeviceName"); +- ASSERT_STREQ(map_info->keys[3], "MergedDir"); +- ASSERT_STREQ(map_info->values[3], "/tmp/isulad/data/devicemapper/mnt/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f/rootfs"); +- +- free_json_map_string_string(map_info); +-} + +-TEST_F(DriverDevmapperUnitTest, test_devmapper_get_driver_status) +-{ +- struct graphdriver_status *status = static_cast(util_common_calloc_s(sizeof(struct graphdriver_status))); ++ container_inspect_graph_driver *inspect = graphdriver_get_metadata(id.c_str()); ++ ASSERT_NE(inspect, nullptr); ++ ASSERT_STREQ(inspect->data->device_id, "4"); ++ ASSERT_STREQ(inspect->data->device_size, "10737418240"); ++ ASSERT_STREQ(inspect->data->merged_dir, "/tmp/isulad/data/devicemapper/mnt/3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f/rootfs"); ++ free_container_inspect_graph_driver(inspect); + + EXPECT_CALL(m_libdevmapper_mock, DMUdevGetSyncSupport()).WillOnce(Return(1)); + +- ASSERT_EQ(devmapper_get_driver_status(&driver, status), 0); ++ struct graphdriver_status *status = graphdriver_get_status(); ++ ASSERT_NE(status, nullptr); + ASSERT_STREQ(status->driver_name, "devicemapper"); +- free(status->driver_name); +- free(status->backing_fs); +- free(status->status); +- free(status); ++ free_graphdriver_status(status); ++ ++ ASSERT_EQ(devmapper_repair_lowers(nullptr, nullptr, nullptr), 0); ++ ASSERT_EQ(devmapper_get_layer_fs_info(nullptr, nullptr, nullptr), 0); + } ++ ++TEST_F(DriverDevmapperUnitTest, test_devmapper_apply_diff) ++{ ++ struct io_read_wrapper reader = {0}; ++ std::string id { "3d24ee258efc3bfe4066a1a9fb83febf6dc0b1548dfe896161533668281c9f4f" }; ++ MOCK_SET(util_mount, 0); ++ MOCK_SET(archive_unpack, 0); ++ MOCK_SET(umount2, 0); ++ EXPECT_CALL(m_isulad_conf_mock, ConfGetISuladRootDir()).WillOnce(Return(util_strdup_s("/tmp/isulad"))); ++ ASSERT_EQ(graphdriver_apply_diff(id.c_str(), &reader), 0); ++ MOCK_CLEAR(archive_unpack); ++ MOCK_CLEAR(util_mount); ++ MOCK_CLEAR(umount2); ++} ++ ++TEST_F(DriverDevmapperUnitTest, test_wrapper_devmapper) ++{ ++ ASSERT_STREQ(dev_strerror(ERR_TASK_RUN), "Task run error"); ++ ASSERT_STREQ(dev_strerror(ERR_TASK_SET_COOKIE), "Task set cookie error"); ++ ASSERT_STREQ(dev_strerror(ERR_NIL_COOKIE), "cookie ptr can't be nil"); ++ ASSERT_STREQ(dev_strerror(ERR_TASK_SET_ADD_NODE), "Task add dm node failed"); ++ ASSERT_STREQ(dev_strerror(ERR_BUSY), "Device busy"); ++ ASSERT_STREQ(dev_strerror(ERR_DEVICE_ID_EXISTS), "Device exists already"); ++ ASSERT_STREQ(dev_strerror(ERR_ENXIO), "No such device of address"); ++ ASSERT_STREQ(dev_strerror(ERR_TASK_ADD_TARGET), "Task add target device error"); ++ ASSERT_STREQ(dev_strerror(ERR_TASK_DEFERRED_REMOVE), "dm_task_deferred_remove failed"); ++ ASSERT_STREQ(dev_strerror(100), "Unknown error"); ++} +\ No newline at end of file +-- +2.42.0 + diff --git a/0046-2292-bugfix-for-run.sh-and-add-build-notify-msg-for-.patch b/0046-2292-bugfix-for-run.sh-and-add-build-notify-msg-for-.patch new file mode 100644 index 0000000000000000000000000000000000000000..410d120d81e73bfd23ad19efb7524adb4ffb37a8 --- /dev/null +++ b/0046-2292-bugfix-for-run.sh-and-add-build-notify-msg-for-.patch @@ -0,0 +1,56 @@ +From d813e654b5b964f79857df3c9130f174443a76be Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 4 Dec 2023 09:44:42 +0000 +Subject: [PATCH 46/65] !2292 bugfix for run.sh and add build notify msg for + ENABLE_GRPC_REMOTE_CONNECT * bugfix for run.sh and add build notify msg for + ENABLE_GRPC_REMOTE_CONNECT + +--- + CI/test_cases/container_cases/run.sh | 6 +++--- + cmake/options.cmake | 1 + + 2 files changed, 4 insertions(+), 3 deletions(-) + +diff --git a/CI/test_cases/container_cases/run.sh b/CI/test_cases/container_cases/run.sh +index 8ea3e514..1bfd388b 100755 +--- a/CI/test_cases/container_cases/run.sh ++++ b/CI/test_cases/container_cases/run.sh +@@ -27,7 +27,8 @@ function do_test_t() + { + tid=`isula run --runtime $1 -tid --name hostname busybox` + chostname=`isula exec -it $tid hostname` +- fn_check_eq "$chostname" "${tid:0:12}" "default hostname is id of container" ++ clean_hostname=$(echo "$hostname" | sed 's/[\x01-\x1F\x7F]//g') ++ fn_check_eq "${clean_hostname}" "${tid:0:12}" "default hostname is not id of container" + isula exec -it hostname env | grep HOSTNAME + fn_check_eq "$?" "0" "check HOSTNAME env failed" + isula stop -t 0 $tid +@@ -149,13 +150,12 @@ function do_run_remote_test_t() + + isula run --runtime $1 -ti -H "$config" --name $containername busybox xxx + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed check invalid run ${containername} remote" && ((ret++)) +- testcontainer $containername exited ++ + isula rm -f -H "$config" $containername + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container remote" && ((ret++)) + + isula run --runtime $1 -ti -H "$config" --name $containername busybox /bin/sh -c 'echo "hello"' | grep hello + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run ${containername} remote" && ((ret++)) +- testcontainer $containername exited + + isula rm -f -H "$config" $containername + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container remote" && ((ret++)) +diff --git a/cmake/options.cmake b/cmake/options.cmake +index aeb24662..bf7db93a 100644 +--- a/cmake/options.cmake ++++ b/cmake/options.cmake +@@ -110,6 +110,7 @@ option(ENABLE_GRPC_REMOTE_CONNECT "enable gRPC remote connect" OFF) + if (ENABLE_GRPC_REMOTE_CONNECT STREQUAL "ON") + add_definitions(-DENABLE_GRPC_REMOTE_CONNECT=1) + set(ENABLE_GRPC_REMOTE_CONNECT 1) ++ message("${Green}-- enable gRPC remote connect${ColourReset}") + endif() + + option(ENABLE_SHIM_V2 "enable shim v2 runtime" OFF) +-- +2.42.0 + diff --git a/0047-2295-keep-the-service-status-unchanged-after-iSulad-.patch b/0047-2295-keep-the-service-status-unchanged-after-iSulad-.patch new file mode 100644 index 0000000000000000000000000000000000000000..29aab369ff2ac2e13dd68b481e177dc28ae2617d --- /dev/null +++ b/0047-2295-keep-the-service-status-unchanged-after-iSulad-.patch @@ -0,0 +1,251 @@ +From 98825c56135aeeb02f50a5eec5896d39d3ea649f Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Wed, 6 Dec 2023 01:56:52 +0000 +Subject: [PATCH 47/65] !2295 keep the service status unchanged after iSulad + service upgrade * keep the service status unchanged after iSulad service + upgrade and + +--- + iSulad.spec | 121 +++++++++++++++++++++++++++------------------------- + 1 file changed, 62 insertions(+), 59 deletions(-) + +diff --git a/iSulad.spec b/iSulad.spec +index 6be2067d..0efbf043 100644 +--- a/iSulad.spec ++++ b/iSulad.spec +@@ -1,24 +1,23 @@ + %global _version 2.1.4 +-%global _release 1 ++%global _release 2 + %global is_systemd 1 + %global enable_criv1 1 + %global enable_shimv2 1 +-%global enable_embedded 1 ++%global is_embedded 1 ++%global cpp_std 17 + + Name: iSulad + Version: %{_version} + Release: %{_release} + Summary: Lightweight Container Runtime Daemon + License: Mulan PSL v2 +-URL: isulad +-Source: iSulad-2.1.tar.gz ++URL: https://gitee.com/openeuler/iSulad ++Source: https://gitee.com/openeuler/iSulad/repository/archive/v%{version}.tar.gz + BuildRoot: {_tmppath}/iSulad-%{version} +-ExclusiveArch: x86_64 aarch64 + + %ifarch x86_64 aarch64 + Provides: libhttpclient.so()(64bit) + Provides: libisula_client.so()(64bit) +-Provides: libisulad_img.so()(64bit) + Provides: libisulad_tools.so()(64bit) + %endif + +@@ -33,40 +32,56 @@ Requires(preun): chkconfig + Requires(preun): initscripts + %endif + +-%if 0%{?enable_embedded} ++%if 0%{?is_embedded} + BuildRequires: sqlite-devel +-Requires: sqlite ++Requires: sqlite + %endif + +-%if 0%{?enable_shimv2} +-BuildRequires: lib-shim-v2-devel +-Requires: lib-shim-v2 ++%if %{defined openeuler} ++BuildRequires: gtest-devel gmock-devel + %endif + +-BuildRequires: cmake gcc-c++ lxc-devel lcr-devel yajl-devel libisula-devel +-BuildRequires: grpc-plugins grpc-devel protobuf-devel +-BuildRequires: libcurl-devel libarchive-devel device-mapper-devel ++%define lcrver_lower 2.1.3-0 ++%define lcrver_upper 2.1.4-0 ++ ++BuildRequires: libisula-devel > %{lcrver_lower} libisula-devel < %{lcrver_upper} ++BuildRequires: cmake gcc-c++ yajl-devel ++BuildRequires: grpc grpc-plugins grpc-devel protobuf-devel ++BuildRequires: libcurl libcurl-devel libarchive-devel device-mapper-devel + BuildRequires: http-parser-devel +-BuildRequires: libselinux-devel libwebsockets-devel ++BuildRequires: libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel + BuildRequires: systemd-devel git ++BuildRequires: libevhtp-devel libevent-devel ++%if 0%{?enable_shimv2} ++BuildRequires: lib-shim-v2 lib-shim-v2-devel ++%endif ++ + +-Requires: libisula lxc +-Requires: grpc libcurl http-parser +-Requires: libselinux libwebsockets libarchive device-mapper ++Requires: libisula > %{lcrver_lower} libisula < %{lcrver_upper} ++Requires: grpc protobuf ++Requires: libcurl ++Requires: http-parser libseccomp ++Requires: libcap libselinux libwebsockets libarchive device-mapper + Requires: systemd ++Requires: (docker-runc or runc) ++BuildRequires: libevhtp libevent ++%if 0%{?enable_shimv2} ++Requires: lib-shim-v2 ++%endif + + %description + This is a umbrella project for gRPC-services based Lightweight Container + Runtime Daemon, written by C. + + %prep +-%autosetup -c -n iSulad-%{version} ++%autosetup -n iSulad-v%{_version} -Sgit -p1 + + %build + mkdir -p build + cd build + %cmake \ + -DDEBUG=ON \ ++ -DCMAKE_SKIP_RPATH=TRUE \ + -DLIB_INSTALL_DIR=%{_libdir} \ + -DCMAKE_INSTALL_PREFIX=/usr \ + %if 0%{?enable_criv1} +@@ -76,36 +91,47 @@ cd build + %if 0%{?enable_shimv2} + -DENABLE_SHIM_V2=ON \ + %endif ++%if %{defined openeuler} ++ -DENABLE_UT=OFF \ ++%endif ++ -DENABLE_GRPC_REMOTE_CONNECT=OFF \ ++ -DENABLE_GRPC=ON \ ++ -DCMAKE_CXX_STANDARD=%{cpp_std} \ + ../ ++ ++sed -i "10 a\# undef linux" grpc/src/api/services/cri/v1alpha/api.pb.h ++%if 0%{?enable_criv1} ++sed -i "10 a\# undef linux" grpc/src/api/services/cri/v1/api_v1.pb.h ++%endif ++ + %make_build + ++%check ++%if %{defined openeuler} ++cd build ++# registry_images_ut and volume_ut must run with root user ++ctest -E "registry_images_ut|volume_ut" ++%endif ++ + %install + rm -rf %{buildroot} + cd build + install -d $RPM_BUILD_ROOT/%{_libdir} +-install -m 0644 ./src/libisula_client.so %{buildroot}/%{_libdir}/libisula_client.so +-install -m 0644 ./src/utils/http/libhttpclient.so %{buildroot}/%{_libdir}/libhttpclient.so +-chrpath -d ./src/libisulad_tools.so +-install -m 0644 ./src/libisulad_tools.so %{buildroot}/%{_libdir}/libisulad_tools.so +-chrpath -d ./src/daemon/modules/image/libisulad_img.so +-install -m 0644 ./src/daemon/modules/image/libisulad_img.so %{buildroot}/%{_libdir}/libisulad_img.so +-chmod +x %{buildroot}/%{_libdir}/libisula_client.so +-chmod +x %{buildroot}/%{_libdir}/libhttpclient.so +-chmod +x %{buildroot}/%{_libdir}/libisulad_img.so ++install -m 0755 ./src/libisula_client.so %{buildroot}/%{_libdir}/libisula_client.so ++install -m 0755 ./src/utils/http/libhttpclient.so %{buildroot}/%{_libdir}/libhttpclient.so ++install -m 0755 ./src/libisulad_tools.so %{buildroot}/%{_libdir}/libisulad_tools.so + + install -d $RPM_BUILD_ROOT/%{_libdir}/pkgconfig + install -m 0640 ./conf/isulad.pc %{buildroot}/%{_libdir}/pkgconfig/isulad.pc + + install -d $RPM_BUILD_ROOT/%{_bindir} ++ + install -m 0755 ./src/isula %{buildroot}/%{_bindir}/isula + install -m 0755 ./src/isulad-shim %{buildroot}/%{_bindir}/isulad-shim +-install -m 0755 ./src/isulad %{buildroot}/%{_bindir}/isulad +-chrpath -d ./src/isula +-chrpath -d ./src/isulad-shim +-chrpath -d ./src/isulad ++ ++install -m 0755 ./src/isulad %{buildroot}/%{_bindir}/isulad + + install -d $RPM_BUILD_ROOT/%{_includedir}/isulad +-install -m 0644 ../src/daemon/modules/api/image_api.h %{buildroot}/%{_includedir}/isulad/image_api.h + + install -d $RPM_BUILD_ROOT/%{_sysconfdir}/isulad + install -m 0640 ../src/contrib/config/daemon.json %{buildroot}/%{_sysconfdir}/isulad/daemon.json +@@ -134,8 +160,6 @@ install -d $RPM_BUILD_ROOT/%{_initddir} + install -p -m 0640 ../src/contrib/init/isulad.init $RPM_BUILD_ROOT/%{_initddir}/isulad.init + %endif + +-install -d $RPM_BUILD_ROOT/usr/share/bash-completion/completions +-install -p -m 0644 ../src/contrib/completion/isula $RPM_BUILD_ROOT/usr/share/bash-completion/completions/isula + %clean + rm -rf %{buildroot} + +@@ -143,19 +167,17 @@ rm -rf %{buildroot} + # support update from lcrd to isulad, will remove in next version + if [ "$1" = "2" ]; then + %if 0%{?is_systemd} +-systemctl stop lcrd +-systemctl disable lcrd ++systemctl stop lcrd &>/dev/null ++systemctl disable lcrd &>/dev/null + if [ -e %{_sysconfdir}/isulad/daemon.json ];then + sed -i 's#/etc/default/lcrd/hooks#/etc/default/isulad/hooks#g' %{_sysconfdir}/isulad/daemon.json + fi + %else +-/sbin/chkconfig --del lcrd ++/sbin/chkconfig --del lcrd &>/dev/null + %endif + fi + + %post +-source /usr/share/bash-completion/completions/isula +- + if ! getent group isula > /dev/null; then + groupadd --system isula + fi +@@ -174,12 +196,6 @@ if [ -e %{_unitdir}/lcrd.service.rpmsave ]; then + mv %{_unitdir}/lcrd.service.rpmsave %{_unitdir}/isulad.service + sed -i 's/lcrd/isulad/g' %{_unitdir}/isulad.service + fi +-systemctl status isulad | grep 'Active:' | grep 'running' +-if [ $? -eq 0 ]; then +- systemctl restart isulad +-else +- systemctl start isulad +-fi + %else + /sbin/service isulad status | grep 'Active:' | grep 'running' + if [ $? -eq 0 ]; then +@@ -226,7 +242,6 @@ fi + %{_initddir}/isulad.init + %attr(0640,root,root) %{_initddir}/isulad.init + %endif +-%{_includedir}/isulad/* + %attr(0755,root,root) %{_libdir}/pkgconfig + %attr(0640,root,root) %{_libdir}/pkgconfig/isulad.pc + %defattr(0755,root,root,0755) +@@ -242,17 +257,5 @@ fi + %else + %config(noreplace,missingok) %{_initddir}/isulad.init + %endif +-/usr/share/bash-completion/completions/isula + + %changelog +-* Tue Sep 10 2020 openEuler Buildteam - 2.0.5-20200910.140350.git72990229 +-- Type:enhancement +-- ID:NA +-- SUG:NA +-- DESC: add chrpath +- +-* Mon Aug 03 2020 openEuler Buildteam - 2.0.3-20200803.130854.git0c7dc28a +-- Type:enhancement +-- ID:NA +-- SUG:NA +-- DESC: add debug packages +-- +2.42.0 + diff --git a/0048-modify-attach-socket-name.patch b/0048-modify-attach-socket-name.patch new file mode 100644 index 0000000000000000000000000000000000000000..23d96303f24d0c7b11be5255396b80ea39677ac9 --- /dev/null +++ b/0048-modify-attach-socket-name.patch @@ -0,0 +1,40 @@ +From c01b761e14e6b4ea6745688e47b255f17ba26055 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Wed, 6 Dec 2023 15:15:32 +0800 +Subject: [PATCH 48/65] modify attach socket name + +Signed-off-by: zhongtao +--- + src/cmd/isulad-shim/common.h | 2 +- + src/daemon/modules/runtime/isula/isula_rt_ops.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/cmd/isulad-shim/common.h b/src/cmd/isulad-shim/common.h +index 2020a799..c4f86d24 100644 +--- a/src/cmd/isulad-shim/common.h ++++ b/src/cmd/isulad-shim/common.h +@@ -60,7 +60,7 @@ extern "C" { + #define CONTAINER_ACTION_REBOOT 129 + #define CONTAINER_ACTION_SHUTDOWN 130 + +-#define ATTACH_SOCKET "attach_socket.sock" ++#define ATTACH_SOCKET "attach.sock" + #define ATTACH_LOG_NAME "attach-log.json" + #define ATTACH_DETACH_MSG "read escape sequence" + #define MAX_ATTACH_NUM 16 +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 3950ff4a..fbb779f7 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -57,7 +57,7 @@ + + #define SHIM_BINARY "isulad-shim" + #define RESIZE_FIFO_NAME "resize_fifo" +-#define ATTACH_SOCKET "attach_socket.sock" ++#define ATTACH_SOCKET "attach.sock" + #define SHIM_LOG_SIZE ((BUFSIZ - 100) / 2) + #define RESIZE_DATA_SIZE 100 + #define PID_WAIT_TIME 120 +-- +2.42.0 + diff --git a/0049-2298-bugfix-for-hook_ignore_poststart_error-run-in-o.patch b/0049-2298-bugfix-for-hook_ignore_poststart_error-run-in-o.patch new file mode 100644 index 0000000000000000000000000000000000000000..7bfec1c89028dae892196d0e3a6f3926a1d58b46 --- /dev/null +++ b/0049-2298-bugfix-for-hook_ignore_poststart_error-run-in-o.patch @@ -0,0 +1,110 @@ +From 94122c5752936b4f5db14521cdd0f39a3dec6851 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Thu, 7 Dec 2023 03:32:15 +0000 +Subject: [PATCH 49/65] !2298 bugfix for hook_ignore_poststart_error run in oci + runtime * bugfix for hook_ignore_poststart_error run in oci runtime + +--- + .../hook_ignore_poststart_error.sh | 70 +++++++++++++------ + 1 file changed, 50 insertions(+), 20 deletions(-) + +diff --git a/CI/test_cases/container_cases/hook_ignore_poststart_error.sh b/CI/test_cases/container_cases/hook_ignore_poststart_error.sh +index 8c636f7e..38b6f021 100755 +--- a/CI/test_cases/container_cases/hook_ignore_poststart_error.sh ++++ b/CI/test_cases/container_cases/hook_ignore_poststart_error.sh +@@ -24,6 +24,48 @@ source ../helpers.sh + + test_data_path=$(realpath $curr_path/test_data) + ++# $1 hook process ++# $2 container id ++# $3 expect container status ++# $4 process statement ++function test_kill_hook() ++{ ++ for a in `seq 20` ++ do ++ bpid=`ps aux | grep "$1" | grep -v grep | awk '{print $2}'` ++ if [ "x" != "x$bpid" ];then ++ kill -9 $bpid ++ break ++ else ++ sleep .5 ++ continue ++ fi ++ done ++ ++ if [ "x" != "x$4" ];then ++ for a in `seq 20` ++ do ++ bpid=`ps aux | grep "$4" | grep -v grep | awk '{print $2}'` ++ if [ "x" != "x$bpid" ];then ++ kill -9 $bpid ++ break ++ else ++ sleep .5 ++ continue ++ fi ++ done ++ fi ++ ++ status=`isula inspect -f '{{json .State.Status}}' $2` ++ if [ "$status" == "$3" ];then ++ echo "get right status" ++ return 0 ++ else ++ echo "expect $2 $3, but get $status" ++ return 1 ++ fi ++} ++ + function test_hook_ignore_poststart_error_spec() + { + local ret=0 +@@ -42,27 +84,15 @@ function test_hook_ignore_poststart_error_spec() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + + isula run -n $CONT -itd --runtime $runtime --hook-spec ${test_data_path}/oci_hook_poststart_check.json ${image} & +- +- for a in `seq 20` +- do +- bpid=`ps aux | grep "poststart.sh" | grep -v grep | awk '{print $2}'` +- if [ "x" != "x$bpid" ];then +- kill -9 $bpid +- break +- else +- sleep .5 +- continue +- fi +- done +- +- status=`isula inspect -f '{{json .State.Status}}' $CONT` +- if [ "$status" == "\"running\"" ];then +- echo "get right status" ++ ++ # when runc container run poststart hook, the process structure is different from lxc ++ if [ $runtime == "lcr" ]; then ++ test_kill_hook "poststart.sh" $CONT \"running\" + else +- echo "expect $CONT running, but get $status" +- ret++ ++ test_kill_hook "poststart.sh" $CONT \"exited\" "sleep 300" + fi +- ++ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to test kill hook: ${image}" && ((ret++)) ++ + isula stop -t 0 ${CONT} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop ${CONT}" && ((ret++)) + +@@ -77,7 +107,7 @@ declare -i ans=0 + + for element in ${RUNTIME_LIST[@]}; + do +- test_hook_ignore_poststart_error_spec $1 || ((ans++)) ++ test_hook_ignore_poststart_error_spec $element || ((ans++)) + done + + show_result ${ans} "${curr_path}/${0}" +-- +2.42.0 + diff --git a/0050-2304-remove-build-and-test-in-coverage.patch b/0050-2304-remove-build-and-test-in-coverage.patch new file mode 100644 index 0000000000000000000000000000000000000000..f90a6a56b61d87b38413bf7a43fbfc1b949945c3 --- /dev/null +++ b/0050-2304-remove-build-and-test-in-coverage.patch @@ -0,0 +1,28 @@ +From c2e9919ec8612d6e811644ec8aacf53cec0c4f20 Mon Sep 17 00:00:00 2001 +From: jake +Date: Tue, 12 Dec 2023 08:55:30 +0000 +Subject: [PATCH 50/65] !2304 remove build and test in coverage * remove build + and test in coverage + +--- + CI/generate_gcov.sh | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/CI/generate_gcov.sh b/CI/generate_gcov.sh +index 153c9f5a..76bf382b 100755 +--- a/CI/generate_gcov.sh ++++ b/CI/generate_gcov.sh +@@ -31,8 +31,8 @@ ctest + lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1 + # Remove std/build files + lcov --remove coverage.info '/usr/*' -o coverage.info --rc lcov_branch_coverage=1 +-lcov --remove coverage.info 'build/*' -o coverage.info --rc lcov_branch_coverage=1 +-lcov --remove coverage.info 'test/*' -o coverage.info --rc lcov_branch_coverage=1 ++lcov --remove coverage.info "$ISULAD_SRC_PATH/build/*" -o coverage.info --rc lcov_branch_coverage=1 ++lcov --remove coverage.info "$ISULAD_SRC_PATH/test/*" -o coverage.info --rc lcov_branch_coverage=1 + + # Generate html + genhtml --ignore-errors source -o $GCOV_RESULT_PATH/coverage coverage.info --branch-coverage --rc lcov_branch_coverage=1 +-- +2.42.0 + diff --git a/0051-2303-use-a-timeout-epoll-loop-to-ensure-complete-dat.patch b/0051-2303-use-a-timeout-epoll-loop-to-ensure-complete-dat.patch new file mode 100644 index 0000000000000000000000000000000000000000..8f26469bea461d52cf329614a6833dda477c474c --- /dev/null +++ b/0051-2303-use-a-timeout-epoll-loop-to-ensure-complete-dat.patch @@ -0,0 +1,197 @@ +From 7d1b8d25468528a59318430d50d839032f2c1a07 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 12 Dec 2023 12:26:32 +0000 +Subject: [PATCH 51/65] !2303 use a timeout epoll loop to ensure complete data + reception * use a timeout epoll loop to ensure complete data reception + +--- + src/cmd/isulad-shim/process.c | 105 +++++++++------------------------- + src/cmd/isulad-shim/process.h | 1 - + 2 files changed, 26 insertions(+), 80 deletions(-) + +diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c +index e8cb9b32..97524f1a 100644 +--- a/src/cmd/isulad-shim/process.c ++++ b/src/cmd/isulad-shim/process.c +@@ -169,6 +169,7 @@ static int get_exec_winsize(const char *buf, struct winsize *wsize) + + static int sync_exit_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t *descr) + { ++ isula_epoll_remove_handler(descr, fd); + return EPOLL_LOOP_HANDLE_CLOSE; + } + +@@ -364,23 +365,14 @@ static int stdout_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + int r_count = 0; + int w_count = 0; + +- if (events & EPOLLHUP) { +- return EPOLL_LOOP_HANDLE_CLOSE; +- } +- +- if (!(events & EPOLLIN)) { +- return EPOLL_LOOP_HANDLE_CONTINUE; +- } +- + (void)memset(p->buf, 0, DEFAULT_IO_COPY_BUF); + +- if (p->block_read) { +- r_count = isula_file_read_nointr(fd, p->buf, DEFAULT_IO_COPY_BUF); +- } else { +- r_count = read(fd, p->buf, DEFAULT_IO_COPY_BUF); +- } +- if (r_count <= 0) { +- return EPOLL_LOOP_HANDLE_CLOSE; ++ r_count = isula_file_read_nointr(fd, p->buf, DEFAULT_IO_COPY_BUF); ++ if (r_count <= 0 ) { ++ isula_epoll_remove_handler(descr, fd); ++ // fd cannot be closed here, which will cause the container process to exit abnormally ++ // due to terminal fd receiving the sighup signal. ++ return EPOLL_LOOP_HANDLE_CONTINUE; + } + + shim_write_container_log_file(p->terminal, STDID_OUT, p->buf, r_count); +@@ -419,23 +411,14 @@ static int stderr_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + int r_count = 0; + int w_count = 0; + +- if (events & EPOLLHUP) { +- return EPOLL_LOOP_HANDLE_CLOSE; +- } +- +- if (!(events & EPOLLIN)) { +- return EPOLL_LOOP_HANDLE_CONTINUE; +- } +- + (void)memset(p->buf, 0, DEFAULT_IO_COPY_BUF); + +- if (p->block_read) { +- r_count = isula_file_read_nointr(fd, p->buf, DEFAULT_IO_COPY_BUF); +- } else { +- r_count = read(fd, p->buf, DEFAULT_IO_COPY_BUF); +- } +- if (r_count <= 0) { +- return EPOLL_LOOP_HANDLE_CLOSE; ++ r_count = isula_file_read_nointr(fd, p->buf, DEFAULT_IO_COPY_BUF); ++ if (r_count <= 0 ) { ++ isula_epoll_remove_handler(descr, fd); ++ // fd cannot be closed here, which will cause the container process to exit abnormally ++ // due to terminal fd receiving the sighup signal. ++ return EPOLL_LOOP_HANDLE_CONTINUE; + } + + shim_write_container_log_file(p->terminal, STDID_ERR, p->buf, r_count); +@@ -474,18 +457,11 @@ static int resize_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + int r_count = 0; + int resize_fd = -1; + +- if (events & EPOLLHUP) { +- return EPOLL_LOOP_HANDLE_CLOSE; +- } +- +- if (!(events & EPOLLIN)) { +- return EPOLL_LOOP_HANDLE_CONTINUE; +- } +- + (void)memset(p->buf, 0, DEFAULT_IO_COPY_BUF); + r_count = isula_file_read_nointr(fd, p->buf, DEFAULT_IO_COPY_BUF); + if (r_count <= 0) { +- return EPOLL_LOOP_HANDLE_CLOSE; ++ close(fd); ++ return EPOLL_LOOP_HANDLE_CONTINUE; + } + + resize_fd = p->recv_fd; +@@ -915,8 +891,6 @@ static int open_generic_io(process_t *p, isula_epoll_descr_t *descr) + static void *io_epoll_loop(void *data) + { + int ret = 0; +- int fd_out = -1; +- int fd_err = -1; + process_t *p = (process_t *)data; + isula_epoll_descr_t descr; + +@@ -953,49 +927,23 @@ static void *io_epoll_loop(void *data) + + (void)sem_post(&p->sem_mainloop); + ++ // th frist epoll_loop will exit in the following scenarios: ++ // 1. Receive sync fd event ++ // 2. stdin fd receive EPOLLHUP event ++ // 3. stdin fd read failed + ret = isula_epoll_loop(&descr, -1); + if (ret != 0) { + write_message(ERR_MSG, "epoll loop failed"); + exit(EXIT_FAILURE); + } + +- // in order to avoid data loss, set fd non-block and read it +- p->block_read = false; +- if (p->state->terminal) { +- fd_out = p->recv_fd; +- } else { +- fd_out = p->shim_io->out; +- fd_err = p->shim_io->err; +- } +- +- if (fd_out > 0) { +- ret = isula_set_non_block(fd_out); +- if (ret != SHIM_OK) { +- write_message(ERR_MSG, "set fd %d non_block failed:%d", fd_out, SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); +- } +- +- for (;;) { +- ret = stdout_cb(fd_out, EPOLLIN, p, &descr); +- if (ret == EPOLL_LOOP_HANDLE_CLOSE) { +- break; +- } +- } +- } +- +- if (fd_err > 0) { +- ret = isula_set_non_block(fd_err); +- if (ret != SHIM_OK) { +- write_message(ERR_MSG, "set fd %d non_block failed:%d", fd_err, SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); +- } +- +- for (;;) { +- ret = stderr_cb(fd_err, EPOLLIN, p, &descr); +- if (ret == EPOLL_LOOP_HANDLE_CLOSE) { +- break; +- } +- } ++ // use a timeout epoll loop to ensure complete data reception ++ // th second epoll_loop will exit in the following scenarios: ++ // 1. both stdout fd and stderr fd failed to read ++ // 2. no event received within 100 milliseconds ++ ret = isula_epoll_loop(&descr, 100); ++ if (ret != 0) { ++ write_message(ERR_MSG, "Repeat the epoll loop to ensure that all data is transferred"); + } + + return NULL; +@@ -1220,7 +1168,6 @@ process_t *new_process(char *id, char *bundle, char *runtime) + p->bundle = bundle; + p->runtime = runtime; + p->state = p_state; +- p->block_read = true; + p->console_sock_path = NULL; + p->exit_fd = -1; + p->io_loop_fd = -1; +diff --git a/src/cmd/isulad-shim/process.h b/src/cmd/isulad-shim/process.h +index 5607316c..32ba7366 100644 +--- a/src/cmd/isulad-shim/process.h ++++ b/src/cmd/isulad-shim/process.h +@@ -55,7 +55,6 @@ typedef struct process { + int sync_fd; + int listen_fd; + int recv_fd; +- bool block_read; + log_terminal *terminal; + stdio_t *stdio; // shim to on runtime side, in:r out/err: w + stdio_t *shim_io; // shim io on isulad side, in: w out/err: r +-- +2.42.0 + diff --git a/0052-modify-the-default-value-of-ISULAD_TMPDIR-to-var-lib.patch b/0052-modify-the-default-value-of-ISULAD_TMPDIR-to-var-lib.patch new file mode 100644 index 0000000000000000000000000000000000000000..101c263914c51058ac0844786acb9bb00a3ba36e --- /dev/null +++ b/0052-modify-the-default-value-of-ISULAD_TMPDIR-to-var-lib.patch @@ -0,0 +1,170 @@ +From 06d42781cbfc3d9baa7155b480e22b9f4164ab91 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 12 Dec 2023 20:24:57 +0800 +Subject: [PATCH 52/65] modify the default value of ISULAD_TMPDIR to + /var/lib/isulad + +Signed-off-by: zhongtao +--- + src/cmd/isulad/main.c | 13 +++++++------ + src/common/constants.h | 2 ++ + src/contrib/config/iSulad.sysconfig | 4 ++-- + .../modules/container/leftover_cleanup/cleanup.c | 6 +++--- + src/daemon/modules/image/oci/utils_images.c | 2 +- + src/utils/cutils/utils_verify.c | 5 +++++ + src/utils/cutils/utils_verify.h | 2 ++ + src/utils/tar/util_archive.c | 9 +++++---- + 8 files changed, 27 insertions(+), 16 deletions(-) + +diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c +index 95454e2a..d33e4004 100644 +--- a/src/cmd/isulad/main.c ++++ b/src/cmd/isulad/main.c +@@ -1295,8 +1295,8 @@ static int ensure_isulad_tmpdir_security() + char *isulad_tmp_dir = NULL; + + isulad_tmp_dir = getenv("ISULAD_TMPDIR"); +- if (!util_valid_str(isulad_tmp_dir)) { +- isulad_tmp_dir = "/tmp"; ++ if (!util_valid_isulad_tmpdir(isulad_tmp_dir)) { ++ isulad_tmp_dir = DEFAULT_ISULAD_TMPDIR; + } + + if (do_ensure_isulad_tmpdir_security(isulad_tmp_dir) != 0) { +@@ -1304,14 +1304,15 @@ static int ensure_isulad_tmpdir_security() + return -1; + } + +- if (strcmp(isulad_tmp_dir, "/tmp") == 0) { ++ if (strcmp(isulad_tmp_dir, DEFAULT_ISULAD_TMPDIR) == 0) { + return 0; + } + + // No matter whether ISULAD_TMPDIR is set or not, +- // ensure the "/tmp" directory is a safe directory +- if (do_ensure_isulad_tmpdir_security("/tmp") != 0) { +- WARN("Failed to ensure the /tmp directory is a safe directory"); ++ // ensure the DEFAULT_ISULAD_TMPDIR directory is a safe directory ++ // TODO: if isula is no longer tarred in the future, we can delete it. ++ if (do_ensure_isulad_tmpdir_security(DEFAULT_ISULAD_TMPDIR) != 0) { ++ WARN("Failed to ensure the default ISULAD_TMPDIR : %s directory is a safe directory", DEFAULT_ISULAD_TMPDIR); + } + + return 0; +diff --git a/src/common/constants.h b/src/common/constants.h +index 5f12ae25..27d4956e 100644 +--- a/src/common/constants.h ++++ b/src/common/constants.h +@@ -129,6 +129,8 @@ extern "C" { + + #define OCI_IMAGE_GRAPH_ROOTPATH_NAME "storage" + ++#define DEFAULT_ISULAD_TMPDIR "/var/lib/isulad" ++ + #ifdef ENABLE_GRPC_REMOTE_CONNECT + #define DEFAULT_TCP_HOST "tcp://localhost:2375" + #define DEFAULT_TLS_HOST "tcp://localhost:2376" +diff --git a/src/contrib/config/iSulad.sysconfig b/src/contrib/config/iSulad.sysconfig +index 43ba7cbd..25099480 100644 +--- a/src/contrib/config/iSulad.sysconfig ++++ b/src/contrib/config/iSulad.sysconfig +@@ -22,5 +22,5 @@ + #SYSMONITOR_OPTIONS='-H tcp://127.0.0.1:2375 --tlsverify --tlscacert=/root/.iSulad/ca.pem --tlscert=/root/.iSulad/cert.pem --tlskey=/root/.iSulad/key.pem' + + # Location used for temporary files, such as those created by isula load and pull operations. +-# Default is /var/tmp. Can be overridden by setting the following env variable. +-# ISULAD_TMPDIR=/var/tmp ++# Default is /var/lib/isulad. Can be overridden by setting the following env variable. ++# ISULAD_TMPDIR=/var/lib/isulad +diff --git a/src/daemon/modules/container/leftover_cleanup/cleanup.c b/src/daemon/modules/container/leftover_cleanup/cleanup.c +index 9a38ffc2..af5f0eee 100644 +--- a/src/daemon/modules/container/leftover_cleanup/cleanup.c ++++ b/src/daemon/modules/container/leftover_cleanup/cleanup.c +@@ -203,12 +203,12 @@ void do_isulad_tmpdir_cleaner(void) + char *isula_tmp_dir = NULL; + + isula_tmp_dir = getenv("ISULAD_TMPDIR"); +- if (util_valid_str(isula_tmp_dir)) { ++ if (util_valid_isulad_tmpdir(isula_tmp_dir)) { + cleanup_path(isula_tmp_dir); + } + // No matter whether ISULAD_TMPDIR is set or not, +- // clean up the "/tmp" directory to prevent the mount point from remaining +- cleanup_path("/tmp"); ++ // clean up the DEFAULT_ISULAD_TMPDIR directory to prevent the mount point from remaining ++ cleanup_path(DEFAULT_ISULAD_TMPDIR); + + return; + } +diff --git a/src/daemon/modules/image/oci/utils_images.c b/src/daemon/modules/image/oci/utils_images.c +index f92ee59a..d94388bd 100644 +--- a/src/daemon/modules/image/oci/utils_images.c ++++ b/src/daemon/modules/image/oci/utils_images.c +@@ -595,7 +595,7 @@ char *oci_get_isulad_tmpdir(const char *root_dir) + } + + env_dir = getenv("ISULAD_TMPDIR"); +- if (util_valid_str(env_dir)) { ++ if (util_valid_isulad_tmpdir(env_dir)) { + isulad_tmpdir = util_path_join(env_dir, "isulad_tmpdir"); + } else { + isulad_tmpdir = util_path_join(root_dir, "isulad_tmpdir"); +diff --git a/src/utils/cutils/utils_verify.c b/src/utils/cutils/utils_verify.c +index f4ce3199..7f2db48b 100644 +--- a/src/utils/cutils/utils_verify.c ++++ b/src/utils/cutils/utils_verify.c +@@ -744,6 +744,11 @@ bool util_valid_volume_name(const char *name) + return util_reg_match(patten, name) == 0; + } + ++bool util_valid_isulad_tmpdir(const char *dir) ++{ ++ return util_valid_str(dir) && strcmp(dir, "/tmp") != 0; ++} ++ + #ifdef ENABLE_IMAGE_SEARCH + bool util_valid_search_name(const char *name) + { +diff --git a/src/utils/cutils/utils_verify.h b/src/utils/cutils/utils_verify.h +index 54d1ce71..bafd2a82 100644 +--- a/src/utils/cutils/utils_verify.h ++++ b/src/utils/cutils/utils_verify.h +@@ -124,6 +124,8 @@ bool util_valid_sysctl(const char *sysctl_key); + + bool util_valid_volume_name(const char *name); + ++bool util_valid_isulad_tmpdir(const char *dir); ++ + #ifdef ENABLE_IMAGE_SEARCH + bool util_valid_search_name(const char *name); + #endif +diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c +index 82e940a5..e8fad391 100644 +--- a/src/utils/tar/util_archive.c ++++ b/src/utils/tar/util_archive.c +@@ -134,7 +134,7 @@ static void do_disable_unneccessary_caps() + // Add flock when bind mount and make it private. + // Because bind mount usually makes safedir shared mount point, + // and sometimes it will cause "mount point explosion". +-// E.g. concurrently execute isula cp /tmp/ : ++// E.g. concurrently execute isula cp DEFAULT_ISULAD_TMPDIR/ : + static int bind_mount_with_flock(const char *flock_path, const char *dstdir, const char *tmp_dir) + { + __isula_auto_close int fd = -1; +@@ -192,9 +192,10 @@ static int make_safedir_is_noexec(const char *flock_path, const char *dstdir, ch + int nret; + + isulad_tmpdir_env = getenv("ISULAD_TMPDIR"); +- if (!util_valid_str(isulad_tmpdir_env)) { +- // if not setted isulad tmpdir, just use /tmp +- isulad_tmpdir_env = "/tmp"; ++ if (!util_valid_isulad_tmpdir(isulad_tmpdir_env)) { ++ INFO("if not setted isulad tmpdir or setted unvalid dir, use DEFAULT_ISULAD_TMPDIR"); ++ // if not setted isulad tmpdir, just use DEFAULT_ISULAD_TMPDIR ++ isulad_tmpdir_env = DEFAULT_ISULAD_TMPDIR; + } + + nret = snprintf(isula_tmpdir, PATH_MAX, "%s/isulad_tmpdir", isulad_tmpdir_env); +-- +2.42.0 + diff --git a/0053-prevent-the-parent-dir-from-being-bind-mounted-to-th.patch b/0053-prevent-the-parent-dir-from-being-bind-mounted-to-th.patch new file mode 100644 index 0000000000000000000000000000000000000000..fdbd3d28f0a026e170d38e8e997ede2119539a65 --- /dev/null +++ b/0053-prevent-the-parent-dir-from-being-bind-mounted-to-th.patch @@ -0,0 +1,58 @@ +From 05117ed2887ee1535978170cd06596ee015951f4 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 12 Dec 2023 20:26:30 +0800 +Subject: [PATCH 53/65] prevent the parent dir from being bind mounted to the + subdir + +Signed-off-by: zhongtao +--- + src/utils/tar/util_archive.c | 26 ++++++++++++++++++++++++++ + 1 file changed, 26 insertions(+) + +diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c +index e8fad391..29c2bc03 100644 +--- a/src/utils/tar/util_archive.c ++++ b/src/utils/tar/util_archive.c +@@ -182,6 +182,26 @@ unlock_out: + return ret; + } + ++static int is_parent_directory(const char *parent_path, const char *child_path) ++{ ++ size_t parent_len = strlen(parent_path); ++ size_t child_len = strlen(child_path); ++ ++ if (parent_len == 0 || child_len == 0 || parent_len >= child_len) { ++ return -1; ++ } ++ ++ if (strncmp(parent_path, child_path, parent_len) != 0) { ++ return -1; ++ } ++ ++ if (child_path[parent_len] != '/') { ++ return -1; ++ } ++ ++ return 0; ++} ++ + static int make_safedir_is_noexec(const char *flock_path, const char *dstdir, char **safe_dir) + { + struct stat buf; +@@ -235,6 +255,12 @@ static int make_safedir_is_noexec(const char *flock_path, const char *dstdir, ch + return -1; + } + ++ // prevent the parent directory from being bind mounted to the subdirectory ++ if (is_parent_directory(dstdir, tmp_dir) == 0) { ++ ERROR("Cannot bind mount the parent directory: %s to its subdirectory: %s", dstdir, tmp_dir); ++ return -1; ++ } ++ + if (bind_mount_with_flock(flock_path, dstdir, tmp_dir) != 0) { + ERROR("Failed to bind mount from %s to %s with flock", dstdir, tmp_dir); + if (util_path_remove(tmp_dir) != 0) { +-- +2.42.0 + diff --git a/0054-2308-Remove-unused-header-file.patch b/0054-2308-Remove-unused-header-file.patch new file mode 100644 index 0000000000000000000000000000000000000000..c7b09cb81da3de7e64f2cc0d0a7c844528c0d928 --- /dev/null +++ b/0054-2308-Remove-unused-header-file.patch @@ -0,0 +1,25 @@ +From 93071602df77cc3b5508266b181f1ace947bd3be Mon Sep 17 00:00:00 2001 +From: xuxuepeng +Date: Wed, 13 Dec 2023 02:34:20 +0000 +Subject: [PATCH 54/65] !2308 Remove unused header file * Fix compiling failure + in image oci UT + +--- + src/daemon/config/isulad_config.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/src/daemon/config/isulad_config.c b/src/daemon/config/isulad_config.c +index 1af47127..51758adb 100644 +--- a/src/daemon/config/isulad_config.c ++++ b/src/daemon/config/isulad_config.c +@@ -32,7 +32,6 @@ + + #include "constants.h" + #include "utils.h" +-#include "sysinfo.h" + #include "err_msg.h" + #include "daemon_arguments.h" + #include "utils_array.h" +-- +2.42.0 + diff --git a/0055-verify-the-mount-dir-first-and-then-create-tmpdir.patch b/0055-verify-the-mount-dir-first-and-then-create-tmpdir.patch new file mode 100644 index 0000000000000000000000000000000000000000..6880ea80a8b4d39efb7fad19632977b8b89a8b04 --- /dev/null +++ b/0055-verify-the-mount-dir-first-and-then-create-tmpdir.patch @@ -0,0 +1,43 @@ +From 3d38013418d0c5304dfbafcb0b2a5b4062964c53 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Wed, 13 Dec 2023 15:13:12 +0800 +Subject: [PATCH 55/65] verify the mount dir first and then create tmpdir + +Signed-off-by: zhongtao +--- + src/utils/tar/util_archive.c | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c +index 29c2bc03..655b3516 100644 +--- a/src/utils/tar/util_archive.c ++++ b/src/utils/tar/util_archive.c +@@ -235,6 +235,12 @@ static int make_safedir_is_noexec(const char *flock_path, const char *dstdir, ch + return -1; + } + ++ // prevent the parent directory from being bind mounted to the subdirectory ++ if (is_parent_directory(dstdir, tmp_dir) == 0) { ++ ERROR("Cannot bind mount the parent directory: %s to its subdirectory: %s", dstdir, tmp_dir); ++ return -1; ++ } ++ + if (stat(dstdir, &buf) < 0) { + SYSERROR("Check chroot dir failed"); + return -1; +@@ -255,12 +261,6 @@ static int make_safedir_is_noexec(const char *flock_path, const char *dstdir, ch + return -1; + } + +- // prevent the parent directory from being bind mounted to the subdirectory +- if (is_parent_directory(dstdir, tmp_dir) == 0) { +- ERROR("Cannot bind mount the parent directory: %s to its subdirectory: %s", dstdir, tmp_dir); +- return -1; +- } +- + if (bind_mount_with_flock(flock_path, dstdir, tmp_dir) != 0) { + ERROR("Failed to bind mount from %s to %s with flock", dstdir, tmp_dir); + if (util_path_remove(tmp_dir) != 0) { +-- +2.42.0 + diff --git a/0056-2300-Maintaining-a-uniform-code-style.patch b/0056-2300-Maintaining-a-uniform-code-style.patch new file mode 100644 index 0000000000000000000000000000000000000000..06030b79ea225ba64c623188234e88730ae27ed0 --- /dev/null +++ b/0056-2300-Maintaining-a-uniform-code-style.patch @@ -0,0 +1,26 @@ +From 2f36e5cae2414804040b6168b79011550281d8d7 Mon Sep 17 00:00:00 2001 +From: chen524 +Date: Wed, 13 Dec 2023 08:02:20 +0000 +Subject: [PATCH 56/65] !2300 Maintaining a uniform code style * update + src/cmd/command_parser.c. + +--- + src/cmd/command_parser.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cmd/command_parser.c b/src/cmd/command_parser.c +index 1ad1d92b..93b19dae 100644 +--- a/src/cmd/command_parser.c ++++ b/src/cmd/command_parser.c +@@ -438,7 +438,7 @@ int command_valid_socket_append_array(command_option_t *option, const char *arg) + } + + if (util_array_append(option->data, arg) != 0) { +- ERROR("merge hosts config failed"); ++ COMMAND_ERROR("Merge hosts config failed"); + return -1; + } + len++; +-- +2.42.0 + diff --git a/0057-2312-Add-Huawei-Cloud-CodeArts-compilation-script.patch b/0057-2312-Add-Huawei-Cloud-CodeArts-compilation-script.patch new file mode 100644 index 0000000000000000000000000000000000000000..e04b0b296b5251167179829a655a9fd328eca369 --- /dev/null +++ b/0057-2312-Add-Huawei-Cloud-CodeArts-compilation-script.patch @@ -0,0 +1,36 @@ +From 5efff4c61ed885ce45d62e33e2e97a78519fefe8 Mon Sep 17 00:00:00 2001 +From: dreamloy <3038807110@qq.com> +Date: Wed, 13 Dec 2023 08:39:04 +0000 +Subject: [PATCH 57/65] =?UTF-8?q?!2312=20Add=20Huawei=20Cloud=20CodeArts?= + =?UTF-8?q?=20compilation=20script=20*=20=E5=B0=86codecheck=5Fcompile.sh?= + =?UTF-8?q?=20=E7=A7=BB=E5=8A=A8=E5=88=B0tools=E4=B8=8B=20*=20=E6=96=B0?= + =?UTF-8?q?=E5=A2=9E=E5=8D=8E=E4=B8=BA=E4=BA=91codeArs=E7=BC=96=E8=AF=91?= + =?UTF-8?q?=E8=84=9A=E6=9C=AC?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + tools/codecheck_compile.sh | 9 +++++++++ + 1 file changed, 9 insertions(+) + create mode 100644 tools/codecheck_compile.sh + +diff --git a/tools/codecheck_compile.sh b/tools/codecheck_compile.sh +new file mode 100644 +index 00000000..99cadfe7 +--- /dev/null ++++ b/tools/codecheck_compile.sh +@@ -0,0 +1,9 @@ ++## 华为云codeArts执行版本检查时,规则集涉及到代码安全增强包需要编译脚本才能执行 ++BASEPATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) ++ROOTDIR="$BASEPATH" ++PROGRAM=$(basename "${BASH_SOURCE[0]:-$0}") ++whoami ++ls ++cd docs/build_docs/guide/script ++chmod +x ./install_iSulad_on_Ubuntu_20_04_LTS.sh ++./install_iSulad_on_Ubuntu_20_04_LTS.sh +\ No newline at end of file +-- +2.42.0 + diff --git a/0058-bugfix-del-redundant-code.patch b/0058-bugfix-del-redundant-code.patch new file mode 100644 index 0000000000000000000000000000000000000000..496d0e9e80aade7dad00a18e9c1bbeb5847b03fe --- /dev/null +++ b/0058-bugfix-del-redundant-code.patch @@ -0,0 +1,26 @@ +From a593232e7f34de03142388fddecbea8f3b617245 Mon Sep 17 00:00:00 2001 +From: liuxu +Date: Wed, 13 Dec 2023 17:06:37 +0800 +Subject: [PATCH 58/65] bugfix:del redundant code + +--- + src/daemon/modules/image/image.c | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c +index 4a1950fe..f01265bf 100644 +--- a/src/daemon/modules/image/image.c ++++ b/src/daemon/modules/image/image.c +@@ -602,9 +602,6 @@ void free_im_prepare_request(im_prepare_request *request) + free(request->mount_label); + request->mount_label = NULL; + +- free(request->mount_label); +- request->mount_label = NULL; +- + free_json_map_string_string(request->storage_opt); + request->storage_opt = NULL; + +-- +2.42.0 + diff --git a/0059-improve-code-of-pull.patch b/0059-improve-code-of-pull.patch new file mode 100644 index 0000000000000000000000000000000000000000..d69b33c021a3089296dbb54e65dddad8053b8824 --- /dev/null +++ b/0059-improve-code-of-pull.patch @@ -0,0 +1,71 @@ +From e47abc01c8778cc07c11a331ae31ce46b6fd06a0 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Thu, 14 Dec 2023 10:59:34 +0800 +Subject: [PATCH 59/65] improve code of pull + +1. ignore unneccessary error log; +2. do not show progress, if stdout is not tty; + +Signed-off-by: haozi007 +--- + src/cmd/isula/images/pull.c | 6 ++++++ + .../modules/image/oci/storage/image_store/image_type.c | 8 ++++++++ + .../layer_store/graphdriver/overlay2/driver_overlay2.c | 5 +++++ + 3 files changed, 19 insertions(+) + +diff --git a/src/cmd/isula/images/pull.c b/src/cmd/isula/images/pull.c +index 9d420778..b30cc0bd 100644 +--- a/src/cmd/isula/images/pull.c ++++ b/src/cmd/isula/images/pull.c +@@ -36,6 +36,12 @@ struct client_arguments g_cmd_pull_args = {}; + static bool is_terminal_show_supported() + { + #ifdef GRPC_CONNECTOR ++ // if stdout is not tty, just ingore progress ++ if (!isatty(STDOUT_FILENO)) { ++ WARN("Stdout is not tty device, just ignore progress."); ++ return false; ++ } ++ + // Initialize the terminfo database + setupterm(NULL, STDOUT_FILENO, (int *)0); + +diff --git a/src/daemon/modules/image/oci/storage/image_store/image_type.c b/src/daemon/modules/image/oci/storage/image_store/image_type.c +index 50af0a69..50a81db2 100644 +--- a/src/daemon/modules/image/oci/storage/image_store/image_type.c ++++ b/src/daemon/modules/image/oci/storage/image_store/image_type.c +@@ -77,6 +77,14 @@ int try_fill_image_spec(image_t *img, const char *id, const char *image_store_di + goto out; + } + ++ // for new_image(), first try will failed because config file not exist ++ // and image_store_set_big_data() will retry this function ++ if (!util_file_exists(config_file)) { ++ WARN("Oci image spec: %s not found.", config_file); ++ ret = -1; ++ goto out; ++ } ++ + img->spec = oci_image_spec_parse_file(config_file, NULL, &err); + if (img->spec == NULL) { + ERROR("Failed to parse oci image spec: %s", err); +diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c +index 3bc433ae..3d814954 100644 +--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c ++++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c +@@ -1133,7 +1133,12 @@ static char *read_layer_lower_file(const char *layer_dir) + goto out; + } + ++ // lowest layer do not have lower file ++ if (!util_file_exists(lower_file)) { ++ goto out; ++ } + lower = util_read_text_file(lower_file); ++ + out: + free(lower_file); + return lower; +-- +2.42.0 + diff --git a/0060-remove-var-in-coverage-and-fix-build-test-remove.patch b/0060-remove-var-in-coverage-and-fix-build-test-remove.patch new file mode 100644 index 0000000000000000000000000000000000000000..7ec93d3da9fa133cfc4a35cd918c3fe2d6e05e2d --- /dev/null +++ b/0060-remove-var-in-coverage-and-fix-build-test-remove.patch @@ -0,0 +1,30 @@ +From f1fa4c7bdc2c67a4ef9c476ba9e0e2de6b589bc5 Mon Sep 17 00:00:00 2001 +From: jikai +Date: Thu, 14 Dec 2023 10:49:26 +0800 +Subject: [PATCH 60/65] remove /var/* in coverage and fix build/test remove + +Signed-off-by: jikai +--- + CI/generate_gcov.sh | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/CI/generate_gcov.sh b/CI/generate_gcov.sh +index 76bf382b..7518c5c1 100755 +--- a/CI/generate_gcov.sh ++++ b/CI/generate_gcov.sh +@@ -29,10 +29,8 @@ cp -r ~/build $ISULAD_COPY_PATH + cd $ISULAD_COPY_PATH/build + ctest + lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1 +-# Remove std/build files +-lcov --remove coverage.info '/usr/*' -o coverage.info --rc lcov_branch_coverage=1 +-lcov --remove coverage.info "$ISULAD_SRC_PATH/build/*" -o coverage.info --rc lcov_branch_coverage=1 +-lcov --remove coverage.info "$ISULAD_SRC_PATH/test/*" -o coverage.info --rc lcov_branch_coverage=1 ++# extract src only files ++lcov --extract coverage.info '*/iSulad/src/*' -o coverage.info --rc lcov_branch_coverage=1 + + # Generate html + genhtml --ignore-errors source -o $GCOV_RESULT_PATH/coverage coverage.info --branch-coverage --rc lcov_branch_coverage=1 +-- +2.42.0 + diff --git a/0061-2320-improve-CI-test.patch b/0061-2320-improve-CI-test.patch new file mode 100644 index 0000000000000000000000000000000000000000..449cb8aa2e2f8c7aa79cda5c7f2a96b616ec54a5 --- /dev/null +++ b/0061-2320-improve-CI-test.patch @@ -0,0 +1,165 @@ +From 712d82656ac9bafda7d29be70e7dbcd761a01f98 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Sun, 17 Dec 2023 05:58:56 +0000 +Subject: [PATCH 61/65] !2320 improve CI test * improve CI test + +--- + .../container_cases/restartpolicy.sh | 35 ++++++++++++++----- + CI/test_cases/image_cases/image_digest.sh | 10 +++--- + CI/test_cases/image_cases/image_search.sh | 26 ++------------ + 3 files changed, 35 insertions(+), 36 deletions(-) + +diff --git a/CI/test_cases/container_cases/restartpolicy.sh b/CI/test_cases/container_cases/restartpolicy.sh +index 11c3608f..0ab09636 100755 +--- a/CI/test_cases/container_cases/restartpolicy.sh ++++ b/CI/test_cases/container_cases/restartpolicy.sh +@@ -23,18 +23,37 @@ curr_path=$(dirname $(readlink -f "$0")) + data_path=$(realpath $curr_path/../data) + source ../helpers.sh + ++# $1 : retry limit ++# $2 : retry_interval ++# $3 : container name ++# $4 : expect restart count ++function do_retry() ++{ ++ for i in $(seq 1 "$1"); do ++ count=`isula inspect --format='{{json .RestartCount}}' ${3}` ++ if [ $count -eq $4 ]; then ++ return 0 ++ fi ++ sleep $2 ++ done ++ echo "expect $4, get $count" ++ return 1 ++} ++ + function do_test_on_failure() + { ++ local retry_limit=15 ++ local retry_interval=1 + containername=test_rp_on_failure + isula run --name $containername -td --restart on-failure:3 busybox /bin/sh -c "exit 2" + fn_check_eq "$?" "0" "run failed" + +- sleep 8 +- count=`isula inspect --format='{{json .RestartCount}}' $containername` +- if [[ $count != "3" ]];then +- echo "expect 3 but get $count" ++ do_retry ${retry_limit} ${retry_interval} ${containername} 3 ++ if [[ $? -ne 0 ]];then + TC_RET_T=$(($TC_RET_T+1)) + fi ++ ++ isula stop -t 0 $containername + testcontainer $containername exited + + isula rm $containername +@@ -43,14 +62,14 @@ function do_test_on_failure() + + function do_test_unless_stopped() + { ++ local retry_limit=15 ++ local retry_interval=1 + containername=test_rp_unless_stopped + isula run --name $containername -td --restart unless-stopped busybox /bin/sh -c "exit 2" + fn_check_eq "$?" "0" "run failed" + +- sleep 8 +- count=`isula inspect --format='{{json .RestartCount}}' $containername` +- if [[ $count == "0" ]];then +- echo "expect not 0 but get $count" ++ do_retry ${retry_limit} ${retry_interval} ${containername} 0 ++ if [[ $? -ne 0 ]];then + TC_RET_T=$(($TC_RET_T+1)) + fi + +diff --git a/CI/test_cases/image_cases/image_digest.sh b/CI/test_cases/image_cases/image_digest.sh +index e30f29f0..cc8b0e48 100755 +--- a/CI/test_cases/image_cases/image_digest.sh ++++ b/CI/test_cases/image_cases/image_digest.sh +@@ -25,14 +25,14 @@ source ../helpers.sh + function test_image_with_digest() + { + local ret=0 +- local image="busybox" +- local image2="ubuntu" +- local image_digest="busybox@sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43" ++ local image="3laho3y3.mirror.aliyuncs.com/library/busybox" ++ local image2="3laho3y3.mirror.aliyuncs.com/library/ubuntu" ++ local image_digest="3laho3y3.mirror.aliyuncs.com/library/busybox@sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee" + local test="pull && inspect && tag image with digest test => (${FUNCNAME[@]})" + + msg_info "${test} starting..." + +- isula pull docker.io/library/${image_digest} ++ isula pull ${image_digest} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE} + + isula tag ${image_digest} ${image}:digest_test +@@ -71,7 +71,7 @@ function test_image_with_digest() + isula inspect -f '{{.image.repo_tags}}' ${image_digest} | grep "${image}:digest_test" + [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - image digest delete error: ${image_digest}" && ((ret++)) + +- isula pull docker.io/library/${image2}:latest ++ isula pull ${image2}:latest + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image2}" && return ${FAILURE} + + digest=$(isula inspect "${image2}:latest" | grep "@sha256" | awk -F"\"" '{print $2}') +diff --git a/CI/test_cases/image_cases/image_search.sh b/CI/test_cases/image_cases/image_search.sh +index 1d281cb2..11af02f1 100755 +--- a/CI/test_cases/image_cases/image_search.sh ++++ b/CI/test_cases/image_cases/image_search.sh +@@ -33,6 +33,7 @@ function test_image_search() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && return ${FAILURE} + + msg_info "${test} starting..." ++ rm -rf /etc/isulad/daemon.bak + cp /etc/isulad/daemon.json /etc/isulad/daemon.bak + sed -i "/registry-mirrors/a\ \"docker.io\"," /etc/isulad/daemon.json + +@@ -49,39 +50,18 @@ function test_image_search() + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - search ${invalid_image} should fail as it's search name is invalid" && return ${FAILURE} + + # test search options +- isula search --no-trunc ${image} +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with no-trunc: ${image}" && ((ret++)) +- +- isula search --limit 5 ${image} +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with limit: ${image}" && ((ret++)) ++ isula search --no-trunc --limit 5 --filter stars=3 --filter is-official=true --filter is-automated=false --format "table {{.Name}}\t{{.IsOfficial}}" ${image} ++ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with search options: ${image}" && ((ret++)) + + isula search --limit -1 ${image} 2>&1 | grep "Invalid value" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with limit: ${image} and and catch error msg" && ((ret++)) + +- isula search --filter stars=3 ${image} +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with filter stars: ${image}" && ((ret++)) +- +- isula search --filter is-official=true ${image} +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with filter is-official: ${image}" && ((ret++)) +- +- isula search --filter is-automated=true ${image} 2>&1 | grep "AUTOMATED" +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with filter is-automated: ${image}" && ((ret++)) +- + isula search --filter aa=true ${image} 2>&1 | grep "Invalid filter" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to set filter for search ${image} and catch error msg" && ((ret++)) + +- isula search ${image} 2>&1 | grep "NAME" +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with default table format: ${image}" && ((ret++)) +- +- isula search --format "table {{.IsAutomated}}\t{{.IsOfficial}}" ${image} 2>&1 | grep "AUTOMATED" +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with table format: ${image}" && ((ret++)) +- + isula search --format "{{Name}}" ${image} 2>&1 | grep "invalid format field" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to set format for search ${image} and catch error msg" && ((ret++)) + +- isula search --format "{{.Name}}" ${image} 2>&1 +- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with none-table format: ${image}" && ((ret++)) +- + cp -f /etc/isulad/daemon.bak /etc/isulad/daemon.json + + check_valgrind_log +-- +2.42.0 + diff --git a/0062-verify-name-and-digest-consistency.patch b/0062-verify-name-and-digest-consistency.patch new file mode 100644 index 0000000000000000000000000000000000000000..43571afbcbe052d2a7040f15e3429d9c67088adc --- /dev/null +++ b/0062-verify-name-and-digest-consistency.patch @@ -0,0 +1,319 @@ +From 950dc3c56f192061383de4d19229ace243eae503 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 18 Dec 2023 15:54:37 +0800 +Subject: [PATCH 62/65] verify name and digest consistency + +Signed-off-by: zhongtao +--- + .../oci/storage/image_store/image_store.c | 265 +++++++++++------- + 1 file changed, 162 insertions(+), 103 deletions(-) + +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 58baa47a..1b482504 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 +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -444,11 +445,161 @@ out: + return value; + } + ++static int resort_image_names(const char **names, size_t names_len, char **first_name, char ***image_tags, ++ char ***image_digests) ++{ ++ int ret = 0; ++ size_t i; ++ char *prefix = NULL; ++ ++ for (i = 0; i < names_len; i++) { ++ size_t len = strlen(names[i]); ++ if (strlen(names[i]) > MAX_IMAGE_NAME_LENGTH) { ++ prefix = util_sub_string(names[i], len - MAX_IMAGE_NAME_LENGTH, ++ 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]); ++ ret = -1; ++ goto out; ++ } ++ } else { ++ if (util_array_append(image_tags, names[i]) != 0) { ++ ERROR("Failed to append image to tags: %s", names[i]); ++ ret = -1; ++ goto out; ++ } ++ } ++ } ++ ++ if (first_name == NULL) { ++ goto out; ++ } ++ ++ if (util_array_len((const char **)(*image_digests)) > 0) { ++ free(*first_name); ++ *first_name = util_strdup_s((*image_digests)[0]); ++ } ++ ++ if (util_array_len((const char **)(*image_tags)) > 0) { ++ free(*first_name); ++ *first_name = util_strdup_s((*image_tags)[0]); ++ } ++ ++out: ++ if (ret != 0) { ++ util_free_array(*image_digests); ++ util_free_array(*image_tags); ++ free(*first_name); ++ } ++ free(prefix); ++ return ret; ++} ++ ++// Validate checks that the contents is a valid digest ++static bool validate_digest(const char *digest) ++{ ++ bool ret = true; ++ const char *sha256_encode_patten = "^[a-f0-9]{64}$"; ++ char *value = util_strdup_s(digest); ++ char *index = strchr(value, ':'); ++ char *alg = NULL; ++ char *encode = NULL; ++ ++ // contains ':' and is not the last character ++ if (index == NULL || index - value + 1 == strlen(value)) { ++ INFO("Invalid checksum digest format"); ++ ret = false; ++ goto out; ++ } ++ ++ *index++ = '\0'; ++ ++ alg = value; ++ encode = index; ++ // Currently only support SHA256 algorithm ++ if (strcmp(alg, "sha256") != 0) { ++ DEBUG("Unsupported digest algorithm: %s", alg); ++ ret = false; ++ goto out; ++ } ++ ++ ret = util_reg_match(sha256_encode_patten, encode) == 0; ++ ++out: ++ free(value); ++ return ret; ++} ++ ++// Parsing a reference string as a possible identifier, full digest, or familiar name. ++static char *parse_digest_reference(const char *ref) ++{ ++ char *indentfier_patten = "^[a-f0-9]{64}$"; ++ ++ if (util_reg_match(indentfier_patten, ref) == 0) { ++ return util_string_append(ref, "sha256:"); ++ } ++ ++ if (validate_digest(ref)) { ++ return util_strdup_s(ref); ++ } ++ ++ return oci_normalize_image_name(ref); ++} ++ ++static int is_name_digest_consistent(const char *name, char **names, size_t names_len, const char *digest) ++{ ++ size_t i; ++ int ret = -1; ++ int nret = 0; ++ char *tag_pos = NULL; ++ char **tags = NULL; ++ char **digests = NULL; ++ ++ if (resort_image_names((const char **)names, names_len, NULL, &tags, &digests) != 0) { ++ ERROR("Failed to resort image names"); ++ goto out; ++ } ++ ++ for (i = 0; i < util_array_len((const char **)tags); i++) { ++ __isula_auto_free char *ref = NULL; ++ __isula_auto_free char *tmp_repo_digests = NULL; ++ ref = parse_digest_reference(tags[i]); ++ if (ref == NULL) { ++ continue; ++ } ++ tag_pos = util_tag_pos(ref); ++ if (tag_pos == NULL) { ++ ERROR("invalid ref %s", ref); ++ continue; ++ } ++ *tag_pos = '\0'; ++ ++ nret = asprintf(&tmp_repo_digests, "%s@%s", ref, digest); ++ if (nret < 0) { ++ ERROR("Failed to receive repo digest"); ++ goto out; ++ } ++ if (strcmp(name, tmp_repo_digests) == 0) { ++ ret = 0; ++ goto out; ++ } ++ } ++out: ++ util_free_array(tags); ++ util_free_array(digests); ++ return ret; ++} ++ + // by_digest returns the image which matches the specified name. + static image_t *by_digest(const char *name) + { + digest_image_t *digest_filter_images = NULL; + char *digest = NULL; ++ image_t *tmp_ret = NULL; + + // split digest for image name with digest + digest = strrchr(name, '@'); +@@ -457,12 +608,21 @@ static image_t *by_digest(const char *name) + } + digest++; + digest_filter_images = (digest_image_t *)map_search(g_image_store->bydigest, (void *)digest); +- if (digest_filter_images == NULL) { ++ if (digest_filter_images == NULL || linked_list_empty(&(digest_filter_images->images_list))) { + return NULL; + } + + // currently, a digest corresponds to an image, directly returning the first element +- return linked_list_first_elem(&(digest_filter_images->images_list)); ++ tmp_ret = linked_list_first_elem(&(digest_filter_images->images_list)); ++ ++ // verify name and digest consistency to ensure we are not matching images to different repositories, ++ // even if the digests match. ++ // For example, ubuntu@sha256:abc......, shouldn't match test@sha256:abc...... ++ if (is_name_digest_consistent(name, tmp_ret->simage->names, tmp_ret->simage->names_len, digest) != 0) { ++ return NULL; ++ } ++ ++ return tmp_ret; + } + + static image_t *lookup(const char *id) +@@ -2001,107 +2161,6 @@ out: + return ret; + } + +-static int resort_image_names(const char **names, size_t names_len, char **first_name, char ***image_tags, +- char ***image_digests) +-{ +- int ret = 0; +- size_t i; +- char *prefix = NULL; +- +- for (i = 0; i < names_len; i++) { +- size_t len = strlen(names[i]); +- if (strlen(names[i]) > MAX_IMAGE_NAME_LENGTH) { +- prefix = util_sub_string(names[i], len - MAX_IMAGE_NAME_LENGTH, +- 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]); +- ret = -1; +- goto out; +- } +- } else { +- if (util_array_append(image_tags, names[i]) != 0) { +- ERROR("Failed to append image to tags: %s", names[i]); +- ret = -1; +- goto out; +- } +- } +- } +- +- if (util_array_len((const char **)(*image_digests)) > 0) { +- free(*first_name); +- *first_name = util_strdup_s((*image_digests)[0]); +- } +- +- if (util_array_len((const char **)(*image_tags)) > 0) { +- free(*first_name); +- *first_name = util_strdup_s((*image_tags)[0]); +- } +- +-out: +- if (ret != 0) { +- util_free_array(*image_digests); +- util_free_array(*image_tags); +- free(*first_name); +- } +- free(prefix); +- return ret; +-} +- +-// Validate checks that the contents is a valid digest +-static bool validate_digest(const char *digest) +-{ +- bool ret = true; +- const char *sha256_encode_patten = "^[a-f0-9]{64}$"; +- char *value = util_strdup_s(digest); +- char *index = strchr(value, ':'); +- char *alg = NULL; +- char *encode = NULL; +- +- // contains ':' and is not the last character +- if (index == NULL || index - value + 1 == strlen(value)) { +- INFO("Invalid checksum digest format"); +- ret = false; +- goto out; +- } +- +- *index++ = '\0'; +- +- alg = value; +- encode = index; +- // Currently only support SHA256 algorithm +- if (strcmp(alg, "sha256") != 0) { +- DEBUG("Unsupported digest algorithm: %s", alg); +- ret = false; +- goto out; +- } +- +- ret = util_reg_match(sha256_encode_patten, encode) == 0; +- +-out: +- free(value); +- return ret; +-} +- +-// Parsing a reference string as a possible identifier, full digest, or familiar name. +-static char *parse_digest_reference(const char *ref) +-{ +- char *indentfier_patten = "^[a-f0-9]{64}$"; +- +- if (util_reg_match(indentfier_patten, ref) == 0) { +- return util_string_append(ref, "sha256:"); +- } +- +- if (validate_digest(ref)) { +- return util_strdup_s(ref); +- } +- +- return oci_normalize_image_name(ref); +-} +- + static int pack_repo_digest(char ***old_repo_digests, const char **image_tags, const char *digest, char ***repo_digests) + { + int ret = 0; +-- +2.42.0 + diff --git a/0063-code-improve-for-oci_rmi.patch b/0063-code-improve-for-oci_rmi.patch new file mode 100644 index 0000000000000000000000000000000000000000..b5b61e2b022db8eee5cc1f69f0b22bc6a9f38952 --- /dev/null +++ b/0063-code-improve-for-oci_rmi.patch @@ -0,0 +1,35 @@ +From 2db6add74c621344e902ce28b5e6764f6ef55b8e Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 18 Dec 2023 16:07:57 +0800 +Subject: [PATCH 63/65] code improve for oci_rmi + +Signed-off-by: zhongtao +--- + src/daemon/modules/image/oci/oci_image.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/src/daemon/modules/image/oci/oci_image.c b/src/daemon/modules/image/oci/oci_image.c +index 471510e7..9cf2cd4f 100644 +--- a/src/daemon/modules/image/oci/oci_image.c ++++ b/src/daemon/modules/image/oci/oci_image.c +@@ -542,6 +542,17 @@ int oci_rmi(const im_rmi_request *request) + goto out; + } + ++ for (i = 0; i < image_names_len; i++) { ++ if (strcmp(real_image_name, image_names[i]) == 0) { ++ break; ++ } ++ } ++ if (i == image_names_len) { ++ ERROR("Invalid real_image_name"); ++ ret = -1; ++ goto out; ++ } ++ + reduced_image_names = (char **)util_smart_calloc_s(sizeof(char *), image_names_len - 1); + if (reduced_image_names == NULL) { + ERROR("Out of memory"); +-- +2.42.0 + diff --git a/0064-bugfix-for-resort_image_names.patch b/0064-bugfix-for-resort_image_names.patch new file mode 100644 index 0000000000000000000000000000000000000000..d6d7a8c92ad0a72cbe5bd31077983af3f99201db --- /dev/null +++ b/0064-bugfix-for-resort_image_names.patch @@ -0,0 +1,26 @@ +From 39686ee4443400b810edecb38e3891b808e3a065 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Mon, 18 Dec 2023 20:59:46 +0800 +Subject: [PATCH 64/65] bugfix for resort_image_names + +Signed-off-by: zhongtao +--- + src/daemon/modules/image/oci/storage/image_store/image_store.c | 2 ++ + 1 file changed, 2 insertions(+) + +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 1b482504..034268bc 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 +@@ -473,6 +473,8 @@ static int resort_image_names(const char **names, size_t names_len, char **first + goto out; + } + } ++ free(prefix); ++ prefix = NULL; + } + + if (first_name == NULL) { +-- +2.42.0 + diff --git a/0065-refactor-isulad-shim-log.patch b/0065-refactor-isulad-shim-log.patch new file mode 100644 index 0000000000000000000000000000000000000000..d8042e1521ea8f12bf9a6b3f4281d24efbdb98a9 --- /dev/null +++ b/0065-refactor-isulad-shim-log.patch @@ -0,0 +1,1590 @@ +From ec5736c76acc80b6099c82cd21fdad5b8da79b73 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Tue, 19 Dec 2023 19:47:18 +0800 +Subject: [PATCH 65/65] refactor isulad-shim log + +Signed-off-by: zhongtao +--- + src/cmd/isulad-shim/common.c | 179 ++++++++------- + src/cmd/isulad-shim/common.h | 33 ++- + src/cmd/isulad-shim/main.c | 60 ++--- + src/cmd/isulad-shim/process.c | 192 +++++++++------- + .../modules/runtime/isula/isula_rt_ops.c | 212 +++++++++++++----- + 5 files changed, 425 insertions(+), 251 deletions(-) + +diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c +index 3cc7d2a7..d96b6c65 100644 +--- a/src/cmd/isulad-shim/common.c ++++ b/src/cmd/isulad-shim/common.c +@@ -31,34 +31,124 @@ + + #include + #include ++#include ++#include ++#include + +-int g_log_fd = -1; +-int g_attach_log_fd = -1; ++char *g_shim_errmsg = NULL; ++bool log_to_stderr = false; + +-int init_shim_log(void) ++int isulad_shim_log_init(const char *file, const char *priority) + { +- g_log_fd = open_no_inherit(SHIM_LOG_NAME, O_CREAT | O_WRONLY | O_APPEND | O_SYNC, LOG_FILE_MODE); +- if (g_log_fd < 0) { +- return SHIM_ERR; ++ __isula_auto_free char *full_path = NULL; ++ const char *pre_name = "fifo:"; ++ size_t pre_len = 0; ++ struct isula_libutils_log_config lconf = { 0 }; ++ ++ if (file == NULL || priority == NULL || strncmp(file, pre_name, pre_len) != 0) { ++ goto err_out; + } +- return SHIM_OK; ++ ++ pre_len = strlen(pre_name); ++ lconf.name = "engine"; ++ /* File has prefix "fifo:", */ ++ full_path = isula_strdup_s(file + pre_len); ++ lconf.file = full_path; ++ lconf.driver = "fifo"; ++ lconf.priority = priority; ++ if (isula_libutils_log_enable(&lconf) != 0) { ++ goto err_out; ++ } ++ ++ return 0; ++err_out: ++ // because shim log init error, print error msg to stderr. ++ // isulad can obtain the reason why shim exits. ++ dprintf(STDERR_FILENO, "failed to init shim log"); ++ return -1; + } + +-int init_attach_log(void) ++void shim_set_error_message(const char *format, ...) + { +- g_attach_log_fd = open_no_inherit(ATTACH_LOG_NAME, O_CREAT | O_WRONLY | O_APPEND | O_SYNC, LOG_FILE_MODE); +- if (g_attach_log_fd < 0) { +- return SHIM_ERR; ++ int ret = 0; ++ char errbuf[BUFSIZ + 1] = { 0 }; ++ va_list argp; ++ ++ if (format == NULL) { ++ return; + } +- return SHIM_OK; ++ va_start(argp, format); ++ ++ ret = vsnprintf(errbuf, BUFSIZ, format, argp); ++ va_end(argp); ++ if (ret < 0) { ++ return; ++ } ++ ++ SHIM_CLEAR_ERRMSG(); ++ g_shim_errmsg = isula_strdup_s(errbuf); ++} ++ ++void shim_try_set_error_message(const char *format, ...) ++{ ++ int ret = 0; ++ ++ if (g_shim_errmsg != NULL) { ++ return; ++ } ++ char errbuf[BUFSIZ + 1] = { 0 }; ++ ++ va_list argp; ++ va_start(argp, format); ++ ++ ret = vsnprintf(errbuf, BUFSIZ, format, argp); ++ va_end(argp); ++ if (ret < 0) { ++ return; ++ } ++ ++ g_shim_errmsg = isula_strdup_s(errbuf); ++} ++ ++void shim_append_error_message(const char *format, ...) ++{ ++ int ret = 0; ++ char errbuf[BUFSIZ + 1] = { 0 }; ++ char *result = NULL; ++ ++ va_list argp; ++ va_start(argp, format); ++ ++ ret = vsnprintf(errbuf, BUFSIZ, format, argp); ++ va_end(argp); ++ if (ret < 0) { ++ return; ++ } ++ result = isula_string_append(g_shim_errmsg, errbuf); ++ if (result == NULL) { ++ return; ++ } ++ if (g_shim_errmsg != NULL) { ++ free(g_shim_errmsg); ++ } ++ g_shim_errmsg = result; ++} ++ ++void error_exit(int exit_code) ++{ ++ if (log_to_stderr && g_shim_errmsg != NULL) { ++ dprintf(STDERR_FILENO, "shim-error: %s\n", g_shim_errmsg); ++ } ++ exit(exit_code); + } + + void signal_routine(int sig) + { + switch (sig) { + case SIGALRM: +- write_message(ERR_MSG, "runtime timeout"); +- exit(EXIT_FAILURE); ++ ERROR("runtime timeout"); ++ shim_set_error_message("runtime timeout"); ++ error_exit(EXIT_FAILURE); + default: + break; + } +@@ -172,67 +262,6 @@ int generate_random_str(char *id, size_t len) + return SHIM_OK; + } + +-#define MAX_MSG_JSON_TEMPLATE 32 +-#define MAX_MESSAGE_CONTENT_LEN 128 +-#define MAX_MESSAGE_LEN (MAX_MSG_JSON_TEMPLATE + MAX_MESSAGE_CONTENT_LEN) +- +-static void format_log_msg(const char *level, const char *buf, char *msg, int max_message_len) +-{ +- time_t current_time = time(NULL); +- struct tm *local_time = localtime(¤t_time); +- char time_str[20]; +- +- strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", local_time); +- +- (void)snprintf(msg, max_message_len - 1, "{\"time\": \"%s\", \"level\": \"%s\", \"msg\": \"%s\"}\n", time_str, level, +- buf); +-} +- +-void write_message(const char *level, const char *fmt, ...) +-{ +- if (g_log_fd < 0) { +- return; +- } +- +- char buf[MAX_MESSAGE_CONTENT_LEN] = { 0 }; +- char msg[MAX_MESSAGE_LEN] = { 0 }; +- int nwrite = -1; +- +- va_list arg_list; +- va_start(arg_list, fmt); +- nwrite = vsnprintf(buf, MAX_MESSAGE_CONTENT_LEN, fmt, arg_list); +- va_end(arg_list); +- if (nwrite < 0) { +- return; +- } +- +- format_log_msg(level, buf, msg, MAX_MESSAGE_CONTENT_LEN); +- +- (void)isula_file_total_write_nointr(g_log_fd, msg, strlen(msg)); +-} +- +-void write_attach_message(const char *level, const char *fmt, ...) +-{ +- char buf[MAX_MESSAGE_CONTENT_LEN] = { 0 }; +- char msg[MAX_MESSAGE_LEN] = { 0 }; +- int nwrite = -1; +- +- if (g_attach_log_fd < 0) { +- return; +- } +- va_list arg_list; +- va_start(arg_list, fmt); +- nwrite = vsnprintf(buf, MAX_MESSAGE_CONTENT_LEN, fmt, arg_list); +- va_end(arg_list); +- if (nwrite < 0) { +- return; +- } +- +- format_log_msg(level, buf, msg, MAX_MESSAGE_CONTENT_LEN); +- +- (void)isula_file_total_write_nointr(g_attach_log_fd, msg, strlen(msg)); +-} +- + /* note: This function can only read small text file. */ + char *read_text_file(const char *path) + { +diff --git a/src/cmd/isulad-shim/common.h b/src/cmd/isulad-shim/common.h +index c4f86d24..9ac11b61 100644 +--- a/src/cmd/isulad-shim/common.h ++++ b/src/cmd/isulad-shim/common.h +@@ -55,7 +55,8 @@ extern "C" { + #define MAX_RUNTIME_ARGS 100 + + #define SHIM_BINARY "isulad-shim" +-#define SHIM_LOG_NAME "shim-log.json" ++#define DEFAULT_ISULAD_SHIIM_LOG_PATH "fifo:/var/run/isulad/isulad_log_gather_fifo" ++#define DEFAULT_ISULAD_SHIIM_LOG_LEVEL "ERROR" + + #define CONTAINER_ACTION_REBOOT 129 + #define CONTAINER_ACTION_SHUTDOWN 130 +@@ -72,9 +73,7 @@ extern "C" { + #define SOCKET_DIRECTORY_MODE 0600 + #define ATTACH_FIFOPATH_MODE 0600 + +-int init_shim_log(void); +- +-int init_attach_log(void); ++int isulad_shim_log_init(const char *file, const char *priority); + + void signal_routine(int sig); + +@@ -114,13 +113,31 @@ struct shim_fifos_fd { + int err_fd; + }; + +-char *read_text_file(const char *path); ++/* record the isulad-shim errmsg */ ++extern char *g_shim_errmsg; + +-int cmd_combined_output(const char *binary, const char *params[], void *output, int *output_len); ++extern bool log_to_stderr; ++ ++/* clear the g_shim_errmsg */ ++#define SHIM_CLEAR_ERRMSG() \ ++ do { \ ++ if (g_shim_errmsg != NULL) { \ ++ free(g_shim_errmsg); \ ++ g_shim_errmsg = NULL; \ ++ } \ ++ } while (0) ++ ++void shim_set_error_message(const char *format, ...); + +-void write_message(const char *level, const char *fmt, ...); ++void shim_try_set_error_message(const char *format, ...); + +-void write_attach_message(const char *level, const char *fmt, ...); ++void shim_append_error_message(const char *format, ...); ++ ++void error_exit(int exit_code); ++ ++char *read_text_file(const char *path); ++ ++int cmd_combined_output(const char *binary, const char *params[], void *output, int *output_len); + + int generate_random_str(char *id, size_t len); + +diff --git a/src/cmd/isulad-shim/main.c b/src/cmd/isulad-shim/main.c +index deb07271..a12e459f 100644 +--- a/src/cmd/isulad-shim/main.c ++++ b/src/cmd/isulad-shim/main.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + #include "common.h" + #include "process.h" +@@ -91,17 +92,25 @@ int main(int argc, char **argv) + char *bundle = NULL; + char *rt_name = NULL; + char *log_level = NULL; ++ char *engine_log_path = NULL; + int ret = SHIM_ERR; + process_t *p = NULL; + // execSync timeout + uint64_t timeout = 0; + pthread_t tid_epoll; + +- ret = init_shim_log(); ++ engine_log_path = getenv("ISULAD_SHIIM_LOG_PATH"); ++ if (engine_log_path == NULL) { ++ engine_log_path = DEFAULT_ISULAD_SHIIM_LOG_PATH; ++ } ++ ++ log_level = getenv("ISULAD_SHIIM_LOG_LEVEL"); ++ if (log_level == NULL) { ++ log_level = DEFAULT_ISULAD_SHIIM_LOG_LEVEL; ++ } ++ ++ ret = isulad_shim_log_init(engine_log_path, log_level); + if (ret != SHIM_OK) { +- // because shim log init error, print error msg to stderr. +- // isulad can obtain the reason why shim exits. +- dprintf(STDERR_FILENO, "failed to init shim log"); + _exit(EXIT_FAILURE); + } + +@@ -113,22 +122,26 @@ int main(int argc, char **argv) + + ret = set_subreaper(); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "set subreaper failed:%d", ret); +- exit(EXIT_FAILURE); ++ ERROR("set subreaper failed:%d", ret); ++ error_exit(EXIT_FAILURE); + } + + ret = parse_args(argc, argv, &container_id, &bundle, &rt_name, &log_level, &timeout); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "parse args failed:%d", ret); +- exit(EXIT_FAILURE); ++ ERROR("parse args failed:%d", ret); ++ error_exit(EXIT_FAILURE); + } + + p = new_process(container_id, bundle, rt_name); + if (p == NULL) { +- write_message(ERR_MSG, "new process failed"); +- exit(EXIT_FAILURE); ++ ERROR("new process failed"); ++ error_exit(EXIT_FAILURE); + } + ++ // If isulad-shim is a child process of the isulad process, ++ // print the log to stderr so that isulad can obtain the exit information of isulad-shim. ++ log_to_stderr = (p->state->exec) && (p->state->isulad_stdin != NULL || p->state->isulad_stdout != NULL || p->state->isulad_stderr != NULL); ++ + /* + * Open exit pipe + * The exit pipe exists only when the container is started, +@@ -138,8 +151,9 @@ int main(int argc, char **argv) + if (p->state->exit_fifo != NULL) { + int efd = open_no_inherit("exit_fifo", O_WRONLY, -1); + if (efd < 0) { +- write_message(ERR_MSG, "open exit pipe failed:%d", SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); ++ ERROR("open exit pipe failed:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("open exit pipe failed:%d", SHIM_SYS_ERR(errno)); ++ error_exit(EXIT_FAILURE); + } + p->exit_fd = efd; + } +@@ -148,22 +162,18 @@ int main(int argc, char **argv) + if (p->state->attach_socket != NULL) { + ret = prepare_attach_socket(p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "failed to prepare attach socket:%d", ret); +- exit(EXIT_FAILURE); +- } +- +- ret = init_attach_log(); +- if (ret != SHIM_OK) { +- write_message(ERR_MSG, "failed to init shim attach log"); +- exit(EXIT_FAILURE); ++ ERROR("failed to prepare attach socket:%d", ret); ++ shim_append_error_message("open exit pipe failed:%d", SHIM_SYS_ERR(errno)); ++ error_exit(EXIT_FAILURE); + } + } + + /* start epoll for io copy */ + ret = process_io_start(p, &tid_epoll); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "process io init failed:%d", ret); +- exit(EXIT_FAILURE); ++ ERROR("process io init failed:%d", ret); ++ shim_set_error_message("process io init failed:%d", ret); ++ error_exit(EXIT_FAILURE); + } + + ret = create_process(p); +@@ -171,17 +181,17 @@ int main(int argc, char **argv) + if (p->console_sock_path != NULL) { + (void)unlink(p->console_sock_path); + } +- exit(EXIT_FAILURE); ++ error_exit(EXIT_FAILURE); + } + + released_timeout_exit(); + + ret = process_signal_handle_routine(p, tid_epoll, timeout); + if (ret == SHIM_ERR) { +- exit(EXIT_FAILURE); ++ error_exit(EXIT_FAILURE); + } + if (ret == SHIM_ERR_TIMEOUT) { +- exit(SHIM_EXIT_TIMEOUT); ++ error_exit(SHIM_EXIT_TIMEOUT); + } + + exit(EXIT_SUCCESS); +diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c +index 97524f1a..5c508173 100644 +--- a/src/cmd/isulad-shim/process.c ++++ b/src/cmd/isulad-shim/process.c +@@ -46,6 +46,7 @@ + #include + #include + #include ++#include + + #include "common.h" + #include "terminal.h" +@@ -61,7 +62,8 @@ static shim_client_process_state *load_process() + + p_state = shim_client_process_state_parse_file("process.json", NULL, &err); + if (p_state == NULL) { +- write_message(ERR_MSG, "parse process state failed: %s", err); ++ ERROR("parse process state failed: %s", err); ++ shim_set_error_message("parse process state failed: %s", err); + } + /* "err" will definitely be allocated memory in the function above */ + free(err); +@@ -76,7 +78,7 @@ static int open_fifo_noblock(const char *path, mode_t mode) + /* By default, We consider that the file has been created by isulad */ + fd = open_no_inherit(path, mode | O_NONBLOCK, -1); + if (fd < 0) { +- write_message(ERR_MSG, "open fifo file failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("open fifo file failed:%d", SHIM_SYS_ERR(errno)); + return -1; + } + +@@ -115,7 +117,7 @@ static int receive_fd(int sock) + */ + int ret = recvmsg(sock, &msg, 0); + if (ret <= 0) { +- write_message(ERR_MSG, "get console fd failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("get console fd failed:%d", SHIM_SYS_ERR(errno)); + free(cmptr); + return -1; + } +@@ -198,14 +200,14 @@ static int add_attach_terminal_fifos(const char *in, const char *out, const char + bool invalid = (in != NULL && !fifo_exists(in)) || (out != NULL && !fifo_exists(out)) || (err != NULL && + !fifo_exists(err)); + if (invalid) { +- write_attach_message(ERR_MSG, "File %s or %s or %s does not refer to a FIFO", in, out, err); ++ ERROR("File %s or %s or %s does not refer to a FIFO", in, out, err); + return -1; + } + + if (in != NULL) { + fifofd_in = isula_file_open(in, O_RDONLY | O_NONBLOCK | O_CLOEXEC, 0); + if (fifofd_in < 0) { +- write_attach_message(ERR_MSG, "Failed to open FIFO: %s", in); ++ ERROR("Failed to open FIFO: %s", in); + return -1; + } + } +@@ -213,7 +215,7 @@ static int add_attach_terminal_fifos(const char *in, const char *out, const char + if (out != NULL) { + fifofd_out = isula_file_open(out, O_WRONLY | O_NONBLOCK | O_CLOEXEC, 0); + if (fifofd_out < 0) { +- write_attach_message(ERR_MSG, "Failed to open FIFO: %s", out); ++ ERROR("Failed to open FIFO: %s", out); + return -1; + } + } +@@ -221,14 +223,14 @@ static int add_attach_terminal_fifos(const char *in, const char *out, const char + if (err != NULL) { + fifofd_err = isula_file_open(err, O_WRONLY | O_NONBLOCK | O_CLOEXEC, 0); + if (fifofd_err < 0) { +- write_attach_message(ERR_MSG, "Failed to open FIFO: %s", err); ++ ERROR("Failed to open FIFO: %s", err); + return -1; + } + } + + fifos = isula_common_calloc_s(sizeof(*fifos)); + if (fifos == NULL) { +- write_attach_message(ERR_MSG, "Out of memory"); ++ ERROR("Out of memory"); + goto err_out; + } + +@@ -241,7 +243,7 @@ static int add_attach_terminal_fifos(const char *in, const char *out, const char + fifos->err_fd = isula_transfer_fd(fifofd_err); + node = isula_common_calloc_s(sizeof(struct isula_linked_list)); + if (node == NULL) { +- write_attach_message(ERR_MSG, "Out of memory"); ++ ERROR("Out of memory"); + goto err_out; + } + +@@ -300,7 +302,7 @@ static int stdin_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t * + w_count = isula_file_total_write_nointr(*fd_to, p->buf, r_count); + if (w_count < 0) { + /* When any error occurs, set the write fd -1 */ +- write_message(WARN_MSG, "write in_fd %d error:%d", *fd_to, SHIM_SYS_ERR(errno)); ++ WARN("write in_fd %d error:%d", *fd_to, SHIM_SYS_ERR(errno)); + close(*fd_to); + *fd_to = -1; + } +@@ -317,7 +319,7 @@ static int attach_stdin_cb(int fd, uint32_t events, void *cbdata, isula_epoll_de + struct isula_linked_list *item; + + if (events & EPOLLHUP) { +- write_message(ERR_MSG, "attach stdin %d received the EPOLLHUP event", fd); ++ ERROR("attach stdin %d received the EPOLLHUP event", fd); + goto err_out; + } + +@@ -329,7 +331,7 @@ static int attach_stdin_cb(int fd, uint32_t events, void *cbdata, isula_epoll_de + + r_count = isula_file_read_nointr(fd, p->buf, DEFAULT_IO_COPY_BUF); + if (r_count <= 0) { +- write_message(ERR_MSG, "failed to read from attach stdin %d, error:%d", fd, SHIM_SYS_ERR(errno)); ++ ERROR("failed to read from attach stdin %d, error:%d", fd, SHIM_SYS_ERR(errno)); + goto err_out; + } + +@@ -345,7 +347,7 @@ static int attach_stdin_cb(int fd, uint32_t events, void *cbdata, isula_epoll_de + w_count = isula_file_total_write_nointr(*fd_to, p->buf, r_count); + if (w_count < 0) { + /* When any error occurs, set the write fd -1 */ +- write_message(WARN_MSG, "write in_fd %d error:%d", *fd_to, SHIM_SYS_ERR(errno)); ++ WARN("write in_fd %d error:%d", *fd_to, SHIM_SYS_ERR(errno)); + close(*fd_to); + *fd_to = -1; + } +@@ -381,7 +383,7 @@ static int stdout_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + w_count = isula_file_total_write_nointr(p->isulad_io->out, p->buf, r_count); + if (w_count < 0) { + /* When any error occurs, set the write fd -1 */ +- write_message(WARN_MSG, "write out_fd %d error:%d", p->isulad_io->out, SHIM_SYS_ERR(errno)); ++ WARN("write out_fd %d error:%d", p->isulad_io->out, SHIM_SYS_ERR(errno)); + close(p->isulad_io->out); + p->isulad_io->out = -1; + } +@@ -427,7 +429,7 @@ static int stderr_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + w_count = isula_file_total_write_nointr(p->isulad_io->err, p->buf, r_count); + if (w_count < 0) { + /* When any error occurs, set the write fd -1 */ +- write_message(WARN_MSG, "write err_fd %d error:%d", p->isulad_io->err, SHIM_SYS_ERR(errno)); ++ WARN("write err_fd %d error:%d", p->isulad_io->err, SHIM_SYS_ERR(errno)); + close(p->isulad_io->err); + p->isulad_io->err = -1; + } +@@ -482,37 +484,37 @@ static bool attach_fifopath_security_check(process_t *p, const char *fifopath) + char real_path[PATH_MAX] = { 0 }; + + if (isula_validate_absolute_path(fifopath) != 0) { +- write_attach_message(ERR_MSG, "attach fifo path \"%s\" must be an valid absolute path", fifopath); ++ ERROR("attach fifo path \"%s\" must be an valid absolute path", fifopath); + return false; + } + + if (realpath(fifopath, real_path) == NULL) { +- write_attach_message(ERR_MSG, "Failed to get realpath for '%s': %s.", real_path, SHIM_SYS_ERR(errno)); ++ ERROR("Failed to get realpath for '%s': %d.", real_path, SHIM_SYS_ERR(errno)); + return false; + } + + if (!isula_has_prefix(real_path, p->workdir)) { +- write_attach_message(ERR_MSG, "attach fifo path \"%s\" must be under the state path", real_path, p->workdir); ++ ERROR("attach fifo path \"%s\" must be under the state path: %s", real_path, p->workdir); + return false; + } + + if (lstat(real_path, &st) != 0) { +- write_attach_message(ERR_MSG, "Failed to lstat %s : %s", real_path, SHIM_SYS_ERR(errno)); ++ ERROR("Failed to lstat %s : %d", real_path, SHIM_SYS_ERR(errno)); + return false; + } + + if (!S_ISFIFO(st.st_mode)) { +- write_attach_message(ERR_MSG, "attach fifo path \"%s\" must be an FIFO", real_path); ++ ERROR("attach fifo path \"%s\" must be an FIFO", real_path); + return false; + } + + if ((st.st_mode & 0777) != ATTACH_FIFOPATH_MODE) { +- write_attach_message(ERR_MSG, "attach fifo path \"%s\" permission invalid", real_path); ++ ERROR("attach fifo path \"%s\" permission invalid", real_path); + return false; + } + + if (st.st_uid != 0) { +- write_attach_message(ERR_MSG, "attach fifo path \"%s\" uid invalid", real_path); ++ ERROR("attach fifo path \"%s\" uid invalid", real_path); + return false; + } + +@@ -553,20 +555,20 @@ static int attach_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + + r_count = isula_file_read_nointr(fd, tmp_buf, sizeof(tmp_buf) - 1); + if (r_count <= 0) { +- write_attach_message(ERR_MSG, "Failed to read msg from attach conn fd"); ++ ERROR("Failed to read msg from attach conn fd"); + goto out; + } + + // limit the number of attach connections to MAX_ATTACH_NUM + if (isula_linked_list_len(p->attach_fifos) >= MAX_ATTACH_NUM) { +- write_attach_message(ERR_MSG, "The number of attach connections exceeds the limit:%d, and this connection is rejected.", ++ ERROR("The number of attach connections exceeds the limit:%d, and this connection is rejected.", + MAX_ATTACH_NUM); + goto out; + } + + tmp_str_array = isula_string_split_to_multi(tmp_buf, ' '); + if (tmp_str_array->len != 3) { +- write_attach_message(ERR_MSG, "Invalid attach msg from isulad"); ++ ERROR("Invalid attach msg from isulad"); + goto out; + } + +@@ -575,7 +577,7 @@ static int attach_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + } + + if (!valid) { +- write_attach_message(ERR_MSG, "Invalid attach fifo path from isulad"); ++ ERROR("Invalid attach fifo path from isulad"); + goto out; + } + +@@ -584,14 +586,14 @@ static int attach_cb(int fd, uint32_t events, void *cbdata, isula_epoll_descr_t + err = tmp_str_array->items[2]; + + if (add_attach_terminal_fifos(in, out, err, &fifofd_in, p) < 0) { +- write_attach_message(ERR_MSG, "Failed to add attach terminal fifos"); ++ ERROR("Failed to add attach terminal fifos"); + goto out; + } + + // attach stdin --> container stdin + ret = isula_epoll_add_handler(descr, fifofd_in, attach_stdin_cb, p); + if (ret != SHIM_OK) { +- write_attach_message(ERR_MSG, "add fifofd_in fd %d to epoll loop failed:%d", fifofd_in, SHIM_SYS_ERR(errno)); ++ ERROR("add fifofd_in fd %d to epoll loop failed:%d", fifofd_in, SHIM_SYS_ERR(errno)); + struct isula_linked_list *item = get_attach_fifo_item(fd, p->attach_fifos); + if (item != NULL && item->elem != NULL) { + remove_attach_terminal_fifos(descr, item); +@@ -616,13 +618,13 @@ static int do_attach_socket_accept(int fd, uint32_t events, void *cbdata, isula_ + + conn_fd = accept(p->attach_socket_fd, NULL, NULL); + if (conn_fd < 0) { +- write_attach_message(ERR_MSG, "accept from fd %d failed:%d", p->attach_socket_fd, SHIM_SYS_ERR(errno)); ++ ERROR("accept from fd %d failed:%d", p->attach_socket_fd, SHIM_SYS_ERR(errno)); + return EPOLL_LOOP_HANDLE_CONTINUE; + } + + ret = isula_epoll_add_handler(descr, conn_fd, attach_cb, p); + if (ret != SHIM_OK) { +- write_attach_message(ERR_MSG, "add recv_fd %d to epoll loop failed:%d", conn_fd, SHIM_SYS_ERR(errno)); ++ ERROR("add recv_fd %d to epoll loop failed:%d", conn_fd, SHIM_SYS_ERR(errno)); + close(conn_fd); + return EPOLL_LOOP_HANDLE_CONTINUE; + } +@@ -637,13 +639,13 @@ static int task_console_accept(int fd, uint32_t events, void *cbdata, isula_epol + + conn_fd = accept(p->listen_fd, NULL, NULL); + if (conn_fd < 0) { +- write_message(ERR_MSG, "accept from fd %d failed:%d", p->listen_fd, SHIM_SYS_ERR(errno)); ++ ERROR("accept from fd %d failed:%d", p->listen_fd, SHIM_SYS_ERR(errno)); + goto out; + } + + p->recv_fd = receive_fd(conn_fd); + if (check_fd(p->recv_fd) != true) { +- write_message(ERR_MSG, "check console fd failed"); ++ ERROR("check console fd failed"); + goto out; + } + +@@ -652,19 +654,19 @@ static int task_console_accept(int fd, uint32_t events, void *cbdata, isula_epol + // p->isulad_io->in ----> p->recv_fd + ret = isula_epoll_add_handler(descr, p->isulad_io->in, stdin_cb, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add in fd %d to epoll loop failed:%d", p->isulad_io->in, SHIM_SYS_ERR(errno)); ++ ERROR("add in fd %d to epoll loop failed:%d", p->isulad_io->in, SHIM_SYS_ERR(errno)); + goto out; + } + // p->recv_fd ----> p->isulad_io->out + ret = isula_epoll_add_handler(descr, p->recv_fd, stdout_cb, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add recv_fd fd %d to epoll loop failed:%d", p->recv_fd, SHIM_SYS_ERR(errno)); ++ ERROR("add recv_fd fd %d to epoll loop failed:%d", p->recv_fd, SHIM_SYS_ERR(errno)); + goto out; + } + // p->isulad_io->resize ----> p->recv_fd + ret = isula_epoll_add_handler(descr, p->isulad_io->resize, resize_cb, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add resize fd %d to epoll loop failed:%d", p->isulad_io->resize, SHIM_SYS_ERR(errno)); ++ ERROR("add resize fd %d to epoll loop failed:%d", p->isulad_io->resize, SHIM_SYS_ERR(errno)); + goto out; + } + +@@ -724,7 +726,7 @@ static stdio_t *initialize_io(process_t *p) + */ + if ((pipe2(stdio_fd[0], O_CLOEXEC) != 0) || (pipe2(stdio_fd[1], O_CLOEXEC) != 0) || + (pipe2(stdio_fd[2], O_CLOEXEC) != 0)) { +- write_message(ERR_MSG, "open pipe failed when init io:%d", SHIM_SYS_ERR(errno)); ++ ERROR("open pipe failed when init io:%d", SHIM_SYS_ERR(errno)); + goto failure; + } + +@@ -789,7 +791,7 @@ static int console_init(process_t *p, isula_epoll_descr_t *descr) + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { +- write_message(ERR_MSG, "create socket failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("create socket failed:%d", SHIM_SYS_ERR(errno)); + goto failure; + } + +@@ -799,13 +801,13 @@ static int console_init(process_t *p, isula_epoll_descr_t *descr) + + ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) { +- write_message(ERR_MSG, "bind console fd failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("bind console fd failed:%d", SHIM_SYS_ERR(errno)); + goto failure; + } + + ret = listen(fd, 2); + if (ret < 0) { +- write_message(ERR_MSG, "listen console fd failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("listen console fd failed:%d", SHIM_SYS_ERR(errno)); + goto failure; + } + +@@ -813,7 +815,7 @@ static int console_init(process_t *p, isula_epoll_descr_t *descr) + + ret = isula_epoll_add_handler(descr, p->listen_fd, task_console_accept, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add listen_fd fd %d to epoll loop failed:%d", p->listen_fd, SHIM_SYS_ERR(errno)); ++ ERROR("add listen_fd fd %d to epoll loop failed:%d", p->listen_fd, SHIM_SYS_ERR(errno)); + goto failure; + } + +@@ -831,7 +833,7 @@ static int open_terminal_io(process_t *p, isula_epoll_descr_t *descr) + + ret = new_temp_console_path(p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "get temp console sock path failed"); ++ ERROR("get temp console sock path failed"); + return SHIM_ERR; + } + +@@ -853,19 +855,19 @@ static int open_generic_io(process_t *p, isula_epoll_descr_t *descr) + // p->isulad_io->in ----> p->shim_io->in + ret = isula_epoll_add_handler(descr, p->isulad_io->in, stdin_cb, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add in fd %d to epoll loop failed:%d", p->isulad_io->in, SHIM_SYS_ERR(errno)); ++ ERROR("add in fd %d to epoll loop failed:%d", p->isulad_io->in, SHIM_SYS_ERR(errno)); + return SHIM_ERR; + } + // p->shim_io->out ----> p->isulad_io->out + ret = isula_epoll_add_handler(descr, p->shim_io->out, stdout_cb, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add out fd %d to epoll loop failed:%d", p->shim_io->out, SHIM_SYS_ERR(errno)); ++ ERROR("add out fd %d to epoll loop failed:%d", p->shim_io->out, SHIM_SYS_ERR(errno)); + return SHIM_ERR; + } + // p->shim_io->err ----> p->isulad_io->err + ret = isula_epoll_add_handler(descr, p->shim_io->err, stderr_cb, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add err fd %d to epoll loop failed:%d", p->shim_io->err, SHIM_SYS_ERR(errno)); ++ ERROR("add err fd %d to epoll loop failed:%d", p->shim_io->err, SHIM_SYS_ERR(errno)); + return SHIM_ERR; + } + +@@ -896,22 +898,25 @@ static void *io_epoll_loop(void *data) + + ret = isula_epoll_open(&descr); + if (ret != 0) { +- write_message(ERR_MSG, "epoll loop open failed:%d", SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); ++ ERROR("epoll loop open failed:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("epoll loop open failed:%d", SHIM_SYS_ERR(errno)); ++ error_exit(EXIT_FAILURE); + } + + // sync fd: epoll loop will exit when recive sync fd event. + ret = isula_epoll_add_handler(&descr, p->sync_fd, sync_exit_cb, p); + if (ret != 0) { +- write_message(ERR_MSG, "add sync_fd %d to epoll loop failed:%d", p->sync_fd, SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); ++ ERROR("add sync_fd %d to epoll loop failed:%d", p->sync_fd, SHIM_SYS_ERR(errno)); ++ shim_set_error_message("add sync_fd %d to epoll loop failed:%d", p->sync_fd, SHIM_SYS_ERR(errno)); ++ error_exit(EXIT_FAILURE); + } + + if (p->state->attach_socket != NULL) { + ret = isula_epoll_add_handler(&descr, p->attach_socket_fd, do_attach_socket_accept, p); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "add attach_socket_fd %d to epoll loop failed:%d", p->attach_socket_fd, SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); ++ ERROR("add attach_socket_fd %d to epoll loop failed:%d", p->attach_socket_fd, SHIM_SYS_ERR(errno)); ++ shim_set_error_message("add attach_socket_fd %d to epoll loop failed:%d", p->attach_socket_fd, SHIM_SYS_ERR(errno)); ++ error_exit(EXIT_FAILURE); + } + } + +@@ -921,8 +926,9 @@ static void *io_epoll_loop(void *data) + ret = open_generic_io(p, &descr); + } + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "open io failed:%d", SHIM_SYS_ERR(errno)); +- exit(EXIT_FAILURE); ++ ERROR("open io failed:%d", SHIM_SYS_ERR(errno)); ++ shim_append_error_message("open io failed:%d", SHIM_SYS_ERR(errno)); ++ error_exit(EXIT_FAILURE); + } + + (void)sem_post(&p->sem_mainloop); +@@ -933,8 +939,9 @@ static void *io_epoll_loop(void *data) + // 3. stdin fd read failed + ret = isula_epoll_loop(&descr, -1); + if (ret != 0) { +- write_message(ERR_MSG, "epoll loop failed"); +- exit(EXIT_FAILURE); ++ ERROR("epoll loop failed"); ++ shim_set_error_message("epoll loop failed"); ++ error_exit(EXIT_FAILURE); + } + + // use a timeout epoll loop to ensure complete data reception +@@ -943,7 +950,7 @@ static void *io_epoll_loop(void *data) + // 2. no event received within 100 milliseconds + ret = isula_epoll_loop(&descr, 100); + if (ret != 0) { +- write_message(ERR_MSG, "Repeat the epoll loop to ensure that all data is transferred"); ++ ERROR("Repeat the epoll loop to ensure that all data is transferred"); + } + + return NULL; +@@ -966,12 +973,12 @@ static int terminal_init(log_terminal **terminal, shim_client_process_state *p_s + + log_term = isula_common_calloc_s(sizeof(log_terminal)); + if (log_term == NULL) { +- write_message(ERR_MSG, "Failed to calloc log_terminal"); ++ ERROR("Failed to calloc log_terminal"); + goto clean_out; + } + + if (pthread_rwlock_init(&log_term->log_terminal_rwlock, NULL) != 0) { +- write_message(ERR_MSG, "Failed to init isulad conf rwlock"); ++ ERROR("Failed to init isulad conf rwlock"); + goto clean_out; + } + +@@ -1047,25 +1054,25 @@ static int init_isulad_stdio(process_t *p) + + ret = open_isulad_fd(STDID_IN, p->state->isulad_stdin, &p->isulad_io->in); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "Failed to open in isulad fd: %s", p->state->isulad_stdin); ++ ERROR("Failed to open in isulad fd: %s", p->state->isulad_stdin); + goto failure; + } + + ret = open_isulad_fd(STDID_OUT, p->state->isulad_stdout, &p->isulad_io->out); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "Failed to open out isulad fd: %s", p->state->isulad_stdout); ++ ERROR("Failed to open out isulad fd: %s", p->state->isulad_stdout); + goto failure; + } + + ret = open_isulad_fd(STDID_ERR, p->state->isulad_stderr, &p->isulad_io->err); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "Failed to open err isulad fd: %s", p->state->isulad_stderr); ++ ERROR("Failed to open err isulad fd: %s", p->state->isulad_stderr); + goto failure; + } + + ret = open_isulad_fd(EXEC_RESIZE, p->state->resize_fifo, &p->isulad_io->resize); + if (ret != SHIM_OK) { +- write_message(ERR_MSG, "Failed to open resize isulad fd: %s", p->state->resize_fifo); ++ ERROR("Failed to open resize isulad fd: %s", p->state->resize_fifo); + goto failure; + } + return SHIM_OK; +@@ -1105,13 +1112,13 @@ static int init_root_path(process_t *p) + // state_path: /run/isulad/runc/{container_id} + char *tmp_dir = strrchr(state_path, '/'); + if (tmp_dir == NULL) { +- write_message(ERR_MSG, "Invalid exec workdir"); ++ ERROR("Invalid exec workdir"); + return SHIM_ERR; + } + *tmp_dir = '\0'; + tmp_dir = strrchr(state_path, '/'); + if (tmp_dir == NULL) { +- write_message(ERR_MSG, "Invalid exec workdir"); ++ ERROR("Invalid exec workdir"); + return SHIM_ERR; + } + *tmp_dir = '\0'; +@@ -1119,12 +1126,12 @@ static int init_root_path(process_t *p) + + isula_buffer *buffer = isula_buffer_alloc(PATH_MAX); + if (buffer == NULL) { +- write_message(ERR_MSG, "Failed to malloc buffer\n"); ++ ERROR("Failed to malloc buffer\n"); + return SHIM_ERR; + } + + if (buffer->nappend(buffer, PATH_MAX, "%s/%s", state_path, p->runtime) < 0) { +- write_message(ERR_MSG, "Failed to append state_path\n"); ++ ERROR("Failed to append state_path\n"); + isula_buffer_free(buffer); + return SHIM_ERR; + } +@@ -1132,7 +1139,7 @@ static int init_root_path(process_t *p) + p->root_path = buffer->to_str(buffer); + isula_buffer_free(buffer); + if (strlen(p->root_path) > PATH_MAX) { +- write_message(ERR_MSG, "Root_path is too long\n"); ++ ERROR("Root_path is too long\n"); + return SHIM_ERR; + } + return SHIM_OK; +@@ -1180,7 +1187,7 @@ process_t *new_process(char *id, char *bundle, char *runtime) + + p->sync_fd = eventfd(0, EFD_CLOEXEC); + if (p->sync_fd < 0) { +- write_message(ERR_MSG, "Failed to create eventfd: %s", strerror(errno)); ++ ERROR("Failed to create eventfd: %s", strerror(errno)); + goto failure; + } + +@@ -1197,7 +1204,7 @@ process_t *new_process(char *id, char *bundle, char *runtime) + // during the execution of isulad-shim, the current working directory will not change. + p->workdir = getcwd(NULL, 0); + if (p->workdir == NULL) { +- write_message(ERR_MSG, "get cwd failed when do create process"); ++ ERROR("get cwd failed when do create process"); + goto failure; + } + +@@ -1432,13 +1439,15 @@ int create_process(process_t *p) + int nread = -1; + + if (pipe2(exec_fd, O_CLOEXEC) != 0) { +- write_message(ERR_MSG, "create pipe failed when create process:%d", SHIM_SYS_ERR(errno)); ++ ERROR("create pipe failed when create process:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("create pipe failed when create process:%d", SHIM_SYS_ERR(errno)); + return SHIM_ERR; + } + + pid_t pid = fork(); + if (pid == (pid_t) -1) { +- write_message(ERR_MSG, "fork failed when create process:%d", SHIM_SYS_ERR(errno)); ++ ERROR("fork failed when create process:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("fork failed when create process:%d", SHIM_SYS_ERR(errno)); + return SHIM_ERR; + } + +@@ -1461,14 +1470,16 @@ int create_process(process_t *p) + /* block to wait runtime pid exit */ + ret = waitpid(pid, NULL, 0); + if (ret != pid) { +- write_message(ERR_MSG, "wait runtime failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("wait runtime failed:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("wait runtime failed:%d", SHIM_SYS_ERR(errno)); + ret = SHIM_ERR; + goto out; + } + + // if an error occurs in exec_runtime_process, jump directly to the out branch after waitpid. + if (nread > 0) { +- write_message(ERR_MSG, "%s", exec_buff); ++ ERROR("%s", exec_buff); ++ shim_set_error_message("%s", exec_buff); + ret = SHIM_ERR; + goto out; + } +@@ -1476,7 +1487,8 @@ int create_process(process_t *p) + /* save runtime pid */ + data = read_text_file("pid"); + if (data == NULL) { +- write_message(ERR_MSG, "read pid of runtime failed"); ++ ERROR("read pid of runtime failed"); ++ shim_set_error_message("read pid of runtime failed"); + goto out; + } + int ctr_pid = atoi(data); +@@ -1537,12 +1549,12 @@ static int waitpid_with_timeout(int ctr_pid, int *status, const uint64_t timeou + if (*status == CONTAINER_ACTION_REBOOT) { + nret = setenv("CONTAINER_ACTION", "reboot", 1); + if (nret != SHIM_OK) { +- write_message(WARN_MSG, "set reboot action failed:%d", SHIM_SYS_ERR(errno)); ++ WARN("set reboot action failed:%d", SHIM_SYS_ERR(errno)); + } + } else if (*status == CONTAINER_ACTION_SHUTDOWN) { + nret = setenv("CONTAINER_ACTION", "shutdown", 1); + if (nret != SHIM_OK) { +- write_message(WARN_MSG, "set shutdown action failed:%d", SHIM_SYS_ERR(errno)); ++ WARN("set shutdown action failed:%d", SHIM_SYS_ERR(errno)); + } + } + return SHIM_OK; +@@ -1565,12 +1577,12 @@ static int wait_container_process_with_timeout(process_t *p, const uint64_t time + if (*status == CONTAINER_ACTION_REBOOT) { + ret = setenv("CONTAINER_ACTION", "reboot", 1); + if (ret != SHIM_OK) { +- write_message(WARN_MSG, "set reboot action failed:%d", SHIM_SYS_ERR(errno)); ++ WARN("set reboot action failed:%d", SHIM_SYS_ERR(errno)); + } + } else if (*status == CONTAINER_ACTION_SHUTDOWN) { + ret = setenv("CONTAINER_ACTION", "shutdown", 1); + if (ret != SHIM_OK) { +- write_message(WARN_MSG, "set shutdown action failed:%d", SHIM_SYS_ERR(errno)); ++ WARN("set shutdown action failed:%d", SHIM_SYS_ERR(errno)); + } + } + return SHIM_OK; +@@ -1600,7 +1612,7 @@ int process_signal_handle_routine(process_t *p, const pthread_t tid_epoll, const + // kill container process to ensure process_kill_all effective + nret = kill(p->ctr_pid, SIGKILL); + if (nret < 0 && errno != ESRCH) { +- write_message(ERR_MSG, "Can not kill process (pid=%d) with SIGKILL", p->ctr_pid); ++ ERROR("Can not kill process (pid=%d) with SIGKILL, %d", p->ctr_pid, SHIM_SYS_ERR(errno)); + return SHIM_ERR; + } + } +@@ -1610,7 +1622,7 @@ int process_signal_handle_routine(process_t *p, const pthread_t tid_epoll, const + // wait atmost 120 seconds + DO_RETRY_CALL(120, 1000000, nret, try_wait_all_child); + if (nret != 0) { +- write_message(ERR_MSG, "Failed to wait all child after 120 seconds"); ++ ERROR("Failed to wait all child after 120 seconds"); + } + + process_delete(p); +@@ -1620,13 +1632,13 @@ int process_signal_handle_routine(process_t *p, const pthread_t tid_epoll, const + + if (p->sync_fd > 0) { + if (eventfd_write(p->sync_fd, 1)) { +- write_message(ERR_MSG, "Failed to write sync fd"); ++ ERROR("Failed to write sync fd"); + } + } + + nret = pthread_join(tid_epoll, NULL); + if (nret != 0) { +- write_message(ERR_MSG, "Failed to join epoll loop thread"); ++ ERROR("Failed to join epoll loop thread"); + } + + close(p->sync_fd); +@@ -1638,7 +1650,8 @@ int process_signal_handle_routine(process_t *p, const pthread_t tid_epoll, const + } + + if (ret == SHIM_ERR_TIMEOUT) { +- write_message(INFO_MSG, "Wait %d timeout", p->ctr_pid); ++ ERROR("Wait %d timeout", p->ctr_pid); ++ shim_set_error_message("Wait %d timeout", p->ctr_pid); + return SHIM_ERR_TIMEOUT; + } + +@@ -1653,13 +1666,15 @@ int prepare_attach_socket(process_t *p) + int ret = -1; + + if (strlen(p->state->attach_socket) >= sizeof(addr.sun_path)) { +- write_message(ERR_MSG, "Invalid attach socket path: %s", p->state->attach_socket); ++ ERROR("Invalid attach socket path: %s", p->state->attach_socket); ++ shim_set_error_message("Invalid attach socket path: %s", p->state->attach_socket); + return SHIM_ERR; + } + + p->attach_socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (p->attach_socket_fd < 0) { +- write_message(ERR_MSG, "Failed to create socket:%d", SHIM_SYS_ERR(errno)); ++ ERROR("Failed to create socket:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("Invalid attach socket path: %s", p->state->attach_socket); + return SHIM_ERR; + } + +@@ -1669,13 +1684,15 @@ int prepare_attach_socket(process_t *p) + + ret = bind(p->attach_socket_fd, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) { +- write_message(ERR_MSG, "bind console fd failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("bind console fd failed:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("Invalid attach socket path: %s", p->state->attach_socket); + return SHIM_ERR; + } + + ret = chmod(p->state->attach_socket, SOCKET_DIRECTORY_MODE); + if (ret != 0) { +- write_message(ERR_MSG, "Failed to chmod for socket: %s", p->state->attach_socket); ++ ERROR("Failed to chmod for socket: %s", p->state->attach_socket); ++ shim_set_error_message("Invalid attach socket path: %s", p->state->attach_socket); + return SHIM_ERR; + } + +@@ -1687,7 +1704,8 @@ int prepare_attach_socket(process_t *p) + // The maximum number of attach we allow here is MAX_ATTACH_NUM, so just use it directly + ret = listen(p->attach_socket_fd, MAX_ATTACH_NUM); + if (ret < 0) { +- write_message(ERR_MSG, "listen console fd failed:%d", SHIM_SYS_ERR(errno)); ++ ERROR("listen console fd failed:%d", SHIM_SYS_ERR(errno)); ++ shim_set_error_message("Invalid attach socket path: %s", p->state->attach_socket); + return SHIM_ERR; + } + return SHIM_OK; +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index fbb779f7..2b12d173 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -69,6 +69,16 @@ + + // handle string from stderr output. + typedef int(*handle_output_callback_t)(const char *output); ++typedef struct { ++ bool fg; ++ const char *id; ++ char *workdir; ++ const char *bundle; ++ const char *runtime_cmd; ++ int *exit_code; ++ char *timeout; ++ int *shim_exit_code; ++} shim_create_args; + + static void copy_process(shim_client_process_state *p, defs_process *dp) + { +@@ -154,9 +164,10 @@ static void file_read_int(const char *fname, int *val) + free(sint); + } + +-static void get_err_message(char *buf, int buf_size, const char *workdir, const char *file) ++static int get_err_message(char *buf, int buf_size, const char *workdir, const char *file) + { + int nret; ++ int ret = 0; + char fname[PATH_MAX] = { 0 }; + FILE *fp = NULL; + char *pline = NULL; +@@ -166,12 +177,12 @@ static void get_err_message(char *buf, int buf_size, const char *workdir, const + nret = snprintf(fname, PATH_MAX, "%s/%s", workdir, file); + if (nret < 0 || (size_t)nret >= PATH_MAX) { + ERROR("failed make full path %s/%s", workdir, file); +- return; ++ return ret; + } + + fp = util_fopen(fname, "r"); + if (fp == NULL) { +- return; ++ return ret; + } + + while (getline(&pline, &length, fp) != -1) { +@@ -199,48 +210,58 @@ static void get_err_message(char *buf, int buf_size, const char *workdir, const + fclose(fp); + + if (lines[2] != NULL) { +- (void)snprintf(buf, buf_size, "%s%s%s", lines[0], lines[1], lines[2]); ++ nret = snprintf(buf, buf_size, "%s%s%s", lines[0], lines[1], lines[2]); ++ ret += nret; + } else if (lines[1] != NULL) { +- (void)snprintf(buf, buf_size, "%s%s", lines[0], lines[1]); ++ nret = snprintf(buf, buf_size, "%s%s", lines[0], lines[1]); ++ ret += nret; + } else if (lines[0] != NULL) { +- (void)snprintf(buf, buf_size, "%s", lines[0]); ++ nret = snprintf(buf, buf_size, "%s", lines[0]); ++ ret += nret; + } + + UTIL_FREE_AND_SET_NULL(pline); + UTIL_FREE_AND_SET_NULL(lines[0]); + UTIL_FREE_AND_SET_NULL(lines[1]); + UTIL_FREE_AND_SET_NULL(lines[2]); ++ return ret; + } + +-static void show_shim_runtime_errlog(const char *workdir) ++static void show_runtime_errlog(const char *workdir) + { + char buf[BUFSIZ] = { 0 }; + char buf1[SHIM_LOG_SIZE] = { 0 }; +- char buf2[SHIM_LOG_SIZE] = { 0 }; ++ int nret; + + 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); +- ERROR("runtime-log: %s", buf2); +- (void)snprintf(buf, sizeof(buf), "shim-log error: %s\nruntime-log error: %s\n", buf1, buf2); ++ nret = get_err_message(buf1, sizeof(buf1), workdir, "log.json"); ++ if (nret == 0) { ++ ERROR("empty runtime-log : %s", workdir); ++ return; ++ } ++ ERROR("runtime-log: %s", buf1); ++ (void)snprintf(buf, sizeof(buf), "runtime-log error: %s\n", buf1); + isulad_set_error_message(buf); + } + +-static void show_shim_attach_errlog(const char *workdir) ++static void show_shim_errlog(const int fd) + { +- char buf[SHIM_LOG_SIZE] = { 0 }; ++ int num; ++ char buf[BUFSIZ] = { 0 }; + + if (g_isulad_errmsg != NULL) { + return; + } + +- get_err_message(buf, sizeof(buf), workdir, "attach-log.json"); +- ERROR("shim-log: %s", buf); +- isulad_set_error_message("shim-log error:\n%s\n", buf); ++ num = util_read_nointr(fd, buf, sizeof(buf) - 1); ++ if (num < 0) { ++ SYSERROR("Failed to read err msg from shim stderr"); ++ return; ++ } ++ isulad_set_error_message(buf); + } + + bool rt_isula_detect(const char *runtime) +@@ -818,12 +839,48 @@ static int status_to_exit_code(int status) + return exit_code; + } + ++static int get_engine_routine_log_info(char **engine_log_path, char **log_level) ++{ ++ int ret = 0; ++ struct service_arguments *args = NULL; ++ ++ if (isulad_server_conf_rdlock() != 0) { ++ return -1; ++ } ++ ++ args = conf_get_server_conf(); ++ if (args == NULL) { ++ ERROR("Failed to get isulad server config"); ++ ret = -1; ++ goto unlock_out; ++ } ++ ++ *engine_log_path = conf_get_engine_log_file(); ++ if (*engine_log_path == NULL) { ++ ERROR("Log fifo path is NULL"); ++ ret = -1; ++ goto unlock_out; ++ } ++ ++ *log_level = util_strdup_s(args->json_confs->log_level); ++ if (*engine_log_path == NULL) { ++ ERROR("Log level is NULL"); ++ ret = -1; ++ goto unlock_out; ++ } ++ ++unlock_out: ++ if (isulad_server_conf_unlock()) { ++ ret = -1; ++ } ++ return ret; ++} ++ + /* + exit_code records the exit code of the container, obtained by reading the stdout of isulad-shim; + shim_exit_code records the exit code of isulad-shim, obtained through waitpid; + */ +-static int shim_create(bool fg, const char *id, const char *workdir, const char *bundle, const char *runtime_cmd, +- int *exit_code, const char *timeout, int *shim_exit_code) ++static int shim_create(shim_create_args *args) + { + pid_t pid = 0; + int shim_stderr_pipe[2] = { -1, -1 }; +@@ -833,22 +890,29 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char + char exec_buff[BUFSIZ + 1] = { 0 }; + char fpid[PATH_MAX] = { 0 }; + const char *params[PARAM_NUM] = { 0 }; ++ __isula_auto_free char *engine_log_path = NULL; ++ __isula_auto_free char *log_level = NULL; + int i = 0; + int status = 0; + int nret = 0; + + params[i++] = SHIM_BINARY; +- params[i++] = id; +- params[i++] = bundle; +- params[i++] = runtime_cmd; ++ params[i++] = args->id; ++ params[i++] = args->bundle; ++ params[i++] = args->runtime_cmd; + params[i++] = "info"; + // execSync timeout +- if (timeout != NULL) { +- params[i++] = timeout; ++ if (args->timeout != NULL) { ++ params[i++] = args->timeout; + } + runtime_exec_param_dump(params); + +- nret = snprintf(fpid, sizeof(fpid), "%s/shim-pid", workdir); ++ if (get_engine_routine_log_info(&engine_log_path, &log_level) != 0) { ++ ERROR("failed to get engine log path"); ++ return -1; ++ } ++ ++ nret = snprintf(fpid, sizeof(fpid), "%s/shim-pid", args->workdir); + if (nret < 0 || (size_t)nret >= sizeof(fpid)) { + ERROR("failed make shim-pid full path"); + return -1; +@@ -875,12 +939,12 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char + } + + if (pid == (pid_t)0) { +- if (chdir(workdir) < 0) { +- (void)dprintf(shim_stderr_pipe[1], "%s: failed chdir to %s", id, workdir); ++ if (chdir(args->workdir) < 0) { ++ (void)dprintf(shim_stderr_pipe[1], "%s: failed chdir to %s", args->id, args->workdir); + exit(EXIT_FAILURE); + } + +- if (fg) { ++ if (args->fg) { + // child process, dup2 shim_stdout_pipe[1] to STDOUT + if (dup2(shim_stdout_pipe[1], STDOUT_FILENO) < 0) { + (void)dprintf(shim_stderr_pipe[1], "Dup stdout fd error: %s", strerror(errno)); +@@ -896,18 +960,18 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char + + // clear NOTIFY_SOCKET from the env to adapt runc create + if (unsetenv("NOTIFY_SOCKET") != 0) { +- (void)dprintf(shim_stderr_pipe[1], "%s: unset env NOTIFY_SOCKET failed %s", id, strerror(errno)); ++ (void)dprintf(shim_stderr_pipe[1], "%s: unset env NOTIFY_SOCKET failed %s", args->id, strerror(errno)); + exit(EXIT_FAILURE); + } + + pid = fork(); + if (pid < 0) { +- (void)dprintf(shim_stderr_pipe[1], "%s: fork shim-process failed %s", id, strerror(errno)); ++ (void)dprintf(shim_stderr_pipe[1], "%s: fork shim-process failed %s", args->id, strerror(errno)); + _exit(EXIT_FAILURE); + } + if (pid != 0) { + if (file_write_int(fpid, pid) != 0) { +- (void)dprintf(shim_stderr_pipe[1], "%s: write %s with %d failed", id, fpid, pid); ++ (void)dprintf(shim_stderr_pipe[1], "%s: write %s with %d failed", args->id, fpid, pid); + } + _exit(EXIT_SUCCESS); + } +@@ -918,7 +982,7 @@ realexec: + close(shim_stdout_pipe[0]); + + if (setsid() < 0) { +- (void)dprintf(shim_stderr_pipe[1], "%s: failed setsid for process %d", id, getpid()); ++ (void)dprintf(shim_stderr_pipe[1], "%s: failed setsid for process %d", args->id, getpid()); + exit(EXIT_FAILURE); + } + +@@ -927,6 +991,16 @@ realexec: + exit(EXIT_FAILURE); + } + ++ if (setenv("ISULAD_SHIIM_LOG_PATH", engine_log_path, 1) != 0) { ++ (void)dprintf(shim_stderr_pipe[1], "%s: failed to set ISULAD_SHIIM_LOG_PATH env for process %d", args->id, getpid()); ++ exit(EXIT_FAILURE); ++ } ++ ++ if (setenv("ISULAD_SHIIM_LOG_LEVEL", log_level, 1) != 0) { ++ (void)dprintf(shim_stderr_pipe[1], "%s: failed to set ISULAD_SHIIM_LOG_LEVEL env for process %d", args->id, getpid()); ++ exit(EXIT_FAILURE); ++ } ++ + execvp(SHIM_BINARY, (char * const *)params); + (void)dprintf(shim_stderr_pipe[1], "run process: %s failed: %s", SHIM_BINARY, strerror(errno)); + exit(EXIT_FAILURE); +@@ -951,38 +1025,43 @@ realexec: + goto out; + } + +- *shim_exit_code = status_to_exit_code(status); +- if (*shim_exit_code != 0) { +- ERROR("Isulad-shim exit error"); ++ *(args->shim_exit_code) = status_to_exit_code(status); ++ if (*(args->shim_exit_code) != 0) { ++ ERROR("Isulad-shim exit error : %d", *(args->shim_exit_code)); ++ isulad_set_error_message("Isulad-shim exit error : %d, please get more information from log", *(args->shim_exit_code)); + ret = -1; + goto out; + } + + // exit_code is NULL when command is create. +- if (exit_code == NULL) { ++ if (args->exit_code == NULL) { + goto out; + } + + // when exec in background, exit code is shim exit code +- if (!fg) { +- *exit_code = *shim_exit_code; ++ if (!args->fg) { ++ *(args->exit_code) = *(args->shim_exit_code); + goto out; + } +- ret = util_read_nointr(shim_stdout_pipe[0], exit_code, sizeof(int)); ++ ret = util_read_nointr(shim_stdout_pipe[0], args->exit_code, sizeof(int)); + if (ret <= 0) { +- *exit_code = 137; ++ *(args->exit_code) = 137; + } + ret = 0; + + out: +- close(shim_stderr_pipe[0]); + close(shim_stdout_pipe[0]); + if (ret != 0) { +- show_shim_runtime_errlog(workdir); +- if (timeout != NULL) { ++ if (*(args->shim_exit_code) == 0) { ++ show_runtime_errlog(args->workdir); ++ } else { ++ show_shim_errlog(shim_stderr_pipe[0]); ++ } ++ if (args->timeout != NULL) { + kill(pid, SIGKILL); /* can kill other process? */ + } + } ++ close(shim_stderr_pipe[0]); + + return ret; + } +@@ -1061,6 +1140,7 @@ int rt_isula_create(const char *id, const char *runtime, const rt_create_params_ + char workdir[PATH_MAX] = { 0 }; + char attach_socket[PATH_MAX] = { 0 }; + shim_client_process_state p = { 0 }; ++ shim_create_args args = { 0 }; + int shim_exit_code = 0; + int nret = 0; + +@@ -1108,7 +1188,15 @@ 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, NULL, &shim_exit_code); ++ args.fg = false; ++ args.id = id; ++ args.workdir = workdir; ++ args.bundle = params->bundle; ++ args.runtime_cmd = cmd; ++ args.exit_code = NULL; ++ args.timeout = NULL; ++ args.shim_exit_code = &shim_exit_code; ++ ret = shim_create(&args); + if (ret != 0) { + runtime_call_delete_force(workdir, runtime, id); + ERROR("%s: failed create shim process", id); +@@ -1185,7 +1273,7 @@ int rt_isula_start(const char *id, const char *runtime, const rt_start_params_t + ret = 0; + out: + if (ret != 0) { +- show_shim_runtime_errlog(workdir); ++ show_runtime_errlog(workdir); + shim_kill_force(workdir); + } + return ret; +@@ -1363,6 +1451,7 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p + int pid = 0; + char bundle[PATH_MAX] = { 0 }; + char workdir[PATH_MAX] = { 0 }; ++ shim_create_args args = { 0 }; + char *timeout = NULL; + int shim_exit_code = 0; + +@@ -1411,7 +1500,15 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p + } + } + +- ret = shim_create(fg_exec(params), id, workdir, bundle, cmd, exit_code, timeout, &shim_exit_code); ++ args.fg = fg_exec(params); ++ args.id = id; ++ args.workdir = workdir; ++ args.bundle = bundle; ++ args.runtime_cmd = cmd; ++ args.exit_code = exit_code; ++ args.timeout = timeout; ++ args.shim_exit_code = &shim_exit_code; ++ ret = shim_create(&args); + if (shim_exit_code == SHIM_EXIT_TIMEOUT) { + ret = -1; + isulad_set_error_message("Exec container error;exec timeout"); +@@ -1432,7 +1529,7 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p + + errlog_out: + if (ret != 0) { +- show_shim_runtime_errlog(workdir); ++ show_runtime_errlog(workdir); + } + + if (timeout != NULL) { +@@ -1559,13 +1656,13 @@ int rt_isula_attach(const char *id, const char *runtime, const rt_attach_params_ + + if (id == NULL || runtime == NULL || params == NULL) { + ERROR("Null argument"); +- return -1; ++ goto err_out; + } + + ret = snprintf(workdir, sizeof(workdir), "%s/%s", params->state, id); + if (ret < 0 || (size_t)ret >= sizeof(workdir)) { + ERROR("Failed join exec full path"); +- return -1; ++ goto err_out; + } + + // the communication format between isulad and isulad-shim attach is: +@@ -1573,19 +1670,19 @@ int rt_isula_attach(const char *id, const char *runtime, const rt_attach_params_ + len = snprintf(buf, sizeof(buf), "%s %s %s", params->stdin, params->stdout, params->stderr); + if (len < 0 || (size_t)len >= sizeof(buf)) { + ERROR("Failed to snprintf string"); +- return -1; ++ goto err_out; + } + + ret = snprintf(attach_socket, sizeof(attach_socket), "%s/%s", workdir, ATTACH_SOCKET); + if (ret < 0 || (size_t)ret >= sizeof(attach_socket)) { + ERROR("Failed to get full attach socket path"); +- return -1; ++ goto err_out; + } + + ret = get_attach_socketfd(attach_socket, &socket_fd); + if (ret < 0) { + ERROR("Failed to get attach socketfd"); +- return -1; ++ goto err_out; + } + + DEBUG("write %s to attach fd", buf); +@@ -1593,16 +1690,19 @@ int rt_isula_attach(const char *id, const char *runtime, const rt_attach_params_ + ret = isula_file_write_nointr(socket_fd, buf, len); + if (ret < 0) { + SYSERROR("Failed to write attach isulad fd"); +- return -1; ++ goto err_out; + } + + status_code = get_container_attach_statuscode(workdir, socket_fd); + if (status_code < 0) { +- show_shim_attach_errlog(workdir); +- return -1; ++ ERROR("Failed to attach container io, get more information from log"); ++ goto err_out; + } + + return 0; ++err_out: ++ isulad_set_error_message("Failed to attach container io, get more information from log"); ++ return -1; + } + + static int to_engine_resources_unified(const host_config *hostconfig, shim_client_cgroup_resources *cr) +-- +2.42.0 + diff --git a/iSulad.spec b/iSulad.spec index 6d9b3f09b27dfeda7c4338bd081f7b41de07cc22..0bf18cc5af720fecc43152d040e89551ec8810b4 100644 --- a/iSulad.spec +++ b/iSulad.spec @@ -1,5 +1,5 @@ %global _version 2.1.4 -%global _release 1 +%global _release 3 %global is_systemd 1 %global enable_criv1 1 %global enable_shimv2 1 @@ -30,7 +30,55 @@ Patch0012: 0012-add-runc-attach-implement-unit-test-and-ci-test.patch Patch0013: 0013-support-gcov-of-CI.patch Patch0014: 0014-compatibility-for-manage-pods-which-created-by-old-i.patch Patch0015: 0015-2250-Remove-PERFMON-BPF-CHECKPOINT_RESTORE.patch -Patch0016: 0016-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch +Patch0016: 0016-improve-event-logs.patch +Patch0017: 0017-2251-open-ENABLE_GRPC_REMOTE_CONNECT-in-CI.patch +Patch0018: 0018-Add-compatibility-between-iSulad-and-k8s.patch +Patch0019: 0019-2254-lcr-container-with-a-damaged-config-file-will-r.patch +Patch0020: 0020-2253-bugfix-for-runc-container-exec.patch +Patch0021: 0021-bugfix-of-update-restart-policy-for-auto-remove-cont.patch +Patch0022: 0022-add-update-restart-policy-test.patch +Patch0023: 0023-2260-bugfix-for-rebuild-config.patch +Patch0024: 0024-2170-isula-image-pull.patch +Patch0025: 0025-2084-image-pull.patch +Patch0026: 0026-CI-add-ncurse-for-ubuntu-and-centos.patch +Patch0027: 0027-improve-code-of-pull-progress.patch +Patch0028: 0028-2230-format-code.patch +Patch0029: 0029-2255-Fix-cpusets-offline-issue.patch +Patch0030: 0030-modify-daemon-json-default-runtime-to-runc.patch +Patch0031: 0031-modify-CI-for-default-runtime-to-runc.patch +Patch0032: 0032-add-ut-for-devicemapper.patch +Patch0033: 0033-2275-bugfix-for-rt_lcr_rebuild_config.patch +Patch0034: 0034-2277-remove-shim-v2-format-error-log.patch +Patch0035: 0035-2276-bugfix-for-integration_check.sh.patch +Patch0036: 0036-modify-create_network.sh-for-default-runtime-changed.patch +Patch0037: 0037-modify-the-container-runtime-when-running-embedded.s.patch +Patch0038: 0038-save-sandbox-to-disk-after-network-ready.patch +Patch0039: 0039-fix-the-problem-of-abnormal-branches-not-waiting-for.patch +Patch0040: 0040-remove-embedded-image-support-in-readme.patch +Patch0041: 0041-Acquire-system-info-in-on-demand.patch +Patch0042: 0042-2268-bugfix-for-the-bliko-zero-value-exception-when-.patch +Patch0043: 0043-move-variable-declaration-out-of-loop.patch +Patch0044: 0044-2289-check-protobuf-and-grpc-version-in-cmake-for-cr.patch +Patch0045: 0045-improve-ut-for-devicemapper.patch +Patch0046: 0046-2292-bugfix-for-run.sh-and-add-build-notify-msg-for-.patch +Patch0047: 0047-2295-keep-the-service-status-unchanged-after-iSulad-.patch +Patch0048: 0048-modify-attach-socket-name.patch +Patch0049: 0049-2298-bugfix-for-hook_ignore_poststart_error-run-in-o.patch +Patch0050: 0050-2304-remove-build-and-test-in-coverage.patch +Patch0051: 0051-2303-use-a-timeout-epoll-loop-to-ensure-complete-dat.patch +Patch0052: 0052-modify-the-default-value-of-ISULAD_TMPDIR-to-var-lib.patch +Patch0053: 0053-prevent-the-parent-dir-from-being-bind-mounted-to-th.patch +Patch0054: 0054-2308-Remove-unused-header-file.patch +Patch0055: 0055-verify-the-mount-dir-first-and-then-create-tmpdir.patch +Patch0056: 0056-2300-Maintaining-a-uniform-code-style.patch +Patch0057: 0057-2312-Add-Huawei-Cloud-CodeArts-compilation-script.patch +Patch0058: 0058-bugfix-del-redundant-code.patch +Patch0059: 0059-improve-code-of-pull.patch +Patch0060: 0060-remove-var-in-coverage-and-fix-build-test-remove.patch +Patch0061: 0061-2320-improve-CI-test.patch +Patch0062: 0062-verify-name-and-digest-consistency.patch +Patch0063: 0063-code-improve-for-oci_rmi.patch +Patch0064: 0064-bugfix-for-resort_image_names.patch %ifarch x86_64 aarch64 Provides: libhttpclient.so()(64bit) @@ -62,8 +110,8 @@ BuildRequires: gtest-devel gmock-devel %define lcrver_upper 2.1.4-0 BuildRequires: libisula-devel > %{lcrver_lower} libisula-devel < %{lcrver_upper} -BuildRequires: cmake gcc-c++ yajl-devel lxc lxc-devel -BuildRequires: grpc grpc-plugins grpc-devel protobuf-devel +BuildRequires: cmake gcc-c++ yajl-devel +BuildRequires: grpc grpc-plugins grpc-devel protobuf-devel ncurses-devel BuildRequires: libcurl libcurl-devel libarchive-devel device-mapper-devel BuildRequires: http-parser-devel BuildRequires: libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel @@ -76,11 +124,12 @@ BuildRequires: lib-shim-v2 lib-shim-v2-devel Requires: libisula > %{lcrver_lower} libisula < %{lcrver_upper} Requires: lcr > %{lcrver_lower} lcr < %{lcrver_upper} -Requires: grpc protobuf lxc +Requires: grpc protobuf Requires: libcurl Requires: http-parser libseccomp Requires: libcap libselinux libwebsockets libarchive device-mapper Requires: systemd +Requires: (docker-runc or runc) BuildRequires: libevhtp libevent %if 0%{?enable_shimv2} Requires: lib-shim-v2 @@ -282,6 +331,18 @@ fi %endif %changelog +* Thu Dec 21 2023 zhongtao - 2.1.4-3 +- Type: bugfix +- ID: NA +- SUG: NA +- DESC: delete compilation dependency:lxc, and add running dependency:runc, compilation dependency:ncurses-devel + +* Thu Dec 21 2023 zhongtao - 2.1.4-2 +- Type: bugfix +- ID: NA +- SUG: NA +- DESC: upgrade from upstream + * Tue Nov 14 2023 zhongtao - 2.1.4-1 - Type: update - ID: NA