From e46cd3b4cff04bbb71aae786911257f77c8a1247 Mon Sep 17 00:00:00 2001 From: caihaomin Date: Thu, 2 Jan 2020 17:16:59 +0800 Subject: [PATCH 01/11] change ReadME Signed-off-by: caihaomin --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++---- logo/isula-logo.png | Bin 0 -> 12202 bytes 2 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 logo/isula-logo.png diff --git a/README.md b/README.md index 0475907..d632af2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,63 @@ -# iSulad +iSulad -This is a umbrella project for gRPC-services based Lightweight Container Runtime Daemon. -iSulad provide a unified architecture to meet the different needs of CT and IT. -Compared with Docker written by Golang, iSulad has the characteristics of light, agile, fast, -not limited by hardware specifications and architecture, and can be applied more widely. +## iSulad + +`iSulad` is a light weight container runtime daemon which is desinged for IOT and Cloud infrastructure.`iSulad` has the characteristics of light, fast and not limited by hardware specifications and architecture, and can be applied more widely. + +## Getting Started + +### Installing +To install iSulad, you can use `rpm` or `yum` package manager command with `openEuler` repository. + +Install iSulad with yum +```sh +yum install -y iSulad +``` + +### Run +We provide `systemd` service to start `iSulad` +```sh +systemd start lcrd # run the server with systemd command +``` + +You can use direct command to start `iSulad` server: +```sh +$ sudo lcrd # run the server with default socket name and default log level and images manage function +``` +### Operations on containers: +`iSulad` provides command line `lcrd` to talk with server. +Here are some sample commands to manager containers. + +List all containers in your own environment: +```sh +# list containers +$ sudo lcrc ps -a +``` + +Create a container with busybox named `test` +```sh +# create a container 'test' with image busybox +$ sudo lcrc create -t -n test busybox +``` + +Start this container `test` +```sh +# start the container 'test' +$ sudo lcrc start test +``` +Kill the container `test` +```sh +# kill the container 'test' +$ sudo lcrc kill test +``` +Remove the container `test` +```sh +# remove the container 'test' +$ sudo lcrc rm test +``` + +### Build from source +Build requirements for developers are listed in [build_guide](./doc/build_guide.md) ## How to Contribute diff --git a/logo/isula-logo.png b/logo/isula-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..011d66d9c1a696a605bc88a02c8e470d6f54d039 GIT binary patch literal 12202 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 Date: Thu, 2 Jan 2020 04:22:50 -0500 Subject: [PATCH 02/11] iSulad: internal change in read user file Signed-off-by: LiFeng --- src/services/execution/spec/specs_extend.c | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/services/execution/spec/specs_extend.c b/src/services/execution/spec/specs_extend.c index fb5a0c9..1a36f81 100644 --- a/src/services/execution/spec/specs_extend.c +++ b/src/services/execution/spec/specs_extend.c @@ -468,34 +468,35 @@ out: static int read_user_file(const char *basefs, const char *user_path, FILE **stream) { - int nret; + int ret = 0; int64_t filesize = 0; - char path[PATH_MAX] = {0}; - char real_path[PATH_MAX] = {0}; + char *real_path = NULL; - nret = snprintf(path, sizeof(path), "%s/%s", basefs, user_path); - if (nret < 0 || (size_t)nret >= sizeof(path)) { - ERROR("Path is too long"); - return -1; - } - if (cleanpath(path, real_path, sizeof(real_path)) == NULL) { - ERROR("Failed to clean path"); - return -1; + if (realpath_in_scope(basefs, user_path, &real_path) < 0) { + ERROR("user target file '%s' real path must be under '%s'", user_path, basefs); + lcrd_set_error_message("user target file '%s' real path must be under '%s'", user_path, basefs); + ret = -1; + goto out; } filesize = util_file_size(real_path); if (filesize > REGULAR_FILE_SIZE) { ERROR("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE); lcrd_set_error_message("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE); - return -1; + ret = -1; + goto out; } *stream = util_fopen(real_path, "r"); if (*stream == NULL) { ERROR("Failed to open %s: %s", real_path, strerror(errno)); - return 0; + ret = 0; + goto out; } - return 0; + +out: + free(real_path); + return ret; } static void parse_user_group(const char *username, char **user, char **group, char **tmp_dup) -- Gitee From 4807f2d38dd384cb2f4442d5cf7bb1024212cf3e Mon Sep 17 00:00:00 2001 From: LiuHao Date: Fri, 3 Jan 2020 11:03:26 +0800 Subject: [PATCH 03/11] iSulad: use cpp code style Signed-off-by: LiuHao --- src/services/cri/cri_sandbox.cc | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/services/cri/cri_sandbox.cc b/src/services/cri/cri_sandbox.cc index 5c0d0eb..4cf4e2b 100644 --- a/src/services/cri/cri_sandbox.cc +++ b/src/services/cri/cri_sandbox.cc @@ -26,6 +26,7 @@ #include #include +#include "cxxutils.h" #include "log.h" #include "utils.h" #include "errors.h" @@ -275,7 +276,7 @@ void CRIRuntimeServiceImpl::SetupSandboxFiles(const std::string &resolvPath, if (resolvPath.empty()) { return; } - std::string resolvContent; + std::vector resolvContentStrs; /* set DNS options */ int len = config.dns_config().searches_size(); @@ -283,26 +284,24 @@ void CRIRuntimeServiceImpl::SetupSandboxFiles(const std::string &resolvPath, error.SetError("DNSOption.Searches has more than 6 domains"); return; } - resolvContent = "search "; - int i; - for (i = 0; i < len - 1; i++) { - resolvContent += (config.dns_config().searches(i) + " "); + + std::vector servers(config.dns_config().servers().begin(), config.dns_config().servers().end()); + if (!servers.empty()) { + resolvContentStrs.push_back("nameserver " + CXXUtils::StringsJoin(servers, "\nnameserver ")); } - resolvContent += (config.dns_config().searches(i) + "\n"); - len = config.dns_config().servers_size(); - resolvContent += "nameserver "; - for (i = 0; i < len - 1; i++) { - resolvContent += (config.dns_config().servers(i) + "\nnameserver "); + + std::vector searchs(config.dns_config().searches().begin(), config.dns_config().searches().end()); + if (!searchs.empty()) { + resolvContentStrs.push_back("search " + CXXUtils::StringsJoin(searchs, " ")); } - resolvContent += config.dns_config().servers(i) + "\n"; - len = config.dns_config().options_size(); - resolvContent += "options "; - for (i = 0; i < len - 1; i++) { - resolvContent += (config.dns_config().options(i) + " "); + + std::vector options(config.dns_config().options().begin(), config.dns_config().options().end()); + if (!options.empty()) { + resolvContentStrs.push_back("options " + CXXUtils::StringsJoin(options, " ")); } - resolvContent += (config.dns_config().options(i) + "\n"); - if (!resolvContent.empty()) { + if (!resolvContentStrs.empty()) { + std::string resolvContent = CXXUtils::StringsJoin(resolvContentStrs, "\n") + "\n"; if (util_write_file(resolvPath.c_str(), resolvContent.c_str(), resolvContent.size()) != 0) { error.SetError("Failed to write resolv content"); } -- Gitee From 6efcdd4c58dfe7da802107983458ef29eb4365a7 Mon Sep 17 00:00:00 2001 From: wujing Date: Fri, 3 Jan 2020 12:27:23 +0800 Subject: [PATCH 04/11] update health monitor process when container paused and unpaused Signed-off-by: wujing --- src/services/execution/execute/execution_extend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/execution/execute/execution_extend.c b/src/services/execution/execute/execution_extend.c index cb589f1..8d24dcd 100644 --- a/src/services/execution/execute/execution_extend.c +++ b/src/services/execution/execute/execution_extend.c @@ -553,6 +553,7 @@ static int resume_container(container_t *cont) } state_reset_paused(cont->state); + update_health_monitor(cont->common_config->id); if (container_to_disk(cont)) { ERROR("Failed to save container \"%s\" to disk", id); @@ -738,6 +739,7 @@ static int pause_container(container_t *cont) } state_set_paused(cont->state); + update_health_monitor(cont->common_config->id); if (container_to_disk(cont)) { ERROR("Failed to save container \"%s\" to disk", id); @@ -831,8 +833,6 @@ static int container_pause_cb(const container_pause_request *request, EVENT("Event: {Object: %s, Type: Paused}", id); - update_health_monitor(id); - pack_response: pack_pause_response(*response, cc, id); container_unref(cont); -- Gitee From f0b6c9619ea7616f29c78d19a9aadc47d1a2da1e Mon Sep 17 00:00:00 2001 From: wujing Date: Fri, 3 Jan 2020 13:03:39 +0800 Subject: [PATCH 05/11] using glibc library functions for unit test Signed-off-by: wujing --- test/cutils/utils_array/CMakeLists.txt | 4 +- test/cutils/utils_array/utils_array_llt.cc | 29 ----------- test/cutils/utils_convert/CMakeLists.txt | 2 +- .../cutils/utils_convert/utils_convert_llt.cc | 1 - test/cutils/utils_string/CMakeLists.txt | 2 +- test/cutils/utils_string/utils_string_llt.cc | 48 ------------------- .../image/oci/oci_config_merge/CMakeLists.txt | 2 +- .../oci_config_merge/oci_config_merge_llt.cc | 1 - test/path/CMakeLists.txt | 2 +- test/path/path_llt.cc | 9 ++-- test/{llt.sh => test.sh} | 0 11 files changed, 12 insertions(+), 88 deletions(-) rename test/{llt.sh => test.sh} (100%) diff --git a/test/cutils/utils_array/CMakeLists.txt b/test/cutils/utils_array/CMakeLists.txt index 6f7c8dd..df29cef 100644 --- a/test/cutils/utils_array/CMakeLists.txt +++ b/test/cutils/utils_array/CMakeLists.txt @@ -24,5 +24,5 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils ${CMAKE_BINARY_DIR}/json ) -set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc -Wl,--wrap,memcpy_s") -target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz) +set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc") +target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz) diff --git a/test/cutils/utils_array/utils_array_llt.cc b/test/cutils/utils_array/utils_array_llt.cc index 830e3c9..cb18c74 100644 --- a/test/cutils/utils_array/utils_array_llt.cc +++ b/test/cutils/utils_array/utils_array_llt.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include #include "mock.h" #include "utils_array.h" @@ -25,10 +24,6 @@ extern "C" { DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size)); DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size)); - - DECLARE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count)); - DEFINE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count), - (dest, destMax, src, count)); } TEST(utils_array, test_util_array_len) @@ -158,17 +153,6 @@ TEST(utils_array, test_util_grow_array) util_free_array(array); array = nullptr; capacity = 0; - - capacity = 1; - array = (char **)util_common_calloc_s(capacity * sizeof(char *)); - ASSERT_NE(array, nullptr); - MOCK_SET(memcpy_s, EINVAL); - ret = util_grow_array(&array, &capacity, 1, 1); - ASSERT_NE(ret, 0); - MOCK_CLEAR(memcpy_s); - util_free_array(array); - array = nullptr; - capacity = 0; } TEST(utils_array, test_util_array_append) @@ -219,17 +203,4 @@ TEST(utils_array, test_util_array_append) MOCK_CLEAR(calloc); util_free_array(array); array = nullptr; - - array_three = (char **)util_common_calloc_s(4 * sizeof(char *)); - ASSERT_NE(array_three, nullptr); - array_three[0] = util_strdup_s("test1"); - array_three[1] = util_strdup_s("test2"); - array_three[2] = util_strdup_s("test3"); - array_three[3] = nullptr; - MOCK_SET(memcpy_s, EINVAL); - ret = util_array_append(&array_three, "123"); - ASSERT_NE(ret, 0); - MOCK_CLEAR(memcpy_s); - util_free_array(array_three); - array_three = nullptr; } diff --git a/test/cutils/utils_convert/CMakeLists.txt b/test/cutils/utils_convert/CMakeLists.txt index 53886ad..265ac1d 100644 --- a/test/cutils/utils_convert/CMakeLists.txt +++ b/test/cutils/utils_convert/CMakeLists.txt @@ -24,4 +24,4 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils ${CMAKE_BINARY_DIR}/json ) -target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz) +target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz) diff --git a/test/cutils/utils_convert/utils_convert_llt.cc b/test/cutils/utils_convert/utils_convert_llt.cc index 9808c93..0ad48f8 100644 --- a/test/cutils/utils_convert/utils_convert_llt.cc +++ b/test/cutils/utils_convert/utils_convert_llt.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include #include "mock.h" #include "utils_convert.h" diff --git a/test/cutils/utils_string/CMakeLists.txt b/test/cutils/utils_string/CMakeLists.txt index 1b9d0bd..33c2373 100644 --- a/test/cutils/utils_string/CMakeLists.txt +++ b/test/cutils/utils_string/CMakeLists.txt @@ -25,4 +25,4 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_BINARY_DIR}/json ) set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_strdup_s -Wl,--wrap,calloc -Wl,--wrap,strcat_s") -target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz) +target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz) diff --git a/test/cutils/utils_string/utils_string_llt.cc b/test/cutils/utils_string/utils_string_llt.cc index bf2486a..04210bd 100644 --- a/test/cutils/utils_string/utils_string_llt.cc +++ b/test/cutils/utils_string/utils_string_llt.cc @@ -15,7 +15,6 @@ #include #include -#include #include #include "mock.h" #include "utils_string.h" @@ -26,26 +25,6 @@ extern "C" { DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size)); DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size)); - - DECLARE_WRAPPER_V(strcat_s, errno_t, (char *strDest, size_t destMax, const char *strSrc)); - DEFINE_WRAPPER_V(strcat_s, errno_t, (char *strDest, size_t destMax, const char *strSrc), - (strDest, destMax, strSrc)); -} - -static int g_strcat_s_cnt = 0; - -static errno_t strcat_s_fail(char *strDest, size_t destMax, const char *strSrc) -{ - return (errno_t)EINVAL; -} - -static errno_t strcat_s_second_fail(char *strDest, size_t destMax, const char *strSrc) -{ - g_strcat_s_cnt++; - if (g_strcat_s_cnt == 1) { - return __real_strcat_s(strDest, destMax, strSrc); - } - return (errno_t)EINVAL; } TEST(utils_string_llt, test_strings_count) @@ -681,22 +660,6 @@ TEST(utils_string_llt, test_util_string_join) result = util_string_join(nullptr, array_long, array_long_len); ASSERT_STREQ(result, nullptr); - - MOCK_SET_V(strcat_s, strcat_s_fail); - result = util_string_join(" ", array_short, array_short_len); - ASSERT_STREQ(result, nullptr); - MOCK_CLEAR(strcat_s); - - MOCK_SET_V(strcat_s, strcat_s_fail); - result = util_string_join(" ", array_long, array_long_len); - ASSERT_STREQ(result, nullptr); - MOCK_CLEAR(strcat_s); - - g_strcat_s_cnt = 0; - MOCK_SET_V(strcat_s, strcat_s_second_fail); - result = util_string_join(" ", array_long, array_long_len); - ASSERT_STREQ(result, nullptr); - MOCK_CLEAR(strcat_s); } TEST(utils_string_llt, test_util_string_append) @@ -742,17 +705,6 @@ TEST(utils_string_llt, test_util_string_append) result = util_string_append("abc", "123"); ASSERT_STREQ(result, nullptr); MOCK_CLEAR(calloc); - - MOCK_SET_V(strcat_s, strcat_s_fail); - result = util_string_append("abc", "123"); - ASSERT_STREQ(result, nullptr); - MOCK_CLEAR(strcat_s); - - g_strcat_s_cnt = 0; - MOCK_SET_V(strcat_s, strcat_s_second_fail); - result = util_string_append("abc", "123"); - ASSERT_STREQ(result, nullptr); - MOCK_CLEAR(strcat_s); } TEST(utils_string_llt, test_dup_array_of_strings) diff --git a/test/image/oci/oci_config_merge/CMakeLists.txt b/test/image/oci/oci_config_merge/CMakeLists.txt index 23c3f18..141d120 100644 --- a/test/image/oci/oci_config_merge/CMakeLists.txt +++ b/test/image/oci/oci_config_merge/CMakeLists.txt @@ -57,4 +57,4 @@ target_include_directories(${EXE} PUBLIC ) set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_common_calloc_s -Wl,--wrap,util_smart_calloc_s -Wl,--wrap,merge_env") -target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz) +target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz) diff --git a/test/image/oci/oci_config_merge/oci_config_merge_llt.cc b/test/image/oci/oci_config_merge/oci_config_merge_llt.cc index 9437b14..25728ec 100644 --- a/test/image/oci/oci_config_merge/oci_config_merge_llt.cc +++ b/test/image/oci/oci_config_merge/oci_config_merge_llt.cc @@ -15,7 +15,6 @@ #include #include -#include #include #include "mock.h" #include "oci_runtime_spec.h" diff --git a/test/path/CMakeLists.txt b/test/path/CMakeLists.txt index f9afca9..62d4a10 100644 --- a/test/path/CMakeLists.txt +++ b/test/path/CMakeLists.txt @@ -24,4 +24,4 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_BINARY_DIR}/json ) set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,getcwd -Wl,--wrap,readlink") -target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz) +target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz) diff --git a/test/path/path_llt.cc b/test/path/path_llt.cc index 557573f..ba7ef7c 100644 --- a/test/path/path_llt.cc +++ b/test/path/path_llt.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include #include "mock.h" #include "utils.h" @@ -36,13 +35,16 @@ extern "C" { static char *getcwd_specify(char *str, size_t size) { + const char *dst = "/home"; if (str == nullptr) { return nullptr; } - if (strcpy_s(str, size, "/home") != EOK) { + if (size <= strlen(dst)) { return nullptr; } + (void)strcpy(str, dst); + return str; } @@ -74,9 +76,10 @@ static ssize_t readlink_specify(const char *path, char *buf, size_t bufsize) return -1; } - if (strcpy_s(buf, bufsize, linkpath) != EOK) { + if (bufsize <= linkpath_length) { return -1; } + (void)strcpy(buf, linkpath); if (linkpath_length > bufsize) { return bufsize; diff --git a/test/llt.sh b/test/test.sh similarity index 100% rename from test/llt.sh rename to test/test.sh -- Gitee From 49143326b4ba366754ad3205491aa810170a4c3c Mon Sep 17 00:00:00 2001 From: caihaomin Date: Sat, 4 Jan 2020 09:28:46 +0800 Subject: [PATCH 06/11] fix typos Signed-off-by: caihaomin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d632af2..48bd7a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## iSulad -`iSulad` is a light weight container runtime daemon which is desinged for IOT and Cloud infrastructure.`iSulad` has the characteristics of light, fast and not limited by hardware specifications and architecture, and can be applied more widely. +`iSulad` is a light weight container runtime daemon which is designed for IOT and Cloud infrastructure.`iSulad` has the characteristics of light, fast and not limited by hardware specifications and architecture, and can be applied more widely. ## Getting Started -- Gitee From 5eae8968dbbcd8bcda9a4e57b6c3225d119fdd3e Mon Sep 17 00:00:00 2001 From: caihaomin Date: Sat, 4 Jan 2020 19:35:53 +0800 Subject: [PATCH 07/11] fix wrong link in ReadME Signed-off-by: caihaomin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48bd7a9..21f1f27 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ $ sudo lcrc rm test ``` ### Build from source -Build requirements for developers are listed in [build_guide](./doc/build_guide.md) +Build requirements for developers are listed in [build_guide](./docs/build_guide.md) ## How to Contribute -- Gitee From e22d12dc30af03b99cd2b4d0bd8681329c5f3ee7 Mon Sep 17 00:00:00 2001 From: wujing Date: Sat, 4 Jan 2020 21:32:26 +0800 Subject: [PATCH 08/11] internal change Signed-off-by: wujing --- src/api/services/cri/api.proto | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/api/services/cri/api.proto b/src/api/services/cri/api.proto index 5166276..022fa51 100644 --- a/src/api/services/cri/api.proto +++ b/src/api/services/cri/api.proto @@ -1,17 +1,19 @@ -// ####################################################################### -// ##- @Copyright (C) Huawei Technologies., Ltd. 2019. All rights reserved. -// # - iSulad licensed under the Mulan PSL v1. -// # - You can use this software according to the terms and conditions of the Mulan PSL v1. -// # - You may obtain a copy of Mulan PSL v1 at: -// # - http://license.coscl.org.cn/MulanPSL -// # - 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 v1 for more details. -// ##- @Description: generate grpc -// ##- @Author: wujing -// ##- @Create: 2019-04-25 -// ####################################################################### +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // To regenerate api.pb.go run hack/update-generated-runtime.sh syntax = 'proto3'; -- Gitee From e2728aa73eb274f036b63ebdaaef7ab88e7bb43a Mon Sep 17 00:00:00 2001 From: LiFeng Date: Mon, 6 Jan 2020 05:11:01 -0500 Subject: [PATCH 09/11] iSulad: internal change Signed-off-by: LiFeng --- cmake/options.cmake | 2 +- iSulad.spec | 4 +- src/api/services/containers/container.proto | 56 ++- .../services/containers/rest/container.rest.h | 3 - src/cmd/lcrc/arguments.h | 3 + src/cmd/lcrc/base/create.c | 1 - src/cmd/lcrc/base/run.c | 100 +++++- src/cmd/lcrc/extend/stats.c | 1 - src/cmd/lcrc/extend/stats.h | 2 - src/cmd/lcrc/stream/exec.c | 129 +++++++ .../client/grpc/grpc_containers_client.cc | 128 ++++--- src/connect/client/lcrc_connect.h | 6 +- .../client/rest/rest_containers_client.c | 106 ------ .../service/grpc/grpc_containers_service.cc | 47 +-- .../service/grpc/grpc_containers_service.h | 17 +- .../grpc/grpc_containers_service_private.cc | 68 ++-- .../service/rest/rest_containers_service.c | 120 ------- src/cutils/utils.c | 50 +++ src/cutils/utils.h | 10 + src/cutils/utils_regex.c | 10 +- src/cutils/utils_verify.c | 11 + src/cutils/utils_verify.h | 2 + src/engines/engine.h | 44 +-- src/engines/lcr/lcr_engine.c | 252 ++------------ src/image/oci/global_config.h | 21 -- src/image/oci/isula_image.c | 8 +- src/image/oci/run_image_server.c | 38 ++- .../schema/schema/container/exec-request.json | 3 + src/liblcrc.c | 81 +++-- src/liblcrc.h | 39 +-- src/liblcrd.c | 62 ++-- src/liblcrd.h | 30 +- src/runtime/lcr/lcr_rt_ops.c | 214 ++++++++++-- src/runtime/lcr/lcr_rt_ops.h | 12 +- src/runtime/runtime.c | 157 ++++++++- src/runtime/runtime.h | 72 +++- src/services/callback.h | 4 +- src/services/cri/cri_container.cc | 94 ++++-- src/services/cri/cri_runtime_service.h | 7 + src/services/cri/cri_security_context.cc | 3 +- .../execution/execute/execution_create.c | 35 +- .../execution/execute/execution_extend.c | 271 ++++++++++----- .../execution/execute/execution_information.c | 155 ++------- .../execution/execute/execution_stream.c | 58 ++-- .../execution/manager/container_unix.c | 75 ++-- .../execution/manager/container_unix.h | 4 +- src/services/execution/manager/restore.c | 319 ++++-------------- 47 files changed, 1535 insertions(+), 1399 deletions(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index f03bc84..2004add 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -33,7 +33,7 @@ endif() option(VERSION "set lcrd version" ON) if (VERSION STREQUAL "ON") - set(LCRD_VERSION "1.1.4") + set(LCRD_VERSION "1.1.5") endif() option(DEBUG "set lcrd gcc option" ON) diff --git a/iSulad.spec b/iSulad.spec index 9699dab..46e2539 100644 --- a/iSulad.spec +++ b/iSulad.spec @@ -1,5 +1,5 @@ -%global _version 1.1.4 -%global _release 20191226.061440.gitfa7769d5 +%global _version 1.1.5 +%global _release 20200106.022952.git939935db %global is_systemd 1 %global debug_package %{nil} diff --git a/src/api/services/containers/container.proto b/src/api/services/containers/container.proto index 69ea47c..73729cf 100644 --- a/src/api/services/containers/container.proto +++ b/src/api/services/containers/container.proto @@ -69,20 +69,18 @@ message Container { message Container_info { string id = 1; - int32 pid = 2; - ContainerStatus status = 3; - uint64 pids_current = 4; - uint64 cpu_use_nanos = 5; - uint64 cpu_use_user = 6; - uint64 cpu_use_kernel = 7; - uint64 cpu_system_use = 8; - uint32 online_cpus = 9; - uint64 blkio_read = 10; - uint64 blkio_write = 11; - uint64 mem_used = 12; - uint64 mem_limit = 13; - uint64 kmem_used = 14; - uint64 kmem_limit = 15; + uint64 pids_current = 2; + uint64 cpu_use_nanos = 3; + uint64 cpu_use_user = 4; + uint64 cpu_use_kernel = 5; + uint64 cpu_system_use = 6; + uint32 online_cpus = 7; + uint64 blkio_read = 8; + uint64 blkio_write = 9; + uint64 mem_used = 10; + uint64 mem_limit = 11; + uint64 kmem_used = 12; + uint64 kmem_limit = 13; } message Event { @@ -114,13 +112,13 @@ service ContainerService { rpc Info(InfoRequest) returns (InfoResponse); rpc Update(UpdateRequest) returns (UpdateResponse); rpc Attach(stream AttachRequest) returns (stream AttachResponse); - rpc Container_conf(Container_conf_Request) returns (Container_conf_Response); rpc Restart(RestartRequest) returns (RestartResponse); rpc Export(ExportRequest) returns (ExportResponse); rpc CopyFromContainer(CopyFromContainerRequest) returns (stream CopyFromContainerResponse); rpc CopyToContainer(stream CopyToContainerRequest) returns (stream CopyToContainerResponse); rpc Rename(RenameRequest) returns (RenameResponse); rpc Logs(LogsRequest) returns (stream LogsResponse); + rpc Resize(ResizeRequest) returns (ResizeResponse); } message CreateRequest { @@ -271,7 +269,6 @@ message ListResponse { } message StatsRequest { - string runtime = 1; repeated string containers = 2; bool all = 3; } @@ -313,6 +310,7 @@ message ExecRequest { repeated string argv = 10; repeated string env = 11; string user = 12; + string suffix = 13; } message ExecResponse { int32 pid = 1; @@ -390,19 +388,6 @@ message UpdateResponse { uint32 cc = 2; string errmsg = 3; } -message Container_conf_Request { - // ContainerID specifies the container in which to get config. - string container_id = 1; - string runtime = 2; -} - -message Container_conf_Response { - string container_logpath = 1; - string container_logsize = 2; - uint32 container_logrotate = 3; - uint32 cc = 4; - string errmsg = 5; -} message ExportRequest { string id = 1; @@ -461,3 +446,16 @@ message LogsResponse { string time = 3; bytes attrs = 4; } + +message ResizeRequest { + string id = 1; + string suffix = 2; + uint32 height = 3; + uint32 width = 4; +} + +message ResizeResponse { + string id = 1; + uint32 cc = 2; + string errmsg = 3; +} diff --git a/src/api/services/containers/rest/container.rest.h b/src/api/services/containers/rest/container.rest.h index 4bf3baf..f848e55 100644 --- a/src/api/services/containers/rest/container.rest.h +++ b/src/api/services/containers/rest/container.rest.h @@ -45,8 +45,6 @@ #include "container_resume_response.h" #include "container_wait_request.h" #include "container_wait_response.h" -#include "container_conf_request.h" -#include "container_conf_response.h" #ifndef RestHttpHead #define RestHttpHead "http://localhost" @@ -67,7 +65,6 @@ #define ContainerServiceAttach "/ContainerService/Attach" #define ContainerServiceResume "/ContainerService/Resume" #define ContainerServiceWait "/ContainerService/Wait" -#define ContainerServiceConf "/ContainerService/Container_conf" /* "/ContainerService/Kill", "/ContainerService/Delete", diff --git a/src/cmd/lcrc/arguments.h b/src/cmd/lcrc/arguments.h index 4d8bd98..308d45c 100644 --- a/src/cmd/lcrc/arguments.h +++ b/src/cmd/lcrc/arguments.h @@ -286,6 +286,9 @@ struct client_arguments { char *type; char *tag; + // exec + char *exec_suffix; + // login/logout char *username; char *password; diff --git a/src/cmd/lcrc/base/create.c b/src/cmd/lcrc/base/create.c index b96dbcc..d22bd8e 100644 --- a/src/cmd/lcrc/base/create.c +++ b/src/cmd/lcrc/base/create.c @@ -1273,7 +1273,6 @@ int cmd_create_main(int argc, const char **argv) printf("%s\n", g_cmd_create_args.name); nret = EXIT_SUCCESS; out: - client_arguments_free(&g_cmd_create_args); exit(nret); } diff --git a/src/cmd/lcrc/base/run.c b/src/cmd/lcrc/base/run.c index 7cec120..ed2a520 100644 --- a/src/cmd/lcrc/base/run.c +++ b/src/cmd/lcrc/base/run.c @@ -12,7 +12,11 @@ * Create: 2018-11-08 * Description: provide container run functions ******************************************************************************/ +#include #include +#include +#include + #include "run.h" #include "arguments.h" #include "log.h" @@ -127,6 +131,97 @@ out: return ret; } +static int do_resize_run_console(const struct client_arguments *args, unsigned int height, unsigned int width) +{ + int ret = 0; + lcrc_connect_ops *ops = NULL; + struct lcrc_resize_request request = { 0 }; + struct lcrc_resize_response *response = NULL; + client_connect_config_t config = { 0 }; + + ops = get_connect_client_ops(); + if (ops == NULL || ops->container.resize == NULL) { + ERROR("Unimplemented ops"); + ret = -1; + goto out; + } + + request.id = args->name; + request.height = height; + request.width = width; + + response = util_common_calloc_s(sizeof(struct lcrc_resize_response)); + if (response == NULL) { + ERROR("Out of memory"); + ret = -1; + goto out; + } + + config = get_connect_config(args); + ret = ops->container.resize(&request, response, &config); + if (ret != 0) { + ERROR("Failed to call resize"); + goto out; + } + +out: + lcrc_resize_response_free(response); + return ret; +} + +static void *run_console_resize_thread(void *arg) +{ + int ret = 0; + const struct client_arguments *args = arg; + static struct winsize s_pre_wsz; + struct winsize wsz; + + if (!isatty(STDIN_FILENO)) { + goto out; + } + + ret = pthread_detach(pthread_self()); + if (ret != 0) { + CRIT("Start: set thread detach fail"); + goto out; + } + + while (true) { + sleep(1); // check the windows size per 1s + ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz); + if (ret < 0) { + WARN("Failed to get window size"); + continue; + } + if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) { + continue; + } + ret = do_resize_run_console(args, wsz.ws_row, wsz.ws_col); + if (ret != 0) { + continue; + } + s_pre_wsz.ws_row = wsz.ws_row; + s_pre_wsz.ws_col = wsz.ws_col; + } + +out: + return NULL; +} + +int run_client_console_resize_thread(struct client_arguments *args) +{ + int res = 0; + pthread_t a_thread; + + res = pthread_create(&a_thread, NULL, run_console_resize_thread, (void *)(args)); + if (res != 0) { + CRIT("Thread creation failed"); + return -1; + } + + return 0; +} + int cmd_run_main(int argc, const char **argv) { int ret = 0; @@ -172,6 +267,10 @@ int cmd_run_main(int argc, const char **argv) printf("%s\n", g_cmd_run_args.name); } + if (g_cmd_run_args.custom_conf.tty && isatty(STDIN_FILENO)) { + (void)run_client_console_resize_thread(&g_cmd_run_args); + } + if (strncmp(g_cmd_run_args.socket, "tcp://", strlen("tcp://")) == 0) { ret = remote_cmd_start(&g_cmd_run_args, &exit_code); if (ret != 0) { @@ -187,7 +286,6 @@ int cmd_run_main(int argc, const char **argv) } free_out: - client_arguments_free(&g_cmd_run_args); exit(ret); } diff --git a/src/cmd/lcrc/extend/stats.c b/src/cmd/lcrc/extend/stats.c index aab1db4..36de0b8 100644 --- a/src/cmd/lcrc/extend/stats.c +++ b/src/cmd/lcrc/extend/stats.c @@ -213,7 +213,6 @@ static int client_stats(const struct client_arguments *args) { struct lcrc_stats_request request = { 0 }; - request.runtime = args->runtime; request.all = args->showall; request.containers = (char **)(args->argv); request.containers_len = (size_t)(args->argc); diff --git a/src/cmd/lcrc/extend/stats.h b/src/cmd/lcrc/extend/stats.h index 8f14b91..2535116 100644 --- a/src/cmd/lcrc/extend/stats.h +++ b/src/cmd/lcrc/extend/stats.h @@ -18,8 +18,6 @@ #include "arguments.h" #define STATUS_OPTIONS(cmdargs) \ - { CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \ - "Runtime to use for containers(default: lcr)", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \ "Show all containers (default shows just running)", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \ diff --git a/src/cmd/lcrc/stream/exec.c b/src/cmd/lcrc/stream/exec.c index d95238d..2b6322c 100644 --- a/src/cmd/lcrc/stream/exec.c +++ b/src/cmd/lcrc/stream/exec.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "arguments.h" #include "exec.h" @@ -52,6 +54,7 @@ static int client_exec(const struct client_arguments *args, const struct command } request.name = args->name; + request.suffix = args->exec_suffix; request.tty = args->custom_conf.tty; request.open_stdin = args->custom_conf.open_stdin; request.attach_stdin = args->custom_conf.attach_stdin; @@ -248,6 +251,7 @@ static int remote_cmd_exec(const struct client_arguments *args, uint32_t *exit_c g_cmd_exec_args.name = util_strdup_s(inspect_data->id); request.name = args->name; + request.suffix = args->exec_suffix; request.tty = args->custom_conf.tty; request.open_stdin = args->custom_conf.open_stdin; request.attach_stdin = args->custom_conf.attach_stdin; @@ -313,6 +317,119 @@ out: return ret; } +static char *generate_exec_suffix() +{ + char *exec_suffix = NULL; + + exec_suffix = util_common_calloc_s(sizeof(char) * (CONTAINER_ID_MAX_LEN + 1)); + if (exec_suffix == NULL) { + ERROR("Out of memory"); + goto out; + } + + if (util_generate_random_str(exec_suffix, (size_t)CONTAINER_ID_MAX_LEN)) { + ERROR("Generate exec suffix failed"); + free(exec_suffix); + exec_suffix = NULL; + goto out; + } + +out: + return exec_suffix; +} + +static int do_resize_exec_console(const struct client_arguments *args, unsigned int height, unsigned int width) +{ + int ret = 0; + lcrc_connect_ops *ops = NULL; + struct lcrc_resize_request request = { 0 }; + struct lcrc_resize_response *response = NULL; + client_connect_config_t config = { 0 }; + + ops = get_connect_client_ops(); + if (ops == NULL || ops->container.resize == NULL) { + ERROR("Unimplemented ops"); + ret = -1; + goto out; + } + + request.id = args->name; + request.suffix = args->exec_suffix; + request.height = height; + request.width = width; + + response = util_common_calloc_s(sizeof(struct lcrc_resize_response)); + if (response == NULL) { + ERROR("Out of memory"); + ret = -1; + goto out; + } + + config = get_connect_config(args); + ret = ops->container.resize(&request, response, &config); + if (ret != 0) { + ERROR("Failed to call resize"); + goto out; + } + +out: + lcrc_resize_response_free(response); + return ret; +} + +static void *exec_console_resize_thread(void *arg) +{ + int ret = 0; + const struct client_arguments *args = arg; + static struct winsize s_pre_wsz; + struct winsize wsz; + + if (!isatty(STDIN_FILENO)) { + goto out; + } + + ret = pthread_detach(pthread_self()); + if (ret != 0) { + CRIT("Start: set thread detach fail"); + goto out; + } + + while (true) { + sleep(1); // check the windows size per 1s + ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz); + if (ret < 0) { + WARN("Failed to get window size"); + continue; + } + if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) { + continue; + } + ret = do_resize_exec_console(args, wsz.ws_row, wsz.ws_col); + if (ret != 0) { + continue; + } + s_pre_wsz.ws_row = wsz.ws_row; + s_pre_wsz.ws_col = wsz.ws_col; + } + +out: + return NULL; +} + +int exec_client_console_resize_thread(struct client_arguments *args) +{ + int res = 0; + pthread_t a_thread; + + res = pthread_create(&a_thread, NULL, exec_console_resize_thread, (void *)(args)); + if (res != 0) { + CRIT("Thread creation failed"); + return -1; + } + + return 0; +} + int cmd_exec_main(int argc, const char **argv) { int ret = 0; @@ -339,6 +456,18 @@ int cmd_exec_main(int argc, const char **argv) custom_cfg->open_stdin = false; } + g_cmd_exec_args.exec_suffix = generate_exec_suffix(); + if (g_cmd_exec_args.exec_suffix == NULL) { + ERROR("Failed to generate exec suffix"); + ret = -1; + goto out; + } + + if (custom_cfg->tty && isatty(STDIN_FILENO) && (custom_cfg->attach_stdin || custom_cfg->attach_stdout || + custom_cfg->attach_stderr)) { + (void)exec_client_console_resize_thread(&g_cmd_exec_args); + } + if (strncmp(g_cmd_exec_args.socket, "tcp://", strlen("tcp://")) == 0) { ret = remote_cmd_exec(&g_cmd_exec_args, &exit_code); if (ret != 0) { diff --git a/src/connect/client/grpc/grpc_containers_client.cc b/src/connect/client/grpc/grpc_containers_client.cc index 59b3293..50a1089 100644 --- a/src/connect/client/grpc/grpc_containers_client.cc +++ b/src/connect/client/grpc/grpc_containers_client.cc @@ -636,6 +636,61 @@ public: } }; +class ContainerResize : public ClientBase { +public: + explicit ContainerResize(void *args) + : ClientBase(args) + { + } + ~ContainerResize() = default; + + int request_to_grpc(const lcrc_resize_request *request, ResizeRequest *grequest) override + { + if (request == nullptr) { + return -1; + } + + if (request->id != nullptr) { + grequest->set_id(request->id); + } + if (request->suffix != nullptr) { + grequest->set_suffix(request->suffix); + } + grequest->set_height(request->height); + + grequest->set_width(request->width); + + return 0; + } + + int response_from_grpc(ResizeResponse *gresponse, lcrc_resize_response *response) override + { + response->server_errono = gresponse->cc(); + if (!gresponse->errmsg().empty()) { + response->errmsg = util_strdup_s(gresponse->errmsg().c_str()); + } + + return 0; + } + + int check_parameter(const ResizeRequest &req) override + { + if (req.id().empty()) { + ERROR("Missing container id in the request"); + return -1; + } + + return 0; + } + + Status grpc_call(ClientContext *context, const ResizeRequest &req, ResizeResponse *reply) override + { + return stub_->Resize(context, req, reply); + } +}; + + class ContainerRestart : public ClientBase { public: @@ -752,6 +807,9 @@ public: if (request->name != nullptr) { grequest->set_container_id(request->name); } + if (request->suffix != nullptr) { + grequest->set_suffix(request->suffix); + } grequest->set_tty(request->tty); grequest->set_open_stdin(request->open_stdin); grequest->set_attach_stdin(request->attach_stdin); @@ -876,6 +934,7 @@ public: exec.argv_len = (size_t)request->argc; exec.env = request->env; exec.env_len = request->env_len; + exec.suffix = request->suffix; json = container_exec_request_generate_json(&exec, &ctx, &err); if (json == nullptr) { format_errorf(&response->errmsg, "Can not generate json: %s", err); @@ -1589,61 +1648,6 @@ cleanup: } }; -class ContainerConf : public ClientBase { -public: - explicit ContainerConf(void *args) - : ClientBase(args) - { - } - ~ContainerConf() = default; - - int request_to_grpc(const lcrc_container_conf_request *request, Container_conf_Request *grequest) override - { - if (request == nullptr) { - return -1; - } - - if (request->name != nullptr) { - grequest->set_container_id(request->name); - } - - return 0; - } - - int response_from_grpc(Container_conf_Response *gresponse, lcrc_container_conf_response *response) override - { - response->server_errono = gresponse->cc(); - if (!gresponse->errmsg().empty()) { - response->errmsg = util_strdup_s(gresponse->errmsg().c_str()); - } - if (!gresponse->container_logpath().empty()) { - response->container_logpath = util_strdup_s(gresponse->container_logpath().c_str()); - } - response->container_logrotate = gresponse->container_logrotate(); - if (!gresponse->container_logsize().empty()) { - response->container_logsize = util_strdup_s(gresponse->container_logsize().c_str()); - } - - return 0; - } - - int check_parameter(const Container_conf_Request &req) override - { - if (req.container_id().empty()) { - ERROR("Missing container name in the request"); - return -1; - } - - return 0; - } - - Status grpc_call(ClientContext *context, const Container_conf_Request &req, Container_conf_Response *reply) override - { - return stub_->Container_conf(context, req, reply); - } -}; - class ContainerStats : public ClientBase { public: @@ -1659,10 +1663,6 @@ public: return -1; } - if (request->runtime != nullptr) { - grequest->set_runtime(request->runtime); - } - for (size_t i = 0; request->containers != nullptr && i < request->containers_len; i++) { grequest->add_containers(request->containers[i]); } @@ -1686,9 +1686,6 @@ public: if (!gresponse->containers(i).id().empty()) { response->container_stats[i].id = util_strdup_s(gresponse->containers(i).id().c_str()); } - response->container_stats[i].has_pid = (int)gresponse->containers(i).pid() != -1; - response->container_stats[i].pid = (uint32_t)gresponse->containers(i).pid(); - response->container_stats[i].status = (Container_Status)((int)gresponse->containers(i).status()); response->container_stats[i].pids_current = gresponse->containers(i).pids_current(); response->container_stats[i].cpu_use_nanos = gresponse->containers(i).cpu_use_nanos(); response->container_stats[i].cpu_system_use = gresponse->containers(i).cpu_system_use(); @@ -1712,11 +1709,6 @@ public: int check_parameter(const StatsRequest &req) override { - if (req.runtime().empty()) { - ERROR("Missing runtime in the request"); - return -1; - } - return 0; } @@ -2213,7 +2205,6 @@ int grpc_containers_client_ops_init(lcrc_connect_ops *ops) ops->container.pause = container_func; ops->container.resume = container_func; ops->container.update = container_func; - ops->container.conf = container_func; ops->container.kill = container_func; ops->container.stats = container_func; ops->container.wait = container_func; @@ -2226,6 +2217,7 @@ int grpc_containers_client_ops_init(lcrc_connect_ops *ops) container_func; ops->container.top = container_func; ops->container.rename = container_func; + ops->container.resize = container_func; ops->container.logs = container_func; return 0; diff --git a/src/connect/client/lcrc_connect.h b/src/connect/client/lcrc_connect.h index b18e3a5..46635d9 100644 --- a/src/connect/client/lcrc_connect.h +++ b/src/connect/client/lcrc_connect.h @@ -83,9 +83,6 @@ typedef struct { int(*update)(const struct lcrc_update_request *request, struct lcrc_update_response *response, void *arg); - int(*conf)(const struct lcrc_container_conf_request *request, - struct lcrc_container_conf_response *response, void *arg); - int(*attach)(const struct lcrc_attach_request *request, struct lcrc_attach_response *response, void *arg); @@ -98,7 +95,8 @@ typedef struct { struct lcrc_top_response *response, void *arg); int(*rename)(const struct lcrc_rename_request *request, struct lcrc_rename_response *response, void *arg); - + int(*resize)(const struct lcrc_resize_request *request, + struct lcrc_resize_response *response, void *arg); int(*logs)(const struct lcrc_logs_request *request, struct lcrc_logs_response *response, void *arg); } container_ops; diff --git a/src/connect/client/rest/rest_containers_client.c b/src/connect/client/rest/rest_containers_client.c index 7c0c2a6..f92ead5 100644 --- a/src/connect/client/rest/rest_containers_client.c +++ b/src/connect/client/rest/rest_containers_client.c @@ -271,37 +271,6 @@ out: return ret; } -/* container conf request to rest */ -static int container_conf_request_to_rest(const struct lcrc_container_conf_request *lconf_request, char **body, - size_t *body_len) -{ - container_conf_request *crequest = NULL; - struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; - parser_error err = NULL; - int ret = 0; - - crequest = util_common_calloc_s(sizeof(container_conf_request)); - if (crequest == NULL) { - ERROR("Out of memory"); - return -1; - } - - if (lconf_request->name != NULL) { - crequest->container_id = util_strdup_s(lconf_request->name); - } - *body = container_conf_request_generate_json(crequest, &ctx, &err); - if (*body == NULL) { - ERROR("Failed to generate conf request json:%s", err); - ret = -1; - goto out; - } - *body_len = strlen(*body) + 1; -out: - free(err); - free_container_conf_request(crequest); - return ret; -} - /* wait request to rest */ static int wait_request_to_rest(const struct lcrc_wait_request *lw_request, char **body, size_t *body_len) { @@ -568,47 +537,6 @@ out: return ret; } -/* unpack container conf response */ -static int unpack_container_conf_response(const struct parsed_http_message *message, void *arg) -{ - struct lcrc_container_conf_response *response = arg; - container_conf_response *cresponse = NULL; - parser_error err = NULL; - int ret = 0; - - ret = check_status_code(message->status_code); - if (ret != 0) { - goto out; - } - - cresponse = container_conf_response_parse_data(message->body, NULL, &err); - if (cresponse == NULL) { - ERROR("Invalid create response:%s", err); - ret = -1; - goto out; - } - response->server_errono = cresponse->cc; - if (cresponse->errmsg != NULL) { - response->errmsg = util_strdup_s(cresponse->errmsg); - } - if (cresponse->container_logpath != NULL) { - response->container_logpath = util_strdup_s(cresponse->container_logpath); - } - response->container_logrotate = cresponse->container_logrotate; - if (cresponse->container_logsize != NULL) { - response->container_logsize = util_strdup_s(cresponse->container_logsize); - } - ret = (cresponse->cc == LCRD_SUCCESS) ? 0 : -1; - if (message->status_code == EVHTP_RES_SERVERR) { - ret = -1; - } - -out: - free(err); - free_container_conf_response(cresponse); - return ret; -} - /* unpack wait response */ static int unpack_wait_response(const struct parsed_http_message *message, void *arg) { @@ -811,39 +739,6 @@ out: return ret; } -/* rest container conf */ -static int rest_container_conf(const struct lcrc_container_conf_request *lc_request, - struct lcrc_container_conf_response *lc_response, void *arg) -{ - char *body = NULL; - int ret = 0; - size_t len = 0; - client_connect_config_t *connect_config = (client_connect_config_t *)arg; - const char *socketname = (const char *)(connect_config->socket); - Buffer *c_output = NULL; - - ret = container_conf_request_to_rest(lc_request, &body, &len); - if (ret != 0) { - goto out; - } - ret = rest_send_requst(socketname, RestHttpHead ContainerServiceConf, body, len, &c_output); - if (ret != 0) { - lc_response->errmsg = util_strdup_s(errno_to_error_message(LCRD_ERR_CONNECT)); - lc_response->cc = LCRD_ERR_EXEC; - goto out; - } - ret = get_response(c_output, unpack_container_conf_response, (void *)lc_response); - if (ret != 0) { - goto out; - } -out: - if (c_output != NULL) { - buffer_free(c_output); - } - put_body(body); - return ret; -} - /* rest container wait */ static int rest_container_wait(const struct lcrc_wait_request *lw_request, struct lcrc_wait_response *lw_response, void *arg) @@ -1871,7 +1766,6 @@ int rest_containers_client_ops_init(lcrc_connect_ops *ops) ops->container.attach = &rest_container_attach; ops->container.resume = &rest_container_resume; ops->container.update = &rest_container_update; - ops->container.conf = &rest_container_conf; ops->container.kill = &rest_container_kill; ops->container.version = &rest_container_version; ops->container.wait = &rest_container_wait; diff --git a/src/connect/service/grpc/grpc_containers_service.cc b/src/connect/service/grpc/grpc_containers_service.cc index 5b9f28c..016a959 100644 --- a/src/connect/service/grpc/grpc_containers_service.cc +++ b/src/connect/service/grpc/grpc_containers_service.cc @@ -1041,31 +1041,36 @@ Status ContainerServiceImpl::Export(ServerContext *context, const ExportRequest return Status::OK; } -Status ContainerServiceImpl::Container_conf(ServerContext *context, const Container_conf_Request *request, - Container_conf_Response *reply) +Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest *request, + RenameResponse *reply) { int ret, tret; service_callback_t *cb = nullptr; - struct lcrd_container_conf_request *lcrdreq = nullptr; - struct lcrd_container_conf_response *lcrdres = nullptr; + struct lcrd_container_rename_request *lcrdreq = nullptr; + struct lcrd_container_rename_response *lcrdres = nullptr; + + auto status = GrpcServerTlsAuth::auth(context, "container_rename"); + if (!status.ok()) { + return status; + } cb = get_service_callback(); - if (cb == nullptr || cb->container.conf == nullptr) { + if (cb == nullptr || cb->container.rename == nullptr) { return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback"); } - tret = container_conf_request_from_grpc(request, &lcrdreq); + tret = container_rename_request_from_grpc(request, &lcrdreq); if (tret != 0) { ERROR("Failed to transform grpc request"); reply->set_cc(LCRD_ERR_INPUT); return Status::OK; } - ret = cb->container.conf(lcrdreq, &lcrdres); - tret = container_conf_response_to_grpc(lcrdres, reply); + ret = cb->container.rename(lcrdreq, &lcrdres); + tret = container_rename_response_to_grpc(lcrdres, reply); - lcrd_container_conf_request_free(lcrdreq); - lcrd_container_conf_response_free(lcrdres); + lcrd_container_rename_request_free(lcrdreq); + lcrd_container_rename_response_free(lcrdres); if (tret != 0) { reply->set_errmsg(errno_to_error_message(LCRD_ERR_INTERNAL)); reply->set_cc(LCRD_ERR_INTERNAL); @@ -1074,36 +1079,36 @@ Status ContainerServiceImpl::Container_conf(ServerContext *context, const Contai return Status::OK; } -Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest *request, - RenameResponse *reply) +Status ContainerServiceImpl::Resize(ServerContext *context, const ResizeRequest *request, + ResizeResponse *reply) { int ret, tret; service_callback_t *cb = nullptr; - struct lcrd_container_rename_request *lcrdreq = nullptr; - struct lcrd_container_rename_response *lcrdres = nullptr; + struct lcrd_container_resize_request *lcrdreq = nullptr; + struct lcrd_container_resize_response *lcrdres = nullptr; - auto status = GrpcServerTlsAuth::auth(context, "container_rename"); + auto status = GrpcServerTlsAuth::auth(context, "container_resize"); if (!status.ok()) { return status; } cb = get_service_callback(); - if (cb == nullptr || cb->container.rename == nullptr) { + if (cb == nullptr || cb->container.resize == nullptr) { return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback"); } - tret = container_rename_request_from_grpc(request, &lcrdreq); + tret = container_resize_request_from_grpc(request, &lcrdreq); if (tret != 0) { ERROR("Failed to transform grpc request"); reply->set_cc(LCRD_ERR_INPUT); return Status::OK; } - ret = cb->container.rename(lcrdreq, &lcrdres); - tret = container_rename_response_to_grpc(lcrdres, reply); + ret = cb->container.resize(lcrdreq, &lcrdres); + tret = container_resize_response_to_grpc(lcrdres, reply); - lcrd_container_rename_request_free(lcrdreq); - lcrd_container_rename_response_free(lcrdres); + lcrd_container_resize_request_free(lcrdreq); + lcrd_container_resize_response_free(lcrdres); if (tret != 0) { reply->set_errmsg(errno_to_error_message(LCRD_ERR_INTERNAL)); reply->set_cc(LCRD_ERR_INTERNAL); diff --git a/src/connect/service/grpc/grpc_containers_service.h b/src/connect/service/grpc/grpc_containers_service.h index 4d903cc..9dee9b1 100644 --- a/src/connect/service/grpc/grpc_containers_service.h +++ b/src/connect/service/grpc/grpc_containers_service.h @@ -75,11 +75,10 @@ public: Status Resume(ServerContext *context, const ResumeRequest *request, ResumeResponse *reply) override; - Status Container_conf(ServerContext *context, const Container_conf_Request *request, - Container_conf_Response *reply) override; - Status Rename(ServerContext *context, const RenameRequest *request, RenameResponse *reply) override; + Status Resize(ServerContext *context, const ResizeRequest *request, ResizeResponse *reply) override; + Status Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply) override; @@ -165,18 +164,18 @@ private: int resume_request_from_grpc(const ResumeRequest *grequest, container_resume_request **request); - int container_conf_request_from_grpc(const Container_conf_Request *grequest, - struct lcrd_container_conf_request **request); - - int container_conf_response_to_grpc(const struct lcrd_container_conf_response *response, - Container_conf_Response *gresponse); - int container_rename_request_from_grpc(const RenameRequest *grequest, struct lcrd_container_rename_request **request); int container_rename_response_to_grpc(const struct lcrd_container_rename_response *response, RenameResponse *gresponse); + int container_resize_request_from_grpc(const ResizeRequest *grequest, + struct lcrd_container_resize_request **request); + + int container_resize_response_to_grpc(const struct lcrd_container_resize_response *response, + ResizeResponse *gresponse); + int update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request); int update_response_to_grpc(const container_update_response *response, UpdateResponse *gresponse); diff --git a/src/connect/service/grpc/grpc_containers_service_private.cc b/src/connect/service/grpc/grpc_containers_service_private.cc index 4454a84..a573f7b 100644 --- a/src/connect/service/grpc/grpc_containers_service_private.cc +++ b/src/connect/service/grpc/grpc_containers_service_private.cc @@ -352,6 +352,10 @@ int ContainerServiceImpl::exec_request_from_grpc(const ExecRequest *grequest, co tmpreq->container_id = util_strdup_s(grequest->container_id().c_str()); } + if (!grequest->suffix().empty()) { + tmpreq->suffix = util_strdup_s(grequest->suffix().c_str()); + } + tmpreq->tty = grequest->tty(); tmpreq->attach_stdin = grequest->attach_stdin(); tmpreq->attach_stdout = grequest->attach_stdout(); @@ -607,26 +611,30 @@ int ContainerServiceImpl::resume_request_from_grpc(const ResumeRequest *grequest return 0; } -int ContainerServiceImpl::container_conf_request_from_grpc(const Container_conf_Request *grequest, - struct lcrd_container_conf_request **request) +int ContainerServiceImpl::container_rename_request_from_grpc(const RenameRequest *grequest, + struct lcrd_container_rename_request **request) { - struct lcrd_container_conf_request *tmpreq = (struct lcrd_container_conf_request *)util_common_calloc_s( - sizeof(struct lcrd_container_conf_request)); + struct lcrd_container_rename_request *tmpreq = (struct lcrd_container_rename_request *)util_common_calloc_s( + sizeof(struct lcrd_container_rename_request)); if (tmpreq == nullptr) { ERROR("Out of memory"); return -1; } - if (!grequest->container_id().empty()) { - tmpreq->name = util_strdup_s(grequest->container_id().c_str()); + if (!grequest->oldname().empty()) { + tmpreq->old_name = util_strdup_s(grequest->oldname().c_str()); + } + + if (!grequest->newname().empty()) { + tmpreq->new_name = util_strdup_s(grequest->newname().c_str()); } *request = tmpreq; return 0; } -int ContainerServiceImpl::container_conf_response_to_grpc(const struct lcrd_container_conf_response *response, - Container_conf_Response *gresponse) +int ContainerServiceImpl::container_rename_response_to_grpc(const struct lcrd_container_rename_response *response, + RenameResponse *gresponse) { if (response == nullptr) { gresponse->set_cc(LCRD_ERR_MEMOUT); @@ -637,40 +645,41 @@ int ContainerServiceImpl::container_conf_response_to_grpc(const struct lcrd_cont if (response->errmsg != nullptr) { gresponse->set_errmsg(response->errmsg); } - if (response->container_logpath != nullptr) { - gresponse->set_container_logpath(response->container_logpath); - } - gresponse->set_container_logrotate(response->container_logrotate); - if (response->container_logsize != nullptr) { - gresponse->set_container_logsize(response->container_logsize); + if (response->id != nullptr) { + gresponse->set_id(response->id); } + return 0; } -int ContainerServiceImpl::container_rename_request_from_grpc(const RenameRequest *grequest, - struct lcrd_container_rename_request **request) +int ContainerServiceImpl::container_resize_request_from_grpc(const ResizeRequest *grequest, + struct lcrd_container_resize_request **request) { - struct lcrd_container_rename_request *tmpreq = (struct lcrd_container_rename_request *)util_common_calloc_s( - sizeof(struct lcrd_container_rename_request)); + struct lcrd_container_resize_request *tmpreq = (struct lcrd_container_resize_request *)util_common_calloc_s( + sizeof(struct lcrd_container_resize_request)); if (tmpreq == nullptr) { ERROR("Out of memory"); return -1; } - if (!grequest->oldname().empty()) { - tmpreq->old_name = util_strdup_s(grequest->oldname().c_str()); + if (!grequest->id().empty()) { + tmpreq->id = util_strdup_s(grequest->id().c_str()); } - if (!grequest->newname().empty()) { - tmpreq->new_name = util_strdup_s(grequest->newname().c_str()); + if (!grequest->suffix().empty()) { + tmpreq->suffix = util_strdup_s(grequest->suffix().c_str()); } + tmpreq->height = grequest->height(); + + tmpreq->width = grequest->width(); + *request = tmpreq; return 0; } -int ContainerServiceImpl::container_rename_response_to_grpc(const struct lcrd_container_rename_response *response, - RenameResponse *gresponse) +int ContainerServiceImpl::container_resize_response_to_grpc(const struct lcrd_container_resize_response *response, + ResizeResponse *gresponse) { if (response == nullptr) { gresponse->set_cc(LCRD_ERR_MEMOUT); @@ -688,7 +697,6 @@ int ContainerServiceImpl::container_rename_response_to_grpc(const struct lcrd_co return 0; } - int ContainerServiceImpl::update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request) { container_update_request *tmpreq = (container_update_request *)util_common_calloc_s( @@ -735,10 +743,6 @@ int ContainerServiceImpl::stats_request_from_grpc(const StatsRequest *grequest, return -1; } - if (!grequest->runtime().empty()) { - tmpreq->runtime = util_strdup_s(grequest->runtime().c_str()); - } - if (grequest->containers_size() > 0) { tmpreq->containers = (char **)util_common_calloc_s(grequest->containers_size() * sizeof(char *)); if (tmpreq->containers == nullptr) { @@ -771,12 +775,6 @@ int ContainerServiceImpl::stats_response_to_grpc(const container_stats_response if (response->container_stats[i]->id != nullptr) { stats->set_id(response->container_stats[i]->id); } - if (response->container_stats[i]->has_pid) { - stats->set_pid(response->container_stats[i]->pid); - } else { - stats->set_pid(-1); - } - stats->set_status((ContainerStatus)response->container_stats[i]->status); stats->set_pids_current(response->container_stats[i]->pids_current); stats->set_cpu_use_nanos(response->container_stats[i]->cpu_use_nanos); stats->set_cpu_system_use(response->container_stats[i]->cpu_system_use); diff --git a/src/connect/service/rest/rest_containers_service.c b/src/connect/service/rest/rest_containers_service.c index d392094..30ac093 100644 --- a/src/connect/service/rest/rest_containers_service.c +++ b/src/connect/service/rest/rest_containers_service.c @@ -150,20 +150,6 @@ static int list_request_check(void *req) return ret; } -/* container conf response check */ -static int container_conf_request_check(void *req) -{ - int ret = 0; - struct lcrd_container_conf_request *req_conf = (struct lcrd_container_conf_request *)req; - if (req_conf->name == NULL) { - DEBUG("container name error"); - ret = -1; - goto out; - } - -out: - return ret; -} /* create request check */ static int create_request_check(void *req) { @@ -297,11 +283,6 @@ static struct rest_handle_st g_rest_handle[] = { .request_parse_data = (void *)container_wait_request_parse_data, .request_check = wait_request_check, }, - { - .name = ContainerServiceConf, - .request_parse_data = (void *)container_conf_request_parse_data, - .request_check = container_conf_request_check, - }, { .name = ContainerServiceInspect, .request_parse_data = (void *)container_inspect_request_parse_data, @@ -411,50 +392,6 @@ out: return; } -/* evhtp send container conf repsponse */ -static void evhtp_send_container_conf_repsponse(evhtp_request_t *req, container_conf_response *response, int rescode) -{ - parser_error err = NULL; - struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; - char *responsedata = NULL; - - responsedata = container_conf_response_generate_json(response, &ctx, &err); - if (responsedata == NULL) { - ERROR("Failed to generate container_conf request json:%s", err); - evhtp_send_reply(req, EVHTP_RES_ERROR); - goto out; - } - - evhtp_send_response(req, responsedata, rescode); - -out: - free(err); - free(responsedata); - return; -} - -/* container conf response to rest */ -static int container_conf_response_to_rest(container_conf_response *cresponse, - struct lcrd_container_conf_response *response) -{ - if (response == NULL) { - cresponse->cc = LCRD_ERR_MEMOUT; - return 0; - } - cresponse->cc = response->cc; - if (response->errmsg) { - cresponse->errmsg = util_strdup_s(response->errmsg); - } - if (response->container_logpath) { - cresponse->container_logpath = util_strdup_s(response->container_logpath); - } - cresponse->container_logrotate = response->container_logrotate; - if (response->container_logsize) { - cresponse->container_logsize = util_strdup_s(response->container_logsize); - } - return 0; -} - /* evhtp send wait repsponse */ static void evhtp_send_wait_repsponse(evhtp_request_t *req, container_wait_response *response, int rescode) { @@ -547,58 +484,6 @@ out: free_container_start_response(cresponse); } -/* rest container conf cb */ -static void rest_container_conf_cb(evhtp_request_t *req, void *arg) -{ - int ret, tret; - service_callback_t *cb = NULL; - struct lcrd_container_conf_request *lcrdreq = NULL; - struct lcrd_container_conf_response *lcrdres = NULL; - container_conf_response *cresponse = NULL; - - // only deal with POST request - if (evhtp_request_get_method(req) != htp_method_POST) { - evhtp_send_reply(req, EVHTP_RES_NOTIMPL); - return; - } - cb = get_service_callback(); - if (cb == NULL || cb->container.conf == NULL) { - ERROR("Unimplemented callback"); - evhtp_send_reply(req, EVHTP_RES_NOTIMPL); - return; - } - - cresponse = util_common_calloc_s(sizeof(container_conf_response)); - if (cresponse == NULL) { - evhtp_send_reply(req, EVHTP_RES_ERROR); - return; - } - - tret = action_request_from_rest(req, (void **)&lcrdreq, ContainerServiceConf); - if (tret < 0) { - ERROR("Bad request"); - cresponse->cc = LCRD_ERR_EXEC; - evhtp_send_container_conf_repsponse(req, cresponse, EVHTP_RES_SERVERR); - goto out; - } - - ret = cb->container.conf(lcrdreq, &lcrdres); - - tret = container_conf_response_to_rest(cresponse, lcrdres); - if (tret) { - ERROR("Failed to translate response to rest,operation is %s", ret ? "failed" : "success"); - cresponse->cc = LCRD_ERR_EXEC; - if (cresponse->errmsg == NULL) { - cresponse->errmsg = util_strdup_s(errno_to_error_message(LCRD_ERR_INTERNAL)); - } - } - evhtp_send_container_conf_repsponse(req, cresponse, EVHTP_RES_OK); -out: - lcrd_container_conf_request_free(lcrdreq); - lcrd_container_conf_response_free(lcrdres); - free_container_conf_response(cresponse); -} - /* rest wait cb */ static void rest_wait_cb(evhtp_request_t *req, void *arg) { @@ -1213,11 +1098,6 @@ int rest_register_containers_handler(evhtp_t *htp) return -1; } - if (evhtp_set_cb(htp, ContainerServiceConf, rest_container_conf_cb, NULL) == NULL) { - ERROR("Failed to register container_conf callback"); - return -1; - } - if (evhtp_set_cb(htp, ContainerServiceWait, rest_wait_cb, NULL) == NULL) { ERROR("Failed to register wait callback"); return -1; diff --git a/src/cutils/utils.c b/src/cutils/utils.c index d2c50bc..1e30aaf 100644 --- a/src/cutils/utils.c +++ b/src/cutils/utils.c @@ -1424,4 +1424,54 @@ void usleep_nointerupt(unsigned long usec) request = remain; } while (ret == -1 && errno == EINTR); } +int util_generate_random_str(char *id, size_t len) +{ + int fd = -1; + int num = 0; + size_t i; + const int m = 256; + + len = len / 2; + fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + ERROR("Failed to open /dev/urandom"); + return -1; + } + for (i = 0; i < len; i++) { + int nret; + if (read(fd, &num, sizeof(int)) < 0) { + ERROR("Failed to read urandom value"); + close(fd); + return -1; + } + unsigned char rs = (unsigned char)(num % m); + nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs); + if (nret < 0 || (size_t)nret >= ((len - i) * 2 + 1)) { + ERROR("Failed to snprintf random string"); + close(fd); + return -1; + } + } + close(fd); + id[i * 2] = '\0'; + return 0; +} + +void add_array_elem(char **array, size_t total, size_t *pos, const char *elem) +{ + if (*pos + 1 >= total - 1) { + return; + } + array[*pos] = util_strdup_s(elem); + *pos += 1; +} + +void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v) +{ + if (k == NULL || v == NULL) { + return; + } + add_array_elem(array, total, pos, k); + add_array_elem(array, total, pos, v); +} diff --git a/src/cutils/utils.h b/src/cutils/utils.h index 66e737c..ea594a0 100644 --- a/src/cutils/utils.h +++ b/src/cutils/utils.h @@ -57,6 +57,8 @@ extern "C" { #define ECOMMON 1 +#define PARAM_NUM 100 + /* image error start */ #define EIMAGEBUSY 2 #define ENAMECONFLICT 3 @@ -90,6 +92,8 @@ extern "C" { /* container id max length */ #define CONTAINER_ID_MAX_LEN 64 +#define CONTAINER_EXEC_ID_MAX_LEN 64 + #define LIST_SIZE_MAX 1000LL #define LIST_DEVICE_SIZE_MAX 10000LL #define LIST_ENV_SIZE_MAX 200000LL @@ -418,6 +422,12 @@ bool util_check_signal_valid(int sig); void usleep_nointerupt(unsigned long usec); +int util_generate_random_str(char *id, size_t len); + +void add_array_elem(char **array, size_t total, size_t *pos, const char *elem); + +void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v); + #ifdef __cplusplus } #endif diff --git a/src/cutils/utils_regex.c b/src/cutils/utils_regex.c index 68ac587..420f939 100644 --- a/src/cutils/utils_regex.c +++ b/src/cutils/utils_regex.c @@ -95,15 +95,15 @@ int util_wildcard_to_regex(const char *wildcard, char **regex) size_t index = 0; size_t regex_size; char escapes[] = { '$', '^', '[', ']', '(', ')', '{', '|', '+', '\\', '.', '<', '>', '}' }; - if (wildcard == NULL) { - return 0; - } + if (wildcard == NULL || regex == NULL) { + ERROR("Invalid output parameter"); + return -1; + } if (get_regex_size_from_wildcard(wildcard, escapes, sizeof(escapes) / sizeof(char), ®ex_size) != 0) { return -1; } - - *regex = malloc(regex_size); + *regex = (char *)util_common_calloc_s(regex_size); if (*regex == NULL) { ERROR("Out of memory"); return -1; diff --git a/src/cutils/utils_verify.c b/src/cutils/utils_verify.c index ccd7eb1..562a942 100644 --- a/src/cutils/utils_verify.c +++ b/src/cutils/utils_verify.c @@ -622,3 +622,14 @@ cleanup: return bret; } +bool util_valid_exec_suffix(const char *suffix) +{ + char *patten = "^[a-f0-9]{64}$"; + + if (suffix == NULL) { + ERROR("invalid NULL param"); + return false; + } + + return util_reg_match(patten, suffix) == 0; +} diff --git a/src/cutils/utils_verify.h b/src/cutils/utils_verify.h index 148f413..443fe5c 100644 --- a/src/cutils/utils_verify.h +++ b/src/cutils/utils_verify.h @@ -96,6 +96,8 @@ bool util_valid_runtime_name(const char *name); bool util_valid_short_sha256_id(const char *id); +bool util_valid_exec_suffix(const char *suffix); + #ifdef __cplusplus } #endif diff --git a/src/engines/engine.h b/src/engines/engine.h index c57f05d..f50545f 100644 --- a/src/engines/engine.h +++ b/src/engines/engine.h @@ -23,12 +23,6 @@ extern "C" { #endif -struct engine_console_config { - char *log_path; - unsigned int log_rotate; - char *log_file_size; -}; - struct engine_cgroup_resources { uint64_t blkio_weight; uint64_t cpu_shares; @@ -66,11 +60,13 @@ struct engine_container_summary_info { char *finishat; }; -struct engine_container_info { - char *id; +struct engine_container_status_info { bool has_pid; uint32_t pid; Engine_Container_Status status; +}; + +struct engine_container_resources_stats_info { uint64_t pids_current; /* CPU usage */ uint64_t cpu_use_nanos; @@ -131,6 +127,8 @@ typedef struct _engine_exec_request_t { size_t args_len; int64_t timeout; + + const char *suffix; } engine_exec_request_t; @@ -149,33 +147,25 @@ typedef bool (*engine_resume_t)(const char *name, const char *enginepath); typedef bool (*engine_reset_t)(const char *name, const char *enginepath); +typedef bool (*engine_resize_t)(const char *name, const char *lcrpath, unsigned int height, unsigned int width); +typedef bool (*engine_exec_resize_t)(const char *name, const char *lcrpath, const char *suffix, unsigned int height, + unsigned int width); + typedef bool (*engine_update_t)(const char *name, const char *enginepath, const struct engine_cgroup_resources *cr); typedef bool (*engine_exec_t)(const engine_exec_request_t *request, int *exit_code); -typedef int (*engine_get_all_containers_info_t)(const char *enginepath, struct engine_container_summary_info **cons); - -typedef struct engine_container_summary_info *(*engine_get_container_info_t)(const char *name, const char *enginepath); - -typedef void (*engine_free_container_info_t)(struct engine_container_summary_info *info); - -typedef void (*engine_free_all_containers_info_t)(struct engine_container_summary_info *info, int num); - typedef int (*engine_get_container_status_t)(const char *name, const char *enginepath, - struct engine_container_info *status); + struct engine_container_status_info *status); -typedef void (*engine_free_container_status_t)(struct engine_container_info *container); +typedef int (*engine_get_container_resources_stats_t)(const char *name, const char *enginepath, + struct engine_container_resources_stats_info *rs_stats); typedef bool (*engine_get_container_pids_t)(const char *name, const char *rootpath, pid_t **pids, size_t *pids_len); typedef bool (*engine_console_t)(const char *name, const char *enginepath, char *in_fifo, char *out_fifo, char *err_fifo); -typedef bool (*engine_get_console_config_t)(const char *name, const char *enginepath, - struct engine_console_config *config); - -typedef void (*engine_free_console_config_t)(struct engine_console_config *config); - typedef int (*engine_log_init_t)(const char *name, const char *file, const char *priority, const char *prefix, int quiet, const char *enginepath); @@ -193,17 +183,15 @@ struct engine_operation { engine_pause_t engine_pause_op; engine_resume_t engine_resume_op; engine_reset_t engine_reset_op; + engine_resize_t engine_resize_op; + engine_exec_resize_t engine_exec_resize_op; engine_exec_t engine_exec_op; engine_console_t engine_console_op; engine_get_container_status_t engine_get_container_status_op; - engine_free_container_status_t engine_free_container_status_op; - engine_get_all_containers_info_t engine_get_all_containers_info_op; - engine_free_all_containers_info_t engine_free_all_containers_info_op; + engine_get_container_resources_stats_t engine_get_container_resources_stats_op; engine_get_container_pids_t engine_get_container_pids_op; engine_log_init_t engine_log_init_op; engine_update_t engine_update_op; - engine_get_console_config_t engine_get_console_config_op; - engine_free_console_config_t engine_free_console_config_op; engine_get_errmsg_t engine_get_errmsg_op; engine_clear_errmsg_t engine_clear_errmsg_op; engine_clean_t engine_clean_op; diff --git a/src/engines/lcr/lcr_engine.c b/src/engines/lcr/lcr_engine.c index 083ec31..922a016 100644 --- a/src/engines/lcr/lcr_engine.c +++ b/src/engines/lcr/lcr_engine.c @@ -27,23 +27,15 @@ #include "log.h" #include "lcrd_config.h" -typedef int(*lcr_list_all_containers_t)(const char *lcrpath, struct lcr_container_info **info_arr); -typedef void(*lcr_containers_info_free_t)(struct lcr_container_info **info_arr, size_t size); typedef bool(*lcr_state_op_t)(const char *name, const char *lcrpath, struct lcr_container_state *lcs); typedef void(*lcr_container_state_free_t)(struct lcr_container_state *lcs); typedef bool(*lcr_update_op_t)(const char *name, const char *lcrpath, struct lcr_cgroup_resources *cr); -typedef bool(*lcr_get_console_config_op_t)(const char *name, const char *lcrpath, struct lcr_console_config *config); -typedef void(*lcr_free_console_config_op_t)(struct lcr_console_config *config); typedef bool(*lcr_start_op_t)(struct lcr_start_request *request); typedef bool(*lcr_exec_op_t)(const struct lcr_exec_request *request, int *exit_code); -static lcr_list_all_containers_t g_lcr_list_all_containers_op = NULL; -static lcr_containers_info_free_t g_lcr_containers_info_free_op = NULL; static lcr_state_op_t g_lcr_state_op = NULL; static lcr_container_state_free_t g_lcr_container_state_free_op = NULL; static lcr_update_op_t g_lcr_update_op = NULL; -static lcr_get_console_config_op_t g_lcr_get_console_config_op = NULL; -static lcr_free_console_config_op_t g_lcr_free_console_config_op = NULL; static lcr_start_op_t g_lcr_start_op = NULL; static lcr_exec_op_t g_lcr_exec_op = NULL; /* @@ -120,199 +112,59 @@ static bool lcr_exec_container(const engine_exec_request_t *request, int *exit_c return g_lcr_exec_op(lcr_request, exit_code); } -/* free console config */ -void free_console_config(struct engine_console_config *config) -{ - if (config == NULL) { - return; - } - free(config->log_path); - config->log_path = NULL; - - free(config->log_file_size); - config->log_file_size = NULL; - - config->log_rotate = 0; -} - -/* get console config */ -bool get_console_config(const char *name, const char *lcrpath, struct engine_console_config *config) -{ - struct lcr_console_config lcr_config; - bool ret = false; - - if (name == NULL || config == NULL) { - ERROR("Invalid arguments"); - return ret; - } - - (void)memset(&lcr_config, 0, sizeof(struct lcr_console_config)); - - if (g_lcr_get_console_config_op != NULL) { - ret = g_lcr_get_console_config_op(name, lcrpath, &lcr_config); - } - - if (ret) { - if (lcr_config.log_path) { - config->log_path = util_strdup_s(lcr_config.log_path); - } else { - config->log_path = NULL; - } - config->log_rotate = lcr_config.log_rotate; - if (lcr_config.log_file_size) { - config->log_file_size = util_strdup_s(lcr_config.log_file_size); - } else { - config->log_file_size = NULL; - } - - if (g_lcr_free_console_config_op != NULL) { - g_lcr_free_console_config_op(&lcr_config); - } - } - - return ret; -} - -/* - * Get the containers info by liblcr - */ -static void get_containers_info(int num, const struct lcr_container_info *info_arr, - struct engine_container_summary_info *info) -{ - int i = 0; - const struct lcr_container_info *in = NULL; - char *name = NULL; - - for (i = 0, in = info_arr; i < num; i++, in++) { - name = in->name; - if (name == NULL) { - continue; - } - - info[i].id = util_strdup_s(name); - info[i].has_pid = (-1 == in->init) ? false : true; - info[i].pid = (uint32_t)in->init; - info[i].status = lcrsta2sta(in->state); - } -} - /* * Get the state of container from 'lcr_container_state' */ -static void copy_container_status(const struct lcr_container_state *lcs, struct engine_container_info *status) +static void copy_container_status(const struct lcr_container_state *lcs, struct engine_container_status_info *status) { - const char *defvalue = "-"; - const char *name = NULL; - - (void)memset(status, 0, sizeof(struct engine_container_info)); - - name = lcs->name ? lcs->name : defvalue; - status->id = util_strdup_s(name); + (void)memset(status, 0, sizeof(struct engine_container_status_info)); status->has_pid = (-1 == lcs->init) ? false : true; status->pid = (uint32_t)lcs->init; status->status = lcrsta2sta(lcs->state); - - status->pids_current = lcs->pids_current; - - status->cpu_use_nanos = lcs->cpu_use_nanos; - - status->blkio_read = lcs->io_service_bytes.read; - status->blkio_write = lcs->io_service_bytes.write; - - status->mem_used = lcs->mem_used; - status->mem_limit = lcs->mem_limit; - status->kmem_used = lcs->kmem_used; - status->kmem_limit = lcs->kmem_limit; } -/* - * Alloc Memory for containerArray and container - */ -static int service_list_alloc(int num, struct engine_container_summary_info **cons) +/* get container status */ +static int get_container_status(const char *name, const char *enginepath, struct engine_container_status_info *status) { - if (num <= 0 || cons == NULL) { - return -1; - } + struct lcr_container_state lcs = { 0 }; - if ((size_t)num > SIZE_MAX / sizeof(struct engine_container_summary_info)) { - ERROR("Too many engine container summaries!"); + if (g_lcr_state_op == NULL || g_lcr_container_state_free_op == NULL) { + ERROR("Not supported op"); return -1; } - *cons = util_common_calloc_s((size_t)num * sizeof(struct engine_container_summary_info)); - if ((*cons) == NULL) { - ERROR("Out of memory"); + + if (!g_lcr_state_op(name, enginepath, &lcs)) { + DEBUG("Failed to state for container '%s'", name); + g_lcr_container_state_free_op(&lcs); return -1; } - + copy_container_status(&lcs, status); + g_lcr_container_state_free_op(&lcs); return 0; } -/* - * Free the container** containerArray - */ -static void free_all_containers_info(struct engine_container_summary_info *info, int num) +static void copy_container_resources_stats(const struct lcr_container_state *lcs, + struct engine_container_resources_stats_info *rs_stats) { - int i = 0; - - if (num <= 0 || info == NULL) { - return; - } - for (i = 0; i < num; i++) { - free(info[i].id); - info[i].id = NULL; - free(info[i].command); - info[i].command = NULL; - free(info[i].image); - info[i].image = NULL; - free(info[i].finishat); - info[i].finishat = NULL; - free(info[i].startat); - info[i].startat = NULL; - } - free(info); -} - -/* get all containers info */ -static int get_all_containers_info(const char *enginepath, struct engine_container_summary_info **cons) -{ - struct lcr_container_info *info_arr = NULL; - int num = 0; - - if (cons == NULL) { - ERROR("Invalid argument"); - return -1; - } + (void)memset(rs_stats, 0, sizeof(struct engine_container_resources_stats_info)); + rs_stats->pids_current = lcs->pids_current; - if (g_lcr_list_all_containers_op == NULL || g_lcr_containers_info_free_op == NULL) { - ERROR("Not supported op"); - num = -1; - goto free_out; - } - - num = g_lcr_list_all_containers_op(enginepath, &info_arr); - if (num <= 0) { - num = 0; /* set to 0 if non were found */ - goto free_out; - } - - if (service_list_alloc(num, cons)) { - g_lcr_containers_info_free_op(&info_arr, (size_t)num); - ERROR("service list alloc failed"); - num = -1; - goto free_out; - } + rs_stats->cpu_use_nanos = lcs->cpu_use_nanos; - get_containers_info(num, info_arr, *cons); - g_lcr_containers_info_free_op(&info_arr, (size_t)num); + rs_stats->blkio_read = lcs->io_service_bytes.read; + rs_stats->blkio_write = lcs->io_service_bytes.write; -free_out: - return num; + rs_stats->mem_used = lcs->mem_used; + rs_stats->mem_limit = lcs->mem_limit; + rs_stats->kmem_used = lcs->kmem_used; + rs_stats->kmem_limit = lcs->kmem_limit; } -/* get container status */ -static int get_container_status(const char *name, const char *enginepath, struct engine_container_info *status) +/* get container cgroup resources */ +static int lcr_get_container_resources_stats(const char *name, const char *enginepath, + struct engine_container_resources_stats_info *rs_stats) { struct lcr_container_state lcs = { 0 }; @@ -326,28 +178,11 @@ static int get_container_status(const char *name, const char *enginepath, struct g_lcr_container_state_free_op(&lcs); return -1; } - copy_container_status(&lcs, status); + copy_container_resources_stats(&lcs, rs_stats); g_lcr_container_state_free_op(&lcs); return 0; } -/* free container status */ -static void free_container_status(struct engine_container_info *status) -{ - if (status == NULL) { - return; - } - - free(status->id); - status->id = NULL; -} - -#define CHECK_ERROR(P) do { \ - if (dlerror() != NULL) { \ - goto badcleanup; \ - } \ - } while (0) - static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop) { eop->engine_create_op = dlsym(lcr_handler, "lcr_create"); @@ -386,6 +221,14 @@ static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop) if (dlerror() != NULL) { return false; } + eop->engine_resize_op = dlsym(lcr_handler, "lcr_resize"); + if (dlerror() != NULL) { + return false; + } + eop->engine_exec_resize_op = dlsym(lcr_handler, "lcr_exec_resize"); + if (dlerror() != NULL) { + return false; + } return true; } @@ -403,22 +246,6 @@ static bool load_lcr_info_ops(void *lcr_handler, struct engine_operation *eop) if (dlerror() != NULL) { return false; } - g_lcr_get_console_config_op = dlsym(lcr_handler, "lcr_get_console_config"); - if (dlerror() != NULL) { - return false; - } - g_lcr_free_console_config_op = dlsym(lcr_handler, "lcr_free_console_config"); - if (dlerror() != NULL) { - return false; - } - g_lcr_list_all_containers_op = dlsym(lcr_handler, "lcr_list_all_containers"); - if (dlerror() != NULL) { - return false; - } - g_lcr_containers_info_free_op = dlsym(lcr_handler, "lcr_containers_info_free"); - if (dlerror() != NULL) { - return false; - } g_lcr_state_op = dlsym(lcr_handler, "lcr_state"); if (dlerror() != NULL) { return false; @@ -464,16 +291,11 @@ struct engine_operation *lcr_engine_init() ERROR("Load lcr info operations failed"); goto badcleanup; } - - eop->engine_get_all_containers_info_op = get_all_containers_info; - eop->engine_free_all_containers_info_op = free_all_containers_info; eop->engine_get_container_status_op = get_container_status; - eop->engine_free_container_status_op = free_container_status; + eop->engine_get_container_resources_stats_op = lcr_get_container_resources_stats; eop->engine_update_op = lcr_update_container; eop->engine_start_op = lcr_start_container; eop->engine_exec_op = lcr_exec_container; - eop->engine_get_console_config_op = get_console_config; - eop->engine_free_console_config_op = free_console_config; goto cleanup; diff --git a/src/image/oci/global_config.h b/src/image/oci/global_config.h index 50b64a1..4420224 100644 --- a/src/image/oci/global_config.h +++ b/src/image/oci/global_config.h @@ -21,8 +21,6 @@ extern "C" { #endif -#define PARAM_NUM 100 - enum { GB_OPTION_GRAPH_ROOT = 0, GB_OPTION_RUN_ROOT, @@ -37,25 +35,6 @@ enum { GB_OPTION_MAX, // should not be used }; - -static inline void add_array_elem(char **array, size_t total, size_t *pos, const char *elem) -{ - if (*pos + 1 >= total - 1) { - return; - } - array[*pos] = util_strdup_s(elem); - *pos += 1; -} - -static inline void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v) -{ - if (k == NULL || v == NULL) { - return; - } - add_array_elem(array, total, pos, k); - add_array_elem(array, total, pos, v); -} - int pack_global_options(const char * const *options, char *params[], size_t *count, bool ignore_storage_opt_size); #ifdef __cplusplus diff --git a/src/image/oci/isula_image.c b/src/image/oci/isula_image.c index fa902af..f231f5d 100644 --- a/src/image/oci/isula_image.c +++ b/src/image/oci/isula_image.c @@ -61,11 +61,15 @@ void isula_exit(void) static int start_isula_image_server(void) { - struct server_monitor_conf sm_conf = {0}; +#define MIN_OPT_TIMEOUT 15 + struct server_monitor_conf sm_conf = { 0 }; struct timespec ts = { 0 }; sem_t wait_monitor_sem; + unsigned int im_opt_timeout = conf_get_im_opt_timeout(); int ret = 0; + im_opt_timeout = im_opt_timeout >= MIN_OPT_TIMEOUT ? im_opt_timeout : MIN_OPT_TIMEOUT; + // check whether isula_kit is running by systemd if (util_file_exists(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) { if (!conf_update_im_server_sock_addr(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) { @@ -93,7 +97,7 @@ static int start_isula_image_server(void) ret = -1; goto out; } - ts.tv_sec += 15; // set deadline 15s + ts.tv_sec += (time_t)im_opt_timeout; // set deadline ret = sem_timedwait(&wait_monitor_sem, &ts); if (ret != 0) { diff --git a/src/image/oci/run_image_server.c b/src/image/oci/run_image_server.c index 41afa1f..01945ca 100644 --- a/src/image/oci/run_image_server.c +++ b/src/image/oci/run_image_server.c @@ -245,10 +245,42 @@ static void *heartbeat_for_isulad_kit(void *arg) return NULL; } +static unsigned long get_timeout_secs(bool retry) +{ + unsigned long result = RETRY_COUNT_MAX; + + if (retry) { + return result; + } + + result = conf_get_im_opt_timeout(); + if (result < RETRY_COUNT_MAX) { + result = RETRY_COUNT_MAX; + } + + return result; +} + +static bool is_timeout(unsigned long max_second, unsigned long retry_cnt) +{ + unsigned long total = retry_cnt; + + if (total >= ULONG_MAX / (total + 1)) { + return true; + } + total = total * (total + 1) / 2; + // time unit is second, retry time is 0.1s + if (total >= max_second * 10) { + return true; + } + return false; +} + static int isula_image_server_load_first_check(const struct server_monitor_conf *conf, bool retry) { int ret = 0; - unsigned long retry_cnt = 1; + unsigned long retry_cnt = 0; + unsigned long opt_timeout = get_timeout_secs(retry); /* parent: check server is running */ while (true) { @@ -257,13 +289,13 @@ static int isula_image_server_load_first_check(const struct server_monitor_conf if (ret == 0) { break; } - retry_cnt++; - if (retry_cnt > RETRY_COUNT_MAX) { + if (is_timeout(opt_timeout, retry_cnt)) { // don't post sem to main thread ERROR("First load image server failed"); ret = -1; goto out; } + retry_cnt++; } /* 1. If health check success, send a mutex to main thread and make it run again; diff --git a/src/json/schema/schema/container/exec-request.json b/src/json/schema/schema/container/exec-request.json index 233c6f0..1482b55 100644 --- a/src/json/schema/schema/container/exec-request.json +++ b/src/json/schema/schema/container/exec-request.json @@ -5,6 +5,9 @@ "container_id": { "type": "string" }, + "suffix": { + "type": "string" + }, "tty": { "type": "boolean" }, diff --git a/src/liblcrc.c b/src/liblcrc.c index 12ec385..9c32de7 100644 --- a/src/liblcrc.c +++ b/src/liblcrc.c @@ -648,6 +648,9 @@ void lcrc_exec_request_free(struct lcrc_exec_request *request) free(request->name); request->name = NULL; + free(request->suffix); + request->suffix = NULL; + free(request->stdout); request->stdout = NULL; @@ -778,38 +781,6 @@ void lcrc_resume_response_free(struct lcrc_resume_response *response) free(response); } -/* lcrc container conf request free */ -void lcrc_container_conf_request_free(struct lcrc_container_conf_request *req) -{ - if (req == NULL) { - return; - } - - free(req->name); - req->name = NULL; - - free(req); -} - -/* lcrc container conf response free */ -void lcrc_container_conf_response_free(struct lcrc_container_conf_response *resp) -{ - if (resp == NULL) { - return; - } - - free(resp->errmsg); - resp->errmsg = NULL; - - free(resp->container_logpath); - resp->container_logpath = NULL; - - free(resp->container_logsize); - resp->container_logsize = NULL; - - free(resp); -} - /* lcrc kill request free */ void lcrc_kill_request_free(struct lcrc_kill_request *request) { @@ -882,12 +853,20 @@ void lcrc_update_response_free(struct lcrc_update_response *response) /* lcrc stats request free */ void lcrc_stats_request_free(struct lcrc_stats_request *request) { + size_t i = 0; + if (request == NULL) { return; } - free(request->runtime); - request->runtime = NULL; + for (i = 0; i < request->containers_len; i++) { + free(request->containers[i]); + request->containers[i] = NULL; + } + + free(request->containers); + request->containers = NULL; + free(request); } @@ -902,8 +881,8 @@ void lcrc_stats_response_free(struct lcrc_stats_response *response) response->errmsg = NULL; if (response->container_stats != NULL && response->container_num) { - int i; - for (i = 0; i < (int)response->container_num; i++) { + size_t i; + for (i = 0; i < response->container_num; i++) { free(response->container_stats[i].id); response->container_stats[i].id = NULL; } @@ -1348,6 +1327,36 @@ void lcrc_rename_response_free(struct lcrc_rename_response *response) free(response); } +/* lcrc resize request free */ +void lcrc_resize_request_free(struct lcrc_resize_request *request) +{ + if (request == NULL) { + return; + } + + free(request->id); + request->id = NULL; + + free(request->suffix); + request->suffix = NULL; + + free(request); +} + +/* lcrc resize response free */ +void lcrc_resize_response_free(struct lcrc_resize_response *response) +{ + if (response == NULL) { + return; + } + + free(response->errmsg); + response->errmsg = NULL; + + free(response); +} + + /* lcrc logs request free */ void lcrc_logs_request_free(struct lcrc_logs_request *request) { diff --git a/src/liblcrc.h b/src/liblcrc.h index 2b4dbf6..423f7fc 100644 --- a/src/liblcrc.h +++ b/src/liblcrc.h @@ -296,9 +296,6 @@ struct lcrc_resume_response { struct lcrc_container_info { char *id; - bool has_pid; - uint32_t pid; - Container_Status status; uint64_t pids_current; // CPU usage uint64_t cpu_use_nanos; @@ -359,7 +356,6 @@ struct lcrc_list_response { }; struct lcrc_stats_request { - char *runtime; char **containers; size_t containers_len; bool all; @@ -449,6 +445,7 @@ struct lcrc_wait_response { struct lcrc_exec_request { char *name; + char *suffix; bool tty; bool open_stdin; bool attach_stdin; @@ -542,19 +539,6 @@ struct lcrc_info_response { char *errmsg; }; -struct lcrc_container_conf_request { - char *name; -}; - -struct lcrc_container_conf_response { - uint32_t cc; - uint32_t server_errono; - char *container_logpath; - uint32_t container_logrotate; - char *container_logsize; - char *errmsg; -}; - typedef struct lcrc_update_config { char *restart_policy; container_cgroup_resources_t *cr; @@ -688,6 +672,19 @@ struct lcrc_rename_response { char *errmsg; }; +struct lcrc_resize_request { + char *id; + char *suffix; + uint32_t height; + uint32_t width; +}; + +struct lcrc_resize_response { + uint32_t cc; + uint32_t server_errono; + char *errmsg; +}; + Container_Status lcrcstastr2sta(const char *state); struct lcrc_filters *lcrc_filters_parse_args(const char **array, size_t len); @@ -758,10 +755,6 @@ void lcrc_resume_request_free(struct lcrc_resume_request *request); void lcrc_resume_response_free(struct lcrc_resume_response *response); -void lcrc_container_conf_request_free(struct lcrc_container_conf_request *req); - -void lcrc_container_conf_response_free(struct lcrc_container_conf_response *resp); - void lcrc_kill_request_free(struct lcrc_kill_request *request); void lcrc_kill_response_free(struct lcrc_kill_response *response); @@ -833,6 +826,10 @@ void lcrc_rename_request_free(struct lcrc_rename_request *request); void lcrc_rename_response_free(struct lcrc_rename_response *response); +void lcrc_resize_request_free(struct lcrc_resize_request *request); + +void lcrc_resize_response_free(struct lcrc_resize_response *response); + void lcrc_logs_request_free(struct lcrc_logs_request *request); void lcrc_logs_response_free(struct lcrc_logs_response *response); diff --git a/src/liblcrd.c b/src/liblcrd.c index 83aa7f6..2fdb820 100644 --- a/src/liblcrd.c +++ b/src/liblcrd.c @@ -26,36 +26,6 @@ // record the errno __thread char *g_lcrd_errmsg = NULL; -/* lcrd container conf request free */ -void lcrd_container_conf_request_free(struct lcrd_container_conf_request *request) -{ - if (request == NULL) { - return; - } - free(request->name); - request->name = NULL; - - free(request); -} - -/* lcrd container conf response free */ -void lcrd_container_conf_response_free(struct lcrd_container_conf_response *response) -{ - if (response == NULL) { - return; - } - free(response->errmsg); - response->errmsg = NULL; - - free(response->container_logpath); - response->container_logpath = NULL; - - free(response->container_logsize); - response->container_logsize = NULL; - - free(response); -} - /* lcrd events request free */ void lcrd_events_request_free(struct lcrd_events_request *request) { @@ -193,6 +163,38 @@ void lcrd_container_rename_response_free(struct lcrd_container_rename_response * free(response); } +/* lcrd container rename request free */ +void lcrd_container_resize_request_free(struct lcrd_container_resize_request *request) +{ + if (request == NULL) { + return; + } + + free(request->id); + request->id = NULL; + + free(request->suffix); + request->suffix = NULL; + + free(request); +} + +/* lcrd container rename response free */ +void lcrd_container_resize_response_free(struct lcrd_container_resize_response *response) +{ + if (response == NULL) { + return; + } + + free(response->id); + response->id = NULL; + free(response->errmsg); + response->errmsg = NULL; + + free(response); +} + + void lcrd_logs_request_free(struct lcrd_logs_request *request) { if (request == NULL) { diff --git a/src/liblcrd.h b/src/liblcrd.h index 7b47532..9e31e5f 100644 --- a/src/liblcrd.h +++ b/src/liblcrd.h @@ -243,25 +243,25 @@ struct lcrd_health_check_response { char *errmsg; }; -struct lcrd_container_conf_request { - char *name; +struct lcrd_container_rename_request { + char *old_name; + char *new_name; }; -struct lcrd_container_conf_response { +struct lcrd_container_rename_response { + char *id; uint32_t cc; - uint32_t server_errono; - char *container_logpath; - uint32_t container_logrotate; - char *container_logsize; char *errmsg; }; -struct lcrd_container_rename_request { - char *old_name; - char *new_name; +struct lcrd_container_resize_request { + char *id; + char *suffix; + uint32_t height; + uint32_t width; }; -struct lcrd_container_rename_response { +struct lcrd_container_resize_response { char *id; uint32_t cc; char *errmsg; @@ -295,10 +295,6 @@ struct container_log_config { }; void container_log_config_free(struct container_log_config *conf); -void lcrd_container_conf_request_free(struct lcrd_container_conf_request *request); - -void lcrd_container_conf_response_free(struct lcrd_container_conf_response *response); - void lcrd_events_request_free(struct lcrd_events_request *request); void lcrd_copy_from_container_request_free(struct lcrd_copy_from_container_request *request); @@ -315,6 +311,10 @@ void lcrd_container_rename_request_free(struct lcrd_container_rename_request *re void lcrd_container_rename_response_free(struct lcrd_container_rename_response *response); +void lcrd_container_resize_request_free(struct lcrd_container_resize_request *request); + +void lcrd_container_resize_response_free(struct lcrd_container_resize_response *response); + void lcrd_logs_request_free(struct lcrd_logs_request *request); void lcrd_logs_response_free(struct lcrd_logs_response *response); #ifdef __cplusplus diff --git a/src/runtime/lcr/lcr_rt_ops.c b/src/runtime/lcr/lcr_rt_ops.c index dee1d41..e66a8ae 100644 --- a/src/runtime/lcr/lcr_rt_ops.c +++ b/src/runtime/lcr/lcr_rt_ops.c @@ -62,12 +62,14 @@ int rt_lcr_create(const char *name, const char *runtime, const rt_create_params_ lcrd_set_error_message("Create container error: %s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR); - engine_ops->engine_clear_errmsg_op(); ret = -1; goto out; } out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } free(runtime_root); return ret; } @@ -138,7 +140,6 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t : DEF_ERR_RUNTIME_STR); ERROR("Start container error: %s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR); - engine_ops->engine_clear_errmsg_op(); ret = -1; goto out; } @@ -149,6 +150,9 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t goto out; } out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } return ret; } @@ -247,29 +251,27 @@ out: return ret; } -int rt_lcr_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params) +int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params, + struct engine_container_status_info *status) { int ret = 0; + int nret = 0; struct engine_operation *engine_ops = NULL; engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || (engine_ops->engine_get_console_config_op) == NULL) { - ERROR("Failed to get engine get_console_config operation"); + if (engine_ops == NULL || engine_ops->engine_get_container_status_op == NULL) { + ERROR("Failed to get engine status operations"); ret = -1; goto out; } - if (!engine_ops->engine_get_console_config_op(name, params->rootpath, params->config)) { - ERROR("Failed to get console config"); - const char *tmpmsg = NULL; - tmpmsg = engine_ops->engine_get_errmsg_op(); - lcrd_set_error_message("Get console config error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? - tmpmsg : DEF_ERR_RUNTIME_STR); + nret = engine_ops->engine_get_container_status_op(name, params->rootpath, status); + if (nret != 0) { + engine_ops->engine_clear_errmsg_op(); ret = -1; goto out; } - out: if (engine_ops != NULL) { engine_ops->engine_clear_errmsg_op(); @@ -277,21 +279,21 @@ out: return ret; } -int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params, - struct engine_container_info *status) +int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params, + struct engine_container_resources_stats_info *rs_stats) { int ret = 0; int nret = 0; struct engine_operation *engine_ops = NULL; engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || engine_ops->engine_get_container_status_op == NULL) { - ERROR("Failed to get engine status operations"); + if (engine_ops == NULL || engine_ops->engine_get_container_resources_stats_op == NULL) { + ERROR("Failed to get engine stats operations"); ret = -1; goto out; } - nret = engine_ops->engine_get_container_status_op(name, params->rootpath, status); + nret = engine_ops->engine_get_container_resources_stats_op(name, params->rootpath, rs_stats); if (nret != 0) { engine_ops->engine_clear_errmsg_op(); ret = -1; @@ -299,9 +301,11 @@ int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_ } out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } return ret; } - int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code) { int ret = 0; @@ -326,6 +330,7 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par request.console_fifos = params->console_fifos; request.timeout = params->timeout; request.user = params->user; + request.suffix = params->suffix; if (!engine_ops->engine_exec_op(&request, exit_code)) { const char *tmpmsg = NULL; @@ -339,6 +344,9 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par } out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } return ret; } @@ -360,11 +368,13 @@ int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t tmpmsg = engine_ops->engine_get_errmsg_op(); lcrd_set_error_message("Pause container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR); - engine_ops->engine_clear_errmsg_op(); ret = -1; goto out; } out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } return ret; } @@ -387,11 +397,177 @@ int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_ lcrd_set_error_message("Resume container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR); + ret = -1; + goto out; + } +out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } + return ret; +} + +int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_t *params) +{ + int ret = 0; + struct engine_operation *engine_ops = NULL; + + engine_ops = engines_get_handler(runtime); + if (engine_ops == NULL || engine_ops->engine_console_op == NULL) { + DEBUG("Failed to get engine attach operations"); + ret = -1; + goto out; + } + if (!engine_ops->engine_console_op(name, params->rootpath, (char *)params->stdin, (char *)params->stdout, + (char *)params->stderr)) { + ERROR("attach failed"); + const char *tmpmsg = NULL; + tmpmsg = engine_ops->engine_get_errmsg_op(); + lcrd_set_error_message("Attach container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? + tmpmsg : DEF_ERR_RUNTIME_STR); + ret = -1; + goto out; + } +out: + if (engine_ops != NULL) { engine_ops->engine_clear_errmsg_op(); + } + return ret; +} + +static void to_engine_resources(const host_config *hostconfig, struct engine_cgroup_resources *cr) +{ + if (hostconfig == NULL || cr == NULL) { + return; + } + + cr->blkio_weight = hostconfig->blkio_weight; + cr->cpu_shares = (uint64_t)hostconfig->cpu_shares; + cr->cpu_period = (uint64_t)hostconfig->cpu_period; + cr->cpu_quota = (uint64_t)hostconfig->cpu_quota; + cr->cpuset_cpus = hostconfig->cpuset_cpus; + cr->cpuset_mems = hostconfig->cpuset_mems; + cr->memory_limit = (uint64_t)hostconfig->memory; + cr->memory_swap = (uint64_t)hostconfig->memory_swap; + cr->memory_reservation = (uint64_t)hostconfig->memory_reservation; + cr->kernel_memory_limit = (uint64_t)hostconfig->kernel_memory; +} + +int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t *params) +{ + int ret = 0; + struct engine_operation *engine_ops = NULL; + struct engine_cgroup_resources cr = { 0 }; + + engine_ops = engines_get_handler(runtime); + if (engine_ops == NULL || engine_ops->engine_update_op == NULL) { + DEBUG("Failed to get engine update operations"); + ret = -1; + goto out; + } + + to_engine_resources(params->hostconfig, &cr); + + if (!engine_ops->engine_update_op(id, params->rootpath, &cr)) { + DEBUG("Update container %s failed", id); + const char *tmpmsg = NULL; + tmpmsg = engine_ops->engine_get_errmsg_op(); + lcrd_set_error_message("Cannot update container %s: %s", id, (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? + tmpmsg : DEF_ERR_RUNTIME_STR); ret = -1; goto out; } out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } + return ret; +} + +int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out) +{ + int ret = 0; + struct engine_operation *engine_ops = NULL; + + engine_ops = engines_get_handler(runtime); + if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) { + DEBUG("Failed to get engine top operations"); + ret = -1; + goto out; + } + + if (!engine_ops->engine_get_container_pids_op(name, params->rootpath, &(out->pids), &(out->pids_len))) { + DEBUG("Top container %s failed", name); + const char *tmpmsg = NULL; + tmpmsg = engine_ops->engine_get_errmsg_op(); + lcrd_set_error_message("Runtime top container error: %s", + (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR); + ret = -1; + goto out; + } +out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } + return ret; +} + +int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t *params) +{ + int ret = 0; + struct engine_operation *engine_ops = NULL; + + engine_ops = engines_get_handler(runtime); + if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) { + DEBUG("Failed to get engine resume operations"); + ret = -1; + goto out; + } + + if (!engine_ops->engine_resize_op(id, params->rootpath, params->height, params->width)) { + DEBUG("resize container %s failed", id); + const char *tmpmsg = NULL; + tmpmsg = engine_ops->engine_get_errmsg_op(); + lcrd_set_error_message("Resize container error;%s", + (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg + : DEF_ERR_RUNTIME_STR); + + ret = -1; + goto out; + } +out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } + return ret; +} + +int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params) +{ + int ret = 0; + struct engine_operation *engine_ops = NULL; + + engine_ops = engines_get_handler(runtime); + if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) { + DEBUG("Failed to get engine resume operations"); + ret = -1; + goto out; + } + + if (!engine_ops->engine_exec_resize_op(id, params->rootpath, params->suffix, params->height, params->width)) { + DEBUG("exec resize container %s failed", id); + const char *tmpmsg = NULL; + tmpmsg = engine_ops->engine_get_errmsg_op(); + lcrd_set_error_message("Resize container error;%s", + (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg + : DEF_ERR_RUNTIME_STR); + ret = -1; + goto out; + } +out: + if (engine_ops != NULL) { + engine_ops->engine_clear_errmsg_op(); + } return ret; } diff --git a/src/runtime/lcr/lcr_rt_ops.h b/src/runtime/lcr/lcr_rt_ops.h index a75f8d5..4cf29ef 100644 --- a/src/runtime/lcr/lcr_rt_ops.h +++ b/src/runtime/lcr/lcr_rt_ops.h @@ -28,13 +28,21 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t int rt_lcr_restart(const char *name, const char *runtime, const rt_restart_params_t *params); int rt_lcr_clean_resource(const char *name, const char *runtime, const rt_clean_params_t *params); int rt_lcr_rm(const char *name, const char *runtime, const rt_rm_params_t *params); -int rt_lcr_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params); int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params, - struct engine_container_info *status); + struct engine_container_status_info *status); int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code); int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t *params); int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_t *params); +int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_t *params); + +int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t *params); + +int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out); +int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params, + struct engine_container_resources_stats_info *rs_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); #ifdef __cplusplus } #endif diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index acea344..e9906de 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -33,11 +33,16 @@ static const struct rt_ops g_lcr_rt_ops = { .rt_restart = rt_lcr_restart, .rt_clean_resource = rt_lcr_clean_resource, .rt_rm = rt_lcr_rm, - .rt_get_console_config = rt_lcr_get_console_config, .rt_status = rt_lcr_status, .rt_exec = rt_lcr_exec, .rt_pause = rt_lcr_pause, .rt_resume = rt_lcr_resume, + .rt_attach = rt_lcr_attach, + .rt_update = rt_lcr_update, + .rt_listpids = rt_lcr_listpids, + .rt_resources_stats = rt_lcr_resources_stats, + .rt_resize = rt_lcr_resize, + .rt_exec_resize = rt_lcr_exec_resize, }; static const struct rt_ops *g_rt_ops[] = { @@ -184,13 +189,14 @@ out: return ret; } -int runtime_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params) +int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params, + struct engine_container_status_info *status) { int ret = 0; const struct rt_ops *ops = NULL; - if (name == NULL || runtime == NULL) { - ERROR("Invalide arguments for runtime get console config"); + if (name == NULL || runtime == NULL || status == NULL) { + ERROR("Invalide arguments for runtime status"); ret = -1; goto out; } @@ -202,20 +208,20 @@ int runtime_get_console_config(const char *name, const char *runtime, const rt_g goto out; } - ret = ops->rt_get_console_config(name, runtime, params); + ret = ops->rt_status(name, runtime, params, status); out: return ret; } -int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params, - struct engine_container_info *status) +int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params, + struct engine_container_resources_stats_info *rs_stats) { int ret = 0; const struct rt_ops *ops = NULL; - if (name == NULL || runtime == NULL || status == NULL) { - ERROR("Invalide arguments for runtime start"); + if (name == NULL || runtime == NULL || rs_stats == NULL) { + ERROR("Invalide arguments for runtime stats"); ret = -1; goto out; } @@ -227,7 +233,7 @@ int runtime_status(const char *name, const char *runtime, const rt_status_params goto out; } - ret = ops->rt_status(name, runtime, params, status); + ret = ops->rt_resources_stats(name, runtime, params, rs_stats); out: return ret; @@ -305,3 +311,134 @@ int runtime_resume(const char *name, const char *runtime, const rt_resume_params out: return ret; } + +int runtime_attach(const char *name, const char *runtime, const rt_attach_params_t *params) +{ + int ret = 0; + const struct rt_ops *ops = NULL; + + if (name == NULL || runtime == NULL || params == NULL) { + ERROR("Invalide arguments for runtime attach"); + ret = -1; + goto out; + } + + ops = rt_ops_query(runtime); + if (ops == NULL) { + ERROR("Failed to get runtime ops"); + ret = -1; + goto out; + } + + ret = ops->rt_attach(name, runtime, params); + +out: + return ret; +} + +int runtime_update(const char *name, const char *runtime, const rt_update_params_t *params) +{ + int ret = 0; + const struct rt_ops *ops = NULL; + + if (name == NULL || runtime == NULL || params == NULL) { + ERROR("Invalide arguments for runtime update"); + ret = -1; + goto out; + } + + ops = rt_ops_query(runtime); + if (ops == NULL) { + ERROR("Failed to get runtime ops"); + ret = -1; + goto out; + } + + ret = ops->rt_update(name, runtime, params); + +out: + return ret; +} + +void free_rt_listpids_out_t(rt_listpids_out_t *out) +{ + if (out == NULL) { + return; + } + + free(out->pids); + out->pids = NULL; + free(out); +} + +int runtime_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out) +{ + int ret = 0; + const struct rt_ops *ops = NULL; + + if (name == NULL || runtime == NULL || params == NULL || out == NULL) { + ERROR("Invalide arguments for runtime listpids"); + ret = -1; + goto out; + } + + ops = rt_ops_query(runtime); + if (ops == NULL) { + ERROR("Failed to get runtime ops"); + ret = -1; + goto out; + } + + ret = ops->rt_listpids(name, runtime, params, out); + +out: + return ret; +} + +int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params) +{ + int ret = 0; + const struct rt_ops *ops = NULL; + + if (name == NULL || runtime == NULL || params == NULL) { + ERROR("Invalide arguments for runtime resize"); + ret = -1; + goto out; + } + + ops = rt_ops_query(runtime); + if (ops == NULL) { + ERROR("Failed to get runtime ops"); + ret = -1; + goto out; + } + + ret = ops->rt_resize(name, runtime, params); + +out: + return ret; +} + +int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_resize_params_t *params) +{ + int ret = 0; + const struct rt_ops *ops = NULL; + + if (name == NULL || runtime == NULL || params == NULL) { + ERROR("Invalide arguments for runtime exec resize"); + ret = -1; + goto out; + } + + ops = rt_ops_query(runtime); + if (ops == NULL) { + ERROR("Failed to get runtime ops"); + ret = -1; + goto out; + } + + ret = ops->rt_exec_resize(name, runtime, params); + +out: + return ret; +} diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index a63e1aa..5eb0a81 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -73,15 +73,14 @@ typedef struct _rt_rm_params_t { const char *rootpath; } rt_rm_params_t; -typedef struct _rt_get_console_conf_params_t { - const char *rootpath; - struct engine_console_config *config; -} rt_get_console_conf_params_t; - typedef struct _rt_status_params_t { const char *rootpath; } rt_status_params_t; +typedef struct _rt_stats_params_t { + const char *rootpath; +} rt_stats_params_t; + typedef struct _rt_exec_params_t { const char *rootpath; const char *logpath; @@ -93,6 +92,7 @@ typedef struct _rt_exec_params_t { size_t args_len; const char * const *envs; size_t envs_len; + const char *suffix; } rt_exec_params_t; typedef struct _rt_pause_params_t { @@ -103,6 +103,40 @@ typedef struct _rt_resume_params_t { const char *rootpath; } rt_resume_params_t; +typedef struct _rt_attach_params_t { + const char *rootpath; + const char *stdin; + const char *stdout; + const char *stderr; +} rt_attach_params_t; + +typedef struct _rt_update_params_t { + const char *rootpath; + const host_config *hostconfig; +} rt_update_params_t; + +typedef struct _rt_listpids_params_t { + const char *rootpath; +} rt_listpids_params_t; + +typedef struct _rt_listpids_out_t { + pid_t *pids; + size_t pids_len; +} rt_listpids_out_t; + +typedef struct _rt_resize_params_t { + const char *rootpath; + unsigned int height; + unsigned int width; +} rt_resize_params_t; + +typedef struct _rt_exec_resize_params_t { + const char *rootpath; + const char *suffix; + unsigned int height; + unsigned int width; +} rt_exec_resize_params_t; + struct rt_ops { /* detect whether runtime is of this runtime type */ bool (*detect)(const char *runtime); @@ -118,16 +152,26 @@ struct rt_ops { int (*rt_rm)(const char *name, const char *runtime, const rt_rm_params_t *params); - int (*rt_get_console_config)(const char *name, const char *runtime, const rt_get_console_conf_params_t *params); - int (*rt_status)(const char *name, const char *runtime, const rt_status_params_t *params, - struct engine_container_info *status); + struct engine_container_status_info *status); + + int (*rt_resources_stats)(const char *name, const char *runtime, const rt_stats_params_t *params, + struct engine_container_resources_stats_info *rs_stats); int (*rt_exec)(const char *name, const char *runtime, const rt_exec_params_t *params, int *exit_code); int (*rt_pause)(const char *name, const char *runtime, const rt_pause_params_t *params); int (*rt_resume)(const char *name, const char *runtime, const rt_resume_params_t *params); + + int (*rt_attach)(const char *name, const char *runtime, const rt_attach_params_t *params); + + int (*rt_update)(const char *name, const char *runtime, const rt_update_params_t *params); + + int (*rt_listpids)(const char *name, const char *runtime, const rt_listpids_params_t *params, + 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 runtime_create(const char *name, const char *runtime, const rt_create_params_t *params); @@ -135,14 +179,22 @@ int runtime_clean_resource(const char *name, const char *runtime, const rt_clean int runtime_start(const char *name, const char *runtime, const rt_start_params_t *params, container_pid_t *pid_info); int runtime_restart(const char *name, const char *runtime, const rt_restart_params_t *params); int runtime_rm(const char *name, const char *runtime, const rt_rm_params_t *params); -int runtime_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params); int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params, - struct engine_container_info *status); + struct engine_container_status_info *status); +int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params, + struct engine_container_resources_stats_info *rs_stats); int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params, int *exit_code); int runtime_pause(const char *name, const char *runtime, const rt_pause_params_t *params); int runtime_resume(const char *name, const char *runtime, const rt_resume_params_t *params); +int runtime_attach(const char *name, const char *runtime, const rt_attach_params_t *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); +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); #ifdef __cplusplus } #endif diff --git a/src/services/callback.h b/src/services/callback.h index 350a2d1..129ecba 100644 --- a/src/services/callback.h +++ b/src/services/callback.h @@ -123,8 +123,6 @@ typedef struct { int(*inspect)(const container_inspect_request *request, container_inspect_response **response); - int(*conf)(const struct lcrd_container_conf_request *request, struct lcrd_container_conf_response **response); - int(*wait)(const container_wait_request *request, container_wait_response **response); int(*events)(const struct lcrd_events_request *request, const stream_func_wrapper *stream); @@ -140,6 +138,8 @@ typedef struct { int(*logs)(const struct lcrd_logs_request *request, stream_func_wrapper *stream, struct lcrd_logs_response **response); + + int(*resize)(const struct lcrd_container_resize_request *request, struct lcrd_container_resize_response **response); } service_container_callback_t; typedef struct { diff --git a/src/services/cri/cri_container.cc b/src/services/cri/cri_container.cc index 73b2fea..3f6cc22 100644 --- a/src/services/cri/cri_container.cc +++ b/src/services/cri/cri_container.cc @@ -811,14 +811,74 @@ cleanup: free_container_list_response(response); } +void CRIRuntimeServiceImpl::PackContainerStatsAttributes( + const char *id, + std::unique_ptr &container, + Errors &error) +{ + if (id == nullptr) { + return; + } + + container->mutable_attributes()->set_id(id); + auto status = ContainerStatus(std::string(id), error); + if (status->has_metadata()) { + std::unique_ptr metadata( + new (std::nothrow) runtime::v1alpha2::ContainerMetadata(status->metadata())); + if (metadata == nullptr) { + error.SetError("Out of memory"); + ERROR("Out of memory"); + return; + } + container->mutable_attributes()->set_allocated_metadata(metadata.release()); + } + if (status->labels_size() > 0) { + auto labels = container->mutable_attributes()->mutable_labels(); + *labels = status->labels(); + } + if (status->annotations_size() > 0) { + auto annotations = container->mutable_attributes()->mutable_annotations(); + *annotations = status->annotations(); + } +} + +void CRIRuntimeServiceImpl::PackContainerStatsFilesystemUsage( + const char *id, const char *image_type, + std::unique_ptr &container, + Errors &error) +{ + if (id == nullptr || image_type == nullptr) { + return; + } + + imagetool_fs_info *fs_usage { nullptr }; + if (im_get_container_filesystem_usage(image_type, id, &fs_usage) != 0) { + ERROR("Failed to get container filesystem usage"); + } + + if (fs_usage == nullptr) { + container->mutable_writable_layer()->mutable_used_bytes()->set_value(0); + container->mutable_writable_layer()->mutable_inodes_used()->set_value(0); + } else { + if (fs_usage->image_filesystems[0]->used_bytes->value) { + container->mutable_writable_layer()->mutable_used_bytes()->set_value( + fs_usage->image_filesystems[0]->used_bytes->value); + } + + if (fs_usage->image_filesystems[0]->inodes_used->value) { + container->mutable_writable_layer()->mutable_inodes_used()->set_value( + fs_usage->image_filesystems[0]->inodes_used->value); + } + } + + free_imagetool_fs_info(fs_usage); +} + void CRIRuntimeServiceImpl::ContainerStatsToGRPC( container_stats_response *response, std::vector> *containerstats, Errors &error) { - int ret {}; - for (size_t i {}; i < response->container_stats_len; i++) { - imagetool_fs_info *fs_usage { nullptr }; using ContainerStatsPtr = std::unique_ptr; ContainerStatsPtr container(new (std::nothrow) runtime::v1alpha2::ContainerStats); if (container == nullptr) { @@ -826,14 +886,12 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC( return; } - if (response->container_stats[i]->id != nullptr && response->container_stats[i]->image_type != nullptr) { - container->mutable_attributes()->set_id(response->container_stats[i]->id); - ret = im_get_container_filesystem_usage(response->container_stats[i]->image_type, - response->container_stats[i]->id, &fs_usage); - if (ret != 0) { - ERROR("Failed to get container filesystem usage"); - } + PackContainerStatsAttributes(response->container_stats[i]->id, container, error); + if (error.NotEmpty()) { + return; } + PackContainerStatsFilesystemUsage(response->container_stats[i]->id, + response->container_stats[i]->image_type, container, error); if (response->container_stats[i]->mem_used) { container->mutable_memory()->mutable_working_set_bytes()->set_value(response->container_stats[i]->mem_used); @@ -845,23 +903,7 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC( container->mutable_cpu()->set_timestamp((int64_t)(response->container_stats[i]->cpu_system_use)); } - if (fs_usage == nullptr) { - container->mutable_writable_layer()->mutable_used_bytes()->set_value(0); - container->mutable_writable_layer()->mutable_inodes_used()->set_value(0); - } - if (fs_usage != nullptr) { - if (fs_usage->image_filesystems[0]->used_bytes->value) { - container->mutable_writable_layer()->mutable_used_bytes()->set_value( - fs_usage->image_filesystems[0]->used_bytes->value); - } - - if (fs_usage->image_filesystems[0]->inodes_used->value) { - container->mutable_writable_layer()->mutable_inodes_used()->set_value( - fs_usage->image_filesystems[0]->inodes_used->value); - } - } containerstats->push_back(move(container)); - free_imagetool_fs_info(fs_usage); } } diff --git a/src/services/cri/cri_runtime_service.h b/src/services/cri/cri_runtime_service.h index ab00a0d..df0a8f9 100644 --- a/src/services/cri/cri_runtime_service.h +++ b/src/services/cri/cri_runtime_service.h @@ -143,6 +143,13 @@ private: void ListContainersToGRPC(container_list_response *response, std::vector> *pods, Errors &error); + void PackContainerStatsAttributes(const char *id, std::unique_ptr &container, + Errors &error); + + void PackContainerStatsFilesystemUsage(const char *id, const char *image_type, + std::unique_ptr &container, + Errors &error); + void ContainerStatsToGRPC(container_stats_response *response, std::vector> *pods, Errors &error); diff --git a/src/services/cri/cri_security_context.cc b/src/services/cri/cri_security_context.cc index d03c383..2ac79eb 100644 --- a/src/services/cri/cri_security_context.cc +++ b/src/services/cri/cri_security_context.cc @@ -174,9 +174,10 @@ static void ModifyHostNetworkOptionForSandbox(const runtime::v1alpha2::Namespace static void ModifyContainerNamespaceOptions(const runtime::v1alpha2::NamespaceOption &nsOpts, const std::string &podSandboxID, host_config *hostConfig, Errors &error) { + std::string sandboxNSMode = "container:" + podSandboxID; if (nsOpts.pid() == runtime::v1alpha2::NamespaceMode::POD) { free(hostConfig->pid_mode); - hostConfig->pid_mode = util_strdup_s(""); + hostConfig->pid_mode = util_strdup_s(sandboxNSMode.c_str()); } /* set common Namespace options */ diff --git a/src/services/execution/execute/execution_create.c b/src/services/execution/execute/execution_create.c index 312a41c..8cce2ad 100644 --- a/src/services/execution/execute/execution_create.c +++ b/src/services/execution/execute/execution_create.c @@ -212,39 +212,6 @@ error_out: return NULL; } - -static int generateID(char *id, size_t len) -{ - int fd = -1; - int num = 0; - size_t i; - const int m = 256; - - len = len / 2; - fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) { - ERROR("Failed to open /dev/urandom"); - return -1; - } - for (i = 0; i < len; i++) { - int nret; - if (read(fd, &num, sizeof(int)) < 0) { - ERROR("Failed to read urandom value"); - close(fd); - return -1; - } - unsigned char rs = (unsigned char)(num % m); - nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs); - if (nret >= ((len - i) * 2 + 1) || nret < 0) { - close(fd); - return -1; - } - } - close(fd); - id[i * 2] = '\0'; - return 0; -} - static oci_runtime_spec *merge_config(const char *id, const char *image_type, const char *image_name, const char *ext_config_image, host_config *host_spec, container_custom_config *custom_spec, @@ -311,7 +278,7 @@ static char *try_generate_id() } for (i = 0; i < max_time; i++) { - if (generateID(id, (size_t)CONTAINER_ID_MAX_LEN)) { + if (util_generate_random_str(id, (size_t)CONTAINER_ID_MAX_LEN)) { ERROR("Generate id failed"); goto err_out; } diff --git a/src/services/execution/execute/execution_extend.c b/src/services/execution/execute/execution_extend.c index 8d24dcd..be8ea29 100644 --- a/src/services/execution/execute/execution_extend.c +++ b/src/services/execution/execute/execution_extend.c @@ -213,7 +213,8 @@ static int copy_map_labels(const container_config *config, map_t **map_labels) return 0; } -static container_info *get_container_stats(const container_t *cont, const struct engine_container_info *einfo, +static container_info *get_container_stats(const container_t *cont, + const struct engine_container_resources_stats_info *einfo, const struct stats_context *ctx) { int ret = 0; @@ -229,9 +230,6 @@ static container_info *get_container_stats(const container_t *cont, const struct } info->id = util_strdup_s(cont->common_config->id); - info->has_pid = einfo->has_pid; - info->pid = (int32_t)einfo->pid; - info->status = (int)einfo->status; info->pids_current = einfo->pids_current; info->cpu_use_nanos = einfo->cpu_use_nanos; info->blkio_read = einfo->blkio_read; @@ -395,29 +393,12 @@ cleanup: return ret; } -static int get_containers_stats(const char *runtime, char **idsarray, size_t ids_len, const struct stats_context *ctx, +static int get_containers_stats(char **idsarray, size_t ids_len, const struct stats_context *ctx, bool check_exists, container_info ***info, size_t *info_len) { int ret = 0; int nret; size_t i; - char *engine_path = NULL; - struct engine_operation *engine_ops = NULL; - - engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || engine_ops->engine_get_container_status_op == NULL || - engine_ops->engine_free_container_status_op == NULL) { - ERROR("Failed to get engine stats operations"); - ret = -1; - goto cleanup; - } - - engine_path = conf_get_routine_rootdir(runtime); - if (engine_path == NULL) { - ERROR("Get engine path failed"); - ret = -1; - goto cleanup; - } nret = service_stats_make_memory(info, ids_len); if (nret != 0) { @@ -426,7 +407,7 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids } for (i = 0; i < ids_len; i++) { - struct engine_container_info einfo = { 0 }; + struct engine_container_resources_stats_info einfo = { 0 }; container_t *cont = NULL; cont = containers_store_get(idsarray[i]); @@ -440,9 +421,11 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids continue; } if (is_running(cont->state)) { - nret = engine_ops->engine_get_container_status_op(cont->common_config->id, engine_path, &einfo); + rt_stats_params_t params = { 0 }; + params.rootpath = cont->root_path; + + nret = runtime_resources_stats(cont->common_config->id, cont->runtime, ¶ms, &einfo); if (nret != 0) { - engine_ops->engine_clear_errmsg_op(); container_unref(cont); continue; } @@ -455,14 +438,12 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids (*info)[*info_len] = get_container_stats(cont, &einfo, ctx); container_unref(cont); - engine_ops->engine_free_container_status_op(&einfo); if ((*info)[*info_len] == NULL) { continue; } (*info_len)++; } cleanup: - free(engine_path); return ret; } @@ -490,12 +471,6 @@ static int container_stats_cb(const container_stats_request *request, goto pack_response; } - if (request->runtime == NULL) { - ERROR("Receive NULL Request runtime"); - cc = LCRD_ERR_INPUT; - goto pack_response; - } - ctx = fold_stats_filter(request); if (ctx == NULL) { cc = LCRD_ERR_EXEC; @@ -510,7 +485,7 @@ static int container_stats_cb(const container_stats_request *request, goto pack_response; } - if (get_containers_stats(request->runtime, idsarray, ids_len, ctx, check_exists, &info, &info_len)) { + if (get_containers_stats(idsarray, ids_len, ctx, check_exists, &info, &info_len)) { cc = LCRD_ERR_EXEC; goto pack_response; } @@ -553,6 +528,7 @@ static int resume_container(container_t *cont) } state_reset_paused(cont->state); + update_health_monitor(cont->common_config->id); if (container_to_disk(cont)) { @@ -739,6 +715,7 @@ static int pause_container(container_t *cont) } state_set_paused(cont->state); + update_health_monitor(cont->common_config->id); if (container_to_disk(cont)) { @@ -840,24 +817,6 @@ pack_response: return (cc == LCRD_SUCCESS) ? 0 : -1; } -static void to_engine_resources(const host_config *hostconfig, struct engine_cgroup_resources *cr) -{ - if (hostconfig == NULL || cr == NULL) { - return; - } - - cr->blkio_weight = hostconfig->blkio_weight; - cr->cpu_shares = (uint64_t)hostconfig->cpu_shares; - cr->cpu_period = (uint64_t)hostconfig->cpu_period; - cr->cpu_quota = (uint64_t)hostconfig->cpu_quota; - cr->cpuset_cpus = hostconfig->cpuset_cpus; - cr->cpuset_mems = hostconfig->cpuset_mems; - cr->memory_limit = (uint64_t)hostconfig->memory; - cr->memory_swap = (uint64_t)hostconfig->memory_swap; - cr->memory_reservation = (uint64_t)hostconfig->memory_reservation; - cr->kernel_memory_limit = (uint64_t)hostconfig->kernel_memory; -} - static void host_config_restore_unlocking(container_t *cont, host_config *backup_hostconfig) { free_host_config(cont->hostconfig); @@ -1034,32 +993,6 @@ out: return ret; } -static int runtime_update(const char *id, const char *runtime, const char *rootpath, struct engine_cgroup_resources *cr) -{ - int ret = 0; - struct engine_operation *engine_ops = NULL; - - engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || engine_ops->engine_update_op == NULL) { - DEBUG("Failed to get engine update operations"); - ret = -1; - goto out; - } - - if (!engine_ops->engine_update_op(id, rootpath, cr)) { - DEBUG("Update container %s failed", id); - const char *tmpmsg = NULL; - tmpmsg = engine_ops->engine_get_errmsg_op(); - lcrd_set_error_message("Cannot update container %s: %s", id, (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? - tmpmsg : DEF_ERR_RUNTIME_STR); - engine_ops->engine_clear_errmsg_op(); - ret = -1; - goto out; - } -out: - return ret; -} - static int do_update_resources(const container_update_request *request, container_t *cont) { int ret = 0; @@ -1067,7 +1000,7 @@ static int do_update_resources(const container_update_request *request, containe parser_error err = NULL; host_config *hostconfig = NULL; host_config *backup_hostconfig = NULL; - struct engine_cgroup_resources cr = { 0 }; + rt_update_params_t params = { 0 }; if (request->host_config == NULL) { DEBUG("receive NULL host config"); @@ -1111,10 +1044,10 @@ static int do_update_resources(const container_update_request *request, containe container_update_restart_manager(cont, hostconfig->restart_policy); } - to_engine_resources(hostconfig, &cr); - if (runtime_update(id, cont->runtime, cont->root_path, &cr)) { + params.rootpath = cont->root_path; + params.hostconfig = hostconfig; + if (runtime_update(id, cont->runtime, ¶ms)) { ERROR("Update container %s failed", id); - host_config_restore_unlocking(cont, backup_hostconfig); ret = -1; goto unlock_out; } @@ -1291,6 +1224,179 @@ pack_response: return (cc == LCRD_SUCCESS) ? 0 : -1; } +static int runtime_resize_helper(const char *id, const char *runtime, const char *rootpath, unsigned int height, + unsigned int width) +{ + int ret = 0; + rt_resize_params_t params = { 0 }; + + params.rootpath = rootpath; + params.height = height; + params.width = width; + + ret = runtime_resize(id, runtime, ¶ms); + if (ret != 0) { + ERROR("Failed to resize container %s", id); + } + + return ret; +} + +static int runtime_exec_resize_helper(const char *id, const char *runtime, const char *rootpath, const char *suffix, + unsigned int height, + unsigned int width) +{ + int ret = 0; + rt_exec_resize_params_t params = { 0 }; + + params.rootpath = rootpath; + params.suffix = suffix; + params.height = height; + params.width = width; + + ret = runtime_exec_resize(id, runtime, ¶ms); + if (ret != 0) { + ERROR("Failed to resize container %s", id); + } + + return ret; +} + +static int resize_container(container_t *cont, const char *suffix, unsigned int height, unsigned int width) +{ + int ret = 0; + const char *id = cont->common_config->id; + + container_lock(cont); + + if (!is_running(cont->state)) { + ERROR("Container %s is not running", id); + lcrd_set_error_message("Container %s is not running", id); + ret = -1; + goto out; + } + + if (suffix != NULL) { + DEBUG("Failed to resize container:%s suffix:%s", id, suffix); + if (runtime_exec_resize_helper(id, cont->runtime, cont->root_path, suffix, height, width)) { + ERROR("Failed to resize container:%s", id); + ret = -1; + goto out; + } + } else { + if (runtime_resize_helper(id, cont->runtime, cont->root_path, height, width)) { + ERROR("Failed to resize container:%s", id); + ret = -1; + goto out; + } + } + +out: + container_unlock(cont); + return ret; +} + +static void pack_resize_response(struct lcrd_container_resize_response *response, uint32_t cc, const char *id) +{ + if (response == NULL) { + return; + } + response->cc = cc; + if (id != NULL) { + response->id = util_strdup_s(id); + } + if (g_lcrd_errmsg != NULL) { + response->errmsg = util_strdup_s(g_lcrd_errmsg); + DAEMON_CLEAR_ERRMSG(); + } +} + +static int resize_request_check(const struct lcrd_container_resize_request *request) +{ + int ret = 0; + + char *name = request->id; + if (name == NULL) { + ERROR("Resume: receive NULL id"); + ret = -1; + goto out; + } + + if (!util_valid_container_id_or_name(name)) { + ERROR("Invalid container name %s", name); + lcrd_set_error_message("Invalid container name %s", name); + ret = -1; + goto out; + } + + if (request->suffix != NULL && !util_valid_exec_suffix(request->suffix)) { + ERROR("Invalid suffix name %s", name); + lcrd_set_error_message("Invalid suffix name %s", name); + ret = -1; + goto out; + } + +out: + return ret; +} + +static int container_resize_cb(const struct lcrd_container_resize_request *request, + struct lcrd_container_resize_response **response) +{ + int ret = 0; + uint32_t cc = LCRD_SUCCESS; + char *name = NULL; + char *id = NULL; + container_t *cont = NULL; + + DAEMON_CLEAR_ERRMSG(); + if (request == NULL || response == NULL) { + ERROR("Invalid NULL input"); + return -1; + } + + *response = util_common_calloc_s(sizeof(struct lcrd_container_resize_response)); + if (*response == NULL) { + ERROR("Resume: Out of memory"); + cc = LCRD_ERR_MEMOUT; + goto pack_response; + } + + if (resize_request_check(request) != 0) { + cc = LCRD_ERR_INPUT; + goto pack_response; + } + + name = request->id; + + cont = containers_store_get(name); + if (cont == NULL) { + ERROR("No such container:%s", name); + lcrd_set_error_message("No such container:%s", name); + cc = LCRD_ERR_EXEC; + goto pack_response; + } + + id = cont->common_config->id; + set_log_prefix(id); + EVENT("Event: {Object: %s, Type: Resizing}", id); + + ret = resize_container(cont, request->suffix, request->height, request->width); + if (ret != 0) { + cc = LCRD_ERR_EXEC; + container_state_set_error(cont->state, (const char *)g_lcrd_errmsg); + goto pack_response; + } + + EVENT("Event: {Object: %s, Type: Resized}", id); + +pack_response: + pack_resize_response(*response, cc, id); + container_unref(cont); + free_log_prefix(); + return (cc == LCRD_SUCCESS) ? 0 : -1; +} + void container_extend_callback_init(service_container_callback_t *cb) { cb->update = container_update_cb; @@ -1299,5 +1405,6 @@ void container_extend_callback_init(service_container_callback_t *cb) cb->stats = container_stats_cb; cb->events = container_events_cb; cb->export_rootfs = container_export_cb; + cb->resize = container_resize_cb; } diff --git a/src/services/execution/execute/execution_information.c b/src/services/execution/execute/execution_information.c index 47d68e9..ab8c84c 100644 --- a/src/services/execution/execute/execution_information.c +++ b/src/services/execution/execute/execution_information.c @@ -456,7 +456,6 @@ out: static inline void add_ps_array_elem(char **array, size_t *pos, const char *elem) { -#define PARAM_NUM 100 if (*pos + 1 >= (PARAM_NUM - 1)) { return; } @@ -537,26 +536,48 @@ static int get_pids(const char *name, const char *runtime, const char *rootpath, char **pid_args) { int ret = 0; - struct engine_operation *engine_ops = NULL; + size_t i = 0; + rt_listpids_params_t params = { 0 }; + rt_listpids_out_t *out = NULL; + + out = util_common_calloc_s(sizeof(rt_listpids_out_t)); + if (out == NULL) { + ERROR("Memeory out"); + ret = -1; + goto out; + } + + params.rootpath = rootpath; - engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) { - DEBUG("Failed to get engine top operations"); + if (runtime_listpids(name, runtime, ¶ms, out) != 0) { + ERROR("runtime failed to list pids"); ret = -1; goto out; } - if (!engine_ops->engine_get_container_pids_op(name, rootpath, pids, pids_len)) { - DEBUG("Top container %s failed", name); - const char *tmpmsg = NULL; - tmpmsg = engine_ops->engine_get_errmsg_op(); - lcrd_set_error_message("Runtime top container error: %s", - (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR); + if (out->pids_len > SIZE_MAX / sizeof(pid_t)) { + ERROR("list too many pids"); ret = -1; goto out; } + if (out->pids_len != 0) { + pid_t *tmp = NULL; + tmp = util_common_calloc_s(sizeof(pid_t) * out->pids_len); + if (tmp == NULL) { + ERROR("Memory out"); + ret = -1; + goto out; + } + for (i = 0; i < out->pids_len; i++) { + tmp[i] = out->pids[i]; + } + *pids = tmp; + } + + *pids_len = out->pids_len; + *pid_args = ps_pids_arg(*pids, *pids_len); if (*pid_args == NULL) { ERROR("failed to get pid_args"); @@ -564,9 +585,7 @@ static int get_pids(const char *name, const char *runtime, const char *rootpath, goto out; } out: - if (engine_ops != NULL) { - engine_ops->engine_clear_errmsg_op(); - } + free_rt_listpids_out_t(out); return ret; } @@ -1467,113 +1486,6 @@ pack_response: return (cc == LCRD_SUCCESS) ? 0 : -1; } -static int container_conf_request_check(const struct lcrd_container_conf_request *h) -{ - int ret = 0; - - if (h->name == NULL) { - ERROR("Receive NULL container name"); - ret = -1; - goto out; - } - - if (!util_valid_container_id_or_name(h->name)) { - ERROR("Invalid container name %s", h->name); - lcrd_set_error_message("Invalid container name %s", h->name); - ret = -1; - goto out; - } - -out: - return ret; -} - -static void pack_container_conf_response(struct lcrd_container_conf_response *response, uint32_t cc, - const struct engine_console_config *config) -{ - if (response == NULL) { - return; - } - response->cc = cc; - if (g_lcrd_errmsg != NULL) { - response->errmsg = util_strdup_s(g_lcrd_errmsg); - DAEMON_CLEAR_ERRMSG(); - } - - if (config->log_path != NULL) { - response->container_logpath = util_strdup_s(config->log_path); - } - response->container_logrotate = (uint32_t)config->log_rotate; - if (config->log_file_size != NULL) { - response->container_logsize = util_strdup_s(config->log_file_size); - } -} - -static int container_conf_cb(const struct lcrd_container_conf_request *request, - struct lcrd_container_conf_response **response) -{ - char *id = NULL; - uint32_t cc = LCRD_SUCCESS; - struct engine_operation *engine_ops = NULL; - struct engine_console_config config = { 0 }; - container_t *cont = NULL; - rt_get_console_conf_params_t params = { 0 }; - - DAEMON_CLEAR_ERRMSG(); - if (request == NULL || response == NULL) { - ERROR("Invalid NULL input"); - return -1; - } - - *response = util_common_calloc_s(sizeof(struct lcrd_container_conf_response)); - if (*response == NULL) { - ERROR("Out of memory"); - cc = LCRD_ERR_MEMOUT; - goto pack_response; - } - - if (container_conf_request_check(request) != 0) { - cc = LCRD_ERR_INPUT; - goto pack_response; - } - - cont = containers_store_get(request->name); - if (cont == NULL) { - ERROR("No such container:%s", request->name); - lcrd_set_error_message("No such container:%s", request->name); - cc = LCRD_ERR_EXEC; - goto pack_response; - } - - engine_ops = engines_get_handler(cont->runtime); - if (engine_ops == NULL || engine_ops->engine_free_console_config_op == NULL) { - ERROR("Failed to get engine free_console_config operation"); - cc = LCRD_ERR_EXEC; - goto pack_response; - } - - id = cont->common_config->id; - set_log_prefix(id); - - params.rootpath = cont->root_path; - params.config = &config; - - if (runtime_get_console_config(id, cont->runtime, ¶ms) != 0) { - cc = LCRD_ERR_EXEC; - goto pack_response; - } - -pack_response: - pack_container_conf_response(*response, cc, &config); - container_unref(cont); - if (engine_ops != NULL && engine_ops->engine_free_console_config_op != NULL) { - engine_ops->engine_free_console_config_op(&config); - } - - free_log_prefix(); - return (cc == LCRD_SUCCESS) ? 0 : -1; -} - static int rename_request_check(const struct lcrd_container_rename_request *request) { int ret = 0; @@ -1745,7 +1657,6 @@ void container_information_callback_init(service_container_callback_t *cb) cb->inspect = container_inspect_cb; cb->list = container_list_cb; cb->wait = container_wait_cb; - cb->conf = container_conf_cb; cb->top = container_top_cb; cb->rename = container_rename_cb; } diff --git a/src/services/execution/execute/execution_stream.c b/src/services/execution/execute/execution_stream.c index 80ebf20..c05bd9a 100644 --- a/src/services/execution/execute/execution_stream.c +++ b/src/services/execution/execute/execution_stream.c @@ -250,7 +250,7 @@ out: static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[], const char *user, size_t argc, const char **argv, size_t env_len, const char **env, - int64_t timeout, int *exit_code) + int64_t timeout, const char *suffix, int *exit_code) { int ret = 0; char *engine_log_path = NULL; @@ -287,6 +287,7 @@ static int exec_container(container_t *cont, const char *runtime, char * const c params.args_len = argc; params.envs = (const char * const *)env; params.envs_len = env_len; + params.suffix = suffix; if (runtime_exec(cont->common_config->id, runtime, ¶ms, exit_code)) { ERROR("Runtime exec container failed"); @@ -332,6 +333,13 @@ static int container_exec_cb_check(const container_exec_request *request, contai return -1; } + if (request->suffix != NULL && !util_valid_exec_suffix(request->suffix)) { + ERROR("Invalid exec suffix %s", request->suffix); + lcrd_set_error_message("Invalid exec suffix %s", request->suffix); + *cc = LCRD_ERR_EXEC; + return -1; + } + *cont = containers_store_get(container_name); if (*cont == NULL) { ERROR("No such container:%s", container_name); @@ -564,7 +572,7 @@ static int container_exec_cb(const container_exec_request *request, container_ex if (exec_container(cont, cont->runtime, (char * const *)fifos, user, request->argv_len, (const char **)request->argv, request->env_len, - (const char **)request->env, request->timeout, &exit_code)) { + (const char **)request->env, request->timeout, request->suffix, &exit_code)) { cc = LCRD_ERR_EXEC; goto pack_response; } @@ -698,7 +706,7 @@ static int container_attach_cb(const container_attach_request *request, containe char *fifopath = NULL; pthread_t tid = 0; container_t *cont = NULL; - struct engine_operation *engine_ops = NULL; + rt_attach_params_t params = { 0 }; DAEMON_CLEAR_ERRMSG(); if (request == NULL || response == NULL) { @@ -725,21 +733,14 @@ static int container_attach_cb(const container_attach_request *request, containe goto pack_response; } - engine_ops = engines_get_handler(cont->runtime); - if (engine_ops == NULL || engine_ops->engine_console_op == NULL) { - DEBUG("Failed to get engine attach operations"); - cc = LCRD_ERR_EXEC; - goto pack_response; - } + params.rootpath = cont->root_path; + params.stdin = fifos[0]; + params.stdout = fifos[1]; + params.stderr = fifos[2]; - if (!engine_ops->engine_console_op(id, cont->root_path, fifos[0], fifos[1], fifos[2])) { - ERROR("attach failed"); + if (runtime_attach(cont->common_config->id, cont->runtime, ¶ms)) { + ERROR("Runtime attach container failed"); cc = LCRD_ERR_EXEC; - const char *tmpmsg = NULL; - tmpmsg = engine_ops->engine_get_errmsg_op(); - lcrd_set_error_message("Attach container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? - tmpmsg : DEF_ERR_RUNTIME_STR); - engine_ops->engine_clear_errmsg_op(); goto pack_response; } @@ -1796,6 +1797,20 @@ static int handle_rotate(int fd, int wd, const char *path) return watch_fd; } +static void cleanup_handler(void *arg) +{ + int *fds = (int *)arg; + + if (fds[0] < 0) { + return; + } + + if (fds[1] >= 0 && inotify_rm_watch(fds[0], fds[1]) < 0) { + SYSERROR("Rm watch failed"); + } + close(fds[0]); +} + static int hanlde_events(int fd, const struct follow_args *farg) { int write_cnt, rename_cnt; @@ -1805,17 +1820,21 @@ static int hanlde_events(int fd, const struct follow_args *farg) ssize_t len = 0; struct inotify_event *c_event = NULL; char buf[MAXLINE] __attribute__((aligned(__alignof__(struct inotify_event)))) = { 0 }; + int clean_fds[2] = { fd, -1 }; struct last_log_file_position last_pos = { .file_index = farg->last_file_index, .pos = farg->last_file_pos, }; + pthread_cleanup_push(cleanup_handler, clean_fds); + watch_fd = inotify_add_watch(fd, farg->path, IN_MODIFY | IN_DELETE | IN_MOVED_FROM | IN_MOVE_SELF); if (watch_fd < 0) { SYSERROR("Add watch %s failed", farg->path); goto out; } + clean_fds[1] = watch_fd; for (;;) { if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) { @@ -1866,9 +1885,7 @@ static int hanlde_events(int fd, const struct follow_args *farg) } out: - if (inotify_rm_watch(fd, watch_fd) < 0) { - SYSERROR("Rm watch failed"); - } + pthread_cleanup_pop(1); return ret; } @@ -1881,7 +1898,7 @@ static void *follow_thread_func(void *arg) INFO("Get args, path: %s, last pos: %ld, last file: %d", farg->path, farg->last_file_pos, farg->last_file_index); - inotify_fd = inotify_init(); + inotify_fd = inotify_init1(IN_CLOEXEC); if (inotify_fd < 0) { SYSERROR("Init inotify failed"); goto set_flag; @@ -1891,7 +1908,6 @@ static void *follow_thread_func(void *arg) ERROR("Handle inotify event failed"); } - close(inotify_fd); set_flag: *(farg->finish) = true; return NULL; diff --git a/src/services/execution/manager/container_unix.c b/src/services/execution/manager/container_unix.c index eb34534..9c4c32b 100644 --- a/src/services/execution/manager/container_unix.c +++ b/src/services/execution/manager/container_unix.c @@ -1255,46 +1255,6 @@ unlock: return ret; } -static container_pid_t *parse_container_pid(const char *S) -{ - int num; - container_pid_t *P = NULL; - - if (S == NULL) { - return NULL; - } - - P = util_common_calloc_s(sizeof(container_pid_t)); - if (P == NULL) { - return NULL; - } - - num = sscanf(S, "%d %Lu %d %Lu", &P->pid, &P->start_time, &P->ppid, &P->pstart_time); - if (num != 4) { // args num to read is 4 - ERROR("Call sscanf error: %s", errno ? strerror(errno) : ""); - free(P); - return NULL; - } - - return P; -} - -container_pid_t *container_read_pidfile(const char *pidfile) -{ - if (pidfile == NULL) { - ERROR("Invalid input arguments"); - return NULL; - } - - char sbuf[1024] = { 0 }; /* bufs for stat */ - - if ((util_file2str(pidfile, sbuf, sizeof(sbuf))) == -1) { - return NULL; - } - - return parse_container_pid(sbuf); -} - char *container_get_env_nolock(const container_t *cont, const char *key) { size_t i = 0; @@ -1340,3 +1300,38 @@ char *container_get_env_nolock(const container_t *cont, const char *key) return val; } +int container_read_proc(uint32_t pid, container_pid_t *pid_info) +{ + int ret = 0; + proc_t *proc = NULL; + proc_t *p_proc = NULL; + + if (pid == 0) { + ret = -1; + goto out; + } + + proc = util_get_process_proc_info((pid_t)pid); + if (proc == NULL) { + ret = -1; + goto out; + } + + p_proc = util_get_process_proc_info((pid_t)proc->ppid); + if (p_proc == NULL) { + ret = -1; + goto out; + } + + pid_info->pid = proc->pid; + pid_info->start_time = proc->start_time; + pid_info->ppid = proc->ppid; + pid_info->pstart_time = p_proc->start_time; + +out: + free(proc); + free(p_proc); + return ret; +} + + diff --git a/src/services/execution/manager/container_unix.h b/src/services/execution/manager/container_unix.h index 55d8311..cf89139 100644 --- a/src/services/execution/manager/container_unix.h +++ b/src/services/execution/manager/container_unix.h @@ -106,11 +106,11 @@ int container_wait_stop_locking(container_t *cont, int timeout); void container_wait_rm_cond_broadcast(container_t *cont); int container_wait_rm_locking(container_t *cont, int timeout); -container_pid_t *container_read_pidfile(const char *pidfile); - int save_host_config(const char *id, const char *rootpath, const char *hostconfigstr); int save_config_v2_json(const char *id, const char *rootpath, const char *v2configstr); +int container_read_proc(uint32_t pid, container_pid_t *pid_info); + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/src/services/execution/manager/restore.c b/src/services/execution/manager/restore.c index 60d9d15..46ff8ae 100644 --- a/src/services/execution/manager/restore.c +++ b/src/services/execution/manager/restore.c @@ -28,6 +28,7 @@ #include "container_unix.h" #include "error.h" #include "image.h" +#include "runtime.h" #ifdef ENABLE_OCI_IMAGE #include "oci_images_store.h" @@ -36,15 +37,17 @@ #include "execution.h" /* restore supervisor */ -static int restore_supervisor(const char *id, const char *runtime, const char *statepath) +static int restore_supervisor(const container_t *cont) { int ret = 0; int nret = 0; int exit_fifo_fd = -1; char container_state[PATH_MAX] = { 0 }; - char pidfile[PATH_MAX] = { 0 }; char *exit_fifo = NULL; - container_pid_t *pid_info = NULL; + char *id = cont->common_config->id; + char *statepath = cont->state_path; + char *runtime = cont->runtime; + container_pid_t pid_info = { 0 }; nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id); if (nret < 0 || (size_t)nret >= sizeof(container_state)) { @@ -67,23 +70,12 @@ static int restore_supervisor(const char *id, const char *runtime, const char *s goto out; } - nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state); - if (nret < 0 || (size_t)nret >= sizeof(pidfile)) { - close(exit_fifo_fd); - ERROR("Failed to sprintf pidfile"); - ret = -1; - goto out; - } - - pid_info = container_read_pidfile(pidfile); - if (pid_info == NULL) { - close(exit_fifo_fd); - ERROR("Failed to get started container's pid info"); - ret = -1; - goto out; - } + pid_info.pid = cont->state->state->pid; + pid_info.ppid = cont->state->state->p_pid; + pid_info.start_time = cont->state->state->start_time; + pid_info.pstart_time = cont->state->state->p_start_time; - if (supervisor_add_exit_monitor(exit_fifo_fd, pid_info, id, runtime)) { + if (supervisor_add_exit_monitor(exit_fifo_fd, &pid_info, id, runtime)) { ERROR("Failed to add exit monitor to supervisor"); ret = -1; goto out; @@ -91,115 +83,31 @@ static int restore_supervisor(const char *id, const char *runtime, const char *s out: free(exit_fifo); - free(pid_info); return ret; } -static container_pid_t *container_read_proc(uint32_t pid) -{ - container_pid_t *pid_info = NULL; - proc_t *proc_info = NULL; - - if (pid == 0) { - goto out; - } - - proc_info = util_get_process_proc_info((pid_t)pid); - if (proc_info == NULL) { - goto out; - } - - pid_info = util_common_calloc_s(sizeof(container_pid_t)); - if (pid_info == NULL) { - goto out; - } - - pid_info->pid = proc_info->pid; - pid_info->start_time = proc_info->start_time; - -out: - free(proc_info); - return pid_info; -} - /* post stopped container to gc */ static int post_stopped_container_to_gc(const char *id, const char *runtime, const char *statepath, uint32_t pid) { int ret = 0; - int nret = 0; - char container_state[PATH_MAX] = { 0 }; - char pidfile[PATH_MAX] = { 0 }; - container_pid_t *pid_info = NULL; + container_pid_t pid_info = { 0 }; - nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id); - if (nret < 0 || (size_t)nret >= sizeof(container_state)) { - ERROR("Failed to sprintf container state %s/%s", statepath, id); - ret = -1; - goto out; - } + (void)container_read_proc(pid, &pid_info); - nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state); - if (nret < 0 || (size_t)nret >= sizeof(pidfile)) { - ERROR("Failed to sprintf pidfile"); - ret = -1; - goto out; - } - - pid_info = container_read_pidfile(pidfile); - if (pid_info == NULL) { - WARN("Failed to get started container's pid info, try to read proc filesystem"); - pid_info = container_read_proc(pid); - if (pid_info == NULL) { - ERROR("Failed to get started container's pid info"); - ret = -1; - goto out; - } - } - - if (gc_add_container(id, runtime, pid_info)) { + if (gc_add_container(id, runtime, &pid_info)) { ERROR("Failed to post container %s to garbage collector", id); ret = -1; goto out; } out: - free(pid_info); return ret; } -static container_pid_t *load_running_container_pid_info(const container_t *cont) -{ - int nret = 0; - const char *id = cont->common_config->id; - char pidfile[PATH_MAX] = { 0 }; - char container_state[PATH_MAX] = { 0 }; - container_pid_t *pid_info = NULL; - - nret = snprintf(container_state, sizeof(container_state), "%s/%s", cont->state_path, id); - if (nret < 0 || (size_t)nret >= sizeof(container_state)) { - ERROR("Failed to sprintf container_state for container %s", id); - goto out; - } - - nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state); - if (nret < 0 || (size_t)nret >= sizeof(pidfile)) { - ERROR("Failed to sprintf pidfile"); - goto out; - } - - pid_info = container_read_pidfile(pidfile); - if (pid_info == NULL) { - goto out; - } - -out: - return pid_info; -} - #ifdef ENABLE_OCI_IMAGE static void post_nonexist_image_containers(const container_t *cont, Container_Status status, - const struct engine_container_summary_info *info) + const struct engine_container_status_info *info) { int nret; const char *id = cont->common_config->id; @@ -267,50 +175,31 @@ out: } #endif -static void try_to_set_container_running(Container_Status status, const container_t *cont, - const container_pid_t *pid_info) +static bool is_same_process(const container_t *cont, const container_pid_t *pid_info) { - int pid = 0; - - pid = state_get_pid(cont->state); - if (status != CONTAINER_STATUS_RUNNING || pid != pid_info->pid) { - state_set_running(cont->state, pid_info, true); + if (pid_info->pid == cont->state->state->pid && + pid_info->ppid == cont->state->state->p_pid && + pid_info->start_time == cont->state->state->start_time && + pid_info->pstart_time == cont->state->state->p_start_time) { + return true; } + return false; } static void try_to_set_paused_container_pid(Container_Status status, const container_t *cont, const container_pid_t *pid_info) { - int pid = 0; - - pid = state_get_pid(cont->state); - if (status != CONTAINER_STATUS_RUNNING || pid != pid_info->pid) { + if (status != CONTAINER_STATUS_RUNNING || !is_same_process(cont, pid_info)) { state_set_running(cont->state, pid_info, false); } } -static int restore_check_id_valid(const char *id, const struct engine_container_summary_info *info, - size_t container_num) +static void try_to_set_container_running(Container_Status status, container_t *cont, + const container_pid_t *pid_info) { - size_t i = 0; - - if (id == NULL) { - ERROR("Cannot get container id from config v2"); - return -1; - } - - for (i = 0; i < container_num; i++) { - if (strcmp(id, info[i].id) == 0) { - break; - } - } - - if (i >= container_num) { - ERROR("Container %s is not in runtime container array", id); - return -1; + if (status != CONTAINER_STATUS_RUNNING || !is_same_process(cont, pid_info)) { + state_set_running(cont->state, pid_info, true); } - - return (int)i; } static int restore_stopped_container(Container_Status status, const container_t *cont, bool *need_save) @@ -333,16 +222,19 @@ static int restore_stopped_container(Container_Status status, const container_t } static int restore_running_container(Container_Status status, container_t *cont, - const struct engine_container_summary_info *info) + const struct engine_container_status_info *info) { int ret = 0; + int nret = 0; const char *id = cont->common_config->id; - container_pid_t *pid_info = NULL; + container_pid_t pid_info = { 0 }; - pid_info = load_running_container_pid_info(cont); - if (pid_info == NULL) { - ERROR("Failed to restore container:%s due to unable to read container pid info", id); - int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, info->pid); + nret = container_read_proc(info->pid, &pid_info); + if (nret == 0) { + try_to_set_container_running(status, cont, &pid_info); + } else { + ERROR("Failed to restore container:%s due to unable to read container pid information", id); + nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0); if (nret != 0) { ERROR("Failed to post container %s to garbage" "collector, that may lost some resources" @@ -350,29 +242,30 @@ static int restore_running_container(Container_Status status, container_t *cont, } ret = -1; goto out; - } else { - try_to_set_container_running(status, cont, pid_info); } + container_reset_manually_stopped(cont); out: - free(pid_info); return ret; } static int restore_paused_container(Container_Status status, container_t *cont, - const struct engine_container_summary_info *info) + const struct engine_container_status_info *info) { int ret = 0; + int nret = 0; const char *id = cont->common_config->id; - container_pid_t *pid_info = NULL; + container_pid_t pid_info = { 0 }; state_set_paused(cont->state); - pid_info = load_running_container_pid_info(cont); - if (pid_info == NULL) { - ERROR("Failed to restore container:%s due to unable to read container pid info", id); - int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, info->pid); + nret = container_read_proc(info->pid, &pid_info); + if (nret == 0) { + try_to_set_paused_container_pid(status, cont, &pid_info); + } else { + ERROR("Failed to restore container:%s due to unable to read container pid information", id); + nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0); if (nret != 0) { ERROR("Failed to post container %s to garbage" "collector, that may lost some resources" @@ -380,27 +273,31 @@ static int restore_paused_container(Container_Status status, container_t *cont, } ret = -1; goto out; - } else { - try_to_set_paused_container_pid(status, cont, pid_info); } + container_reset_manually_stopped(cont); out: - free(pid_info); return ret; } /* restore state */ -static int restore_state(container_t *cont, const struct engine_container_summary_info *info, size_t container_num) +static int restore_state(container_t *cont) { int ret = 0; - int c_index = 0; + int nret = 0; bool need_save = false; const char *id = cont->common_config->id; + const char *runtime = cont->runtime; + rt_status_params_t params = { 0 }; + struct engine_container_status_info real_status = { 0 }; Container_Status status = CONTAINER_STATUS_UNKNOWN; - c_index = restore_check_id_valid(id, info, container_num); - if (c_index < 0) { + params.rootpath = cont->root_path; + + nret = runtime_status(id, runtime, ¶ms, &real_status); + if (nret != 0) { + ERROR("Failed to restore container %s, due to can not load container status", id); ret = -1; goto out; } @@ -411,29 +308,31 @@ static int restore_state(container_t *cont, const struct engine_container_summar #ifdef ENABLE_OCI_IMAGE if (check_container_image_exist(cont) != 0) { ERROR("Failed to restore container:%s due to image not exist", id); - post_nonexist_image_containers(cont, status, &info[c_index]); + post_nonexist_image_containers(cont, status, &real_status); ret = -1; goto out; } #endif - if (info[c_index].status == ENGINE_CONTAINER_STATUS_STOPPED) { + if (real_status.status == ENGINE_CONTAINER_STATUS_STOPPED) { ret = restore_stopped_container(status, cont, &need_save); if (ret != 0) { goto out; } - } else if (info[c_index].status == ENGINE_CONTAINER_STATUS_RUNNING) { - ret = restore_running_container(status, cont, &info[c_index]); + } else if (real_status.status == ENGINE_CONTAINER_STATUS_RUNNING) { + ret = restore_running_container(status, cont, &real_status); if (ret != 0) { goto out; } - } else if (info[c_index].status == ENGINE_CONTAINER_STATUS_PAUSED) { - ret = restore_paused_container(status, cont, &info[c_index]); + } else if (real_status.status == ENGINE_CONTAINER_STATUS_PAUSED) { + ret = restore_paused_container(status, cont, &real_status); if (ret != 0) { goto out; } } else { - ERROR("Container %s get invalid status %d", id, info[c_index].status); + ERROR("Container %s get invalid status %d", id, real_status.status); + ret = -1; + goto out; } if (is_removal_in_progress(cont->state)) { @@ -538,7 +437,7 @@ static void handle_restored_container() id = cont->common_config->id; if (is_running(cont->state)) { - if (restore_supervisor(id, cont->runtime, cont->state_path)) { + if (restore_supervisor(cont)) { ERROR("Failed to restore %s supervisor", id); } init_health_monitor(id); @@ -563,8 +462,7 @@ static void handle_restored_container() /* scan dir to add store */ static void scan_dir_to_add_store(const char *runtime, const char *rootpath, const char *statepath, - const size_t subdir_num, const char **subdir, const size_t container_num, - const struct engine_container_summary_info *info) + const size_t subdir_num, const char **subdir) { size_t i = 0; container_t *cont = NULL; @@ -579,7 +477,7 @@ static void scan_dir_to_add_store(const char *runtime, const char *rootpath, con goto error_load; } - if (restore_state(cont, info, container_num)) { + if (restore_state(cont)) { WARN("Failed to restore container %s state", subdir[i]); goto error_load; } @@ -609,83 +507,14 @@ error_load: } } -/* query all containers info */ -static int query_all_containers_info(const char *runtime, struct engine_container_summary_info **container_summary, - size_t *container_num) -{ - int ret = 0; - int container_nums = 0; - char *engine_path = NULL; - struct engine_operation *engine_ops = NULL; - - if (runtime == NULL || container_summary == NULL || container_num == NULL) { - ERROR("invalid NULL param"); - return -1; - } - - engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || engine_ops->engine_get_all_containers_info_op == NULL) { - ERROR("Failed to get list op of engine %s", runtime); - ret = -1; - goto out; - } - - engine_path = conf_get_routine_rootdir(runtime); - if (engine_path == NULL) { - ret = -1; - goto out; - } - container_nums = engine_ops->engine_get_all_containers_info_op(engine_path, container_summary); - if (container_nums < 0) { - ERROR("Engine %s get all containers info failed", runtime); - ret = -1; - goto out; - } - *container_num = (size_t)container_nums; - -out: - free(engine_path); - if (engine_ops != NULL) { - engine_ops->engine_clear_errmsg_op(); - } - - return ret; -} - -/* all containers info free */ -static void all_containers_info_free(const char *runtime, struct engine_container_summary_info *container_summary, - size_t container_num) -{ - struct engine_operation *engine_ops = NULL; - - if (container_summary == NULL || runtime == NULL) { - return; - } - - engine_ops = engines_get_handler(runtime); - if (engine_ops == NULL || engine_ops->engine_free_all_containers_info_op == NULL) { - ERROR("Failed to get free op of engine %s", runtime); - return; - } - - engine_ops->engine_free_all_containers_info_op(container_summary, (int)container_num); - - if (engine_ops->engine_clear_errmsg_op != NULL) { - engine_ops->engine_clear_errmsg_op(); - } - return; -} - /* restore container by runtime */ static int restore_container_by_runtime(const char *runtime) { int ret = 0; char *rootpath = NULL; char *statepath = NULL; - size_t container_num = 0; size_t subdir_num = 0; char **subdir = NULL; - struct engine_container_summary_info *info = NULL; rootpath = conf_get_routine_rootdir(runtime); if (rootpath == NULL) { @@ -712,17 +541,9 @@ static int restore_container_by_runtime(const char *runtime) goto out; } - ret = query_all_containers_info(runtime, &info, &container_num); - if (ret < 0) { - ERROR("query all containers info failed"); - ret = -1; - goto out; - } - - scan_dir_to_add_store(runtime, rootpath, statepath, subdir_num, (const char **)subdir, container_num, info); + scan_dir_to_add_store(runtime, rootpath, statepath, subdir_num, (const char **)subdir); out: - all_containers_info_free(runtime, info, container_num); free(rootpath); free(statepath); util_free_array(subdir); -- Gitee From 01fc9ba5e34c5a06d425104df7c3b555c0a52045 Mon Sep 17 00:00:00 2001 From: wei Ding Date: Wed, 8 Jan 2020 16:31:54 +0800 Subject: [PATCH 10/11] ext_config_image don't need judge wheather be null --- src/image/image.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/image/image.c b/src/image/image.c index 180dec1..ce277ac 100644 --- a/src/image/image.c +++ b/src/image/image.c @@ -246,11 +246,6 @@ static struct bim *bim_get(const char *image_type, const char *image_name, const } if (ext_config_image != NULL) { bim->ext_config_image = util_strdup_s(ext_config_image); - if (bim->ext_config_image == NULL) { - lcrd_append_error_message("Failed to dup external config image %s", bim->ext_config_image); - bim_put(bim); - return NULL; - } } if (container_id != NULL) { bim->container_id = util_strdup_s(container_id); -- Gitee From 82aeafab4e156f22d39671706ae7fa745bbd018a Mon Sep 17 00:00:00 2001 From: wei Ding Date: Thu, 9 Jan 2020 13:46:17 +0800 Subject: [PATCH 11/11] bim->image_name is null ,so should use image_name --- src/image/image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image/image.c b/src/image/image.c index ce277ac..8e76b17 100644 --- a/src/image/image.c +++ b/src/image/image.c @@ -239,7 +239,7 @@ static struct bim *bim_get(const char *image_type, const char *image_name, const if (image_name != NULL) { bim->image_name = bim->ops->resolve_image_name(image_name); if (bim->image_name == NULL) { - lcrd_append_error_message("Failed to resovle image name%s", bim->image_name); + lcrd_append_error_message("Failed to resovle image name%s", image_name); bim_put(bim); return NULL; } -- Gitee