lcr: sync patches from upstream

Signed-off-by: WangFengTu <wangfengtu@huawei.com>
This commit is contained in:
WangFengTu 2021-05-18 11:09:12 +08:00
parent 5225bddc28
commit dd412f0344
9 changed files with 1844 additions and 1 deletions

View File

@ -0,0 +1,30 @@
From 60e18350f884ecc995865eb773da7508ec580f49 Mon Sep 17 00:00:00 2001
From: jikui <jikui2@huawei.com>
Date: Mon, 8 Mar 2021 18:16:12 +0800
Subject: [PATCH 03/10] lcr: add default runtime field for isula info
Signed-off-by: jikui <jikui2@huawei.com>
---
src/json/schema/host/info-response.json | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/json/schema/host/info-response.json b/src/json/schema/host/info-response.json
index c42fa68..a7482eb 100644
--- a/src/json/schema/host/info-response.json
+++ b/src/json/schema/host/info-response.json
@@ -50,6 +50,12 @@
"isulad_root_dir": {
"type": "string"
},
+ "default_runtime": {
+ "type": "string"
+ },
+ "runtimes": {
+ "type": "ArrayOfStrings"
+ },
"total_mem": {
"type": "uint32"
},
--
2.25.1

View File

@ -0,0 +1,57 @@
From dee153e7de91235ba179378773bc79efd980d344 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 11 Mar 2021 11:20:19 +0800
Subject: [PATCH 04/10] support isula exec --workdir
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/json/schema/container/exec-request.json | 5 ++++-
src/lcrcontainer.h | 1 +
src/lcrcontainer_execute.c | 3 +++
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/json/schema/container/exec-request.json b/src/json/schema/container/exec-request.json
index 1482b55..9c9c0d1 100644
--- a/src/json/schema/container/exec-request.json
+++ b/src/json/schema/container/exec-request.json
@@ -40,6 +40,9 @@
},
"user": {
"type": "string"
+ },
+ "workdir": {
+ "type": "string"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/lcrcontainer.h b/src/lcrcontainer.h
index dcd1b12..ecf3655 100644
--- a/src/lcrcontainer.h
+++ b/src/lcrcontainer.h
@@ -295,6 +295,7 @@ struct lcr_exec_request {
bool tty;
bool open_stdin;
+ char *workdir;
};
/*
* Execute process inside a container
diff --git a/src/lcrcontainer_execute.c b/src/lcrcontainer_execute.c
index ab04c7e..8ea479e 100644
--- a/src/lcrcontainer_execute.c
+++ b/src/lcrcontainer_execute.c
@@ -536,6 +536,9 @@ static void execute_lxc_attach(const char *name, const char *path, const struct
add_array_elem(params, args_len, &i, path);
add_array_elem(params, args_len, &i, "--clear-env");
add_array_elem(params, args_len, &i, "--quiet");
+ if (request->workdir != NULL) {
+ add_array_kv(params, args_len, &i, "--workdir", request->workdir);
+ }
add_array_kv(params, args_len, &i, "--logfile", request->logpath);
add_array_kv(params, args_len, &i, "-l", request->loglevel);
add_array_kv(params, args_len, &i, "--in-fifo", request->console_fifos[0]);
--
2.25.1

View File

@ -0,0 +1,26 @@
From 84368fe8c022bd8e0d0d8968bf9325070f677383 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Tue, 16 Mar 2021 09:59:37 +0800
Subject: [PATCH 05/10] add secure compile options prohibit rpath options
Signed-off-by: wujing <wujing50@huawei.com>
---
lcr.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lcr.spec b/lcr.spec
index 71d6abd..6911cd5 100644
--- a/lcr.spec
+++ b/lcr.spec
@@ -54,7 +54,7 @@ the %{name}-libs package contains libraries for running iSula applications.
%build
mkdir -p build
cd build
-%cmake -DDEBUG=ON -DENABLE_UT=ON -DLIB_INSTALL_DIR=%{_libdir} ../
+%cmake -DDEBUG=ON -DENABLE_UT=ON -DCMAKE_SKIP_RPATH=TRUE -DLIB_INSTALL_DIR=%{_libdir} ../
%make_build
%install
--
2.25.1

View File

@ -0,0 +1,26 @@
From fac14fbabd07c587d09cb96ef9ccb663096dca3e Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 23 Mar 2021 10:05:04 +0800
Subject: [PATCH 06/10] remove invalid fuzz option
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
tests/fuzz/fuzz.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/fuzz/fuzz.sh b/tests/fuzz/fuzz.sh
index d71be7c..7513e65 100755
--- a/tests/fuzz/fuzz.sh
+++ b/tests/fuzz/fuzz.sh
@@ -23,7 +23,7 @@
#!/bin/bash
LIB_FUZZING_ENGINE="/lib64/libFuzzer.a"
-FUZZ_OPTION="corpus -dict=./dict/log_fuzz.dict -runs=10000000 -max_total_time=3600"
+FUZZ_OPTION="-dict=./dict/log_fuzz.dict -runs=10000000 -max_total_time=3600"
if [ ! -f "$LIB_FUZZING_ENGINE" ];then
echo "$LIB_FUZZING_ENGINE not exist, pls check"
--
2.25.1

1418
0007-support-cgroup-v2.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,214 @@
From 26f52ea703a5a232de6d1bed5a0cbe9a6aea36d7 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Fri, 2 Apr 2021 16:57:58 +0800
Subject: [PATCH 08/10] fix pause container error
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/conf.c | 18 +++++++++---------
src/lcrcontainer_execute.c | 10 +++++-----
src/utils.c | 10 +++++-----
src/utils.h | 10 +++++-----
4 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/conf.c b/src/conf.c
index d1fd2f3..f2569b3 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -50,7 +50,7 @@ static int files_limit_checker_v1(const char *value)
int ret = 0;
int cgroup_version = 0;
- cgroup_version = get_cgroup_version();
+ cgroup_version = lcr_util_get_cgroup_version();
if (cgroup_version < 0) {
return -1;
}
@@ -75,7 +75,7 @@ static int files_limit_checker_v2(const char *value)
int ret = 0;
int cgroup_version = 0;
- cgroup_version = get_cgroup_version();
+ cgroup_version = lcr_util_get_cgroup_version();
if (cgroup_version < 0) {
return -1;
}
@@ -2044,7 +2044,7 @@ static int trans_resources_mem_swap_v2(const defs_resources *res, struct lcr_lis
return 0;
}
- if (get_real_swap(res->memory->limit, res->memory->swap, &swap) != 0) {
+ if (lcr_util_get_real_swap(res->memory->limit, res->memory->swap, &swap) != 0) {
return -1;
}
@@ -2085,7 +2085,7 @@ static int trans_resources_cpu_weight_v2(const defs_resources *res, struct lcr_l
return -1;
}
- if (trans_conf_int64(conf, "lxc.cgroup2.cpu.weight", trans_cpushare_to_cpuweight(res->cpu->shares)) != 0) {
+ if (trans_conf_int64(conf, "lxc.cgroup2.cpu.weight", lcr_util_trans_cpushare_to_cpuweight(res->cpu->shares)) != 0) {
return -1;
}
@@ -2176,7 +2176,7 @@ static int trans_io_weight_v2(const defs_resources_block_io *block_io, struct lc
size_t len = block_io->weight_device_len;
if (block_io->weight != INVALID_INT) {
- weight = trans_blkio_weight_to_io_weight(block_io->weight);
+ weight = lcr_util_trans_blkio_weight_to_io_weight(block_io->weight);
if (weight < CGROUP2_WEIGHT_MIN || weight > CGROUP2_WEIGHT_MAX) {
ERROR("invalid io weight cased by invalid blockio weight %d", block_io->weight);
return -1;
@@ -2196,7 +2196,7 @@ static int trans_io_weight_v2(const defs_resources_block_io *block_io, struct lc
int nret = 0;
char buf_value[300] = { 0x00 };
- weight = trans_blkio_weight_to_io_weight(weight_device[i]->weight);
+ weight = lcr_util_trans_blkio_weight_to_io_weight(weight_device[i]->weight);
if (weight < CGROUP2_WEIGHT_MIN || weight > CGROUP2_WEIGHT_MAX) {
ERROR("invalid io weight cased by invalid blockio weight %d", weight_device[i]->weight);
return -1;
@@ -2227,7 +2227,7 @@ static int trans_io_bfq_weight_v2(const defs_resources_block_io *block_io, struc
size_t len = block_io->weight_device_len;
if (block_io->weight != INVALID_INT) {
- weight = trans_blkio_weight_to_io_bfq_weight(block_io->weight);
+ weight = lcr_util_trans_blkio_weight_to_io_bfq_weight(block_io->weight);
if (weight < CGROUP2_BFQ_WEIGHT_MIN || weight > CGROUP2_BFQ_WEIGHT_MAX) {
ERROR("invalid io weight cased by invalid blockio weight %d", block_io->weight);
return -1;
@@ -2247,7 +2247,7 @@ static int trans_io_bfq_weight_v2(const defs_resources_block_io *block_io, struc
int nret = 0;
char buf_value[300] = { 0x00 };
- weight = trans_blkio_weight_to_io_weight(weight_device[i]->weight);
+ weight = lcr_util_trans_blkio_weight_to_io_weight(weight_device[i]->weight);
if (weight < CGROUP2_BFQ_WEIGHT_MIN || weight > CGROUP2_BFQ_WEIGHT_MAX) {
ERROR("invalid io weight cased by invalid blockio weight %d", weight_device[i]->weight);
return -1;
@@ -2433,7 +2433,7 @@ static struct lcr_list *trans_oci_resources(const defs_resources *res)
{
int cgroup_version = 0;
- cgroup_version = get_cgroup_version();
+ cgroup_version = lcr_util_get_cgroup_version();
if (cgroup_version < 0) {
return NULL;
}
diff --git a/src/lcrcontainer_execute.c b/src/lcrcontainer_execute.c
index bef787b..4c8e0e6 100644
--- a/src/lcrcontainer_execute.c
+++ b/src/lcrcontainer_execute.c
@@ -199,7 +199,7 @@ static int update_resources_cpu_weight_v2(struct lxc_container *c, const struct
}
int num = snprintf(numstr, sizeof(numstr), "%llu",
- (unsigned long long)trans_cpushare_to_cpuweight(cr->cpu_shares));
+ (unsigned long long)lcr_util_trans_cpushare_to_cpuweight(cr->cpu_shares));
if (num < 0 || (size_t)num >= sizeof(numstr)) {
return -1;
}
@@ -486,7 +486,7 @@ static int update_resources_memory_swap_v2(struct lxc_container *c, const struct
return 0;
}
- if (get_real_swap(cr->memory_limit, cr->memory_swap, &swap) != 0) {
+ if (lcr_util_get_real_swap(cr->memory_limit, cr->memory_swap, &swap) != 0) {
return -1;
}
@@ -637,7 +637,7 @@ static int update_resources_io_weight_v2(struct lxc_container *c, const struct l
return 0;
}
- weight = trans_blkio_weight_to_io_weight(cr->blkio_weight);
+ weight = lcr_util_trans_blkio_weight_to_io_weight(cr->blkio_weight);
if (weight < CGROUP2_WEIGHT_MIN || weight > CGROUP2_WEIGHT_MAX) {
ERROR("invalid io weight cased by invalid blockio weight %llu", (unsigned long long) cr->blkio_weight);
return -1;
@@ -665,7 +665,7 @@ static int update_resources_io_bfq_weight_v2(struct lxc_container *c, const stru
return 0;
}
- weight = trans_blkio_weight_to_io_bfq_weight(cr->blkio_weight);
+ weight = lcr_util_trans_blkio_weight_to_io_bfq_weight(cr->blkio_weight);
if (weight < CGROUP2_BFQ_WEIGHT_MIN || weight > CGROUP2_BFQ_WEIGHT_MAX) {
ERROR("invalid io weight cased by invalid blockio weight %llu", (unsigned long long) cr->blkio_weight);
return -1;
@@ -693,7 +693,7 @@ static bool update_resources(struct lxc_container *c, struct lcr_cgroup_resource
return false;
}
- cgroup_version = get_cgroup_version();
+ cgroup_version = lcr_util_get_cgroup_version();
if (cgroup_version < 0) {
return false;
}
diff --git a/src/utils.c b/src/utils.c
index 24dc926..7ee9ba8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1264,7 +1264,7 @@ out:
}
/* swap in oci is memoy+swap, so here we need to get real swap */
-int get_real_swap(int64_t memory, int64_t memory_swap, int64_t *swap)
+int lcr_util_get_real_swap(int64_t memory, int64_t memory_swap, int64_t *swap)
{
if (memory == -1 && memory_swap == 0) {
*swap = -1; // -1 is max
@@ -1295,25 +1295,25 @@ int get_real_swap(int64_t memory, int64_t memory_swap, int64_t *swap)
return 0;
}
-int trans_cpushare_to_cpuweight(int64_t cpu_share)
+int lcr_util_trans_cpushare_to_cpuweight(int64_t cpu_share)
{
/* map from range [2-262144] to [1-10000] */
return 1 + ((cpu_share - 2) * 9999) / 262142;
}
-uint64_t trans_blkio_weight_to_io_weight(int weight)
+uint64_t lcr_util_trans_blkio_weight_to_io_weight(int weight)
{
// map from [10-1000] to [1-10000]
return (uint64_t)(1 + ((uint64_t)weight - 10) * 9999 / 990);
}
-uint64_t trans_blkio_weight_to_io_bfq_weight(int weight)
+uint64_t lcr_util_trans_blkio_weight_to_io_bfq_weight(int weight)
{
// map from [10-1000] to [1-1000]
return (uint64_t)(1 + ((uint64_t)weight - 10) * 999 / 990);
}
-int get_cgroup_version()
+int lcr_util_get_cgroup_version()
{
struct statfs fs = {0};
diff --git a/src/utils.h b/src/utils.h
index 423c0c8..5aae95d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -216,11 +216,11 @@ int lcr_util_null_stdfds(void);
int lcr_util_atomic_write_file(const char *filepath, const char *content);
-int get_real_swap(int64_t memory, int64_t memory_swap, int64_t *swap);
-int trans_cpushare_to_cpuweight(int64_t cpu_share);
-uint64_t trans_blkio_weight_to_io_weight(int weight);
-uint64_t trans_blkio_weight_to_io_bfq_weight(int weight);
-int get_cgroup_version();
+int lcr_util_get_real_swap(int64_t memory, int64_t memory_swap, int64_t *swap);
+int lcr_util_trans_cpushare_to_cpuweight(int64_t cpu_share);
+uint64_t lcr_util_trans_blkio_weight_to_io_weight(int weight);
+uint64_t lcr_util_trans_blkio_weight_to_io_bfq_weight(int weight);
+int lcr_util_get_cgroup_version();
#ifdef __cplusplus
}
--
2.25.1

View File

@ -0,0 +1,25 @@
From 4b7b830f5e20b4751584fd462219919d4bd756da Mon Sep 17 00:00:00 2001
From: wangyueliang <wangyueliang@kylinos.cn>
Date: Mon, 12 Apr 2021 10:30:24 +0800
Subject: [PATCH 09/10] Fix spelling errors
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 8a45755..dd960dd 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# lcr
`lcr`(Lightweight Container Runtime) is CLI tool for spawning and running containers according to OCI specification.
-It is based on `liblxc` and written by `C`. It can use by container engine: [iSulad](https://gitee.com/openeuler/iSulad). [iSulad](https://gitee.com/openeuler/iSulad) use `ldopen` to call functions defined in lcr.
+It is based on `liblxc` and written by `C`. It can use by container engine: [iSulad](https://gitee.com/openeuler/iSulad). [iSulad](https://gitee.com/openeuler/iSulad) use `dlopen` to call functions defined in lcr.
## How to Contribute
--
2.25.1

View File

@ -0,0 +1,33 @@
From e63b4e066c79caaab65db5bbb04f9c72aac399df Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Wed, 12 May 2021 10:54:57 +0800
Subject: [PATCH 10/10] fix memory usage of stats not right when runtime is
kata
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
src/json/schema/shim/client/runtime-stats.json | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/json/schema/shim/client/runtime-stats.json b/src/json/schema/shim/client/runtime-stats.json
index 707e58e..6ed9473 100644
--- a/src/json/schema/shim/client/runtime-stats.json
+++ b/src/json/schema/shim/client/runtime-stats.json
@@ -45,6 +45,14 @@
"$ref": "../../defs.json#/definitions/uint64"
}
}
+ },
+ "raw": {
+ "type": "object",
+ "properties": {
+ "total_inactive_file": {
+ "$ref": "../../defs.json#/definitions/uint64"
+ }
+ }
}
}
}
--
2.25.1

View File

@ -1,5 +1,5 @@
%global _version 2.0.5 %global _version 2.0.5
%global _release 20210319.090408.git6ac27845 %global _release 20210518.110611.git5225bddc
%global _inner_name isula_libutils %global _inner_name isula_libutils
Name: lcr Name: lcr
@ -14,6 +14,14 @@ BuildRoot: %{_tmppath}/lcr-%{version}
Patch1: 0001-support-quiet-of-log-config.patch Patch1: 0001-support-quiet-of-log-config.patch
Patch2: 0002-lcr-add-inactive-file-total-metric.patch Patch2: 0002-lcr-add-inactive-file-total-metric.patch
Patch3: 0003-lcr-add-default-runtime-field-for-isula-info.patch
Patch4: 0004-support-isula-exec-workdir.patch
Patch5: 0005-add-secure-compile-options.patch
Patch6: 0006-remove-invalid-fuzz-option.patch
Patch7: 0007-support-cgroup-v2.patch
Patch8: 0008-fix-pause-container-error.patch
Patch9: 0009-Fix-spelling-errors.patch
Patch10: 0010-fix-memory-usage-of-stats-not-right-when-runtime-is-.patch
BuildRequires: cmake BuildRequires: cmake
BuildRequires: lxc BuildRequires: lxc
@ -102,6 +110,12 @@ rm -rf %{buildroot}
%changelog %changelog
* Tue May 18 2021 wagnfengtu <wagnfengtu@huawei.com> - 2.0.5-20210518.110611.git5225bddc
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: sync patches from upstream
* Fri Mar 19 2021 wujing <wujing50@huawei.com> - 2.0.5-20210319.090408.git6ac27845 * Fri Mar 19 2021 wujing <wujing50@huawei.com> - 2.0.5-20210319.090408.git6ac27845
- Type:enhancement - Type:enhancement
- ID:NA - ID:NA