iSulad: update to v2.0.9

Signed-off-by: wujing <wujing50@huawei.com>
This commit is contained in:
wujing 2021-06-24 17:17:16 +08:00
parent 00f4cca371
commit dcecb6d076
106 changed files with 11 additions and 17329 deletions

View File

@ -1,32 +0,0 @@
From 1ef7a43907ac6fc521cedd2b4744be4d102efd32 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 31 Dec 2020 14:05:25 +0800
Subject: [PATCH 01/53] make thread detach to avoid resource leak
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/daemon/modules/image/oci/registry/registry.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c
index 391af4fb..3fba2039 100644
--- a/src/daemon/modules/image/oci/registry/registry.c
+++ b/src/daemon/modules/image/oci/registry/registry.c
@@ -1389,6 +1389,14 @@ static void *register_layers_in_thread(void *arg)
size_t i = 0;
struct timespec ts = {0};
+ ret = pthread_detach(pthread_self());
+ if (ret != 0) {
+ ERROR("Set thread detach fail");
+ goto out;
+ }
+
+ prctl(PR_SET_NAME, "register_layer");
+
for (i = 0; i < desc->layers_len; i++) {
mutex_lock(&desc->mutex);
while (wait_fetch_complete(&infos[i])) {
--
2.25.1

View File

@ -1,134 +0,0 @@
From 025416aae9f7eaaa8fe5ad52ecbbf6692505186b Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Thu, 31 Dec 2020 14:31:12 +0800
Subject: [PATCH 02/53] devmapper: fix udev wait thread resource leak
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../graphdriver/devmapper/driver_devmapper.c | 2 +-
.../graphdriver/devmapper/wrapper_devmapper.c | 35 +++++++++++--------
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
index ab60845d..f2586f0d 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
@@ -216,7 +216,7 @@ char *devmapper_mount_layer(const char *id, const struct graphdriver *driver,
}
if (mount_device(id, mnt_point_dir, mount_opts, driver->devset) != 0) {
- ERROR("Mount device:%s to path:%s failed", id, mnt_parent_dir);
+ ERROR("Mount device:%s to path:%s failed", id, mnt_point_dir);
ret = -1;
goto out;
}
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
index 112e2b73..1dcdf595 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
@@ -358,28 +358,32 @@ out:
static void *udev_wait_process(void *data)
{
+ int ret = 0;
udev_wait_pth_t *uwait = (udev_wait_pth_t *)data;
- if (dm_udev_wait(uwait->cookie) != 1) {
- pthread_mutex_lock(&uwait->udev_mutex);
- uwait->state = ERR_UDEV_WAIT;
- pthread_mutex_unlock(&uwait->udev_mutex);
- DAEMON_CLEAR_ERRMSG();
- pthread_exit((void *)ERR_UDEV_WAIT);
+ if (pthread_detach(pthread_self()) != 0) {
+ CRIT("Start: set thread detach fail");
+ goto out;
}
+ ret = dm_udev_wait(uwait->cookie);
pthread_mutex_lock(&uwait->udev_mutex);
- uwait->state = DEV_OK;
+ if (ret != 1) {
+ uwait->state = ERR_UDEV_WAIT;
+ } else {
+ uwait->state = DEV_OK;
+ }
pthread_mutex_unlock(&uwait->udev_mutex);
+
+out:
DAEMON_CLEAR_ERRMSG();
- pthread_exit((void *)0);
+ return NULL;
}
// UdevWait waits for any processes that are waiting for udev to complete the specified cookie.
void dev_udev_wait(uint32_t cookie)
{
pthread_t tid;
- int thread_result = 0;
udev_wait_pth_t *uwait = NULL;
float timeout = 0;
struct timeval start, end;
@@ -403,7 +407,7 @@ void dev_udev_wait(uint32_t cookie)
}
if (pthread_create(&tid, NULL, udev_wait_process, uwait) != 0) {
- ERROR("devmapper: create udev wait process thread failed");
+ ERROR("devmapper: create udev wait process thread error:%s", strerror(errno));
goto free_out;
}
@@ -419,15 +423,14 @@ void dev_udev_wait(uint32_t cookie)
ERROR("devmapper: get time failed");
goto free_out;
}
+
timeout = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000; // seconds
if (timeout >= (float)dm_udev_wait_timeout) {
if (dm_udev_complete(cookie) != 1) {
ERROR("Failed to complete udev cookie %u on udev wait timeout", cookie);
goto free_out;
}
- INFO("devmapper: udev wait join thread start...");
- pthread_join(tid, (void *)&thread_result);
- INFO("devmapper: udev wait join thread end exit %d", thread_result);
+ ERROR("Wait on udev cookie time out");
break;
}
}
@@ -482,6 +485,7 @@ int dev_delete_device_force(const char *name)
}
udev:
+ DEBUG("Start udev wait on delete device force");
dev_udev_wait(cookie);
out:
@@ -536,6 +540,7 @@ int dev_remove_device_deferred(const char *name)
}
udev:
+ DEBUG("Start udev wait on remove device deferred");
dev_udev_wait(cookie);
out:
if (dmt != NULL) {
@@ -825,6 +830,7 @@ int dev_resume_device(const char *dm_name)
ret = -1;
}
+ DEBUG("Start udev wait on resume device");
dev_udev_wait(cookie);
out:
@@ -886,7 +892,8 @@ int dev_active_device(const char *pool_name, const char *name, int device_id, ui
ERROR("devicemapper: error running deviceCreate (ActivateDevice) %d", ret);
ret = -1;
}
-
+
+ DEBUG("Start udev wait on create device");
dev_udev_wait(cookie);
out:
if (dmt != NULL) {
--
2.25.1

View File

@ -1,61 +0,0 @@
From 200f49ff353ee8266505316659493ffc4082c803 Mon Sep 17 00:00:00 2001
From: lifeng68 <lifeng68@huawei.com>
Date: Tue, 5 Jan 2021 18:48:20 +0800
Subject: [PATCH 03/53] clean code: fix clean code
Signed-off-by: lifeng68 <lifeng68@huawei.com>
---
.../layer_store/graphdriver/devmapper/wrapper_devmapper.c | 2 +-
src/utils/console/console.c | 2 +-
src/utils/cutils/utils.c | 2 --
3 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
index 1dcdf595..5748ec54 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
@@ -892,7 +892,7 @@ int dev_active_device(const char *pool_name, const char *name, int device_id, ui
ERROR("devicemapper: error running deviceCreate (ActivateDevice) %d", ret);
ret = -1;
}
-
+
DEBUG("Start udev wait on create device");
dev_udev_wait(cookie);
out:
diff --git a/src/utils/console/console.c b/src/utils/console/console.c
index cb748196..7fda519c 100644
--- a/src/utils/console/console.c
+++ b/src/utils/console/console.c
@@ -68,7 +68,7 @@ static int console_cb_tty_stdin_with_escape(int fd, uint32_t events, void *cbdat
}
if (c == 'q' && ts->saw_tty_exit) {
- ret = 1;
+ ret = EPOLL_LOOP_HANDLE_CLOSE;
goto out;
}
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
index 1e777dc3..9107f540 100644
--- a/src/utils/cutils/utils.c
+++ b/src/utils/cutils/utils.c
@@ -493,7 +493,6 @@ out:
static void set_stderr_buf(char **stderr_buf, const char *format, ...)
{
char errbuf[BUFSIZ + 1] = { 0 };
- char *jerr = NULL;
UTIL_FREE_AND_SET_NULL(*stderr_buf);
@@ -511,7 +510,6 @@ static void set_stderr_buf(char **stderr_buf, const char *format, ...)
if (*stderr_buf == NULL) {
*stderr_buf = util_strdup_s(errbuf);
}
- free(jerr);
}
static int open_devnull(void)
--
2.25.1

View File

@ -1,29 +0,0 @@
From c0b6c4187a3c66bef8b75a63e699df1be57d05b4 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Mon, 11 Jan 2021 18:29:26 +0800
Subject: [PATCH 04/53] judge isula load file exists
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
src/cmd/isula/images/load.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/cmd/isula/images/load.c b/src/cmd/isula/images/load.c
index 343d8d6d..0fb8014e 100644
--- a/src/cmd/isula/images/load.c
+++ b/src/cmd/isula/images/load.c
@@ -162,6 +162,11 @@ int cmd_load_main(int argc, const char **argv)
g_cmd_load_args.file = file;
}
+ if (!util_file_exists(g_cmd_load_args.file)) {
+ COMMAND_ERROR("File %s is not exist", g_cmd_load_args.file);
+ exit(exit_code);
+ }
+
ret = client_load_image(&g_cmd_load_args);
if (ret) {
exit(exit_code);
--
2.25.1

View File

@ -1,29 +0,0 @@
From e151821a1e092995836631b273bddc339cadffbe Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Mon, 11 Jan 2021 18:33:39 +0800
Subject: [PATCH 05/53] modify image_load.sh CI to test file not exist
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
CI/test_cases/image_cases/image_load.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CI/test_cases/image_cases/image_load.sh b/CI/test_cases/image_cases/image_load.sh
index 8415e036..bf41f2af 100755
--- a/CI/test_cases/image_cases/image_load.sh
+++ b/CI/test_cases/image_cases/image_load.sh
@@ -30,6 +30,11 @@ function test_image_load()
local test="isula load image test => (${FUNCNAME[@]})"
msg_info "${test} starting..."
+
+ # file is not exist, expect fail
+ isula load -i xxx.tar
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - image tar file not exist test failed" && ((ret++))
+
# single image without --tag
isula load -i $single_image
--
2.25.1

File diff suppressed because it is too large Load Diff

View File

@ -1,157 +0,0 @@
From 085b93daf8f080f21b304058da3af404be9ac61d Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Fri, 8 Jan 2021 14:02:00 +0800
Subject: [PATCH 07/53] add testcases for isula cp
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/container_cases/cp.sh | 93 ++++++++++++++++++++++++++++-
1 file changed, 90 insertions(+), 3 deletions(-)
diff --git a/CI/test_cases/container_cases/cp.sh b/CI/test_cases/container_cases/cp.sh
index dfbd222f..67a36909 100644
--- a/CI/test_cases/container_cases/cp.sh
+++ b/CI/test_cases/container_cases/cp.sh
@@ -163,6 +163,7 @@ test_cp_file_to_container()
return ${ret}
}
+
test_cp_dir_to_container()
{
local ret=0
@@ -194,6 +195,66 @@ test_cp_dir_to_container()
isula exec $containername /bin/sh -c "ls $dstfile/passwd"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to do copy" && ((ret++))
+ # test copy dir with hardlink
+ rm -rf $cpfiles/a
+ mkdir -p $cpfiles/a/a $cpfiles/a/b
+ echo "test_hardlink_a" > $cpfiles/a/a/a
+ ln $cpfiles/a/a/a $cpfiles/a/b/b
+ isula cp $cpfiles/a $containername:/c
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to do copy" && ((ret++))
+
+ isula exec -ti $containername cat /c/a/a | grep "test_hardlink_a"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - copy hardlink a not right" && ((ret++))
+
+ isula exec -ti $containername cat /c/b/b | grep "test_hardlink_a"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - copy hardlink b not right" && ((ret++))
+ rm -rf $cpfiles/a
+
+ # test copy dir to file
+ mkdir -p $cpfiles/dst
+ isula exec -ti $containername sh -c 'touch /dst'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to touch file in container" && ((ret++))
+
+ isula cp $cpfiles/dst $containername:/
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - copy dir to container failed" && ((ret++))
+
+ isula exec -ti $containername stat / | grep directory
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - file should be replaced to be dir" && ((ret++))
+ rm -rf $cpfiles/dir
+
+ # test copy current dir file
+ touch $cpfiles/current
+ cd $cpfiles
+ isula cp . $containername:/current1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cp current1 file" && ((ret++))
+
+ isula exec -ti $containername stat /current1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - file current1 not exist" && ((ret++))
+
+ isula cp ./ $containername:/current2
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cp current2 file" && ((ret++))
+
+ isula exec -ti $containername stat /current2
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - file current2 not exist" && ((ret++))
+ cd -
+ rm -f $cpfiles/current
+
+ # test copy perm
+ mkdir -p $cpfiles/perm && chmod 700 $cpfiles/perm
+ isula cp $cpfiles/perm $containername:/
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cp dir to container" && ((ret++))
+
+ isula exec -ti $containername stat /perm | grep "Access: (0700/drwx"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - copy perm not right" && ((ret++))
+ rm -f $cpfiles/perm
+
+ # test copy hardlink
+ rm -rf $cpfiles/cp_dir
+ mkdir $cpfiles/cp_dir && cd $cpfiles/cp_dir && echo hello > norm_file && ln norm_file norm_file_link && cd -
+ isula cp $cpfiles/cp_dir $containername:/home/
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - copy hardlink failed" && ((ret++))
+ rm -rf $cpfiles/cp_dir
+
return ${ret}
}
@@ -227,6 +288,17 @@ test_cp_symlink_to_container()
isula exec $containername /bin/sh -c "cat $cpfiles/target | grep root"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to do copy" && ((ret++))
+ # test cp symlink with dir which have the same name prefix
+ rm -rf $cpfiles/abc $cpfiles/a
+ ln -s $cpfiles/abc $cpfiles/a
+
+ isula cp $cpfiles/a $containername:/b
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to copy symlink" && ((ret++))
+
+ isula exec -ti $containername readlink /b | grep "$cpfiles/abc"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid symlink" && ((ret++))
+ rm -f $cpfiles/abc $cpfiles/a
+
return ${ret}
}
@@ -256,14 +328,21 @@ function cp_test_t()
msg_info "${test} starting..."
- isula pull ${image}
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+ local isulad_pid=$(cat /var/run/isulad.pid)
+ local fd_num1=$(ls -l /proc/$isulad_pid/fd | wc -l)
+ [[ $fd_num1 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
+
+ isula inspect ${image}
+ if [ x"$?" != x"0" ];then
+ isula pull ${image}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+ fi
isula images | grep busybox
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
containername=test_cmd_cp
- isula run -n $containername -itd $image
+ isula run -n $containername -itd $image
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container: ${image}" && ((ret++))
rm -rf $cpfiles
@@ -274,6 +353,7 @@ function cp_test_t()
test_cp_file_from_container $containername || ((ret++))
test_cp_dir_from_container $containername || ((ret++))
test_cp_file_to_container $containername || ((ret++))
+ test_cp_dir_to_container $containername || ((ret++))
test_cp_symlink_to_container $containername || ((ret++))
test_cp_symlink_from_container $containername || ((ret++))
@@ -281,6 +361,13 @@ function cp_test_t()
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container: ${containername}" && ((ret++))
rm -rf $cpfiles
+
+ local fd_num2=$(ls -l /proc/$isulad_pid/fd | wc -l)
+ [[ $fd_num2 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
+
+ # make sure fd not increase after test
+ [[ $fd_num1 -ne $fd_num2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - fd number not right" && ((ret++))
+
echo "test end"
return ${ret}
}
--
2.25.1

View File

@ -1,107 +0,0 @@
From c8d14980e145a7d400aa6c5b449a59952a422801 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Fri, 15 Jan 2021 10:34:43 +0800
Subject: [PATCH 08/53] image_cb: rename the function {isula_/docker_} to do_
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/executor/image_cb/image_cb.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/daemon/executor/image_cb/image_cb.c b/src/daemon/executor/image_cb/image_cb.c
index 6ab8067f..156cf88c 100644
--- a/src/daemon/executor/image_cb/image_cb.c
+++ b/src/daemon/executor/image_cb/image_cb.c
@@ -54,7 +54,7 @@
#include "utils_timestamp.h"
#include "utils_verify.h"
-static int isula_import_image(const char *file, const char *tag, char **id)
+static int do_import_image(const char *file, const char *tag, char **id)
{
int ret = 0;
im_import_request *request = NULL;
@@ -114,7 +114,7 @@ static int import_cb(const image_import_request *request, image_import_response
EVENT("Image Event: {Object: %s, Type: Importing}", request->file);
- ret = isula_import_image(request->file, request->tag, &id);
+ ret = do_import_image(request->file, request->tag, &id);
if (ret != 0) {
ERROR("Failed to import docker image %s with tag %s", request->file, request->tag);
cc = EINVALIDARGS;
@@ -140,7 +140,7 @@ out:
return (ret < 0) ? ECOMMON : ret;
}
-static int docker_load_image(const char *file, const char *tag, const char *type)
+static int do_load_image(const char *file, const char *tag, const char *type)
{
int ret = 0;
im_load_request *request = NULL;
@@ -210,7 +210,7 @@ static int image_load_cb(const image_load_image_request *request, image_load_ima
EVENT("Image Event: {Object: %s, Type: Loading}", request->file);
- ret = docker_load_image(request->file, request->tag, request->type);
+ ret = do_load_image(request->file, request->tag, request->type);
if (ret != 0) {
ERROR("Failed to load docker image %s with tag %s and type %s", request->file, request->tag, request->type);
cc = EINVALIDARGS;
@@ -233,7 +233,7 @@ out:
return (ret < 0) ? ECOMMON : ret;
}
-static int docker_login(const char *username, const char *password, const char *server, const char *type)
+static int do_login(const char *username, const char *password, const char *server, const char *type)
{
int ret = 0;
im_login_request *request = NULL;
@@ -290,7 +290,7 @@ static int login_cb(const image_login_request *request, image_login_response **r
EVENT("Image Event: {Object: %s, Type: Logining}", request->server);
- ret = docker_login(request->username, request->password, request->server, request->type);
+ ret = do_login(request->username, request->password, request->server, request->type);
if (ret != 0) {
ERROR("Failed to login %s", request->server);
cc = EINVALIDARGS;
@@ -312,7 +312,7 @@ out:
return (ret < 0) ? ECOMMON : ret;
}
-static int docker_logout(const char *server, const char *type)
+static int do_logout(const char *server, const char *type)
{
int ret = 0;
im_logout_request *request = NULL;
@@ -367,7 +367,7 @@ static int logout_cb(const image_logout_request *request, image_logout_response
EVENT("Image Event: {Object: %s, Type: Logouting}", request->server);
- ret = docker_logout(request->server, request->type);
+ ret = do_logout(request->server, request->type);
if (ret != 0) {
ERROR("Failed to logout %s", request->server);
cc = EINVALIDARGS;
@@ -442,7 +442,7 @@ out:
}
/* tag image */
-static int tag_image(const char *src_name, const char *dest_name)
+static int do_tag_image(const char *src_name, const char *dest_name)
{
int ret = 0;
im_tag_request *im_request = NULL;
@@ -524,7 +524,7 @@ static int image_tag_cb(const image_tag_image_request *request, image_tag_image_
EVENT("Image Event: {Object: %s, Type: Tagging}", src_name);
- ret = tag_image(src_name, dest_name);
+ ret = do_tag_image(src_name, dest_name);
if (ret != 0) {
cc = ISULAD_ERR_EXEC;
goto out;
--
2.25.1

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +0,0 @@
From 7e04901403a0053f67eae6c9bb58764b529c0bd8 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Tue, 19 Jan 2021 16:57:17 +0800
Subject: [PATCH 10/53] fix ramdom coredump if pull failed
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/daemon/modules/image/oci/registry/registry.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c
index 3fba2039..1bb91d0f 100644
--- a/src/daemon/modules/image/oci/registry/registry.c
+++ b/src/daemon/modules/image/oci/registry/registry.c
@@ -1298,8 +1298,10 @@ static void free_thread_fetch_info(thread_fetch_info *info)
return;
}
-static bool all_fetch_complete(pull_descriptor *desc, int *result)
+static bool all_fetch_complete(pull_descriptor *desc, thread_fetch_info *infos, int *result)
{
+ int i = 0;
+
if (!desc->config.complete) {
return false;
}
@@ -1314,6 +1316,13 @@ static bool all_fetch_complete(pull_descriptor *desc, int *result)
return false;
}
+ // wait all fetch threads completed
+ for (i = 0; i < desc->layers_len; i++) {
+ if (infos[i].use && !infos[i].notified) {
+ return false;
+ }
+ }
+
if (desc->cancel) {
*result = -1;
}
@@ -1584,7 +1593,7 @@ static int fetch_all(pull_descriptor *desc)
// wait until all pulled or cancelled
mutex_lock(&g_shared->mutex);
- while (!all_fetch_complete(desc, &result)) {
+ while (!all_fetch_complete(desc, infos, &result)) {
ts.tv_sec = time(NULL) + DEFAULT_WAIT_TIMEOUT; // avoid wait forever
cond_ret = pthread_cond_timedwait(&g_shared->cond, &g_shared->mutex, &ts);
if (cond_ret != 0 && cond_ret != ETIMEDOUT) {
--
2.25.1

View File

@ -1,257 +0,0 @@
From bbf3f17765483e2e87e96e975c1d85bb5250c8f2 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Wed, 20 Jan 2021 10:13:14 +0800
Subject: [PATCH 11/53] shim: optimize io stream
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
src/cmd/isulad-shim/common.c | 25 ++++++++++++++
src/cmd/isulad-shim/common.h | 2 ++
src/cmd/isulad-shim/process.c | 48 ++++++++++++++++----------
src/cmd/isulad-shim/process.h | 6 ++--
src/cmd/isulad-shim/terminal.c | 2 +-
test/cmd/isulad-shim/isulad-shim_ut.cc | 2 +-
6 files changed, 61 insertions(+), 24 deletions(-)
diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c
index 23aa33cd..324d72a1 100644
--- a/src/cmd/isulad-shim/common.c
+++ b/src/cmd/isulad-shim/common.c
@@ -84,6 +84,31 @@ ssize_t write_nointr(int fd, const void *buf, size_t count)
return nret;
}
+ssize_t write_nointr_in_total(int fd, const char *buf, size_t count)
+{
+ ssize_t nret = 0;
+ ssize_t nwritten;
+
+ if (buf == NULL) {
+ return -1;
+ }
+
+ for (nwritten = 0; nwritten < count;) {
+ nret = write(fd, buf + nwritten, count - nwritten);
+ if (nret < 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ } else {
+ return nret;
+ }
+ } else {
+ nwritten += nret;
+ }
+ }
+
+ return nwritten;
+}
+
bool file_exists(const char *f)
{
struct stat buf;
diff --git a/src/cmd/isulad-shim/common.h b/src/cmd/isulad-shim/common.h
index b83d72ba..8c6ea7ba 100644
--- a/src/cmd/isulad-shim/common.h
+++ b/src/cmd/isulad-shim/common.h
@@ -52,6 +52,8 @@ extern "C" {
ssize_t read_nointr(int fd, void *buf, size_t count);
ssize_t write_nointr(int fd, const void *buf, size_t count);
+ssize_t write_nointr_in_total(int fd, const char *buf, size_t count);
+
char *read_text_file(const char *path);
bool file_exists(const char *f);
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
index 606a3df7..3ac739b9 100644
--- a/src/cmd/isulad-shim/process.c
+++ b/src/cmd/isulad-shim/process.c
@@ -44,15 +44,6 @@
extern int g_log_fd;
-typedef int (*epoll_loop_callback_t)(int fd, uint32_t event, void *data);
-
-struct epoll_loop_handler {
- epoll_loop_callback_t cb;
- int epfd;
- int cbfd;
- void *cbdata;
-};
-
static shim_client_process_state *load_process()
{
parser_error err = NULL;
@@ -243,7 +234,7 @@ static void remove_io_dispatch(io_thread_t *io_thd, int from, int to)
pthread_mutex_unlock(&(ioc->mutex));
}
-static void *task_io_copy(void *data)
+static void *do_io_copy(void *data)
{
io_thread_t *io_thd = (io_thread_t *)data;
if (io_thd == NULL || io_thd->ioc == NULL) {
@@ -278,7 +269,7 @@ static void *task_io_copy(void *data)
shim_write_container_log_file(io_thd->terminal, ioc->id == stdid_out ? "stdout" : "stderr", buf,
r_count);
} else {
- int w_count = write_nointr(fn->fd, buf, r_count);
+ int w_count = write_nointr_in_total(fn->fd, buf, r_count);
if (w_count < 0) {
/* When any error occurs, remove the write fd */
remove_io_dispatch(io_thd, -1, fn->fd);
@@ -287,7 +278,11 @@ static void *task_io_copy(void *data)
}
}
- if (io_thd->shutdown) {
+ /*
+ In the case of stdout and stderr, maybe numbers of read bytes are not the last msg in pipe.
+ So, when the value of r_count is larger than zero, we need to try reading again to avoid loss msgs.
+ */
+ if (io_thd->shutdown && r_count <= 0) {
break;
}
}
@@ -301,7 +296,7 @@ static void *task_io_copy(void *data)
return NULL;
}
-static void do_io_copy(int fd, uint32_t event, void *data)
+static void sem_post_inotify_io_copy(int fd, uint32_t event, void *data)
{
io_thread_t *thd = (io_thread_t *)data;
if (thd->ioc == NULL || fd != thd->ioc->fd_from) {
@@ -318,7 +313,7 @@ static void do_io_copy(int fd, uint32_t event, void *data)
return;
}
-static int process_io_start(process_t *p, int std_id)
+static int create_io_copy_thread(process_t *p, int std_id)
{
int ret = SHIM_ERR;
io_thread_t *io_thd = NULL;
@@ -351,7 +346,7 @@ static int process_io_start(process_t *p, int std_id)
p->io_threads[std_id] = io_thd;
- ret = pthread_create(&(io_thd->tid), NULL, task_io_copy, io_thd);
+ ret = pthread_create(&(io_thd->tid), NULL, do_io_copy, io_thd);
if (ret != SHIM_OK) {
write_message(g_log_fd, ERR_MSG, "thread io copy create failed:%d", SHIM_SYS_ERR(errno));
goto failure;
@@ -380,7 +375,7 @@ static int start_io_copy_threads(process_t *p)
/* 3 threads for stdin, stdout and stderr */
for (i = 0; i < 3; i++) {
- ret = process_io_start(p, i);
+ ret = create_io_copy_thread(p, i);
if (ret != SHIM_OK) {
return SHIM_ERR;
}
@@ -405,6 +400,20 @@ static void destroy_io_thread(process_t *p, int std_id)
p->io_threads[std_id] = NULL;
}
+/*
+ std_id: channel type
+ isulad_stdio: one side of the isulad fifo file
+ fd: one side of the shim io pipe
+ ---------------------------------------------------------------
+ | CHANNEL | iSulad Fifo Side | Flow Direction | fd |
+ ---------------------------------------------------------------
+ | STDIN | READ | --> | WRITE |
+ ---------------------------------------------------------------
+ | STDOUT | WRITE | <-- | READ |
+ ---------------------------------------------------------------
+ | STDERR | WRITE | <-- | READ |
+ ---------------------------------------------------------------
+*/
static int connect_to_isulad(process_t *p, int std_id, const char *isulad_stdio, int fd)
{
mode_t mode;
@@ -501,7 +510,7 @@ out:
return NULL;
}
-static void *task_io_loop(void *data)
+static void *io_epoll_loop(void *data)
{
process_t *p = (process_t *)data;
int wait_fds = 0;
@@ -526,7 +535,7 @@ static void *task_io_loop(void *data)
for (i = 0; i < wait_fds; i++) {
io_thread_t *thd_io = (io_thread_t *)evs[i].data.ptr;
- do_io_copy(thd_io->ioc->fd_from, evs[i].events, thd_io);
+ sem_post_inotify_io_copy(thd_io->ioc->fd_from, evs[i].events, thd_io);
}
}
}
@@ -702,6 +711,7 @@ static int open_generic_io(process_t *p)
{
int ret = SHIM_ERR;
+ // io: in: w out/err: r
stdio_t *io = initialize_io(p);
if (io == NULL) {
return SHIM_ERR;
@@ -858,7 +868,7 @@ int process_io_init(process_t *p)
int ret = SHIM_ERR;
pthread_t tid_loop;
- ret = pthread_create(&tid_loop, NULL, task_io_loop, p);
+ ret = pthread_create(&tid_loop, NULL, io_epoll_loop, p);
if (ret != SHIM_OK) {
return SHIM_SYS_ERR(errno);
}
diff --git a/src/cmd/isulad-shim/process.h b/src/cmd/isulad-shim/process.h
index 17704320..c17a20b1 100644
--- a/src/cmd/isulad-shim/process.h
+++ b/src/cmd/isulad-shim/process.h
@@ -66,13 +66,13 @@ typedef struct process {
char *id;
char *bundle;
char *runtime;
- char *console_sock_path;
+ char *console_sock_path;// pty socket path
int io_loop_fd;
int exit_fd;
int ctr_pid;
log_terminal *terminal;
- stdio_t *stdio;
- stdio_t *shim_io;
+ stdio_t *stdio;// shim to on runtime side, in:r out/err: w
+ stdio_t *shim_io; // shim io on isulad side, in: w out/err: r
io_thread_t *io_threads[3];// stdin,stdout,stderr
shim_client_process_state *state;
sem_t sem_mainloop;
diff --git a/src/cmd/isulad-shim/terminal.c b/src/cmd/isulad-shim/terminal.c
index 989f20d8..ac39539a 100644
--- a/src/cmd/isulad-shim/terminal.c
+++ b/src/cmd/isulad-shim/terminal.c
@@ -38,7 +38,7 @@ static ssize_t shim_write_nointr_lock(log_terminal *terminal, const void *buf, s
ssize_t ret;
(void)pthread_rwlock_wrlock(&terminal->log_terminal_rwlock);
- ret = write_nointr(terminal->fd, buf, count);
+ ret = write_nointr_in_total(terminal->fd, buf, count);
(void)pthread_rwlock_unlock(&terminal->log_terminal_rwlock);
return ret;
diff --git a/test/cmd/isulad-shim/isulad-shim_ut.cc b/test/cmd/isulad-shim/isulad-shim_ut.cc
index d512f0bc..34ecd452 100644
--- a/test/cmd/isulad-shim/isulad-shim_ut.cc
+++ b/test/cmd/isulad-shim/isulad-shim_ut.cc
@@ -79,7 +79,7 @@ TEST_F(IsuladShimUnitTest, test_read_write_nointr)
fd_wr = open_no_inherit(test_file.c_str(), O_CREAT | O_RDWR | O_APPEND | O_SYNC, 0640);
EXPECT_GT(fd_wr, 0);
- nwrite = write_nointr(fd_wr, test_string.c_str(), 5);
+ nwrite = write_nointr_in_total(fd_wr, test_string.c_str(), 5);
EXPECT_EQ(nwrite, 5);
fd_rd = open(test_file.c_str(), O_RDONLY);
nread = read_nointr(fd_rd, buf, 32);
--
2.25.1

View File

@ -1,412 +0,0 @@
From f3f4c25792721bc130aec31deea9473d5283dfc6 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Wed, 20 Jan 2021 10:13:35 +0800
Subject: [PATCH 12/53] add CI to test shim io
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../container_cases/bigdata_stream_runc.sh | 392 ++++++++++++++++++
1 file changed, 392 insertions(+)
create mode 100755 CI/test_cases/container_cases/bigdata_stream_runc.sh
diff --git a/CI/test_cases/container_cases/bigdata_stream_runc.sh b/CI/test_cases/container_cases/bigdata_stream_runc.sh
new file mode 100755
index 00000000..203bdd98
--- /dev/null
+++ b/CI/test_cases/container_cases/bigdata_stream_runc.sh
@@ -0,0 +1,392 @@
+#!/bin/bash
+#
+# attributes: isulad basic container stream exec start attach
+# concurrent: NA
+# spend time: 6
+
+#######################################################################
+##- @Copyright (C) Huawei Technologies., 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.
+##- @Description:CI
+##- @Author: gaohuatao
+##- @Create: 2021-01-19
+#######################################################################
+declare -r curr_path=$(dirname $(readlink -f "$0"))
+source ../helpers.sh
+
+function set_up()
+{
+ local ret=0
+ local image="busybox"
+ local test="set_up => (${FUNCNAME[@]})"
+
+ msg_info "${test} starting..."
+
+ check_valgrind_log
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - memory leak before current testcase, please check...." && return ${FAILURE}
+
+ start_isulad_without_valgrind
+
+ isula pull ${image}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+
+ isula images | grep busybox
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
+
+ CID=$(isula run -itd --runtime runc ${image} sh)
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
+
+ isula exec -it $CID dd if=/dev/zero of=test_500M bs=1M count=500
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function record_origin_status()
+{
+ origin_isulad_cpu_usage=$(ps -o %cpu -p $(cat /var/run/isulad.pid) | sed -n '2p')
+ msg_info "origin isulad cpu usage: $origin_isulad_cpu_usage"
+
+ lxc_monitor_pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
+ origin_lxc_monitor_cpu_usage=$(ps -o %cpu -p $lxc_monitor_pid | sed -n '2p')
+ msg_info "origin lxc monitor cpu usage: $origin_lxc_monitor_cpu_usage"
+
+ rm -rf /iocopy_stream_data_*
+}
+
+function check_last_status()
+{
+ local ret=0
+ sleep 5
+ ps -T -p $(cat /var/run/isulad.pid) | grep IoCopy
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - IOCopy Thread residue" && ((ret++))
+
+ last_isulad_cpu_usage=$(ps -o %cpu -p $(cat /var/run/isulad.pid) | sed -n '2p')
+ allowable_isulad_cpu_usage=$(echo "$origin_isulad_cpu_usage*2" | bc)
+ if [[ $(echo "$allowable_isulad_cpu_usage < 80.0" | bc) -eq 1 ]]; then
+ allowable_isulad_cpu_usage=80.0
+ fi
+ msg_info "allowable isulad cpu usage: $allowable_isulad_cpu_usage"
+ if [[ $(echo "$last_isulad_cpu_usage > $allowable_isulad_cpu_usage" | bc) -eq 1 ]]; then
+ msg_err "${FUNCNAME[0]}:${LINENO} - Process exception: endless loop or residual thread" && ((ret++))
+ ps -o %cpu -p $(cat /var/run/isulad.pid)
+ fi
+
+ lxc_monintor_pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
+ last_lxc_monitor_cpu_usage=$(ps -o %cpu -p $lxc_monintor_pid | sed -n '2p')
+ allowable_lxc_monitor_cpu_usage=$(echo "$origin_lxc_monitor_cpu_usage*2" | bc)
+ if [[ $(echo "$allowable_lxc_monitor_cpu_usage < 1.0" | bc) -eq 1 ]]; then
+ allowable_lxc_monitor_cpu_usage=1.0
+ fi
+ msg_info "allowable lxc_monitor cpu usage: $allowable_lxc_monitor_cpu_usage"
+ if [[ $(echo "$last_lxc_monitor_cpu_usage > $allowable_lxc_monitor_cpu_usage" | bc) -eq 1 ]]; then
+ msg_err "${FUNCNAME[0]}:${LINENO} - Process exception: endless loop or residual thread" && ((ret++))
+ ps -o %cpu -p $lxc_monintor_pid
+ fi
+
+ lxc_attach_process_number=$(ps aux | grep lxc-attach | grep $CID | wc -l)
+ if [[ $lxc_attach_process_number -ne 0 ]]; then
+ msg_err "${FUNCNAME[0]}:${LINENO} - lxc_attach process residual" && ((ret++))
+ ps aux | grep lxc-attach | grep $CID
+ fi
+
+ client_pid=$(pidof isula)
+ if [[ -n "$client_pid" ]]; then
+ msg_err "${FUNCNAME[0]}:${LINENO} - client not exit!!" && ((ret++))
+ fi
+
+ ps aux | grep "cat test_" | grep -v "grep"
+ if [[ $? -eq 0 ]]; then
+ msg_err "${FUNCNAME[0]}:${LINENO} - business process residual" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cat_bigdata()
+{
+ local ret=0
+ local test="test_concurrent_bigdata_stream => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+ declare -a pids
+
+ for index in $(seq 1 5); do
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ pids[${#pids[@]}]=$!
+ done
+ wait ${pids[*]// /|}
+
+ for index in $(seq 1 5); do
+ ls -l /tmp/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+ rm -f /tmp/iocopy_stream_data_500M_$index
+ done
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_stop_client()
+{
+ local ret=0
+ local test="test_stream_with_stop_client => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ pid=$!
+ sleep 2
+ kill -19 $pid
+ sleep 5
+ kill -18 $pid
+
+ wait $pid
+
+ ls -l /tmp/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_kill_client()
+{
+ local ret=0
+ local test="test_stream_with_kill_client => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ pid=$!
+ sleep 5
+ kill -9 $pid
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_stop_attach()
+{
+ local ret=0
+ local test="test_stream_with_stop_attach => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ exec_pid=$!
+ sleep 2
+ pid=$(ps aux | grep lxc-attach | grep $CID |grep "cat test_500M" | awk '{print $2}')
+ kill -19 $pid
+ sleep 3
+ kill -18 $pid
+
+ wait $exec_pid
+
+ ls -l /tmp/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_kill_attach()
+{
+ local ret=0
+ local test="test_stream_with_kill_client => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ sleep 3
+ pid=$(ps aux | grep lxc-attach | grep $CID |grep "cat test_500M" | awk '{print $2}')
+ kill -9 $pid
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_stop_lxc_monitor()
+{
+ local ret=0
+ local test="test_stream_with_stop_lxc_monitor => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ exec_pid=$!
+ sleep 2
+ pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
+ kill -19 $pid
+ sleep 3
+ kill -18 $pid
+
+ wait $exec_pid
+
+ ls -l /tmp/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_kill_lxc_monitor()
+{
+ local ret=0
+ local test="test_stream_with_kill_lxc_monitor => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ sleep 3
+ pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
+ kill -9 $pid
+ sleep 3
+
+ isula start $CID
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to start container: $CID" && ((ret++))
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_stop_isulad()
+{
+ local ret=0
+ local test="test_stream_with_stop_isulad => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ pid=$!
+ sleep 2
+ kill -19 $(cat /var/run/isulad.pid)
+ sleep 3
+ kill -18 $(cat /var/run/isulad.pid)
+
+ wait $pid
+
+ ls -l /tmp/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_stream_with_kill_isulad()
+{
+ local ret=0
+ local test="test_stream_with_kill_isulad => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ sleep 3
+ isulad_pid=$(cat /var/run/isulad.pid)
+ kill -9 $isulad_pid
+ sleep 1
+
+ check_isulad_stopped $isulad_pid
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - isulad still alive" && ((ret++))
+
+ start_isulad_without_valgrind
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function tear_down()
+{
+ local ret=0
+ isula rm -f $CID
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container: $CID" && ((ret++))
+
+ rm -rf //tmp/iocopy_stream_data_*
+
+ stop_isulad_without_valgrind
+
+ return ${ret}
+}
+
+function test_memory_leak_with_bigdata_stream()
+{
+ local ret=0
+ local image="busybox"
+ local test="test_memory_leak_with_bigdata_stream => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ start_isulad_with_valgrind
+
+ CID=$(isula run -itd ${image} sh)
+
+ isula exec -it $CID dd if=/dev/zero of=test_100M bs=1M count=100
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++))
+
+ isula exec -it $CID cat test_100M > /tmp/iocopy_stream_data_100M
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cat bigdata from container" && ((ret++))
+
+ rm -rf /tmp/iocopy_stream_data_100M
+
+ isula rm -f $CID
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++))
+
+ check_valgrind_log
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - memory leak, please check...." && ((ret++))
+
+
+ start_isulad_with_valgrind
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+declare -i ans=0
+
+set_up || ((ans++))
+
+record_origin_status
+test_cat_bigdata || ((ans++))
+test_stream_with_stop_client || ((ans++))
+test_stream_with_kill_client || ((ans++))
+test_stream_with_stop_attach || ((ans++))
+test_stream_with_kill_attach || ((ans++))
+test_stream_with_stop_lxc_monitor || ((ans++))
+test_stream_with_kill_lxc_monitor || ((ans++))
+test_stream_with_stop_isulad || ((ans++))
+test_stream_with_kill_isulad || ((ans++))
+tear_down || ((ans++))
+
+test_memory_leak_with_bigdata_stream || ((ans++))
+
+show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,106 +0,0 @@
From 0eedc0354deb5616fe7e3308547d475af01d7cc3 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Wed, 20 Jan 2021 14:50:43 +0800
Subject: [PATCH 13/53] CI: add testcase for exec without pty
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
.../container_cases/bigdata_stream.sh | 28 +++++++++++++++++++
.../container_cases/bigdata_stream_runc.sh | 28 +++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/CI/test_cases/container_cases/bigdata_stream.sh b/CI/test_cases/container_cases/bigdata_stream.sh
index d7dd2d18..768e9703 100755
--- a/CI/test_cases/container_cases/bigdata_stream.sh
+++ b/CI/test_cases/container_cases/bigdata_stream.sh
@@ -138,6 +138,33 @@ function test_concurrent_bigdata_stream()
return ${ret}
}
+function test_concurrent_bigdata_stream_without_pty()
+{
+ local ret=0
+ local test="test_concurrent_bigdata_stream => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+ declare -a pids
+
+ for index in $(seq 1 5); do
+ nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ pids[${#pids[@]}]=$!
+ done
+ wait ${pids[*]// /|}
+
+ for index in $(seq 1 5); do
+ ls -l /tmp/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+ rm -f /tmp/iocopy_stream_data_500M_$index
+ done
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
function test_more_concurrent_stream()
{
local ret=0
@@ -432,6 +459,7 @@ set_up || ((ans++))
record_origin_status
test_concurrent_bigdata_stream || ((ans++))
+test_concurrent_bigdata_stream_without_pty || ((ans++))
test_more_concurrent_stream || ((ans++))
test_stream_with_stop_client || ((ans++))
test_stream_with_kill_client || ((ans++))
diff --git a/CI/test_cases/container_cases/bigdata_stream_runc.sh b/CI/test_cases/container_cases/bigdata_stream_runc.sh
index 203bdd98..f6c2ee94 100755
--- a/CI/test_cases/container_cases/bigdata_stream_runc.sh
+++ b/CI/test_cases/container_cases/bigdata_stream_runc.sh
@@ -118,6 +118,33 @@ function test_cat_bigdata()
msg_info "${test} starting..."
declare -a pids
+ for index in $(seq 1 5); do
+ nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ pids[${#pids[@]}]=$!
+ done
+ wait ${pids[*]// /|}
+
+ for index in $(seq 1 5); do
+ ls -l /tmp/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
+ rm -f /tmp/iocopy_stream_data_500M_$index
+ done
+
+ check_last_status
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_cat_bigdata_without_pty()
+{
+ local ret=0
+ local test="test_concurrent_bigdata_stream => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+ declare -a pids
+
for index in $(seq 1 5); do
nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
pids[${#pids[@]}]=$!
@@ -377,6 +404,7 @@ set_up || ((ans++))
record_origin_status
test_cat_bigdata || ((ans++))
+test_cat_bigdata_without_pty || ((ans++))
test_stream_with_stop_client || ((ans++))
test_stream_with_kill_client || ((ans++))
test_stream_with_stop_attach || ((ans++))
--
2.25.1

View File

@ -1,69 +0,0 @@
From 7e9b7b16c76785c15fd1465d7985a0919848f786 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 21 Jan 2021 18:44:52 +0800
Subject: [PATCH 14/53] adapt for sparse file when tar file
archive_read_data_block can not process sparse file
correctly, use archive_read_data instead.
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/utils/tar/util_archive.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c
index 7a28286a..1b9553c9 100644
--- a/src/utils/tar/util_archive.c
+++ b/src/utils/tar/util_archive.c
@@ -699,27 +699,39 @@ out:
static int copy_data_between_archives(struct archive *ar, struct archive *aw)
{
int ret = ARCHIVE_FAILED;
- const void *buff = NULL;
- size_t size;
- int64_t offset;
+ char *buff = NULL;
+ ssize_t size = 0;
+
+ buff = util_common_calloc_s(ARCHIVE_BLOCK_SIZE);
+ if (buff == NULL) {
+ ERROR("out of memory");
+ fprintf(stderr, "out of memory");
+ return ARCHIVE_FAILED;
+ }
for (;;) {
- ret = archive_read_data_block(ar, &buff, &size, &offset);
- if (ret == ARCHIVE_EOF) {
- return ARCHIVE_OK;
+ size = archive_read_data(ar, buff, ARCHIVE_BLOCK_SIZE);
+ if (size == 0) {
+ ret = ARCHIVE_OK;
+ goto out;
}
- if (ret < ARCHIVE_OK) {
+ if (size < 0) {
ERROR("tar archive read result %d, error: %s", ret, archive_error_string(ar));
fprintf(stderr, "tar archive read result %d, error: %s", ret, archive_error_string(ar));
- return ret;
+ ret = ARCHIVE_FAILED;
+ goto out;
}
ret = archive_write_data(aw, buff, size);
if (ret < ARCHIVE_OK) {
ERROR("tar archive write result %d, error: %s", ret, archive_error_string(aw));
fprintf(stderr, "tar archive write result %d, error: %s", ret, archive_error_string(aw));
- return ret;
+ goto out;
}
}
+
+out:
+ free(buff);
+ return ret;
}
int update_entry_for_hardlink(map_t *map_link, struct archive_entry *entry, const char *src_base, const char *dst_base)
--
2.25.1

View File

@ -1,29 +0,0 @@
From bba60af5e275a24ab6ae11943ce48ff71524c494 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Mon, 25 Jan 2021 11:31:54 +0800
Subject: [PATCH 15/53] driver: do not unlock and destroy lock when clean up
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
.../image/oci/storage/layer_store/graphdriver/driver.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
index f2df4f8f..b41132ea 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
@@ -517,9 +517,9 @@ int graphdriver_cleanup(void)
g_graphdriver->home = NULL;
free(g_graphdriver->backing_fs);
g_graphdriver->backing_fs = NULL;
- driver_unlock();
- pthread_rwlock_destroy(&(g_graphdriver->rwlock));
g_graphdriver = NULL;
+ // notes, do not driver_unlock and destroy the lock, becase the other threads may wait for it
+ // if we unlock and destroy the lock, may cause the lock failure, and result to coredump
out:
return ret;
--
2.25.1

View File

@ -1,32 +0,0 @@
From d1fbada9a7b520830d8a0c31263aadba97b2dd9d Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Mon, 25 Jan 2021 15:01:35 +0800
Subject: [PATCH 16/53] driver: do not set g_graphdriver to NULL
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
.../image/oci/storage/layer_store/graphdriver/driver.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
index b41132ea..6b1e0922 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
@@ -512,13 +512,7 @@ int graphdriver_cleanup(void)
driver_unlock();
goto out;
}
-
- free((char *)g_graphdriver->home);
- g_graphdriver->home = NULL;
- free(g_graphdriver->backing_fs);
- g_graphdriver->backing_fs = NULL;
- g_graphdriver = NULL;
- // notes, do not driver_unlock and destroy the lock, becase the other threads may wait for it
+ // notes, do not call driver_unlock and destroy the lock, becase the other threads may wait for it
// if we unlock and destroy the lock, may cause the lock failure, and result to coredump
out:
--
2.25.1

View File

@ -1,39 +0,0 @@
From 4f2951681dbe583e80af91d808292aad8cceb599 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 28 Jan 2021 14:04:54 +0800
Subject: [PATCH 17/53] ignore error if get ip failed
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
.../entry/cri/cri_pod_sandbox_manager_service_impl.cc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc b/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc
index 27768852..a668d60b 100644
--- a/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc
+++ b/src/daemon/entry/cri/cri_pod_sandbox_manager_service_impl.cc
@@ -989,12 +989,12 @@ void PodSandboxManagerServiceImpl::GetIPs(const std::string &podSandboxID, const
}
if (inspect->network_settings != nullptr && inspect->network_settings->ip_address != nullptr) {
- WARN("Use container inspect ip info: %s", error.GetCMessage());
- error.Clear();
+ WARN("Use container inspect ip info");
ips.push_back(inspect->network_settings->ip_address);
}
WARN("Failed to read pod IP from plugin/docker: %s", error.GetCMessage());
+ error.Clear();
}
void PodSandboxManagerServiceImpl::SetSandboxStatusNetwork(const container_inspect *inspect,
@@ -1214,4 +1214,4 @@ void PodSandboxManagerServiceImpl::PortForward(const runtime::v1alpha2::PortForw
// This feature is temporarily not supported
}
-} // namespace CRI
\ No newline at end of file
+} // namespace CRI
--
2.25.1

View File

@ -1,35 +0,0 @@
From 72e8e3163524455768986a7496ccfc5ce384fade Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Fri, 29 Jan 2021 15:33:56 +0800
Subject: [PATCH 18/53] GC: add log container info when add into gc
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/modules/container/container_gc/containers_gc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/daemon/modules/container/container_gc/containers_gc.c b/src/daemon/modules/container/container_gc/containers_gc.c
index 6b1c392c..5924aaa3 100644
--- a/src/daemon/modules/container/container_gc/containers_gc.c
+++ b/src/daemon/modules/container/container_gc/containers_gc.c
@@ -203,6 +203,8 @@ int gc_add_container(const char *id, const char *runtime, const pid_ppid_info_t
return -1;
}
+ EVENT("Event: {Object: GC, Type: Add container %s with pid %u into garbage collector}", id, pid_info->pid);
+
newnode = util_common_calloc_s(sizeof(struct linked_list));
if (newnode == NULL) {
CRIT("Memory allocation error.");
@@ -481,6 +483,8 @@ static void gc_container_process(struct linked_list *it)
gc_containers_unlock();
+ EVENT("Event: {Object: GC, Type: Delete container %s with pid %u from garbage collector}", id, pid);
+
/* apply restart policy for the container after gc */
apply_restart_policy_after_gc(id);
--
2.25.1

View File

@ -1,146 +0,0 @@
From 171cb932bbbbfc5816ceb65223f1d5e733c79d8e Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Sat, 30 Jan 2021 10:38:11 +0800
Subject: [PATCH 19/53] log: use the same function to init log in
export/pause/resume
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/cmd/isula/extend/export.c | 19 +++++++++----------
src/cmd/isula/extend/pause.c | 20 +++++++++-----------
src/cmd/isula/extend/resume.c | 17 +++++++----------
3 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/src/cmd/isula/extend/export.c b/src/cmd/isula/extend/export.c
index 476cf775..ea9b9c11 100644
--- a/src/cmd/isula/extend/export.c
+++ b/src/cmd/isula/extend/export.c
@@ -76,15 +76,7 @@ int cmd_export_main(int argc, const char **argv)
char file[PATH_MAX] = { 0 };
struct isula_libutils_log_config lconf = { 0 };
- lconf.name = argv[0];
- lconf.quiet = true;
- lconf.driver = "stdout";
- lconf.file = NULL;
- lconf.priority = "ERROR";
- if (isula_libutils_log_enable(&lconf)) {
- COMMAND_ERROR("Export: log init failed");
- exit(ECOMMON);
- }
+ isula_libutils_default_log_config(argv[0], &lconf);
command_t cmd;
if (client_arguments_init(&g_cmd_export_args)) {
@@ -92,7 +84,9 @@ int cmd_export_main(int argc, const char **argv)
exit(ECOMMON);
}
g_cmd_export_args.progname = argv[0];
- struct command_option options[] = { COMMON_OPTIONS(g_cmd_export_args) EXPORT_OPTIONS(g_cmd_export_args) };
+ struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_export_args)
+ EXPORT_OPTIONS(g_cmd_export_args)
+ };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_export_desc,
g_cmd_export_usage);
@@ -100,6 +94,11 @@ int cmd_export_main(int argc, const char **argv)
exit(EINVALIDARGS);
}
+ if (isula_libutils_log_enable(&lconf)) {
+ COMMAND_ERROR("log init failed");
+ exit(ECOMMON);
+ }
+
if (g_cmd_export_args.argc != 1) {
COMMAND_ERROR("Export requires exactly 1 container name");
exit(EINVALIDARGS);
diff --git a/src/cmd/isula/extend/pause.c b/src/cmd/isula/extend/pause.c
index 4d508e7b..c12eaa8c 100644
--- a/src/cmd/isula/extend/pause.c
+++ b/src/cmd/isula/extend/pause.c
@@ -71,23 +71,16 @@ int cmd_pause_main(int argc, const char **argv)
int i = 0;
int status = 0;
struct isula_libutils_log_config lconf = { 0 };
-
- lconf.name = argv[0];
- lconf.quiet = true;
- lconf.file = NULL;
- lconf.priority = "ERROR";
- lconf.driver = "stdout";
- if (isula_libutils_log_enable(&lconf)) {
- COMMAND_ERROR("log init failed");
- exit(ECOMMON);
- }
command_t cmd;
+
+ isula_libutils_default_log_config(argv[0], &lconf);
+
if (client_arguments_init(&g_cmd_pause_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_pause_args.progname = argv[0];
- struct command_option options[] = { COMMON_OPTIONS(g_cmd_pause_args) };
+ struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_pause_args) };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_pause_desc,
g_cmd_pause_usage);
@@ -95,6 +88,11 @@ int cmd_pause_main(int argc, const char **argv)
exit(EINVALIDARGS);
}
+ if (isula_libutils_log_enable(&lconf)) {
+ COMMAND_ERROR("log init failed");
+ exit(ECOMMON);
+ }
+
if (g_cmd_pause_args.argc == 0) {
COMMAND_ERROR("Pause requires at least 1 container names");
exit(EINVALIDARGS);
diff --git a/src/cmd/isula/extend/resume.c b/src/cmd/isula/extend/resume.c
index c3c43760..7a25ee68 100644
--- a/src/cmd/isula/extend/resume.c
+++ b/src/cmd/isula/extend/resume.c
@@ -71,15 +71,7 @@ int cmd_resume_main(int argc, const char **argv)
int status = 0;
struct isula_libutils_log_config lconf = { 0 };
- lconf.name = argv[0];
- lconf.quiet = true;
- lconf.driver = "stdout";
- lconf.file = NULL;
- lconf.priority = "ERROR";
- if (isula_libutils_log_enable(&lconf)) {
- COMMAND_ERROR("Resume: log init failed");
- exit(ECOMMON);
- }
+ isula_libutils_default_log_config(argv[0], &lconf);
command_t cmd;
if (client_arguments_init(&g_cmd_resume_args)) {
@@ -87,7 +79,7 @@ int cmd_resume_main(int argc, const char **argv)
exit(ECOMMON);
}
g_cmd_resume_args.progname = argv[0];
- struct command_option options[] = { COMMON_OPTIONS(g_cmd_resume_args) };
+ struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_resume_args) };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_resume_desc,
g_cmd_resume_usage);
@@ -95,6 +87,11 @@ int cmd_resume_main(int argc, const char **argv)
exit(EINVALIDARGS);
}
+ if (isula_libutils_log_enable(&lconf)) {
+ COMMAND_ERROR("log init failed");
+ exit(ECOMMON);
+ }
+
if (g_cmd_resume_args.argc == 0) {
COMMAND_ERROR("Pause requires at least 1 container names");
exit(EINVALIDARGS);
--
2.25.1

View File

@ -1,623 +0,0 @@
From 20a6562ea0a6c50bdc6a863067eeaf7fa04909d0 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Sat, 30 Jan 2021 14:46:13 +0800
Subject: [PATCH 20/53] init log config should before command parse
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/cmd/isula/base/create.c | 2 +-
src/cmd/isula/base/kill.c | 2 +-
src/cmd/isula/base/rename.c | 2 +-
src/cmd/isula/base/restart.c | 2 +-
src/cmd/isula/base/rm.c | 2 +-
src/cmd/isula/base/run.c | 2 +-
src/cmd/isula/base/start.c | 2 +-
src/cmd/isula/base/stop.c | 2 +-
src/cmd/isula/extend/events.c | 2 +-
src/cmd/isula/extend/stats.c | 2 +-
src/cmd/isula/extend/update.c | 2 +-
src/cmd/isula/images/images.c | 2 +-
src/cmd/isula/images/import.c | 2 +-
src/cmd/isula/images/load.c | 2 +-
src/cmd/isula/images/login.c | 2 +-
src/cmd/isula/images/logout.c | 2 +-
src/cmd/isula/images/pull.c | 2 +-
src/cmd/isula/images/rmi.c | 2 +-
src/cmd/isula/images/tag.c | 2 +-
src/cmd/isula/information/info.c | 2 +-
src/cmd/isula/information/inspect.c | 2 +-
src/cmd/isula/information/logs.c | 2 +-
src/cmd/isula/information/ps.c | 2 +-
src/cmd/isula/information/top.c | 2 +-
src/cmd/isula/information/version.c | 2 +-
src/cmd/isula/information/wait.c | 2 +-
src/cmd/isula/stream/attach.c | 2 +-
src/cmd/isula/stream/cp.c | 2 +-
src/cmd/isula/stream/exec.c | 2 +-
src/cmd/isula/volume/list.c | 2 +-
src/cmd/isula/volume/prune.c | 2 +-
src/cmd/isula/volume/remove.c | 2 +-
32 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/src/cmd/isula/base/create.c b/src/cmd/isula/base/create.c
index 12f0a8be..a531fc0e 100644
--- a/src/cmd/isula/base/create.c
+++ b/src/cmd/isula/base/create.c
@@ -1538,6 +1538,7 @@ int cmd_create_main(int argc, const char **argv)
g_cmd_create_args) COMMON_OPTIONS(g_cmd_create_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_create_desc,
g_cmd_create_usage);
if (command_parse_args(&cmd, &g_cmd_create_args.argc, &g_cmd_create_args.argv) ||
@@ -1545,7 +1546,6 @@ int cmd_create_main(int argc, const char **argv)
nret = EINVALIDARGS;
goto out;
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/base/kill.c b/src/cmd/isula/base/kill.c
index b8e85459..7c8bf95c 100644
--- a/src/cmd/isula/base/kill.c
+++ b/src/cmd/isula/base/kill.c
@@ -92,12 +92,12 @@ int cmd_kill_main(int argc, const char **argv)
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_kill_args)
KILL_OPTIONS(g_cmd_kill_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_kill_desc,
g_cmd_kill_usage);
if (command_parse_args(&cmd, &g_cmd_kill_args.argc, &g_cmd_kill_args.argv)) {
exit(ECOMMON);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed\n");
exit(ECOMMON);
diff --git a/src/cmd/isula/base/rename.c b/src/cmd/isula/base/rename.c
index aafc9bda..c5cf5bb6 100644
--- a/src/cmd/isula/base/rename.c
+++ b/src/cmd/isula/base/rename.c
@@ -67,12 +67,12 @@ int cmd_rename_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_rename_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_rename_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_rename_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_rename_desc,
g_cmd_rename_usage);
if (command_parse_args(&cmd, &g_cmd_rename_args.argc, &g_cmd_rename_args.argv)) {
diff --git a/src/cmd/isula/base/restart.c b/src/cmd/isula/base/restart.c
index cedfaec1..877b0ff3 100644
--- a/src/cmd/isula/base/restart.c
+++ b/src/cmd/isula/base/restart.c
@@ -73,12 +73,12 @@ int cmd_restart_main(int argc, const char **argv)
RESTART_OPTIONS(g_cmd_restart_args)
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_restart_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_restart_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_restart_desc,
g_cmd_restart_usage);
diff --git a/src/cmd/isula/base/rm.c b/src/cmd/isula/base/rm.c
index 9cd0cbd0..13bd4644 100644
--- a/src/cmd/isula/base/rm.c
+++ b/src/cmd/isula/base/rm.c
@@ -118,12 +118,12 @@ int cmd_delete_main(int argc, const char **argv)
DELETE_OPTIONS(g_cmd_delete_args)
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_delete_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_delete_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_delete_desc,
g_cmd_delete_usage);
if (command_parse_args(&cmd, &g_cmd_delete_args.argc, &g_cmd_delete_args.argv)) {
diff --git a/src/cmd/isula/base/run.c b/src/cmd/isula/base/run.c
index 0c82af02..a6068709 100644
--- a/src/cmd/isula/base/run.c
+++ b/src/cmd/isula/base/run.c
@@ -148,13 +148,13 @@ int cmd_run_main(int argc, const char **argv)
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_run_args) CREATE_OPTIONS(g_cmd_run_args)
CREATE_EXTEND_OPTIONS(g_cmd_run_args) RUN_OPTIONS(g_cmd_run_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_run_desc,
g_cmd_run_usage);
if (command_parse_args(&cmd, &g_cmd_run_args.argc, &g_cmd_run_args.argv) || run_checker(&g_cmd_run_args)) {
exit(EINVALIDARGS);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/base/start.c b/src/cmd/isula/base/start.c
index 104c24ae..5e55524f 100644
--- a/src/cmd/isula/base/start.c
+++ b/src/cmd/isula/base/start.c
@@ -327,12 +327,12 @@ int cmd_start_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_start_args) START_OPTIONS(g_cmd_start_args)};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_start_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_start_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_start_desc,
g_cmd_start_usage);
if (command_parse_args(&cmd, &g_cmd_start_args.argc, &g_cmd_start_args.argv)) {
diff --git a/src/cmd/isula/base/stop.c b/src/cmd/isula/base/stop.c
index e52db79c..6a901c42 100644
--- a/src/cmd/isula/base/stop.c
+++ b/src/cmd/isula/base/stop.c
@@ -78,12 +78,12 @@ int cmd_stop_main(int argc, const char **argv)
STOP_OPTIONS(g_cmd_stop_args)
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_stop_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_stop_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_stop_desc,
g_cmd_stop_usage);
if (command_parse_args(&cmd, &g_cmd_stop_args.argc, &g_cmd_stop_args.argv)) {
diff --git a/src/cmd/isula/extend/events.c b/src/cmd/isula/extend/events.c
index 9dbd7774..7094ac0d 100644
--- a/src/cmd/isula/extend/events.c
+++ b/src/cmd/isula/extend/events.c
@@ -214,12 +214,12 @@ int cmd_events_main(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_events_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_events_desc,
g_cmd_events_usage);
if (command_parse_args(&cmd, &g_cmd_events_args.argc, &g_cmd_events_args.argv)) {
exit(EINVALIDARGS);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("Events: log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/extend/stats.c b/src/cmd/isula/extend/stats.c
index 655332b8..334f859e 100644
--- a/src/cmd/isula/extend/stats.c
+++ b/src/cmd/isula/extend/stats.c
@@ -272,9 +272,9 @@ int cmd_stats_main(int argc, const char **argv)
exit(ECOMMON);
}
g_cmd_stats_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_stats_desc,
g_cmd_stats_usage);
- isula_libutils_default_log_config(argv[0], &lconf);
if (command_parse_args(&cmd, &g_cmd_stats_args.argc, &g_cmd_stats_args.argv)) {
exit(EINVALIDARGS);
}
diff --git a/src/cmd/isula/extend/update.c b/src/cmd/isula/extend/update.c
index da472b0b..42cb8f21 100644
--- a/src/cmd/isula/extend/update.c
+++ b/src/cmd/isula/extend/update.c
@@ -149,12 +149,12 @@ int cmd_update_main(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_update_args)
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_update_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_update_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_update_desc,
g_cmd_update_usage);
if (command_parse_args(&cmd, &g_cmd_update_args.argc, &g_cmd_update_args.argv) ||
diff --git a/src/cmd/isula/images/images.c b/src/cmd/isula/images/images.c
index f60e7500..3d538aa5 100644
--- a/src/cmd/isula/images/images.c
+++ b/src/cmd/isula/images/images.c
@@ -324,12 +324,12 @@ int cmd_images_main(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_images_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_images_desc,
g_cmd_images_usage);
if (command_parse_args(&cmd, &g_cmd_images_args.argc, &g_cmd_images_args.argv)) {
exit(exit_code);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("Images: log init failed");
exit(exit_code);
diff --git a/src/cmd/isula/images/import.c b/src/cmd/isula/images/import.c
index 2dcc6486..dbacb604 100644
--- a/src/cmd/isula/images/import.c
+++ b/src/cmd/isula/images/import.c
@@ -88,12 +88,12 @@ int cmd_import_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_import_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_import_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_import_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_import_desc,
g_cmd_import_usage);
if (command_parse_args(&cmd, &g_cmd_import_args.argc, &g_cmd_import_args.argv)) {
diff --git a/src/cmd/isula/images/load.c b/src/cmd/isula/images/load.c
index 0fb8014e..688edd02 100644
--- a/src/cmd/isula/images/load.c
+++ b/src/cmd/isula/images/load.c
@@ -124,12 +124,12 @@ int cmd_load_main(int argc, const char **argv)
#endif
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_load_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_load_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_load_desc,
g_cmd_load_usage);
if (command_parse_args(&cmd, &g_cmd_load_args.argc, &g_cmd_load_args.argv)) {
diff --git a/src/cmd/isula/images/login.c b/src/cmd/isula/images/login.c
index 92550352..0c0c149b 100644
--- a/src/cmd/isula/images/login.c
+++ b/src/cmd/isula/images/login.c
@@ -184,13 +184,13 @@ int cmd_login_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { COMMON_OPTIONS(g_cmd_login_args) LOGIN_OPTIONS(g_cmd_login_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_login_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_login_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_login_desc,
g_cmd_login_usage);
if (command_parse_args(&cmd, &g_cmd_login_args.argc, &g_cmd_login_args.argv)) {
diff --git a/src/cmd/isula/images/logout.c b/src/cmd/isula/images/logout.c
index 8efec1e3..45f28509 100644
--- a/src/cmd/isula/images/logout.c
+++ b/src/cmd/isula/images/logout.c
@@ -80,13 +80,13 @@ int cmd_logout_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { COMMON_OPTIONS(g_cmd_logout_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_logout_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_logout_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_logout_desc,
g_cmd_logout_usage);
if (command_parse_args(&cmd, &g_cmd_logout_args.argc, &g_cmd_logout_args.argv)) {
diff --git a/src/cmd/isula/images/pull.c b/src/cmd/isula/images/pull.c
index b72b0302..3ba7a715 100644
--- a/src/cmd/isula/images/pull.c
+++ b/src/cmd/isula/images/pull.c
@@ -79,13 +79,13 @@ int cmd_pull_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { COMMON_OPTIONS(g_cmd_pull_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_pull_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_pull_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_pull_desc,
g_cmd_pull_usage);
if (command_parse_args(&cmd, &g_cmd_pull_args.argc, &g_cmd_pull_args.argv)) {
diff --git a/src/cmd/isula/images/rmi.c b/src/cmd/isula/images/rmi.c
index 53ea7343..5b07c866 100644
--- a/src/cmd/isula/images/rmi.c
+++ b/src/cmd/isula/images/rmi.c
@@ -83,12 +83,12 @@ int cmd_rmi_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_rmi_args) RMI_OPTIONS(g_cmd_rmi_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_rmi_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_rmi_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_rmi_desc,
g_cmd_rmi_usage);
if (command_parse_args(&cmd, &g_cmd_rmi_args.argc, &g_cmd_rmi_args.argv)) {
diff --git a/src/cmd/isula/images/tag.c b/src/cmd/isula/images/tag.c
index e5a86708..8f399520 100644
--- a/src/cmd/isula/images/tag.c
+++ b/src/cmd/isula/images/tag.c
@@ -78,12 +78,12 @@ int cmd_tag_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_tag_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_tag_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_tag_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_tag_desc,
g_cmd_tag_usage);
if (command_parse_args(&cmd, &g_cmd_tag_args.argc, &g_cmd_tag_args.argv)) {
diff --git a/src/cmd/isula/information/info.c b/src/cmd/isula/information/info.c
index d6f6f7be..d3dd194a 100644
--- a/src/cmd/isula/information/info.c
+++ b/src/cmd/isula/information/info.c
@@ -160,12 +160,12 @@ int cmd_info_main(int argc, const char **argv)
g_cmd_info_args.progname = argv[0];
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_info_args) };
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_info_desc,
g_cmd_info_usage);
if (command_parse_args(&cmd, &g_cmd_info_args.argc, &g_cmd_info_args.argv) != 0) {
exit(EINVALIDARGS);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf) != 0) {
COMMAND_ERROR("Info: log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/information/inspect.c b/src/cmd/isula/information/inspect.c
index 8ddb032e..d575b3db 100644
--- a/src/cmd/isula/information/inspect.c
+++ b/src/cmd/isula/information/inspect.c
@@ -967,12 +967,12 @@ int cmd_inspect_main(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_inspect_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_inspect_desc,
g_cmd_inspect_usage);
if (command_parse_args(&cmd, &g_cmd_inspect_args.argc, &g_cmd_inspect_args.argv)) {
exit(EINVALIDARGS);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/information/logs.c b/src/cmd/isula/information/logs.c
index 2ddd16e6..5f3951ed 100644
--- a/src/cmd/isula/information/logs.c
+++ b/src/cmd/isula/information/logs.c
@@ -109,12 +109,12 @@ static int cmd_logs_init(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_logs_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_logs_desc,
g_cmd_logs_usage);
if (command_parse_args(&cmd, &g_cmd_logs_args.argc, &g_cmd_logs_args.argv)) {
return EINVALIDARGS;
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed\n");
g_cmd_logs_args.name = g_cmd_logs_args.argv[0];
diff --git a/src/cmd/isula/information/ps.c b/src/cmd/isula/information/ps.c
index 125353a6..e1f8f75a 100644
--- a/src/cmd/isula/information/ps.c
+++ b/src/cmd/isula/information/ps.c
@@ -986,12 +986,12 @@ int cmd_list_main(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_list_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_list_desc,
g_cmd_list_usage);
if (command_parse_args(&cmd, &g_cmd_list_args.argc, &g_cmd_list_args.argv)) {
exit(EINVALIDARGS);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("PS: log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/information/top.c b/src/cmd/isula/information/top.c
index 5d0e3f0f..eeb47892 100644
--- a/src/cmd/isula/information/top.c
+++ b/src/cmd/isula/information/top.c
@@ -120,12 +120,12 @@ int cmd_top_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_top_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_top_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_top_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_top_desc,
g_cmd_top_usage);
diff --git a/src/cmd/isula/information/version.c b/src/cmd/isula/information/version.c
index 62ee5643..46f73cab 100644
--- a/src/cmd/isula/information/version.c
+++ b/src/cmd/isula/information/version.c
@@ -98,12 +98,12 @@ int cmd_version_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_version_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_version_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_version_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_version_desc,
g_cmd_version_usage);
if (command_parse_args(&cmd, &g_cmd_version_args.argc, &g_cmd_version_args.argv)) {
diff --git a/src/cmd/isula/information/wait.c b/src/cmd/isula/information/wait.c
index b39c4953..aaa8f20e 100644
--- a/src/cmd/isula/information/wait.c
+++ b/src/cmd/isula/information/wait.c
@@ -91,12 +91,12 @@ int cmd_wait_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_wait_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_wait_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_wait_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_wait_desc,
g_cmd_wait_usage);
if (command_parse_args(&cmd, &g_cmd_wait_args.argc, &g_cmd_wait_args.argv)) {
diff --git a/src/cmd/isula/stream/attach.c b/src/cmd/isula/stream/attach.c
index f0a77a16..6dac2a0c 100644
--- a/src/cmd/isula/stream/attach.c
+++ b/src/cmd/isula/stream/attach.c
@@ -172,12 +172,12 @@ static int attach_cmd_init(int argc, const char **argv)
g_cmd_attach_args.progname = argv[0];
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_attach_args) };
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_attach_desc,
g_cmd_attach_usage);
if (command_parse_args(&cmd, &g_cmd_attach_args.argc, &g_cmd_attach_args.argv)) {
return EINVALIDARGS;
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed");
return ECOMMON;
diff --git a/src/cmd/isula/stream/cp.c b/src/cmd/isula/stream/cp.c
index e954ed3d..b869741f 100644
--- a/src/cmd/isula/stream/cp.c
+++ b/src/cmd/isula/stream/cp.c
@@ -327,12 +327,12 @@ int cmd_cp_main(int argc, const char **argv)
g_cmd_cp_args.progname = argv[0];
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_cp_args) };
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_cp_desc,
g_cmd_cp_usage);
if (command_parse_args(&cmd, &g_cmd_cp_args.argc, &g_cmd_cp_args.argv)) {
exit(EINVALIDARGS);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("cp: log init failed");
exit(ECOMMON);
diff --git a/src/cmd/isula/stream/exec.c b/src/cmd/isula/stream/exec.c
index 559a9d0f..d1d57268 100644
--- a/src/cmd/isula/stream/exec.c
+++ b/src/cmd/isula/stream/exec.c
@@ -198,12 +198,12 @@ static int exec_cmd_init(int argc, const char **argv)
EXEC_OPTIONS(g_cmd_exec_args)
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_exec_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_exec_args.progname = argv[0];
+ isula_libutils_default_log_config(argv[0], &lconf);
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_exec_desc,
g_cmd_exec_usage);
diff --git a/src/cmd/isula/volume/list.c b/src/cmd/isula/volume/list.c
index f58abc0f..23fe2027 100644
--- a/src/cmd/isula/volume/list.c
+++ b/src/cmd/isula/volume/list.c
@@ -145,12 +145,12 @@ int cmd_volume_ls_main(int argc, const char **argv)
COMMON_OPTIONS(g_cmd_volume_ls_args)
};
+ isula_libutils_default_log_config(argv[0], &lconf);
subcommand_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_volume_ls_desc,
g_cmd_volume_ls_usage);
if (command_parse_args(&cmd, &g_cmd_volume_ls_args.argc, &g_cmd_volume_ls_args.argv)) {
exit(exit_code);
}
- isula_libutils_default_log_config(argv[0], &lconf);
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("volume ls: log init failed");
exit(exit_code);
diff --git a/src/cmd/isula/volume/prune.c b/src/cmd/isula/volume/prune.c
index e9d628d1..2a3bca3e 100644
--- a/src/cmd/isula/volume/prune.c
+++ b/src/cmd/isula/volume/prune.c
@@ -90,12 +90,12 @@ int cmd_volume_prune_main(int argc, const char **argv)
PRUNE_OPTIONS(g_cmd_volume_prune_args)
};
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_volume_prune_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_volume_prune_args.progname = util_string_join(" ", argv, 2);
+ isula_libutils_default_log_config(argv[0], &lconf);
subcommand_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_volume_prune_desc,
g_cmd_volume_prune_usage);
diff --git a/src/cmd/isula/volume/remove.c b/src/cmd/isula/volume/remove.c
index 2d10a002..71194722 100644
--- a/src/cmd/isula/volume/remove.c
+++ b/src/cmd/isula/volume/remove.c
@@ -80,12 +80,12 @@ int cmd_volume_rm_main(int argc, const char **argv)
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_volume_rm_args) };
- isula_libutils_default_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_volume_rm_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_volume_rm_args.progname = util_string_join(" ", argv, 2);
+ isula_libutils_default_log_config(argv[0], &lconf);
subcommand_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_volume_rm_desc,
g_cmd_volume_rm_usage);
if (command_parse_args(&cmd, &g_cmd_volume_rm_args.argc, &g_cmd_volume_rm_args.argv)) {
--
2.25.1

View File

@ -1,102 +0,0 @@
From 82d59974b5fcb0abfa2f488801e7d9ed2f93a718 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Sat, 30 Jan 2021 14:22:16 +0800
Subject: [PATCH 21/53] spec: add verify for device cgroup access mode
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/modules/spec/verify.c | 27 +++++++++++++++++++++++++++
src/utils/cutils/utils_verify.c | 26 ++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c
index 053a57b3..a3156579 100644
--- a/src/daemon/modules/spec/verify.c
+++ b/src/daemon/modules/spec/verify.c
@@ -1064,6 +1064,26 @@ static int adapt_resources_memory(const sysinfo_t *sysinfo, defs_resources_memor
return adapt_memory_swap(sysinfo, &(memory->limit), &(memory->swap));
}
+/* verify resources device */
+static int verify_resources_device(defs_resources *resources)
+{
+ int ret = 0;
+ size_t i = 0;
+
+ for (i = 0; i < resources->devices_len; i++) {
+ if (!util_valid_device_mode(resources->devices[i]->access)) {
+ ERROR("Invalid device mode \"%s\" for device \"%ld %ld\"", resources->devices[i]->access,
+ resources->devices[i]->major, resources->devices[i]->minor);
+ isulad_set_error_message("Invalid device mode \"%s\" for device \"%ld %ld\"", resources->devices[i]->access,
+ resources->devices[i]->major, resources->devices[i]->minor);
+ ret = -1;
+ goto out;
+ }
+ }
+out:
+ return ret;
+}
+
/* verify linux resources */
static int verify_linux_resources(const sysinfo_t *sysinfo, defs_resources *resources)
{
@@ -1104,6 +1124,13 @@ static int verify_linux_resources(const sysinfo_t *sysinfo, defs_resources *reso
goto out;
}
}
+ // device
+ if (resources->devices != NULL) {
+ ret = verify_resources_device(resources);
+ if (ret != 0) {
+ goto out;
+ }
+ }
out:
return ret;
}
diff --git a/src/utils/cutils/utils_verify.c b/src/utils/cutils/utils_verify.c
index 5a18e664..58191685 100644
--- a/src/utils/cutils/utils_verify.c
+++ b/src/utils/cutils/utils_verify.c
@@ -184,14 +184,36 @@ bool util_validate_socket(const char *socket)
bool util_valid_device_mode(const char *mode)
{
size_t i = 0;
+ int r_count = 0;
+ int w_count = 0;
+ int m_count = 0;
if (mode == NULL || !strcmp(mode, "")) {
return false;
}
for (i = 0; i < strlen(mode); i++) {
- if (mode[i] != 'r' && mode[i] != 'w' && mode[i] != 'm') {
- return false;
+ switch (mode[i]) {
+ case 'r':
+ if (r_count != 0) {
+ return false;
+ }
+ r_count++;
+ break;
+ case 'w':
+ if (w_count != 0) {
+ return false;
+ }
+ w_count++;
+ break;
+ case 'm':
+ if (m_count != 0) {
+ return false;
+ }
+ m_count++;
+ break;
+ default:
+ return false;
}
}
--
2.25.1

View File

@ -1,26 +0,0 @@
From 87e886b239a932f37679f12fe2920d1b36e92985 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Sat, 30 Jan 2021 16:12:29 +0800
Subject: [PATCH 22/53] log: change log level from warn to error
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/modules/service/service_container.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index a4a2414c..5eab8ccf 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -1288,7 +1288,7 @@ static int force_kill(container_t *cont)
}
ret = container_wait_stop(cont, 90);
if (ret != 0) {
- WARN("Container(%s) stuck for 90 seconds, try to kill the monitor of container", id);
+ ERROR("Container(%s) stuck for 90 seconds, try to kill the monitor of container", id);
ret = send_signal_to_process(cont->state->state->p_pid, cont->state->state->p_start_time, stop_signal, SIGKILL);
if (ret != 0) {
ERROR("Container stuck for 90 seconds and failed to kill the monitor of container, "
--
2.25.1

View File

@ -1,27 +0,0 @@
From 2bd45202ef01260a2181270012c4781afd5cccba Mon Sep 17 00:00:00 2001
From: zhangsong234 <zhangsong34@huawei.com>
Date: Mon, 1 Feb 2021 09:25:51 +0800
Subject: [PATCH 23/53] Fix create env path dir if dir exist
---
src/daemon/modules/service/service_container.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index 0c1f234e..5fbb06a2 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -291,7 +291,9 @@ static int create_env_path_dir(const char *env_path)
free(dir);
return 0;
}
- ret = util_mkdir_p(dir, DEFAULT_SECURE_DIRECTORY_MODE);
+ if (!util_dir_exists(dir)) {
+ ret = util_mkdir_p(dir, DEFAULT_SECURE_DIRECTORY_MODE);
+ }
free(dir);
return ret;
}
--
2.25.1

View File

@ -1,287 +0,0 @@
From c5aeb37655533ce84161f237ed6175153891d9e0 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Thu, 28 Jan 2021 19:30:44 +0800
Subject: [PATCH 24/53] iSulad: calculate memusage with used -
total_inactive_file
On cgroup v1 host, the result is `mem.used - mem.["total_inactive_file"]` .
This definition is consistent with cadvisor and containerd/CRI.
https://github.com/google/cadvisor/commit/307d1b1cb320fef66fab02db749f07a459245451
https://github.com/containerd/cri/commit/6b8846cdf8b8c98c1d965313d66bc8489166059a
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/api/services/containers/container.proto | 1 +
.../connect/grpc/grpc_containers_client.cc | 4 +-
src/client/connect/protocol_type.h | 1 +
src/cmd/isula/extend/stats.c | 16 +++++-
.../grpc/grpc_containers_service_private.cc | 1 +
.../cri/cri_container_manager_service_impl.cc | 49 +++++++++----------
.../executor/container_cb/execution_extend.c | 1 +
src/daemon/modules/api/runtime_api.h | 1 +
.../modules/runtime/engines/lcr/lcr_engine.c | 1 +
9 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/src/api/services/containers/container.proto b/src/api/services/containers/container.proto
index 36010860..efd085a1 100644
--- a/src/api/services/containers/container.proto
+++ b/src/api/services/containers/container.proto
@@ -85,6 +85,7 @@ message Container_info {
string status = 15;
uint64 cache = 16;
uint64 cache_total = 17;
+ uint64 inactive_file_total = 18;
}
message Event {
diff --git a/src/client/connect/grpc/grpc_containers_client.cc b/src/client/connect/grpc/grpc_containers_client.cc
index 9bb66b4b..ccde59a4 100644
--- a/src/client/connect/grpc/grpc_containers_client.cc
+++ b/src/client/connect/grpc/grpc_containers_client.cc
@@ -1688,6 +1688,7 @@ public:
}
response->container_stats[i].cache = gresponse->containers(i).cache();
response->container_stats[i].cache_total = gresponse->containers(i).cache_total();
+ response->container_stats[i].inactive_file_total = gresponse->containers(i).inactive_file_total();
}
response->container_num = static_cast<size_t>(size);
}
@@ -1981,7 +1982,8 @@ public:
explicit CopyToContainerWriteToServerTask(
const struct io_read_wrapper *reader,
std::shared_ptr<ClientReaderWriter<CopyToContainerRequest, CopyToContainerResponse>> stream)
- : m_reader(reader), m_stream(std::move(std::move(stream)))
+ : m_reader(reader)
+ , m_stream(std::move(std::move(stream)))
{
}
~CopyToContainerWriteToServerTask() = default;
diff --git a/src/client/connect/protocol_type.h b/src/client/connect/protocol_type.h
index 6cbecf66..32f55b51 100644
--- a/src/client/connect/protocol_type.h
+++ b/src/client/connect/protocol_type.h
@@ -172,6 +172,7 @@ struct isula_container_info {
// Cache usage
uint64_t cache;
uint64_t cache_total;
+ uint64_t inactive_file_total;
};
struct isula_inspect_request {
diff --git a/src/cmd/isula/extend/stats.c b/src/cmd/isula/extend/stats.c
index 334f859e..03544325 100644
--- a/src/cmd/isula/extend/stats.c
+++ b/src/cmd/isula/extend/stats.c
@@ -76,6 +76,18 @@ static void stats_print_header(void)
printf(TERMNORM);
}
+// workingset = usage - total_inactive_file
+static uint64_t memory_get_working_set(const struct isula_container_info *stats)
+{
+ uint64_t workingset = stats->mem_used;
+
+ if (stats->inactive_file_total < stats->mem_used) {
+ workingset = stats->mem_used - stats->inactive_file_total;
+ }
+
+ return workingset;
+}
+
static void stats_print(const struct isula_container_info *stats)
{
#define SHORTIDLEN 12
@@ -130,8 +142,10 @@ static void stats_print(const struct isula_container_info *stats)
if (strlen(short_id) > SHORTIDLEN) {
short_id[SHORTIDLEN] = '\0';
}
+ // workingset = usage - total_inactive_file
+ uint64_t workingset = memory_get_working_set(stats);
printf("%-16s %-10.2f %-26s %-10.2f %-26s %-10llu", short_id, cpu_percent, mem_str,
- stats->mem_limit ? ((double)stats->mem_used / stats->mem_limit) * PERCENT : 0.00, iosb_str,
+ stats->mem_limit ? ((double)workingset / stats->mem_limit) * PERCENT : 0.00, iosb_str,
(unsigned long long)stats->pids_current);
free(short_id);
}
diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc b/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc
index ac87a20b..8e19f978 100644
--- a/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc
@@ -790,6 +790,7 @@ void ContainerServiceImpl::stats_response_to_grpc(const container_stats_response
}
stats->set_cache(response->container_stats[i]->cache);
stats->set_cache_total(response->container_stats[i]->cache_total);
+ stats->set_inactive_file_total(response->container_stats[i]->inactive_file_total);
}
}
gresponse->set_cc(response->cc);
diff --git a/src/daemon/entry/cri/cri_container_manager_service_impl.cc b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
index 812469ee..6c6569a6 100644
--- a/src/daemon/entry/cri/cri_container_manager_service_impl.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
@@ -126,9 +126,8 @@ auto ContainerManagerServiceImpl::PackCreateContainerHostConfigSecurityContext(
return 0;
}
-auto ContainerManagerServiceImpl::GenerateCreateContainerHostConfig(const runtime::v1alpha2::ContainerConfig
- &containerConfig,
- Errors &error) -> host_config *
+auto ContainerManagerServiceImpl::GenerateCreateContainerHostConfig(
+ const runtime::v1alpha2::ContainerConfig &containerConfig, Errors &error) -> host_config *
{
host_config *hostconfig = (host_config *)util_common_calloc_s(sizeof(host_config));
if (hostconfig == nullptr) {
@@ -294,11 +293,11 @@ cleanup:
return nullptr;
}
-container_create_request *ContainerManagerServiceImpl::GenerateCreateContainerRequest(
- const std::string &realPodSandboxID,
- const runtime::v1alpha2::ContainerConfig &containerConfig,
- const runtime::v1alpha2::PodSandboxConfig &podSandboxConfig,
- const std::string &podSandboxRuntime, Errors &error)
+container_create_request *
+ContainerManagerServiceImpl::GenerateCreateContainerRequest(const std::string &realPodSandboxID,
+ const runtime::v1alpha2::ContainerConfig &containerConfig,
+ const runtime::v1alpha2::PodSandboxConfig &podSandboxConfig,
+ const std::string &podSandboxRuntime, Errors &error)
{
struct parser_context ctx {
OPT_GEN_SIMPLIFY, 0
@@ -333,8 +332,7 @@ container_create_request *ContainerManagerServiceImpl::GenerateCreateContainerRe
hostconfig->cgroup_parent = util_strdup_s(podSandboxConfig.linux().cgroup_parent().c_str());
}
- custom_config = GenerateCreateContainerCustomConfig(realPodSandboxID, containerConfig,
- podSandboxConfig, error);
+ custom_config = GenerateCreateContainerCustomConfig(realPodSandboxID, containerConfig, podSandboxConfig, error);
if (error.NotEmpty()) {
goto cleanup;
}
@@ -611,7 +609,6 @@ void ContainerManagerServiceImpl::ListContainersToGRPC(container_list_response *
}
}
-
void ContainerManagerServiceImpl::ListContainers(const runtime::v1alpha2::ContainerFilter *filter,
std::vector<std::unique_ptr<runtime::v1alpha2::Container>> *containers,
Errors &error)
@@ -681,9 +678,8 @@ auto ContainerManagerServiceImpl::PackContainerStatsFilter(const runtime::v1alph
return 0;
}
-void ContainerManagerServiceImpl::PackContainerStatsAttributes(const char *id,
- std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
- Errors &error)
+void ContainerManagerServiceImpl::PackContainerStatsAttributes(
+ const char *id, std::unique_ptr<runtime::v1alpha2::ContainerStats> &container, Errors &error)
{
if (id == nullptr) {
return;
@@ -779,7 +775,11 @@ void ContainerManagerServiceImpl::ContainerStatsToGRPC(
container);
if (response->container_stats[i]->mem_used != 0u) {
- container->mutable_memory()->mutable_working_set_bytes()->set_value(response->container_stats[i]->mem_used);
+ uint64_t workingset = response->container_stats[i]->mem_used;
+ if (response->container_stats[i]->inactive_file_total < response->container_stats[i]->mem_used) {
+ workingset = response->container_stats[i]->mem_used - response->container_stats[i]->inactive_file_total;
+ }
+ container->mutable_memory()->mutable_working_set_bytes()->set_value(workingset);
}
if (response->container_stats[i]->cpu_use_nanos != 0u) {
@@ -838,9 +838,8 @@ cleanup:
free_container_stats_response(response);
}
-void ContainerManagerServiceImpl::PackContainerImageToStatus(container_inspect *inspect,
- std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus,
- Errors &error)
+void ContainerManagerServiceImpl::PackContainerImageToStatus(
+ container_inspect *inspect, std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus, Errors &error)
{
if (inspect->config == nullptr) {
return;
@@ -854,9 +853,9 @@ void ContainerManagerServiceImpl::PackContainerImageToStatus(container_inspect *
return;
}
-void ContainerManagerServiceImpl::UpdateBaseStatusFromInspect(container_inspect *inspect, int64_t &createdAt,
- int64_t &startedAt, int64_t &finishedAt,
- std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus)
+void ContainerManagerServiceImpl::UpdateBaseStatusFromInspect(
+ container_inspect *inspect, int64_t &createdAt, int64_t &startedAt, int64_t &finishedAt,
+ std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus)
{
runtime::v1alpha2::ContainerState state { runtime::v1alpha2::CONTAINER_UNKNOWN };
std::string reason;
@@ -1198,7 +1197,6 @@ auto ContainerManagerServiceImpl::InspectContainerState(const std::string &Id, E
return inspect_data;
}
-
auto ContainerManagerServiceImpl::ValidateExecRequest(const runtime::v1alpha2::ExecRequest &req, Errors &error) -> int
{
if (req.container_id().empty()) {
@@ -1260,8 +1258,8 @@ void ContainerManagerServiceImpl::Exec(const runtime::v1alpha2::ExecRequest &req
resp->set_url(url);
}
-auto ContainerManagerServiceImpl::ValidateAttachRequest(const runtime::v1alpha2::AttachRequest &req,
- Errors &error) -> int
+auto ContainerManagerServiceImpl::ValidateAttachRequest(const runtime::v1alpha2::AttachRequest &req, Errors &error)
+-> int
{
if (req.container_id().empty()) {
error.SetError("missing required container id!");
@@ -1286,8 +1284,7 @@ auto ContainerManagerServiceImpl::ValidateAttachRequest(const runtime::v1alpha2:
}
void ContainerManagerServiceImpl::Attach(const runtime::v1alpha2::AttachRequest &req,
- runtime::v1alpha2::AttachResponse *resp,
- Errors &error)
+ runtime::v1alpha2::AttachResponse *resp, Errors &error)
{
if (ValidateAttachRequest(req, error) != 0) {
return;
diff --git a/src/daemon/executor/container_cb/execution_extend.c b/src/daemon/executor/container_cb/execution_extend.c
index 40f24d29..2d5c6bed 100644
--- a/src/daemon/executor/container_cb/execution_extend.c
+++ b/src/daemon/executor/container_cb/execution_extend.c
@@ -268,6 +268,7 @@ static container_info *get_container_stats(const container_t *cont,
info->status = util_strdup_s(container_state_to_string(container_state_get_status(cont->state)));
info->cache = einfo->cache;
info->cache_total = einfo->cache_total;
+ info->inactive_file_total = einfo->inactive_file_total;
if (copy_map_labels(cont->common_config->config, &map_labels) != 0) {
ret = -1;
diff --git a/src/daemon/modules/api/runtime_api.h b/src/daemon/modules/api/runtime_api.h
index f11228b6..dde21b91 100644
--- a/src/daemon/modules/api/runtime_api.h
+++ b/src/daemon/modules/api/runtime_api.h
@@ -61,6 +61,7 @@ struct runtime_container_resources_stats_info {
/* Cache usage */
uint64_t cache;
uint64_t cache_total;
+ uint64_t inactive_file_total;
};
typedef struct _rt_create_params_t {
diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_engine.c b/src/daemon/modules/runtime/engines/lcr/lcr_engine.c
index 691bfaa8..350f6497 100644
--- a/src/daemon/modules/runtime/engines/lcr/lcr_engine.c
+++ b/src/daemon/modules/runtime/engines/lcr/lcr_engine.c
@@ -164,6 +164,7 @@ static void copy_container_resources_stats(const struct lcr_container_state *lcs
rs_stats->kmem_limit = lcs->kmem_limit;
rs_stats->cache = lcs->cache;
rs_stats->cache_total = lcs->cache_total;
+ rs_stats->inactive_file_total = lcs->inactive_file_total;
}
/* get container cgroup resources */
--
2.25.1

View File

@ -1,677 +0,0 @@
From 012b3f94279b0c6d193d510aa211b977a38e7c24 Mon Sep 17 00:00:00 2001
From: wujing <jing.woo@outlook.com>
Date: Fri, 22 Jan 2021 17:13:16 +0800
Subject: [PATCH 25/53] fix container exit health check residue and multiple
health checks
Signed-off-by: wujing <wujing50@huawei.com>
---
.../executor/container_cb/execution_extend.c | 7 +-
src/daemon/modules/api/container_api.h | 2 +
.../container/container_events_handler.c | 1 -
.../container/health_check/health_check.c | 274 +++++++++++++-----
.../modules/service/service_container.c | 3 +-
test/mocks/health_check_mock.cc | 8 +
test/mocks/health_check_mock.h | 1 +
.../execution_extend/execution_extend_ut.cc | 6 +
8 files changed, 220 insertions(+), 82 deletions(-)
diff --git a/src/daemon/executor/container_cb/execution_extend.c b/src/daemon/executor/container_cb/execution_extend.c
index 40f24d29..01a0466f 100644
--- a/src/daemon/executor/container_cb/execution_extend.c
+++ b/src/daemon/executor/container_cb/execution_extend.c
@@ -532,6 +532,7 @@ static int do_resume_container(container_t *cont)
params.rootpath = cont->root_path;
params.state = cont->state_path;
+
if (runtime_resume(id, cont->runtime, &params)) {
ERROR("Failed to resume container:%s", id);
ret = -1;
@@ -716,7 +717,11 @@ static int do_pause_container(container_t *cont)
params.rootpath = cont->root_path;
params.state = cont->state_path;
+
+ container_stop_health_checks(cont->common_config->id);
+
if (runtime_pause(id, cont->runtime, &params)) {
+ container_update_health_monitor(cont->common_config->id);
ERROR("Failed to pause container:%s", id);
ret = -1;
goto out;
@@ -724,8 +729,6 @@ static int do_pause_container(container_t *cont)
container_state_set_paused(cont->state);
- container_update_health_monitor(cont->common_config->id);
-
if (container_state_to_disk(cont)) {
ERROR("Failed to save container \"%s\" to disk", id);
ret = -1;
diff --git a/src/daemon/modules/api/container_api.h b/src/daemon/modules/api/container_api.h
index 83216cf3..3b7f2889 100644
--- a/src/daemon/modules/api/container_api.h
+++ b/src/daemon/modules/api/container_api.h
@@ -49,6 +49,8 @@ typedef struct health_check_manager {
pthread_mutex_t mutex;
bool init_mutex;
health_check_monitor_status_t monitor_status;
+ // Used to wait for the health check minotor thread to close
+ bool monitor_exist;
} health_check_manager_t;
typedef struct _container_state_t_ {
diff --git a/src/daemon/modules/container/container_events_handler.c b/src/daemon/modules/container/container_events_handler.c
index 1283f99c..994c11cc 100644
--- a/src/daemon/modules/container/container_events_handler.c
+++ b/src/daemon/modules/container/container_events_handler.c
@@ -156,7 +156,6 @@ static int container_state_changed(container_t *cont, const struct isulad_events
container_state_set_stopped(cont->state, (int)events->exit_status);
container_wait_stop_cond_broadcast(cont);
plugin_event_container_post_stop(cont);
- container_stop_health_checks(cont->common_config->id);
}
auto_remove = !should_restart && cont->hostconfig != NULL && cont->hostconfig->auto_remove;
diff --git a/src/daemon/modules/container/health_check/health_check.c b/src/daemon/modules/container/health_check/health_check.c
index 04467938..c6ccbbf2 100644
--- a/src/daemon/modules/container/health_check/health_check.c
+++ b/src/daemon/modules/container/health_check/health_check.c
@@ -73,24 +73,47 @@ static char *get_health_status(container_state_t *s)
return status;
}
-static void set_health_status(container_state_t *s, const char *new)
+static void set_health_status(container_t *cont, const char *new)
{
- if (s == NULL || new == NULL) {
+ if (cont->state == NULL || new == NULL) {
return;
}
- container_state_lock(s);
- free(s->state->health->status);
- s->state->health->status = util_strdup_s(new);
- container_state_unlock(s);
+
+ container_state_lock(cont->state);
+ free(cont->state->state->health->status);
+ cont->state->state->health->status = util_strdup_s(new);
+ container_state_unlock(cont->state);
+
+ if (container_state_to_disk(cont)) {
+ WARN("Failed to save container \"%s\" to disk", cont->common_config->id);
+ }
}
-static void set_monitor_idle_status(health_check_manager_t *health)
+static void init_monitor_idle_status(health_check_manager_t *health)
{
container_health_check_lock(health);
health->monitor_status = MONITOR_IDLE;
container_health_check_unlock(health);
}
+static int transfer_monitor_idle_status(health_check_manager_t *health)
+{
+ int ret = 0;
+
+ container_health_check_lock(health);
+ // When the minitor status is MONITOR_STOP, it cann't be set to minitor status
+ if (health->monitor_status == MONITOR_STOP) {
+ ret = -1;
+ goto out;
+ }
+
+ health->monitor_status = MONITOR_IDLE;
+
+out:
+ container_health_check_unlock(health);
+ return ret;
+}
+
static void set_monitor_stop_status(health_check_manager_t *health)
{
container_health_check_lock(health);
@@ -98,11 +121,21 @@ static void set_monitor_stop_status(health_check_manager_t *health)
container_health_check_unlock(health);
}
-static void set_monitor_interval_timeout_status(health_check_manager_t *health)
+static int transfer_monitor_interval_timeout_status(health_check_manager_t *health)
{
+ int ret = 0;
+
container_health_check_lock(health);
+ // When the minitor status is MONITOR_STOP, it cann't be set to minitor status
+ if (health->monitor_status == MONITOR_STOP) {
+ ret = -1;
+ goto out;
+ }
health->monitor_status = MONITOR_INTERVAL;
+
+out:
container_health_check_unlock(health);
+ return ret;
}
static health_check_monitor_status_t get_health_check_monitor_state(health_check_manager_t *health)
@@ -116,18 +149,35 @@ static health_check_monitor_status_t get_health_check_monitor_state(health_check
return ret;
}
-static void close_health_check_monitor(const container_t *cont)
+static void set_monitor_exist_flag(health_check_manager_t *health, bool closed)
+{
+ container_health_check_lock(health);
+ health->monitor_exist = closed;
+ container_health_check_unlock(health);
+}
+
+static bool get_monitor_exist_flag(health_check_manager_t *health)
+{
+ bool ret;
+
+ container_health_check_lock(health);
+ ret = health->monitor_exist;
+ container_health_check_unlock(health);
+
+ return ret;
+}
+
+static void close_health_check_monitor(container_t *cont)
{
if (cont == NULL || cont->health_check == NULL) {
return;
}
- set_monitor_stop_status(cont->health_check);
- set_health_status(cont->state, UNHEALTHY);
-}
-static void open_health_check_monitor(health_check_manager_t *health)
-{
- set_monitor_interval_timeout_status(health);
+ set_monitor_stop_status(cont->health_check);
+ // ensure that the monitor process exits
+ while (get_monitor_exist_flag(cont->health_check)) {
+ util_usleep_nointerupt(500);
+ }
}
// Called when the container is being stopped (whether because the health check is
@@ -160,6 +210,7 @@ void health_check_manager_free(health_check_manager_t *health_check)
if (health_check->init_mutex) {
pthread_mutex_destroy(&health_check->mutex);
}
+
free(health_check);
}
@@ -183,6 +234,8 @@ static health_check_manager_t *health_check_manager_new()
health_check->monitor_status = MONITOR_IDLE;
+ health_check->monitor_exist = false;
+
return health_check;
cleanup:
health_check_manager_free(health_check);
@@ -320,6 +373,43 @@ out:
return ret;
}
+static void *stop_container_on_unhealthy(void *arg)
+{
+ int ret = 0;
+ char *container_id = NULL;
+ container_t *cont = NULL;
+
+ if (arg == NULL) {
+ ERROR("Invalid input arguments");
+ return NULL;
+ }
+ container_id = (char *)arg;
+
+ ret = pthread_detach(pthread_self());
+ if (ret != 0) {
+ CRIT("Set thread detach fail");
+ }
+
+ prctl(PR_SET_NAME, "ExitOnUnhealthy");
+
+ cont = containers_store_get(container_id);
+ if (cont == NULL) {
+ ERROR("Failed to get container info");
+ goto out;
+ }
+
+ // kill container when exit on unhealthy flag is set
+ ret = stop_container(cont, 3, true, false);
+ if (ret != 0) {
+ ERROR("Could not stop running container %s, cannot remove", cont->common_config->id);
+ }
+
+out:
+ free(container_id);
+ container_unref(cont);
+ return NULL;
+}
+
static int handle_increment_streak(container_t *cont, int retries)
{
int ret = 0;
@@ -328,18 +418,19 @@ static int handle_increment_streak(container_t *cont, int retries)
health = cont->state->state->health;
health->failing_streak++;
if (health->failing_streak >= retries) {
- set_health_status(cont->state, UNHEALTHY);
+ set_health_status(cont, UNHEALTHY);
if (cont->common_config->config->healthcheck->exit_on_unhealthy) {
- // kill container when exit on unhealthy flag is set
- ret = stop_container(cont, 3, true, false);
- if (ret != 0) {
- isulad_try_set_error_message("Could not stop running container %s, cannot remove",
- cont->common_config->id);
- ERROR("Could not stop running container %s, cannot remove", cont->common_config->id);
+ pthread_t stop_container_tid = { 0 };
+ char *container_id = util_strdup_s(cont->common_config->id);
+ if (pthread_create(&stop_container_tid, NULL, stop_container_on_unhealthy,
+ (void *)container_id)) {
+ free(container_id);
+ ERROR("Failed to create thread to exec health check");
ret = -1;
}
}
}
+
return ret;
}
@@ -442,7 +533,7 @@ static int handle_probe_result(const char *container_id, const defs_health_log_e
if (result->exit_code == EXIT_STATUS_HEALTHY) {
health->failing_streak = 0;
- set_health_status(cont->state, HEALTHY);
+ set_health_status(cont, HEALTHY);
} else {
if (handle_unhealthy_case(cont, result, retries)) {
ERROR("failed to handle unhealthy case");
@@ -457,10 +548,7 @@ static int handle_probe_result(const char *container_id, const defs_health_log_e
// note: event
EVENT("EVENT: {Object: %s, health_status: %s}", cont->common_config->id, current);
}
- if (container_state_to_disk(cont)) {
- ERROR("Failed to save container \"%s\" to disk", cont->common_config->id);
- ret = -1;
- }
+
out:
free(old_state);
free(current);
@@ -499,10 +587,9 @@ static void health_check_exec_success_handle(const container_exec_response *cont
// exec the healthcheck command in the container.
// Returns the exit code and probe output (if any)
-void *health_check_run(void *arg)
+static void health_check_run(const char *container_id)
{
int ret = 0;
- char *container_id = NULL;
char **cmd_slice = NULL;
char output[REV_BUF_SIZE] = { 0 };
char timebuffer[TIME_STR_SIZE] = { 0 };
@@ -514,13 +601,6 @@ void *health_check_run(void *arg)
defs_health_log_element *result = NULL;
container_config *config = NULL;
- if (arg == NULL) {
- ERROR("Invalid input arguments");
- return NULL;
- }
-
- container_id = util_strdup_s((char *)arg);
-
cont = containers_store_get(container_id);
if (cont == NULL) {
ERROR("Failed to get container info");
@@ -590,14 +670,10 @@ void *health_check_run(void *arg)
out:
util_free_array(cmd_slice);
- free(container_id);
- container_id = NULL;
free_defs_health_log_element(result);
free_container_exec_request(container_req);
free_container_exec_response(container_res);
container_unref(cont);
- DAEMON_CLEAR_ERRMSG();
- return NULL;
}
// Get a suitable probe implementation for the container's healthcheck configuration.
@@ -623,41 +699,81 @@ static health_probe_t get_probe(const container_t *cont)
}
}
+static bool valid_container_status_for_health_check(const char *container_id)
+{
+ bool bret = true;
+ const char *id = NULL;
+ container_t *cont = NULL;
+
+ cont = containers_store_get(container_id);
+ if (cont == NULL) {
+ ERROR("No such container:%s", container_id);
+ bret = false;
+ goto out;
+ }
+
+ id = cont->common_config->id;
+
+ if (!container_is_running(cont->state)) {
+ ERROR("Container %s is not running.", id);
+ bret = false;
+ goto out;
+ }
+
+ if (container_is_paused(cont->state)) {
+ ERROR("Container %s is paused.", id);
+ bret = false;
+ goto out;
+ }
+
+ if (container_is_restarting(cont->state)) {
+ ERROR("Container %s is restarting.", id);
+ bret = false;
+ goto out;
+ }
+
+out:
+ container_unref(cont);
+ return bret;
+}
+
static int do_monitor_interval(const char *container_id, health_check_manager_t *health_check,
types_timestamp_t *start_timestamp)
{
int ret = 0;
- pthread_t exec_tid = { 0 };
- if (pthread_create(&exec_tid, NULL, health_check_run, (void *)container_id)) {
- ERROR("Failed to create thread to exec health check");
+ if (!valid_container_status_for_health_check(container_id)) {
+ ERROR("Invalid container status for health check");
ret = -1;
goto out;
}
- if (pthread_join(exec_tid, NULL) != 0) {
- ERROR("Failed to run health check thread");
+
+ health_check_run(container_id);
+
+ if (transfer_monitor_idle_status(health_check) != 0) {
ret = -1;
goto out;
}
- if (get_health_check_monitor_state(health_check) == MONITOR_STOP) {
- ret = 0;
- goto out;
- }
- set_monitor_idle_status(health_check);
if (util_get_now_time_stamp(start_timestamp) == false) {
ERROR("Failed to get time stamp");
ret = -1;
goto out;
}
+
out:
return ret;
}
-static int do_monitor_default(int64_t probe_interval, health_check_manager_t *health_check,
+static int do_monitor_default(const char *container_id, int64_t probe_interval, health_check_manager_t *health_check,
const types_timestamp_t *start_timestamp, types_timestamp_t *last_timestamp)
{
int64_t time_interval = 0;
+ if (!valid_container_status_for_health_check(container_id)) {
+ ERROR("Invalid container status for health check");
+ return -1;
+ }
+
if (util_get_now_time_stamp(last_timestamp) == false) {
ERROR("Failed to get time stamp");
return -1;
@@ -668,13 +784,14 @@ static int do_monitor_default(int64_t probe_interval, health_check_manager_t *he
return -1;
}
- if (time_interval >= probe_interval) {
- set_monitor_interval_timeout_status(health_check);
+ if (time_interval >= probe_interval && transfer_monitor_interval_timeout_status(health_check) != 0) {
+ return -1;
}
util_usleep_nointerupt(500);
return 0;
}
+
// Run the container's monitoring thread until notified via "stop".
// There is never more than one monitor thread running per container at a time.
static void *health_check_monitor(void *arg)
@@ -689,14 +806,17 @@ static void *health_check_monitor(void *arg)
ERROR("Container id is empty");
return NULL;
}
- container_id = util_strdup_s((char *)arg);
+
+ container_id = (char *)arg;
+
+ prctl(PR_SET_NAME, "HealthCheck");
cont = containers_store_get(container_id);
if (cont == NULL) {
ERROR("Failed to get container info");
goto out;
}
-
+ set_monitor_exist_flag(cont->health_check, true);
if (util_get_now_time_stamp(&start_timestamp) == false) {
ERROR("Failed to monitor start time stamp");
goto out;
@@ -704,7 +824,7 @@ static void *health_check_monitor(void *arg)
probe_interval = (cont->common_config->config->healthcheck->interval == 0) ?
DEFAULT_PROBE_INTERVAL :
cont->common_config->config->healthcheck->interval;
- set_monitor_idle_status(cont->health_check);
+
while (true) {
switch (get_health_check_monitor_state(cont->health_check)) {
case MONITOR_STOP:
@@ -712,30 +832,35 @@ static void *health_check_monitor(void *arg)
goto out;
/* fall-through */
case MONITOR_INTERVAL:
- if (do_monitor_interval(container_id, cont->health_check, &start_timestamp)) {
+ if (do_monitor_interval(container_id, cont->health_check, &start_timestamp) != 0) {
goto out;
}
break;
case MONITOR_IDLE:
/* fall-through */
default:
- if (do_monitor_default(probe_interval, cont->health_check, &start_timestamp, &last_timestamp)) {
+ if (do_monitor_default(container_id, probe_interval, cont->health_check,
+ &start_timestamp, &last_timestamp) != 0) {
goto out;
}
break;
}
}
+
out:
free(container_id);
container_id = NULL;
+ // unhealthy when the monitor has stopped for compatibility reasons
+ set_health_status(cont, UNHEALTHY);
+ // post semaphore, indicating that the minitor process has exited
+ set_monitor_exist_flag(cont->health_check, false);
container_unref(cont);
DAEMON_CLEAR_ERRMSG();
return NULL;
}
// Ensure the health-check monitor is running or not, depending on the current
-// state of the container.
-// Called from monitor.go, with c locked.
+// state of the container. Called from monitor, with c locked.
void container_update_health_monitor(const char *container_id)
{
bool want_running = false;
@@ -746,6 +871,7 @@ void container_update_health_monitor(const char *container_id)
if (container_id == NULL) {
return;
}
+
cont = containers_store_get(container_id);
if (cont == NULL) {
ERROR("Failed to get container info");
@@ -756,13 +882,18 @@ void container_update_health_monitor(const char *container_id)
if (health == NULL) {
goto out;
}
+
probe = get_probe(cont);
- want_running = cont->state->state->running && !cont->state->state->paused && probe != HEALTH_NONE;
+ want_running = container_is_running(cont->state) && !container_is_paused(cont->state) && probe != HEALTH_NONE;
if (want_running) {
- open_health_check_monitor(cont->health_check);
pthread_t monitor_tid = { 0 };
- if (pthread_create(&monitor_tid, NULL, health_check_monitor, (void *)container_id)) {
+ char *cid = util_strdup_s(container_id);
+ // ensured that the health check monitor process is stopped
+ close_health_check_monitor(cont);
+ init_monitor_idle_status(cont->health_check);
+ if (pthread_create(&monitor_tid, NULL, health_check_monitor, (void *)cid)) {
+ free(cid);
ERROR("Failed to create thread to monitor health check...");
goto out;
}
@@ -779,8 +910,7 @@ out:
}
// Reset the health state for a newly-started, restarted or restored container.
-// initHealthMonitor is called from monitor.go and we should never be running
-// two instances at once.
+// initHealthMonitor is called from monitor and we should never be running two instances at once.
// Note: Called with container locked.
void container_init_health_monitor(const char *id)
{
@@ -809,14 +939,9 @@ void container_init_health_monitor(const char *id)
if (get_probe(cont) == HEALTH_NONE) {
goto out;
}
- // This is needed in case we're auto-restarting
- container_stop_health_checks(cont->common_config->id);
- if (cont->state == NULL || cont->state->state == NULL) {
- goto out;
- }
if (cont->state->state->health != NULL) {
- set_health_status(cont->state, HEALTH_STARTING);
+ set_health_status(cont, HEALTH_STARTING);
cont->state->state->health->failing_streak = 0;
} else {
cont->state->state->health = util_common_calloc_s(sizeof(defs_health));
@@ -824,12 +949,7 @@ void container_init_health_monitor(const char *id)
ERROR("out of memory");
goto out;
}
- set_health_status(cont->state, HEALTH_STARTING);
- }
-
- if (container_state_to_disk(cont)) {
- ERROR("Failed to save container \"%s\" to disk", id);
- goto out;
+ set_health_status(cont, HEALTH_STARTING);
}
container_update_health_monitor(id);
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index a4a2414c..e96a94d0 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -1247,8 +1247,6 @@ static int kill_with_signal(container_t *cont, uint32_t signal)
goto out;
}
- container_stop_health_checks(id);
-
ret = send_signal_to_process(cont->state->state->pid, cont->state->state->start_time, stop_signal, signal);
if (ret != 0) {
ERROR("Failed to send signal to container %s with signal %u", id, signal);
@@ -1353,6 +1351,7 @@ int stop_container(container_t *cont, int timeout, bool force, bool restart)
goto out;
}
}
+
out:
if (restart) {
cont->hostconfig->auto_remove = cont->hostconfig->auto_remove_bak;
diff --git a/test/mocks/health_check_mock.cc b/test/mocks/health_check_mock.cc
index 879e4d9c..4347a04e 100644
--- a/test/mocks/health_check_mock.cc
+++ b/test/mocks/health_check_mock.cc
@@ -31,3 +31,11 @@ void container_update_health_monitor(const char *container_id)
}
return;
}
+
+void container_stop_health_checks(const char *container_id)
+{
+ if (g_health_check_mock != nullptr) {
+ return g_health_check_mock->ContainerStopHealthCheck(container_id);
+ }
+ return;
+}
\ No newline at end of file
diff --git a/test/mocks/health_check_mock.h b/test/mocks/health_check_mock.h
index 7891f53c..ab8e20b0 100644
--- a/test/mocks/health_check_mock.h
+++ b/test/mocks/health_check_mock.h
@@ -22,6 +22,7 @@
class MockHealthCheck {
public:
MOCK_METHOD1(UpdateHealthMonitor, void(const char *container_id));
+ MOCK_METHOD1(ContainerStopHealthCheck, void(const char *container_id));
};
void MockHealthCheck_SetMock(MockHealthCheck* mock);
diff --git a/test/services/execution/execute/execution_extend/execution_extend_ut.cc b/test/services/execution/execute/execution_extend/execution_extend_ut.cc
index 2dc67814..03872340 100644
--- a/test/services/execution/execute/execution_extend/execution_extend_ut.cc
+++ b/test/services/execution/execute/execution_extend/execution_extend_ut.cc
@@ -204,6 +204,11 @@ void invokeStateSetPaused(container_state_t *s)
return;
}
+void invokeContainerStopHealthCheck(const char *container_id)
+{
+ return;
+}
+
TEST_F(ExecutionExtendUnitTest, test_container_extend_callback_init_pause)
{
service_container_callback_t cb;
@@ -220,6 +225,7 @@ TEST_F(ExecutionExtendUnitTest, test_container_extend_callback_init_pause)
EXPECT_CALL(m_containerState, IsRestarting(_)).WillRepeatedly(Invoke(invokeIsRestarting));
EXPECT_CALL(m_containerUnix, ContainerToDisk(_)).WillRepeatedly(Invoke(invokeContainerToDisk));
EXPECT_CALL(m_containerUnix, ContainerStateToDisk(_)).WillRepeatedly(Invoke(invokeContainerStateToDisk));
+ EXPECT_CALL(m_healthCheck, ContainerStopHealthCheck(_)).WillRepeatedly(Invoke(invokeContainerStopHealthCheck));
container_extend_callback_init(&cb);
ASSERT_EQ(cb.pause(request, &response), 0);
testing::Mock::VerifyAndClearExpectations(&m_runtime);
--
2.25.1

View File

@ -1,63 +0,0 @@
From 39e9ae73804880f523d83db6c8ad5d25d8bd79ed Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Mon, 1 Feb 2021 16:58:35 +0800
Subject: [PATCH 26/53] CI: supplementary testcase for health check monitor
Signed-off-by: wujing <wujing50@huawei.com>
---
CI/test_cases/container_cases/health_check.sh | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/CI/test_cases/container_cases/health_check.sh b/CI/test_cases/container_cases/health_check.sh
index eeb2749d..cc934fd8 100755
--- a/CI/test_cases/container_cases/health_check.sh
+++ b/CI/test_cases/container_cases/health_check.sh
@@ -160,6 +160,37 @@ function test_health_check_timeout()
return ${ret}
}
+function test_health_check_monitor()
+{
+ local ret=0
+ local image="busybox"
+ local test="health check monitor test => (${FUNCNAME[@]})"
+
+ msg_info "${test} starting..."
+
+ isula images | grep ${image}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
+
+ isula rm -f $(isula ps -qa)
+
+ container_name="health_check_monitor"
+ isula run -itd -n ${container_name} --health-cmd="sleep 3" --health-interval 3s busybox
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
+
+ isula stop -t 0 ${container_name} && isula start ${container_name} && \
+ isula stop -t 0 ${container_name} && isula start ${container_name}
+
+ health_check_monitor_count=$(ps -T -p $(cat /var/run/isulad.pid) | grep HealthCheck | wc -l)
+ [[ ${health_check_monitor_count} -ne 1 ]] && \
+ msg_err "${FUNCNAME[0]}:${LINENO} - multiple health check monitor thread container: ${container_name}" && ((ret++))
+
+ isula rm -f ${container_name}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to remove container: ${container_name}" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
declare -i ans=0
test_health_check_paraments || ((ans++))
@@ -168,5 +199,7 @@ test_health_check_normally || ((ans++))
test_health_check_timeout || ((ans++))
+test_health_check_monitor || ((ans++))
+
show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,36 +0,0 @@
From 002a546ec0ada609aebeccfc935d773968f89312 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Thu, 4 Feb 2021 10:43:59 +0800
Subject: [PATCH 27/53] add container lock when clean container resource
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/daemon/modules/service/service_container.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index c4b9dbd6..6551bfbf 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -968,12 +968,17 @@ int clean_container_resource(const char *id, const char *runtime, pid_t pid)
goto out;
}
+ container_lock(cont);
ret = do_clean_container(cont, pid);
if (ret != 0) {
ERROR("Runtime clean container resource failed");
ret = -1;
- goto out;
+ goto unlock;
}
+
+unlock:
+ container_unlock(cont);
+
out:
container_unref(cont);
return ret;
--
2.25.1

View File

@ -1,36 +0,0 @@
From 3b8075caac328d88018d4607ee8d18138440e8b8 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 4 Feb 2021 15:43:33 +0800
Subject: [PATCH 28/53] sleep some time before calculate to make sure fd closed
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/container_cases/cp.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CI/test_cases/container_cases/cp.sh b/CI/test_cases/container_cases/cp.sh
index 67a36909..09b6ddff 100644
--- a/CI/test_cases/container_cases/cp.sh
+++ b/CI/test_cases/container_cases/cp.sh
@@ -329,6 +329,9 @@ function cp_test_t()
msg_info "${test} starting..."
local isulad_pid=$(cat /var/run/isulad.pid)
+
+ # wait some time to make sure fd closed
+ sleep 3
local fd_num1=$(ls -l /proc/$isulad_pid/fd | wc -l)
[[ $fd_num1 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
@@ -362,6 +365,8 @@ function cp_test_t()
rm -rf $cpfiles
+ # wait some time to make sure fd closed
+ sleep 3
local fd_num2=$(ls -l /proc/$isulad_pid/fd | wc -l)
[[ $fd_num2 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
--
2.25.1

View File

@ -1,41 +0,0 @@
From 3660db243160d45535c1d020844b694e495b4cd7 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Mon, 8 Feb 2021 11:03:58 +0800
Subject: [PATCH 29/53] stats: fix wrong memory usage info in stats
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/cmd/isula/extend/stats.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/cmd/isula/extend/stats.c b/src/cmd/isula/extend/stats.c
index 03544325..724cf381 100644
--- a/src/cmd/isula/extend/stats.c
+++ b/src/cmd/isula/extend/stats.c
@@ -101,10 +101,12 @@ static void stats_print(const struct isula_container_info *stats)
int len;
double cpu_percent = 0.0;
char *short_id = NULL;
+ // workingset = usage - total_inactive_file
+ uint64_t workingset = memory_get_working_set(stats);
isula_size_humanize(stats->blkio_read, iosb_read_str, sizeof(iosb_read_str));
isula_size_humanize(stats->blkio_write, iosb_write_str, sizeof(iosb_write_str));
- isula_size_humanize(stats->mem_used, mem_used_str, sizeof(mem_used_str));
+ isula_size_humanize(workingset, mem_used_str, sizeof(mem_used_str));
isula_size_humanize(stats->mem_limit, mem_limit_str, sizeof(mem_limit_str));
len = snprintf(iosb_str, sizeof(iosb_str), "%s / %s", iosb_read_str, iosb_write_str);
@@ -142,8 +144,7 @@ static void stats_print(const struct isula_container_info *stats)
if (strlen(short_id) > SHORTIDLEN) {
short_id[SHORTIDLEN] = '\0';
}
- // workingset = usage - total_inactive_file
- uint64_t workingset = memory_get_working_set(stats);
+
printf("%-16s %-10.2f %-26s %-10.2f %-26s %-10llu", short_id, cpu_percent, mem_str,
stats->mem_limit ? ((double)workingset / stats->mem_limit) * PERCENT : 0.00, iosb_str,
(unsigned long long)stats->pids_current);
--
2.25.1

View File

@ -1,36 +0,0 @@
From cb82131f8b4b9a1d517b9e4da0d707008567a89e Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Mon, 8 Feb 2021 11:23:24 +0800
Subject: [PATCH 30/53] save health check log to disk before unhealthy
Signed-off-by: wujing <wujing50@huawei.com>
---
src/daemon/modules/container/health_check/health_check.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/daemon/modules/container/health_check/health_check.c b/src/daemon/modules/container/health_check/health_check.c
index c6ccbbf2..a01679db 100644
--- a/src/daemon/modules/container/health_check/health_check.c
+++ b/src/daemon/modules/container/health_check/health_check.c
@@ -429,6 +429,10 @@ static int handle_increment_streak(container_t *cont, int retries)
ret = -1;
}
}
+ } else {
+ if (container_state_to_disk(cont)) {
+ WARN("Failed to save container \"%s\" to disk", cont->common_config->id);
+ }
}
return ret;
@@ -542,6 +546,7 @@ static int handle_probe_result(const char *container_id, const defs_health_log_e
}
// else we're starting or healthy. Stay in that state.
}
+
// note: replicate Health status changes
current = get_health_status(cont->state);
if (strcmp(old_state, current) != 0) {
--
2.25.1

View File

@ -1,179 +0,0 @@
From a3ee97e18060785b22529dca0ea771e7f3e94293 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Mon, 8 Feb 2021 15:56:36 +0800
Subject: [PATCH 31/53] unpack: try to remove and replace dst_path while unpack
if dst path exits, we just want to remove and replace it.
exception: when the exited dstpath is directory and the file from the layer is also a directory.
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/utils/tar/util_archive.c | 61 +++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 19 deletions(-)
diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c
index 1b9553c9..a7522036 100644
--- a/src/utils/tar/util_archive.c
+++ b/src/utils/tar/util_archive.c
@@ -394,6 +394,29 @@ static int rebase_hardlink(struct archive_entry *entry, const char *src_base, co
return 0;
}
+// if dst path exits, we just want to remove and replace it.
+// exception: when the exited dstpath is directory and the file from the layer is also a directory.
+static void try_to_replace_exited_dst(const char *dst_path, struct archive_entry *entry)
+{
+ struct stat s;
+ int nret;
+
+ nret = lstat(dst_path, &s);
+ if (nret < 0) {
+ return;
+ }
+
+ if (S_ISDIR(s.st_mode) && archive_entry_filetype(entry) == AE_IFDIR) {
+ return;
+ }
+
+ if (util_recursive_remove_path(dst_path) != 0) {
+ ERROR("Failed to remove path %s while unpack", dst_path);
+ }
+
+ return;
+}
+
int archive_unpack_handler(const struct io_read_wrapper *content, const struct archive_options *options)
{
int ret = 0;
@@ -499,6 +522,8 @@ int archive_unpack_handler(const struct io_read_wrapper *content, const struct a
continue;
}
+ try_to_replace_exited_dst(dst_path, entry);
+
ret = archive_write_header(ext, entry);
if (ret != ARCHIVE_OK) {
ERROR("Fail to handle tar header: %s", archive_error_string(ext));
@@ -874,8 +899,8 @@ static ssize_t stream_write_data(struct archive *a, void *client_data, const voi
return size;
}
-static int tar_all(const struct io_write_wrapper *writer, const char *tar_dir,
- const char *src_base, const char *dst_base)
+static int tar_all(const struct io_write_wrapper *writer, const char *tar_dir, const char *src_base,
+ const char *dst_base)
{
struct archive *r = NULL;
struct archive *w = NULL;
@@ -906,7 +931,7 @@ static int tar_all(const struct io_write_wrapper *writer, const char *tar_dir,
}
archive_write_set_format_pax(w);
archive_write_set_options(w, "xattrheader=SCHILY");
- ret = archive_write_open(w, (void*)writer, NULL, stream_write_data, NULL);
+ ret = archive_write_open(w, (void *)writer, NULL, stream_write_data, NULL);
if (ret != ARCHIVE_OK) {
ERROR("open archive write failed: %s", archive_error_string(w));
fprintf(stderr, "open archive write failed: %s\n", archive_error_string(w));
@@ -924,7 +949,7 @@ out:
static ssize_t fd_write(void *context, const void *data, size_t len)
{
- return util_write_nointr(*(int*)context, data, len);
+ return util_write_nointr(*(int *)context, data, len);
}
int archive_chroot_tar(char *path, char *file, char **errmsg)
@@ -989,7 +1014,7 @@ int archive_chroot_tar(char *path, char *file, char **errmsg)
goto child_out;
}
- pipe_context.context = (void*)&fd;
+ pipe_context.context = (void *)&fd;
pipe_context.write_func = fd_write;
ret = tar_all(&pipe_context, ".", ".", NULL);
@@ -1024,7 +1049,7 @@ cleanup:
static ssize_t pipe_read(void *context, void *buf, size_t len)
{
- return util_read_nointr(*(int*)context, buf, len);
+ return util_read_nointr(*(int *)context, buf, len);
}
static ssize_t archive_context_write(const void *context, const void *buf, size_t len)
@@ -1041,7 +1066,7 @@ static ssize_t archive_context_write(const void *context, const void *buf, size_
static ssize_t pipe_write(void *context, const void *data, size_t len)
{
- return util_write_nointr(*(int*)context, data, len);
+ return util_write_nointr(*(int *)context, data, len);
}
static ssize_t archive_context_read(void *context, void *buf, size_t len)
@@ -1128,9 +1153,8 @@ static int archive_context_close(void *context, char **err)
return ret;
}
-int archive_chroot_untar_stream(const struct io_read_wrapper *context, const char *chroot_dir,
- const char *untar_dir, const char *src_base, const char *dst_base,
- char **errmsg)
+int archive_chroot_untar_stream(const struct io_read_wrapper *context, const char *chroot_dir, const char *untar_dir,
+ const char *src_base, const char *dst_base, char **errmsg)
{
struct io_read_wrapper pipe_context = { 0 };
int pipe_stream[2] = { -1, -1 };
@@ -1143,10 +1167,9 @@ int archive_chroot_untar_stream(const struct io_read_wrapper *context, const cha
char *buf = NULL;
size_t buf_len = ARCHIVE_BLOCK_SIZE;
ssize_t read_len;
- struct archive_options options = {
- .whiteout_format = NONE_WHITEOUT_FORMATE,
- .src_base = src_base,
- .dst_base = dst_base
+ struct archive_options options = { .whiteout_format = NONE_WHITEOUT_FORMATE,
+ .src_base = src_base,
+ .dst_base = dst_base
};
buf = util_common_calloc_s(buf_len);
@@ -1201,7 +1224,7 @@ int archive_chroot_untar_stream(const struct io_read_wrapper *context, const cha
goto child_out;
}
- pipe_context.context = (void*)&pipe_stream[0];
+ pipe_context.context = (void *)&pipe_stream[0];
pipe_context.read = pipe_read;
ret = archive_unpack_handler(&pipe_context, &options);
@@ -1252,8 +1275,8 @@ cleanup:
return ret;
}
-int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, const char *src_base,
- const char *dst_base, struct io_read_wrapper *reader)
+int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, const char *src_base, const char *dst_base,
+ struct io_read_wrapper *reader)
{
struct io_write_wrapper pipe_context = { 0 };
int keepfds[] = { -1, -1, -1 };
@@ -1273,7 +1296,7 @@ int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, cons
}
pid = fork();
- if (pid == (pid_t) - 1) {
+ if (pid == (pid_t) -1) {
ERROR("Failed to fork: %s", strerror(errno));
goto free_out;
}
@@ -1320,7 +1343,7 @@ int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, cons
goto child_out;
}
- pipe_context.context = (void*)&pipe_stream[1];
+ pipe_context.context = (void *)&pipe_stream[1];
pipe_context.write_func = pipe_write;
ret = tar_all(&pipe_context, tar_base_name, src_base, dst_base);
--
2.25.1

View File

@ -1,93 +0,0 @@
From 513530a98d627ae84b1415f93af5bc298b39ba9d Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Mon, 8 Feb 2021 16:38:22 +0800
Subject: [PATCH 32/53] fd leak check in cp.sh should not include pull fd check
pull may increase fd, we can check pull fd leak in registry.sh
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/container_cases/cp.sh | 14 ++++++++------
CI/test_cases/image_cases/registry.sh | 21 +++++++++++++++++++++
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/CI/test_cases/container_cases/cp.sh b/CI/test_cases/container_cases/cp.sh
index 09b6ddff..fef637a5 100644
--- a/CI/test_cases/container_cases/cp.sh
+++ b/CI/test_cases/container_cases/cp.sh
@@ -328,18 +328,19 @@ function cp_test_t()
msg_info "${test} starting..."
+ isula inspect ${image}
+ if [ x"$?" != x"0" ];then
+ isula pull ${image}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+ fi
+
local isulad_pid=$(cat /var/run/isulad.pid)
# wait some time to make sure fd closed
sleep 3
local fd_num1=$(ls -l /proc/$isulad_pid/fd | wc -l)
[[ $fd_num1 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
-
- isula inspect ${image}
- if [ x"$?" != x"0" ];then
- isula pull ${image}
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
- fi
+ ls -l /proc/$isulad_pid/fd
isula images | grep busybox
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
@@ -369,6 +370,7 @@ function cp_test_t()
sleep 3
local fd_num2=$(ls -l /proc/$isulad_pid/fd | wc -l)
[[ $fd_num2 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
+ ls -l /proc/$isulad_pid/fd
# make sure fd not increase after test
[[ $fd_num1 -ne $fd_num2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - fd number not right" && ((ret++))
diff --git a/CI/test_cases/image_cases/registry.sh b/CI/test_cases/image_cases/registry.sh
index 042b1f4a..4e6adc28 100755
--- a/CI/test_cases/image_cases/registry.sh
+++ b/CI/test_cases/image_cases/registry.sh
@@ -26,6 +26,18 @@ source ../helpers.sh
function isula_pull()
{
isula rm -f `isula ps -a -q`
+
+ isula pull busybox
+ fn_check_eq "$?" "0" "isula pull busybox"
+
+ local isulad_pid=$(cat /var/run/isulad.pid)
+
+ # wait some time to make sure fd closed
+ sleep 3
+ local fd_num1=$(ls -l /proc/$isulad_pid/fd | wc -l)
+ [[ $fd_num1 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
+ ls -l /proc/$isulad_pid/fd
+
isula rmi busybox
for i in `seq 1 10`
@@ -36,6 +48,15 @@ function isula_pull()
fn_check_eq "$?" "0" "isula pull busybox"
wait
+ # wait some time to make sure fd closed
+ sleep 3
+ local fd_num2=$(ls -l /proc/$isulad_pid/fd | wc -l)
+ [[ $fd_num2 -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - can not get fd number" && ((ret++))
+ ls -l /proc/$isulad_pid/fd
+
+ # make sure fd not increase after remove and pull busybox
+ [[ $fd_num1 -ne $fd_num2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - fd number not right" && ((ret++))
+
isula inspect busybox
fn_check_eq "$?" "0" "isula inspect busybox"
--
2.25.1

View File

@ -1,116 +0,0 @@
From 085f9c923fc7e833bcbf93ece33dda1c0e7e0a66 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Tue, 9 Feb 2021 14:34:54 +0800
Subject: [PATCH 33/53] devmapper: modify log msg
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../graphdriver/devmapper/deviceset.c | 17 ++++++++---------
.../graphdriver/devmapper/metadata_store.c | 2 --
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index 67b1ba9c..2bd3b9c8 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -176,7 +176,7 @@ out:
return 0;
}
-static char *metadata_dir(struct device_set *devset)
+static char *metadata_dir(const struct device_set *devset)
{
return util_path_join(devset->root, "metadata");
}
@@ -411,7 +411,7 @@ out:
return exist;
}
-static image_devmapper_device_info *load_metadata(struct device_set *devset, const char *hash)
+static image_devmapper_device_info *load_metadata(const struct device_set *devset, const char *hash)
{
image_devmapper_device_info *info = NULL;
char metadata_file[PATH_MAX] = { 0 };
@@ -420,7 +420,6 @@ static image_devmapper_device_info *load_metadata(struct device_set *devset, con
parser_error err = NULL;
if (hash == NULL) {
- ERROR("Invalid input param");
return NULL;
}
@@ -432,13 +431,13 @@ static image_devmapper_device_info *load_metadata(struct device_set *devset, con
nret = snprintf(metadata_file, sizeof(metadata_file), "%s/%s", metadata_path, util_valid_str(hash) ? hash : "base");
if (nret < 0 || (size_t)nret >= sizeof(metadata_file)) {
- ERROR("Get metadata file with hash:%s path failed", hash);
+ ERROR("Failed to snprintf metadata file path with hash:%s, path is too long", hash);
goto out;
}
info = image_devmapper_device_info_parse_file(metadata_file, NULL, &err);
if (info == NULL) {
- ERROR("load metadata file %s failed %s", metadata_file, err != NULL ? err : "");
+ SYSERROR("Load metadata file:%s failed:%s", metadata_file, err);
goto out;
}
@@ -448,7 +447,7 @@ static image_devmapper_device_info *load_metadata(struct device_set *devset, con
}
if (info->device_id > MAX_DEVICE_ID) {
- ERROR("devmapper: Ignoring Invalid DeviceId=%d", info->device_id);
+ ERROR("devmapper: device id:%d out of limits, to be ignored", info->device_id);
free_image_devmapper_device_info(info);
info = NULL;
goto out;
@@ -878,7 +877,7 @@ static int load_transaction_metadata(struct device_set *devset)
trans = image_devmapper_transaction_parse_file(fname, NULL, &err);
if (trans == NULL) {
- ERROR("devmapper: load transaction metadata file error %s", err);
+ SYSERROR("Load transaction metadata file:%s failed:%s", fname, err);
ret = -1;
goto out;
}
@@ -1061,7 +1060,7 @@ static int load_deviceset_metadata(struct device_set *devset)
deviceset_meta = image_devmapper_deviceset_metadata_parse_file(meta_file, NULL, &err);
if (deviceset_meta == NULL) {
- ERROR("devmapper: load deviceset metadata file error %s", err);
+ SYSERROR("Load deviceset metadata file:%s failed:%s", meta_file, err);
ret = -1;
goto out;
}
@@ -2781,7 +2780,7 @@ int add_device(const char *hash, const char *base_hash, struct device_set *devse
base_device_info = lookup_device(devset, util_valid_str(base_hash) ? base_hash : "base");
if (base_device_info == NULL) {
- ERROR("Lookup device %s failed", util_valid_str(base_hash) ? base_hash : "base");
+ ERROR("Lookup device %s failed, not found", util_valid_str(base_hash) ? base_hash : "base");
ret = -1;
goto free_out;
}
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c
index 01858748..c8d10b7a 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c
@@ -34,7 +34,6 @@ void devmapper_device_info_ref_inc(devmapper_device_info_t *device_info)
static void free_devmapper_device_info_t(devmapper_device_info_t *ptr)
{
if (ptr == NULL) {
- ERROR("invalid argument");
return;
}
@@ -49,7 +48,6 @@ void devmapper_device_info_ref_dec(devmapper_device_info_t *device_info)
bool is_zero = false;
if (device_info == NULL) {
- ERROR("invalid argument");
return;
}
--
2.25.1

View File

@ -1,111 +0,0 @@
From a7f40f1e13f08f03ca369dc908a399dfc3f7fe17 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Fri, 19 Feb 2021 19:06:43 +0800
Subject: [PATCH 34/53] name_id_index: fix restore fail to remove name index
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/executor/container_cb/execution_create.c | 10 ++++++++--
src/daemon/modules/container/containers_store.c | 12 ++++++++++--
src/daemon/modules/container/restore/restore.c | 4 ++--
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index 7ad55fa1..acad7fe3 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -440,6 +440,8 @@ static char *try_generate_id()
value = container_name_index_get(id);
if (value != NULL) {
+ free(value);
+ value = NULL;
continue;
} else {
goto out;
@@ -631,10 +633,14 @@ static int maintain_container_id(const container_create_request *request, char *
EVENT("Event: {Object: %s, Type: Creating %s}", id, name);
if (!container_name_index_add(name, id)) {
- ERROR("Name %s is in use", name);
+ char *used_id = NULL;
+ used_id = container_name_index_get(name);
+ ERROR("Name %s is in use by container %s", name, used_id);
isulad_set_error_message("Conflict. The name \"%s\" is already in use by container %s. "
"You have to remove (or rename) that container to be able to reuse that name.",
- name, name);
+ name, used_id);
+ free(used_id);
+ used_id = NULL;
ret = -1;
goto out;
}
diff --git a/src/daemon/modules/container/containers_store.c b/src/daemon/modules/container/containers_store.c
index bbfbda3a..42972392 100644
--- a/src/daemon/modules/container/containers_store.c
+++ b/src/daemon/modules/container/containers_store.c
@@ -128,6 +128,7 @@ static container_t *containers_store_get_by_id(const char *id)
static container_t *containers_store_get_by_name(const char *name)
{
char *id = NULL;
+ container_t *cont = NULL;
if (name == NULL) {
ERROR("No container name supplied");
@@ -140,7 +141,10 @@ static container_t *containers_store_get_by_name(const char *name)
return NULL;
}
- return containers_store_get_by_id(id);
+ cont = containers_store_get_by_id(id);
+
+ free(id);
+ return cont;
}
/* containers store get container by prefix */
@@ -443,6 +447,7 @@ unlock_out:
char *container_name_index_get(const char *name)
{
char *id = NULL;
+ char *result = NULL;
if (name == NULL) {
return id;
@@ -451,11 +456,14 @@ char *container_name_index_get(const char *name)
ERROR("lock name index failed");
return id;
}
+
id = map_search(g_indexs->map, (void *)name);
+ result = util_strdup_s(id);
+
if (pthread_rwlock_unlock(&g_indexs->rwlock) != 0) {
ERROR("unlock name index failed");
}
- return id;
+ return result;
}
/* name index remove */
diff --git a/src/daemon/modules/container/restore/restore.c b/src/daemon/modules/container/restore/restore.c
index 13cdcd24..a7ee11a2 100644
--- a/src/daemon/modules/container/restore/restore.c
+++ b/src/daemon/modules/container/restore/restore.c
@@ -455,11 +455,11 @@ error_load:
if (remove_invalid_container(cont, runtime, rootpath, statepath, subdir[i])) {
ERROR("Failed to delete subdir:%s", subdir[i]);
}
- container_unref(cont);
if (index_flag) {
- container_name_index_remove(subdir[i]);
+ container_name_index_remove(cont->common_config->name);
}
+ container_unref(cont);
continue;
}
}
--
2.25.1

View File

@ -1,26 +0,0 @@
From 2c08c9e9ce52afbe46753f44daec70270667f760 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Sat, 20 Feb 2021 11:07:59 +0800
Subject: [PATCH 35/53] thread function calls DAEMON_CLEAR_ERRORMSG to prevent
memory leak
Signed-off-by: wujing <wujing50@huawei.com>
---
src/daemon/modules/container/health_check/health_check.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/daemon/modules/container/health_check/health_check.c b/src/daemon/modules/container/health_check/health_check.c
index a01679db..dc00ae33 100644
--- a/src/daemon/modules/container/health_check/health_check.c
+++ b/src/daemon/modules/container/health_check/health_check.c
@@ -407,6 +407,7 @@ static void *stop_container_on_unhealthy(void *arg)
out:
free(container_id);
container_unref(cont);
+ DAEMON_CLEAR_ERRMSG();
return NULL;
}
--
2.25.1

View File

@ -1,359 +0,0 @@
From 4726f2f980f42963a753350aa5306cbe6a4cc668 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Sat, 20 Feb 2021 09:44:19 +0800
Subject: [PATCH 36/53] modify resume task name
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../graphdriver/devmapper/deviceset.c | 68 +++++++++++++------
.../graphdriver/devmapper/wrapper_devmapper.c | 57 +++++++++-------
.../graphdriver/devmapper/wrapper_devmapper.h | 2 +-
3 files changed, 81 insertions(+), 46 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index 2bd3b9c8..0b0394c5 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -125,7 +125,8 @@ static int devmapper_parse_options(struct device_set *devset, const char **optio
devset->min_free_space_percent = (uint32_t)converted;
} else if (strcasecmp(dup, "dm.basesize") == 0) {
int64_t converted = 0;
- if (util_parse_byte_size_string(val, &converted) != 0) {
+ ret = util_parse_byte_size_string(val, &converted);
+ if (ret != 0) {
ERROR("Invalid size: '%s': %s", val, strerror(-ret));
isulad_set_error_message("Invalid size: '%s': %s", val, strerror(-ret));
ret = -1;
@@ -435,6 +436,11 @@ static image_devmapper_device_info *load_metadata(const struct device_set *devse
goto out;
}
+ if (!util_file_exists(metadata_file)) {
+ ERROR("No such file:%s, need not to load", metadata_file);
+ goto out;
+ }
+
info = image_devmapper_device_info_parse_file(metadata_file, NULL, &err);
if (info == NULL) {
SYSERROR("Load metadata file:%s failed:%s", metadata_file, err);
@@ -594,6 +600,7 @@ static uint64_t get_base_device_size(struct device_set *devset)
device_info = lookup_device(devset, "base");
if (device_info == NULL) {
+ ERROR("No such device:\"base\"");
return 0;
}
@@ -1688,10 +1695,10 @@ out:
(void)deactivate_device(devset, base_info);
}
- if (resume_dev && dev_resume_device(dm_name) != 0) {
- ERROR("devmapper: resume dm with name:%s failed", dm_name);
- ret = -1;
+ if (resume_dev) {
+ dev_resume_device(dm_name);
}
+
free(dm_name);
return ret;
}
@@ -2558,7 +2565,8 @@ static int determine_driver_capabilities(const char *version, struct device_set
goto out;
}
- if (util_parse_byte_size_string(tmp_str[0], &major) != 0) {
+ ret = util_parse_byte_size_string(tmp_str[0], &major);
+ if (ret != 0) {
ERROR("devmapper: invalid size: '%s': %s", tmp_str[0], strerror(-ret));
ret = -1;
goto out;
@@ -2577,7 +2585,8 @@ static int determine_driver_capabilities(const char *version, struct device_set
goto out;
}
- if (util_parse_byte_size_string(tmp_str[1], &minor) != 0) {
+ ret = util_parse_byte_size_string(tmp_str[1], &minor);
+ if (ret != 0) {
ERROR("devmapper: invalid size: '%s': %s", tmp_str[1], strerror(-ret));
ret = -1;
goto out;
@@ -2742,7 +2751,8 @@ static int parse_storage_opt(const json_map_string_string *opts, uint64_t *size)
if (strcasecmp("size", opts->keys[i]) == 0) {
int64_t converted = 0;
- if (util_parse_byte_size_string(opts->values[i], &converted) != 0) {
+ ret = util_parse_byte_size_string(opts->values[i], &converted);
+ if (ret != 0) {
ERROR("Invalid size: '%s': %s", opts->values[i], strerror(-ret));
ret = -1;
goto out;
@@ -2760,6 +2770,31 @@ out:
return ret;
}
+static int grow_device_fs(struct device_set *devset, const char *hash, uint64_t size, uint64_t base_size)
+{
+ int ret = 0;
+ devmapper_device_info_t *device_info = NULL;
+
+ if (size <= base_size) {
+ return 0;
+ } else {
+ DEBUG("devmapper: new fs size is larger than old basesize, start to grow fs");
+ device_info = lookup_device(devset, hash);
+ if (device_info == NULL) {
+ ERROR("devmapper: lookup device %s failed", hash);
+ ret = -1;
+ goto out;
+ }
+
+ if (grow_fs(devset, device_info->info) != 0) {
+ ret = -1;
+ goto out;
+ }
+ }
+out:
+ return ret;
+}
+
int add_device(const char *hash, const char *base_hash, struct device_set *devset,
const json_map_string_string *storage_opts)
{
@@ -2820,18 +2855,14 @@ int add_device(const char *hash, const char *base_hash, struct device_set *devse
goto free_out;
}
- if (size > base_device_info->info->size) {
- DEBUG("devmapper: new fs size is larger than old basesize, start to grow fs");
- device_info = lookup_device(devset, hash);
- if (device_info == NULL) {
- ERROR("devmapper: lookup device %s failed", hash);
- ret = -1;
- goto free_out;
- }
- if (grow_fs(devset, device_info->info) != 0) {
- ret = -1;
- goto free_out;
+ if (grow_device_fs(devset, hash, size, base_device_info->info->size) != 0) {
+ ERROR("Grow new deivce fs failed");
+ // Here, we need to delete device directly instead of deferred deleting, so that we can retry to add device with the same hash successfully.
+ if (do_delete_device(devset, hash, true) != 0) {
+ ERROR("devmapper: remove new snapshot device failed");
}
+ ret = -1;
+ goto free_out;
}
free_out:
@@ -2839,7 +2870,6 @@ free_out:
devmapper_device_info_ref_dec(device_info);
if (pthread_rwlock_unlock(&devset->devmapper_driver_rwlock)) {
ERROR("unlock devmapper conf failed");
- return -1;
}
return ret;
}
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
index 5748ec54..38ed5615 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
@@ -45,6 +45,9 @@ char *dev_strerror(int errnum)
case ERR_TASK_SET_COOKIE:
errmsg = "Task set cookie error";
break;
+ case ERR_NIL_COOKIE:
+ errmsg = "cookie ptr can't be nil";
+ break;
case ERR_TASK_SET_ADD_NODE:
errmsg = "Task add dm node failed";
break;
@@ -443,6 +446,7 @@ free_out:
int dev_delete_device_force(const char *name)
{
int ret = 0;
+ int nret = 0;
struct dm_task *dmt = NULL;
uint32_t cookie = 0;
@@ -459,8 +463,9 @@ int dev_delete_device_force(const char *name)
goto out;
}
- if (set_cookie(dmt, &cookie, 0) != 0) {
- ERROR("devicemapper: set cookie failed");
+ nret = set_cookie(dmt, &cookie, 0);
+ if (nret != 0) {
+ ERROR("set cookie failed:%s", dev_strerror(nret));
ret = -1;
goto out;
}
@@ -468,7 +473,7 @@ int dev_delete_device_force(const char *name)
g_dm_saw_busy = false;
g_dm_saw_enxio = false;
if (dm_task_run(dmt) != 1) {
- ERROR("devicemapper: run task to delete device faild");
+ ERROR("devicemapper: task run failed");
if (g_dm_saw_busy) {
ERROR("devicemapper: delete task run err type is \"device is busy\"");
ret = ERR_BUSY;
@@ -498,6 +503,7 @@ out:
int dev_remove_device_deferred(const char *name)
{
int ret = 0;
+ int nret = 0;
struct dm_task *dmt = NULL;
uint32_t cookie = 0;
uint16_t flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK;
@@ -521,15 +527,16 @@ int dev_remove_device_deferred(const char *name)
goto out;
}
- if (set_cookie(dmt, &cookie, flags) != 0) {
- ERROR("devicemapper: set cookie failed");
+ nret = set_cookie(dmt, &cookie, flags);
+ if (nret != 0) {
+ ERROR("set cookie failed:%s", dev_strerror(nret));
ret = -1;
goto out;
}
g_dm_saw_enxio = false;
if (dm_task_run(dmt) != 1) {
- ERROR("devicemapper: Error running RemoveDeviceDeferred %d", ret);
+ ERROR("devicemapper: task run failed");
if (g_dm_saw_enxio) {
ERROR("devicemapper: delete deferred task run err type is \"No such device or address\"");
ret = ERR_ENXIO;
@@ -694,7 +701,7 @@ int dev_create_device(const char *pool_fname, int device_id)
} else {
ret = -1;
}
- ERROR("devicemapper: task run failed to create device");
+ ERROR("devicemapper: task run failed");
goto cleanup;
}
@@ -754,7 +761,7 @@ int dev_delete_device(const char *pool_fname, int device_id)
DEBUG("devicemapper: device(id:%d) from pool(%s) does not exist", device_id, pool_fname);
goto cleanup;
}
- ERROR("devicemapper: Error running dev_delete_device");
+ ERROR("devicemapper: task run failed");
ret = -1;
goto cleanup;
}
@@ -786,7 +793,7 @@ int dev_suspend_device(const char *dm_name)
}
if (dm_task_run(dmt) != 1) {
- ERROR("devicemapper: Error running deviceCreate (ActivateDevice)");
+ ERROR("devicemapper: task run failed");
ret = -1;
goto out;
}
@@ -800,34 +807,32 @@ out:
// ResumeDevice is the programmatic example of "dmsetup resume".
// It un-suspends the specified device.
-int dev_resume_device(const char *dm_name)
+void dev_resume_device(const char *dm_name)
{
- int ret = 0;
+ int nret = 0;
uint32_t cookie = 0;
uint16_t flags = 0;
struct dm_task *dmt = NULL;
if (dm_name == NULL) {
ERROR("devicemapper: invalid input params to resume device");
- return -1;
+ return;
}
- dmt = task_create_named(DM_DEVICE_SUSPEND, dm_name);
+ dmt = task_create_named(DM_DEVICE_RESUME, dm_name);
if (dmt == NULL) {
- ERROR("devicemapper:create named task(DM_DEVICE_SUSPEND) failed");
- ret = -1;
+ ERROR("devicemapper: create named task(DM_DEVICE_RESUME) failed");
goto out;
}
- if (set_cookie(dmt, &cookie, flags) != 0) {
- ERROR("devicemapper: Can't set cookie %d", ret);
- ret = -1;
+ nret = set_cookie(dmt, &cookie, flags);
+ if (nret != 0) {
+ ERROR("set cookie failed:%s", dev_strerror(nret));
goto out;
}
if (dm_task_run(dmt) != 1) {
- ERROR("devicemapper: Error running deviceResume %d", ret);
- ret = -1;
+ ERROR("devicemapper: run task of DM_DEVICE_RESUME failed");
}
DEBUG("Start udev wait on resume device");
@@ -837,7 +842,6 @@ out:
if (dmt != NULL) {
dm_task_destroy(dmt);
}
- return ret;
}
int dev_active_device(const char *pool_name, const char *name, int device_id, uint64_t size)
@@ -882,14 +886,15 @@ int dev_active_device(const char *pool_name, const char *name, int device_id, ui
goto out;
}
- if (set_cookie(dmt, &cookie, flags) != 0) {
- ERROR("devicemapper: Can't set cookie");
+ nret = set_cookie(dmt, &cookie, flags);
+ if (nret != 0) {
+ ERROR("set cookie failed:%s", dev_strerror(nret));
ret = -1;
goto out;
}
if (dm_task_run(dmt) != 1) {
- ERROR("devicemapper: error running deviceCreate (ActivateDevice) %d", ret);
+ ERROR("devicemapper: task run failed");
ret = -1;
}
@@ -944,7 +949,7 @@ int dev_cancel_deferred_remove(const char *dm_name)
ret = ERR_ENXIO;
goto cleanup;
}
- ERROR("devicemapper: Error running CancelDeferredRemove");
+ ERROR("devicemapper: task run failed");
ret = -1;
goto cleanup;
}
@@ -1070,7 +1075,7 @@ int dev_create_snap_device_raw(const char *pool_name, int device_id, int base_de
ret = ERR_DEVICE_ID_EXISTS;
goto cleanup;
}
- ERROR("devicemapper: Error running deviceCreate (CreateSnapDeviceRaw)");
+ ERROR("devicemapper: task run failed");
ret = -1;
goto cleanup;
}
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h
index 0f45a87d..6a45db58 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h
@@ -119,7 +119,7 @@ int dev_delete_device(const char *pool_fname, int device_id);
int dev_suspend_device(const char *dm_name);
-int dev_resume_device(const char *dm_name);
+void dev_resume_device(const char *dm_name);
int dev_active_device(const char *pool_name, const char *name, int device_id, uint64_t size);
--
2.25.1

View File

@ -1,41 +0,0 @@
From 3db92c961e93093d8520f4e46255c12e774b841b Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Mon, 22 Feb 2021 08:04:44 +0800
Subject: [PATCH 37/53] cleadcode: Remove extra semicolons
Signed-off-by: wujing <wujing50@huawei.com>
---
src/client/connect/grpc/client_base.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/client/connect/grpc/client_base.h b/src/client/connect/grpc/client_base.h
index 496370a8..5d1e7f0c 100644
--- a/src/client/connect/grpc/client_base.h
+++ b/src/client/connect/grpc/client_base.h
@@ -153,19 +153,19 @@ protected:
virtual auto request_to_grpc(const RQ * /*rq*/, gRQ * /*grq*/) -> int
{
return 0;
- };
+ }
virtual auto response_from_grpc(gRP * /*reply*/, RP * /*response*/) -> int
{
return 0;
- };
+ }
virtual auto check_parameter(const gRQ & /*grq*/) -> int
{
return 0;
- };
+ }
virtual auto grpc_call(ClientContext * /*context*/, const gRQ & /*req*/, gRP * /*reply*/) -> Status
{
return Status::OK;
- };
+ }
auto ReadTextFile(const char *file) -> std::string
{
--
2.25.1

View File

@ -1,39 +0,0 @@
From 86f34975a4e382a2967a27c589a72c857b0c1781 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Tue, 23 Feb 2021 09:05:45 +0800
Subject: [PATCH 38/53] restart policy: add support unless-stopped policy
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/modules/spec/verify.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c
index a3156579..cef95065 100644
--- a/src/daemon/modules/spec/verify.c
+++ b/src/daemon/modules/spec/verify.c
@@ -1864,6 +1864,11 @@ static inline bool is_restart_policy_always(const char *policy)
return strcmp(policy, "always") == 0;
}
+static inline bool is_restart_policy_unless_stopped(const char *policy)
+{
+ return strcmp(policy, "unless-stopped") == 0;
+}
+
static inline bool is_restart_policy_on_reboot(const char *policy)
{
return strcmp(policy, "on-reboot") == 0;
@@ -1881,7 +1886,8 @@ static inline bool is_restart_policy_on_failure(const char *policy)
static int verify_restart_policy_name(const host_config_restart_policy *rp, const host_config *hostconfig)
{
- if (is_restart_policy_always(rp->name) || is_restart_policy_no(rp->name) || is_restart_policy_on_reboot(rp->name)) {
+ if (is_restart_policy_always(rp->name) || is_restart_policy_no(rp->name) || is_restart_policy_on_reboot(rp->name) ||
+ is_restart_policy_unless_stopped(rp->name)) {
if (rp->maximum_retry_count != 0) {
ERROR("Maximum retry count cannot be used with restart policy '%s'", rp->name);
isulad_set_error_message("Maximum retry count cannot be used with restart policy '%s'", rp->name);
--
2.25.1

View File

@ -1,79 +0,0 @@
From 6d2ce70731b36c8e2942571dca71149c26474d25 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Tue, 23 Feb 2021 09:13:28 +0800
Subject: [PATCH 39/53] CI: add testcase for unless-stopped restart policy
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
.../container_cases/restartpolicy.sh | 48 +++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/CI/test_cases/container_cases/restartpolicy.sh b/CI/test_cases/container_cases/restartpolicy.sh
index be0140e7..bb7ada39 100755
--- a/CI/test_cases/container_cases/restartpolicy.sh
+++ b/CI/test_cases/container_cases/restartpolicy.sh
@@ -41,6 +41,52 @@ function do_test_on_failure()
fn_check_eq "$?" "0" "rm failed"
}
+function do_test_unless_stopped()
+{
+ containername=test_rp_unless_stopped
+ isula run --name $containername -td --restart unless-stopped busybox /bin/sh -c "exit 2"
+ fn_check_eq "$?" "0" "run failed"
+
+ sleep 8
+ count=`isula inspect --format='{{json .RestartCount}}' $containername`
+ if [[ $count == "0" ]];then
+ echo "expect not 0 but get $count"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ isula stop $containername
+ testcontainer $containername exited
+
+ isula rm $containername
+ fn_check_eq "$?" "0" "rm failed"
+}
+
+function do_test_unless_stopped_kill()
+{
+ containername=test_rp_unless_stopped
+ isula run --name $containername -td --restart unless-stopped busybox /bin/sh
+ fn_check_eq "$?" "0" "run failed"
+
+ cpid=`isula inspect -f '{{json .State.Pid}}' $containername`
+ kill -9 $cpid
+ sleep 8
+ testcontainer $containername running
+
+ isula stop $containername
+ fn_check_eq "$?" "0" "stop failed"
+ testcontainer $containername exited
+
+ isula restart $containername
+ testcontainer $containername running
+
+ isula kill $containername
+ fn_check_eq "$?" "0" "stop failed"
+ testcontainer $containername exited
+
+ isula rm $containername
+ fn_check_eq "$?" "0" "rm failed"
+}
+
function do_test_always_cancel()
{
containername=test_rp_always_cancel
@@ -64,6 +110,8 @@ function do_test_t()
{
do_test_on_failure
do_test_always_cancel
+ do_test_unless_stopped
+ do_test_unless_stopped_kill
return $TC_RET_T
}
--
2.25.1

View File

@ -1,162 +0,0 @@
From 42a961197ce8d9c7e5bde3403b444d9e93c4c855 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Tue, 23 Feb 2021 09:43:05 +0800
Subject: [PATCH 40/53] bugfix for embedded image
1. do not create mtab when create container if it's embedded image
2. use mounts in config, they are embedded image's layers
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
.../modules/service/service_container.c | 13 +++--
src/daemon/modules/spec/specs_mount.c | 57 +++++++++++++++++++
.../image/oci/oci_config_merge/CMakeLists.txt | 1 +
test/specs/specs/CMakeLists.txt | 1 +
test/specs/specs_extend/CMakeLists.txt | 1 +
5 files changed, 68 insertions(+), 5 deletions(-)
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index 6551bfbf..e1d698cd 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -731,11 +731,14 @@ static int do_start_container(container_t *cont, const char *console_fifos[], bo
goto close_exit_fd;
}
- nret = create_mtab_link(oci_spec);
- if (nret != 0) {
- ERROR("Failed to create link /etc/mtab for target /proc/mounts");
- ret = -1;
- goto close_exit_fd;
+ // embedded conainter is readonly, create mtab link will fail
+ if (strcmp(IMAGE_TYPE_EMBEDDED, cont->common_config->image_type) != 0) {
+ nret = create_mtab_link(oci_spec);
+ if (nret != 0) {
+ ERROR("Failed to create link /etc/mtab for target /proc/mounts");
+ ret = -1;
+ goto close_exit_fd;
+ }
}
if (verify_mounts(cont)) {
diff --git a/src/daemon/modules/spec/specs_mount.c b/src/daemon/modules/spec/specs_mount.c
index 04ccd415..175a0fbe 100644
--- a/src/daemon/modules/spec/specs_mount.c
+++ b/src/daemon/modules/spec/specs_mount.c
@@ -2799,6 +2799,9 @@ static int calc_mounts_len(host_config *host_spec, container_config *container_s
if (container_spec->volumes != NULL && container_spec->volumes->len != 0) {
(*len) += container_spec->volumes->len;
}
+ if (container_spec->mounts != NULL && container_spec->mounts_len != 0) {
+ (*len) += container_spec->mounts_len;
+ }
return 0;
}
@@ -2809,6 +2812,54 @@ static void add_mount(defs_mount **merged_mounts, size_t *merged_mounts_len, def
*merged_mounts_len += 1;
}
+static int add_embedded_layers(container_config *container_spec, defs_mount **merged_mounts,
+ size_t *merged_mounts_len)
+{
+ int ret = 0;
+ size_t i = 0;
+ defs_mount *mnt = NULL;
+ defs_mount *conflict = NULL;
+ mount_spec *spec = NULL;
+ char *errmsg = NULL;
+
+ for (i = 0; container_spec->mounts != 0 && i < container_spec->mounts_len; i++) {
+ ret = util_parse_mount_spec(container_spec->mounts[i], &spec, &errmsg);
+ if (ret != 0) {
+ ERROR("parse mount spec failed: %s", errmsg);
+ ret = -1;
+ goto out;
+ }
+
+ mnt = parse_mount(spec);
+ if (mnt == NULL) {
+ ERROR("parse mount failed");
+ ret = -1;
+ goto out;
+ }
+
+ // do not use duplicate mount point
+ conflict = get_conflict_mount_point(merged_mounts, *merged_mounts_len, mnt);
+ if (conflict != NULL) {
+ ERROR("Duplicate mount point: %s", conflict->destination);
+ isulad_set_error_message("Duplicate mount point: %s", conflict->destination);
+ ret = -1;
+ goto out;
+ }
+
+ add_mount(merged_mounts, merged_mounts_len, mnt);
+ mnt = NULL;
+ free_mount_spec(spec);
+ spec = NULL;
+ }
+
+out:
+ free_defs_mount(mnt);
+ free_mount_spec(spec);
+ free(errmsg);
+
+ return ret;
+}
+
static int add_mounts(host_config *host_spec, defs_mount **merged_mounts, size_t *merged_mounts_len)
{
int ret = 0;
@@ -3086,6 +3137,12 @@ static int merge_all_fs_mounts(host_config *host_spec, container_config *contain
goto out;
}
+ // add embedded layers
+ ret = add_embedded_layers(container_spec, merged_mounts, &merged_mounts_len);
+ if (ret != 0) {
+ goto out;
+ }
+
// add --mounts
ret = add_mounts(host_spec, merged_mounts, &merged_mounts_len);
if (ret != 0) {
diff --git a/test/image/oci/oci_config_merge/CMakeLists.txt b/test/image/oci/oci_config_merge/CMakeLists.txt
index 48960ff7..36dc3ead 100644
--- a/test/image/oci/oci_config_merge/CMakeLists.txt
+++ b/test/image/oci/oci_config_merge/CMakeLists.txt
@@ -18,6 +18,7 @@ add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/util_atomic.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/sha256/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/path.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/utils_mount_spec.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/spec//specs_extend.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/err_msg.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/config/isulad_config.c
diff --git a/test/specs/specs/CMakeLists.txt b/test/specs/specs/CMakeLists.txt
index e0f2b5b0..e0031e08 100644
--- a/test/specs/specs/CMakeLists.txt
+++ b/test/specs/specs/CMakeLists.txt
@@ -12,6 +12,7 @@ add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_timestamp.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/util_atomic.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_mount_spec.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
diff --git a/test/specs/specs_extend/CMakeLists.txt b/test/specs/specs_extend/CMakeLists.txt
index 7d5c7dfb..45b21ecd 100644
--- a/test/specs/specs_extend/CMakeLists.txt
+++ b/test/specs/specs_extend/CMakeLists.txt
@@ -12,6 +12,7 @@ add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_timestamp.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/util_atomic.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_mount_spec.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
--
2.25.1

View File

@ -1,75 +0,0 @@
From f5cd35cbfb594aad4b4448dd6550eb2faf9368c9 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Tue, 23 Feb 2021 16:27:47 +0800
Subject: [PATCH 41/53] console: client ignore stdin close event
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/utils/console/console.c | 17 +++++++++++++----
src/utils/console/console.h | 1 +
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/utils/console/console.c b/src/utils/console/console.c
index 7fda519c..1aedd0c9 100644
--- a/src/utils/console/console.c
+++ b/src/utils/console/console.c
@@ -57,7 +57,11 @@ static int console_cb_tty_stdin_with_escape(int fd, uint32_t events, void *cbdat
r_ret = util_read_nointr(ts->stdin_reader, &c, 1);
if (r_ret <= 0) {
- ret = EPOLL_LOOP_HANDLE_CLOSE;
+ if (r_ret == 0 && ts->ignore_stdin_close) {
+ ret = EPOLL_LOOP_HANDLE_CONTINUE;
+ } else {
+ ret = EPOLL_LOOP_HANDLE_CLOSE;
+ }
goto out;
}
@@ -122,7 +126,11 @@ static int console_cb_stdio_copy(int fd, uint32_t events, void *cbdata, struct e
ret = EPOLL_LOOP_HANDLE_CONTINUE;
goto out;
} else {
- ret = EPOLL_LOOP_HANDLE_CLOSE;
+ if (r_ret == 0 && ts->ignore_stdin_close && fd == ts->stdin_reader) {
+ ret = EPOLL_LOOP_HANDLE_CONTINUE;
+ } else {
+ ret = EPOLL_LOOP_HANDLE_CLOSE;
+ }
goto out;
}
}
@@ -363,8 +371,8 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin
int tty_exit, bool tty)
{
int ret;
- struct epoll_descr descr;
- struct tty_state ts;
+ struct epoll_descr descr = { 0 };
+ struct tty_state ts = { 0 };
ret = epoll_loop_open(&descr);
if (ret) {
@@ -378,6 +386,7 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin
ts.stdin_reader = -1;
ts.stdout_reader = -1;
ts.stderr_reader = -1;
+ ts.ignore_stdin_close = true;
if (fifoinfd >= 0) {
ts.stdin_reader = stdinfd;
diff --git a/src/utils/console/console.h b/src/utils/console/console.h
index 406a2fe9..0dfe19d3 100644
--- a/src/utils/console/console.h
+++ b/src/utils/console/console.h
@@ -40,6 +40,7 @@ struct tty_state {
int tty_exit;
/* Flag to mark whether detected escape sequence. */
int saw_tty_exit;
+ bool ignore_stdin_close;
};
int console_fifo_name(const char *rundir, const char *subpath, const char *stdflag, char *fifo_name,
--
2.25.1

View File

@ -1,182 +0,0 @@
From d0533ced0b9c4b721d1f7560b503070f07944e45 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Wed, 24 Feb 2021 10:19:44 +0800
Subject: [PATCH 42/53] delete lxc from runc CI test
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../container_cases/bigdata_stream_runc.sh | 128 ++----------------
1 file changed, 12 insertions(+), 116 deletions(-)
diff --git a/CI/test_cases/container_cases/bigdata_stream_runc.sh b/CI/test_cases/container_cases/bigdata_stream_runc.sh
index f6c2ee94..1313774e 100755
--- a/CI/test_cases/container_cases/bigdata_stream_runc.sh
+++ b/CI/test_cases/container_cases/bigdata_stream_runc.sh
@@ -55,9 +55,9 @@ function record_origin_status()
origin_isulad_cpu_usage=$(ps -o %cpu -p $(cat /var/run/isulad.pid) | sed -n '2p')
msg_info "origin isulad cpu usage: $origin_isulad_cpu_usage"
- lxc_monitor_pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
- origin_lxc_monitor_cpu_usage=$(ps -o %cpu -p $lxc_monitor_pid | sed -n '2p')
- msg_info "origin lxc monitor cpu usage: $origin_lxc_monitor_cpu_usage"
+ isulad_shim_pid=$(ps aux | grep "isulad-shim" | grep $CID | awk '{print $2}')
+ origin_isulad_shim_cpu_usage=$(ps -o %cpu -p $isulad_shim_pid | sed -n '2p')
+ msg_info "origin isulad shim cpu usage: $origin_isulad_shim_cpu_usage"
rm -rf /iocopy_stream_data_*
}
@@ -80,22 +80,16 @@ function check_last_status()
ps -o %cpu -p $(cat /var/run/isulad.pid)
fi
- lxc_monintor_pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
- last_lxc_monitor_cpu_usage=$(ps -o %cpu -p $lxc_monintor_pid | sed -n '2p')
- allowable_lxc_monitor_cpu_usage=$(echo "$origin_lxc_monitor_cpu_usage*2" | bc)
- if [[ $(echo "$allowable_lxc_monitor_cpu_usage < 1.0" | bc) -eq 1 ]]; then
- allowable_lxc_monitor_cpu_usage=1.0
+ isulad_shim_pid=$(ps aux | grep "isulad-shim" | grep $CID | awk '{print $2}')
+ last_isulad_shim_cpu_usage=$(ps -o %cpu -p $isulad_shim_pid | sed -n '2p')
+ allowable_isulad_shim_cpu_usage=$(echo "$origin_isulad_shim_cpu_usage*2" | bc)
+ if [[ $(echo "$allowable_isulad_shim_cpu_usage < 1.0" | bc) -eq 1 ]]; then
+ allowable_isulad_shim_cpu_usage=1.0
fi
- msg_info "allowable lxc_monitor cpu usage: $allowable_lxc_monitor_cpu_usage"
- if [[ $(echo "$last_lxc_monitor_cpu_usage > $allowable_lxc_monitor_cpu_usage" | bc) -eq 1 ]]; then
+ msg_info "allowable isulad_shim cpu usage: $allowable_isulad_shim_cpu_usage"
+ if [[ $(echo "$last_isulad_shim_cpu_usage > $allowable_isulad_shim_cpu_usage" | bc) -eq 1 ]]; then
msg_err "${FUNCNAME[0]}:${LINENO} - Process exception: endless loop or residual thread" && ((ret++))
- ps -o %cpu -p $lxc_monintor_pid
- fi
-
- lxc_attach_process_number=$(ps aux | grep lxc-attach | grep $CID | wc -l)
- if [[ $lxc_attach_process_number -ne 0 ]]; then
- msg_err "${FUNCNAME[0]}:${LINENO} - lxc_attach process residual" && ((ret++))
- ps aux | grep lxc-attach | grep $CID
+ ps -o %cpu -p $isulad_shim_pid
fi
client_pid=$(pidof isula)
@@ -209,100 +203,6 @@ function test_stream_with_kill_client()
return ${ret}
}
-function test_stream_with_stop_attach()
-{
- local ret=0
- local test="test_stream_with_stop_attach => (${FUNCNAME[@]})"
- msg_info "${test} starting..."
-
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
- exec_pid=$!
- sleep 2
- pid=$(ps aux | grep lxc-attach | grep $CID |grep "cat test_500M" | awk '{print $2}')
- kill -19 $pid
- sleep 3
- kill -18 $pid
-
- wait $exec_pid
-
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
- [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
-
- check_last_status
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
-
- msg_info "${test} finished with return ${ret}..."
- return ${ret}
-}
-
-function test_stream_with_kill_attach()
-{
- local ret=0
- local test="test_stream_with_kill_client => (${FUNCNAME[@]})"
- msg_info "${test} starting..."
-
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
- sleep 3
- pid=$(ps aux | grep lxc-attach | grep $CID |grep "cat test_500M" | awk '{print $2}')
- kill -9 $pid
-
- check_last_status
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
-
- msg_info "${test} finished with return ${ret}..."
- return ${ret}
-}
-
-function test_stream_with_stop_lxc_monitor()
-{
- local ret=0
- local test="test_stream_with_stop_lxc_monitor => (${FUNCNAME[@]})"
- msg_info "${test} starting..."
-
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
- exec_pid=$!
- sleep 2
- pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
- kill -19 $pid
- sleep 3
- kill -18 $pid
-
- wait $exec_pid
-
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
- [[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
-
- check_last_status
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
-
- msg_info "${test} finished with return ${ret}..."
- return ${ret}
-}
-
-function test_stream_with_kill_lxc_monitor()
-{
- local ret=0
- local test="test_stream_with_kill_lxc_monitor => (${FUNCNAME[@]})"
- msg_info "${test} starting..."
-
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
- sleep 3
- pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
- kill -9 $pid
- sleep 3
-
- isula start $CID
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to start container: $CID" && ((ret++))
-
- check_last_status
- [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - abnormal status" && ((ret++))
-
- msg_info "${test} finished with return ${ret}..."
- return ${ret}
-}
-
function test_stream_with_stop_isulad()
{
local ret=0
@@ -375,7 +275,7 @@ function test_memory_leak_with_bigdata_stream()
start_isulad_with_valgrind
- CID=$(isula run -itd ${image} sh)
+ CID=$(isula run -itd --runtime runc ${image} sh)
isula exec -it $CID dd if=/dev/zero of=test_100M bs=1M count=100
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++))
@@ -407,10 +307,6 @@ test_cat_bigdata || ((ans++))
test_cat_bigdata_without_pty || ((ans++))
test_stream_with_stop_client || ((ans++))
test_stream_with_kill_client || ((ans++))
-test_stream_with_stop_attach || ((ans++))
-test_stream_with_kill_attach || ((ans++))
-test_stream_with_stop_lxc_monitor || ((ans++))
-test_stream_with_kill_lxc_monitor || ((ans++))
test_stream_with_stop_isulad || ((ans++))
test_stream_with_kill_isulad || ((ans++))
tear_down || ((ans++))
--
2.25.1

View File

@ -1,635 +0,0 @@
From f803b85eea63bbe2745678afcfcc57e5eed51c4b Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Mon, 22 Feb 2021 10:26:55 +0800
Subject: [PATCH 43/53] add embedded testcases
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/build.sh | 6 +-
CI/test_cases/image_cases/embedded.sh | 590 ++++++++++++++++++++++++++
2 files changed, 595 insertions(+), 1 deletion(-)
create mode 100755 CI/test_cases/image_cases/embedded.sh
diff --git a/CI/build.sh b/CI/build.sh
index d21419eb..2c535c70 100755
--- a/CI/build.sh
+++ b/CI/build.sh
@@ -37,6 +37,9 @@ BASE_IMAGE=""
devmapper_script="${TOPDIR}/CI/install_devmapper.sh"
disk=NULL
+modprobe squashfs
+losetup -D
+losetup -l
rm -rf ${TESTCASE_ASSIGN}_*
# #Run this file will generate default BASE_IMAGE and auto run isulad unit tests
@@ -370,7 +373,8 @@ if [[ "x$disk" != "xNULL" ]] && [[ "x${enable_gcov}" != "xON" ]] ; then
for index in $(seq 1 ${CONTAINER_INDEX})
do
suffix=$(ls ${CIDIR} | grep testcase_assign_ | grep -E "*[S|P]${index}$" | awk -F '_' '{print $NF}')
- cat ${CIDIR}/testcase_assign_${suffix} >> ${CIDIR}/testcase_assign_devmapper
+ # only one embedded.sh shell is allowed at the same time and embedded image will not use in devicemapper enviorment
+ cat ${CIDIR}/testcase_assign_${suffix} | grep -v embedded.sh >> ${CIDIR}/testcase_assign_devmapper
done
docker cp ${CIDIR}/testcase_assign_devmapper ${devmappercontainer}:/root
echo_success "Run container ${devmappercontainer} success"
diff --git a/CI/test_cases/image_cases/embedded.sh b/CI/test_cases/image_cases/embedded.sh
new file mode 100755
index 00000000..535077ce
--- /dev/null
+++ b/CI/test_cases/image_cases/embedded.sh
@@ -0,0 +1,590 @@
+#!/bin/bash
+#
+# attributes: isulad embedded image
+# concurrent: YES
+# spend time: 15
+
+#######################################################################
+##- @Copyright (C) Huawei Technologies., 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.
+##- @Description:CI
+##- @Author: wangfengtu
+##- @Create: 2021-02-20
+#######################################################################
+
+declare -r curr_path=$(dirname $(readlink -f "$0"))
+source ../helpers.sh
+test="embedded image test => test_embedded"
+
+free_loop=""
+embedded_basedir="$(pwd)/embedded/img"
+embedded_basedir2="$(pwd)/embedded/img2"
+embedded_basedir3="$(pwd)/embedded/img3"
+embedded_basedir4="$(pwd)/embedded/img4"
+embedded_basedir5="$(pwd)/embedded/img5"
+embedded_manifest="$embedded_basedir/test.manifest"
+embedded_manifest2="$embedded_basedir2/test.manifest"
+embedded_manifest3="$embedded_basedir3/manifest"
+embedded_manifest_template="$embedded_basedir/template.manifest"
+embedded_manifest_invalid="$embedded_basedir/invalid.manifest"
+embedded_manifest_invalid_sgn="$embedded_basedir/invalid.sgn"
+embedded_manifest_not_file="$embedded_basedir/notfile"
+embedded_manifest_not_exist="$embedded_basedir/notexist.manifest"
+embedded_manifest_sgn2="$embedded_basedir2/test.sgn"
+embedded_manifest_sgn5="$embedded_basedir5/sgn"
+embedded_app="$embedded_basedir/app.img"
+embedded_app2="$embedded_basedir2/app.img"
+embedded_platform="$embedded_basedir/platform.img"
+embedded_platform2="$embedded_basedir2/platform.img"
+embedded_rootfs0="/tmp/embedded_rootfs0"
+embedded_manifest_ori="$embedded_basedir/test.manifest.ori"
+embedded_manifest_template_ori="$embedded_basedir/template.manifest.ori"
+
+function test_load_image()
+{
+ local ret=0
+
+ isula load -i "$embedded_manifest" -t abc
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load invalid type failed" && ((ret++))
+
+ # load embedded image
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++))
+
+ # load embedded image again
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image again failed" && ((ret++))
+
+ # delete embedded image
+ isula rmi test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete embedded image failed" && ((ret++))
+
+ # load embedded image again
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image again failed" && ((ret++))
+
+ # delete embedded image
+ isula rmi test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete embedded image failed" && ((ret++))
+
+ return ${ret}
+}
+
+function test_run_image()
+{
+ local ret=0
+
+ isula run -t -n embedded_test1 nonexistentname1:v1 /bin/sh
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run nonexistent image should failed" && ((ret++))
+
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++))
+
+ # run container based on embedded image
+ isula run --name embedded_test1 test:v1 ls /home/home/home
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run embedded image failed" && ((ret++))
+
+ # delete container based on embedded image
+ isula rm embedded_test1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete container based on embedded image failed" && ((ret++))
+
+ # test image's env
+ isula run --name embedded_test1 test:v1 /bin/sh -c "echo \$c | grep \"d e\""
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's env failed" && ((ret++))
+
+ # delete container based on embedded image
+ isula rm embedded_test1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete container based on embedded image failed" && ((ret++))
+
+ # delete embedded image
+ isula rmi test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete embedded image failed" && ((ret++))
+
+ return ${ret}
+}
+
+function test_mount()
+{
+ local ret=0
+
+ # load embedded image
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded imagefailed" && ((ret++))
+
+ # run --mount
+ isula run --mount type=bind,src="$embedded_basedir",dst=/usr,ro=true,bind-propagation=rprivate --name embedded_test2 test:v1 true
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run --mount failed" && ((ret++))
+
+ testcontainer embedded_test2 exited
+
+ isula rm embedded_test2
+
+ # test invalid mode
+ isula run --mount type=bind,src="$embedded_basedir",dst=/usr,ro=invalid --name embedded_test2 test:v1 true
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid mode should failed" && ((ret++))
+
+ isula rm embedded_test2
+
+ # test invalid bind propagation mode
+ isula run --mount type=bind,src="$embedded_basedir",dst=/usr,bind-propagation=invalid --name embedded_test2 test:v1 true
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid bind propagation mode should failed" && ((ret++))
+
+ isula rm embedded_test2
+
+ # test source not exist
+ isula run --mount type=bind,src=abcdefg/notexist,dst=/usr --name embedded_test2 test:v1 true
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid source not exist should failed" && ((ret++))
+
+ isula rm embedded_test2
+
+ # test source not a regular file
+ isula run --mount type=squashfs,src=/tmp,dst=/usr --name embedded_test2 test:v1 true
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - source not a regular file should failed" && ((ret++))
+
+ isula rm embedded_test2
+
+ # test path //tmp/test
+ mkdir -p /tmp/test_mount
+ mkdir -p /tmp/test_mount1/test
+ isula run -v /tmp/test_mount:/tmp --mount type=bind,src=/tmp/test_mount1,dst=//tmp/test_mount1,ro=true,bind-propagation=rprivate --name embedded_test2 test:v1 ls /tmp/test_mount1/test
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test path //tmp/test failed" && ((ret++))
+
+ isula rm embedded_test2
+
+ # delete embedded image
+ isula rmi test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete embedded image failed" && ((ret++))
+
+ return ${ret}
+}
+
+function test_query_image()
+{
+ local ret=0
+
+ # load embedded image
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded imagefailed" && ((ret++))
+
+ # inspect embedded image
+ isula inspect test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - inspect embedded image failed" && ((ret++))
+
+ # test list embedded image
+ isula images | grep test | grep v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - list embedded image failed" && ((ret++))
+
+ # inspect nonexist item
+ isula inspect -f '{{json .abc}}' test:v1
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - inspect nonexist item should failed" && ((ret++))
+
+ # test inspect container, it should conatainer image info
+ isula run --name embedded_inspect test:v1 ls /home/home/home
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container for inspect failed" && ((ret++))
+
+ isula inspect -f '{{json .Image}}' embedded_inspect
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - image does not contain image info failed" && ((ret++))
+
+ # test list container based on embedded image
+ isula ps -a | grep embedded_inspect
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - ps does not contain embedded container failed" && ((ret++))
+
+ # delete container
+ isula rm embedded_inspect
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete container for inspect failed" && ((ret++))
+
+ # delete embedded image
+ isula rmi test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - delete embedded image failed" && ((ret++))
+
+ # test inspect nonexist image
+ isula inspect test:v1
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - inspect nonexist image should failed" && ((ret++))
+
+ # test list nonexist image
+ isula images | grep test | grep v1
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - list nonexist image should failed" && ((ret++))
+
+ # test list nonexist container
+ isula ps -a | grep embedded_inspect
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - ps should not contain embedded container failed" && ((ret++))
+
+ return ${ret}
+}
+
+function test_invalid_manifest_part1()
+{
+ local ret=0
+
+ # test 'none' image name
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/test:v1/none/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test 'none' image name failed" && ((ret++))
+
+ # test 'none:latest' image name
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/test:v1/none:latest/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test 'none:latest' image name failed" && ((ret++))
+
+ # test invalid image name k~k
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/test:v1/k~k/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid image name k~k failed" && ((ret++))
+
+ # test invalid image name test
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/test:v1/test/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid image name test failed" && ((ret++))
+
+ # test invalid time
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/Z/Zabc#$@/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid image time failed" && ((ret++))
+
+ # test invalid layer number
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "16,36d" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid layer number failed" && ((ret++))
+
+ # test layer 0 not a device
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s#$free_loop#/home#g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test layer 0 not a device failed" && ((ret++))
+
+ # test layer(not the first layer) not a regular file
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ mkdir -p "$embedded_manifest_not_file"
+ sed -i "s#platform.img#notfile#g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test layer(not the first layer) not a regular file failed" && ((ret++))
+ rm -rf "$embedded_manifest_not_file"
+
+ # test invalid layer digest
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/4613a9d1e9016293f53833b0ac61ea072882d468fe2fce7701ecea6f201eebbe/7a7eb18fd0a7b9ac0cdae8c9754ff846d65a4831b9ad8786d943618b497bd886/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid layer digest failed" && ((ret++))
+
+ # test invalid layer not exist
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/app.img/kkk/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid layer not exist failed" && ((ret++))
+
+ # test invalid host path(not relative path)
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s#platform.img#/platform.img#g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid host path(not relative path) failed" && ((ret++))
+
+ # test invalid container path(not absolute path)
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s#/home/home#home/home#g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid container path(not absolute path) failed" && ((ret++))
+
+ # test invalid first layer(not absolute path)
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s#$free_loop#${free_loop:1}#g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid first layer(not absolute path) failed" && ((ret++))
+
+ # test invalid manifest digest
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ echo -n "sha256:36c7c17757c24fa1e86018c8009f3b98690709236f05910937d59e401d87d6c5" > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest digest failed" && ((ret++))
+
+ # test invalid manifest not exist
+ isula load -i "$embedded_manifest_not_exist" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest not exist failed" && ((ret++))
+
+ # test invalid manifest not a regular file
+ isula load -i /dev/zero -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest not a regular file failed" && ((ret++))
+
+ # test invalid manifest empty file
+ rm -f "$embedded_manifest_invalid"
+ touch "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest empty file failed" && ((ret++))
+
+ # test invalid manifest not a json file
+ rm -f "$embedded_manifest_invalid"
+ echo hello > "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest not a json file failed" && ((ret++))
+
+ # test image conflict when in different path
+ rm -rf "$embedded_basedir2"
+ cp -rf "$embedded_basedir" "$embedded_basedir2"
+ isula load -i "$embedded_manifest" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image conflict when in different path failed" && ((ret++))
+
+ echo -n sha256:$(sha256sum "$embedded_manifest2" | awk '{print $1}') > "$embedded_manifest_sgn2"
+ isula load -i "$embedded_manifest2" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load manifest in different path should failed" && ((ret++))
+
+ rm -rf "$embedded_basedir2"
+ isula rmi test:v1
+
+ return ${ret}
+}
+
+function test_invalid_manifest_part2()
+{
+ local ret=0
+
+ # test manifest's sgn file not exist
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ rm -f "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test manifest's sgn file not exist failed" && ((ret++))
+
+ # test content of manifest's sgn file not right
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ # note: add '\n' at the end of the sgn file
+ echo sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test content of manifest's sgn file not right failed" && ((ret++))
+
+ # test invalid schema version
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "2d" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid schema version failed" && ((ret++))
+
+ # test invalid manifest's media type
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/embedded/invalid/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest's media type failed" && ((ret++))
+
+ # test invalid manifest's layer type
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/squashfs/invalid/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test invalid manifest's layer type failed" && ((ret++))
+
+ # test size negative number
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "s/823/-823/g" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test size negative number failed" && ((ret++))
+
+ # test first layer digest not empty
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "19d" "$embedded_manifest_invalid"
+ sed -i "19i\"digest\": \"a\"," "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test size negative number failed" && ((ret++))
+
+ # test first layer path in container not empty
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "21d" "$embedded_manifest_invalid"
+ sed -i "21i\"pathInContainer\": \"a\"" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 1 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test first layer path in container not empty failed" && ((ret++))
+
+ return ${ret}
+}
+
+function test_entrypoint()
+{
+ local ret=0
+
+ # load embedded image
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "12i\"/bin/ls\"," "$embedded_manifest_invalid"
+ sed -i "13i\"/home\"" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++))
+
+ # test image's entrypoint
+ isula run --name embedded_entrypoint1 test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's entrypoint failed" && ((ret++))
+
+ isula rm embedded_entrypoint1
+
+ # test image's entrypoint with cmds
+ isula run --name embedded_entrypoint1 test:v1 /bin
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's entrypoint with cmds failed" && ((ret++))
+
+ isula rm embedded_entrypoint1
+
+ # test image's entrypoint override image's entrypoint
+ isula run --entrypoint=/bin/ls --name embedded_entrypoint1 test:v1 /bin
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test image's entrypoint override image's entrypoint failed" && ((ret++))
+
+ isula rm embedded_entrypoint1
+ isula rmi test:v1
+
+ # test entrypoint with variable
+ cp -f "$embedded_manifest_template" "$embedded_manifest_invalid"
+ sed -i "12i\"/bin/sh\"," "$embedded_manifest_invalid"
+ sed -i "13i\"-c\"," "$embedded_manifest_invalid"
+ sed -i "14i\"ls /ho\${env_id}\"" "$embedded_manifest_invalid"
+ echo -n sha256:$(sha256sum "$embedded_manifest_invalid" | awk '{print $1}') > "$embedded_manifest_invalid_sgn"
+ isula load -i "$embedded_manifest_invalid" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test entrypoint with variable failed" && ((ret++))
+
+ isula run -e env_id=me --name embedded_entrypoint1 test:v1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - test run embedded image with env failed" && ((ret++))
+
+ isula rm embedded_entrypoint1
+ isula rmi test:v1
+
+ return ${ret}
+}
+
+function test_symbolic()
+{
+ local ret=0
+
+ # test symbolic
+ # image layout
+ # .
+ # |__ img
+ # | |__ app.img
+ # | |__ platform.img
+ # |
+ # |__ img2
+ # | |__ app.img -> ../img/app.img
+ # | |__ platform.img -> ../img/platform.img
+ # | |__ test.manifest
+ # | |__ test.sgn -> ../img5/sgn
+ # |
+ # |__ img3
+ # | |__ manifest -> ../img2/test.manifest
+ # |
+ # |__ img4 -> img3
+ # |
+ # |__ img5
+ # |__ sgn
+ #
+ # /tmp/embedded_rootfs0 -> /dev/loopx
+
+ rm -rf "$embedded_basedir2"
+ mkdir -p "$embedded_basedir2"
+ ln -sf "$embedded_app" "$embedded_app2"
+ ln -sf "$embedded_platform" "$embedded_platform2"
+ cp -f "$embedded_manifest_template" "$embedded_manifest2"
+ sed -i "s#$free_loop#$embedded_rootfs0#g" "$embedded_manifest2"
+ ln -sf $free_loop $embedded_rootfs0
+ mkdir -p "$embedded_basedir5"
+ echo -n sha256:$(sha256sum "$embedded_manifest2" | awk '{print $1}') > "$embedded_manifest_sgn5"
+ ln -sf "$embedded_manifest_sgn5" "$embedded_manifest_sgn2"
+ mkdir -p "$embedded_basedir3"
+ ln -sf "$embedded_manifest2" "$embedded_manifest3"
+ ln -sf "$embedded_basedir3" "$embedded_basedir4"
+
+ # load embedded image
+ isula load -i "$embedded_manifest2" -t embedded
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - load embedded image failed" && ((ret++))
+
+ # run container based on embedded image
+ isula run --name embedded_test_symbolic test:v1 ls /home/home/home
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container based on embedded image failed" && ((ret++))
+
+ isula rm embedded_test_symbolic
+ isula rmi test:v1
+
+ return ${ret}
+}
+
+function prepare_test_embedded()
+{
+ local ret=0
+
+ isula rm -f `isula ps -a -q`
+ isula rmi test:v1
+
+ free_loop=$(losetup -f)
+ losetup $free_loop $embedded_basedir/busybox.img
+
+ cp -f $embedded_manifest_ori $embedded_manifest
+ cp -f $embedded_manifest_template_ori $embedded_manifest_template
+ sed -i "s#/dev/ram0#$free_loop#g" "$embedded_manifest"
+ sed -i "s#/dev/ram0#$free_loop#g" "$embedded_manifest_template"
+ checksum=$(sha256sum $embedded_basedir/test.manifest | awk '{print $1}')
+ echo -n "sha256:$checksum" > $embedded_basedir/test.sgn
+
+ return ${ret}
+}
+
+function post_test_embedded()
+{
+ local ret=0
+
+ rm -rf "$embedded_manifest_not_file"
+ rm -rf "$embedded_basedir2"
+ rm -rf "$embedded_basedir3"
+ rm -rf "$embedded_basedir4"
+ rm -rf "$embedded_basedir5"
+
+ isula rm -f `isula ps -a -q`
+ isula rmi test:v1
+
+ umount $(mount | grep busybox.img | awk '{print $3}')
+ losetup -d $free_loop
+
+ return ${ret}
+}
+
+declare -i ans=0
+
+msg_info "${test} starting..."
+[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++))
+
+prepare_test_embedded || ((ans++))
+
+test_load_image || ((ans++))
+test_run_image || ((ans++))
+test_mount || ((ans++))
+test_query_image || ((ans++))
+test_invalid_manifest_part1 || ((ans++))
+test_invalid_manifest_part2 || ((ans++))
+test_entrypoint || ((ans++))
+test_symbolic || ((ans++))
+
+post_test_embedded
+
+msg_info "${test} finished with return ${ans}..."
+
+show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,100 +0,0 @@
From f5ebba3e76bdc39fc62b25202c9794ca2e773106 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Wed, 24 Feb 2021 17:41:56 +0800
Subject: [PATCH 44/53] fix the error of ContainerStats interface field value
Signed-off-by: wujing <wujing50@huawei.com>
---
.../cri/cri_container_manager_service_impl.cc | 22 ++++++++++++++-----
.../cri/cri_container_manager_service_impl.h | 5 +++--
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/daemon/entry/cri/cri_container_manager_service_impl.cc b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
index 6c6569a6..af21e78a 100644
--- a/src/daemon/entry/cri/cri_container_manager_service_impl.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
@@ -711,7 +711,7 @@ void ContainerManagerServiceImpl::PackContainerStatsAttributes(
}
}
-void ContainerManagerServiceImpl::SetFsUsage(const imagetool_fs_info *fs_usage,
+void ContainerManagerServiceImpl::SetFsUsage(const imagetool_fs_info *fs_usage, int64_t timestamp,
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container)
{
if (fs_usage == nullptr || fs_usage->image_filesystems_len == 0 || fs_usage->image_filesystems[0] == nullptr) {
@@ -733,10 +733,18 @@ void ContainerManagerServiceImpl::SetFsUsage(const imagetool_fs_info *fs_usage,
container->mutable_writable_layer()->mutable_inodes_used()->set_value(
fs_usage->image_filesystems[0]->inodes_used->value);
}
+ container->mutable_writable_layer()->set_timestamp(timestamp);
+
+ if (fs_usage->image_filesystems[0]->fs_id != nullptr &&
+ fs_usage->image_filesystems[0]->fs_id->mountpoint != nullptr) {
+ container->mutable_writable_layer()->mutable_fs_id()->set_mountpoint(
+ fs_usage->image_filesystems[0]->fs_id->mountpoint);
+ }
}
void ContainerManagerServiceImpl::PackContainerStatsFilesystemUsage(
- const char *id, const char *image_type, std::unique_ptr<runtime::v1alpha2::ContainerStats> &container)
+ const char *id, const char *image_type, int64_t timestamp,
+ std::unique_ptr<runtime::v1alpha2::ContainerStats> &container)
{
if (id == nullptr || image_type == nullptr) {
return;
@@ -747,7 +755,7 @@ void ContainerManagerServiceImpl::PackContainerStatsFilesystemUsage(
ERROR("Failed to get container filesystem usage");
}
- SetFsUsage(fs_usage, container);
+ SetFsUsage(fs_usage, timestamp, container);
free_imagetool_fs_info(fs_usage);
}
@@ -771,21 +779,23 @@ void ContainerManagerServiceImpl::ContainerStatsToGRPC(
if (error.NotEmpty()) {
return;
}
- PackContainerStatsFilesystemUsage(response->container_stats[i]->id, response->container_stats[i]->image_type,
- container);
+ int64_t timestamp = util_get_now_time_nanos();
+ PackContainerStatsFilesystemUsage(response->container_stats[i]->id, response->container_stats[i]->image_type,
+ timestamp, container);
if (response->container_stats[i]->mem_used != 0u) {
uint64_t workingset = response->container_stats[i]->mem_used;
if (response->container_stats[i]->inactive_file_total < response->container_stats[i]->mem_used) {
workingset = response->container_stats[i]->mem_used - response->container_stats[i]->inactive_file_total;
}
container->mutable_memory()->mutable_working_set_bytes()->set_value(workingset);
+ container->mutable_memory()->set_timestamp(timestamp);
}
if (response->container_stats[i]->cpu_use_nanos != 0u) {
container->mutable_cpu()->mutable_usage_core_nano_seconds()->set_value(
response->container_stats[i]->cpu_use_nanos);
- container->mutable_cpu()->set_timestamp((int64_t)(response->container_stats[i]->cpu_system_use));
+ container->mutable_cpu()->set_timestamp(timestamp);
}
containerstats->push_back(move(container));
diff --git a/src/daemon/entry/cri/cri_container_manager_service_impl.h b/src/daemon/entry/cri/cri_container_manager_service_impl.h
index 49551469..d08d9124 100644
--- a/src/daemon/entry/cri/cri_container_manager_service_impl.h
+++ b/src/daemon/entry/cri/cri_container_manager_service_impl.h
@@ -103,9 +103,10 @@ private:
Errors &error);
void PackContainerStatsAttributes(const char *id, std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
Errors &error);
- void PackContainerStatsFilesystemUsage(const char *id, const char *image_type,
+ void PackContainerStatsFilesystemUsage(const char *id, const char *image_type, int64_t timestamp,
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container);
- void SetFsUsage(const imagetool_fs_info *fs_usage, std::unique_ptr<runtime::v1alpha2::ContainerStats> &container);
+ void SetFsUsage(const imagetool_fs_info *fs_usage, int64_t timestamp,
+ std::unique_ptr<runtime::v1alpha2::ContainerStats> &container);
void ContainerStatusToGRPC(container_inspect *inspect,
std::unique_ptr<runtime::v1alpha2::ContainerStatus> &contStatus, Errors &error);
void PackContainerImageToStatus(container_inspect *inspect,
--
2.25.1

View File

@ -1,275 +0,0 @@
From e5304673ad2069b98256a942d13f959856578383 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 23 Feb 2021 19:42:43 +0800
Subject: [PATCH 45/53] rollback setuped network if mult-network failed
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/daemon/entry/cri/cni_network_plugin.cc | 121 ++++++++++-----------
src/daemon/entry/cri/cni_network_plugin.h | 2 +-
2 files changed, 56 insertions(+), 67 deletions(-)
diff --git a/src/daemon/entry/cri/cni_network_plugin.cc b/src/daemon/entry/cri/cni_network_plugin.cc
index b764b2a4..de599361 100644
--- a/src/daemon/entry/cri/cni_network_plugin.cc
+++ b/src/daemon/entry/cri/cni_network_plugin.cc
@@ -382,32 +382,33 @@ void CniNetworkPlugin::Status(Errors &err)
CheckInitialized(err);
}
-
+// return: represent need rollback
bool CniNetworkPlugin::SetupMultNetworks(const std::string &ns, const std::string &defaultInterface,
const std::string &name,
const std::string &netnsPath, const std::string &podSandboxID,
const std::map<std::string, std::string> &annotations,
const std::map<std::string, std::string> &options, Errors &err)
{
- bool ret = false;
int defaultIdx = -1;
size_t len = 0;
+ struct result *preResult = nullptr;
+ CNINetwork *useDefaultNet = nullptr;
+ bool ret = true;
cri_pod_network_element **networks = CRIHelpers::GetNetworkPlaneFromPodAnno(annotations, &len, err);
if (err.NotEmpty()) {
ERROR("Couldn't get network plane from pod annotations: %s", err.GetCMessage());
err.Errorf("Couldn't get network plane from pod annotations: %s", err.GetCMessage());
- goto cleanup;
+ return false;
}
for (size_t i = 0; i < len; i++) {
if (networks[i] == nullptr || networks[i]->name == nullptr || networks[i]->interface == nullptr) {
continue;
}
- struct result *preResult = nullptr;
auto netIter = m_mutlNetworks.find(networks[i]->name);
if (netIter == m_mutlNetworks.end()) {
err.Errorf("Cannot found user defined net: %s", networks[i]->name);
- break;
+ goto cleanup;
}
if (defaultInterface == networks[i]->interface) {
defaultIdx = i;
@@ -416,32 +417,32 @@ bool CniNetworkPlugin::SetupMultNetworks(const std::string &ns, const std::strin
AddToNetwork((netIter->second).get(), name, ns, networks[i]->interface, podSandboxID, netnsPath, annotations, options,
&preResult, err);
free_result(preResult);
+ preResult = nullptr;
if (err.NotEmpty()) {
ERROR("Do setup user defined net: %s, failed: %s", networks[i]->name, err.GetCMessage());
- break;
+ goto cleanup;
}
- INFO("Setup user defained net: %s success", networks[i]->name);
+ INFO("Setup user defined net: %s success", networks[i]->name);
}
+ useDefaultNet = m_defaultNetwork.get();
// mask default network pod, if user defined net use same interface
if (defaultIdx >= 0) {
auto netIter = m_mutlNetworks.find(networks[defaultIdx]->name);
if (netIter == m_mutlNetworks.end()) {
- err.Errorf("Cannot found user defined net: %s", networks[defaultIdx]->name);
+ err.Errorf("Cannot default net: %s", networks[defaultIdx]->name);
goto cleanup;
}
-
- struct result *preResult = nullptr;
- AddToNetwork((netIter->second).get(), name, ns, networks[defaultIdx]->interface, podSandboxID, netnsPath, annotations,
- options, &preResult, err);
- free_result(preResult);
- if (err.NotEmpty()) {
- ERROR("Do setup user defined net: %s, failed: %s", networks[defaultIdx]->name, err.GetCMessage());
- goto cleanup;
- }
- INFO("Setup default net: %s success", networks[defaultIdx]->name);
- ret = true;
+ useDefaultNet = (netIter->second).get();
+ }
+ AddToNetwork(useDefaultNet, name, ns, defaultInterface, podSandboxID, netnsPath, annotations, options, &preResult, err);
+ free_result(preResult);
+ if (err.NotEmpty()) {
+ ERROR("Setup default net failed: %s", err.GetCMessage());
+ goto cleanup;
}
+ INFO("Setup default net: %s success", useDefaultNet->GetName().c_str());
+ ret = false;
cleanup:
free_cri_pod_network(networks, len);
return ret;
@@ -489,8 +490,8 @@ void CniNetworkPlugin::SetUpPod(const std::string &ns, const std::string &name,
return;
}
- struct result *preResult = nullptr;
if (m_loNetwork != nullptr) {
+ struct result *preResult = nullptr;
AddToNetwork(m_loNetwork.get(), name, ns, interfaceName, id, netnsPath, annotations, options, &preResult, err);
free_result(preResult);
preResult = nullptr;
@@ -506,38 +507,32 @@ void CniNetworkPlugin::SetUpPod(const std::string &ns, const std::string &name,
return;
}
- bool setedDefaultNet = SetupMultNetworks(ns, interfaceName, name, netnsPath, id, annotations, options, err);
- if (err.NotEmpty()) {
- goto unlock;
- }
-
- if (setedDefaultNet) {
- goto unlock;
- }
-
- AddToNetwork(m_defaultNetwork.get(), name, ns, interfaceName, id, netnsPath, annotations, options, &preResult, err);
- free_result(preResult);
- if (err.NotEmpty()) {
- ERROR("Error while adding to cni network: %s", err.GetCMessage());
+ bool needRollback = SetupMultNetworks(ns, interfaceName, name, netnsPath, id, annotations, options, err);
+ if (needRollback && err.NotEmpty()) {
+ Errors tmpErr;
+ TearDownMultNetworks(ns, interfaceName, name, netnsPath, id, annotations, tmpErr);
+ if (tmpErr.NotEmpty()) {
+ err.AppendError(tmpErr.GetMessage());
+ }
}
-unlock:
UnlockNetworkMap(err);
}
-bool CniNetworkPlugin::TearDownMultNetworks(const std::string &ns, const std::string &defaultInterface,
+void CniNetworkPlugin::TearDownMultNetworks(const std::string &ns, const std::string &defaultInterface,
const std::string &name,
const std::string &netnsPath, const std::string &podSandboxID, const std::map<std::string, std::string> &annotations,
Errors &err)
{
- bool ret = false;
int defaultIdx = -1;
size_t len = 0;
+ CNINetwork *useDefaultNet = nullptr;
+ Errors tmpErr;
cri_pod_network_element **networks = CRIHelpers::GetNetworkPlaneFromPodAnno(annotations, &len, err);
if (err.NotEmpty()) {
ERROR("Couldn't get network plane from pod annotations: %s", err.GetCMessage());
err.Errorf("Couldn't get network plane from pod annotations: %s", err.GetCMessage());
- goto cleanup;
+ return;
}
for (size_t i = 0; i < len; i++) {
@@ -553,14 +548,18 @@ bool CniNetworkPlugin::TearDownMultNetworks(const std::string &ns, const std::st
defaultIdx = i;
continue;
}
- DeleteFromNetwork((netIter->second).get(), name, ns, networks[i]->interface, podSandboxID, netnsPath, annotations, err);
- if (err.NotEmpty()) {
- ERROR("Do teardown user defined net: %s, failed: %s", networks[i]->name, err.GetCMessage());
- break;
+ DeleteFromNetwork((netIter->second).get(), name, ns, networks[i]->interface, podSandboxID, netnsPath, annotations,
+ tmpErr);
+ if (tmpErr.NotEmpty()) {
+ ERROR("Do teardown user defined net: %s, failed: %s", networks[i]->name, tmpErr.GetCMessage());
+ err.AppendError(tmpErr.GetMessage());
+ tmpErr.Clear();
+ continue;
}
INFO("Teardown user defained net: %s success", networks[i]->name);
}
+ useDefaultNet = m_defaultNetwork.get();
// mask default network pod, if user defined net use same interface
if (defaultIdx >= 0) {
auto netIter = m_mutlNetworks.find(networks[defaultIdx]->name);
@@ -568,19 +567,18 @@ bool CniNetworkPlugin::TearDownMultNetworks(const std::string &ns, const std::st
err.Errorf("Cannot found user defined net: %s", networks[defaultIdx]->name);
goto cleanup;
}
-
- DeleteFromNetwork((netIter->second).get(), name, ns, networks[defaultIdx]->interface, podSandboxID, netnsPath,
- annotations, err);
- if (err.NotEmpty()) {
- ERROR("Do teardown user defined net: %s, failed: %s", networks[defaultIdx]->name, err.GetCMessage());
- goto cleanup;
- }
- INFO("Teardown default net: %s success", networks[defaultIdx]->name);
- ret = true;
+ useDefaultNet = (netIter->second).get();
+ }
+ DeleteFromNetwork(useDefaultNet, name, ns, defaultInterface, podSandboxID, netnsPath, annotations, tmpErr);
+ if (tmpErr.NotEmpty()) {
+ ERROR("Teardown default net: %s, failed: %s", useDefaultNet->GetName().c_str(), tmpErr.GetCMessage());
+ err.AppendError(tmpErr.GetMessage());
+ goto cleanup;
}
+ INFO("Teardown default net: %s success", useDefaultNet->GetName().c_str());
+
cleanup:
free_cri_pod_network(networks, len);
- return ret;
}
void CniNetworkPlugin::TearDownPod(const std::string &ns, const std::string &name, const std::string &interfaceName,
@@ -605,21 +603,11 @@ void CniNetworkPlugin::TearDownPod(const std::string &ns, const std::string &nam
return;
}
- bool defaultNetDone = TearDownMultNetworks(ns, interfaceName, name, netnsPath, id, annotations, err);
- if (defaultNetDone) {
- goto unlock;
- }
+ TearDownMultNetworks(ns, interfaceName, name, netnsPath, id, annotations, err);
if (err.NotEmpty()) {
WARN("Teardown user defined networks failed: %s", err.GetCMessage());
}
- DeleteFromNetwork(m_defaultNetwork.get(), name, ns, interfaceName, id, netnsPath, annotations, tmpErr);
- if (tmpErr.NotEmpty()) {
- WARN("Teardown default network failed: %s", tmpErr.GetCMessage());
- err.AppendError(tmpErr.GetMessage());
- }
-
-unlock:
UnlockNetworkMap(err);
}
@@ -801,7 +789,8 @@ static void GetExtensionCNIArgs(const std::map<std::string, std::string> &annota
// get cni multinetwork extension
auto iter = annotations.find(CRIHelpers::Constants::CNI_MUTL_NET_EXTENSION_KEY);
if (iter != annotations.end()) {
- if (!CheckCNIArgValue(iter->second)) {
+ // args value must do not have ';'
+ if (iter->second.find(';') != std::string::npos) {
WARN("Ignore: invalid multinetwork cni args: %s", iter->second.c_str());
} else {
args[CRIHelpers::Constants::CNI_MUTL_NET_EXTENSION_ARGS_KEY] = iter->second;
@@ -817,9 +806,9 @@ static void GetExtensionCNIArgs(const std::map<std::string, std::string> &annota
continue;
}
auto strs = CXXUtils::Split(work.second, '=');
- iter = annotations.find(work.first);
- if (iter != annotations.end()) {
- WARN("Ignore: Same key cni args: %s", work.first.c_str());
+ iter = args.find(strs[0]);
+ if (iter != args.end()) {
+ WARN("Ignore: Same key cni args: %s", work.second.c_str());
continue;
}
args[strs[0]] = strs[1];
diff --git a/src/daemon/entry/cri/cni_network_plugin.h b/src/daemon/entry/cri/cni_network_plugin.h
index f545930f..8d51a94d 100644
--- a/src/daemon/entry/cri/cni_network_plugin.h
+++ b/src/daemon/entry/cri/cni_network_plugin.h
@@ -167,7 +167,7 @@ private:
const std::string &netnsPath, const std::string &podSandboxID, const std::map<std::string, std::string> &annotations,
const std::map<std::string, std::string> &options, Errors &err);
- bool TearDownMultNetworks(const std::string &ns, const std::string &defaultInterface, const std::string &name,
+ void TearDownMultNetworks(const std::string &ns, const std::string &defaultInterface, const std::string &name,
const std::string &netnsPath, const std::string &podSandboxID, const std::map<std::string, std::string> &annotations,
Errors &err);
--
2.25.1

View File

@ -1,242 +0,0 @@
From 389be7c170c28b24bfe762027e235f6fa986ac07 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 24 Feb 2021 17:11:28 +0800
Subject: [PATCH 46/53] add testcase for rollback mutlnetworks
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
CI/test_cases/container_cases/cni_test.sh | 85 ++++++++++++++++++-
.../criconfigs/bins/isulad-cni | 4 +-
.../container_cases/criconfigs/bins/wrong-cni | 25 ++++++
.../criconfigs/mock_wrong.json | 9 ++
.../criconfigs/mutl_wrong_net_pod.json | 14 +++
CI/test_cases/helpers.sh | 2 +-
6 files changed, 132 insertions(+), 7 deletions(-)
create mode 100755 CI/test_cases/container_cases/criconfigs/bins/wrong-cni
create mode 100644 CI/test_cases/container_cases/criconfigs/mock_wrong.json
create mode 100644 CI/test_cases/container_cases/criconfigs/mutl_wrong_net_pod.json
diff --git a/CI/test_cases/container_cases/cni_test.sh b/CI/test_cases/container_cases/cni_test.sh
index c9e1e1ac..093178d6 100644
--- a/CI/test_cases/container_cases/cni_test.sh
+++ b/CI/test_cases/container_cases/cni_test.sh
@@ -177,6 +177,7 @@ function new_cni_config()
function check_annotation()
{
+ rm -f /etc/cni/net.d/*
cp ${data_path}/mock.json /etc/cni/net.d/bridge.json
sync;sync;
tail $ISUALD_LOG
@@ -199,19 +200,82 @@ function check_annotation()
fi
basepath=/tmp/cnilogs/
- cat ${basepath}/${sid}.env | grep CNI_MUTLINET_EXTENSION
+ cat ${basepath}/${sid}_eth0.env | grep CNI_MUTLINET_EXTENSION
if [ $? -ne 0 ];then
msg_err "lost extension for mutl network args"
TC_RET_T=$(($TC_RET_T+1))
fi
- cat ${basepath}/${sid}.env | grep "extension=first"
+ cat ${basepath}/${sid}_eth0.env | grep "extension=first"
if [ $? -ne 0 ];then
msg_err "lost extension for first cni args"
TC_RET_T=$(($TC_RET_T+1))
fi
- cat ${basepath}/${sid}.env | grep "extension=second"
+ cat ${basepath}/${sid}_eth0.env | grep "extension=second"
+ if [ $? -eq 0 ];then
+ msg_err "same extension key write to cni args"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ crictl stopp $sid
if [ $? -ne 0 ];then
- msg_err "lost extension for second cni args"
+ msg_err "stop sandbox failed"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ crictl rmp $sid
+ if [ $? -ne 0 ];then
+ msg_err "rm sandbox failed"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ return $TC_RET_T
+}
+
+function check_rollback()
+{
+ rm -f /etc/cni/net.d/*
+ cp ${data_path}/mock.json /etc/cni/net.d/bridge.json
+ sed -i "s#mock#default#g" /etc/cni/net.d/bridge.json
+ cp ${data_path}/mock.json /etc/cni/net.d/
+ cp ${data_path}/mock_wrong.json /etc/cni/net.d/
+ sync;sync;
+ tail $ISUALD_LOG
+ # wait cni updated
+ s=`date "+%s"`
+ for ((i=0;i<30;i++)); do
+ sleep 1
+ cur=`date "+%s"`
+ let "t=cur-s"
+ if [ $t -gt 6 ];then
+ break
+ fi
+ done
+ tail $ISUALD_LOG
+
+ crictl runp ${data_path}/mutl_wrong_net_pod.json
+ if [ $? -eq 0 ]; then
+ msg_err "Run sandbox success with invalid cni configs"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ sid=`crictl pods -q | head -1`
+
+ basepath=/tmp/cnilogs/
+
+ cat ${basepath}/${sid}_eth0.env | grep "CNI_COMMAND=DEL"
+ if [ $? -ne 0 ];then
+ msg_err "do not rollback for eth0"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ cat ${basepath}/${sid}_eth1.env | grep "CNI_COMMAND=DEL"
+ if [ $? -ne 0 ];then
+ msg_err "do not rollback for eth1"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ cat ${basepath}/${sid}_eth2.env | grep "CNI_COMMAND=DEL"
+ if [ $? -ne 0 ];then
+ msg_err "do not rollback for eth2"
TC_RET_T=$(($TC_RET_T+1))
fi
@@ -227,6 +291,9 @@ function check_annotation()
TC_RET_T=$(($TC_RET_T+1))
fi
+ rm -f /etc/cni/net.d/*
+ cp ${data_path}/bridge.json /etc/cni/net.d/
+
return $TC_RET_T
}
@@ -247,6 +314,16 @@ if [ $? -ne 0 ];then
let "ret=$ret + 1"
fi
+check_annotation
+if [ $? -ne 0 ];then
+ let "ret=$ret + 1"
+fi
+
+check_rollback
+if [ $? -ne 0 ];then
+ let "ret=$ret + 1"
+fi
+
do_post
show_result $ret "cni base test"
diff --git a/CI/test_cases/container_cases/criconfigs/bins/isulad-cni b/CI/test_cases/container_cases/criconfigs/bins/isulad-cni
index e4b7e598..be48b77a 100755
--- a/CI/test_cases/container_cases/criconfigs/bins/isulad-cni
+++ b/CI/test_cases/container_cases/criconfigs/bins/isulad-cni
@@ -8,8 +8,8 @@ envpath=${basepath}/${secs}.env
env | grep CNI_CONTAINERID >/dev/null 2>&1
if [ $? -eq 0 ];then
- confpath=${basepath}/${CNI_CONTAINERID}.netconf
- envpath=${basepath}/${CNI_CONTAINERID}.env
+ confpath=${basepath}/${CNI_CONTAINERID}_${CNI_IFNAME}.netconf
+ envpath=${basepath}/${CNI_CONTAINERID}_${CNI_IFNAME}.env
fi
read -r line
diff --git a/CI/test_cases/container_cases/criconfigs/bins/wrong-cni b/CI/test_cases/container_cases/criconfigs/bins/wrong-cni
new file mode 100755
index 00000000..558c3401
--- /dev/null
+++ b/CI/test_cases/container_cases/criconfigs/bins/wrong-cni
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+basepath=/tmp/cnilogs/
+mkdir -p $basepath
+secs=`date "+%s"`
+confpath=${basepath}/${secs}.netconf
+envpath=${basepath}/${secs}.env
+
+env | grep CNI_CONTAINERID >/dev/null 2>&1
+if [ $? -eq 0 ];then
+ confpath=${basepath}/${CNI_CONTAINERID}_${CNI_IFNAME}.netconf
+ envpath=${basepath}/${CNI_CONTAINERID}_${CNI_IFNAME}.env
+fi
+
+read -r line
+echo $line > ${confpath}
+
+env > ${envpath}
+
+echo "{
+ \"cniVersion\": \"0.3.1\",
+ \"dns\": {}
+}"
+
+exit 1
\ No newline at end of file
diff --git a/CI/test_cases/container_cases/criconfigs/mock_wrong.json b/CI/test_cases/container_cases/criconfigs/mock_wrong.json
new file mode 100644
index 00000000..7b2a92e4
--- /dev/null
+++ b/CI/test_cases/container_cases/criconfigs/mock_wrong.json
@@ -0,0 +1,9 @@
+{
+ "cniVersion": "0.3.1",
+ "name": "wrong",
+ "type": "wrong-cni",
+ "ipam": {
+ "type": "wrong-cni",
+ "subnet": "10.8.0.0/16"
+ }
+}
diff --git a/CI/test_cases/container_cases/criconfigs/mutl_wrong_net_pod.json b/CI/test_cases/container_cases/criconfigs/mutl_wrong_net_pod.json
new file mode 100644
index 00000000..01a6096c
--- /dev/null
+++ b/CI/test_cases/container_cases/criconfigs/mutl_wrong_net_pod.json
@@ -0,0 +1,14 @@
+{
+ "port_mappings":[{"protocol": 1, "container_port": 80, "host_port": 8080}],
+ "metadata": {
+ "name": "test",
+ "namespace": "default",
+ "attempt": 1,
+ "uid": "hdishd83djaidwnduwk28bcsb"
+ },
+ "linux": {
+ },
+ "annotations": {
+ "network.alpha.kubernetes.io/network": "[{\"name\":\"mock\",\"interface\":\"eth1\"},{\"name\":\"wrong\",\"interface\":\"eth2\"}]"
+ }
+}
diff --git a/CI/test_cases/helpers.sh b/CI/test_cases/helpers.sh
index 5a782281..fe256e8c 100755
--- a/CI/test_cases/helpers.sh
+++ b/CI/test_cases/helpers.sh
@@ -174,7 +174,7 @@ function init_cni_conf()
mkdir -p /etc/cni/net.d/
rm -rf /etc/cni/net.d/*
mkdir -p /opt/cni/bin
- cp $dtpath/bins/isulad-cni /opt/cni/bin
+ cp $dtpath/bins/* /opt/cni/bin/
cp $dtpath/good.conflist /etc/cni/net.d/
check_valgrind_log
--
2.25.1

View File

@ -1,328 +0,0 @@
From 9a605646c7e20773c52799ee4abcff20e26071de Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Sat, 27 Feb 2021 14:19:24 +0800
Subject: [PATCH 47/53] log: adjust log level from EVENT to WARN to reduce log
number
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/cmd/isulad/main.c | 2 +-
.../connect/grpc/runtime_image_service.cc | 13 ++++-----
.../connect/grpc/runtime_runtime_service.cc | 28 +++++++++----------
src/daemon/executor/container_cb/list.c | 2 +-
src/daemon/modules/image/image.c | 12 ++++----
.../modules/image/oci/oci_common_operators.c | 4 +--
src/utils/cutils/utils_fs.c | 2 +-
7 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index ce93eaa0..cb2b71a2 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -1515,7 +1515,7 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &t_end);
use_time = (double)(t_end.tv_sec - t_start.tv_sec) * (double)1000000000 + (double)(t_end.tv_nsec - t_start.tv_nsec);
use_time /= 1000000000;
- INFO("iSulad successfully booted in %.3f s", use_time);
+ EVENT("iSulad successfully booted in %.3f s", use_time);
#ifdef GRPC_CONNECTOR
INFO("Starting grpc server...");
#else
diff --git a/src/daemon/entry/connect/grpc/runtime_image_service.cc b/src/daemon/entry/connect/grpc/runtime_image_service.cc
index 8e740caf..23447baf 100644
--- a/src/daemon/entry/connect/grpc/runtime_image_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_image_service.cc
@@ -21,7 +21,6 @@
#include "cri_helpers.h"
#include "cri_image_manager_service_impl.h"
-
RuntimeImageServiceImpl::RuntimeImageServiceImpl()
{
std::unique_ptr<ImageManagerService> service(new ImageManagerServiceImpl);
@@ -55,7 +54,7 @@ grpc::Status RuntimeImageServiceImpl::ListImages(grpc::ServerContext *context,
std::vector<std::unique_ptr<runtime::v1alpha2::Image>> images;
Errors error;
- EVENT("Event: {Object: CRI, Type: Listing all images}");
+ WARN("Event: {Object: CRI, Type: Listing all images}");
rService->ListImages(request->filter(), &images, error);
if (!error.Empty()) {
@@ -71,7 +70,7 @@ grpc::Status RuntimeImageServiceImpl::ListImages(grpc::ServerContext *context,
*image = *(iter->get());
}
- EVENT("Event: {Object: CRI, Type: Listed all images}");
+ WARN("Event: {Object: CRI, Type: Listed all images}");
return grpc::Status::OK;
}
@@ -83,7 +82,7 @@ grpc::Status RuntimeImageServiceImpl::ImageStatus(grpc::ServerContext *context,
std::unique_ptr<runtime::v1alpha2::Image> image_info = nullptr;
Errors error;
- EVENT("Event: {Object: CRI, Type: Statusing image %s}", request->image().image().c_str());
+ WARN("Event: {Object: CRI, Type: Statusing image %s}", request->image().image().c_str());
image_info = rService->ImageStatus(request->image(), error);
if (!error.Empty() && !CRIHelpers::IsImageNotFoundError(error.GetMessage())) {
@@ -97,7 +96,7 @@ grpc::Status RuntimeImageServiceImpl::ImageStatus(grpc::ServerContext *context,
*image = *image_info;
}
- EVENT("Event: {Object: CRI, Type: Statused image %s}", request->image().image().c_str());
+ WARN("Event: {Object: CRI, Type: Statused image %s}", request->image().image().c_str());
return grpc::Status::OK;
}
@@ -109,7 +108,7 @@ grpc::Status RuntimeImageServiceImpl::ImageFsInfo(grpc::ServerContext *context,
std::vector<std::unique_ptr<runtime::v1alpha2::FilesystemUsage>> usages;
Errors error;
- EVENT("Event: {Object: CRI, Type: Statusing image fs info}");
+ WARN("Event: {Object: CRI, Type: Statusing image fs info}");
rService->ImageFsInfo(&usages, error);
if (!error.Empty()) {
@@ -126,7 +125,7 @@ grpc::Status RuntimeImageServiceImpl::ImageFsInfo(grpc::ServerContext *context,
*fs_info = *(iter->get());
}
- EVENT("Event: {Object: CRI, Type: Statused image fs info}");
+ WARN("Event: {Object: CRI, Type: Statused image fs info}");
return grpc::Status::OK;
}
diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
index c09153eb..c9702401 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
@@ -50,8 +50,8 @@ void RuntimeRuntimeServiceImpl::Init(Network::NetworkPluginConf mConf, isulad_da
Network::ProbeNetworkPlugins(mConf.GetPluginConfDir(), mConf.GetPluginBinDir(), &plugins);
std::shared_ptr<Network::NetworkPlugin> chosen { nullptr };
- Network::InitNetworkPlugin(&plugins, mConf.GetPluginName(), mConf.GetHairpinMode(),
- mConf.GetNonMasqueradeCIDR(), mConf.GetMTU(), &chosen, err);
+ Network::InitNetworkPlugin(&plugins, mConf.GetPluginName(), mConf.GetHairpinMode(), mConf.GetNonMasqueradeCIDR(),
+ mConf.GetMTU(), &chosen, err);
if (err.NotEmpty()) {
ERROR("Init network plugin failed: %s", err.GetCMessage());
return;
@@ -181,7 +181,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainers(grpc::ServerContext *cont
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Listing all Container}");
+ WARN("Event: {Object: CRI, Type: Listing all Container}");
std::vector<std::unique_ptr<runtime::v1alpha2::Container>> containers;
rService->ListContainers(request->has_filter() ? &request->filter() : nullptr, &containers, error);
@@ -199,7 +199,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainers(grpc::ServerContext *cont
*container = *(iter->get());
}
- EVENT("Event: {Object: CRI, Type: Listed all Container}");
+ WARN("Event: {Object: CRI, Type: Listed all Container}");
return grpc::Status::OK;
}
@@ -210,7 +210,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainerStats(grpc::ServerContext *
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Listing all Container stats}");
+ WARN("Event: {Object: CRI, Type: Listing all Container stats}");
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> containers;
rService->ListContainerStats(request->has_filter() ? &request->filter() : nullptr, &containers, error);
@@ -228,7 +228,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListContainerStats(grpc::ServerContext *
*container = *(iter->get());
}
- EVENT("Event: {Object: CRI, Type: Listed all Container stats}");
+ WARN("Event: {Object: CRI, Type: Listed all Container stats}");
return grpc::Status::OK;
}
@@ -239,7 +239,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ContainerStatus(grpc::ServerContext *con
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Statusing Container: %s}", request->container_id().c_str());
+ WARN("Event: {Object: CRI, Type: Statusing Container: %s}", request->container_id().c_str());
std::unique_ptr<runtime::v1alpha2::ContainerStatus> contStatus =
rService->ContainerStatus(request->container_id(), error);
@@ -249,7 +249,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ContainerStatus(grpc::ServerContext *con
}
*(reply->mutable_status()) = *contStatus;
- EVENT("Event: {Object: CRI, Type: Statused Container: %s}", request->container_id().c_str());
+ WARN("Event: {Object: CRI, Type: Statused Container: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
@@ -339,7 +339,7 @@ grpc::Status RuntimeRuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *co
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Status Pod: %s}", request->pod_sandbox_id().c_str());
+ WARN("Event: {Object: CRI, Type: Status Pod: %s}", request->pod_sandbox_id().c_str());
std::unique_ptr<runtime::v1alpha2::PodSandboxStatus> podStatus;
podStatus = rService->PodSandboxStatus(request->pod_sandbox_id(), error);
@@ -350,7 +350,7 @@ grpc::Status RuntimeRuntimeServiceImpl::PodSandboxStatus(grpc::ServerContext *co
}
*(reply->mutable_status()) = *podStatus;
- EVENT("Event: {Object: CRI, Type: Statused Pod: %s}", request->pod_sandbox_id().c_str());
+ WARN("Event: {Object: CRI, Type: Statused Pod: %s}", request->pod_sandbox_id().c_str());
return grpc::Status::OK;
}
@@ -361,7 +361,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *cont
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Listing all Pods}");
+ WARN("Event: {Object: CRI, Type: Listing all Pods}");
std::vector<std::unique_ptr<runtime::v1alpha2::PodSandbox>> pods;
rService->ListPodSandbox(request->has_filter() ? &request->filter() : nullptr, &pods, error);
@@ -378,7 +378,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ListPodSandbox(grpc::ServerContext *cont
*pod = *(iter->get());
}
- EVENT("Event: {Object: CRI, Type: Listed all Pods}");
+ WARN("Event: {Object: CRI, Type: Listed all Pods}");
return grpc::Status::OK;
}
@@ -470,7 +470,7 @@ grpc::Status RuntimeRuntimeServiceImpl::Status(grpc::ServerContext *context,
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Statusing daemon}");
+ WARN("Event: {Object: CRI, Type: Statusing daemon}");
std::unique_ptr<runtime::v1alpha2::RuntimeStatus> status = rService->Status(error);
if (status == nullptr || error.NotEmpty()) {
@@ -479,7 +479,7 @@ grpc::Status RuntimeRuntimeServiceImpl::Status(grpc::ServerContext *context,
}
*(reply->mutable_status()) = *status;
- EVENT("Event: {Object: CRI, Type: Statused daemon}");
+ WARN("Event: {Object: CRI, Type: Statused daemon}");
return grpc::Status::OK;
}
diff --git a/src/daemon/executor/container_cb/list.c b/src/daemon/executor/container_cb/list.c
index 34c1b956..d8f26328 100644
--- a/src/daemon/executor/container_cb/list.c
+++ b/src/daemon/executor/container_cb/list.c
@@ -503,7 +503,7 @@ static container_container *get_container_info(const char *name, const struct li
cont = containers_store_get(name);
if (cont == NULL) {
- ERROR("Container '%s' already removed", name);
+ ERROR("Container '%s' not exist", name);
return NULL;
}
cont_state = container_dup_state(cont->state);
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
index 4563efea..8e663863 100644
--- a/src/daemon/modules/image/image.c
+++ b/src/daemon/modules/image/image.c
@@ -392,7 +392,7 @@ int im_get_filesystem_info(const char *image_type, im_fs_info_response **respons
goto out;
}
- EVENT("Event: {Object: get image filesystem info, Type: inspecting}");
+ WARN("Event: {Object: get image filesystem info, Type: inspecting}");
ret = q->ops->get_filesystem_info(response);
if (ret != 0) {
if (response != NULL && *response != NULL) {
@@ -402,7 +402,7 @@ int im_get_filesystem_info(const char *image_type, im_fs_info_response **respons
}
goto out;
}
- EVENT("Event: {Object: get image filesystem info, Type: inspected}");
+ WARN("Event: {Object: get image filesystem info, Type: inspected}");
out:
return ret;
@@ -442,7 +442,7 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
request->name_id = util_strdup_s(id);
}
- EVENT("Event: {Object: container \'%s\' filesystem info, Type: inspecting}", id != NULL ? id : "");
+ WARN("Event: {Object: container \'%s\' filesystem info, Type: inspecting}", id != NULL ? id : "");
ret = q->ops->container_fs_usage(request, &filesystemusage);
if (ret != 0) {
ERROR("Failed to get filesystem usage for container %s", id);
@@ -452,7 +452,7 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
*fs_usage = filesystemusage;
filesystemusage = NULL;
- EVENT("Event: {Object: container \'%s\' filesystem info, Type: inspected}", id != NULL ? id : "");
+ WARN("Event: {Object: container \'%s\' filesystem info, Type: inspected}", id != NULL ? id : "");
out:
free_im_container_fs_usage_request(request);
@@ -1597,7 +1597,7 @@ int im_inspect_image(const im_inspect_request *request, im_inspect_response **re
image_ref = util_strdup_s(request->image.image);
- EVENT("Event: {Object: %s, Type: image inspecting}", image_ref);
+ WARN("Event: {Object: %s, Type: image inspecting}", image_ref);
bim_type = bim_query(image_ref);
if (bim_type == NULL) {
@@ -1619,7 +1619,7 @@ int im_inspect_image(const im_inspect_request *request, im_inspect_response **re
goto pack_response;
}
- EVENT("Event: {Object: %s, Type: image inspected}", image_ref);
+ WARN("Event: {Object: %s, Type: image inspected}", image_ref);
pack_response:
if (g_isulad_errmsg != NULL) {
diff --git a/src/daemon/modules/image/oci/oci_common_operators.c b/src/daemon/modules/image/oci/oci_common_operators.c
index aecb63d0..845e1fde 100644
--- a/src/daemon/modules/image/oci/oci_common_operators.c
+++ b/src/daemon/modules/image/oci/oci_common_operators.c
@@ -431,7 +431,7 @@ int oci_summary_image(im_summary_request *request, im_summary_response *response
goto pack_response;
}
- EVENT("Event: {Object: %s, Type: statusing image summary}", resolved_name);
+ WARN("Event: {Object: %s, Type: statusing image summary}", resolved_name);
image_summary = storage_img_get_summary(resolved_name);
if (image_summary == NULL) {
@@ -444,7 +444,7 @@ int oci_summary_image(im_summary_request *request, im_summary_response *response
response->image_summary = image_summary;
image_summary = NULL;
- EVENT("Event: {Object: %s, Type: statused image summary}", resolved_name);
+ WARN("Event: {Object: %s, Type: statused image summary}", resolved_name);
pack_response:
free(resolved_name);
diff --git a/src/utils/cutils/utils_fs.c b/src/utils/cutils/utils_fs.c
index 788557f9..bbbf2d2d 100644
--- a/src/utils/cutils/utils_fs.c
+++ b/src/utils/cutils/utils_fs.c
@@ -515,7 +515,7 @@ int util_mount(const char *src, const char *dst, const char *mtype, const char *
if ((mntflags & MS_REMOUNT) != MS_REMOUNT) {
if (util_detect_mounted(dst)) {
- ERROR("mount dst %s had been mounted, skip mount", dst);
+ WARN("mount dst %s had been mounted, skip mount", dst);
ret = 0;
goto out;
}
--
2.25.1

View File

@ -1,249 +0,0 @@
From 358e79c5e21503348eae0f1b9e56206269060ec4 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Fri, 26 Feb 2021 04:37:03 -0500
Subject: [PATCH 48/53] isulad-shim: fix shim exit bug
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
src/cmd/isulad-shim/process.c | 3 +-
src/cmd/isulad-shim/process.h | 2 +-
src/cmd/isulad-shim/terminal.c | 109 ++++++++++++++++++++-------------
src/cmd/isulad-shim/terminal.h | 2 +-
4 files changed, 70 insertions(+), 46 deletions(-)
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
index 3ac739b9..25e84fbd 100644
--- a/src/cmd/isulad-shim/process.c
+++ b/src/cmd/isulad-shim/process.c
@@ -266,8 +266,7 @@ static void *do_io_copy(void *data)
fd_node_t *fn = ioc->fd_to;
for (; fn != NULL; fn = fn->next) {
if (fn->is_log) {
- shim_write_container_log_file(io_thd->terminal, ioc->id == stdid_out ? "stdout" : "stderr", buf,
- r_count);
+ shim_write_container_log_file(io_thd->terminal, ioc->id, buf, r_count);
} else {
int w_count = write_nointr_in_total(fn->fd, buf, r_count);
if (w_count < 0) {
diff --git a/src/cmd/isulad-shim/process.h b/src/cmd/isulad-shim/process.h
index c17a20b1..6e596551 100644
--- a/src/cmd/isulad-shim/process.h
+++ b/src/cmd/isulad-shim/process.h
@@ -59,7 +59,7 @@ typedef struct {
io_copy_t *ioc;
bool shutdown;
bool is_stdin;
- log_terminal *terminal;
+ log_terminal *terminal;// just used by stdout and stderr
} io_thread_t;
typedef struct process {
diff --git a/src/cmd/isulad-shim/terminal.c b/src/cmd/isulad-shim/terminal.c
index ac39539a..ed40ad5e 100644
--- a/src/cmd/isulad-shim/terminal.c
+++ b/src/cmd/isulad-shim/terminal.c
@@ -30,19 +30,11 @@
#include <unistd.h>
#include "common.h"
+#include "process.h"
-#define BUF_CACHE_SIZE (16 * 1024)
-
-static ssize_t shim_write_nointr_lock(log_terminal *terminal, const void *buf, size_t count)
-{
- ssize_t ret;
-
- (void)pthread_rwlock_wrlock(&terminal->log_terminal_rwlock);
- ret = write_nointr_in_total(terminal->fd, buf, count);
- (void)pthread_rwlock_unlock(&terminal->log_terminal_rwlock);
-
- return ret;
-}
+#define BUF_CACHE_SIZE (32 * 1024)
+#define STDOUT_STR "stdout"
+#define STDERR_STR "stderr"
static int shim_rename_old_log_file(log_terminal *terminal)
{
@@ -137,23 +129,29 @@ static int64_t get_log_file_size(int fd)
static int shim_json_data_write(log_terminal *terminal, const char *buf, int read_count)
{
- int ret;
+ int ret = 0;
+ int nret = 0;
int64_t available_space = -1;
int64_t file_size;
+ (void)pthread_rwlock_wrlock(&terminal->log_terminal_rwlock);
+
+
file_size = get_log_file_size(terminal->fd);
if (file_size < 0) {
- return SHIM_ERR;
+ ret = -1;
+ goto out;
}
available_space = terminal->log_maxsize - file_size;
if (read_count <= available_space) {
- return shim_write_nointr_lock(terminal, buf, read_count);
+ ret = write_nointr_in_total(terminal->fd, buf, read_count);
+ goto out;
}
- ret = shim_dump_log_file(terminal);
- if (ret < 0) {
- return SHIM_ERR;
+ if (shim_dump_log_file(terminal) < 0) {
+ ret = -1;
+ goto out;
}
/*
@@ -161,13 +159,18 @@ static int shim_json_data_write(log_terminal *terminal, const char *buf, int rea
* We have set the log file min size 16k, so the scenario of log_maxsize < read_count
* shouldn't happen, otherwise, discard some last bytes.
*/
- ret = shim_write_nointr_lock(terminal, buf,
+ nret = write_nointr_in_total(terminal->fd, buf,
terminal->log_maxsize < read_count ? terminal->log_maxsize : read_count);
- if (ret < 0) {
- return SHIM_ERR;
+ if (nret < 0) {
+ ret = -1;
+ goto out;
}
- return (read_count - ret);
+ ret = read_count - nret;
+
+out:
+ (void)pthread_rwlock_unlock(&terminal->log_terminal_rwlock);
+ return ret;
}
static bool util_get_time_buffer(struct timespec *timestamp, char *timebuffer, size_t maxsize)
@@ -256,10 +259,18 @@ cleanup:
return ret;
}
-void shim_write_container_log_file(log_terminal *terminal, const char *type, char *buf, int read_count)
+// BUF_CACHE_SIZE must be larger than read_count of buf readed
+static char cache_out[BUF_CACHE_SIZE] = { 0 };
+static char cache_err[BUF_CACHE_SIZE] = { 0 };
+static int size_out = 0;
+static int size_err = 0;
+
+// Just used by stdout stderr threads
+void shim_write_container_log_file(log_terminal *terminal, int type, char *buf, int read_count)
{
- static char cache[BUF_CACHE_SIZE];
- static int size = 0;
+ char *cache = NULL;
+ int *size = NULL;
+ const char *type_str = NULL;
int upto, index;
int begin = 0;
int buf_readed = 0;
@@ -268,38 +279,52 @@ void shim_write_container_log_file(log_terminal *terminal, const char *type, cha
if (terminal == NULL) {
return;
}
+ switch (type) {
+ case stdid_out:
+ type_str = STDOUT_STR;
+ cache = cache_out;
+ size = &size_out;
+ break;
+ case stdid_err:
+ type_str = STDERR_STR;
+ cache = cache_err;
+ size = &size_err;
+ break;
+ default:
+ return;
+ }
if (buf != NULL && read_count > 0) {
- if (read_count > (BUF_CACHE_SIZE - size)) {
+ if (read_count > (BUF_CACHE_SIZE - *size)) {
upto = BUF_CACHE_SIZE;
} else {
- upto = size + read_count;
+ upto = *size + read_count;
}
- if (upto > size) {
- buf_readed = upto - size;
- memcpy(cache + size, buf, buf_readed);
+ if (upto > *size) {
+ buf_readed = upto - *size;
+ memcpy(cache + *size, buf, buf_readed);
buf_left = read_count - buf_readed;
- size += buf_readed;
+ *size += buf_readed;
}
}
- if (size == 0) {
+ if (*size == 0) {
return;
}
- for (index = 0; index < size; index++) {
+ for (index = 0; index < *size; index++) {
if (cache[index] == '\n') {
- (void)shim_logger_write(terminal, type, cache + begin, index - begin + 1);
+ (void)shim_logger_write(terminal, type_str, cache + begin, index - begin + 1);
begin = index + 1;
}
}
- if (buf == NULL || (begin == 0 && size == BUF_CACHE_SIZE)) {
- if (begin < size) {
- (void)shim_logger_write(terminal, type, cache + begin, size - begin);
+ if (buf == NULL || (begin == 0 && *size == BUF_CACHE_SIZE)) {
+ if (begin < *size) {
+ (void)shim_logger_write(terminal, type_str, cache + begin, *size - begin);
begin = 0;
- size = 0;
+ *size = 0;
}
if (buf == NULL) {
return;
@@ -307,13 +332,13 @@ void shim_write_container_log_file(log_terminal *terminal, const char *type, cha
}
if (begin > 0) {
- memcpy(cache, cache + begin, size - begin);
- size -= begin;
+ memcpy(cache, cache + begin, *size - begin);
+ *size -= begin;
}
if (buf_left > 0) {
- memcpy(cache + size, buf + buf_readed, buf_left);
- size += buf_left;
+ memcpy(cache + *size, buf + buf_readed, buf_left);
+ *size += buf_left;
}
}
diff --git a/src/cmd/isulad-shim/terminal.h b/src/cmd/isulad-shim/terminal.h
index d9ed8f1a..556117a0 100644
--- a/src/cmd/isulad-shim/terminal.h
+++ b/src/cmd/isulad-shim/terminal.h
@@ -34,7 +34,7 @@ typedef struct {
pthread_rwlock_t log_terminal_rwlock;
} log_terminal;
-void shim_write_container_log_file(log_terminal *terminal, const char *type, char *buf,
+void shim_write_container_log_file(log_terminal *terminal, int type, char *buf,
int bytes_read);
int shim_create_container_log_file(log_terminal *terminal);
--
2.25.1

View File

@ -1,116 +0,0 @@
From 4692715e4ef7e1ec5461b03940f85cac4af8b18e Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Sat, 27 Feb 2021 10:44:26 +0800
Subject: [PATCH 049/104] support --pull option when create/run container
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/cmd/isula/base/create.c | 24 +++++++++++++++++++++++-
src/cmd/isula/base/create.h | 7 +++++++
src/cmd/isula/base/run.c | 1 +
src/cmd/isula/client_arguments.h | 1 +
4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/cmd/isula/base/create.c b/src/cmd/isula/base/create.c
index a531fc0e..48dc29be 100644
--- a/src/cmd/isula/base/create.c
+++ b/src/cmd/isula/base/create.c
@@ -59,6 +59,7 @@ struct client_arguments g_cmd_create_args = {
.custom_conf.health_timeout = 0,
.custom_conf.health_start_period = 0,
.custom_conf.health_retries = 0,
+ .pull = "missing"
};
static void request_pack_host_config_limit(const struct client_arguments *args, isula_host_config_t *hostconfig)
@@ -1268,9 +1269,17 @@ static int client_try_to_create(const struct client_arguments *args, const struc
goto out;
}
+ if (strcmp(args->pull, "always") == 0) {
+ ret = client_pull(args);
+ if (ret != 0) {
+ goto out;
+ }
+ }
+
ret = do_client_create(args, ops, request, response);
if (ret != 0) {
- if (response->errmsg == NULL || strstr(response->errmsg, IMAGE_NOT_FOUND_ERROR) == NULL) {
+ if (response->errmsg == NULL || strstr(response->errmsg, IMAGE_NOT_FOUND_ERROR) == NULL ||
+ strcmp(args->pull, "missing") != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
goto out;
}
@@ -1299,6 +1308,14 @@ out:
return ret;
}
+static bool valid_pull_option(const char *pull)
+{
+ if (strcmp(pull, "always") == 0 || strcmp(pull, "missing") == 0 || strcmp(pull, "never") == 0) {
+ return true;
+ }
+ return false;
+}
+
/*
* Create a create request message and call RPC
*/
@@ -1551,6 +1568,11 @@ int cmd_create_main(int argc, const char **argv)
exit(ECOMMON);
}
+ if (!valid_pull_option(g_cmd_create_args.pull)) {
+ COMMAND_ERROR("invalid --pull option, only \"always\"|\"missing\"|\"never\" is allowed");
+ exit(ECOMMON);
+ }
+
ret = client_create(&g_cmd_create_args);
if (ret != 0) {
ERROR("Container \"%s\" create failed", g_cmd_create_args.name);
diff --git a/src/cmd/isula/base/create.h b/src/cmd/isula/base/create.h
index 1c455d40..610a289f 100644
--- a/src/cmd/isula/base/create.h
+++ b/src/cmd/isula/base/create.h
@@ -276,6 +276,13 @@ extern "C" {
&(cmdargs).custom_conf.privileged, \
"Give extended privileges to this container", \
NULL }, \
+ { CMD_OPT_TYPE_STRING, \
+ false, \
+ "pull", \
+ 0, \
+ &(cmdargs).pull, \
+ "Pull image before running (\"always\"|\"missing\"|\"never\") (default \"missing\")", \
+ NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "tmpfs", 0, &(cmdargs).custom_conf.tmpfs, "Mount a tmpfs directory", \
command_append_array }, \
{ CMD_OPT_TYPE_BOOL, false, "tty", 't', &(cmdargs).custom_conf.tty, "Allocate a pseudo-TTY", NULL }, \
diff --git a/src/cmd/isula/base/run.c b/src/cmd/isula/base/run.c
index a6068709..53e89c3d 100644
--- a/src/cmd/isula/base/run.c
+++ b/src/cmd/isula/base/run.c
@@ -39,6 +39,7 @@ static int run_checker(struct client_arguments *args);
struct client_arguments g_cmd_run_args = {
.runtime = "",
.restart = "no",
+ .pull = "missing"
};
static int local_cmd_start(const struct client_arguments *args)
diff --git a/src/cmd/isula/client_arguments.h b/src/cmd/isula/client_arguments.h
index adb45104..a155b863 100644
--- a/src/cmd/isula/client_arguments.h
+++ b/src/cmd/isula/client_arguments.h
@@ -307,6 +307,7 @@ struct client_arguments {
// pull/rmi
char *ref;
bool plain_http;
+ char *pull;
// logs
bool follow;
--
2.25.1

View File

@ -1,38 +0,0 @@
From 55ffef15be755f2e5fbf78ec6b5b4a6e7be9b690 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Sat, 27 Feb 2021 11:23:53 +0800
Subject: [PATCH 050/104] add testcase for --pull option
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/image_cases/registry.sh | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/CI/test_cases/image_cases/registry.sh b/CI/test_cases/image_cases/registry.sh
index 4e6adc28..c0a0db05 100755
--- a/CI/test_cases/image_cases/registry.sh
+++ b/CI/test_cases/image_cases/registry.sh
@@ -60,6 +60,20 @@ function isula_pull()
isula inspect busybox
fn_check_eq "$?" "0" "isula inspect busybox"
+ # test --pull always option
+ isula run --rm -ti --pull always busybox echo hello 2>&1 | grep pulling
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - --pull always failed" && ((ret++))
+
+ # test --pull never option
+ isula rm -f `isula ps -a -q`
+ isula rmi busybox
+ isula run --rm -ti --pull never busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - --pull never failed" && ((ret++))
+
+ # test default --pull option (missing)
+ isula run --rm -ti busybox echo hello 2>&1 | grep pulling
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - --pull missing failed" && ((ret++))
+
isula pull 3laho3y3.mirror.aliyuncs.com/library/busybox
fn_check_eq "$?" "0" "isula pull 3laho3y3.mirror.aliyuncs.com/library/busybox"
--
2.25.1

View File

@ -1,25 +0,0 @@
From 72ad417b26b17b0981cd163f42bc23d98e19b4e7 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Mon, 1 Mar 2021 17:17:17 +0800
Subject: [PATCH 051/104] remove redundant code
Signed-off-by: wujing <wujing50@huawei.com>
---
src/daemon/modules/runtime/isula/isula_rt_ops.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
index 540f1f67..ecea2b3d 100644
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
@@ -612,7 +612,6 @@ static int status_to_exit_code(int status)
exit_code = WEXITSTATUS(status);
} else {
exit_code = -1;
- exit_code = -1;
}
if (WIFSIGNALED(status)) {
int signal;
--
2.25.1

View File

@ -1,35 +0,0 @@
From adde17cdd844a51fa606c74a0f241c62dbf11a27 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Fri, 5 Mar 2021 23:13:31 -0500
Subject: [PATCH 052/104] devicemapper: umount when resize2fs command failed
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../storage/layer_store/graphdriver/devmapper/deviceset.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index 0b0394c5..3a271c3a 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -2158,14 +2158,15 @@ static int grow_fs(struct device_set *devset, image_devmapper_device_info *info)
if (exec_grow_fs_command("resize2fs", dev_fname) != 0) {
ERROR("Failed execute resize2fs to grow rootfs");
ret = -1;
- goto out;
+ goto clean_mount;
}
} else {
ERROR("Unsupported filesystem type %s", devset->base_device_filesystem);
ret = -1;
- goto out;
+ goto clean_mount;
}
+clean_mount:
if (umount2(FS_MOUNT_POINT, MNT_DETACH) < 0 && errno != EINVAL) {
WARN("Failed to umount directory %s:%s", FS_MOUNT_POINT, strerror(errno));
}
--
2.25.1

View File

@ -1,174 +0,0 @@
From 4794f7a73a40e612c49d7c9f78fabaab0f9ab696 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 11 Mar 2021 11:51:37 +0800
Subject: [PATCH 053/104] support isula exec --workdir
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/api/services/containers/container.proto | 1 +
src/client/connect/grpc/grpc_containers_client.cc | 3 +++
src/client/connect/protocol_type.c | 3 +++
src/client/connect/protocol_type.h | 1 +
src/cmd/isula/stream/exec.c | 2 ++
src/cmd/isula/stream/exec.h | 4 +++-
.../entry/connect/grpc/grpc_containers_service_private.cc | 3 +++
src/daemon/modules/api/runtime_api.h | 1 +
src/daemon/modules/runtime/engines/engine.h | 1 +
src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c | 3 +++
src/daemon/modules/service/service_container.c | 1 +
11 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/api/services/containers/container.proto b/src/api/services/containers/container.proto
index efd085a1..d7adc506 100644
--- a/src/api/services/containers/container.proto
+++ b/src/api/services/containers/container.proto
@@ -316,6 +316,7 @@ message ExecRequest {
repeated string env = 11;
string user = 12;
string suffix = 13;
+ string workdir = 14;
}
message ExecResponse {
int32 pid = 1;
diff --git a/src/client/connect/grpc/grpc_containers_client.cc b/src/client/connect/grpc/grpc_containers_client.cc
index ccde59a4..6661970b 100644
--- a/src/client/connect/grpc/grpc_containers_client.cc
+++ b/src/client/connect/grpc/grpc_containers_client.cc
@@ -807,6 +807,9 @@ public:
grequest->set_attach_stdin(request->attach_stdin);
grequest->set_attach_stdout(request->attach_stdout);
grequest->set_attach_stderr(request->attach_stderr);
+ if (request->workdir != nullptr) {
+ grequest->set_workdir(request->workdir);
+ }
if (request->stdin != nullptr) {
grequest->set_stdin(request->stdin);
}
diff --git a/src/client/connect/protocol_type.c b/src/client/connect/protocol_type.c
index 94f682a8..3e5dafb1 100644
--- a/src/client/connect/protocol_type.c
+++ b/src/client/connect/protocol_type.c
@@ -525,6 +525,9 @@ void isula_exec_request_free(struct isula_exec_request *request)
free(request->user);
request->user = NULL;
+ free(request->workdir);
+ request->workdir = NULL;
+
util_free_array_by_len(request->argv, request->argc);
request->argv = NULL;
request->argc = 0;
diff --git a/src/client/connect/protocol_type.h b/src/client/connect/protocol_type.h
index 32f55b51..62208d98 100644
--- a/src/client/connect/protocol_type.h
+++ b/src/client/connect/protocol_type.h
@@ -332,6 +332,7 @@ struct isula_exec_request {
char **env;
int64_t timeout;
char *user;
+ char *workdir;
};
struct isula_exec_response {
diff --git a/src/cmd/isula/stream/exec.c b/src/cmd/isula/stream/exec.c
index d1d57268..3c8601f2 100644
--- a/src/cmd/isula/stream/exec.c
+++ b/src/cmd/isula/stream/exec.c
@@ -65,6 +65,7 @@ static int fill_exec_request(const struct client_arguments *args, const struct c
}
request->user = util_strdup_s(args->custom_conf.user);
+ request->workdir = util_strdup_s(args->custom_conf.workdir);
if (util_dup_array_of_strings((const char **)args->argv, args->argc, &(request->argv),
(size_t *)(&request->argc)) != 0) {
@@ -327,6 +328,7 @@ static int remote_cmd_exec(const struct client_arguments *args, uint32_t *exit_c
request.attach_stdin = args->custom_conf.attach_stdin;
request.attach_stdout = args->custom_conf.attach_stdout;
request.attach_stderr = args->custom_conf.attach_stderr;
+ request.workdir = args->custom_conf.workdir;
request.argc = args->argc;
request.argv = (char **)args->argv;
diff --git a/src/cmd/isula/stream/exec.h b/src/cmd/isula/stream/exec.h
index 1e54ab82..cd94d91f 100644
--- a/src/cmd/isula/stream/exec.h
+++ b/src/cmd/isula/stream/exec.h
@@ -42,7 +42,9 @@
'u', \
&(cmdargs).custom_conf.user, \
"Username or UID (format: <name|uid>[:<group|gid>])", \
- NULL },
+ NULL }, \
+ { CMD_OPT_TYPE_STRING_DUP, false, "workdir", 0, &(cmdargs).custom_conf.workdir, \
+ "Working directory inside the container", NULL }
extern const char g_cmd_exec_desc[];
extern const char g_cmd_exec_usage[];
diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc b/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc
index 8e19f978..56283c8d 100644
--- a/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service_private.cc
@@ -359,6 +359,9 @@ int ContainerServiceImpl::exec_request_from_grpc(const ExecRequest *grequest, co
tmpreq->attach_stdout = grequest->attach_stdout();
tmpreq->attach_stderr = grequest->attach_stderr();
+ if (!grequest->workdir().empty()) {
+ tmpreq->workdir = util_strdup_s(grequest->workdir().c_str());
+ }
if (!grequest->stdin().empty()) {
tmpreq->stdin = util_strdup_s(grequest->stdin().c_str());
}
diff --git a/src/daemon/modules/api/runtime_api.h b/src/daemon/modules/api/runtime_api.h
index dde21b91..1203cde5 100644
--- a/src/daemon/modules/api/runtime_api.h
+++ b/src/daemon/modules/api/runtime_api.h
@@ -127,6 +127,7 @@ typedef struct _rt_exec_params_t {
const char *logpath;
const char *loglevel;
const char **console_fifos;
+ const char *workdir;
int64_t timeout;
const char *suffix;
defs_process *spec;
diff --git a/src/daemon/modules/runtime/engines/engine.h b/src/daemon/modules/runtime/engines/engine.h
index ced3cf22..7dd96f1e 100644
--- a/src/daemon/modules/runtime/engines/engine.h
+++ b/src/daemon/modules/runtime/engines/engine.h
@@ -82,6 +82,7 @@ typedef struct _engine_exec_request_t {
bool tty;
bool open_stdin;
+ const char *workdir;
} engine_exec_request_t;
typedef bool (*engine_create_t)(const char *, const char *, void *);
diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
index 27c6a631..2ed2f31e 100644
--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
+++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
@@ -390,6 +390,9 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
if (params->spec != NULL) {
request.tty = params->spec->terminal;
}
+ if (params->workdir != NULL) {
+ request.workdir = params->workdir;
+ }
if (!engine_ops->engine_exec_op(&request, exit_code)) {
const char *tmpmsg = NULL;
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index e1d698cd..ecf35821 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -1777,6 +1777,7 @@ static int do_exec_container(const container_t *cont, const char *runtime, char
params.state = cont->state_path;
params.spec = process_spec;
params.attach_stdin = request->attach_stdin;
+ params.workdir = request->workdir;
if (runtime_exec(cont->common_config->id, runtime, &params, exit_code)) {
ERROR("Runtime exec container failed");
--
2.25.1

View File

@ -1,72 +0,0 @@
From e6dfb82aaaee374f26538c11913233e4fb6037fe Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 11 Mar 2021 15:05:46 +0800
Subject: [PATCH 054/104] add testcase for isula exec --workdir
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/container_cases/exec.sh | 52 +++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
create mode 100755 CI/test_cases/container_cases/exec.sh
diff --git a/CI/test_cases/container_cases/exec.sh b/CI/test_cases/container_cases/exec.sh
new file mode 100755
index 00000000..28e27cfd
--- /dev/null
+++ b/CI/test_cases/container_cases/exec.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# attributes: isulad exec
+# concurrent: YES
+# spend time: 1
+
+#######################################################################
+##- @Copyright (C) Huawei Technologies., Ltd. 2021. All rights reserved.
+# - iSulad licensed under the Mulan PSL v2.
+# - You can use this software according to the terms and conditions of the Mulan PSL v2.
+# - You may obtain a copy of Mulan PSL v2 at:
+# - http://license.coscl.org.cn/MulanPSL2
+# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# - PURPOSE.
+# - See the Mulan PSL v2 for more details.
+##- @Description:CI
+##- @Author: wangfengtu
+##- @Create: 2021-03-09
+#######################################################################
+
+curr_path=$(dirname $(readlink -f "$0"))
+data_path=$(realpath $curr_path/../data)
+source ../helpers.sh
+test="exec test => test_exec"
+
+function exec_workdir()
+{
+ local ret=0
+
+ isula rm -f `isula ps -a -q`
+
+ isula run -tid -n cont_workdir busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with --workdir" && ((ret++))
+
+ isula exec -ti --workdir /workdir cont_workdir pwd | grep "/workdir"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - workdir is not /workdir failed" && ((ret++))
+
+ isula rm -f `isula ps -a -q`
+
+ return ${ret}
+}
+
+declare -i ans=0
+
+msg_info "${test} starting..."
+
+exec_workdir || ((ans++))
+
+msg_info "${test} finished with return ${ret}..."
+
+show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,36 +0,0 @@
From a24118b4382492e27415f25411fcaadef990b659 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Mon, 15 Mar 2021 09:49:10 -0400
Subject: [PATCH 055/104] ignore to create mtab when runtime is kata-runtime
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
src/daemon/modules/service/service_container.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index e1d698cd..d6a82587 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -60,6 +60,8 @@
#include "utils_verify.h"
#include "volume_api.h"
+#define KATA_RUNTIME "kata-runtime"
+
int set_container_to_removal(const container_t *cont)
{
int ret = 0;
@@ -732,7 +734,8 @@ static int do_start_container(container_t *cont, const char *console_fifos[], bo
}
// embedded conainter is readonly, create mtab link will fail
- if (strcmp(IMAGE_TYPE_EMBEDDED, cont->common_config->image_type) != 0) {
+ // kata-runtime container's qemu donot support to create mtab in host
+ if (strcmp(IMAGE_TYPE_EMBEDDED, cont->common_config->image_type) != 0 && strcmp(KATA_RUNTIME, cont->runtime) != 0) {
nret = create_mtab_link(oci_spec);
if (nret != 0) {
ERROR("Failed to create link /etc/mtab for target /proc/mounts");
--
2.25.1

View File

@ -1,91 +0,0 @@
From 64b45885abf0c4b3563008d2be5d04b5ec8cd28d Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 18 Mar 2021 11:05:33 +0800
Subject: [PATCH 056/104] remove unchecked layer ignore rootfs layer
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
.../modules/image/oci/storage/storage.c | 42 ++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c
index 0e9708f5..40fc15a8 100644
--- a/src/daemon/modules/image/oci/storage/storage.c
+++ b/src/daemon/modules/image/oci/storage/storage.c
@@ -1480,6 +1480,26 @@ out:
return ret;
}
+static bool is_rootfs_layer(const char *layer_id, const struct rootfs_list *all_rootfs)
+{
+ int j;
+
+ if (all_rootfs == NULL || layer_id == NULL) {
+ return false;
+ }
+
+ for (j = 0; j < all_rootfs->rootfs_len; j++) {
+ if (all_rootfs->rootfs[j]->layer == NULL) {
+ continue;
+ }
+ if (strcmp(layer_id, all_rootfs->rootfs[j]->layer) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
static bool do_storage_integration_check(const char *path, map_t *checked_layers)
{
struct rootfs_list *all_rootfs = NULL;
@@ -1558,6 +1578,7 @@ static void delete_unchecked_layers(map_t *checked_layers)
{
struct layer_list *all_layers = NULL;
size_t i;
+ struct rootfs_list *all_rootfs = NULL;
all_layers = util_common_calloc_s(sizeof(struct layer_list));
if (all_layers == NULL) {
@@ -1570,11 +1591,29 @@ static void delete_unchecked_layers(map_t *checked_layers)
goto out;
}
+ all_rootfs = util_common_calloc_s(sizeof(struct rootfs_list));
+ if (all_rootfs == NULL) {
+ ERROR("Out of memory");
+ goto out;
+ }
+
+ if (rootfs_store_get_all_rootfs(all_rootfs) != 0) {
+ ERROR("Failed to get all container rootfs information");
+ goto out;
+ }
+
for (i = 0; i < all_layers->layers_len; i++) {
if (map_search(checked_layers, (void *)all_layers->layers[i]->id) != NULL) {
+ DEBUG("ignore checked layer: %s", all_layers->layers[i]->id);
+ continue;
+ }
+
+ if (is_rootfs_layer(all_layers->layers[i]->id, all_rootfs)) {
+ DEBUG("ignore rootfs layer: %s", all_layers->layers[i]->id);
continue;
}
- WARN("Delete unchecked layer: %s due to no related image", all_layers->layers[i]->id);
+
+ ERROR("Delete unchecked layer: %s due to no related image", all_layers->layers[i]->id);
if (layer_store_delete(all_layers->layers[i]->id) != 0) {
ERROR("Failed to delete unchecked layer %s", all_layers->layers[i]->id);
}
@@ -1582,6 +1621,7 @@ static void delete_unchecked_layers(map_t *checked_layers)
out:
free_layer_list(all_layers);
+ free_rootfs_list(all_rootfs);
}
static bool storage_integration_check()
--
2.25.1

View File

@ -1,38 +0,0 @@
From 19b3a0bfd08433d39a1115f2ad9ef3eaac006514 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 18 Mar 2021 11:25:57 +0800
Subject: [PATCH 057/104] add test to check running container with image
integration check
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
CI/test_cases/image_cases/integration_check.sh | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/CI/test_cases/image_cases/integration_check.sh b/CI/test_cases/image_cases/integration_check.sh
index 2e6f962e..fe342cc2 100755
--- a/CI/test_cases/image_cases/integration_check.sh
+++ b/CI/test_cases/image_cases/integration_check.sh
@@ -58,6 +58,9 @@ function test_image_info()
ucid=$(isula create ${uimage})
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - create container failed" && ((ret++))
+ isula run -tid --name checker alpine
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container failed" && ((ret++))
+
tmp_fname=$(echo -n "/var/run/isulad/storage" | sha256sum | awk '{print $1}')
rm -f "${ISULAD_RUN_ROOT_PATH}/storage/${tmp_fname}.json"
@@ -74,6 +77,9 @@ function test_image_info()
isula ps -a | grep ${ucid}
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - container: ${ucid} do not exist with valid image" && ((ret++))
+ isula exec -it checker date
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - container: checker exec failed with valid image" && ((ret++))
+
isula images | grep busybox
[[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid image: ${image} exist" && ((ret++))
--
2.25.1

View File

@ -1,34 +0,0 @@
From c720232af726a79d6c5527d8ca96f0acd9772730 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Thu, 25 Mar 2021 16:44:45 +0800
Subject: [PATCH 058/104] fix coredump when inspect container when daemon sets
the ulimit parameters
Signed-off-by: wujing <wujing50@huawei.com>
---
src/daemon/modules/service/inspect_container.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/daemon/modules/service/inspect_container.c b/src/daemon/modules/service/inspect_container.c
index abfb8517..d678f7bb 100644
--- a/src/daemon/modules/service/inspect_container.c
+++ b/src/daemon/modules/service/inspect_container.c
@@ -517,7 +517,7 @@ static container_inspect *pack_inspect_data(const container_t *cont, bool with_h
ERROR("Failed to pack inspect host config data, continue to pack other information");
}
- if (merge_default_ulimit_with_ulimit(inspect) != 0) {
+ if (with_host_config && merge_default_ulimit_with_ulimit(inspect) != 0) {
ERROR("Failed to pack default ulimit data, continue to pack other information");
}
@@ -622,4 +622,4 @@ out:
inspect = NULL;
}
return inspect;
-}
\ No newline at end of file
+}
--
2.25.1

View File

@ -1,33 +0,0 @@
From 19b67eeb87d8c8ef2add632c6f9c3041272b67c2 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Sat, 27 Mar 2021 10:00:03 +0800
Subject: [PATCH 059/104] Readme: add related resouces in readme
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
README.md | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1dd3cf1a..68f35f34 100644
--- a/README.md
+++ b/README.md
@@ -249,7 +249,13 @@ You can get more information about iSulad from our wikis, including roadmap, fea
iSulad is licensed under the Mulan PSL v2.
+## Related Resouces
+
+- [bilibili videos](https://space.bilibili.com/527064077/video?keyword=iSulad)
+- [如何在openEuler树莓派镜像上部署k8s+iSula集群](https://my.oschina.net/openeuler/blog/4774838)
+- [基于openEuler搭建部署k8s](https://bbs.huaweicloud.com/forum/forum.php?mod=viewthread&tid=94271)
+
## Join us
You can join us on any of the following channels:
* Join our [mailing list](https://mailweb.openeuler.org/postorius/lists/isulad.openeuler.org/)
-* Join our Biweekly meeting at 16:30 pm on Tuesday (meeting link will be mailed at mailing list)
+* Join our Biweekly meeting at 16:30 pm on Tuesday (meeting link will be mailed at mailing list)
\ No newline at end of file
--
2.25.1

View File

@ -1,25 +0,0 @@
From 2d47bb3796bf3ff6b2cd66416fd1ae43a248b75f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=AE=B8=E6=8C=AF=E6=B6=9B?= <970391472@qq.com>
Date: Tue, 30 Mar 2021 15:34:43 +0800
Subject: [PATCH 060/104] update docs/build_guide_zh.md.
---
docs/build_guide_zh.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/build_guide_zh.md b/docs/build_guide_zh.md
index 748701a3..d6621fcf 100644
--- a/docs/build_guide_zh.md
+++ b/docs/build_guide_zh.md
@@ -24,7 +24,7 @@ $ sudo yum --enablerepo='*' install -y automake autoconf libtool cmake make libc
### Ubuntu的安装命令
```bash
-$ sudo apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux-dev libseccomp-dev libcap-dev libsystemd-dev git libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar libtar-dev
+$ sudo apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux-dev libseccomp-dev libcap-dev libsystemd-dev git libarchive libarchive-dev libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar libtar-dev
```
## 从源码构建和安装关键依赖
--
2.25.1

View File

@ -1,88 +0,0 @@
From 66c2bfda515a3e176cc9e65e3ef393acf1eb1502 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 1 Apr 2021 10:37:00 +0800
Subject: [PATCH 061/104] fix health_check.sh execute failure
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/container_cases/health_check.sh | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/CI/test_cases/container_cases/health_check.sh b/CI/test_cases/container_cases/health_check.sh
index cc934fd8..c466b6f2 100755
--- a/CI/test_cases/container_cases/health_check.sh
+++ b/CI/test_cases/container_cases/health_check.sh
@@ -38,20 +38,20 @@ function test_health_check_paraments()
container_name="health_check_para"
isula run -itd -n ${container_name} --health-cmd 'echo "iSulad" ; exit 1' \
- --health-interval 2s --health-retries 2 --health-start-period 2s --health-exit-on-unhealthy ${image} /bin/sh
+ --health-interval 5s --health-retries 2 --health-start-period 8s --health-exit-on-unhealthy ${image} /bin/sh
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
# start period : 2s => do health check => interval: 2s => do health check => exit on unhealthy
[[ $(isula inspect -f '{{.State.Status}}' ${container_name}) == "running" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container status: not running" && ((ret++))
- sleep 3 # finish first health check
+ sleep 13 # finish first health check
# keep starting status with health check return non-zero at always until status change to unhealthy
[[ $(isula inspect -f '{{.State.Health.Status}}' ${container_name}) == "starting" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container health check status: not starting" && ((ret++))
- sleep 2 # finish second health check
+ sleep 6 # finish second health check
[[ $(isula inspect -f '{{.State.Health.Status}}' ${container_name}) == "unhealthy" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container health check status: not unhealthy" && ((ret++))
@@ -85,20 +85,20 @@ function test_health_check_normally()
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
container_name="health_check_normally"
- isula run -itd -n ${container_name} --health-cmd 'date' --health-interval 2s ${image} /bin/sh
+ isula run -itd -n ${container_name} --health-cmd 'date' --health-interval 5s ${image} /bin/sh
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
# start period : 0s => interval: 2s => do health check => interval: 2s => do health check => ...
[[ $(isula inspect -f '{{.State.Status}}' ${container_name}) == "running" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container status: not running" && ((ret++))
- sleep 1 # Health check has been performed yet
+ sleep 2 # Health check has been performed yet
# Initial status when the container is still starting
[[ $(isula inspect -f '{{.State.Health.Status}}' ${container_name}) == "starting" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container health check status: not starting" && ((ret++))
- sleep 2 # finish first health check
+ sleep 8 # finish first health check
# When the health check returns successfully, status immediately becomes healthy
[[ $(isula inspect -f '{{.State.Health.Status}}' ${container_name}) == "healthy" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container health check status: not healthy" && ((ret++))
@@ -131,11 +131,11 @@ function test_health_check_timeout()
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
container_name="health_check_timeout"
- isula run -itd -n ${container_name} --health-cmd 'sleep 5' --health-interval 2s --health-timeout 1s \
+ isula run -itd -n ${container_name} --health-cmd 'sleep 5' --health-interval 5s --health-timeout 1s \
--health-retries 1 --health-exit-on-unhealthy ${image} /bin/sh
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
- # start period : 0s => interval: 2s => do health check(1s timeout) => unhealthy(exited)
+ # start period : 0s => interval: 5s => do health check(1s timeout) => unhealthy(exited)
[[ $(isula inspect -f '{{.State.Status}}' ${container_name}) == "running" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container status: not running" && ((ret++))
@@ -145,7 +145,7 @@ function test_health_check_timeout()
[[ $(isula inspect -f '{{.State.Health.Status}}' ${container_name}) == "starting" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container health check status: not starting" && ((ret++))
- sleep 3 # finish first health check
+ sleep 7 # finish first health check
# The container process exits and the health check status becomes unhealthy
[[ $(isula inspect -f '{{.State.Health.Status}}' ${container_name}) == "unhealthy" ]]
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - incorrent container health check status: not unhealthy" && ((ret++))
--
2.25.1

View File

@ -1,488 +0,0 @@
From c00ee6acf534371c65455424d3e40d9394e96ec2 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Mon, 25 Jan 2021 10:14:56 +0800
Subject: [PATCH 062/104] support cgroup v2
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/cmd/isula/extend/update.c | 4 +
src/cmd/isulad/main.c | 2 +
src/daemon/common/sysinfo.c | 312 ++++++++++++++++--
.../executor/container_cb/execution_create.c | 2 -
src/daemon/modules/spec/verify.c | 16 +-
5 files changed, 308 insertions(+), 28 deletions(-)
diff --git a/src/cmd/isula/extend/update.c b/src/cmd/isula/extend/update.c
index 42cb8f21..a9b0fccf 100644
--- a/src/cmd/isula/extend/update.c
+++ b/src/cmd/isula/extend/update.c
@@ -75,6 +75,10 @@ static isula_host_config_t *pack_update_request(const struct client_arguments *a
host_config->cr->kernel_memory = args->cr.kernel_memory_limit;
+ // make sure swappiness have default value -1 if not configed, so it
+ // will not fail even if kernel does not support swappiness.
+ host_config->cr->swappiness = args->cr.swappiness;
+
return host_config;
error_out:
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index cb2b71a2..47bd6e2c 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -1483,6 +1483,8 @@ int main(int argc, char **argv)
update_isulad_rlimits();
+ (void)get_sys_info(true);
+
clock_gettime(CLOCK_MONOTONIC, &t_start);
if (pre_init_daemon(argc, argv, &msg) != 0) {
diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c
index 87ea47f4..bdd0dbad 100644
--- a/src/daemon/common/sysinfo.c
+++ b/src/daemon/common/sysinfo.c
@@ -20,6 +20,9 @@
#include <dirent.h>
#include <errno.h>
#include <sys/sysinfo.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
+#include <sys/stat.h>
#include "err_msg.h"
#include "isula_libutils/log.h"
@@ -28,7 +31,7 @@
#include "utils_file.h"
#include "utils_string.h"
-// Cgroup Item Definition
+// Cgroup V1 Item Definition
#define CGROUP_BLKIO_WEIGHT "blkio.weight"
#define CGROUP_BLKIO_WEIGHT_DEVICE "blkio.weight_device"
#define CGROUP_BLKIO_READ_BPS_DEVICE "blkio.throttle.read_bps_device"
@@ -49,6 +52,45 @@
#define CGROUP_KENEL_MEMORY_LIMIT "memory.kmem.limit_in_bytes"
#define CGROUP_MEMORY_OOM_CONTROL "memory.oom_control"
+// Cgroup V2 Item Definition
+#define CGROUP2_CPU_WEIGHT "cpu.weight"
+#define CGROUP2_CPU_MAX "cpu.max"
+#define CGROUP2_CPUSET_CPUS_EFFECTIVE "cpuset.cpus.effective"
+#define CGROUP2_CPUSET_MEMS_EFFECTIVE "cpuset.mems.effective"
+#define CGROUP2_CPUSET_CPUS "cpuset.cpus"
+#define CGROUP2_CPUSET_MEMS "cpuset.mems"
+#define CGROUP2_IO_WEIGHT "io.weight"
+#define CGROUP2_IO_BFQ_WEIGHT "io.bfq.weight"
+#define CGROUP2_IO_MAX "io.max"
+#define CGROUP2_MEMORY_MAX "memory.max"
+#define CGROUP2_MEMORY_LOW "memory.low"
+#define CGROUP2_MEMORY_SWAP_MAX "memory.swap.max"
+#define CGROUP2_HUGETLB_MAX "hugetlb.%s.max"
+#define CGROUP2_PIDS_MAX "pids.max"
+#define CGROUP2_FILES_LIMIT "files.limit"
+
+#define CGROUP_MOUNTPOINT "/sys/fs/cgroup"
+#define CGROUP_ISULAD_PATH CGROUP_MOUNTPOINT"/isulad"
+#define DEFAULT_CGROUP_DIR_MODE 0755
+#define DEFAULT_CGROUP_FILE_MODE 0644
+#define CGROUP2_CONTROLLERS_PATH CGROUP_MOUNTPOINT"/cgroup.controllers"
+#define CGROUP2_SUBTREE_CONTROLLER_PATH CGROUP_MOUNTPOINT"/cgroup.subtree_control"
+#define CGROUP2_CPUSET_CPUS_EFFECTIVE_PATH CGROUP_MOUNTPOINT"/cpuset.cpus.effective"
+#define CGROUP2_CPUSET_MEMS_EFFECTIVE_PATH CGROUP_MOUNTPOINT"/cpuset.mems.effective"
+
+#ifndef CGROUP2_SUPER_MAGIC
+#define CGROUP2_SUPER_MAGIC 0x63677270
+#endif
+
+#ifndef CGROUP_SUPER_MAGIC
+#define CGROUP_SUPER_MAGIC 0x27e0eb
+#endif
+
+#define CGROUP_VERSION_1 1
+#define CGROUP_VERSION_2 2
+
+static sysinfo_t *g_sysinfo = NULL;
+
struct layer {
char **controllers;
char *mountpoint;
@@ -966,6 +1008,27 @@ free_out:
free(defaultpagesize);
}
+static int get_cgroup_version()
+{
+ struct statfs fs = {0};
+
+ if (statfs(CGROUP_MOUNTPOINT, &fs) != 0) {
+ ERROR("failed to statfs %s: %s", CGROUP_MOUNTPOINT, strerror(errno));
+ return -1;
+ }
+
+ if (fs.f_type == CGROUP2_SUPER_MAGIC) {
+ return CGROUP_VERSION_2;
+ } else {
+ return CGROUP_VERSION_1;
+ }
+}
+
+static bool is_hugetlb_max(const char *name)
+{
+ return util_has_prefix(name, "hugetlb.") && util_has_suffix(name, ".max");
+}
+
/* get huge page sizes */
static char **get_huge_page_sizes()
{
@@ -975,11 +1038,17 @@ static char **get_huge_page_sizes()
char **hps = NULL;
DIR *dir = NULL;
struct dirent *info_archivo = NULL;
+ int cgroup_version = 0;
- ret = find_cgroup_mountpoint_and_root("hugetlb", &hugetlbmp, NULL);
- if (ret != 0 || hugetlbmp == NULL) {
- ERROR("Hugetlb cgroup not supported");
- return NULL;
+ cgroup_version = get_cgroup_version();
+ if (cgroup_version == CGROUP_VERSION_2) {
+ hugetlbmp = util_strdup_s(CGROUP_ISULAD_PATH);
+ } else {
+ ret = find_cgroup_mountpoint_and_root("hugetlb", &hugetlbmp, NULL);
+ if (ret != 0 || hugetlbmp == NULL) {
+ ERROR("Hugetlb cgroup not supported");
+ return NULL;
+ }
}
dir = opendir(hugetlbmp);
@@ -994,9 +1063,15 @@ static char **get_huge_page_sizes()
char *pos = NULL;
char *dot2 = NULL;
- contain = strstr(info_archivo->d_name, "limit_in_bytes");
- if (contain == NULL) {
- continue;
+ if (cgroup_version == CGROUP_VERSION_2) {
+ if (!is_hugetlb_max(info_archivo->d_name)) {
+ continue;
+ }
+ } else {
+ contain = strstr(info_archivo->d_name, "limit_in_bytes");
+ if (contain == NULL) {
+ continue;
+ }
}
dup = util_strdup_s(info_archivo->d_name);
@@ -1151,28 +1226,16 @@ void free_sysinfo(sysinfo_t *sysinfo)
free(sysinfo);
}
-/* get sys info */
-sysinfo_t *get_sys_info(bool quiet)
+static int get_cgroup_info_v1(sysinfo_t *sysinfo, bool quiet)
{
struct layer **layers = NULL;
- sysinfo_t *sysinfo = NULL;
- bool ret = true;
-
- sysinfo = util_common_calloc_s(sizeof(sysinfo_t));
- if (sysinfo == NULL) {
- ERROR("Out of memory");
- return NULL;
- }
layers = cgroup_layers_find();
if (layers == NULL) {
ERROR("Failed to parse cgroup information");
- ret = false;
- goto out;
+ return -1;
}
- sysinfo->ncpus = get_nprocs();
-
check_cgroup_mem(layers, quiet, &sysinfo->cgmeminfo);
check_cgroup_cpu(layers, quiet, &sysinfo->cgcpuinfo);
check_cgroup_hugetlb(layers, quiet, &sysinfo->hugetlbinfo);
@@ -1180,9 +1243,210 @@ sysinfo_t *get_sys_info(bool quiet)
check_cgroup_cpuset_info(layers, quiet, &sysinfo->cpusetinfo);
check_cgroup_pids(quiet, &sysinfo->pidsinfo);
check_cgroup_files(quiet, &sysinfo->filesinfo);
-out:
+
free_layer(layers);
- if (!ret) {
+
+ return 0;
+}
+
+static int cgroup2_enable_all()
+{
+ int ret = 0;
+ int nret = 0;
+ int n = 0;
+ size_t i = 0;
+ const char *space = "";
+ char *controllers_str = NULL;
+ char *subtree_controller_str = NULL;
+ char **controllers = NULL;
+ char enable_controllers[PATH_MAX] = {0};
+
+ controllers_str = util_read_content_from_file(CGROUP2_CONTROLLERS_PATH);
+ if (controllers_str == NULL || strlen(controllers_str) == 0 ||
+ strcmp(controllers_str, "\n") == 0) {
+ ERROR("read cgroup controllers failed");
+ ret = -1;
+ goto out;
+ }
+
+ subtree_controller_str = util_read_content_from_file(CGROUP2_SUBTREE_CONTROLLER_PATH);
+ if (subtree_controller_str != NULL && strcmp(controllers_str, subtree_controller_str) == 0) {
+ goto out;
+ }
+
+ controllers = util_string_split(controllers_str, ' ');
+ if (controllers == NULL) {
+ ERROR("split %s failed", controllers_str);
+ ret = -1;
+ goto out;
+ }
+
+ for (i = 0; i < util_array_len((const char **)controllers); i++) {
+ nret = snprintf(enable_controllers + n, PATH_MAX - n, "%s+%s", space, controllers[i]);
+ if (nret < 0 || (size_t)nret >= PATH_MAX - n) {
+ ERROR("Path is too long");
+ goto out;
+ }
+ n += nret;
+ space = " ";
+ }
+ ret = util_write_file(CGROUP2_SUBTREE_CONTROLLER_PATH, enable_controllers, strlen(enable_controllers),
+ DEFAULT_CGROUP_FILE_MODE);
+ if (ret != 0) {
+ ERROR("write %s to %s failed: %s", enable_controllers, CGROUP2_SUBTREE_CONTROLLER_PATH, strerror(errno));
+ goto out;
+ }
+
+out:
+ util_free_array(controllers);
+ free(controllers_str);
+ free(subtree_controller_str);
+
+ return ret;
+}
+
+static int make_sure_cgroup2_isulad_path_exist()
+{
+ int ret = 0;
+
+ if (util_dir_exists(CGROUP_ISULAD_PATH)) {
+ return 0;
+ }
+
+ if (cgroup2_enable_all() != 0) {
+ return -1;
+ }
+
+ ret = mkdir(CGROUP_ISULAD_PATH, DEFAULT_CGROUP_DIR_MODE);
+ if (ret != 0 && (errno != EEXIST || !util_dir_exists(CGROUP_ISULAD_PATH))) {
+ return -1;
+ }
+
+ return ret;
+}
+
+static int get_cgroup_info_v2(sysinfo_t *sysinfo, bool quiet)
+{
+ int ret = 0;
+ int nret = 0;
+ char *size = NULL;
+ char path[PATH_MAX] = {0};
+
+ if (make_sure_cgroup2_isulad_path_exist() != 0) {
+ return -1;
+ }
+
+ // cpu cgroup
+ sysinfo->cgcpuinfo.cpu_shares = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_CPU_WEIGHT);
+ cgroup_do_log(quiet, !(sysinfo->cgcpuinfo.cpu_shares), "Your kernel does not support cgroup2 cpu weight");
+
+ sysinfo->cgcpuinfo.cpu_cfs_period = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_CPU_MAX);
+ sysinfo->cgcpuinfo.cpu_cfs_quota = sysinfo->cgcpuinfo.cpu_cfs_period;
+ cgroup_do_log(quiet, !(sysinfo->cgcpuinfo.cpu_cfs_period), "Your kernel does not support cgroup2 cpu max");
+
+ sysinfo->cpusetinfo.cpuset = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_CPUSET_CPUS_EFFECTIVE) &&
+ cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_CPUSET_CPUS) &&
+ cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_CPUSET_MEMS_EFFECTIVE) &&
+ cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_CPUSET_MEMS);
+ cgroup_do_log(quiet, !(sysinfo->cpusetinfo.cpuset), "Your kernel does not support cpuset");
+ if (sysinfo->cpusetinfo.cpuset) {
+ sysinfo->cpusetinfo.cpus = util_read_content_from_file(CGROUP2_CPUSET_CPUS_EFFECTIVE_PATH);
+ sysinfo->cpusetinfo.mems = util_read_content_from_file(CGROUP2_CPUSET_MEMS_EFFECTIVE_PATH);
+ if (sysinfo->cpusetinfo.cpus == NULL || sysinfo->cpusetinfo.mems == NULL) {
+ ERROR("read cpus or mems failed");
+ return -1;
+ }
+ sysinfo->cpusetinfo.cpus = util_trim_space(sysinfo->cpusetinfo.cpus);
+ sysinfo->cpusetinfo.mems = util_trim_space(sysinfo->cpusetinfo.mems);
+ }
+
+ // io cgroup
+ sysinfo->blkioinfo.blkio_weight = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_IO_BFQ_WEIGHT) ||
+ cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_IO_WEIGHT);
+ sysinfo->blkioinfo.blkio_weight_device = sysinfo->blkioinfo.blkio_weight;
+ cgroup_do_log(quiet, !(sysinfo->blkioinfo.blkio_weight), "Your kernel does not support cgroup2 io weight");
+
+ sysinfo->blkioinfo.blkio_read_bps_device = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_IO_MAX);
+ sysinfo->blkioinfo.blkio_write_bps_device = sysinfo->blkioinfo.blkio_read_bps_device;
+ sysinfo->blkioinfo.blkio_read_iops_device = sysinfo->blkioinfo.blkio_read_bps_device;
+ sysinfo->blkioinfo.blkio_write_iops_device = sysinfo->blkioinfo.blkio_read_bps_device;
+ cgroup_do_log(quiet, !(sysinfo->blkioinfo.blkio_read_bps_device), "Your kernel does not support cgroup2 io max");
+
+ // memory cgroup
+ sysinfo->cgmeminfo.limit = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_MEMORY_MAX);
+ cgroup_do_log(quiet, !(sysinfo->cgmeminfo.limit), "Your kernel does not support cgroup2 memory max");
+
+ sysinfo->cgmeminfo.reservation = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_MEMORY_LOW);
+ cgroup_do_log(quiet, !(sysinfo->cgmeminfo.reservation), "Your kernel does not support cgroup2 memory low");
+
+ sysinfo->cgmeminfo.swap = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_MEMORY_SWAP_MAX);
+ cgroup_do_log(quiet, !(sysinfo->cgmeminfo.swap), "Your kernel does not support cgroup2 memory swap max");
+
+ // pids cgroup
+ sysinfo->pidsinfo.pidslimit = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_PIDS_MAX);
+ cgroup_do_log(quiet, !(sysinfo->pidsinfo.pidslimit), "Your kernel does not support cgroup2 pids max");
+
+ // hugetlb cgroup
+ size = get_default_huge_page_size();
+ if (size != NULL) {
+ nret = snprintf(path, sizeof(path), CGROUP2_HUGETLB_MAX, size);
+ if (nret < 0 || (size_t)nret >= sizeof(path)) {
+ WARN("Failed to print hugetlb path");
+ ret = -1;
+ goto out;
+ }
+ sysinfo->hugetlbinfo.hugetlblimit = cgroup_enabled(CGROUP_ISULAD_PATH, path);
+ cgroup_do_log(quiet, !sysinfo->hugetlbinfo.hugetlblimit, "Your kernel does not support cgroup2 hugetlb limit");
+ } else {
+ WARN("Your kernel does not support cgroup2 hugetlb limit");
+ }
+
+ // files cgroup
+ sysinfo->filesinfo.fileslimit = cgroup_enabled(CGROUP_ISULAD_PATH, CGROUP2_FILES_LIMIT);
+ cgroup_do_log(quiet, !(sysinfo->filesinfo.fileslimit), "Your kernel does not support cgroup2 files limit");
+
+out:
+ free(size);
+
+ return ret;
+}
+
+/* get sys info */
+sysinfo_t *get_sys_info(bool quiet)
+{
+ int cgroup_version = 0;
+ sysinfo_t *sysinfo = NULL;
+ int ret = 0;
+
+ if (g_sysinfo != NULL) {
+ return g_sysinfo;
+ }
+
+ sysinfo = util_common_calloc_s(sizeof(sysinfo_t));
+ if (sysinfo == NULL) {
+ ERROR("Out of memory");
+ return NULL;
+ }
+
+ sysinfo->ncpus = get_nprocs();
+
+ cgroup_version = get_cgroup_version();
+ if (cgroup_version < 0) {
+ ret = -1;
+ goto out;
+ }
+
+ if (cgroup_version == CGROUP_VERSION_1) {
+ ret = get_cgroup_info_v1(sysinfo, quiet);
+ } else {
+ ret = get_cgroup_info_v2(sysinfo, quiet);
+ }
+ if (ret != 0) {
+ goto out;
+ }
+ g_sysinfo = sysinfo;
+out:
+ if (ret != 0) {
free_sysinfo(sysinfo);
sysinfo = NULL;
}
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index acad7fe3..9136348e 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -908,7 +908,6 @@ static int adapt_host_spec(host_config *host_spec)
}
out:
- free_sysinfo(sysinfo);
return ret;
}
@@ -1292,7 +1291,6 @@ static int cpurt_controller_init(const char *cgroups_path)
ret = do_init_cpurt_cgroups_path(dirpath, 0, mnt_root, cpu_rt_period, cpu_rt_runtime);
out:
- free_sysinfo(sysinfo);
free(mnt_root);
free(dup);
return ret;
diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c
index cef95065..2a73f7c1 100644
--- a/src/daemon/modules/spec/verify.c
+++ b/src/daemon/modules/spec/verify.c
@@ -425,6 +425,20 @@ static int verify_cpu_cfs_period(const sysinfo_t *sysinfo, int64_t cpu_cfs_perio
ret = -1;
goto out;
}
+
+ if (cpu_cfs_period > 0 && cpu_cfs_period < 1000) {
+ ERROR("CPU cfs period can not be less than 1ms (i.e. 1000)");
+ isulad_set_error_message("CPU cfs period can not be less than 1ms (i.e. 1000)");
+ ret = -1;
+ goto out;
+ }
+
+ if (cpu_cfs_period > 1000000) {
+ ERROR("CPU cfs period can not be more than 1s (i.e. 1000000)");
+ isulad_set_error_message("CPU cfs period can not be more than 1s (i.e. 1000000)");
+ ret = -1;
+ goto out;
+ }
out:
return ret;
}
@@ -1600,7 +1614,6 @@ int verify_container_settings(const oci_runtime_spec *container)
}
out:
- free_sysinfo(sysinfo);
return ret;
}
@@ -1980,7 +1993,6 @@ static int host_config_settings_with_sysinfo(host_config *hostconfig, bool updat
}
out:
- free_sysinfo(sysinfo);
return ret;
}
--
2.25.1

View File

@ -1,785 +0,0 @@
From 4822231b594762cf3301518ef0bff0396584b493 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Mon, 8 Feb 2021 14:32:46 +0800
Subject: [PATCH 063/104] add testcases for cgroup v2
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/manual_cases/cgroupv2.sh | 765 +++++++++++++++++++++++++
1 file changed, 765 insertions(+)
create mode 100755 CI/test_cases/manual_cases/cgroupv2.sh
diff --git a/CI/test_cases/manual_cases/cgroupv2.sh b/CI/test_cases/manual_cases/cgroupv2.sh
new file mode 100755
index 00000000..bd1dc482
--- /dev/null
+++ b/CI/test_cases/manual_cases/cgroupv2.sh
@@ -0,0 +1,765 @@
+#!/bin/bash
+#
+# attributes: isulad cgroupv2
+# concurrent: YES
+# spend time: 15
+
+#######################################################################
+##- @Copyright (C) Huawei Technologies., 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.
+##- @Description:CI
+##- @Author: wangfengtu
+##- @Create: 2021-01-26
+#######################################################################
+
+declare -r curr_path=$(dirname $(readlink -f "$0"))
+source ../helpers.sh
+test="cgroupv2 test => test_cgroupv2"
+cgroupv2=0
+cgroup2_update="cgroup2_update"
+
+function test_cgroup2_cpu()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/cpu.weight ]];then
+ # min value
+ isula run -ti --rm --cpu-shares 2 busybox cat /sys/fs/cgroup/cpu.weight | grep ^1$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.weight min value failed" && ((ret++))
+
+ # max value
+ isula run -ti --rm --cpu-shares 262144 busybox cat /sys/fs/cgroup/cpu.weight | grep ^10000$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.weight max value failed" && ((ret++))
+
+ # invalid value
+ isula run -ti --rm --cpu-shares -1 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.weight -1 failed" && ((ret++))
+
+ # default value
+ isula run -ti --rm --cpu-shares 0 busybox cat /sys/fs/cgroup/cpu.weight | grep ^100$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.weight default value failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/cpu.max ]];then
+ # normal value
+ isula run -ti --rm --cpu-quota 50000 --cpu-period 12345 busybox cat /sys/fs/cgroup/cpu.max | grep ^"50000 12345"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max normal value failed" && ((ret++))
+
+ # invalid min period
+ isula run -ti --rm --cpu-quota 50000 --cpu-period 999 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max invalid min period failed" && ((ret++))
+
+ # invalid max period
+ isula run -ti --rm --cpu-quota 50000 --cpu-period 1000001 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max invalid max period failed" && ((ret++))
+
+ # invalid quota
+ isula run -ti --rm --cpu-quota 999 --cpu-period 1000000 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max invalid quota failed" && ((ret++))
+
+ # default 0 quota
+ isula run -ti --rm --cpu-quota 0 --cpu-period 1000000 busybox cat /sys/fs/cgroup/cpu.max | grep ^"max 1000000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max default 0 quota failed" && ((ret++))
+
+ # default -1 quota
+ isula run -ti --rm --cpu-quota -1 --cpu-period 1000000 busybox cat /sys/fs/cgroup/cpu.max | grep ^"max 1000000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max default -1 quota failed" && ((ret++))
+
+ # cpus 1
+ isula run -ti --rm --cpus 1 busybox cat /sys/fs/cgroup/cpu.max | grep ^"100000 100000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max cpus 1 failed" && ((ret++))
+
+ # cpus 0
+ isula run -ti --rm --cpus 0 busybox cat /sys/fs/cgroup/cpu.max | grep ^"max 100000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpu.max cpus 0 failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/cpuset.cpus.effective ]];then
+ # normal value
+ isula run -tid -n cpuset --cpuset-cpus 0 --cpuset-mems 0 busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset run container failed" && ((ret++))
+
+ isula exec -ti cpuset cat /sys/fs/cgroup/cpuset.cpus | grep ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset value not right" && ((ret++))
+
+ isula exec -ti cpuset cat /sys/fs/cgroup/cpuset.mems | grep ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset value not right" && ((ret++))
+
+ isula rm -f cpuset
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset remove container failed" && ((ret++))
+
+ # invalid cpus -1 value
+ isula run -tid -n cpuset --cpuset-cpus -1 busybox sh
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset cpus invalid -1 failed" && ((ret++))
+
+ # invalid cpus 100000 value
+ isula run -tid -n cpuset --cpuset-cpus 100000 busybox sh
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset cpus invalid 100000 failed" && ((ret++))
+
+ # invalid mems -1 value
+ isula run -tid -n cpuset --cpuset-mems -1 busybox sh
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset mems invalid -1 failed" && ((ret++))
+
+ # invalid mems 100000 value
+ isula run -tid -n cpuset --cpuset-mems 100000 busybox sh
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 cpuset mems invalid 100000 failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_io()
+{
+ local ret=0
+
+ if [[ -f "/sys/fs/cgroup/isulad/io.bfq.weight" ]];then
+ # min value
+ isula run -ti --rm --blkio-weight 10 busybox cat "/sys/fs/cgroup/io.bfq.weight" | grep 1$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight min value failed" && ((ret++))
+
+ # max value
+ isula run -ti --rm --blkio-weight 1000 busybox cat "/sys/fs/cgroup/io.bfq.weight" | grep 1000$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight max value failed" && ((ret++))
+
+ # default value
+ isula run -ti --rm --blkio-weight 0 busybox cat "/sys/fs/cgroup/io.bfq.weight" | grep 100$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight default value failed" && ((ret++))
+
+ # invalid value
+ isula run -ti --rm --blkio-weight -1 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight -1 failed" && ((ret++))
+ fi
+
+ if [[ -f "/sys/fs/cgroup/isulad/io.bfq.weight_device" ]];then
+ # min value
+ isula run -ti --rm --blkio-weight-device /dev/null:10 busybox cat "/sys/fs/cgroup/io.bfq.weight_device" | grep ^"1:3 10"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight_device max value failed" && ((ret++))
+
+ # max value
+ isula run -ti --rm --blkio-weight-device /dev/null:1000 busybox cat "/sys/fs/cgroup/io.bfq.weight_device" | grep ^"1:3 10000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight_device max value failed" && ((ret++))
+
+ # disable weight device
+ isula run -tid -n weight_device --rm --blkio-weight-device /dev/null:0 busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight_device failed" && ((ret++))
+
+ isula exec -ti weight_device cat "/sys/fs/cgroup/io.bfq.weight_device" | grep "1:3"
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight_device disable failed" && ((ret++))
+
+ isula rm -f weight_device
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.bfq.weight_device remove container failed" && ((ret++))
+ fi
+
+ if [[ -f "/sys/fs/cgroup/isulad/io.weight" ]];then
+ # min value
+ isula run -ti --rm --blkio-weight 10 busybox cat "/sys/fs/cgroup/io.weight" | grep ^"default 1"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight min value failed" && ((ret++))
+
+ # max value
+ isula run -ti --rm --blkio-weight 1000 busybox cat "/sys/fs/cgroup/io.weight" | grep ^"default 10000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight max value failed" && ((ret++))
+
+ # default value
+ isula run -ti --rm --blkio-weight 0 busybox cat "/sys/fs/cgroup/io.weight" | grep ^"default 100"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight default value failed" && ((ret++))
+
+ # invalid value
+ isula run -ti --rm --blkio-weight -1 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight -1 failed" && ((ret++))
+ fi
+
+ if [[ -f "/sys/fs/cgroup/isulad/io.weight_device" ]];then
+ # min value
+ isula run -ti --rm --blkio-weight-device /dev/null:10 busybox cat "/sys/fs/cgroup/io.weight_device" | grep ^"1:3 10"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight max value failed" && ((ret++))
+
+ # max value
+ isula run -ti --rm --blkio-weight-device /dev/null:1000 busybox cat "/sys/fs/cgroup/io.weight_device" | grep ^"1:3 10000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight max value failed" && ((ret++))
+
+ # disable weight device
+ isula run -tid -n weight_device --rm --blkio-weight-device /dev/null:0 busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight failed" && ((ret++))
+
+ isula exec -ti weight_device cat "/sys/fs/cgroup/io.weight_device" | grep ^"1:3"$'\r'
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight disable failed" && ((ret++))
+
+ isula rm -f weight_device
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.weight remove container failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/io.max ]];then
+ # normal value
+ isula run -ti --rm --device-read-bps /dev/null:1g --device-read-iops /dev/null:1000 --device-write-bps /dev/null:2g --device-write-iops /dev/null:2000 busybox cat /sys/fs/cgroup/io.max | grep ^"1:3 rbps=1073741824 wbps=2147483648 riops=1000 wiops=2000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.max failed" && ((ret++))
+
+ # invalid
+ isula run -ti --rm --device-read-bps /dev/null:-1 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.max -1 failed" && ((ret++))
+
+ # 0 is no limit
+ isula run -ti --rm --device-read-bps /dev/null:0 --device-read-iops /dev/null:0 --device-write-bps /dev/null:0 --device-write-iops /dev/null:0 busybox echo hello
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 io.max 0 failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_memory()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/memory.max ]];then
+ # normal value
+ isula run -ti --rm -m 10m busybox cat /sys/fs/cgroup/memory.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.max run container failed" && ((ret++))
+
+ # 0 is max
+ isula run -ti --rm -m 0 busybox cat /sys/fs/cgroup/memory.max | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.max 0 failed" && ((ret++))
+
+ # invalid
+ isula run -ti --rm -m -1 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.max -1 failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/memory.low ]];then
+ # normal value
+ isula run -ti --rm --memory-reservation 10m busybox cat /sys/fs/cgroup/memory.low | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.low normal value failed" && ((ret++))
+
+ # -1 is invalid
+ isula run -ti --rm --memory-reservation -1 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.low invalid failed" && ((ret++))
+
+ # 0
+ isula run -ti --rm --memory-reservation 0 busybox cat /sys/fs/cgroup/memory.low | grep ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.low 0 failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/memory.swap.max ]];then
+ # normal value
+ isula run -ti --rm --memory 10m --memory-swap 20m busybox cat /sys/fs/cgroup/memory.swap.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.swap.max normal value failed" && ((ret++))
+
+ # invalid
+ isula run -ti --rm --memory 10m --memory-swap 5m busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.swap.max invalid failed" && ((ret++))
+
+ # 0 is the same as memory
+ isula run -ti --rm --memory 10m --memory-swap 0 busybox cat /sys/fs/cgroup/memory.swap.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.swap.max 0 failed" && ((ret++))
+
+ # -1 is max
+ isula run -ti --rm --memory 10m --memory-swap -1 busybox cat /sys/fs/cgroup/memory.swap.max | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.swap.max -1 failed" && ((ret++))
+
+ # disable swap
+ isula run -ti --rm --memory 10m --memory-swap 10m busybox cat /sys/fs/cgroup/memory.swap.max | grep ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 memory.swap.max disable swap failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_pids()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/pids.max ]];then
+ # normal value
+ isula run -ti --rm --pids-limit 123456 busybox cat /sys/fs/cgroup/pids.max | grep ^123456$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 pids.max run container failed" && ((ret++))
+
+ # -1 is max
+ isula run -ti --rm --pids-limit -1 busybox cat /sys/fs/cgroup/pids.max | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 pids.max run container failed" && ((ret++))
+
+ # 0 is max
+ isula run -ti --rm --pids-limit 0 busybox cat /sys/fs/cgroup/pids.max | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 pids.max run container failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_hugetlb()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/hugetlb.2MB.max ]];then
+ isula run -ti --rm --hugetlb-limit 2M:32M busybox cat /sys/fs/cgroup/hugetlb.2MB.max | grep ^33554432$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 hugetlb.2M.max run container failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_freeze()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/cgroup.freeze ]];then
+ isula run -tid -n freeze busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 freeze run container failed" && ((ret++))
+
+ isula pause freeze
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 freeze pause container failed" && ((ret++))
+
+ isula exec -ti freeze echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 freeze pause take no effect" && ((ret++))
+
+ isula unpause freeze
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 freeze unpause container failed" && ((ret++))
+
+ isula exec -ti freeze echo hello
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 freeze unpause take no effect" && ((ret++))
+
+ isula rm -f freeze
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 freeze remove container failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_files()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/files.limit ]];then
+ # normal value
+ isula run -ti --rm --files-limit 123 busybox cat /sys/fs/cgroup/files.limit | grep ^123$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 files.limit run container failed" && ((ret++))
+
+ # -1 is max
+ isula run -ti --rm --files-limit -1 busybox cat /sys/fs/cgroup/files.limit | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 files.limit run container failed" && ((ret++))
+
+ # 0 is max
+ isula run -ti --rm --files-limit 0 busybox cat /sys/fs/cgroup/files.limit | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 files.limit run container failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_cpu_update()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/cpu.weight ]];then
+ # min value
+ isula update --cpu-shares 2 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight min value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpu.weight | grep ^1$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight min value not right" && ((ret++))
+
+ # max value
+ isula update --cpu-shares 262144 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight max value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpu.weight | grep ^10000$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight max value not right" && ((ret++))
+
+ # 0 means not change
+ isula update --cpu-shares 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight 0 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpu.weight | grep ^10000$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight 0 not right" && ((ret++))
+
+ # invalid value
+ isula update --cpu-shares -1 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.weight -1 failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/cpu.max ]];then
+ # normal value
+ isula update --cpu-quota 50000 --cpu-period 12345 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max normal value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpu.max | grep ^"50000 12345"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max normal value not right" && ((ret++))
+
+ # invalid min period
+ isula update --cpu-quota 50000 --cpu-period 999 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max invalid min period failed" && ((ret++))
+
+ # invalid max period
+ isula update --cpu-quota 50000 --cpu-period 1000001 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max invalid max period failed" && ((ret++))
+
+ # invalid quota
+ isula update --cpu-quota 999 --cpu-period 1000000 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max invalid quota failed" && ((ret++))
+
+ # default 0 quota
+ isula update --cpu-quota 0 --cpu-period 1000000 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max 0 quota failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpu.max | grep ^"max 1000000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max 0 quota value not right" && ((ret++))
+
+ # default -1 quota
+ isula update --cpu-quota -1 --cpu-period 1000000 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max -1 quota failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpu.max | grep ^"max 1000000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max -1 quota value not right" && ((ret++))
+
+ # cpus 1
+ isula run -tid -n cpu_update busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 run cpu_update failed" && ((ret++))
+
+ isula update --cpus 1 cpu_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max cpus 1 failed" && ((ret++))
+
+ isula exec -ti cpu_update cat /sys/fs/cgroup/cpu.max | grep ^"100000 100000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max cpus 1 value not right" && ((ret++))
+
+ # cpus 0 means not change
+ isula update --cpus 0 cpu_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max cpus 0 failed" && ((ret++))
+
+ isula exec -ti cpu_update cat /sys/fs/cgroup/cpu.max | grep ^"100000 100000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpu.max cpus 0 value not right" && ((ret++))
+
+ isula rm -f cpu_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 remove cpu_update failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/cpuset.cpus.effective ]];then
+ # normal value
+ isula update --cpuset-cpus 0 --cpuset-mems 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update update cpuset failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpuset.cpus | grep -E ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpuset.cpus value not right" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/cpuset.mems | grep -E ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpuset.mems value not right" && ((ret++))
+
+ # invalid cpus -1 value
+ isula update --cpuset-cpus -1 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpuset.cpus invalid -1 failed" && ((ret++))
+
+ # invalid cpus 100000 value
+ isula update --cpuset-cpus 100000 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpuset.cpus invalid 100000 failed" && ((ret++))
+
+ # invalid mems -1 value
+ isula update --cpuset-mems -1 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpuset.mems invalid -1 failed" && ((ret++))
+
+ # invalid mems 100000 value
+ isula update --cpuset-mems 100000 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update cpuset.mems invalid 100000 failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_io_update()
+{
+ local ret=0
+
+ if [[ -f "/sys/fs/cgroup/isulad/io.bfq.weight" ]];then
+ # min value
+ isula update --blkio-weight 10 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfq.weight min value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat "/sys/fs/cgroup/io.bfq.weight" | grep 1$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfq.weight min value not right" && ((ret++))
+
+ # max value
+ isula update --blkio-weight 1000 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfq.weight max value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat "/sys/fs/cgroup/io.bfq.weight" | grep 1000$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfq.weight max value not right" && ((ret++))
+
+ # 0 means value not change
+ isula update --blkio-weight 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfq.weight 0 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat "/sys/fs/cgroup/io.bfq.weight" | grep 1000$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfq.weight 0 not right" && ((ret++))
+
+ # invalid value
+ isula update --blkio-weight -1 $cgroup2_update echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.bfqweight -1 failed" && ((ret++))
+ fi
+
+ if [[ -f "/sys/fs/cgroup/isulad/io.weight" ]];then
+ # min value
+ isula update --blkio-weight 10 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight min value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat "/sys/fs/cgroup/io.weight" | grep ^"default 1"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight min value not right" && ((ret++))
+
+ # max value
+ isula update --blkio-weight 1000 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight max value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat "/sys/fs/cgroup/io.weight" | grep ^"default 10000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight max value not right" && ((ret++))
+
+ # 0 means value not change
+ isula update --blkio-weight 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight 0 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat "/sys/fs/cgroup/io.weight" | grep ^"default 10000"$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight 0 not right" && ((ret++))
+
+ # invalid value
+ isula update --blkio-weight -1 $cgroup2_update echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update io.weight -1 failed" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_memory_update()
+{
+ local ret=0
+
+ if [[ -f /sys/fs/cgroup/isulad/memory.max ]];then
+ # normal value
+ isula update -m 10m $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.max 10m failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.max 10m value not right" && ((ret++))
+
+ # 0 is not change
+ isula update -m 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.max 0 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.max 0 not right" && ((ret++))
+
+ # invalid
+ isula update -m -1 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.max -1 failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/memory.low ]];then
+ # normal value
+ isula update --memory-reservation 10m $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.low normal value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.low | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.low normal value not right" && ((ret++))
+
+ # 0 means not change
+ isula update --memory-reservation 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.low 0 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.low | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.low 0 value not right" && ((ret++))
+
+ # -1 is invalid
+ isula update --memory-reservation -1 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.low invalid failed" && ((ret++))
+ fi
+
+ if [[ -f /sys/fs/cgroup/isulad/memory.swap.max ]];then
+ # normal value
+ isula update --memory 10m --memory-swap 20m $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max normal value failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.swap.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max normal value not right" && ((ret++))
+
+ # invalid
+ isula update --memory 10m --memory-swap 5m $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max invalid failed" && ((ret++))
+
+ # 0 is the same as memory
+ isula update --memory 10m --memory-swap 0 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max 0 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.swap.max | grep ^10485760$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max 0 value not right" && ((ret++))
+
+ # -1 is max
+ isula update --memory 10m --memory-swap -1 $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max -1 failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.swap.max | grep ^max$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max -1 value not right" && ((ret++))
+
+ # disable swap
+ isula update --memory 10m --memory-swap 10m $cgroup2_update
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max disable swap failed" && ((ret++))
+
+ isula exec -ti $cgroup2_update cat /sys/fs/cgroup/memory.swap.max | grep ^0$'\r'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update memory.swap.max disable swap value not right" && ((ret++))
+ fi
+
+ return ${ret}
+}
+
+function test_cgroup2_unsupported()
+{
+ local ret=0
+
+ isula run -ti --rm --cpu-rt-period 1000000 --cpu-rt-runtime 1000000 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --cpu-rt-period and --cpu-rt-runtime should failed" && ((ret++))
+
+ isula run -ti --rm --kernel-memory 100m busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --kernel-memory should failed" && ((ret++))
+
+ isula run -ti --rm --memory-swappiness 50 busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --memory-swappiness should failed" && ((ret++))
+
+ isula run -ti --rm --oom-kill-disable busybox echo hello
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --oom-kill-disable should failed" && ((ret++))
+
+ isula update --cpu-rt-period 1000000 --cpu-rt-runtime 1000000 $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update --cpu-rt-period and --cpu-rt-runtime should failed" && ((ret++))
+
+ isula update --kernel-memory 100m $cgroup2_update
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 update --kernel-memory should failed" && ((ret++))
+
+ return ${ret}
+}
+
+function test_cgroup2_parent()
+{
+ local ret=0
+
+ rmdir /sys/fs/cgroup/isulad
+ rmdir /sys/fs/cgroup/abc
+
+ id=`isula run -tid --cgroup-parent /abc -m 10m busybox sh`
+ cat /sys/fs/cgroup/abc/$id/memory.max | grep ^10485760$
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --cgroup-parent cannot work" && ((ret++))
+
+ return ${ret}
+}
+
+function test_cgroup2_device()
+{
+ local ret=0
+
+ dev_name=/dev/$(lsblk | grep disk | head -n 1 | awk '{print $1}')
+ dev_num=$(lsblk | grep disk | head -n 1 | awk '{print $2}')
+ mknod_num=$(echo $dev_num | sed 's/:/ /g')
+
+ # read only
+ isula run -ti --rm --device=$dev_name:/dev/sdx:r busybox sh -c 'echo q | fdisk /dev/sdx | grep "read only"'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device r failed" && ((ret++))
+
+ isula run -ti --rm --device=$dev_name:/dev/sdx:rm busybox sh -c 'echo q | fdisk /dev/sdx | grep "read only"'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device rm failed" && ((ret++))
+
+ isula run -ti --rm --device-cgroup-rule="b $dev_num r" busybox sh -c "mknod /dev/sdx b $mknod_num && echo q | fdisk /dev/sdx | grep 'read only'"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device r failed" && ((ret++))
+
+ isula run -ti --rm --device-cgroup-rule="b $dev_num rm" busybox sh -c "mknod /dev/sdx b $mknod_num && echo q | fdisk /dev/sdx | grep 'read only'"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device rm failed" && ((ret++))
+
+ # can't read
+ isula run -ti --rm --device=$dev_name:/dev/sdx:w busybox sh -c 'echo q | fdisk /dev/sdx 2>&1 | grep "t open"'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device w failed" && ((ret++))
+
+ isula run -ti --rm --device=$dev_name:/dev/sdx:wm busybox sh -c 'echo q | fdisk /dev/sdx 2>&1 | grep "t open"'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device wm failed" && ((ret++))
+
+ isula run -ti --rm --device-cgroup-rule="b $dev_num w" busybox sh -c "mknod /dev/sdx b $mknod_num && echo q | fdisk /dev/sdx 2>&1 | grep 't open'"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device w failed" && ((ret++))
+
+ isula run -ti --rm --device-cgroup-rule="b $dev_num wm" busybox sh -c "mknod /dev/sdx b $mknod_num && echo q | fdisk /dev/sdx 2>&1 | grep 't open'"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device wm failed" && ((ret++))
+
+ # can't read write
+ isula run -ti --rm --device=$dev_name:/dev/sdx:m busybox sh -c 'echo q | fdisk /dev/sdx 2>&1 | grep "t open"'
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device m" && ((ret++))
+
+ isula run -ti --rm --device-cgroup-rule="b $dev_num m" busybox sh -c "mknod /dev/sdx b $mknod_num && echo q | fdisk /dev/sdx 2>&1 | grep 't open'"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device wm failed" && ((ret++))
+
+ isula run -ti --rm --device-cgroup-rule="b *:* m" busybox sh -c "mknod /dev/sdx b $mknod_num && echo q | fdisk /dev/sdx 2>&1 | grep 't open'"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 --device wm failed" && ((ret++))
+
+ return ${ret}
+}
+
+function prepare_test_cgroupv2()
+{
+ local ret=0
+
+ cat /proc/1/mountinfo | grep "\- cgroup2" | grep "/sys/fs/cgroup rw"
+ if [ x"$?" == x"0" ];then
+ cgroupv2=1
+ else
+ return 0
+ fi
+
+ all=$(cat /sys/fs/cgroup/cgroup.controllers)
+ sub=$(cat /sys/fs/cgroup/cgroup.subtree_control)
+ if [ x"$all" != x"$sub" ];then
+ echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control
+ echo +cpu > /sys/fs/cgroup/cgroup.subtree_control
+ echo +io > /sys/fs/cgroup/cgroup.subtree_control
+ echo +memory > /sys/fs/cgroup/cgroup.subtree_control
+ echo +pids > /sys/fs/cgroup/cgroup.subtree_control
+ echo +hugetlb > /sys/fs/cgroup/cgroup.subtree_control
+ echo +files > /sys/fs/cgroup/cgroup.subtree_control
+ fi
+
+ mkdir -p /sys/fs/cgroup/isulad
+ chmod 755 /sys/fs/cgroup/isulad
+
+ isula rm -f `isula ps -a -q`
+
+ isula run -tid -n $cgroup2_update busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - cgroup2 run container failed" && ((ret++))
+
+ return ${ret}
+}
+
+function post_test_cgroupv2()
+{
+ isula rm -f `isula ps -a -q`
+ return 0
+}
+
+declare -i ans=0
+
+msg_info "${test} starting..."
+[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++))
+
+prepare_test_cgroupv2 || ((ans++))
+if [ "$cgroupv2" == "1" ];then
+ test_cgroup2_cpu || ((ans++))
+ test_cgroup2_io || ((ans++))
+ test_cgroup2_memory || ((ans++))
+ test_cgroup2_pids || ((ans++))
+ test_cgroup2_hugetlb || ((ans++))
+ test_cgroup2_freeze || ((ans++))
+ test_cgroup2_files || ((ans++))
+ test_cgroup2_cpu_update || ((ans++))
+ test_cgroup2_io_update || ((ans++))
+ test_cgroup2_memory_update || ((ans++))
+ test_cgroup2_unsupported || ((ans++))
+ test_cgroup2_parent || ((ans++))
+ test_cgroup2_device || ((ans++))
+else
+ msg_info "${test} not cgroup v2 enviorment, ignore test..."
+fi
+post_test_cgroupv2
+
+msg_info "${test} finished with return ${ans}..."
+
+show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,44 +0,0 @@
From 36912c87592d8b46aae340df9b51287c6a8ce78b Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Thu, 1 Apr 2021 20:14:05 +0800
Subject: [PATCH 064/104] Readme: add configure image registry address
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
README.md | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 68f35f34..fdbc8757 100644
--- a/README.md
+++ b/README.md
@@ -53,10 +53,25 @@ For more information contact your distribution or package provider.
you should run `rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-openEuler` first
+
+### Configure
+
+Configure the container image registry address, for example "docker.io" or other registry addrss.
+
+```sh
+# cat /etc/isulad/daemon.json
+.....
+ "registry-mirrors": [
+ "docker.io"
+ ],
+.....
+```
+
### Run
+
We provide `systemd` service to start `iSulad`:
```sh
-systemctl start isulad # run the server with systemd command
+systemctl restart isulad # restart the server with systemd command
```
You can use direct command to start `iSulad` server
--
2.25.1

View File

@ -1,32 +0,0 @@
From 3b743b6c460869b3118a63c22f620383c234e17d Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Fri, 2 Apr 2021 15:45:45 +0800
Subject: [PATCH 065/104] add iSulad experiment in README
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.md b/README.md
index fdbc8757..39e23de1 100644
--- a/README.md
+++ b/README.md
@@ -249,6 +249,14 @@ base operators of CRI
| 100 * runp | 27802 | 29197 | 2398 | -91.37% | -91.79% |
| 100 * stopp | 14429 | 11173 | 1170 | -91.89% | -89.53% |
+## Try to Use iSulad
+
+If you want to experience iSulad right now, you can try to use it at
+
+- https://lab.huaweicloud.com/testdetail_498
+
+It is the experiment about iSulad. In this experiment you can install iSulad easily. And then you can pull image, run container, analyse iSulad's performance and compare it with performance of Docker.
+
## How to Contribute
We always welcome new contributors. And we are happy to provide guidance for the new contributors.
--
2.25.1

View File

@ -1,106 +0,0 @@
From e13e14225cbdcb504268b740f171b2850b61aa88 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Tue, 6 Apr 2021 14:41:17 +0800
Subject: [PATCH 066/104] CI: add testcase for long label
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
CI/test_cases/container_cases/annotaion.sh | 86 ++++++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100755 CI/test_cases/container_cases/annotaion.sh
diff --git a/CI/test_cases/container_cases/annotaion.sh b/CI/test_cases/container_cases/annotaion.sh
new file mode 100755
index 00000000..b563e390
--- /dev/null
+++ b/CI/test_cases/container_cases/annotaion.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# attributes: isulad annotation
+# concurrent: YES
+# spend time: 15
+
+#######################################################################
+##- @Copyright (C) Huawei Technologies., 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.
+##- @Description:CI
+##- @Author: lifeng
+##- @Create: 2021-04-06
+#######################################################################
+
+declare -r curr_path=$(dirname $(readlink -f "$0"))
+source ../helpers.sh
+test="annotation test => test_annotation"
+
+function test_label()
+{
+ local ret=0
+
+ isula run -tid --name annotation --label "test_long_label=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container for long label" && ((ret++))
+
+ isula inspect annotation
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to inspect container for long label" && ((ret++))
+
+ isula exec -ti annotation echo 1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to exec in container" && ((ret++))
+
+ check_valgrind_log
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++))
+
+ start_isulad_with_valgrind
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++))
+
+ isula rm -f annotation
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm -f container" && ((ret++))
+
+ return ${ret}
+}
+
+function test_annotation()
+{
+ local ret=0
+
+ isula run -tid --name annotation --annotation "test_long_label=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" busybox sh
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container for long label" && ((ret++))
+
+ isula inspect annotation
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to inspect container for long label" && ((ret++))
+
+ isula exec -ti annotation echo 1
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to exec in container" && ((ret++))
+
+ check_valgrind_log
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++))
+
+ start_isulad_with_valgrind
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++))
+
+ isula rm -f annotation
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm -f container" && ((ret++))
+
+ return ${ret}
+}
+
+declare -i ans=0
+
+msg_info "${test} starting..."
+[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++))
+
+test_label || ((ans++))
+test_annotation || ((ans++))
+
+msg_info "${test} finished with return ${ans}..."
+
+show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,92 +0,0 @@
From 1e2ebc309064e88d0d5aac6a91b23ef8cbc0c727 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Tue, 6 Apr 2021 15:05:59 +0800
Subject: [PATCH 067/104] event: fix memory leak when pack annotation failed
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
.../connect/grpc/grpc_containers_client.cc | 2 +-
src/daemon/modules/events/collector.c | 18 +++---------------
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/src/client/connect/grpc/grpc_containers_client.cc b/src/client/connect/grpc/grpc_containers_client.cc
index 6661970b..bb50d811 100644
--- a/src/client/connect/grpc/grpc_containers_client.cc
+++ b/src/client/connect/grpc/grpc_containers_client.cc
@@ -1810,8 +1810,8 @@ private:
for (const auto &iter : map) {
std::string anno = iter.first + "=" + iter.second;
(void)util_array_append(&event->annotations, anno.c_str());
- event->annotations_len++;
}
+ event->annotations_len = util_array_len((const char **)event->annotations);
}
auto events_request_to_grpc(const struct isula_events_request *request, EventsRequest *grequest) -> int
diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c
index 3e587aeb..67a823f1 100644
--- a/src/daemon/modules/events/collector.c
+++ b/src/daemon/modules/events/collector.c
@@ -332,44 +332,36 @@ static int supplement_labels_for_container_msg(const container_t *cont, const st
return 0;
}
-static int supplement_annotations_for_container_msg(const container_t *cont, const struct monitord_msg *msg,
- struct isulad_events_format *format_msg)
+static void supplement_annotations_for_container_msg(const container_t *cont, const struct monitord_msg *msg,
+ struct isulad_events_format *format_msg)
{
if (supplement_pid_for_container_msg(cont, msg, format_msg) != 0) {
ERROR("Failed to supplement pid info");
- return -1;
}
if (supplement_exitcode_for_container_msg(cont, msg, format_msg) != 0) {
ERROR("Failed to supplement exitCode info");
- return -1;
}
if (supplement_image_for_container_msg(cont, msg, format_msg) != 0) {
ERROR("Failed to supplement image info");
- return -1;
}
if (supplement_name_for_container_msg(cont, msg, format_msg) != 0) {
ERROR("Failed to supplement name info");
- return -1;
}
if (supplement_labels_for_container_msg(cont, msg, format_msg) != 0) {
ERROR("Failed to supplement label info");
- return -1;
}
if (strlen(msg->extra_annations) != 0) {
if (util_array_append(&format_msg->annotations, msg->extra_annations) != 0) {
ERROR("Failed to supplement extra annations info");
- return -1;
}
}
format_msg->annotations_len = util_array_len((const char **)format_msg->annotations);
-
- return 0;
}
static int supplement_msg_for_container(struct monitord_msg *msg, struct isulad_events_format *format_msg)
@@ -395,11 +387,7 @@ static int supplement_msg_for_container(struct monitord_msg *msg, struct isulad_
goto out;
}
- if (supplement_annotations_for_container_msg(cont, msg, format_msg) != 0) {
- ERROR("Failed to supplement annotations info");
- ret = -1;
- goto out;
- }
+ supplement_annotations_for_container_msg(cont, msg, format_msg);
out:
container_unref(cont);
--
2.25.1

View File

@ -1,198 +0,0 @@
From 38b5c74dcce5fc61438ce03252c14c9b5a009d81 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Wed, 7 Apr 2021 11:34:21 +0800
Subject: [PATCH 068/104] Readme: add script to install iSulad on Centos7
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
docs/build_guide.md | 9 +-
docs/build_guide_zh.md | 8 +-
docs/install_iSulad_on_Centos_7.sh | 137 +++++++++++++++++++++++++++++
3 files changed, 150 insertions(+), 4 deletions(-)
create mode 100644 docs/install_iSulad_on_Centos_7.sh
diff --git a/docs/build_guide.md b/docs/build_guide.md
index d710cbbb..449767ae 100644
--- a/docs/build_guide.md
+++ b/docs/build_guide.md
@@ -7,8 +7,13 @@ If you intend to contribute on iSulad. Thanks for your effort. Every contributio
These dependencies are required for build:
### install basic dependencies based on Centos distribution
-```bash
-$ sudo yum --enablerepo='*' install -y automake autoconf libtool cmake make libcap libcap-devel libselinux libselinux-devel libseccomp libseccomp-devel yajl-devel git libcgroup tar python3 python3-pip device-mapper-devel libarchive libarchive-devel libcurl-devel zlib-devel glibc-headers openssl-devel gcc gcc-c++ systemd-devel systemd-libs golang libtar libtar-devel
+
+We provided a script to auto install iSulad on centos7, you can just execute the script to install iSulad.
+
+```sh
+$ git clone https://gitee.com/openeuler/iSulad.git
+$ cd iSulad/docs
+$ sudo ./install_iSulad_on_Centos_7.sh
```
### install basic dependencies based on Ubuntu distribution
diff --git a/docs/build_guide_zh.md b/docs/build_guide_zh.md
index d6621fcf..2cb709e8 100644
--- a/docs/build_guide_zh.md
+++ b/docs/build_guide_zh.md
@@ -18,8 +18,12 @@ dnf builddep iSulad.spec
### Centos的安装命令
-```bash
-$ sudo yum --enablerepo='*' install -y automake autoconf libtool cmake make libcap libcap-devel libselinux libselinux-devel libseccomp libseccomp-devel yajl-devel git libcgroup tar python3 python3-pip device-mapper-devel libarchive libarchive-devel libcurl-devel zlib-devel glibc-headers openssl-devel gcc gcc-c++ systemd-devel systemd-libs libtar libtar-devel
+我们在代码仓中提供了在Centos7上自动化安装的脚本您只需要执行这个脚本就可以自动编译安装iSulad以及其依赖的组件。
+
+```sh
+$ git clone https://gitee.com/openeuler/iSulad.git
+$ cd iSulad/docs
+$ sudo ./install_iSulad_on_Centos_7.sh
```
### Ubuntu的安装命令
diff --git a/docs/install_iSulad_on_Centos_7.sh b/docs/install_iSulad_on_Centos_7.sh
new file mode 100644
index 00000000..48aff5cf
--- /dev/null
+++ b/docs/install_iSulad_on_Centos_7.sh
@@ -0,0 +1,137 @@
+#/bin/bash
+
+
+set -x
+set -e
+
+# install neccessary packages
+yum install -y patch automake autoconf libtool cmake make libcap libcap-devel libselinux libselinux-devel libseccomp libseccomp-devel yajl-devel git libcgroup tar python3 python3-pip device-mapper-devel libcurl-devel zlib-devel glibc-headers openssl-devel gcc gcc-c++ systemd-devel systemd-libs golang libtar libtar-devel
+
+# export LDFLAGS
+export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
+export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
+ echo "/usr/local/lib" >> /etc/ld.so.conf
+
+BUILD_DIR=/tmp/build_isulad
+
+rm -rf $BUILD_DIR
+mkdir -p $BUILD_DIR
+
+# build libarchive
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/libarchive.git
+cd libarchive
+git checkout -b openEuler-20.03-LTS-tag openEuler-20.03-LTS-tag
+tar -zxvf libarchive-3.4.1.tar.gz
+cd libarchive-3.4.1
+patch -p1 -F1 -s < ../libarchive-uninitialized-value.patch
+cd build
+cmake -DCMAKE_USE_SYSTEM_LIBRARIES=ON ../
+make -j $(nproc)
+make install
+ldconfig
+
+# build protobuf
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/protobuf.git
+cd protobuf
+git checkout openEuler-20.03-LTS-tag
+tar -xzvf protobuf-all-3.9.0.tar.gz
+cd protobuf-3.9.0
+./autogen.sh
+./configure
+make -j $(nproc)
+make install
+ldconfig
+
+# build c-ares
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/c-ares.git
+cd c-ares
+git checkout openEuler-20.03-LTS-tag
+tar -xzvf c-ares-1.15.0.tar.gz
+cd c-ares-1.15.0
+autoreconf -if
+./configure --enable-shared --disable-dependency-tracking
+make -j $(nproc)
+make install
+ldconfig
+
+# build grpc
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/grpc.git
+cd grpc
+git checkout openEuler-20.03-LTS-tag
+tar -xzvf grpc-1.22.0.tar.gz
+cd grpc-1.22.0
+make -j $(nproc)
+make install
+ldconfig
+
+# build http_parser
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/http-parser.git
+cd http-parser
+git checkout openEuler-20.03-LTS-tag
+tar -xzvf http-parser-2.9.2.tar.gz
+cd http-parser-2.9.2
+make -j CFLAGS="-Wno-error"
+make CFLAGS="-Wno-error" install
+ldconfig
+
+# build libwebsockets
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/libwebsockets.git
+cd libwebsockets
+git checkout openEuler-20.03-LTS-tag
+tar -xzvf libwebsockets-2.4.2.tar.gz
+cd libwebsockets-2.4.2
+patch -p1 -F1 -s < ../libwebsockets-fix-coredump.patch
+mkdir build
+cd build
+cmake -DLWS_WITH_SSL=0 -DLWS_MAX_SMP=32 -DCMAKE_BUILD_TYPE=Debug ../
+make -j $(nproc)
+make install
+ldconfig
+
+# build lxc
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/lxc.git
+cd lxc
+tar -zxf lxc-4.0.3.tar.gz
+./apply-patches
+cd lxc-4.0.3
+./autogen.sh
+./configure
+make -j
+make install
+
+# build lcr
+cd $BUILD_DIR
+git clone https://gitee.com/openeuler/lcr.git
+cd lcr
+mkdir build
+cd build
+cmake ..
+make -j
+make install
+
+# build and install clibcni
+cd $BUILD_DIR
+git clone https://gitee.com/openeuler/clibcni.git
+cd clibcni
+mkdir build
+cd build
+cmake ..
+make -j
+make install
+
+# build and install iSulad
+cd $BUILD_DIR
+git clone https://gitee.com/openeuler/iSulad.git
+cd iSulad
+mkdir build
+cd build
+cmake ..
+make
+make install
--
2.25.1

File diff suppressed because it is too large Load Diff

View File

@ -1,191 +0,0 @@
From b4dbbf16a6bfadbc2d09079c7b27c4af3feee6a6 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Wed, 7 Apr 2021 15:35:09 +0800
Subject: [PATCH 070/104] CI: add testcase for cri stream
Signed-off-by: wujing <wujing50@huawei.com>
---
CI/install_depends.sh | 8 ++
CI/test_cases/container_cases/cri_stream.sh | 151 ++++++++++++++++++++
2 files changed, 159 insertions(+)
create mode 100755 CI/test_cases/container_cases/cri_stream.sh
diff --git a/CI/install_depends.sh b/CI/install_depends.sh
index 5dd25439..f643deb8 100755
--- a/CI/install_depends.sh
+++ b/CI/install_depends.sh
@@ -143,6 +143,14 @@ make install
cd -
ldconfig
+# install cricli
+cd ~
+git clone https://gitee.com/jingwoo/cricli.git
+cd cricli
+make -j $(nproc)
+cp cricli /usr/local/bin
+cd -
+
wait
if [ -e ${buildstatus} ];then
for i in ${buildlogs[@]}
diff --git a/CI/test_cases/container_cases/cri_stream.sh b/CI/test_cases/container_cases/cri_stream.sh
new file mode 100755
index 00000000..3107308f
--- /dev/null
+++ b/CI/test_cases/container_cases/cri_stream.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+#
+# attributes: isulad cri websockets exec attach
+# concurrent: NA
+# spend time: 46
+
+curr_path=$(dirname $(readlink -f "$0"))
+data_path=$(realpath $curr_path/criconfigs)
+pause_img_path=$(realpath $curr_path/test_data)
+source ../helpers.sh
+
+function set_up()
+{
+ local ret=0
+ local image="busybox"
+ local podimage="mirrorgooglecontainers/pause-amd64"
+ local test="set_up => (${FUNCNAME[@]})"
+
+ msg_info "${test} starting..."
+
+ cp /etc/isulad/daemon.json /etc/isulad/daemon.bak
+ sed -i "s#\"pod-sandbox-image\": \"\"#\"pod-sandbox-image\": \"mirrorgooglecontainers/pause-amd64:3.0\"#g" /etc/isulad/daemon.json
+
+ check_valgrind_log
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop isulad" && return ${FAILURE}
+
+ start_isulad_with_valgrind
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to start isulad" && return ${FAILURE}
+
+ isula load -i ${pause_img_path}/pause.tar
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to load pause image" && return ${FAILURE}
+
+ crictl pull ${image}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
+
+ crictl images | grep ${podimage}
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${podimage}" && ((ret++))
+
+ sid=$(crictl runp ${data_path}/sandbox-config.json)
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run sandbox" && ((ret++))
+
+ cid=$(crictl create $sid ${data_path}/container-config.json ${data_path}/sandbox-config.json)
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create container" && ((ret++))
+
+ crictl start $cid
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to start container" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_cri_exec_fun()
+{
+ local ret=0
+ local test="test_cri_exec_fun => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+ declare -a fun_pids
+ for index in $(seq 1 20); do
+ nohup cricli exec -it ${cid} date &
+ fun_pids[${#pids[@]}]=$!
+ done
+ wait ${fun_pids[*]// /|}
+
+ declare -a abn_pids
+ for index in $(seq 1 20); do
+ nohup cricli exec -it ${cid} xxx &
+ abn_pids[${#pids[@]}]=$!
+ done
+ wait ${abn_pids[*]// /|}
+
+ sleep 2
+ ps -T -p $(cat /var/run/isulad.pid) | grep IoCopy
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - residual IO copy thread in CRI exec operation" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_cri_exec_abn
+{
+ local ret=0
+ local test="test_cri_exec_abn => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup cricli exec -it ${cid} sleep 100 &
+ pid=$!
+ sleep 3
+ kill -9 $pid
+ sleep 2
+
+ ps -T -p $(cat /var/run/isulad.pid) | grep IoCopy
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - residual IO copy thread in CRI exec operation" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function test_cri_attach
+{
+ local ret=0
+ local test="test_cri_attach => (${FUNCNAME[@]})"
+ msg_info "${test} starting..."
+
+ nohup cricli attach -i ${cid} &
+ pid=$!
+ sleep 2
+ kill -9 $pid
+ sleep 2
+
+ ps -T -p $(cat /var/run/isulad.pid) | grep IoCopy
+ [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - residual IO copy thread in CRI attach operation" && ((ret++))
+
+ msg_info "${test} finished with return ${ret}..."
+ return ${ret}
+}
+
+function tear_down()
+{
+ local ret=0
+
+ crictl stop $cid
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop container" && ((ret++))
+
+ crictl rm $cid
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++))
+
+ crictl stopp $sid
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop sandbox" && ((ret++))
+
+ crictl rmp $sid
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm sandbox" && ((ret++))
+
+ cp -f /etc/isulad/daemon.bak /etc/isulad/daemon.json
+ check_valgrind_log
+ start_isulad_with_valgrind
+
+ return ${ret}
+}
+
+declare -i ans=0
+
+set_up || ((ans++))
+
+test_cri_exec_fun || ((ans++))
+test_cri_exec_abn || ((ans++))
+
+test_cri_attach || ((ans++))
+
+tear_down || ((ans++))
+
+show_result ${ans} "${curr_path}/${0}"
--
2.25.1

View File

@ -1,69 +0,0 @@
From 91ca85b8d8539992a6862a1a54c1e7b9d734b151 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Thu, 8 Apr 2021 15:41:18 +0800
Subject: [PATCH 071/104] stats: show cpu usage normal when stats with
--no-stream
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/cmd/isula/extend/stats.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/cmd/isula/extend/stats.c b/src/cmd/isula/extend/stats.c
index 724cf381..b35156a6 100644
--- a/src/cmd/isula/extend/stats.c
+++ b/src/cmd/isula/extend/stats.c
@@ -192,13 +192,15 @@ static void stats_output(const struct client_arguments *args, struct isula_stats
{
size_t i;
- printf(TERMCLEAR);
- stats_print_header();
- for (i = 0; i < (*response)->container_num; i++) {
- stats_print(&((*response)->container_stats[i]));
- printf("\n");
+ if (g_oldstats != NULL) {
+ printf(TERMCLEAR);
+ stats_print_header();
+ for (i = 0; i < (*response)->container_num; i++) {
+ stats_print(&((*response)->container_stats[i]));
+ printf("\n");
+ }
+ fflush(stdout);
}
- fflush(stdout);
isula_stats_response_free(g_oldstats);
g_oldstats = *response;
@@ -222,6 +224,7 @@ static int client_stats_mainloop(const struct client_arguments *args, const stru
config = get_connect_config(args);
while (1) {
+ bool first_frame = false;
struct isula_stats_response *response = NULL;
response = util_common_calloc_s(sizeof(struct isula_stats_response));
if (response == NULL) {
@@ -239,6 +242,10 @@ static int client_stats_mainloop(const struct client_arguments *args, const stru
goto out;
}
+ if (g_oldstats == NULL) {
+ first_frame = true;
+ }
+
if (args->original) {
stats_output_original(args, &response);
isula_stats_response_free(response);
@@ -247,7 +254,8 @@ static int client_stats_mainloop(const struct client_arguments *args, const stru
stats_output(args, &response);
isula_stats_response_free(response);
- if (args->nostream) {
+
+ if (args->nostream && !first_frame) {
goto out;
}
--
2.25.1

View File

@ -1,118 +0,0 @@
From ac38baf0a2a49b9cfeb8010393b5f8e5d8a49739 Mon Sep 17 00:00:00 2001
From: NiGo <nigo@xiyoulinux.org>
Date: Tue, 13 Apr 2021 19:49:14 +0800
Subject: [PATCH 072/104] Readme: add script to install iSulad on Ubuntu 20.04
LTS
---
docs/build_guide.md | 6 ++-
docs/build_guide_zh.md | 6 ++-
docs/install_iSulad_on_Ubuntu_20_04_LTS.sh | 62 ++++++++++++++++++++++
3 files changed, 70 insertions(+), 4 deletions(-)
create mode 100644 docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
diff --git a/docs/build_guide.md b/docs/build_guide.md
index 449767ae..1b481a11 100644
--- a/docs/build_guide.md
+++ b/docs/build_guide.md
@@ -17,8 +17,10 @@ $ sudo ./install_iSulad_on_Centos_7.sh
```
### install basic dependencies based on Ubuntu distribution
-```bash
-$ sudo apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux-dev libseccomp-dev libcap-dev libsystemd-dev git libcurl4-gnutls-dev openssl libdevmapper-dev golang python3 libtar libtar-dev
+```sh
+$ git clone https://gitee.com/openeuler/iSulad.git
+$ cd iSulad/docs
+$ sudo ./docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
```
## Build and install other dependencies from source
diff --git a/docs/build_guide_zh.md b/docs/build_guide_zh.md
index 2cb709e8..0c844816 100644
--- a/docs/build_guide_zh.md
+++ b/docs/build_guide_zh.md
@@ -27,8 +27,10 @@ $ sudo ./install_iSulad_on_Centos_7.sh
```
### Ubuntu的安装命令
-```bash
-$ sudo apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux-dev libseccomp-dev libcap-dev libsystemd-dev git libarchive libarchive-dev libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar libtar-dev
+```sh
+$ git clone https://gitee.com/openeuler/iSulad.git
+$ cd iSulad/docs
+$ sudo ./docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
```
## 从源码构建和安装关键依赖
diff --git a/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh b/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
new file mode 100644
index 00000000..4b0b7a85
--- /dev/null
+++ b/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+set -x
+set -e
+
+# export LDFLAGS
+export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
+export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
+echo "/usr/local/lib" >> /etc/ld.so.conf
+
+apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux1-dev libseccomp-dev libcap-dev libsystemd-dev git libarchive libarchive-dev libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar0 libtar-dev libhttp-parser-dev libwebsockets-dev
+
+BUILD_DIR=/tmp/build_isulad
+
+rm -rf $BUILD_DIR
+mkdir -p $BUILD_DIR
+
+# build lxc
+cd $BUILD_DIR
+git clone https://gitee.com/src-openeuler/lxc.git
+cd lxc
+tar -zxf lxc-4.0.3.tar.gz
+./apply-patches
+cd lxc-4.0.3
+./autogen.sh
+./configure
+make -j $(nproc)
+make install
+
+# build lcr
+cd $BUILD_DIR
+git clone https://gitee.com/openeuler/lcr.git
+cd lcr
+mkdir build
+cd build
+cmake ..
+make -j $(nproc)
+make install
+
+# build and install clibcni
+cd $BUILD_DIR
+git clone https://gitee.com/openeuler/clibcni.git
+cd clibcni
+mkdir build
+cd build
+cmake ..
+make -j $(nproc)
+make install
+
+# build and install iSulad
+cd $BUILD_DIR
+git clone https://gitee.com/openeuler/iSulad.git
+cd iSulad
+mkdir build
+cd build
+cmake ..
+make -j $(nproc)
+make install
+
+# clean
+rm -rf $BUILD_DIR
+apt autoremove
--
2.25.1

View File

@ -1,26 +0,0 @@
From 998835f4bca41a91b938a97d4a25e7389e24b19a Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 15 Apr 2021 09:45:06 +0800
Subject: [PATCH 073/104] update libarchive requirement to v3.4
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
cmake/checker.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmake/checker.cmake b/cmake/checker.cmake
index 5ba4c63d..d4337a1b 100644
--- a/cmake/checker.cmake
+++ b/cmake/checker.cmake
@@ -57,7 +57,7 @@ find_library(LIBYAJL_LIBRARY yajl
_CHECK(LIBYAJL_LIBRARY "LIBYAJL_LIBRARY-NOTFOUND" "libyajl.so")
# check libarchive
-pkg_check_modules(PC_LIBARCHIVE REQUIRED "libarchive>=3.2")
+pkg_check_modules(PC_LIBARCHIVE REQUIRED "libarchive>=3.4")
find_path(LIBARCHIVE_INCLUDE_DIR archive.h
HINTS ${PC_LIBARCHIVE_INCLUDEDIR} ${PC_LIBARCHIVE_INCLUDE_DIRS})
_CHECK(LIBARCHIVE_INCLUDE_DIR "LIBARCHIVE_INCLUDE_DIR-NOTFOUND" "archive.h")
--
2.25.1

View File

@ -1,26 +0,0 @@
From 8b5115b5d43cc73d41ade4e984e7ee38eb237d3a Mon Sep 17 00:00:00 2001
From: XiyouNiGo <1275810355@qq.com>
Date: Thu, 15 Apr 2021 12:33:07 +0800
Subject: [PATCH 074/104] correct the mistake package: libarchive-dev
---
docs/install_iSulad_on_Ubuntu_20_04_LTS.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh b/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
index 4b0b7a85..630febe1 100644
--- a/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
+++ b/docs/install_iSulad_on_Ubuntu_20_04_LTS.sh
@@ -7,8 +7,7 @@ set -e
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
echo "/usr/local/lib" >> /etc/ld.so.conf
-
-apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux1-dev libseccomp-dev libcap-dev libsystemd-dev git libarchive libarchive-dev libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar0 libtar-dev libhttp-parser-dev libwebsockets-dev
+apt install -y g++ libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev libgrpc-dev libtool automake autoconf cmake make pkg-config libyajl-dev zlib1g-dev libselinux1-dev libseccomp-dev libcap-dev libsystemd-dev git libarchive-dev libcurl4-gnutls-dev openssl libdevmapper-dev python3 libtar0 libtar-dev libhttp-parser-dev libwebsockets-dev
BUILD_DIR=/tmp/build_isulad
--
2.25.1

View File

@ -1,140 +0,0 @@
From 5f1fe5416c56846da50dd88c7423e80ec8514f5f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=B9=E7=A7=80=E6=B1=9F?= <yinxiujiang@kylinos.cn>
Date: Thu, 15 Apr 2021 16:23:30 +0800
Subject: [PATCH 075/104] Added autocomplete in isula command line mode
---
iSulad.spec | 5 ++
src/contrib/completion/isula | 90 ++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
create mode 100644 src/contrib/completion/isula
diff --git a/iSulad.spec b/iSulad.spec
index eca7ddd8..532af2dc 100644
--- a/iSulad.spec
+++ b/iSulad.spec
@@ -107,6 +107,8 @@ install -d $RPM_BUILD_ROOT/%{_initddir}
install -p -m 0640 ../src/contrib/init/isulad.init $RPM_BUILD_ROOT/%{_initddir}/isulad.init
%endif
+install -d $RPM_BUILD_ROOT/usr/share/bash-completion/completions
+install -p -m 0644 ../src/contrib/completion/isula $RPM_BUILD_ROOT/usr/share/bash-completion/completions/isula
%clean
rm -rf %{buildroot}
@@ -125,6 +127,8 @@ fi
fi
%post
+source /usr/share/bash-completion/completions/isula
+
if ! getent group isula > /dev/null; then
groupadd --system isula
fi
@@ -211,6 +215,7 @@ fi
%else
%config(noreplace,missingok) %{_initddir}/isulad.init
%endif
+/usr/share/bash-completion/completions/isula
%changelog
* Tue Sep 10 2020 openEuler Buildteam <buildteam@openeuler.org> - 2.0.5-20200910.140350.git72990229
diff --git a/src/contrib/completion/isula b/src/contrib/completion/isula
new file mode 100644
index 00000000..305c5150
--- /dev/null
+++ b/src/contrib/completion/isula
@@ -0,0 +1,90 @@
+#!/usr/bin/env bash
+_isula_isula() {
+ local isula_management_commands=(
+ volume
+ )
+
+ local isula_commands=(
+ attach
+ cp
+ create
+ events
+ exec
+ export
+ images
+ import
+ info
+ inspect
+ kill
+ load
+ login
+ logout
+ logs
+ pause
+ ps
+ pull
+ rename
+ restart
+ rm
+ rmi
+ run
+ start
+ stats
+ stop
+ tag
+ top
+ unpause
+ update
+ version
+ wait
+ )
+
+ local commands=(${isula_management_commands[*]} ${isula_commands[*]})
+ local common_options=(
+ --help
+ -H --host
+ --tls
+ --tlscacert
+ --tlscert
+ --tlskey
+ --tlsverify
+ --version
+ )
+
+ case "$prev" in
+ #todo.....
+ esac
+
+ case "$cur" in
+ -*)
+ COMPREPLY=( $( compgen -W "${common_options[*]}" -- "$cur" ) )
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
+ ;;
+ esac
+}
+
+
+_isula() {
+ COMPREPLY=()
+
+ #An array variable consisting of the individual words in the current command line
+ local words=(${COMP_WORDS[*]})
+ #An index into ${word} of the word containing the current cursor position
+ local cword=$COMP_CWORD
+ local cur="${words[$cword]}"
+ local prev="${words[$cword-1]}"
+ local command='isula'
+
+ local completions_func=_isula_${command//-/_}
+
+ #The completion of the secondary command will be added later
+ if [ $cword -lt 2 ] ; then
+ declare -F $completions_func >/dev/null && $completions_func
+ fi
+
+ return 0
+}
+
+complete -F _isula isula
--
2.25.1

View File

@ -1,27 +0,0 @@
From 2b82695e69369b2d5666f13d40e168e89248a51f Mon Sep 17 00:00:00 2001
From: jikui <jikui2@huawei.com>
Date: Sat, 17 Apr 2021 11:49:47 +0800
Subject: [PATCH 076/104] iSulad: fix bugs of isula runtime ops
Signed-off-by: jikui <jikui2@huawei.com>
---
src/daemon/modules/runtime/isula/isula_rt_ops.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
index ecea2b3d..3b55ac88 100644
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
@@ -582,7 +582,8 @@ static int runtime_call_simple(const char *workdir, const char *runtime, const c
runtime_exec_info_init(&rei, workdir, runtime, subcmd, opts, opts_len, id, params, PARAM_NUM);
if (!util_exec_cmd(runtime_exec_func, &rei, NULL, &stdout, &stderr)) {
- WARN("call runtime %s failed stderr %s", subcmd, stderr);
+ ERROR("call runtime %s failed stderr %s", subcmd, stderr);
+ ret = -1;
goto out;
}
--
2.25.1

View File

@ -1,57 +0,0 @@
From 8ee530b4cc42114ae713fb909f52e053b274008b Mon Sep 17 00:00:00 2001
From: wangyueliang <wangyueliang@kylinos.cn>
Date: Tue, 20 Apr 2021 10:53:58 +0800
Subject: [PATCH 077/104] Compatible with registry URL ending in '/'
---
src/daemon/modules/image/oci/utils_images.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/daemon/modules/image/oci/utils_images.c b/src/daemon/modules/image/oci/utils_images.c
index a909b0f3..ece37d2e 100644
--- a/src/daemon/modules/image/oci/utils_images.c
+++ b/src/daemon/modules/image/oci/utils_images.c
@@ -142,6 +142,11 @@ char *oci_add_host(const char *host, const char *name)
return NULL;
}
+ if (strlen(host) == 0) {
+ WARN("Invalid host");
+ return NULL;
+ }
+
if (strchr(name, '/') == NULL) {
need_repo_prefix = true;
}
@@ -152,7 +157,9 @@ char *oci_add_host(const char *host, const char *name)
return NULL;
}
(void)strcat(with_host, host);
- (void)strcat(with_host, "/");
+ if (host[strlen(host) - 1] != '/') {
+ (void)strcat(with_host, "/");
+ }
if (need_repo_prefix) {
(void)strcat(with_host, REPO_PREFIX_TO_STRIP);
}
@@ -491,7 +498,7 @@ bool oci_valid_time(char *time)
static int makesure_path_is_dir(char *path)
{
- struct stat st = {0};
+ struct stat st = { 0 };
if (lstat(path, &st) != 0) {
if (errno == ENOENT) {
@@ -542,7 +549,7 @@ char *oci_get_isulad_tmpdir(const char *root_dir)
int makesure_isulad_tmpdir_perm_right(const char *root_dir)
{
- struct stat st = {0};
+ struct stat st = { 0 };
char *isulad_tmpdir = NULL;
int ret = 0;
--
2.25.1

View File

@ -1,443 +0,0 @@
From a5b1605c8e6552aa78439fb45ff4df59f542ef27 Mon Sep 17 00:00:00 2001
From: lifeng68 <lifeng68@huawei.com>
Date: Wed, 21 Apr 2021 08:54:19 +0800
Subject: [PATCH 078/104] CI: fix CI to fit run on 2 cpu 4G memory environment
Signed-off-by: lifeng68 <lifeng68@huawei.com>
---
.gitignore | 1 +
CI/Dockerfile | 36 ++++++++--
.../container_cases/bigdata_stream.sh | 70 +++++++++----------
.../container_cases/bigdata_stream_runc.sh | 40 +++++------
4 files changed, 87 insertions(+), 60 deletions(-)
diff --git a/.gitignore b/.gitignore
index 8c2dfb40..26e5010e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ compile_commands.json
tags
.clangd
iSula-libutils
+isulad_ci_test_data
diff --git a/CI/Dockerfile b/CI/Dockerfile
index e0a50f65..d25db5c9 100644
--- a/CI/Dockerfile
+++ b/CI/Dockerfile
@@ -219,13 +219,39 @@ RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
cd ~ && \
git clone https://gitee.com/src-openeuler/libwebsockets.git && \
cd libwebsockets && \
- git checkout -b openEuler-20.03-LTS-tag openEuler-20.03-LTS-tag && \
- tar -xzvf libwebsockets-2.4.2.tar.gz && \
- cd libwebsockets-2.4.2 && \
- patch -p1 -F1 -s < ../libwebsockets-fix-coredump.patch && \
+ git checkout -b openEuler-21.03-20210330 openEuler-21.03-20210330 && \
+ tar -xzvf libwebsockets-4.0.20.tar.gz && \
+ cd libwebsockets-4.0.20 && \
mkdir build && \
cd build && \
- cmake -DLWS_WITH_SSL=0 -DLWS_MAX_SMP=32 -DCMAKE_BUILD_TYPE=Debug ../ && \
+ cmake \
+ -D LWS_WITH_HTTP2=ON \
+ -D LWS_IPV6=ON \
+ -D LWS_WITH_ZIP_FOPS=ON \
+ -D LWS_WITH_SOCKS5=ON \
+ -D LWS_WITH_RANGES=ON \
+ -D LWS_WITH_ACME=ON \
+ -D LWS_WITH_LIBUV=OFF \
+ -D LWS_WITH_LIBEV=OFF \
+ -D LWS_WITH_LIBEVENT=OFF \
+ -D LWS_WITH_FTS=ON \
+ -D LWS_WITH_THREADPOOL=ON \
+ -D LWS_UNIX_SOCK=ON \
+ -D LWS_WITH_HTTP_PROXY=ON \
+ -D LWS_WITH_DISKCACHE=ON \
+ -D LWS_WITH_LWSAC=ON \
+ -D LWS_LINK_TESTAPPS_DYNAMIC=ON \
+ -D LWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
+ -D LWS_USE_BUNDLED_ZLIB=OFF \
+ -D LWS_WITHOUT_BUILTIN_SHA1=ON \
+ -D LWS_WITH_STATIC=OFF \
+ -D LWS_WITHOUT_CLIENT=OFF \
+ -D LWS_WITHOUT_SERVER=OFF \
+ -D LWS_WITHOUT_TESTAPPS=OFF \
+ -D LWS_WITHOUT_TEST_SERVER=ON \
+ -D LWS_WITHOUT_TEST_SERVER_EXTPOLL=ON \
+ -D LWS_WITHOUT_TEST_PING=ON \
+ -D LWS_WITHOUT_TEST_CLIENT=ON .. && \
make -j $(nproc) && \
make install && \
ldconfig
diff --git a/CI/test_cases/container_cases/bigdata_stream.sh b/CI/test_cases/container_cases/bigdata_stream.sh
index 768e9703..1eae3df2 100755
--- a/CI/test_cases/container_cases/bigdata_stream.sh
+++ b/CI/test_cases/container_cases/bigdata_stream.sh
@@ -2,7 +2,7 @@
#
# attributes: isulad basic container stream exec start attach
# concurrent: NA
-# spend time: 6
+# spend time: 224
#######################################################################
##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved.
@@ -119,16 +119,16 @@ function test_concurrent_bigdata_stream()
declare -a pids
for index in $(seq 1 5); do
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M_$index &
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
for index in $(seq 1 5); do
- ls -l /tmp/iocopy_stream_data_500M_$index
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ ls -l /home/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M_$index)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
- rm -f /tmp/iocopy_stream_data_500M_$index
+ rm -f /home/iocopy_stream_data_500M_$index
done
check_last_status
@@ -146,16 +146,16 @@ function test_concurrent_bigdata_stream_without_pty()
declare -a pids
for index in $(seq 1 5); do
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ nohup isula exec $CID cat test_500M > /home/iocopy_stream_data_500M_$index &
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
for index in $(seq 1 5); do
- ls -l /tmp/iocopy_stream_data_500M_$index
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ ls -l /home/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M_$index)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
- rm -f /tmp/iocopy_stream_data_500M_$index
+ rm -f /home/iocopy_stream_data_500M_$index
done
check_last_status
@@ -175,16 +175,16 @@ function test_more_concurrent_stream()
isula exec -it $CID dd if=/dev/zero of=test_20M bs=1M count=20
for index in $(seq 1 30); do
- nohup isula exec -it $CID cat test_20M > /tmp/iocopy_stream_data_20M_$index &
+ nohup isula exec -it $CID cat test_20M > /home/iocopy_stream_data_20M_$index &
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
for index in $(seq 1 30); do
- ls -l /tmp/iocopy_stream_data_20M_$index
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_20M_$index)
+ ls -l /home/iocopy_stream_data_20M_$index
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_20M_$index)
[[ $total_size -ne 20971520 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
- rm -f /tmp/iocopy_stream_data_20M_$index
+ rm -f /home/iocopy_stream_data_20M_$index
done
check_last_status
@@ -200,7 +200,7 @@ function test_stream_with_stop_client()
local test="test_stream_with_stop_client => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
pid=$!
sleep 2
kill -19 $pid
@@ -209,8 +209,8 @@ function test_stream_with_stop_client()
wait $pid
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ ls -l /home/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
check_last_status
@@ -226,7 +226,7 @@ function test_stream_with_kill_client()
local test="test_stream_with_kill_client => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
pid=$!
sleep 5
kill -9 $pid
@@ -244,7 +244,7 @@ function test_stream_with_stop_attach()
local test="test_stream_with_stop_attach => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
exec_pid=$!
sleep 2
pid=$(ps aux | grep lxc-attach | grep $CID |grep "cat test_500M" | awk '{print $2}')
@@ -254,8 +254,8 @@ function test_stream_with_stop_attach()
wait $exec_pid
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ ls -l /home/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
check_last_status
@@ -271,7 +271,7 @@ function test_stream_with_kill_attach()
local test="test_stream_with_kill_client => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
sleep 3
pid=$(ps aux | grep lxc-attach | grep $CID |grep "cat test_500M" | awk '{print $2}')
kill -9 $pid
@@ -289,7 +289,7 @@ function test_stream_with_stop_lxc_monitor()
local test="test_stream_with_stop_lxc_monitor => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
exec_pid=$!
sleep 2
pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
@@ -299,8 +299,8 @@ function test_stream_with_stop_lxc_monitor()
wait $exec_pid
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ ls -l /home/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
check_last_status
@@ -316,7 +316,7 @@ function test_stream_with_kill_lxc_monitor()
local test="test_stream_with_kill_lxc_monitor => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
sleep 3
pid=$(ps aux | grep "lxc monitor" | grep $CID | awk '{print $2}')
kill -9 $pid
@@ -338,7 +338,7 @@ function test_stream_with_stop_isulad()
local test="test_stream_with_stop_isulad => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
pid=$!
sleep 2
kill -19 $(cat /var/run/isulad.pid)
@@ -347,8 +347,8 @@ function test_stream_with_stop_isulad()
wait $pid
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ ls -l /home/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
check_last_status
@@ -364,7 +364,7 @@ function test_stream_with_kill_isulad()
local test="test_stream_with_kill_isulad => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M &
sleep 3
isulad_pid=$(cat /var/run/isulad.pid)
kill -9 $isulad_pid
@@ -393,16 +393,16 @@ function test_stream_with_runc()
isula exec -it $RUNCID dd if=/dev/zero of=test_500M bs=1M count=500
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++))
- isula exec -it $RUNCID cat test_500M > /tmp/iocopy_stream_data_500M
+ isula exec -it $RUNCID cat test_500M > /home/iocopy_stream_data_500M
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cat bigdata" && ((ret++))
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
isula rm -f $RUNCID
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++))
- rm -rf /tmp/iocopy_stream_data_500M
+ rm -rf /home/iocopy_stream_data_500M
msg_info "${test} finished with return ${ret}..."
return ${ret}
@@ -414,7 +414,7 @@ function tear_down()
isula rm -f $CID
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container: $CID" && ((ret++))
- rm -rf //tmp/iocopy_stream_data_*
+ rm -rf //home/iocopy_stream_data_*
stop_isulad_without_valgrind
@@ -435,10 +435,10 @@ function test_memory_leak_with_bigdata_stream()
isula exec -it $CID dd if=/dev/zero of=test_100M bs=1M count=100
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++))
- isula exec -it $CID cat test_100M > /tmp/iocopy_stream_data_100M
+ isula exec -it $CID cat test_100M > /home/iocopy_stream_data_100M
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cat bigdata from container" && ((ret++))
- rm -rf /tmp/iocopy_stream_data_100M
+ rm -rf /home/iocopy_stream_data_100M
isula rm -f $CID
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++))
diff --git a/CI/test_cases/container_cases/bigdata_stream_runc.sh b/CI/test_cases/container_cases/bigdata_stream_runc.sh
index 1313774e..e5ae77a2 100755
--- a/CI/test_cases/container_cases/bigdata_stream_runc.sh
+++ b/CI/test_cases/container_cases/bigdata_stream_runc.sh
@@ -2,7 +2,7 @@
#
# attributes: isulad basic container stream exec start attach
# concurrent: NA
-# spend time: 6
+# spend time: 144
#######################################################################
##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved.
@@ -113,16 +113,16 @@ function test_cat_bigdata()
declare -a pids
for index in $(seq 1 5); do
- nohup isula exec -it $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ nohup isula exec -it $CID cat test_500M > /home/iocopy_stream_data_500M_$index &
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
for index in $(seq 1 5); do
- ls -l /tmp/iocopy_stream_data_500M_$index
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ ls -l /home/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M_$index)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
- rm -f /tmp/iocopy_stream_data_500M_$index
+ rm -f /home/iocopy_stream_data_500M_$index
done
check_last_status
@@ -140,16 +140,16 @@ function test_cat_bigdata_without_pty()
declare -a pids
for index in $(seq 1 5); do
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M_$index &
+ nohup isula exec $CID cat test_500M > /home/iocopy_stream_data_500M_$index &
pids[${#pids[@]}]=$!
done
wait ${pids[*]// /|}
for index in $(seq 1 5); do
- ls -l /tmp/iocopy_stream_data_500M_$index
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M_$index)
+ ls -l /home/iocopy_stream_data_500M_$index
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M_$index)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
- rm -f /tmp/iocopy_stream_data_500M_$index
+ rm -f /home/iocopy_stream_data_500M_$index
done
check_last_status
@@ -165,7 +165,7 @@ function test_stream_with_stop_client()
local test="test_stream_with_stop_client => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec $CID cat test_500M > /home/iocopy_stream_data_500M &
pid=$!
sleep 2
kill -19 $pid
@@ -174,8 +174,8 @@ function test_stream_with_stop_client()
wait $pid
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ ls -l /home/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
check_last_status
@@ -191,7 +191,7 @@ function test_stream_with_kill_client()
local test="test_stream_with_kill_client => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec $CID cat test_500M > /home/iocopy_stream_data_500M &
pid=$!
sleep 5
kill -9 $pid
@@ -209,7 +209,7 @@ function test_stream_with_stop_isulad()
local test="test_stream_with_stop_isulad => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec $CID cat test_500M > /home/iocopy_stream_data_500M &
pid=$!
sleep 2
kill -19 $(cat /var/run/isulad.pid)
@@ -218,8 +218,8 @@ function test_stream_with_stop_isulad()
wait $pid
- ls -l /tmp/iocopy_stream_data_500M
- total_size=$(stat -c"%s" /tmp/iocopy_stream_data_500M)
+ ls -l /home/iocopy_stream_data_500M
+ total_size=$(stat -c"%s" /home/iocopy_stream_data_500M)
[[ $total_size -ne 524288000 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stream iocopy loss data" && ((ret++))
check_last_status
@@ -235,7 +235,7 @@ function test_stream_with_kill_isulad()
local test="test_stream_with_kill_isulad => (${FUNCNAME[@]})"
msg_info "${test} starting..."
- nohup isula exec $CID cat test_500M > /tmp/iocopy_stream_data_500M &
+ nohup isula exec $CID cat test_500M > /home/iocopy_stream_data_500M &
sleep 3
isulad_pid=$(cat /var/run/isulad.pid)
kill -9 $isulad_pid
@@ -259,7 +259,7 @@ function tear_down()
isula rm -f $CID
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container: $CID" && ((ret++))
- rm -rf //tmp/iocopy_stream_data_*
+ rm -rf //home/iocopy_stream_data_*
stop_isulad_without_valgrind
@@ -280,10 +280,10 @@ function test_memory_leak_with_bigdata_stream()
isula exec -it $CID dd if=/dev/zero of=test_100M bs=1M count=100
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to create bigdata" && ((ret++))
- isula exec -it $CID cat test_100M > /tmp/iocopy_stream_data_100M
+ isula exec -it $CID cat test_100M > /home/iocopy_stream_data_100M
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to cat bigdata from container" && ((ret++))
- rm -rf /tmp/iocopy_stream_data_100M
+ rm -rf /home/iocopy_stream_data_100M
isula rm -f $CID
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++))
--
2.25.1

View File

@ -1,41 +0,0 @@
From 68147c64b7dc1f9ef149781e4c10d37b0b2c59f5 Mon Sep 17 00:00:00 2001
From: yinxiujiang <yinxiujiang@kylinos.cn>
Date: Wed, 21 Apr 2021 09:33:05 +0800
Subject: [PATCH 079/104] added default completion
---
src/contrib/completion/isula | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/contrib/completion/isula b/src/contrib/completion/isula
index 305c5150..a12d90a5 100644
--- a/src/contrib/completion/isula
+++ b/src/contrib/completion/isula
@@ -65,6 +65,10 @@ _isula_isula() {
esac
}
+_isula_default()
+{
+ COMPREPLY=( $( compgen -d -f -- $cur ) )
+}
_isula() {
COMPREPLY=()
@@ -81,9 +85,12 @@ _isula() {
#The completion of the secondary command will be added later
if [ $cword -lt 2 ] ; then
- declare -F $completions_func >/dev/null && $completions_func
+ completions_func=_isula_${command//-/_}
+ else
+ completions_func=_isula_default
fi
+ declare -F $completions_func >/dev/null && $completions_func
return 0
}
--
2.25.1

View File

@ -1,80 +0,0 @@
From 6259cabf9ae7560f64cfab86cf32b77d0ca8cd79 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 22 Apr 2021 17:30:06 +0800
Subject: [PATCH 080/104] fix coredump when poweroff
when doing poweroff cpu are downing and we may
got aviable cpus less then sysinfo->ncpus which
we got when system startup. It can cause crash.
now we use const sysinfo->ncpus to check to
avoid crash.
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/daemon/modules/spec/verify.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c
index 2a73f7c1..57501cde 100644
--- a/src/daemon/modules/spec/verify.c
+++ b/src/daemon/modules/spec/verify.c
@@ -556,7 +556,7 @@ static bool check_cpu(const char *provided, const char *available)
}
/* parse unit list */
-int parse_unit_list(const char *val, bool *available_list)
+int parse_unit_list(const char *val, bool *available_list, int cpu_num)
{
int ret = -1;
char *str = NULL;
@@ -576,7 +576,7 @@ int parse_unit_list(const char *val, bool *available_list)
subchr = strchr(tmp, '-');
if (subchr == NULL) {
int value = 0;
- if (util_safe_int(tmp, &value) || value < 0) {
+ if (util_safe_int(tmp, &value) || value < 0 || value >= cpu_num) {
goto out;
}
available_list[value] = true;
@@ -588,7 +588,7 @@ int parse_unit_list(const char *val, bool *available_list)
if (util_safe_int(tmp, &min) || min < 0) {
goto out;
}
- if (util_safe_int(subchr, &max) || max < 0) {
+ if (util_safe_int(subchr, &max) || max < 0 || max >= cpu_num) {
goto out;
}
for (i = min; i <= max; i++) {
@@ -615,12 +615,15 @@ static bool is_cpuset_list_available(const char *provided, const char *available
bool ret = false;
bool *parsed_provided = NULL;
bool *parsed_available = NULL;
+ sysinfo_t *sysinfo = NULL;
- cpu_num = get_nprocs();
- if (cpu_num <= 0) {
- ERROR("failed to get the number of processors configured by the operating system!");
- goto out;
+ sysinfo = get_sys_info(true);
+ if (sysinfo == NULL) {
+ ERROR("get sysinfo failed");
+ return false;
}
+
+ cpu_num = sysinfo->ncpus;
if ((size_t)cpu_num > SIZE_MAX / sizeof(bool)) {
ERROR("invalid cpu num");
goto out;
@@ -640,7 +643,8 @@ static bool is_cpuset_list_available(const char *provided, const char *available
goto out;
}
- if (parse_unit_list(provided, parsed_provided) < 0 || parse_unit_list(available, parsed_available) < 0) {
+ if (parse_unit_list(provided, parsed_provided, cpu_num) < 0 ||
+ parse_unit_list(available, parsed_available, cpu_num) < 0) {
goto out;
}
for (i = 0; i < cpu_num; i++) {
--
2.25.1

View File

@ -1,36 +0,0 @@
From d6cc390f40a2c3eb0c37a1ea13634c4c33c81362 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Fri, 23 Apr 2021 09:40:13 +0800
Subject: [PATCH 081/104] CI: keep container when build failed for debug
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
CI/build.sh | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/CI/build.sh b/CI/build.sh
index 2c535c70..cf7691d9 100755
--- a/CI/build.sh
+++ b/CI/build.sh
@@ -473,12 +473,12 @@ if [[ -e $CIDIR/${CONTAINER_NAME}.runflag ]]; then
rm -rf /var/lib/isulad/${CONTAINER_NAME}_cptemp
exit 0;
else
- for container in ${containers[@]}
- do
- docker rm -f $container
- rm -rf /var/lib/isulad/$container
- done
- rm -rf /var/lib/isulad/${CONTAINER_NAME}_cptemp
+ #for container in ${containers[@]}
+ #do
+ # docker rm -f $container
+ # rm -rf /var/lib/isulad/$container
+ #done
+ #rm -rf /var/lib/isulad/${CONTAINER_NAME}_cptemp
echo_error "Test failed!"
exit -1;
fi
--
2.25.1

View File

@ -1,85 +0,0 @@
From c1f5f82a2e02597ac2c486caed1bf56b6467ad87 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Fri, 23 Apr 2021 14:47:34 +0800
Subject: [PATCH 082/104] devmapper: decrease log level of check dm device
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../storage/layer_store/graphdriver/devmapper/deviceset.c | 6 +++---
.../layer_store/graphdriver/devmapper/wrapper_devmapper.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index 3a271c3a..6ed546bc 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -437,7 +437,7 @@ static image_devmapper_device_info *load_metadata(const struct device_set *devse
}
if (!util_file_exists(metadata_file)) {
- ERROR("No such file:%s, need not to load", metadata_file);
+ WARN("No such file:%s, need not to load", metadata_file);
goto out;
}
@@ -2405,6 +2405,7 @@ static int do_check_all_devices(struct device_set *devset)
struct stat st;
int nret = 0;
+ // Equal to "dmsetup ls" . That is to say, devices_len is not zero, because isulad-thinpool exists.
if (dev_get_device_list(&devices_list, &devices_len) != 0) {
ERROR("devicemapper: failed to get device list");
ret = -1;
@@ -2511,10 +2512,9 @@ static int do_devmapper_init(struct device_set *devset)
goto out;
}
+ // If checking failed, we just print a log, there is no need to process the error that do not affect isulad starting
if (do_check_all_devices(devset) != 0) {
ERROR("Failed to check all devset devices");
- ret = -1;
- goto out;
}
if (do_init_metadate(devset) != 0) {
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
index 38ed5615..07d64318 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
@@ -556,8 +556,6 @@ out:
return ret;
}
-// from devmapper_wrapper.go
-// FIXME: how to use dm_task_get_names directly
static char **local_dm_task_get_names(struct dm_task *dmt, size_t *size)
{
struct dm_names *ns, *ns1;
@@ -566,6 +564,7 @@ static char **local_dm_task_get_names(struct dm_task *dmt, size_t *size)
int i = 0;
if (!(ns = dm_task_get_names(dmt))) {
+ ERROR("Failed to get device names list from dm task");
return NULL;
}
@@ -585,6 +584,7 @@ static char **local_dm_task_get_names(struct dm_task *dmt, size_t *size)
result = malloc(sizeof(char *) * (*size));
if (!result) {
+ ERROR("Out of memory");
return NULL;
}
@@ -624,7 +624,7 @@ int dev_get_device_list(char ***list, size_t *length)
*list = local_dm_task_get_names(dmt, length);
if (*list == NULL) {
*length = 0;
- ERROR("devicemapper: get device list failed");
+ ERROR("devicemapper: get device list empty");
ret = -1;
goto cleanup;
}
--
2.25.1

View File

@ -1,206 +0,0 @@
From 3347d4d8de7599f3b186bfcd893aca89d1328563 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Wed, 21 Apr 2021 20:26:09 +0800
Subject: [PATCH 083/104] fix bugs when pulling image
1. service in Www-Authenticate may have space, do not split it
2. if url have space, we need to translate it
3. fill diffid if reuse cached layer
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
.../modules/image/oci/registry/registry.c | 10 ++++
.../image/oci/registry/registry_apiv2.c | 24 ++++----
src/utils/http/http.c | 57 ++++++++++++++++++-
3 files changed, 80 insertions(+), 11 deletions(-)
diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c
index 1bb91d0f..bd8e8fd0 100644
--- a/src/daemon/modules/image/oci/registry/registry.c
+++ b/src/daemon/modules/image/oci/registry/registry.c
@@ -389,6 +389,7 @@ static int add_cached_layer(char *blob_digest, char *file, thread_fetch_info *in
cached_layer *cache = NULL;
struct linked_list *node = NULL;
char *src_file = NULL;
+ thread_fetch_info *src_info = NULL;
file_elem *elem = {NULL};
pull_descriptor *desc = info->desc;
@@ -430,6 +431,12 @@ static int add_cached_layer(char *blob_digest, char *file, thread_fetch_info *in
goto out;
}
src_file = ((file_elem*)elem)->file;
+ src_info = ((file_elem*)elem)->info;
+ if (src_info == NULL) {
+ ERROR("source info is NULL, this should never happen");
+ ret = -1;
+ goto out;
+ }
if (link(src_file, file) != 0) {
ERROR("link %s to %s failed: %s", src_file, file, strerror(errno));
@@ -438,6 +445,9 @@ static int add_cached_layer(char *blob_digest, char *file, thread_fetch_info *in
}
// As layer have already downloaded, set this flag to let register thread to do register
info->notified = true;
+ if (info->diffid == NULL) {
+ info->diffid = util_strdup_s(src_info->diffid);
+ }
} else {
ERROR("cached layer have result %d", cache->result);
ret = -1;
diff --git a/src/daemon/modules/image/oci/registry/registry_apiv2.c b/src/daemon/modules/image/oci/registry/registry_apiv2.c
index 935aa4d6..b26e42ba 100644
--- a/src/daemon/modules/image/oci/registry/registry_apiv2.c
+++ b/src/daemon/modules/image/oci/registry/registry_apiv2.c
@@ -162,27 +162,32 @@ static int parse_auth(pull_descriptor *desc, char *auth)
char *origin_tmp_auth = NULL;
char *trimmed_auth = NULL;
int ret = 0;
- char **parts = NULL;
+ char *schema = NULL;
+ char *params = NULL;
if (auth == NULL) {
return -1;
}
+ // auth: Bearer realm="https://auth.isula.org/token",service="isula registry"
origin_tmp_auth = util_strdup_s(auth);
util_trim_newline(origin_tmp_auth);
trimmed_auth = util_trim_space(origin_tmp_auth);
- parts = util_string_split_multi(trimmed_auth, ' ');
- if (util_array_len((const char **)parts) < 2) {
- ERROR("Split auth failed, auth: %s", trimmed_auth);
+ params = strchr(trimmed_auth, ' ');
+ if (params == NULL) {
+ ERROR("invalid auth when parse challenges, auth: %s", trimmed_auth);
ret = -1;
goto out;
}
+ // params: realm="https://auth.isula.org/token",service="isula registry"
+ params[0] = 0;
+ params += 1;
+ // schema: Bearer
+ schema = trimmed_auth;
- // parts[0]: Bearer
- // parts[1]: realm="https://auth.isula.org/token",service="registry.isula.org"
- ret = parse_challenges(desc, parts[0], parts[1]);
+ ret = parse_challenges(desc, schema, params);
if (ret != 0) {
- ERROR("Parse challenges failed, schema: %s, params: %s", parts[0], parts[1]);
+ ERROR("Parse challenges failed, schema: %s, params: %s", schema, params);
ret = -1;
goto out;
}
@@ -190,7 +195,6 @@ static int parse_auth(pull_descriptor *desc, char *auth)
out:
free(origin_tmp_auth);
origin_tmp_auth = NULL;
- util_free_array(parts);
return ret;
}
@@ -268,7 +272,7 @@ static int parse_ping_header(pull_descriptor *desc, char *http_head)
HTTP/1.1 401 Unauthorized
Content-Type: application/json
Docker-Distribution-Api-Version: registry/2.0
- Www-Authenticate: Bearer realm="https://auth.isula.org/token",service="registry.isula.org"
+ Www-Authenticate: Bearer realm="https://auth.isula.org/token",service="isula registry"
Date: Mon, 16 Mar 2020 01:16:09 GMT
Content-Length: 87
Strict-Transport-Security: max-age=31536000
diff --git a/src/utils/http/http.c b/src/utils/http/http.c
index bf9b8ab2..e502bb83 100644
--- a/src/utils/http/http.c
+++ b/src/utils/http/http.c
@@ -337,6 +337,53 @@ static struct curl_slist *set_custom_header(CURL *curl_handle, const struct http
return chunk;
}
+static size_t calc_replaced_url_len(const char *url)
+{
+ size_t i = 0;
+ size_t size = 0;
+ size_t max = 0;
+ size = strlen(url);
+
+ for (i = 0; i < size; i++) {
+ if (url[i] != ' ') {
+ max++;
+ continue;
+ }
+ max += 3; /* ' ' to %20 so size should add 3 */
+ }
+
+ return max + 1; /* +1 for terminator */
+}
+
+static char *replace_url(const char *url)
+{
+ size_t i = 0;
+ size_t pos = 0;
+ size_t size = 0;
+ size_t max = 0;
+ char *replaced_url = NULL;
+
+ size = strlen(url);
+ max = calc_replaced_url_len(url);
+ replaced_url = util_common_calloc_s(max);
+ if (replaced_url == NULL) {
+ ERROR("out of memory");
+ return NULL;
+ }
+
+ for (i = 0; i < size; i++) {
+ if (url[i] != ' ') {
+ *(replaced_url + pos) = url[i];
+ pos++;
+ continue;
+ }
+ (void)strcat(replaced_url + pos, "%20");
+ pos += 3; /* ' ' to %20 so multiply 3 */
+ }
+
+ return replaced_url;
+}
+
int http_request(const char *url, struct http_get_options *options, long *response_code, int recursive_len)
{
#define MAX_REDIRCT_NUMS 32
@@ -352,6 +399,7 @@ int http_request(const char *url, struct http_get_options *options, long *respon
char *redir_url = NULL;
char *tmp = NULL;
size_t fsize = 0;
+ char *replaced_url = 0;
if (recursive_len + 1 >= MAX_REDIRCT_NUMS) {
ERROR("reach the max redirect num");
@@ -364,8 +412,14 @@ int http_request(const char *url, struct http_get_options *options, long *respon
return -1;
}
+ replaced_url = replace_url(url);
+ if (replaced_url == NULL) {
+ ret = -1;
+ goto out;
+ }
+
/* set URL to get here */
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
+ curl_easy_setopt(curl_handle, CURLOPT_URL, replaced_url);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1L);
/* complete connection within 30 seconds */
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30L);
@@ -417,6 +471,7 @@ int http_request(const char *url, struct http_get_options *options, long *respon
}
out:
+ free(replaced_url);
close_file(pagefile);
free_rpath(rpath);
--
2.25.1

View File

@ -1,55 +0,0 @@
From 1fb316f5e3ef84e57c40625d69a6aa900b978b83 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 22 Apr 2021 10:45:43 +0800
Subject: [PATCH 084/104] add testcase for pulling image
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
CI/test_cases/image_cases/registry.sh | 3 +++
test/image/oci/registry/data/v1/ping_head | 2 +-
test/image/oci/registry/registry_ut.cc | 4 ++++
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/CI/test_cases/image_cases/registry.sh b/CI/test_cases/image_cases/registry.sh
index c0a0db05..332af223 100755
--- a/CI/test_cases/image_cases/registry.sh
+++ b/CI/test_cases/image_cases/registry.sh
@@ -74,6 +74,9 @@ function isula_pull()
isula run --rm -ti busybox echo hello 2>&1 | grep pulling
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - --pull missing failed" && ((ret++))
+ isula pull hub.c.163.com/public/centos:6.7-tools
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - --pull hub.c.163.com/public/centos:6.7-tools failed" && ((ret++))
+
isula pull 3laho3y3.mirror.aliyuncs.com/library/busybox
fn_check_eq "$?" "0" "isula pull 3laho3y3.mirror.aliyuncs.com/library/busybox"
diff --git a/test/image/oci/registry/data/v1/ping_head b/test/image/oci/registry/data/v1/ping_head
index b0a076db..0d6a01c7 100644
--- a/test/image/oci/registry/data/v1/ping_head
+++ b/test/image/oci/registry/data/v1/ping_head
@@ -5,5 +5,5 @@ Content-Type: text/html; charset=utf-8
Content-Length: 4
Connection: close
Docker-Distribution-API-Version: registry/2.0
-WWW-Authenticate: Bearer realm="https://auth.quay.io",service="quay.io"
+WWW-Authenticate: Bearer realm="https://auth.quay.io",service="quay.io registry"
diff --git a/test/image/oci/registry/registry_ut.cc b/test/image/oci/registry/registry_ut.cc
index 182e28aa..fc944a5f 100644
--- a/test/image/oci/registry/registry_ut.cc
+++ b/test/image/oci/registry/registry_ut.cc
@@ -143,6 +143,10 @@ int invokeHttpRequestV1(const char *url, struct http_get_options *options, long
if (token_count == 2) {
file = data_path + "token_body2";
} else {
+ if (strstr(url, "quay.io registry") == NULL) {
+ ERROR("invalid url %s", url);
+ return -1;
+ }
file = data_path + "token_body";
}
} else if (util_has_prefix(url, "https://quay.io/v2/coreos/etcd/blobs/sha256")) {
--
2.25.1

View File

@ -1,84 +0,0 @@
From 64ba80d5f9faec9a0a6400fd5f4e21943271cf03 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Fri, 23 Apr 2021 15:35:13 +0800
Subject: [PATCH 085/104] check return value to valid use NULL pointer
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/cmd/isula/isula_host_spec.c | 5 +++++
.../modules/image/oci/storage/image_store/image_store.c | 8 +++++++-
src/daemon/modules/spec/specs.c | 2 +-
src/utils/http/certificate.c | 4 ++++
4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/cmd/isula/isula_host_spec.c b/src/cmd/isula/isula_host_spec.c
index 1a2ad4ed..85451dd4 100644
--- a/src/cmd/isula/isula_host_spec.c
+++ b/src/cmd/isula/isula_host_spec.c
@@ -1021,6 +1021,11 @@ static int parse_security_opts(const isula_host_config_t *srcconfig, host_config
for (i = 0; i < srcconfig->security_len; i++) {
items = util_string_split_n(srcconfig->security[i], '=', 2);
+ if (items == NULL) {
+ COMMAND_ERROR("Invalid --security-opt: %s", srcconfig->security[i]);
+ ret = -1;
+ goto out;
+ }
if (util_array_len((const char **)items) == 1) {
if (strcmp(items[0], "no-new-privileges") != 0) {
ret = -1;
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c
index 83345ab3..9db158d4 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c
@@ -2089,6 +2089,12 @@ static int pack_repo_digest(char ***old_repo_digests, const char **image_tags, c
continue;
}
tag_pos = util_tag_pos(ref);
+ if (tag_pos == NULL) {
+ ERROR("invalid ref %s", ref);
+ free(ref);
+ ref = NULL;
+ continue;
+ }
*tag_pos = '\0';
nret = asprintf(&tmp_repo_digests, "%s@%s", ref, digest);
@@ -3581,4 +3587,4 @@ out:
}
free(root_dir);
return ret;
-}
\ No newline at end of file
+}
diff --git a/src/daemon/modules/spec/specs.c b/src/daemon/modules/spec/specs.c
index d056b005..d8d05ba0 100644
--- a/src/daemon/modules/spec/specs.c
+++ b/src/daemon/modules/spec/specs.c
@@ -1929,7 +1929,7 @@ static int generate_security_opt(host_config *hc)
for (i = 0; i < hc->security_opt_len; i++) {
char **items = util_string_split(hc->security_opt[i], '=');
- if (*items == NULL) {
+ if (items == NULL) {
ERROR("Out of memory");
return -1;
}
diff --git a/src/utils/http/certificate.c b/src/utils/http/certificate.c
index 117bc15c..64f35bdb 100644
--- a/src/utils/http/certificate.c
+++ b/src/utils/http/certificate.c
@@ -49,6 +49,10 @@ static void check_algo(X509 *cert)
}
const char *sig_algo = OBJ_nid2ln(OBJ_obj2nid(cert->sig_alg->algorithm));
#endif
+ if (sig_algo == NULL) {
+ ERROR("sig algo is NULL");
+ return;
+ }
for (i = 0; i < len; i++) {
if (strcmp(g_weak_algos[i], sig_algo) == 0) {
--
2.25.1

View File

@ -1,192 +0,0 @@
From a86e5ede7866a18c681ab95d83cc3ae875a71930 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Mon, 26 Apr 2021 10:09:46 +0800
Subject: [PATCH 086/104] move reinstall_thinpool to helper.sh
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
.../container_cases/graph_root_test.sh | 38 ---------
.../container_cases/storage_opts_dm.sh | 30 -------
CI/test_cases/helpers.sh | 79 +++++++++++++++++++
3 files changed, 79 insertions(+), 68 deletions(-)
diff --git a/CI/test_cases/container_cases/graph_root_test.sh b/CI/test_cases/container_cases/graph_root_test.sh
index 678d176e..4beb5d9e 100644
--- a/CI/test_cases/container_cases/graph_root_test.sh
+++ b/CI/test_cases/container_cases/graph_root_test.sh
@@ -22,44 +22,6 @@
declare -r curr_path=$(dirname $(readlink -f "$0"))
source ../helpers.sh
-function reinstall_thinpool()
-{
- local ret=0
-
- cat /etc/isulad/daemon.json | grep driver | grep devicemapper
- if [[ $? -ne 0 ]]; then
- return ${ret}
- fi
-
- dev_disk=`pvs | grep isulad | awk '{print$1}'`
- rm -rf /var/lib/isulad/*
- dmsetup remove_all
- lvremove -f isulad/thinpool
- lvremove -f isulad/thinpoolmeta
- vgremove -f isulad
- pvremove -f $dev_disk
- mount | grep $dev_disk | grep /var/lib/isulad
- if [ x"$?" == x"0" ]; then
- umount /var/lib/isulad
- fi
- touch /etc/lvm/profile/isulad-thinpool.profile
- cat > /etc/lvm/profile/isulad-thinpool.profile <<EOF
-activation {
-thin_pool_autoextend_threshold=80
-thin_pool_autoextend_percent=20
-}
-EOF
- echo y | mkfs.ext4 $dev_disk
- pvcreate -y $dev_disk
- vgcreate isulad $dev_disk
- echo y | lvcreate --wipesignatures y -n thinpool isulad -l 80%VG
- echo y | lvcreate --wipesignatures y -n thinpoolmeta isulad -l 1%VG
- lvconvert -y --zero n -c 512K --thinpool isulad/thinpool --poolmetadata isulad/thinpoolmeta
- lvchange --metadataprofile isulad-thinpool isulad/thinpool
- lvs -o+seg_monitor
- return ${ret}
-}
-
function test_run_root_dir_realpath()
{
local ret=0
diff --git a/CI/test_cases/container_cases/storage_opts_dm.sh b/CI/test_cases/container_cases/storage_opts_dm.sh
index e0f476fe..c90eab7a 100755
--- a/CI/test_cases/container_cases/storage_opts_dm.sh
+++ b/CI/test_cases/container_cases/storage_opts_dm.sh
@@ -24,36 +24,6 @@ data_path=$(realpath $curr_path/../data)
source ../helpers.sh
image_busybox="busybox"
-function reinstall_thinpool()
-{
- dev_disk=`pvs | grep isulad | awk '{print$1}'`
- rm -rf /var/lib/isulad/*
- dmsetup remove_all
- lvremove -f isulad/thinpool
- lvremove -f isulad/thinpoolmeta
- vgremove -f isulad
- pvremove -f $dev_disk
- mount | grep $dev_disk | grep /var/lib/isulad
- if [ x"$?" == x"0" ]; then
- umount /var/lib/isulad
- fi
- touch /etc/lvm/profile/isulad-thinpool.profile
- cat > /etc/lvm/profile/isulad-thinpool.profile <<EOF
-activation {
-thin_pool_autoextend_threshold=80
-thin_pool_autoextend_percent=20
-}
-EOF
- echo y | mkfs.ext4 $dev_disk
- pvcreate -y $dev_disk
- vgcreate isulad $dev_disk
- echo y | lvcreate --wipesignatures y -n thinpool isulad -l 80%VG
- echo y | lvcreate --wipesignatures y -n thinpoolmeta isulad -l 1%VG
- lvconvert -y --zero n -c 512K --thinpool isulad/thinpool --poolmetadata isulad/thinpoolmeta
- lvchange --metadataprofile isulad-thinpool isulad/thinpool
- lvs -o+seg_monitor
-}
-
function do_pre()
{
local ret=0
diff --git a/CI/test_cases/helpers.sh b/CI/test_cases/helpers.sh
index fe256e8c..7f4a286d 100755
--- a/CI/test_cases/helpers.sh
+++ b/CI/test_cases/helpers.sh
@@ -191,3 +191,82 @@ function init_cni_conf()
return $TC_RET_T
}
+
+function do_install_thinpool()
+{
+ local ret=0
+
+ dev_disk=`pvs | grep isulad | awk '{print$1}'`
+ rm -rf /var/lib/isulad/*
+ dmsetup remove_all
+ lvremove -f isulad/thinpool
+ lvremove -f isulad/thinpoolmeta
+ vgremove -f isulad
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - vgremove failed" && ((ret++))
+
+ pvremove -f $dev_disk
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - pvremove failed" && ((ret++))
+
+ mount | grep $dev_disk | grep /var/lib/isulad
+ if [ x"$?" == x"0" ]; then
+ umount /var/lib/isulad
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - umount isulad failed" && ((ret++))
+ fi
+ touch /etc/lvm/profile/isulad-thinpool.profile
+ cat > /etc/lvm/profile/isulad-thinpool.profile <<EOF
+activation {
+thin_pool_autoextend_threshold=80
+thin_pool_autoextend_percent=20
+}
+EOF
+ echo y | mkfs.ext4 $dev_disk
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - mkfs.ext4 $dev_disk failed" && ((ret++))
+
+ pvcreate -y $dev_disk
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - vgremove isulad failed" && ((ret++))
+
+ vgcreate isulad $dev_disk
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - vgremove isulad failed" && ((ret++))
+
+ echo y | lvcreate --wipesignatures y -n thinpool isulad -l 80%VG
+ echo y | lvcreate --wipesignatures y -n thinpoolmeta isulad -l 1%VG
+
+ dmsetup status | grep -w "isulad-thinpoolmeta"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - isulad-thinpoolmeta: no such device" && ((ret++))
+
+ dmsetup status | grep -w "isulad-thinpool"
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - isulad-thinpool: no such device" && ((ret++))
+
+ lvconvert -y --zero n -c 512K --thinpool isulad/thinpool --poolmetadata isulad/thinpoolmeta
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - lvconvert failed" && ((ret++))
+
+ lvchange --metadataprofile isulad-thinpool isulad/thinpool
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - lvchange failed" && ((ret++))
+
+ lvs -o+seg_monitor
+
+ return $ret
+}
+
+# Delete all containers and stop isulad before executing this func
+function reinstall_thinpool()
+{
+ retry_limit=3
+ retry_interval=2
+ state="fail"
+
+ for i in $(seq 1 "$retry_limit"); do
+ do_install_thinpool
+ if [ $? -eq 0 ]; then
+ state="success"
+ break;
+ fi
+ sleep $retry_interval
+ done
+
+ if [ "$state" != "success" ]; then
+ return 1
+ fi
+ return 0
+}
+
--
2.25.1

View File

@ -1,46 +0,0 @@
From 7a940c14658909a081bbcfa8c05c9cc05b191bce Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Mon, 26 Apr 2021 15:06:35 +0800
Subject: [PATCH 087/104] CI:activate vg isulad
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
CI/test_cases/helpers.sh | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/CI/test_cases/helpers.sh b/CI/test_cases/helpers.sh
index 7f4a286d..c8e7bb8a 100755
--- a/CI/test_cases/helpers.sh
+++ b/CI/test_cases/helpers.sh
@@ -196,6 +196,10 @@ function do_install_thinpool()
{
local ret=0
+ systemctl restart lvm2-lvmetad.service
+ systemctl restart systemd-udevd.service
+ udevadm control --reload-rules && udevadm trigger
+
dev_disk=`pvs | grep isulad | awk '{print$1}'`
rm -rf /var/lib/isulad/*
dmsetup remove_all
@@ -240,6 +244,8 @@ EOF
lvconvert -y --zero n -c 512K --thinpool isulad/thinpool --poolmetadata isulad/thinpoolmeta
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - lvconvert failed" && ((ret++))
+ lvchange --activate ay isulad
+
lvchange --metadataprofile isulad-thinpool isulad/thinpool
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - lvchange failed" && ((ret++))
@@ -251,7 +257,7 @@ EOF
# Delete all containers and stop isulad before executing this func
function reinstall_thinpool()
{
- retry_limit=3
+ retry_limit=10
retry_interval=2
state="fail"
--
2.25.1

View File

@ -1,31 +0,0 @@
From 4e9f8ec1f3229e6992ab2750fac61a062bae64ed Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Tue, 27 Apr 2021 16:31:08 +0800
Subject: [PATCH 088/104] CI devicemapper add filter
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
CI/test_cases/helpers.sh | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/CI/test_cases/helpers.sh b/CI/test_cases/helpers.sh
index c8e7bb8a..d40e61d9 100755
--- a/CI/test_cases/helpers.sh
+++ b/CI/test_cases/helpers.sh
@@ -196,9 +196,10 @@ function do_install_thinpool()
{
local ret=0
- systemctl restart lvm2-lvmetad.service
- systemctl restart systemd-udevd.service
- udevadm control --reload-rules && udevadm trigger
+ cat /etc/isulad/daemon.json | grep driver | grep devicemapper
+ if [[ $? -ne 0 ]]; then
+ return ${ret}
+ fi
dev_disk=`pvs | grep isulad | awk '{print$1}'`
rm -rf /var/lib/isulad/*
--
2.25.1

View File

@ -1,555 +0,0 @@
From 8048944dcc7a23be2a449dc597abe8f82c02fa05 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 21 Jan 2021 11:12:49 +0800
Subject: [PATCH 089/104] syslog tag support dynamic tag values
1. {{.ID}} : first 12 character of the container id
2. {{.FullID}} : full container id
3. {{.Name}} : container name
4. {{.ImageID}} : first 12 character of container's image id
5. {{.ImageFullID}} : container's image id
6. {{.ImageName}} : container's image name
7. {{.DaemonName}} : name of isulad program 'iSulad'
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/cmd/options/opt_log.c | 68 +++++
src/cmd/options/opt_log.h | 13 +
.../executor/container_cb/execution_create.c | 247 +++++++++++++++---
.../graphdriver/devmapper/deviceset.c | 2 +-
4 files changed, 289 insertions(+), 41 deletions(-)
diff --git a/src/cmd/options/opt_log.c b/src/cmd/options/opt_log.c
index f6c18b23..c11792f3 100644
--- a/src/cmd/options/opt_log.c
+++ b/src/cmd/options/opt_log.c
@@ -25,6 +25,7 @@
#include "utils_array.h"
#include "utils_convert.h"
#include "utils_string.h"
+#include "buffer.h"
#define DRIVER_MAX 2
@@ -160,6 +161,7 @@ bool parse_container_log_opt(const char *key, const char *val, json_map_string_s
}
}
nret = append_json_map_string_string(opts, support_parsers[i].real_key, parsed_val);
+ free(parsed_val);
return true;
}
}
@@ -274,3 +276,69 @@ bool check_opt_container_log_driver(const char *driver)
return false;
}
+int parse_container_log_opt_syslog_tag(const char *tag, tag_parser op, map_t *tag_maps, char **parsed_tag)
+{
+ Buffer *bf = NULL;
+ char *work_tag = NULL;
+ char *prefix = NULL;
+ char *curr = NULL;
+ int ret = 0;
+
+ if (tag == NULL || op == NULL || parsed_tag == NULL) {
+ ERROR("Invalid arguments");
+ return -1;
+ }
+ bf = buffer_alloc(strlen(tag));
+ if (bf == NULL) {
+ ERROR("Out of memory");
+ return -1;
+ }
+
+ work_tag = util_strdup_s(tag);
+ prefix = work_tag;
+ while (prefix != NULL && strlen(prefix) != 0) {
+ char *parsed_item = NULL;
+ curr = strstr(prefix, "{{");
+ if (curr == NULL) {
+ ret = buffer_append(bf, prefix, strlen(prefix));
+ break;
+ }
+ *curr = '\0';
+ ret = buffer_append(bf, prefix, strlen(prefix));
+ if (ret != 0) {
+ ERROR("OUt of memory");
+ goto out;
+ }
+ *curr = '{';
+
+ curr = curr + 2;
+ prefix = strstr(curr, "}}");
+ if (prefix == NULL) {
+ ERROR("invalid tag item: %s", tag);
+ ret = -1;
+ goto out;
+ }
+ // get item in '{{' and '}}', to parse to expected string
+ *prefix = '\0';
+ if (op(curr, tag_maps, &parsed_item) != 0) {
+ ERROR("invalid tag item: %s", tag);
+ ret = -1;
+ goto out;
+ }
+ DEBUG("parse syslog tag item: %s --> %s", curr, parsed_item);
+ *prefix = '}';
+ ret = buffer_append(bf, parsed_item, strlen(parsed_item));
+ free(parsed_item);
+ if (ret != 0) {
+ ERROR("OUt of memory");
+ goto out;
+ }
+ prefix = prefix + 2;
+ }
+
+ *parsed_tag = util_strdup_s(bf->contents);
+out:
+ buffer_free(bf);
+ free(work_tag);
+ return ret;
+}
\ No newline at end of file
diff --git a/src/cmd/options/opt_log.h b/src/cmd/options/opt_log.h
index f9daa02d..d87851b0 100644
--- a/src/cmd/options/opt_log.h
+++ b/src/cmd/options/opt_log.h
@@ -17,11 +17,22 @@
#include <stdbool.h>
#include <isula_libutils/json_common.h>
+#include "map.h"
#ifdef __cplusplus
extern "C" {
#endif
+struct logger_info {
+ char *id;
+ char *name;
+ char *img_id;
+ char *img_name;
+ char *daemon_name;
+};
+
+typedef int (*tag_parser)(const char *, map_t *, char **);
+
bool check_raw_log_opt(const char *key);
bool check_opt_container_log_opt(const char *driver, const char *opt);
@@ -32,6 +43,8 @@ bool parse_container_log_opt(const char *key, const char *val, json_map_string_s
bool parse_container_log_opts(json_map_string_string **opts);
+int parse_container_log_opt_syslog_tag(const char *tag, tag_parser op, map_t *tag_maps, char **parsed_tag);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
index 9136348e..71d29b2c 100644
--- a/src/daemon/executor/container_cb/execution_create.c
+++ b/src/daemon/executor/container_cb/execution_create.c
@@ -257,8 +257,7 @@ static int merge_container_log_config_opts(const char *daemon_driver, const json
return 0;
}
-static int do_set_default_log_path_for_json_file(const char *id, const char *root, bool file_found,
- container_config *spec)
+static int do_set_default_log_path_for_json_file(const char *id, const char *root, container_config *spec)
{
int nret = 0;
char default_path[PATH_MAX] = { 0 };
@@ -277,10 +276,150 @@ static int do_set_default_log_path_for_json_file(const char *id, const char *roo
return 0;
}
-static int do_check_container_log_config_opts(const char *id, const char *root, container_config *spec)
+int syslog_tag_parser(const char *tag, map_t *tag_maps, char **parsed)
+{
+ char *tmp_tag = NULL;
+ int ret = 0;
+ char *target = NULL;
+
+ if (tag == NULL) {
+ ERROR("empty tag is invalid.");
+ return -1;
+ }
+
+ tmp_tag = util_strdup_s(tag);
+ tmp_tag = util_trim_space(tmp_tag);
+ target = map_search(tag_maps, (void *)tmp_tag);
+ if (target == NULL) {
+ ERROR("Invalid tag: %s", tag);
+ ret = -1;
+ goto out;
+ }
+
+ *parsed = util_strdup_s(target);
+
+out:
+ free(tmp_tag);
+ return ret;
+}
+
+static int do_update_container_log_config_syslog_tag(map_t *tag_maps, const char *driver, size_t idx,
+ json_map_string_string *annotations)
+{
+ char *parsed_tag = NULL;
+
+ if (driver == NULL || strcmp(driver, CONTAINER_LOG_CONFIG_SYSLOG_DRIVER) != 0) {
+ return 0;
+ }
+
+ if (annotations->keys[idx] == NULL || strcmp(annotations->keys[idx], CONTAINER_LOG_CONFIG_KEY_SYSLOG_TAG) != 0) {
+ return 0;
+ }
+
+ if (parse_container_log_opt_syslog_tag(annotations->values[idx], syslog_tag_parser, tag_maps, &parsed_tag) != 0) {
+ return -1;
+ }
+ DEBUG("new syslog tag: %s", parsed_tag);
+
+ free(annotations->values[idx]);
+ annotations->values[idx] = parsed_tag;
+ return 0;
+}
+
+static map_t *make_tag_mappings(const struct logger_info *p_info)
+{
+#define SHORT_ID_LEN 12
+ map_t *tag_maps = NULL;
+ char *short_id = NULL;
+ char *short_img_id = NULL;
+
+ tag_maps = map_new(MAP_STR_STR, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
+ if (tag_maps == NULL) {
+ ERROR("Out of memory");
+ return NULL;
+ }
+
+ short_id = util_sub_string(p_info->id, 0, SHORT_ID_LEN);
+ if (short_id == NULL) {
+ goto err_out;
+ }
+ if (!map_replace(tag_maps, (void *)".ID", (void *)short_id)) {
+ goto err_out;
+ }
+ if (!map_replace(tag_maps, (void *)".FullID", (void *)p_info->id)) {
+ goto err_out;
+ }
+ if (!map_replace(tag_maps, (void *)".Name", (void *)p_info->name)) {
+ goto err_out;
+ }
+
+ if (p_info->img_id != NULL) {
+ short_img_id = util_sub_string(p_info->img_id, 0, SHORT_ID_LEN);
+ if (short_img_id == NULL) {
+ goto err_out;
+ }
+ if (!map_replace(tag_maps, (void *)".ImageID", (void *)short_img_id)) {
+ goto err_out;
+ }
+ if (!map_replace(tag_maps, (void *)".ImageFullID", (void *)p_info->img_id)) {
+ goto err_out;
+ }
+ } else {
+ WARN("Empty image id");
+ }
+
+ if (p_info->img_name != NULL) {
+ if (!map_replace(tag_maps, (void *)".ImageName", (void *)p_info->img_name)) {
+ goto err_out;
+ }
+ } else {
+ WARN("Empty image name");
+ }
+
+ if (!map_replace(tag_maps, (void *)".DaemonName", (void *)p_info->daemon_name)) {
+ goto err_out;
+ }
+
+ free(short_img_id);
+ free(short_id);
+ return tag_maps;
+err_out:
+ free(short_img_id);
+ free(short_id);
+ map_free(tag_maps);
+ return NULL;
+}
+
+static int do_set_default_container_log_opts(bool set_file, bool set_rotate, bool set_size, const char *id,
+ const char *root, container_config *spec)
+{
+ if (!set_rotate && append_json_map_string_string(spec->annotations, CONTAINER_LOG_CONFIG_KEY_ROTATE, "7") != 0) {
+ return -1;
+ }
+ if (!set_size && append_json_map_string_string(spec->annotations, CONTAINER_LOG_CONFIG_KEY_SIZE, "1MB") != 0) {
+ return -1;
+ }
+ if (set_file) {
+ return 0;
+ }
+ return do_set_default_log_path_for_json_file(id, root, spec);
+}
+
+static int do_parse_container_log_config_opts(const struct logger_info *p_info, const char *root,
+ container_config *spec)
{
size_t i;
- bool file_found = false;
+ bool set_file = false;
+ bool set_rotate = false;
+ bool set_size = false;
+ map_t *tag_maps = NULL;
+ int ret = 0;
+
+ tag_maps = make_tag_mappings(p_info);
+ if (tag_maps == NULL) {
+ ERROR("Out of memory");
+ return -1;
+ }
// check log opts is support by driver
for (i = 0; i < spec->annotations->len; i++) {
@@ -292,23 +431,40 @@ static int do_check_container_log_config_opts(const char *id, const char *root,
DEBUG("check log opt key: %s for driver: %s", tmp_key, spec->log_driver);
if (!check_opt_container_log_opt(spec->log_driver, tmp_key)) {
isulad_set_error_message("container log driver: %s, unsupport: %s", spec->log_driver, tmp_key);
- return -1;
+ ERROR("container log driver: %s, unsupport: %s", spec->log_driver, tmp_key);
+ ret = -1;
+ goto out;
+ }
+
+ if (do_update_container_log_config_syslog_tag(tag_maps, spec->log_driver, i, spec->annotations) != 0) {
+ isulad_set_error_message("container syslog tag: unsupport: %s", spec->annotations->values[i]);
+ ERROR("container syslog tag: unsupport: %s", spec->annotations->values[i]);
+ ret = -1;
+ goto out;
}
if (strcmp(CONTAINER_LOG_CONFIG_KEY_FILE, tmp_key) == 0) {
- file_found = true;
+ set_file = true;
+ }
+ if (strcmp(CONTAINER_LOG_CONFIG_KEY_ROTATE, tmp_key) == 0) {
+ set_rotate = true;
+ }
+ if (strcmp(CONTAINER_LOG_CONFIG_KEY_SIZE, tmp_key) == 0) {
+ set_size = true;
}
}
- if (!file_found && strcmp(spec->log_driver, CONTAINER_LOG_CONFIG_JSON_FILE_DRIVER) == 0) {
- return do_set_default_log_path_for_json_file(id, root, file_found, spec);
+ if (strcmp(spec->log_driver, CONTAINER_LOG_CONFIG_JSON_FILE_DRIVER) == 0) {
+ ret = do_set_default_container_log_opts(set_file, set_rotate, set_size, p_info->id, root, spec);
}
- return 0;
+out:
+ map_free(tag_maps);
+ return ret;
}
-static int set_container_log_config_to_container_spec(const char *id, const char *runtime_root,
- container_config *container_spec)
+static int update_container_log_config_to_container_spec(const struct logger_info *p_info, const char *runtime_root,
+ container_config *spec)
{
int ret = 0;
isulad_daemon_configs_container_log *daemon_container_opts = NULL;
@@ -317,30 +473,42 @@ static int set_container_log_config_to_container_spec(const char *id, const char
return -1;
}
- set_container_log_config_driver(daemon_container_opts, container_spec);
+ set_container_log_config_driver(daemon_container_opts, spec);
- if (container_spec->annotations == NULL) {
- container_spec->annotations = util_common_calloc_s(sizeof(json_map_string_string));
+ if (spec->annotations == NULL) {
+ spec->annotations = util_common_calloc_s(sizeof(json_map_string_string));
}
- if (container_spec->annotations == NULL) {
+ if (spec->annotations == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
- ret = merge_container_log_config_opts(daemon_container_opts->driver, daemon_container_opts->opts, container_spec);
+ ret = merge_container_log_config_opts(daemon_container_opts->driver, daemon_container_opts->opts, spec);
if (ret != 0) {
goto out;
}
- ret = do_check_container_log_config_opts(id, runtime_root, container_spec);
+ ret = do_parse_container_log_config_opts(p_info, runtime_root, spec);
out:
free_isulad_daemon_configs_container_log(daemon_container_opts);
return ret;
}
-static container_config *get_container_spec(const char *id, const char *runtime_root,
- const container_create_request *request)
+static int do_update_container_log_configs(char *id, char *name, char *image_name, char *image_id,
+ const char *runtime_root, container_config *spec)
+{
+ struct logger_info l_info = { 0 };
+ l_info.id = id;
+ l_info.name = name;
+ l_info.img_name = image_name;
+ l_info.img_id = image_id != NULL ? image_id : image_name;
+ l_info.daemon_name = "iSulad";
+
+ return update_container_log_config_to_container_spec(&l_info, runtime_root, spec);
+}
+
+static container_config *get_container_spec(const container_create_request *request)
{
container_config *container_spec = NULL;
@@ -349,15 +517,7 @@ static container_config *get_container_spec(const char *id, const char *runtime_
return NULL;
}
- if (set_container_log_config_to_container_spec(id, runtime_root, container_spec)) {
- goto error_out;
- }
-
return container_spec;
-
-error_out:
- free_container_config(container_spec);
- return NULL;
}
static oci_runtime_spec *generate_oci_config(host_config *host_spec, const char *real_rootfs,
@@ -542,14 +702,13 @@ out:
return ret;
}
-static int register_new_container(const char *id, const char *runtime, host_config *host_spec,
+static int register_new_container(const char *id, const char *image_id, const char *runtime, host_config *host_spec,
container_config_v2_common_config *v2_spec)
{
int ret = -1;
bool registered = false;
char *runtime_root = NULL;
char *runtime_stat = NULL;
- char *image_id = NULL;
container_t *cont = NULL;
runtime_root = conf_get_routine_rootdir(runtime);
@@ -562,11 +721,6 @@ static int register_new_container(const char *id, const char *runtime, host_conf
goto out;
}
- if (strcmp(v2_spec->image_type, IMAGE_TYPE_OCI) == 0) {
- if (conf_get_image_id(v2_spec->image, &image_id) != 0) {
- goto out;
- }
- }
cont = container_new(runtime, runtime_root, runtime_stat, image_id, host_spec, v2_spec, NULL);
if (cont == NULL) {
ERROR("Failed to create container '%s'", id);
@@ -589,7 +743,6 @@ static int register_new_container(const char *id, const char *runtime, host_conf
out:
free(runtime_root);
free(runtime_stat);
- free(image_id);
if (ret != 0) {
/* fail, do not use the input v2 spec and host spec, the memeory will be free by caller*/
if (cont != NULL) {
@@ -911,8 +1064,8 @@ out:
return ret;
}
-static int get_basic_spec(const container_create_request *request, const char *id, const char *runtime_root,
- host_config **host_spec, container_config **container_spec)
+static int get_basic_spec(const container_create_request *request, host_config **host_spec,
+ container_config **container_spec)
{
*host_spec = get_host_spec(request);
if (*host_spec == NULL) {
@@ -923,7 +1076,7 @@ static int get_basic_spec(const container_create_request *request, const char *i
return -1;
}
- *container_spec = get_container_spec(id, runtime_root, request);
+ *container_spec = get_container_spec(request);
if (*container_spec == NULL) {
return -1;
}
@@ -1309,6 +1462,7 @@ int container_create_cb(const container_create_request *request, container_creat
char *real_rootfs = NULL;
char *image_type = NULL;
char *runtime_root = NULL;
+ char *image_id = NULL;
char *oci_config_data = NULL;
char *runtime = NULL;
char *name = NULL;
@@ -1340,7 +1494,7 @@ int container_create_cb(const container_create_request *request, container_creat
goto clean_nameindex;
}
- if (get_basic_spec(request, id, runtime_root, &host_spec, &container_spec) != 0) {
+ if (get_basic_spec(request, &host_spec, &container_spec) != 0) {
cc = ISULAD_ERR_INPUT;
goto clean_container_root_dir;
}
@@ -1390,6 +1544,18 @@ int container_create_cb(const container_create_request *request, container_creat
goto clean_rootfs;
}
+ if (strcmp(v2_spec->image_type, IMAGE_TYPE_OCI) == 0) {
+ if (conf_get_image_id(v2_spec->image, &image_id) != 0) {
+ cc = ISULAD_ERR_EXEC;
+ goto clean_rootfs;
+ }
+ }
+
+ if (do_update_container_log_configs(id, name, image_name, image_id, runtime_root, v2_spec->config)) {
+ cc = ISULAD_ERR_EXEC;
+ goto clean_rootfs;
+ }
+
if (verify_container_config(v2_spec->config) != 0) {
cc = ISULAD_ERR_EXEC;
goto clean_rootfs;
@@ -1453,7 +1619,7 @@ int container_create_cb(const container_create_request *request, container_creat
goto umount_channel;
}
- if (register_new_container(id, runtime, host_spec, v2_spec)) {
+ if (register_new_container(id, image_id, runtime, host_spec, v2_spec)) {
ERROR("Failed to register new container");
cc = ISULAD_ERR_EXEC;
goto umount_channel;
@@ -1490,6 +1656,7 @@ pack_response:
free(image_type);
free(image_name);
free(name);
+ free(image_id);
free(id);
free_oci_runtime_spec(oci_spec);
free_host_config(host_spec);
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index 6ed546bc..2b54634d 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -2405,7 +2405,7 @@ static int do_check_all_devices(struct device_set *devset)
struct stat st;
int nret = 0;
- // Equal to "dmsetup ls" . That is to say, devices_len is not zero, because isulad-thinpool exists.
+ // Equal to "dmsetup ls" . That is to say, devices_len is not zero, because isulad-thinpool exists.
if (dev_get_device_list(&devices_list, &devices_len) != 0) {
ERROR("devicemapper: failed to get device list");
ret = -1;
--
2.25.1

View File

@ -1,218 +0,0 @@
From 62b09ccf7a3a20694d906020fe6e02c61c75bcac Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 28 Apr 2021 19:25:42 +0800
Subject: [PATCH 090/104] add testcase for contailer log opts
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
CI/test_cases/container_cases/log_test.sh | 133 ++++++++++++++++--
.../container_cases/test_data/daemon.json | 1 +
2 files changed, 125 insertions(+), 9 deletions(-)
diff --git a/CI/test_cases/container_cases/log_test.sh b/CI/test_cases/container_cases/log_test.sh
index 08abf212..119a005a 100755
--- a/CI/test_cases/container_cases/log_test.sh
+++ b/CI/test_cases/container_cases/log_test.sh
@@ -12,6 +12,7 @@ function do_pre()
{
mv /etc/isulad/daemon.json /etc/isulad/daemon.bak
cp ${data_path}/daemon.json /etc/isulad/daemon.json
+ TC_RET_T=0
}
function do_post()
@@ -23,8 +24,9 @@ function do_post()
function do_check_item()
{
- cat ${ISULAD_ROOT_PATH}/engine/lcr/$1/config | grep console | grep "$2"
+ cat ${ISULAD_ROOT_PATH}/engines/lcr/$1/config | grep console | grep "$2"
if [ $? -ne 0 ]; then
+ cat ${ISULAD_ROOT_PATH}/engines/lcr/$1/config | grep console
msg_err "expect $2"
TC_RET_T=$(($TC_RET_T+1))
fi
@@ -61,6 +63,112 @@ function do_test_syslog_helper()
return $TC_RET_T
}
+function do_test_syslog_tag()
+{
+ local cid
+ msg_info "this is $0 do_test"
+
+ crictl pull busybox
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to pull busybox image"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ isula run -ti --log-opt="syslog-tag={{.xxx}}" busybox date
+ if [ $? -eq 0 ]; then
+ msg_err "run container success with invalid syslog-tag"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ isula run -ti --log-opt="syslog-tag={{" busybox date
+ if [ $? -eq 0 ]; then
+ msg_err "run container success with invalid syslog-tag"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ isula run -ti --log-opt="syslog-tag=aab{{cd" busybox date
+ if [ $? -eq 0 ]; then
+ msg_err "run container success with invalid syslog-tag"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ cid=$(isula run -tid --log-opt="syslog-tag={{.DaemonName}}" busybox sh)
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = iSulad"
+
+ cid=`isula run -tid --log-opt="syslog-tag={{.ID}}" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = ${cid: 0: 12}"
+
+ cid=`isula run -tid --name=haozi --log-opt="syslog-tag={{.ID}}xx{{.Name}}" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = ${cid: 0: 12}xxhaozi"
+ isula rm -f haozi
+
+ cid=`isula run -tid --log-opt="syslog-tag={{.FullID}}" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = ${cid}"
+
+ cid=`isula run -tid --name haozi --log-opt="syslog-tag={{.Name}}" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = haozi"
+ isula rm -f haozi
+
+ cid=`isula run -tid --name haozi --log-opt="syslog-tag=xx{{.Name}}yy" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = xxhaoziyy"
+ isula rm -f haozi
+
+ cid=`isula run -tid --log-opt="syslog-tag={{.ImageName}}" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = busybox"
+
+ cid=`isula run -tid --log-opt="syslog-tag={{.ImageID}}" busybox sh`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to run container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+ img_id=`isula inspect -f '{{.image.id}}' busybox`
+ do_check_item ${cid} "logdriver = syslog"
+ do_check_item ${cid} "syslog_tag = sha256:${img_id:0:5}"
+
+ isula rm -f `isula ps -aq`
+ if [ $? -ne 0 ]; then
+ msg_err "Failed to remove container"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ return $TC_RET_T
+}
+
function do_test_json_file_helper()
{
msg_info "this is $0 do_test"
@@ -96,6 +204,8 @@ function do_test_json_file_helper()
function do_test_container_log()
{
msg_info "this is $0 do_test"
+ cat /etc/isulad/daemon.json
+ ps aux | grep -i isulad
cid=`isula run -tid --log-driver=json-file busybox sh`
if [ $? -ne 0 ]; then
@@ -129,7 +239,7 @@ function do_test_container_log()
msg_err "Failed to run container"
TC_RET_T=$(($TC_RET_T+1))
fi
- cat ${ISULAD_ROOT_PATH}/engine/lcr/${cid}/config | grep console | grep "logfile ="
+ cat ${ISULAD_ROOT_PATH}/engines/lcr/${cid}/config | grep console | grep "logfile ="
if [ $? -eq 0 ]; then
msg_err "Failed to disable log"
TC_RET_T=$(($TC_RET_T+1))
@@ -139,14 +249,20 @@ function do_test_container_log()
return $TC_RET_T
}
+function do_test_container_syslog() {
+ do_test_syslog_helper "xxxx"
+
+ do_test_syslog_tag
+}
+
function do_test() {
check_valgrind_log
- start_isulad_with_valgrind --log-opts="syslog-tag=xxxx"
+ start_isulad_with_valgrind --container-log-opts="syslog-tag=xxxx"
- do_test_syslog_helper "xxxx"
+ do_test_container_syslog
check_valgrind_log
- start_isulad_with_valgrind --log-driver=json-file --log-opts="max-size=10MB" --log-opts="max-file=3"
+ start_isulad_with_valgrind --container-log-driver=json-file --container-log-opts="max-size=10MB" --container-log-opts="max-file=3"
do_test_json_file_helper "3" "10MB"
check_valgrind_log
@@ -157,10 +273,9 @@ function do_test() {
ret=0
do_pre
-if [ $? -ne 0 ];then
- let "ret=$ret + 1"
-fi
+
+do_test
do_post
-show_result $ret "cni base test"
+show_result $TC_RET_T "container log test"
diff --git a/CI/test_cases/container_cases/test_data/daemon.json b/CI/test_cases/container_cases/test_data/daemon.json
index f8914ed4..aa88c9da 100644
--- a/CI/test_cases/container_cases/test_data/daemon.json
+++ b/CI/test_cases/container_cases/test_data/daemon.json
@@ -23,6 +23,7 @@
"overlay2.override_kernel_check=true"
],
"registry-mirrors": [
+ "docker.io"
],
"insecure-registries": [
],
--
2.25.1

View File

@ -1,40 +0,0 @@
From 8003284bbf9d679e2d3f52cb55cdd4ee70d22977 Mon Sep 17 00:00:00 2001
From: lifeng68 <lifeng68@huawei.com>
Date: Thu, 29 Apr 2021 12:38:44 +0800
Subject: [PATCH 091/104] CI: run the containers one by one
Signed-off-by: lifeng68 <lifeng68@huawei.com>
---
CI/build.sh | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/CI/build.sh b/CI/build.sh
index cf7691d9..5ebe8ea3 100755
--- a/CI/build.sh
+++ b/CI/build.sh
@@ -415,18 +415,17 @@ rm -rf ${cptemp}
# wait for copy files become effective
sleep 3
+docker exec ${copycontainer} tail -f --retry /tmp/runflag/${CONTAINER_NAME}.scripts.log 2>/dev/null &
+tailpid=$!
+
for container in ${containers[@]}
do
{
exec_script ${container} ${testcase_script}
- }&
- pids="$! $pids"
+ }
done
-docker exec ${copycontainer} tail -f --retry /tmp/runflag/${CONTAINER_NAME}.scripts.log 2>/dev/null &
-tailpid=$!
trap "kill -9 $tailpid; exit 0" 15 2
-wait $pids
pid_dev="NULL"
if [[ "x$disk" != "xNULL" ]] && [[ "x${enable_gcov}" == "xON" ]]; then
--
2.25.1

View File

@ -1,102 +0,0 @@
From 03f7d19ef75af75cdc8cb15cb022e5fe367c4760 Mon Sep 17 00:00:00 2001
From: yin-xiujiang <yinxiujiang@kylinos.cn>
Date: Thu, 6 May 2021 14:32:32 +0800
Subject: [PATCH 092/104] completion isula images
---
src/contrib/completion/isula | 64 ++++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 17 deletions(-)
diff --git a/src/contrib/completion/isula b/src/contrib/completion/isula
index a12d90a5..a2adc083 100644
--- a/src/contrib/completion/isula
+++ b/src/contrib/completion/isula
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
-_isula_isula() {
+
+_isula_isula()
+{
local isula_management_commands=(
volume
)
@@ -65,32 +67,60 @@ _isula_isula() {
esac
}
-_isula_default()
+_isula_default()
{
COMPREPLY=( $( compgen -d -f -- $cur ) )
}
-_isula() {
+_isula_isula_list_images_with_tag()
+{
+ local images_with_tag=()
+ case "$cur" in
+ *:*)
+ front=${cur%:*}
+ #先去掉第一行,然后过滤指定镜像名
+ images_with_tag=($(isula images |awk 'NR>1'|grep -w "$front"| awk '{print $2}'))
+ cur=${cur##*:}
+ ;;
+ *)
+ images_with_tag=($(isula images |awk 'NR>1{printf "%s:%s\n",$1,$2}'))
+ ;;
+ esac
+
+ COMPREPLY=( $( compgen -W "${images_with_tag[*]}" -- "$cur" ) )
+}
+
+_isula_isula_rmi()
+{
+ _isula_isula_list_images_with_tag
+}
+
+_isula_isula_tag()
+{
+ _isula_isula_list_images_with_tag
+}
+
+_isula_isula_images()
+{
+ _isula_isula_list_images_with_tag
+}
+
+_isula()
+{
COMPREPLY=()
- #An array variable consisting of the individual words in the current command line
- local words=(${COMP_WORDS[*]})
- #An index into ${word} of the word containing the current cursor position
- local cword=$COMP_CWORD
- local cur="${words[$cword]}"
- local prev="${words[$cword-1]}"
+ local cur prev words cword
+ _get_comp_words_by_ref -n : cur prev words cword
local command='isula'
-
+ if [ $cword -gt 1 ] ; then
+ command="isula_${words[1]}"
+ fi
local completions_func=_isula_${command//-/_}
-
- #The completion of the secondary command will be added later
- if [ $cword -lt 2 ] ; then
- completions_func=_isula_${command//-/_}
+ if declare -F $completions_func >/dev/null; then
+ $completions_func
else
- completions_func=_isula_default
+ _isula_default
fi
-
- declare -F $completions_func >/dev/null && $completions_func
return 0
}
--
2.25.1

View File

@ -1,110 +0,0 @@
From 90b3ae01ff05140cb00baeaf63491bba19ceade6 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 6 May 2021 16:22:17 +0800
Subject: [PATCH 093/104] fix memory leak when pulling image
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
.../modules/image/oci/registry/http_request.c | 5 +++++
src/daemon/modules/image/oci/registry/registry.c | 14 ++++++++++++++
src/daemon/modules/image/oci/registry_type.c | 3 +++
src/daemon/modules/image/oci/registry_type.h | 2 ++
4 files changed, 24 insertions(+)
diff --git a/src/daemon/modules/image/oci/registry/http_request.c b/src/daemon/modules/image/oci/registry/http_request.c
index 2127795e..e86f37f0 100644
--- a/src/daemon/modules/image/oci/registry/http_request.c
+++ b/src/daemon/modules/image/oci/registry/http_request.c
@@ -23,6 +23,7 @@
#include <strings.h>
#include <time.h>
#include <curl/curl.h>
+#include <pthread.h>
#include "isula_libutils/log.h"
#include "buffer.h"
@@ -371,8 +372,10 @@ static int setup_auth_challenges(pull_descriptor *desc, char ***custom_headers)
goto out;
}
} else if (!strcasecmp(desc->challenges[i].schema, "Bearer")) {
+ (void)pthread_mutex_lock(&desc->challenges_mutex);
ret = get_bearer_token(desc, &desc->challenges[i]);
if (ret != 0) {
+ (void)pthread_mutex_unlock(&desc->challenges_mutex);
ERROR("get bearer token failed");
isulad_try_set_error_message("authentication failed");
goto out;
@@ -380,9 +383,11 @@ static int setup_auth_challenges(pull_descriptor *desc, char ***custom_headers)
auth_header = auth_header_str("Bearer", desc->challenges[i].cached_token);
if (auth_header == NULL) {
+ (void)pthread_mutex_unlock(&desc->challenges_mutex);
ret = -1;
goto out;
}
+ (void)pthread_mutex_unlock(&desc->challenges_mutex);
} else {
WARN("Unsupported schema %s", desc->challenges[i].schema);
continue;
diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c
index bd8e8fd0..cc5f6805 100644
--- a/src/daemon/modules/image/oci/registry/registry.c
+++ b/src/daemon/modules/image/oci/registry/registry.c
@@ -1910,6 +1910,13 @@ static int prepare_pull_desc(pull_descriptor *desc, registry_pull_options *optio
}
desc->mutex_inited = true;
+ ret = pthread_mutex_init(&desc->challenges_mutex, NULL);
+ if (ret != 0) {
+ ERROR("Failed to init challenges mutex for pull");
+ goto out;
+ }
+ desc->challenges_mutex_inited = true;
+
ret = pthread_cond_init(&desc->cond, NULL);
if (ret != 0) {
ERROR("Failed to init cond for pull");
@@ -2166,6 +2173,13 @@ int registry_login(registry_login_options *options)
desc->username = util_strdup_s(options->auth.username);
desc->password = util_strdup_s(options->auth.password);
+ ret = pthread_mutex_init(&desc->challenges_mutex, NULL);
+ if (ret != 0) {
+ ERROR("Failed to init challenges mutex for login");
+ goto out;
+ }
+ desc->challenges_mutex_inited = true;
+
ret = login_to_registry(desc);
if (ret != 0) {
ERROR("login to registry failed");
diff --git a/src/daemon/modules/image/oci/registry_type.c b/src/daemon/modules/image/oci/registry_type.c
index 3e0c5e19..51fc1697 100644
--- a/src/daemon/modules/image/oci/registry_type.c
+++ b/src/daemon/modules/image/oci/registry_type.c
@@ -150,6 +150,9 @@ void free_pull_desc(pull_descriptor *desc)
if (desc->mutex_inited) {
pthread_mutex_destroy(&desc->mutex);
}
+ if (desc->challenges_mutex_inited) {
+ pthread_mutex_destroy(&desc->challenges_mutex);
+ }
free(desc);
diff --git a/src/daemon/modules/image/oci/registry_type.h b/src/daemon/modules/image/oci/registry_type.h
index 86449543..11135250 100644
--- a/src/daemon/modules/image/oci/registry_type.h
+++ b/src/daemon/modules/image/oci/registry_type.h
@@ -102,6 +102,8 @@ typedef struct {
bool skip_tls_verify;
bool insecure_registry;
char *scope;
+ pthread_mutex_t challenges_mutex;
+ bool challenges_mutex_inited;
challenge challenges[CHALLENGE_MAX];
// This is temporary field. Once http request is performed, it is cleared
char **headers;
--
2.25.1

View File

@ -1,51 +0,0 @@
From db774e5fc3f6c12d302ef643feec9403b07da47f Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Thu, 6 May 2021 18:45:41 +0800
Subject: [PATCH 094/104] isula: fix --help=xx coredump
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/cmd/command_parser.c | 4 ++++
src/cmd/isula/client_arguments.h | 4 +++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/cmd/command_parser.c b/src/cmd/command_parser.c
index f900ceac..e925aa32 100644
--- a/src/cmd/command_parser.c
+++ b/src/cmd/command_parser.c
@@ -360,6 +360,10 @@ static int command_parse_long_arg(command_t *self, const char *arg)
if (command_get_option_data(self, opt, &opt_arg)) {
return -1;
}
+ if (strcmp(opt->large, "help") == 0 && *(bool *)opt->data) {
+ command_help(self);
+ exit(0);
+ }
return 0;
}
COMMAND_ERROR("Unknown flag found:'--%s'\n", arg);
diff --git a/src/cmd/isula/client_arguments.h b/src/cmd/isula/client_arguments.h
index a155b863..6bd99cb0 100644
--- a/src/cmd/isula/client_arguments.h
+++ b/src/cmd/isula/client_arguments.h
@@ -256,6 +256,8 @@ struct client_arguments {
char *host_channel;
+ bool help;
+
// lcr create
char *external_rootfs;
char *create_rootfs;
@@ -387,7 +389,7 @@ struct client_arguments {
&(cmdargs).key_file, \
"Path to TLS key file (default \"/root/.iSulad/key.pem\")", \
NULL }, \
- { CMD_OPT_TYPE_STRING, false, "help", 0, NULL, "Print usage", NULL },
+ { CMD_OPT_TYPE_BOOL, false, "help", 0, &(cmdargs).help, "Print usage", NULL },
#define VERSION_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "version", 0, NULL, "Print version information and quit", NULL },
--
2.25.1

View File

@ -1,30 +0,0 @@
From d2de6b5d8607f50c2b9b324197d670922bc94fbe Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Fri, 7 May 2021 16:13:11 +0800
Subject: [PATCH 095/104] workdir must be absolute path
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/cmd/isula/stream/exec.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/cmd/isula/stream/exec.c b/src/cmd/isula/stream/exec.c
index 3c8601f2..aa702b90 100644
--- a/src/cmd/isula/stream/exec.c
+++ b/src/cmd/isula/stream/exec.c
@@ -434,6 +434,12 @@ int cmd_exec_main(int argc, const char **argv)
custom_cfg->open_stdin = false;
}
+ if (custom_cfg->workdir != NULL && util_validate_absolute_path(custom_cfg->workdir) != 0) {
+ COMMAND_ERROR("exec failed: workdir is not validate absolute path");
+ ret = ECOMMON;
+ goto out;
+ }
+
g_cmd_exec_args.exec_suffix = generate_exec_suffix();
if (g_cmd_exec_args.exec_suffix == NULL) {
ERROR("Failed to generate exec suffix");
--
2.25.1

View File

@ -1,42 +0,0 @@
From 160a8a6660e1839f72ea625ebe2b30b5bebb46c3 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Fri, 7 May 2021 18:46:32 +0800
Subject: [PATCH 096/104] check if pull option is valid
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/cmd/isula/base/create.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/cmd/isula/base/create.c b/src/cmd/isula/base/create.c
index 48dc29be..2083dcf5 100644
--- a/src/cmd/isula/base/create.c
+++ b/src/cmd/isula/base/create.c
@@ -1568,11 +1568,6 @@ int cmd_create_main(int argc, const char **argv)
exit(ECOMMON);
}
- if (!valid_pull_option(g_cmd_create_args.pull)) {
- COMMAND_ERROR("invalid --pull option, only \"always\"|\"missing\"|\"never\" is allowed");
- exit(ECOMMON);
- }
-
ret = client_create(&g_cmd_create_args);
if (ret != 0) {
ERROR("Container \"%s\" create failed", g_cmd_create_args.name);
@@ -2177,6 +2172,12 @@ int create_checker(struct client_arguments *args)
goto out;
}
+ if (!valid_pull_option(args->pull)) {
+ COMMAND_ERROR("invalid --pull option, only \"always\"|\"missing\"|\"never\" is allowed");
+ ret = -1;
+ goto out;
+ }
+
if (create_check_rootfs(args)) {
ret = -1;
goto out;
--
2.25.1

View File

@ -1,28 +0,0 @@
From e61687773922c3aaae63a8cd7b4f488bf6c967b6 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Wed, 12 May 2021 11:31:01 +0800
Subject: [PATCH 097/104] fix memory usage of stats not right when runtime is
kata
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/daemon/modules/runtime/isula/isula_rt_ops.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
index 3b55ac88..f6067ca1 100644
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
@@ -562,6 +562,9 @@ static int runtime_call_stats(const char *workdir, const char *runtime, const ch
info->mem_used = stats->data->memory->usage->usage;
info->mem_limit = stats->data->memory->usage->limit;
}
+ if (stats != NULL && stats->data != NULL && stats->data->memory != NULL && stats->data->memory->raw) {
+ info->inactive_file_total = stats->data->memory->raw->total_inactive_file;
+ }
out:
free_shim_client_runtime_stats(stats);
--
2.25.1

View File

@ -1,207 +0,0 @@
From 3b05de4f3ecbe8e9fd8c37b61aa20273a9477127 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Thu, 13 May 2021 15:07:03 +0800
Subject: [PATCH 098/104] log: adjust log level to reduce log
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
src/daemon/entry/connect/grpc/runtime_runtime_service.cc | 8 ++++----
src/daemon/executor/container_cb/execution_extend.c | 6 +++---
src/daemon/modules/events/collector.c | 4 ++--
src/daemon/modules/image/image.c | 4 ++--
src/daemon/modules/image/image_rootfs_handler.c | 5 +++--
src/daemon/modules/image/oci/oci_common_operators.c | 4 ++--
src/daemon/modules/service/service_container.c | 4 ++--
src/utils/cutils/utils_file.c | 2 +-
8 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
index c9702401..7cceefc9 100644
--- a/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
+++ b/src/daemon/entry/connect/grpc/runtime_runtime_service.cc
@@ -260,7 +260,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ExecSync(grpc::ServerContext *context,
{
Errors error;
- EVENT("Event: {Object: CRI, Type: sync execing Container: %s}", request->container_id().c_str());
+ WARN("Event: {Object: CRI, Type: sync execing Container: %s}", request->container_id().c_str());
rService->ExecSync(request->container_id(), request->cmd(), request->timeout(), reply, error);
if (!error.Empty()) {
@@ -268,7 +268,7 @@ grpc::Status RuntimeRuntimeServiceImpl::ExecSync(grpc::ServerContext *context,
return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage());
}
- EVENT("Event: {Object: CRI, Type: sync execed Container: %s}", request->container_id().c_str());
+ WARN("Event: {Object: CRI, Type: sync execed Container: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
@@ -390,7 +390,7 @@ RuntimeRuntimeServiceImpl::UpdateContainerResources(grpc::ServerContext *context
{
Errors error;
- EVENT("Event: {Object: CRI, Type: Updating container resources: %s}", request->container_id().c_str());
+ WARN("Event: {Object: CRI, Type: Updating container resources: %s}", request->container_id().c_str());
rService->UpdateContainerResources(request->container_id(), request->linux(), error);
if (error.NotEmpty()) {
@@ -399,7 +399,7 @@ RuntimeRuntimeServiceImpl::UpdateContainerResources(grpc::ServerContext *context
return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage());
}
- EVENT("Event: {Object: CRI, Type: Updated container resources: %s}", request->container_id().c_str());
+ WARN("Event: {Object: CRI, Type: Updated container resources: %s}", request->container_id().c_str());
return grpc::Status::OK;
}
diff --git a/src/daemon/executor/container_cb/execution_extend.c b/src/daemon/executor/container_cb/execution_extend.c
index 77f29fe8..028a3dea 100644
--- a/src/daemon/executor/container_cb/execution_extend.c
+++ b/src/daemon/executor/container_cb/execution_extend.c
@@ -1223,15 +1223,15 @@ static int container_update_cb(const container_update_request *request, containe
id = cont->common_config->id;
isula_libutils_set_log_prefix(id);
- EVENT("Event: {Object: %s, Type: updating}", id);
+ WARN("Event: {Object: %s, Type: updating}", id);
if (do_update_resources(request, cont) != 0) {
cc = ISULAD_ERR_EXEC;
goto pack_response;
}
- EVENT("Event: {Object: %s, Type: updated}", id);
- (void)isulad_monitor_send_container_event(id, CREATE, -1, 0, NULL, NULL);
+ WARN("Event: {Object: %s, Type: updated}", id);
+ (void)isulad_monitor_send_container_event(id, UPDATE, -1, 0, NULL, NULL);
pack_response:
pack_update_response(*response, cc, id);
diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c
index 67a823f1..1a867354 100644
--- a/src/daemon/modules/events/collector.c
+++ b/src/daemon/modules/events/collector.c
@@ -481,7 +481,7 @@ static int write_events_log(const struct isulad_events_format *events)
len = calculate_annaotation_info_len(events);
if (len == 1) {
- EVENT("Event: {Object: %s, Type: %s}", events->id, events->opt);
+ WARN("Event: {Object: %s, Type: %s}", events->id, events->opt);
} else {
annotation = (char *)util_common_calloc_s(len);
if (annotation == NULL) {
@@ -499,7 +499,7 @@ static int write_events_log(const struct isulad_events_format *events)
}
(void)strcat(annotation, ")");
- EVENT("Event: {Object: %s, Type: %s %s}", events->id, events->opt, annotation);
+ WARN("Event: {Object: %s, Type: %s %s}", events->id, events->opt, annotation);
}
out:
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
index 8e663863..6832aec3 100644
--- a/src/daemon/modules/image/image.c
+++ b/src/daemon/modules/image/image.c
@@ -842,7 +842,7 @@ int im_list_images(const im_list_request *ctx, im_list_response **response)
return -1;
}
- EVENT("Event: {Object: list images, Type: listing}");
+ WARN("Event: {Object: list images, Type: listing}");
for (i = 0; i < g_numbims; i++) {
if (g_bims[i].ops->list_ims == NULL) {
@@ -862,7 +862,7 @@ int im_list_images(const im_list_request *ctx, im_list_response **response)
images_tmp = NULL;
}
- EVENT("Event: {Object: list images, Type: listed}");
+ WARN("Event: {Object: list images, Type: listed}");
if (g_isulad_errmsg != NULL) {
(*response)->errmsg = util_strdup_s(g_isulad_errmsg);
diff --git a/src/daemon/modules/image/image_rootfs_handler.c b/src/daemon/modules/image/image_rootfs_handler.c
index f9250a8d..f7bc9bc9 100644
--- a/src/daemon/modules/image/image_rootfs_handler.c
+++ b/src/daemon/modules/image/image_rootfs_handler.c
@@ -275,7 +275,8 @@ static int append_additional_groups(const struct group *grp, struct group **grou
struct group *new_groups = NULL;
size_t new_len = *len + 1;
- ret = util_mem_realloc((void **)&new_groups, new_len * sizeof(struct group), *groups, (*len) * sizeof(struct group));
+ ret = util_mem_realloc((void **)&new_groups, new_len * sizeof(struct group), *groups,
+ (*len) * sizeof(struct group));
if (ret != 0) {
ERROR("Out of memory");
return -1;
@@ -414,7 +415,7 @@ static int read_user_file(const char *basefs, const char *user_path, FILE **stre
*stream = util_fopen(real_path, "r");
if (*stream == NULL) {
- ERROR("Failed to open %s: %s", real_path, strerror(errno));
+ WARN("Failed to open %s: %s", real_path, strerror(errno));
ret = 0;
goto out;
}
diff --git a/src/daemon/modules/image/oci/oci_common_operators.c b/src/daemon/modules/image/oci/oci_common_operators.c
index 845e1fde..09405651 100644
--- a/src/daemon/modules/image/oci/oci_common_operators.c
+++ b/src/daemon/modules/image/oci/oci_common_operators.c
@@ -488,7 +488,7 @@ int oci_status_image(im_status_request *request, im_status_response *response)
goto pack_response;
}
- EVENT("Event: {Object: %s, Type: statusing image}", resolved_name);
+ WARN("Event: {Object: %s, Type: statusing image}", resolved_name);
image_info = storage_img_get(resolved_name);
if (image_info == NULL) {
@@ -501,7 +501,7 @@ int oci_status_image(im_status_request *request, im_status_response *response)
response->image_info->image = image_info;
image_info = NULL;
- EVENT("Event: {Object: %s, Type: statused image}", resolved_name);
+ WARN("Event: {Object: %s, Type: statused image}", resolved_name);
pack_response:
free(resolved_name);
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index 561f24eb..c8e2b1d8 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -1926,7 +1926,7 @@ int exec_container(const container_t *cont, const container_exec_request *reques
}
id = cont->common_config->id;
- EVENT("Event: {Object: %s, Type: execing}", id);
+ WARN("Event: {Object: %s, Type: execing}", id);
get_exec_command(request, exec_command, sizeof(exec_command));
(void)isulad_monitor_send_container_event(id, EXEC_CREATE, -1, 0, exec_command, NULL);
@@ -1984,7 +1984,7 @@ int exec_container(const container_t *cont, const container_exec_request *reques
goto pack_response;
}
- EVENT("Event: {Object: %s, Type: execed}", id);
+ WARN("Event: {Object: %s, Type: execed with exit code %d}", id, exit_code);
(void)isulad_monitor_send_container_event(id, EXEC_DIE, -1, 0, NULL, NULL);
pack_response:
diff --git a/src/utils/cutils/utils_file.c b/src/utils/cutils/utils_file.c
index d2e342a5..302e4e32 100644
--- a/src/utils/cutils/utils_file.c
+++ b/src/utils/cutils/utils_file.c
@@ -862,7 +862,7 @@ int64_t util_file_size(const char *filename)
}
if (stat(filename, &st)) {
- ERROR("stat file %s failed: %s", filename, strerror(errno));
+ WARN("stat file %s failed: %s", filename, strerror(errno));
return -1;
}
--
2.25.1

View File

@ -1,26 +0,0 @@
From 65a13abeb6315985cf43522597ec3494d762e029 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Fri, 14 May 2021 09:21:10 +0800
Subject: [PATCH 099/104] CI: use ali registry instead of docker.io
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
CI/test_cases/container_cases/test_data/daemon.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CI/test_cases/container_cases/test_data/daemon.json b/CI/test_cases/container_cases/test_data/daemon.json
index aa88c9da..27b0e7ce 100644
--- a/CI/test_cases/container_cases/test_data/daemon.json
+++ b/CI/test_cases/container_cases/test_data/daemon.json
@@ -23,7 +23,7 @@
"overlay2.override_kernel_check=true"
],
"registry-mirrors": [
- "docker.io"
+ "https://3laho3y3.mirror.aliyuncs.com"
],
"insecure-registries": [
],
--
2.25.1

View File

@ -1,60 +0,0 @@
From 7311814a1cbe1fbb767ab3879e26e06a4837bfff Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Sat, 15 May 2021 11:18:53 +0800
Subject: [PATCH 100/104] do not check key's case when parse http header
fix pull docker.io/library/busybox:latest failed.
It seems that docker.io registry changes it's
http response header to be all lower case.
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
.../modules/image/oci/registry/registry_apiv2.c | 11 ++++-------
src/utils/http/parser.c | 2 +-
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/daemon/modules/image/oci/registry/registry_apiv2.c b/src/daemon/modules/image/oci/registry/registry_apiv2.c
index b26e42ba..ea9e8dc5 100644
--- a/src/daemon/modules/image/oci/registry/registry_apiv2.c
+++ b/src/daemon/modules/image/oci/registry/registry_apiv2.c
@@ -205,7 +205,7 @@ static int parse_auths(pull_descriptor *desc, struct parsed_http_message *m)
int ret = 0;
for (i = 0; i < m->num_headers; i++) {
- if (!strcmp(m->headers[i][0], "Www-Authenticate") || !strcmp(m->headers[i][0], "WWW-Authenticate")) {
+ if (!strcasecmp(m->headers[i][0], "Www-Authenticate")) {
ret = parse_auth(desc, (char *)m->headers[i][1]);
if (ret != 0) {
WARN("parse auth %s failed", (char *)m->headers[i][1]);
@@ -294,12 +294,9 @@ static int parse_ping_header(pull_descriptor *desc, char *http_head)
version = get_header_value(message, "Docker-Distribution-Api-Version");
if (version == NULL) {
- version = get_header_value(message, "Docker-Distribution-API-Version");
- if (version == NULL) {
- ERROR("Docker-Distribution-Api-Version not found in header, registry may can not support registry API V2");
- ret = -1;
- goto out;
- }
+ ERROR("Docker-Distribution-Api-Version not found in header, registry may can not support registry API V2");
+ ret = -1;
+ goto out;
}
if (!util_strings_contains_word(version, "registry/2.0")) {
diff --git a/src/utils/http/parser.c b/src/utils/http/parser.c
index eb626485..5ea1677c 100644
--- a/src/utils/http/parser.c
+++ b/src/utils/http/parser.c
@@ -320,7 +320,7 @@ char *get_header_value(const struct parsed_http_message *m, const char *header)
char *ret = NULL;
for (i = 0; i < m->num_headers; i++) {
- if (strcmp(m->headers[i][0], header) == 0) {
+ if (strcasecmp(m->headers[i][0], header) == 0) {
ret = (char *)m->headers[i][1];
break;
}
--
2.25.1

Some files were not shown because too many files have changed in this diff Show More