Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
cfd3ebc2
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cfd3ebc2
编写于
6月 29, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact: make daemon/modules
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
69d2c22f
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
215 addition
and
143 deletion
+215
-143
CMakeLists.txt
CMakeLists.txt
+1
-1
src/cmd/isulad/main.c
src/cmd/isulad/main.c
+1
-1
src/daemon/entry/cri/cri_image_service.cc
src/daemon/entry/cri/cri_image_service.cc
+6
-7
src/daemon/executor/container_cb/execution.c
src/daemon/executor/container_cb/execution.c
+1
-1
src/daemon/executor/container_cb/execution_create.c
src/daemon/executor/container_cb/execution_create.c
+1
-1
src/daemon/executor/container_cb/execution_extend.c
src/daemon/executor/container_cb/execution_extend.c
+1
-1
src/daemon/executor/container_cb/execution_stream.c
src/daemon/executor/container_cb/execution_stream.c
+1
-1
src/daemon/executor/container_cb/io_handler.c
src/daemon/executor/container_cb/io_handler.c
+1
-1
src/daemon/executor/image_cb/image_cb.c
src/daemon/executor/image_cb/image_cb.c
+2
-44
src/daemon/modules/CMakeLists.txt
src/daemon/modules/CMakeLists.txt
+3
-0
src/daemon/modules/container/container_events_handler.c
src/daemon/modules/container/container_events_handler.c
+1
-1
src/daemon/modules/container/container_gc/containers_gc.c
src/daemon/modules/container/container_gc/containers_gc.c
+1
-1
src/daemon/modules/container/health_check/health_check.c
src/daemon/modules/container/health_check/health_check.c
+1
-1
src/daemon/modules/container/restart_manager/restartmanager.c
...daemon/modules/container/restart_manager/restartmanager.c
+1
-1
src/daemon/modules/container/restore/restore.c
src/daemon/modules/container/restore/restore.c
+1
-1
src/daemon/modules/container/supervisor/supervisor.c
src/daemon/modules/container/supervisor/supervisor.c
+1
-1
src/daemon/modules/image/CMakeLists.txt
src/daemon/modules/image/CMakeLists.txt
+26
-30
src/daemon/modules/image/embedded/embedded_image.c
src/daemon/modules/image/embedded/embedded_image.c
+1
-42
src/daemon/modules/service/CMakeLists.txt
src/daemon/modules/service/CMakeLists.txt
+12
-0
src/daemon/modules/service/service_container.c
src/daemon/modules/service/service_container.c
+1
-1
src/daemon/modules/service/service_container.h
src/daemon/modules/service/service_container.h
+5
-5
src/daemon/modules/service/service_image.c
src/daemon/modules/service/service_image.c
+115
-0
src/daemon/modules/service/service_image.h
src/daemon/modules/service/service_image.h
+29
-0
test/mocks/container_operator_mock.h
test/mocks/container_operator_mock.h
+1
-1
test/services/execution/execute/execution_extend/CMakeLists.txt
...ervices/execution/execute/execution_extend/CMakeLists.txt
+1
-0
未找到文件。
CMakeLists.txt
浏览文件 @
cfd3ebc2
...
...
@@ -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
...
...
src/cmd/isulad/main.c
浏览文件 @
cfd3ebc2
...
...
@@ -51,7 +51,7 @@
#include "callback.h"
#include "log_gather.h"
#include "containers_store.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include "plugin.h"
#include "selinux_label.h"
#include "http.h"
...
...
src/daemon/entry/cri/cri_image_service.cc
浏览文件 @
cfd3ebc2
...
...
@@ -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
,
&
respon
se
)
!=
0
)
{
if
(
response
!=
nullptr
&&
response
->
errmsg
!=
nullptr
)
{
error
.
SetError
(
response
->
errmsg
);
if
(
delete_image
(
request
->
image
.
image
,
fal
se
)
!=
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
;
}
...
...
src/daemon/executor/container_cb/execution.c
浏览文件 @
cfd3ebc2
...
...
@@ -51,7 +51,7 @@
#include "error.h"
#include "event_sender.h"
#include "specs.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
static
int
filter_by_label
(
const
container_t
*
cont
,
const
container_get_id_request
*
request
)
{
...
...
src/daemon/executor/container_cb/execution_create.c
浏览文件 @
cfd3ebc2
...
...
@@ -45,7 +45,7 @@
#include "namespace.h"
#include "event_sender.h"
#include "sysinfo.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
static
int
runtime_check
(
const
char
*
name
,
bool
*
runtime_res
)
{
...
...
src/daemon/executor/container_cb/execution_extend.c
浏览文件 @
cfd3ebc2
...
...
@@ -36,7 +36,7 @@
#include "verify.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include "sysinfo.h"
#include "specs.h"
#include "runtime.h"
...
...
src/daemon/executor/container_cb/execution_stream.c
浏览文件 @
cfd3ebc2
...
...
@@ -44,7 +44,7 @@
#include "constants.h"
#include "runtime.h"
#include "event_sender.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include "io_handler.h"
struct
container_log_config
{
...
...
src/daemon/executor/container_cb/io_handler.c
浏览文件 @
cfd3ebc2
...
...
@@ -44,7 +44,7 @@
#include "constants.h"
#include "runtime.h"
#include "event_sender.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
static
char
*
create_single_fifo
(
const
char
*
statepath
,
const
char
*
subpath
,
const
char
*
stdflag
)
{
...
...
src/daemon/executor/image_cb/image_cb.c
浏览文件 @
cfd3ebc2
...
...
@@ -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
;
...
...
src/daemon/modules/CMakeLists.txt
浏览文件 @
cfd3ebc2
...
...
@@ -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
...
...
src/daemon/modules/container/container_events_handler.c
浏览文件 @
cfd3ebc2
...
...
@@ -27,7 +27,7 @@
#include "container_events_handler.h"
#include "utils.h"
#include "containers_store.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include "plugin.h"
/* events handler lock */
...
...
src/daemon/modules/container/container_gc/containers_gc.c
浏览文件 @
cfd3ebc2
...
...
@@ -23,7 +23,7 @@
#include "isula_libutils/container_garbage_config.h"
#include "isula_libutils/log.h"
#include "utils.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include "containers_store.h"
#include "runtime.h"
...
...
src/daemon/modules/container/health_check/health_check.c
浏览文件 @
cfd3ebc2
...
...
@@ -26,7 +26,7 @@
#include "utils.h"
#include "health_check.h"
#include "callback.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include "isula_libutils/container_exec_request.h"
#include "isula_libutils/container_exec_response.h"
#include "containers_store.h"
...
...
src/daemon/modules/container/restart_manager/restartmanager.c
浏览文件 @
cfd3ebc2
...
...
@@ -27,7 +27,7 @@
#include "restartmanager.h"
#include "utils.h"
#include "containers_store.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#define backoffMultipulier 2U
// unit nanos
...
...
src/daemon/modules/container/restore/restore.c
浏览文件 @
cfd3ebc2
...
...
@@ -29,7 +29,7 @@
#include "error.h"
#include "image.h"
#include "runtime.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
/* restore supervisor */
static
int
restore_supervisor
(
const
container_t
*
cont
)
...
...
src/daemon/modules/container/supervisor/supervisor.c
浏览文件 @
cfd3ebc2
...
...
@@ -24,7 +24,7 @@
#include "libisulad.h"
#include "event_sender.h"
#include "containers_gc.h"
#include "
container_operato
r.h"
#include "
service_containe
r.h"
pthread_mutex_t
g_supervisor_lock
=
PTHREAD_MUTEX_INITIALIZER
;
struct
epoll_descr
g_supervisor_descr
;
...
...
src/daemon/modules/image/CMakeLists.txt
浏览文件 @
cfd3ebc2
...
...
@@ -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
)
src/daemon/modules/image/embedded/embedded_image.c
浏览文件 @
cfd3ebc2
...
...
@@ -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
)
...
...
src/daemon/modules/service/CMakeLists.txt
0 → 100644
浏览文件 @
cfd3ebc2
# 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
)
src/daemon/modules/
container/container_operato
r.c
→
src/daemon/modules/
service/service_containe
r.c
浏览文件 @
cfd3ebc2
...
...
@@ -13,7 +13,7 @@
* Description: provide container supervisor functions
******************************************************************************/
#define _GNU_SOURCE
#include "
container_operato
r.h"
#include "
service_containe
r.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
...
...
src/daemon/modules/
container/container_operato
r.h
→
src/daemon/modules/
service/service_containe
r.h
浏览文件 @
cfd3ebc2
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 20
17-2019
. All rights reserved.
* Copyright (c) Huawei Technologies Co., Ltd. 20
20
. 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:
tany
ifeng
* Create: 20
17-11
-22
* Author:
l
ifeng
* Create: 20
20-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"
...
...
src/daemon/modules/service/service_image.c
0 → 100644
浏览文件 @
cfd3ebc2
/******************************************************************************
* 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
;
}
src/daemon/modules/service/service_image.h
0 → 100644
浏览文件 @
cfd3ebc2
/******************************************************************************
* 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
test/mocks/container_operator_mock.h
浏览文件 @
cfd3ebc2
...
...
@@ -17,7 +17,7 @@
#define CONTAINERS_OPERATOR_MOCK_H_
#include <gmock/gmock.h>
#include "
container_operato
r.h"
#include "
service_containe
r.h"
class
MockContainersOperator
{
public:
...
...
test/services/execution/execute/execution_extend/CMakeLists.txt
浏览文件 @
cfd3ebc2
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录