提交 cfd3ebc2 编写于 作者: L lifeng68

refact: make daemon/modules

Signed-off-by: Nlifeng68 <lifeng68@huawei.com>
上级 69d2c22f
......@@ -91,7 +91,7 @@ install(FILES src/utils/cutils/error.h
DESTINATION include/isulad)
install(FILES src/daemon/modules/runtime/engines/engine.h
DESTINATION include/isulad)
install(FILES src/daemon/image/image.h
install(FILES src/daemon/modules/image/image.h
DESTINATION include/isulad)
# install config files
......
......@@ -51,7 +51,7 @@
#include "callback.h"
#include "log_gather.h"
#include "containers_store.h"
#include "container_operator.h"
#include "service_container.h"
#include "plugin.h"
#include "selinux_label.h"
#include "http.h"
......
......@@ -27,6 +27,7 @@
#include "utils.h"
#include "cri_helpers.h"
#include "event_sender.h"
#include "service_image.h"
static void conv_image_to_grpc(const imagetool_image *element, std::unique_ptr<runtime::v1alpha2::Image> &image)
{
......@@ -313,26 +314,24 @@ void CRIImageServiceImpl::RemoveImage(const runtime::v1alpha2::ImageSpec &image,
{
std::string out_str { "" };
im_rmi_request *request { nullptr };
im_remove_response *response { nullptr };
DAEMON_CLEAR_ERRMSG();
if (remove_request_from_grpc(&image, &request, error)) {
goto cleanup;
}
if (im_rm_image(request, &response) != 0) {
if (response != nullptr && response->errmsg != nullptr) {
error.SetError(response->errmsg);
if (delete_image(request->image.image, false) != 0) {
if (g_isulad_errmsg != nullptr) {
error.SetError(g_isulad_errmsg);
} else {
error.SetError("Failed to call remove image");
}
} else {
(void)isulad_monitor_send_image_event(request->image.image, IM_REMOVE);
}
cleanup:
DAEMON_CLEAR_ERRMSG();
free_im_remove_request(request);
free_im_remove_response(response);
return;
}
......
......@@ -51,7 +51,7 @@
#include "error.h"
#include "event_sender.h"
#include "specs.h"
#include "container_operator.h"
#include "service_container.h"
static int filter_by_label(const container_t *cont, const container_get_id_request *request)
{
......
......@@ -45,7 +45,7 @@
#include "namespace.h"
#include "event_sender.h"
#include "sysinfo.h"
#include "container_operator.h"
#include "service_container.h"
static int runtime_check(const char *name, bool *runtime_res)
{
......
......@@ -36,7 +36,7 @@
#include "verify.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "container_operator.h"
#include "service_container.h"
#include "sysinfo.h"
#include "specs.h"
#include "runtime.h"
......
......@@ -44,7 +44,7 @@
#include "constants.h"
#include "runtime.h"
#include "event_sender.h"
#include "container_operator.h"
#include "service_container.h"
#include "io_handler.h"
struct container_log_config {
......
......@@ -44,7 +44,7 @@
#include "constants.h"
#include "runtime.h"
#include "event_sender.h"
#include "container_operator.h"
#include "service_container.h"
static char *create_single_fifo(const char *statepath, const char *subpath, const char *stdflag)
{
......
......@@ -34,6 +34,7 @@
#include "mediatype.h"
#include "filters.h"
#include "event_sender.h"
#include "service_image.h"
#ifdef ENABLE_OCI_IMAGE
#include "oci_common_operators.h"
#endif
......@@ -373,49 +374,6 @@ out:
return (ret < 0) ? ECOMMON : ret;
}
/* delete image info */
static int delete_image_info(const char *image_ref, bool force)
{
int ret = 0;
im_rmi_request *im_request = NULL;
im_remove_response *im_response = NULL;
if (image_ref == NULL) {
ERROR("invalid NULL param");
return EINVALIDARGS;
}
im_request = util_common_calloc_s(sizeof(im_rmi_request));
if (im_request == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
im_request->image.image = util_strdup_s(image_ref);
im_request->force = force;
ret = im_rm_image(im_request, &im_response);
if (ret != 0) {
if (im_response != NULL && im_response->errmsg != NULL) {
ERROR("Remove image %s failed:%s", image_ref, im_response->errmsg);
isulad_try_set_error_message("Remove image %s failed:%s", image_ref, im_response->errmsg);
} else {
ERROR("Remove image %s failed", image_ref);
isulad_try_set_error_message("Remove image %s failed", image_ref);
}
ret = -1;
goto out;
}
(void)isulad_monitor_send_image_event(im_request->image.image, IM_REMOVE);
out:
free_im_remove_request(im_request);
free_im_remove_response(im_response);
return ret;
}
/* image remove cb */
static int image_remove_cb(const image_delete_image_request *request, image_delete_image_response **response)
{
......@@ -448,7 +406,7 @@ static int image_remove_cb(const image_delete_image_request *request, image_dele
EVENT("Image Event: {Object: %s, Type: Deleting}", image_ref);
ret = delete_image_info(image_ref, request->force);
ret = delete_image(image_ref, request->force);
if (ret != 0) {
cc = ISULAD_ERR_EXEC;
goto out;
......
......@@ -9,6 +9,7 @@ add_subdirectory(container)
add_subdirectory(log)
add_subdirectory(events)
add_subdirectory(events_sender)
add_subdirectory(service)
set(local_modules_srcs
${modules_top_srcs}
......@@ -20,6 +21,7 @@ set(local_modules_srcs
${LOG_GATHER_SRCS}
${EVENTS_SRCS}
${EVENTS_SENDER_SRCS}
${SERVICE_SRCS}
)
set(local_modules_incs
......@@ -32,6 +34,7 @@ set(local_modules_incs
${LOG_GATHER_INCS}
${EVENTS_INCS}
${EVENTS_SENDER_INCS}
${SERVICE_INCS}
)
set(MODULES_SRCS
......
......@@ -27,7 +27,7 @@
#include "container_events_handler.h"
#include "utils.h"
#include "containers_store.h"
#include "container_operator.h"
#include "service_container.h"
#include "plugin.h"
/* events handler lock */
......
......@@ -23,7 +23,7 @@
#include "isula_libutils/container_garbage_config.h"
#include "isula_libutils/log.h"
#include "utils.h"
#include "container_operator.h"
#include "service_container.h"
#include "containers_store.h"
#include "runtime.h"
......
......@@ -26,7 +26,7 @@
#include "utils.h"
#include "health_check.h"
#include "callback.h"
#include "container_operator.h"
#include "service_container.h"
#include "isula_libutils/container_exec_request.h"
#include "isula_libutils/container_exec_response.h"
#include "containers_store.h"
......
......@@ -27,7 +27,7 @@
#include "restartmanager.h"
#include "utils.h"
#include "containers_store.h"
#include "container_operator.h"
#include "service_container.h"
#define backoffMultipulier 2U
// unit nanos
......
......@@ -29,7 +29,7 @@
#include "error.h"
#include "image.h"
#include "runtime.h"
#include "container_operator.h"
#include "service_container.h"
/* restore supervisor */
static int restore_supervisor(const container_t *cont)
......
......@@ -24,7 +24,7 @@
#include "libisulad.h"
#include "event_sender.h"
#include "containers_gc.h"
#include "container_operator.h"
#include "service_container.h"
pthread_mutex_t g_supervisor_lock = PTHREAD_MUTEX_INITIALIZER;
struct epoll_descr g_supervisor_descr;
......
......@@ -47,45 +47,41 @@ set(LIB_ISULAD_IMG libisulad_img)
add_library(${LIB_ISULAD_IMG} ${LIBTYPE}
${local_image_srcs}
${CMAKE_SOURCE_DIR}/src/cutils/utils.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_regex.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_file.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_verify.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_array.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_convert.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_string.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_base64.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_timestamp.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_fs.c
${CMAKE_SOURCE_DIR}/src/cutils/utils_aes.c
${CMAKE_SOURCE_DIR}/src/cutils/util_atomic.c
${CMAKE_SOURCE_DIR}/src/cutils/filters.c
${CMAKE_SOURCE_DIR}/src/cutils/path.c
${CMAKE_SOURCE_DIR}/src/cutils/map/map.c
${CMAKE_SOURCE_DIR}/src/cutils/map/rb_tree.c
${CMAKE_SOURCE_DIR}/src/sha256/sha256.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_regex.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_file.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_verify.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_array.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_convert.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_string.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_base64.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_timestamp.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_fs.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_aes.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/util_atomic.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/filters.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/path.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/map/map.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/map/rb_tree.c
${CMAKE_SOURCE_DIR}/src/utils/sha256/sha256.c
${CMAKE_SOURCE_DIR}/src/daemon/libisulad.c
${CMAKE_SOURCE_DIR}/src/daemon/isulad_config.c
${CMAKE_SOURCE_DIR}/src/daemon/daemon_arguments.c
${CMAKE_SOURCE_DIR}/src/daemon/spec/sysinfo.c
${CMAKE_SOURCE_DIR}/src/tar/isulad_tar.c
${CMAKE_SOURCE_DIR}/src/tar/util_archive.c
${CMAKE_SOURCE_DIR}/src/daemon/modules/spec/sysinfo.c
${CMAKE_SOURCE_DIR}/src/utils/tar/isulad_tar.c
${CMAKE_SOURCE_DIR}/src/utils/tar/util_archive.c
)
target_include_directories(${LIB_ISULAD_IMG} PUBLIC
${local_image_incs}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/sha256
${CMAKE_SOURCE_DIR}/src/utils/sha256
${CMAKE_SOURCE_DIR}/src/http
${CMAKE_SOURCE_DIR}/src/tar
${CMAKE_SOURCE_DIR}/src/utils/tar
${CMAKE_SOURCE_DIR}/src/daemon
${CMAKE_SOURCE_DIR}/src/daemon/spec/
${CMAKE_SOURCE_DIR}/src/daemon/container
${CMAKE_SOURCE_DIR}/src/daemon/runtime
${CMAKE_SOURCE_DIR}/src/daemon/container/restart_manager
${CMAKE_SOURCE_DIR}/src/daemon/container/health_check
${CMAKE_SOURCE_DIR}/src/cutils
${CMAKE_SOURCE_DIR}/src/cutils/map
${CMAKE_SOURCE_DIR}/src/daemon/modules/spec/
${CMAKE_SOURCE_DIR}/src/utils/cutils
${CMAKE_SOURCE_DIR}/src/utils/cutils/map
${CHECKED_INCLUDE_DIRS}
)
......@@ -99,4 +95,4 @@ target_link_libraries(${LIB_ISULAD_IMG}
-lpthread -lcrypto -larchive -lz libhttpclient)
install(TARGETS ${LIB_ISULAD_IMG}
LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
\ No newline at end of file
LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
......@@ -21,7 +21,6 @@
#include <sys/utsname.h>
#include <ctype.h>
#include "containers_store.h"
#include "specs_extend.h"
#include "isula_libutils/log.h"
#include "embedded_image.h"
......@@ -287,51 +286,11 @@ int embedded_remove_image(const im_rmi_request *request)
{
bool force = false;
char *image_ref = NULL;
int ret = 0;
size_t i = 0;
size_t container_num = 0;
container_t **conts = NULL;
force = request->force;
image_ref = request->image.image;
if (!force) {
ret = containers_store_list(&conts, &container_num);
if (ret != 0) {
ERROR("query all containers info failed");
ret = -1;
goto out;
}
/* check if container is using this image */
for (i = 0; i < container_num; i++) {
if (ret != 0) {
goto unref_continue;
}
if (conts[i]->common_config->image == NULL) {
goto unref_continue;
}
if (strcmp(conts[i]->common_config->image, image_ref) == 0) {
ERROR("unable to remove image %s, container %s is using it", image_ref, conts[i]->common_config->id);
isulad_set_error_message("Image is in use");
ret = EIMAGEBUSY;
goto unref_continue;
}
unref_continue:
container_unref(conts[i]);
continue;
}
if (ret != 0) {
ret = -1;
goto out;
}
}
ret = lim_delete_image(image_ref, force);
out:
free(conts);
return ret;
return lim_delete_image(image_ref, force);
}
int embedded_inspect_image(const im_inspect_request *request, char **inspected_json)
......
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_service_srcs)
set(SERVICE_SRCS
${local_service_srcs}
PARENT_SCOPE
)
set(SERVICE_INCS
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE
)
......@@ -13,7 +13,7 @@
* Description: provide container supervisor functions
******************************************************************************/
#define _GNU_SOURCE
#include "container_operator.h"
#include "service_container.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
......
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
......@@ -8,12 +8,12 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2017-11-22
* Author: lifeng
* Create: 2020-06-22
* Description: provide container supervisor definition
******************************************************************************/
#ifndef __ISULAD_CONTAINER_OPERATOR_H
#define __ISULAD_CONTAINER_OPERATOR_H
#ifndef __ISULAD_SERVICE_CONTAINER_OPERATOR_H
#define __ISULAD_SERVICE_CONTAINER_OPERATOR_H
#include <pthread.h>
#include <semaphore.h>
#include "container_unix.h"
......
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2017-11-22
* Description: provide container supervisor functions
******************************************************************************/
#define _GNU_SOURCE
#include "service_image.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mount.h>
#include "isula_libutils/log.h"
#include "image.h"
#include "utils.h"
#include "containers_store.h"
#include "event_sender.h"
static bool check_image_in_used(const char *image_ref)
{
bool in_used = false;
int ret = 0;
size_t i = 0;
size_t container_num = 0;
container_t **conts = NULL;
ret = containers_store_list(&conts, &container_num);
if (ret != 0) {
ERROR("query all containers info failed");
in_used = true;
goto out;
}
/* check if container is using this image */
for (i = 0; i < container_num; i++) {
if (in_used) {
goto unref_continue;
}
if (conts[i]->common_config->image == NULL) {
goto unref_continue;
}
if (strcmp(conts[i]->common_config->image, image_ref) == 0) {
isulad_set_error_message("Image used by %s", conts[i]->common_config->id);
ERROR("Image used by %s", conts[i]->common_config->id);
in_used = true;
goto unref_continue;
}
unref_continue:
container_unref(conts[i]);
continue;
}
out:
free(conts);
return in_used;
}
/* delete image info */
int delete_image(const char *image_ref, bool force)
{
int ret = 0;
im_rmi_request *im_request = NULL;
im_remove_response *im_response = NULL;
if (image_ref == NULL) {
ERROR("invalid NULL param");
ret = -1;
goto out;
}
if (check_image_in_used(image_ref)) {
ERROR("Failed to remove in used image %s", image_ref);
ret = -1;
goto out;
}
im_request = util_common_calloc_s(sizeof(im_rmi_request));
if (im_request == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
im_request->image.image = util_strdup_s(image_ref);
im_request->force = force;
ret = im_rm_image(im_request, &im_response);
if (ret != 0) {
if (im_response != NULL && im_response->errmsg != NULL) {
ERROR("Remove image %s failed:%s", image_ref, im_response->errmsg);
isulad_try_set_error_message("Remove image %s failed:%s", image_ref, im_response->errmsg);
} else {
ERROR("Remove image %s failed", image_ref);
isulad_try_set_error_message("Remove image %s failed", image_ref);
}
ret = -1;
goto out;
}
(void)isulad_monitor_send_image_event(im_request->image.image, IM_REMOVE);
out:
free_im_remove_request(im_request);
free_im_remove_response(im_response);
return ret;
}
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2020-06-22
* Description: provide container supervisor definition
******************************************************************************/
#ifndef __ISULAD_SERVICE_IMAGE_OPERATOR_H
#define __ISULAD_SERVICE_IMAGE_OPERATOR_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
int delete_image(const char *image_ref, bool force);
#ifdef __cplusplus
}
#endif
#endif
......@@ -17,7 +17,7 @@
#define CONTAINERS_OPERATOR_MOCK_H_
#include <gmock/gmock.h>
#include "container_operator.h"
#include "service_container.h"
class MockContainersOperator {
public:
......
......@@ -58,6 +58,7 @@ target_include_directories(${EXE} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/service
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/container
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/container/restart_manager
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/container/health_check
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册