update version to 2.1.4

Signed-off-by: jikai <jikai11@huawei.com>
This commit is contained in:
jikai 2024-01-30 10:20:49 +08:00
parent 9f47321607
commit 7a7d09f3ba
16 changed files with 8 additions and 1091 deletions

View File

@ -1,36 +0,0 @@
From dcdc428e0e48333405966e6c1188e77f8d2f550b Mon Sep 17 00:00:00 2001
From: jake <jikai11@huawei.com>
Date: Wed, 8 Nov 2023 01:09:36 +0000
Subject: [PATCH 01/13] !280 Add masked and readonly path in host config * Add
masked and readonly path in host config
---
src/json/schema/host-config.json | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/json/schema/host-config.json b/src/json/schema/host-config.json
index 302a537..30f1bdc 100644
--- a/src/json/schema/host-config.json
+++ b/src/json/schema/host-config.json
@@ -293,6 +293,18 @@
},
"CgroupParent": {
"type": "string"
+ },
+ "MaskedPaths": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "ReadonlyPaths": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
}
}
}
--
2.33.0

View File

@ -1,27 +0,0 @@
From 0372a70a82a39b69e07b0953a9e7f1d25aa84ad0 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Wed, 8 Nov 2023 01:10:05 +0000
Subject: [PATCH 02/13] !279 sanbox:del containers in metadata * sanbox:del
containers in metadata
---
src/json/schema/sandbox/metadata.json | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/json/schema/sandbox/metadata.json b/src/json/schema/sandbox/metadata.json
index 56cc9e0..b3b6886 100644
--- a/src/json/schema/sandbox/metadata.json
+++ b/src/json/schema/sandbox/metadata.json
@@ -34,9 +34,6 @@
"networkReady": {
"type": "boolean"
},
- "containers": {
- "type": "ArrayOfStrings"
- },
"sandboxConfigJson": {
"type": "string"
}
--
2.33.0

View File

@ -1,112 +0,0 @@
From fd369e066c94ba19e4233dc36030441754220553 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 8 Nov 2023 10:32:43 +0800
Subject: [PATCH 03/13] add function to transfer of ownership
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/auto_cleanup.h | 18 ++++++++++++++++++
tests/auto_cleanup_ut.cpp | 30 +++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/src/auto_cleanup.h b/src/auto_cleanup.h
index 2fa9f41..6d04372 100644
--- a/src/auto_cleanup.h
+++ b/src/auto_cleanup.h
@@ -24,6 +24,10 @@
#ifndef __ISULA_AUTO_CLEANUP_H
#define __ISULA_AUTO_CLEANUP_H
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -36,6 +40,20 @@
extern "C" {
#endif
+#define isula_transfer_fd(fd) \
+ ({ \
+ int __tmp_fd = (fd); \
+ (fd) = -EBADF; \
+ __tmp_fd; \
+ })
+
+#define isula_transfer_ptr(ptr) \
+ ({ \
+ __typeof__(ptr) __tmp_ptr = (ptr); \
+ (ptr) = NULL; \
+ __tmp_ptr; \
+ })
+
#define auto_cleanup_tag(name) __attribute__((__cleanup__(name##_cb)))
// define all used auto tags
diff --git a/tests/auto_cleanup_ut.cpp b/tests/auto_cleanup_ut.cpp
index b167bcb..2600d56 100644
--- a/tests/auto_cleanup_ut.cpp
+++ b/tests/auto_cleanup_ut.cpp
@@ -122,6 +122,17 @@ size_t do_auto_free()
#endif
}
+int *do_auto_free_and_transfer()
+{
+ __isula_auto_free int *test = nullptr;
+
+ // use 1024 * 1024 to ensure memory allo from mmap
+ test = static_cast<int *>(malloc(sizeof(int)));
+ *test = 8;
+
+ return isula_transfer_ptr(test);
+}
+
TEST(autocleanup_testcase, test__isula_auto_free)
{
#if defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33))
@@ -145,6 +156,10 @@ TEST(autocleanup_testcase, test__isula_auto_free)
ASSERT_NE(used, after.hblks);
ASSERT_NE(used, before.hblks);
ASSERT_EQ(before.hblks, after.hblks);
+
+ __isula_auto_free int *transfer_ptr = do_auto_free_and_transfer();
+ ASSERT_NE(nullptr, transfer_ptr);
+ ASSERT_EQ(8, *transfer_ptr);
}
int do_auto_file()
@@ -198,14 +213,27 @@ int do_auto_close()
return fd;
}
+int do_auto_close_and_transfer()
+{
+ __isula_auto_close int fd = -1;
+
+ fd = open("/proc/self/cmdline", 0444);
+
+ return isula_transfer_fd(fd);
+}
+
TEST(autocleanup_testcase, test__isula_auto_close)
{
int openfd, ret;
size_t i;
struct stat sbuf = { 0 };
+ __isula_auto_close int transfer_fd = -1;
- openfd = do_auto_close();
+ transfer_fd = do_auto_close_and_transfer();
+ ret = fstat(transfer_fd, &sbuf);
+ ASSERT_EQ(0, ret);
+ openfd = do_auto_close();
ret = fstat(openfd, &sbuf);
ASSERT_NE(0, ret);
ASSERT_EQ(EBADF, errno);
--
2.33.0

View File

@ -1,31 +0,0 @@
From 73ed2ec4771fd79912f1683ce094fc6d1becbf58 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Fri, 10 Nov 2023 09:20:41 +0000
Subject: [PATCH 04/13] !283 network:support version opt result *
network:support version opt result
---
src/json/schema/cni/{version.json => version_info.json} | 3 +++
1 file changed, 3 insertions(+)
rename src/json/schema/cni/{version.json => version_info.json} (72%)
diff --git a/src/json/schema/cni/version.json b/src/json/schema/cni/version_info.json
similarity index 72%
rename from src/json/schema/cni/version.json
rename to src/json/schema/cni/version_info.json
index 3831508..9f93d33 100644
--- a/src/json/schema/cni/version.json
+++ b/src/json/schema/cni/version_info.json
@@ -4,6 +4,9 @@
"properties": {
"cniVersion": {
"type": "string"
+ },
+ "supportedVersions": {
+ "$ref": "array_of_strings.json"
}
},
"required": [
--
2.33.0

View File

@ -1,218 +0,0 @@
From d8a706eb0e0ba937d8b99dadbbad2771469eef97 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Wed, 8 Nov 2023 15:40:01 +0800
Subject: [PATCH 05/13] add attach fd for process state and add needed util
function
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
.../schema/shim/client/process-state.json | 3 ++
src/utils/utils.c | 48 +++++++++++++++++++
src/utils/utils.h | 2 +
src/utils/utils_file.c | 41 ++++++++++++++++
src/utils/utils_file.h | 4 ++
src/utils/utils_string.c | 17 +++++++
src/utils/utils_string.h | 2 +
7 files changed, 117 insertions(+)
diff --git a/src/json/schema/shim/client/process-state.json b/src/json/schema/shim/client/process-state.json
index f07d14f..2383b43 100644
--- a/src/json/schema/shim/client/process-state.json
+++ b/src/json/schema/shim/client/process-state.json
@@ -151,6 +151,9 @@
"exit_fifo": {
"type": "string"
},
+ "attach_socket": {
+ "type": "string"
+ },
"control_fifo": {
"type": "string"
},
diff --git a/src/utils/utils.c b/src/utils/utils.c
index cd0934f..fabdf71 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -25,6 +25,9 @@
#include <sys/wait.h>
#include <errno.h>
#include <time.h>
+#include <regex.h>
+
+#include "log.h"
int isula_wait_pid_ret_status(pid_t pid)
{
@@ -81,4 +84,49 @@ void isula_usleep_nointerupt(unsigned long usec)
ret = nanosleep(&request, &remain);
request = remain;
} while (ret == -1 && errno == EINTR);
+}
+
+/*
+ * do not support greedy matching, like: '(:?xx)'
+ * return value:
+ * -1 failed
+ * 0 match
+ * 1 no match
+ */
+int isula_reg_match(const char *patten, const char *str)
+{
+#define EVENT_ARGS_MAX 255
+ int nret = 0;
+ char buffer[EVENT_ARGS_MAX] = { 0 };
+ regex_t reg;
+
+ if (patten == NULL || str == NULL) {
+ ERROR("invalid NULL param");
+ return -1;
+ }
+
+ nret = regcomp(&reg, patten, REG_EXTENDED | REG_NOSUB);
+ if (nret != 0) {
+ regerror(nret, &reg, buffer, EVENT_ARGS_MAX);
+ ERROR("regcomp %s failed: %s", patten, buffer);
+ return -1;
+ }
+
+ nret = regexec(&reg, str, 0, NULL, 0);
+ if (nret == 0) {
+ nret = 0;
+ goto free_out;
+ } else if (nret == REG_NOMATCH) {
+ nret = 1;
+ goto free_out;
+ } else {
+ nret = -1;
+ ERROR("reg match failed");
+ goto free_out;
+ }
+
+free_out:
+ regfree(&reg);
+
+ return nret;
}
\ No newline at end of file
diff --git a/src/utils/utils.h b/src/utils/utils.h
index dabaee2..b4ab9d0 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -46,6 +46,8 @@ int isula_wait_pid(pid_t pid);
void isula_usleep_nointerupt(unsigned long usec);
+int isula_reg_match(const char *patten, const char *str);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/utils/utils_file.c b/src/utils/utils_file.c
index fb55cf8..067715c 100644
--- a/src/utils/utils_file.c
+++ b/src/utils/utils_file.c
@@ -656,4 +656,45 @@ int isula_path_remove(const char *path)
errno = saved_errno;
}
return -1;
+}
+
+int isula_set_non_block(const int fd)
+{
+ int flag = -1;
+ int ret = -1;
+
+ if (fd < 0) {
+ ERROR("Invalid fd: %d.", fd);
+ return -1;
+ }
+
+ flag = fcntl(fd, F_GETFL, 0);
+ if (flag < 0) {
+ SYSERROR("Failed to get flags for fd: %d", fd);
+ return -1;
+ }
+
+ ret = fcntl(fd, F_SETFL, flag | O_NONBLOCK);
+ if (ret != 0) {
+ SYSERROR("Failed to set flags for fd: %d", fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+int isula_validate_absolute_path(const char *path)
+{
+#define PATTEN_STR "^(/[^/ ]*)+/?$"
+ int nret = 0;
+
+ if (path == NULL) {
+ return -1;
+ }
+
+ if (isula_reg_match(PATTEN_STR, path) != 0) {
+ nret = -1;
+ }
+
+ return nret;
}
\ No newline at end of file
diff --git a/src/utils/utils_file.h b/src/utils/utils_file.h
index 83d0a5d..23c4700 100644
--- a/src/utils/utils_file.h
+++ b/src/utils/utils_file.h
@@ -67,6 +67,10 @@ int isula_file_atomic_write(const char *filepath, const char *content);
int isula_close_inherited_fds(bool closeall, int fd_to_ignore);
+int isula_set_non_block(const int fd);
+
+int isula_validate_absolute_path(const char *path);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/utils/utils_string.c b/src/utils/utils_string.c
index 7b0cbef..863bebe 100644
--- a/src/utils/utils_string.c
+++ b/src/utils/utils_string.c
@@ -375,4 +375,21 @@ isula_string_array *isula_string_array_new(size_t req_init_cap)
ptr->append_arr = isula_string_array_append_array;
return ptr;
+}
+
+bool isula_has_prefix(const char *str, const char *prefix)
+{
+ if (str == NULL || prefix == NULL) {
+ return false;
+ }
+
+ if (strlen(str) < strlen(prefix)) {
+ return false;
+ }
+
+ if (strncmp(str, prefix, strlen(prefix)) != 0) {
+ return false;
+ }
+
+ return true;
}
\ No newline at end of file
diff --git a/src/utils/utils_string.h b/src/utils/utils_string.h
index f403fd9..5a25531 100644
--- a/src/utils/utils_string.h
+++ b/src/utils/utils_string.h
@@ -102,6 +102,8 @@ void isula_string_array_free(isula_string_array *ptr);
isula_string_array *isula_string_split_to_multi(const char *src_str, char delim);
+bool isula_has_prefix(const char *str, const char *prefix);
+
#ifdef __cplusplus
}
#endif
--
2.33.0

View File

@ -1,109 +0,0 @@
From e072071325b04d362b1eee69aed5c75199799fa5 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Mon, 13 Nov 2023 15:20:05 +0800
Subject: [PATCH 06/13] add unit test for util function
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
tests/utils_file_ut.cpp | 30 ++++++++++++++++++++++++++++++
tests/utils_string_ut.cpp | 21 +++++++++++++++++++++
tests/utils_utils_ut.cpp | 13 +++++++++++++
3 files changed, 64 insertions(+)
diff --git a/tests/utils_file_ut.cpp b/tests/utils_file_ut.cpp
index d9bd252..7e98bd8 100644
--- a/tests/utils_file_ut.cpp
+++ b/tests/utils_file_ut.cpp
@@ -210,4 +210,34 @@ TEST(utils_file_testcase, test_isula_read_write_nointr)
ASSERT_EQ(nread, 5);
isula_path_remove(test_file.c_str());
+}
+
+TEST(utils_file_testcase, test_isula_set_non_block)
+{
+ ASSERT_EQ(isula_set_non_block(-1), -1);
+
+ int pipefd[2];
+ ASSERT_EQ(0, pipe(pipefd));
+ ASSERT_EQ(0, isula_set_non_block(pipefd[0]));
+ int flag = fcntl(pipefd[0], F_GETFL, 0);
+ ASSERT_NE(-1, flag);
+ EXPECT_TRUE(flag & O_NONBLOCK);
+ close(pipefd[0]);
+ close(pipefd[1]);
+
+ int pipefd2[2];
+ ASSERT_EQ(0, pipe(pipefd2));
+ close(pipefd2[1]);
+ ASSERT_EQ(-1, isula_set_non_block(pipefd2[1]));
+ close(pipefd2[0]);
+}
+
+TEST(utils_file_testcase, test_util_validate_absolute_path)
+{
+ ASSERT_EQ(isula_validate_absolute_path("/etc/isulad"), 0);
+ ASSERT_EQ(isula_validate_absolute_path("/isulad/"), 0);
+
+ ASSERT_EQ(isula_validate_absolute_path(nullptr), -1);
+ ASSERT_EQ(isula_validate_absolute_path("./isulad"), -1);
+ ASSERT_EQ(isula_validate_absolute_path("isulad"), -1);
}
\ No newline at end of file
diff --git a/tests/utils_string_ut.cpp b/tests/utils_string_ut.cpp
index 5b93723..20fd619 100644
--- a/tests/utils_string_ut.cpp
+++ b/tests/utils_string_ut.cpp
@@ -286,4 +286,25 @@ TEST(utils_string_testcase, test_isula_string_split_to_multi)
ASSERT_STREQ(ret->items[2], "c");
ASSERT_STREQ(ret->items[3], "d");
isula_string_array_free(ret);
+}
+
+TEST(utils_string_testcase, test_isula_has_prefix)
+{
+ const char* prefix = "prefix";
+ EXPECT_FALSE(isula_has_prefix(NULL, prefix));
+
+ const char* str = "string";
+ EXPECT_FALSE(isula_has_prefix(str, NULL));
+
+ const char* str2 = "short";
+ const char* prefix2 = "longer";
+ EXPECT_FALSE(isula_has_prefix(str2, prefix2));
+
+ const char* str3 = "string";
+ const char* prefix3 = "prefix";
+ EXPECT_FALSE(isula_has_prefix(str3, prefix3));
+
+ const char* str4 = "prefix_string";
+ const char* prefix4 = "prefix";
+ EXPECT_TRUE(isula_has_prefix(str4, prefix4));
}
\ No newline at end of file
diff --git a/tests/utils_utils_ut.cpp b/tests/utils_utils_ut.cpp
index 843bcf4..7085f23 100644
--- a/tests/utils_utils_ut.cpp
+++ b/tests/utils_utils_ut.cpp
@@ -47,4 +47,17 @@ TEST(utils_utils_testcase, test_isula_usleep_nointerupt)
elapsed_time = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
ASSERT_GT(elapsed_time.count(), 800);
ASSERT_LT(elapsed_time.count(), 1200);
+}
+
+TEST(utils_utils_testcase, test_isula_reg_match)
+{
+ const char *pattern = "^[a-f0-9]{64}$";
+ const char *valid = "c8da28a6cea7443b648ec70a1c947b6cb920ee0ef3c4a691d4252ff6e1888036";
+ const char *invalid = "g8da28a6cea7443b648ec70a1c947b6cb920ee0ef3c4a691d4252ff6e1888036";
+
+ ASSERT_EQ(isula_reg_match(pattern, valid), 0);
+ ASSERT_EQ(isula_reg_match(pattern, invalid), 1);
+
+ ASSERT_EQ(isula_reg_match(pattern, nullptr), -1);
+ ASSERT_EQ(isula_reg_match(nullptr, pattern), -1);
}
\ No newline at end of file
--
2.33.0

View File

@ -1,36 +0,0 @@
From 90aa98210bdfdefc878efdc78b3e778bf5158026 Mon Sep 17 00:00:00 2001
From: jikai <jikai11@huawei.com>
Date: Thu, 16 Nov 2023 10:25:27 +0800
Subject: [PATCH 07/13] Restore subnet, gateway etc in ipam
Signed-off-by: jikai <jikai11@huawei.com>
---
src/json/schema/cni/net_conf.json | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/json/schema/cni/net_conf.json b/src/json/schema/cni/net_conf.json
index ccad8ba..ae8c8e4 100644
--- a/src/json/schema/cni/net_conf.json
+++ b/src/json/schema/cni/net_conf.json
@@ -29,6 +29,18 @@
"type": {
"type": "string"
},
+ "subnet": {
+ "type": "string"
+ },
+ "gateway": {
+ "type": "string"
+ },
+ "rangeStart": {
+ "type": "string"
+ },
+ "rangeEnd": {
+ "type": "string"
+ },
"routes": {
"type": "array",
"items": {
--
2.33.0

View File

@ -1,169 +0,0 @@
From 978f1df2f4e5317ce6f0ab8db29cc07d9c7fe30c Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 16 Nov 2023 10:58:52 +0800
Subject: [PATCH 08/13] improve error of lcr apis
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/runtime/error.h | 1 +
src/runtime/lcrcontainer.c | 41 +++++++++++++++++++++++++-------------
2 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/src/runtime/error.h b/src/runtime/error.h
index a778302..dee86ca 100644
--- a/src/runtime/error.h
+++ b/src/runtime/error.h
@@ -52,6 +52,7 @@ extern __thread engine_error_t g_lcr_error;
XX(ERR_FORMAT, "Error message is too long") \
XX(ERR_INPUT, "Invalid input parameter") \
XX(ERR_INTERNAL, "Server internal error") \
+ XX(ERR_CONFIG, "Invalid container config") \
\
/* err in runtime module */ \
XX(ERR_RUNTIME, DEF_ERR_RUNTIME_STR) \
diff --git a/src/runtime/lcrcontainer.c b/src/runtime/lcrcontainer.c
index a9b06c5..0b430ca 100644
--- a/src/runtime/lcrcontainer.c
+++ b/src/runtime/lcrcontainer.c
@@ -355,7 +355,8 @@ bool lcr_kill(const char *name, const char *lcrpath, uint32_t signal)
c = lxc_container_new(name, path);
if (c == NULL) {
- ERROR("Failed to stop container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for kill: %s", name);
+ ERROR("Failed to load config for kill: %s.", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -403,7 +404,8 @@ bool lcr_delete(const char *name, const char *lcrpath)
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, path);
if (c == NULL) {
- ERROR("Failed to delete container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for delete: %s", name);
+ ERROR("Failed to load config for delete: %s.", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -476,7 +478,8 @@ bool lcr_exec(const struct lcr_exec_request *request, int *exit_code)
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to delete container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for exec: %s", name);
+ ERROR("Failed to load config for exec: %s.", name);
goto out;
}
@@ -521,7 +524,8 @@ bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to delete container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for clean: %s", name);
+ ERROR("Failed to load config for clean: %s.", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -565,7 +569,8 @@ bool lcr_state(const char *name, const char *lcrpath, struct lcr_container_state
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failure to retrieve state infomation on %s", tmp_path);
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for state: %s", name);
+ ERROR("Failed to load config %s for state: %s", tmp_path, name);
isula_libutils_free_log_prefix();
return false;
}
@@ -602,7 +607,8 @@ bool lcr_get_container_pids(const char *name, const char *lcrpath, pid_t **pids,
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failure to retrieve state infomation on %s", tmp_path);
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for get pids of: %s", name);
+ ERROR("Failed to load config for get pids of: %s", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -653,7 +659,8 @@ bool lcr_pause(const char *name, const char *lcrpath)
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to pause container");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for pause: %s", name);
+ ERROR("Failed to load config for pause: %s.", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -696,7 +703,8 @@ bool lcr_resume(const char *name, const char *lcrpath)
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to resume container");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for resume: %s", name);
+ ERROR("Failed to load config for resume: %s.", name);
goto out;
}
@@ -740,7 +748,8 @@ bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsi
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to pause container");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for resize: %s", name);
+ ERROR("Failed to load config for resize: %s", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -763,7 +772,7 @@ bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsi
}
if (!c->set_terminal_winch(c, height, width)) {
- ERROR("Failed to pause");
+ ERROR("Failed to resize: %s", name);
bret = false;
goto out_put;
}
@@ -790,7 +799,8 @@ bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix,
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to pause container");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for exec resize: %s", name);
+ ERROR("Failed to load config for exec resize: %s.", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -839,7 +849,8 @@ bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, con
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to create container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for attach: %s", name);
+ ERROR("Failed to load config for attach: %s.", name);
bresult = false;
goto out;
}
@@ -977,7 +988,8 @@ bool lcr_get_console_config(const char *name, const char *lcrpath, struct lcr_co
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to create container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for get console config of: %s", name);
+ ERROR("Failed to load config for get config of: %s.", name);
isula_libutils_free_log_prefix();
return false;
}
@@ -1027,7 +1039,8 @@ bool lcr_update(const char *name, const char *lcrpath, const struct lcr_cgroup_r
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
- ERROR("Failed to new container.");
+ lcr_set_error_message(LCR_ERR_CONFIG, "Failed to load config for udpate: %s", name);
+ ERROR("Failed to load config for update: %s.", name);
goto out_free;
}
--
2.33.0

View File

@ -1,33 +0,0 @@
From ad30ae4232ed8dfdf0b352997e09070b31592953 Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
Date: Thu, 23 Nov 2023 20:17:45 +0800
Subject: [PATCH 09/13] Add ncurses-devel for gateway
Signed-off-by: xuxuepeng <xuxuepeng1@huawei.com>
---
CI/pr-gateway.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/CI/pr-gateway.sh b/CI/pr-gateway.sh
index 032b3f8..73c3bc5 100755
--- a/CI/pr-gateway.sh
+++ b/CI/pr-gateway.sh
@@ -18,7 +18,7 @@ sed -i "s#http://repo.openeuler.org#https://repo.huaweicloud.com/openeuler#g" /e
dnf update -y
-dnf install -y python3-pip docbook2X doxygen gtest-devel gmock-devel diffutils cmake gcc-c++ yajl-devel patch make libtool libevent-devel libevhtp-devel grpc grpc-plugins grpc-devel protobuf-devel libcurl libcurl-devel sqlite-devel libarchive-devel device-mapper-devel http-parser-devel libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel systemd-devel git chrpath
+dnf install -y python3-pip docbook2X doxygen gtest-devel gmock-devel diffutils cmake gcc-c++ yajl-devel patch make libtool libevent-devel libevhtp-devel grpc grpc-plugins grpc-devel protobuf-devel libcurl libcurl-devel sqlite-devel libarchive-devel device-mapper-devel http-parser-devel libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel systemd-devel git chrpath ncurses-devel
if [ $? -ne 0 ]; then
echo "install dependences failed"
exit 1
@@ -78,4 +78,4 @@ pushd lcr
pushd build
ctest -V || exit 1
popd
-popd
\ No newline at end of file
+popd
--
2.33.0

View File

@ -1,69 +0,0 @@
From 87e8dc5ae7d6de1aa9f75f13a57fec769d9edae3 Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
Date: Thu, 23 Nov 2023 12:49:19 +0000
Subject: [PATCH 10/13] !293 Add declaration macro for unit test * Add
declaration macro for unit test
---
CMakeLists.txt | 1 +
src/utils/utils_macro.h | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 src/utils/utils_macro.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4bf5335..f61bc1f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -134,6 +134,7 @@ install(FILES src/utils/utils_buffer.h DESTINATION include/isula_libutils)
install(FILES src/utils/utils_convert.h DESTINATION include/isula_libutils)
install(FILES src/utils/utils_file.h DESTINATION include/isula_libutils)
install(FILES src/utils/utils_linked_list.h DESTINATION include/isula_libutils)
+install(FILES src/utils/utils_macro.h DESTINATION include/isula_libutils)
install(FILES src/utils/utils_mainloop.h DESTINATION include/isula_libutils)
install(FILES src/utils/utils_memory.h DESTINATION include/isula_libutils)
install(FILES src/utils/utils_string.h DESTINATION include/isula_libutils)
diff --git a/src/utils/utils_macro.h b/src/utils/utils_macro.h
new file mode 100644
index 0000000..9e1bc0a
--- /dev/null
+++ b/src/utils/utils_macro.h
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * isula: macro definitions for isula
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
+ *
+ * Authors:
+ * xuxuepeng <xuxuepeng1@huawei.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ ********************************************************************************/
+
+#ifndef _ISULA_UTILS_MACRO_H
+#define _ISULA_UTILS_MACRO_H
+
+#ifndef UNIT_TEST
+#define STATIC static
+#define INLINE inline
+#else
+#define STATIC
+#define INLINE
+#endif
+
+#endif // _ISULA_UTILS_MACRO_H
\ No newline at end of file
--
2.33.0

View File

@ -1,59 +0,0 @@
From 27ee841b8ee02a5e87c0d0754fb0bd13b1e986f8 Mon Sep 17 00:00:00 2001
From: gaojiazhen <gaojiazhen_yewu@cmss.chinamobile.com>
Date: Thu, 23 Nov 2023 18:23:10 +0000
Subject: [PATCH 11/13] =?UTF-8?q?update=20src/runtime/lcrcontainer.c.=201?=
=?UTF-8?q?=E3=80=81=E4=BD=BF=E4=B8=8A=E4=B8=8B=E6=96=87=E7=9A=84=E5=8A=A8?=
=?UTF-8?q?=E8=AF=8D=E6=97=B6=E6=80=81=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?=
=?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3114=E8=A1=8C=E7=9A=84=E2=80=9Cunlink?=
=?UTF-8?q?=E2=80=9D=E4=B8=BA=E2=80=9Cunlinking=E2=80=9D=E3=80=82=202?=
=?UTF-8?q?=E3=80=81=E8=A7=84=E8=8C=83SYSERROR=E5=86=85=E5=AE=B9=E7=9A=84?=
=?UTF-8?q?=E8=AF=AD=E6=B3=95=EF=BC=8C=E4=BF=AE=E6=AD=A3215=E8=A1=8C?=
=?UTF-8?q?=E7=9A=84=E2=80=9Callocated=E2=80=9D=E4=B8=BA=E2=80=9Callocated?=
=?UTF-8?q?=E2=80=9D=E3=80=82=203=E3=80=81=E4=BD=BF=E4=B8=8A=E4=B8=8B?=
=?UTF-8?q?=E6=96=87=E7=9A=84=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF=E7=9A=84?=
=?UTF-8?q?=E7=94=A8=E6=B3=95=E4=B8=80=E8=87=B4=EF=BC=8C=E4=BF=AE=E6=AD=A3?=
=?UTF-8?q?241=E8=A1=8C=E7=9A=84=E2=80=9Cbegin"=E4=B8=BA=E2=80=9CBegin?=
=?UTF-8?q?=E2=80=9D=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: gaojiazhen <gaojiazhen_yewu@cmss.chinamobile.com>
---
src/runtime/lcrcontainer.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/runtime/lcrcontainer.c b/src/runtime/lcrcontainer.c
index 0b430ca..f93afb8 100644
--- a/src/runtime/lcrcontainer.c
+++ b/src/runtime/lcrcontainer.c
@@ -111,7 +111,7 @@ static void remove_partial(const struct lxc_container *c)
goto out_free;
}
if (unlink(path) < 0) {
- SYSERROR("Error unlink partial file %s", path);
+ SYSERROR("Error unlinking partial file %s", path);
}
out_free:
@@ -212,7 +212,7 @@ static bool lcr_start_check_config(const char *lcrpath, const char *name)
nret = snprintf(config, sizeof(config), "%s/%s/config", lcrpath, name);
if (nret < 0 || (size_t)nret >= sizeof(config)) {
- SYSERROR("Failed to allocated memory");
+ SYSERROR("Failed to allocate memory");
return false;
}
@@ -238,7 +238,7 @@ static bool wait_start_pid(pid_t pid, int rfd, const char *name, const char *pat
// set default error
lcr_set_error_message(LCR_ERR_RUNTIME, "runtime error");
- INFO("begin to stop container\n");
+ INFO("Begin to stop container\n");
if (!lcr_kill(name, path, SIGKILL)) {
ERROR("Failed to stop container");
}
--
2.33.0

View File

@ -1,64 +0,0 @@
From 9b3b233ddcddbe83f5e7f8bc658f9cd3e6a5c674 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Wed, 29 Nov 2023 09:33:13 +0000
Subject: [PATCH 12/13] !292 add blkio info for runtime-stats * add blkio info
for runtime-stats
---
src/json/schema/defs.json | 17 +++++++++++++++++
src/json/schema/shim/client/runtime-stats.json | 11 +++++++++++
2 files changed, 28 insertions(+)
diff --git a/src/json/schema/defs.json b/src/json/schema/defs.json
index ad6f6d8..22683c2 100644
--- a/src/json/schema/defs.json
+++ b/src/json/schema/defs.json
@@ -128,6 +128,23 @@
}
}
},
+ "BlkioEntry": {
+ "type": "object",
+ "properties": {
+ "major": {
+ "$ref": "#/definitions/uint64"
+ },
+ "minor": {
+ "$ref": "#/definitions/uint64"
+ },
+ "op": {
+ "type": "string"
+ },
+ "value": {
+ "$ref": "#/definitions/uint64"
+ }
+ }
+ },
"ArrayOfBlkioWeightDevice": {
"type": "array",
"items": {
diff --git a/src/json/schema/shim/client/runtime-stats.json b/src/json/schema/shim/client/runtime-stats.json
index 6fdc579..35cfe64 100644
--- a/src/json/schema/shim/client/runtime-stats.json
+++ b/src/json/schema/shim/client/runtime-stats.json
@@ -65,6 +65,17 @@
}
}
}
+ },
+ "blkio": {
+ "type": "object",
+ "properties": {
+ "ioServiceBytesRecursive": {
+ "type": "array",
+ "items": {
+ "$ref": "../../defs.json#/definitions/BlkioEntry"
+ }
+ }
+ }
}
}
}
--
2.33.0

View File

@ -1,112 +0,0 @@
From 0f372e949a554b06210bca5a09fff3264ea4be1c Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
Date: Thu, 30 Nov 2023 07:42:18 +0000
Subject: [PATCH 13/13] !296 Add macro for define cleanup function * Add macro
for define cleanup function
---
src/auto_cleanup.h | 23 +++++++++++++------
tests/auto_cleanup_ut.cpp | 48 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/src/auto_cleanup.h b/src/auto_cleanup.h
index 6d04372..95b6294 100644
--- a/src/auto_cleanup.h
+++ b/src/auto_cleanup.h
@@ -57,20 +57,29 @@ extern "C" {
#define auto_cleanup_tag(name) __attribute__((__cleanup__(name##_cb)))
// define all used auto tags
-#define __isula_auto_free auto_cleanup_tag(free_pointer)
+#define __isula_auto_free auto_cleanup_tag(free)
#define __isula_auto_file auto_cleanup_tag(close_file)
#define __isula_auto_dir auto_cleanup_tag(close_dir)
#define __isula_auto_close auto_cleanup_tag(auto_close)
#define __isula_auto_pm_unlock auto_cleanup_tag(auto_pm_unlock)
#define __isula_auto_prw_unlock auto_cleanup_tag(auto_prw_unlock)
-static inline void free_pointer_cb(void *ptr)
-{
- void *real = *(void **)ptr;
- if (real != NULL) {
- free(real);
+/*
+ * define auto cleanup callback for the type free function.
+ * _cleanup_func: the type free function, must be void type and
+ * accept one parameter with type _type *.
+ * _type: the type of the pointer to be cleaned up.
+ */
+#define define_auto_cleanup_callback(_cleanup_func, _type) \
+ static inline void _cleanup_func##_cb(void *p) \
+ { \
+ _type *_p = *(_type **)p; \
+ if (_p != NULL) { \
+ _cleanup_func(_p); \
+ } \
}
-}
+
+define_auto_cleanup_callback(free, void)
static inline void close_file_cb(FILE **p)
{
diff --git a/tests/auto_cleanup_ut.cpp b/tests/auto_cleanup_ut.cpp
index 2600d56..760f0dd 100644
--- a/tests/auto_cleanup_ut.cpp
+++ b/tests/auto_cleanup_ut.cpp
@@ -248,4 +248,50 @@ TEST(autocleanup_testcase, test__isula_auto_close)
inner_fd = open("/proc/self/cmdline", 0444);
openfd = inner_fd;
}
-}
\ No newline at end of file
+}
+
+static bool g_test_auto_cleanup_callback_called = false;
+
+typedef struct foo {
+ int *a;
+ int *b;
+} foo_t;
+
+void foo_free(foo_t *f)
+{
+ if (f == nullptr) {
+ return;
+ }
+ if (f->a != nullptr) {
+ free(f->a);
+ f->a = nullptr;
+ }
+ if (f->b != nullptr) {
+ free(f->b);
+ f->b = nullptr;
+ }
+ g_test_auto_cleanup_callback_called = true;
+ free(f);
+}
+
+define_auto_cleanup_callback(foo_free, foo_t);
+#define __isula_auto_foo_t auto_cleanup_tag(foo_free)
+
+void do_auto_cleanup_callback()
+{
+ __isula_auto_foo_t foo_t *f = nullptr;
+
+ f = static_cast<foo_t *>(malloc(sizeof(foo_t)));
+ f->a = static_cast<int *>(malloc(sizeof(int)));
+ f->b = static_cast<int *>(malloc(sizeof(int)));
+ *(f->a) = 1;
+ *(f->b) = 2;
+}
+
+TEST(autocleanup_testcase, test_define_auto_cleanup_callback)
+{
+ g_test_auto_cleanup_callback_called = false;
+ do_auto_cleanup_callback();
+ // check if the callback function is called
+ ASSERT_EQ(g_test_auto_cleanup_callback_called, true);
+}
--
2.33.0

View File

@ -1,5 +1,5 @@
%global _version 2.1.3
%global _release 3
%global _version 2.1.4
%global _release 1
%global _inner_name isula_libutils
%global enable_lxc 1
@ -13,20 +13,6 @@ Group: Applications/System
License: LGPLv2.1+
BuildRoot: %{_tmppath}/lcr-%{version}
Patch0001: 0001-280-Add-masked-and-readonly-path-in-host-config.patch
Patch0002: 0002-279-sanbox-del-containers-in-metadata.patch
Patch0003: 0003-add-function-to-transfer-of-ownership.patch
Patch0004: 0004-283-network-support-version-opt-result.patch
Patch0005: 0005-add-attach-fd-for-process-state-and-add-needed-util-.patch
Patch0006: 0006-add-unit-test-for-util-function.patch
Patch0007: 0007-Restore-subnet-gateway-etc-in-ipam.patch
Patch0008: 0008-improve-error-of-lcr-apis.patch
Patch0009: 0009-Add-ncurses-devel-for-gateway.patch
Patch0010: 0010-293-Add-declaration-macro-for-unit-test.patch
Patch0011: 0011-update-src-runtime-lcrcontainer.c.patch
Patch0012: 0012-292-add-blkio-info-for-runtime-stats.patch
Patch0013: 0013-296-Add-macro-for-define-cleanup-function.patch
%define lxcver_lower 4.0.3-2022102400
%define lxcver_upper 5.0.3
@ -141,6 +127,12 @@ rm -rf %{buildroot}
%{_includedir}/lcr/utils_compile.h
%changelog
* Tue Jan 30 2024 jikai<jikai11@huawei.com> - 2.1.4-1
- Type:enhancement
- CVE:NA
- SUG:NA
- DESC:update version to 2.1.4
* Mon Dec 11 2023 jikai<jikai11@huawei.com> - 2.1.3-3
- Type:enhancement
- CVE:NA

Binary file not shown.

BIN
v2.1.4.tar.gz Normal file

Binary file not shown.