8 Star 1 Fork 40

src-openEuler/lcr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0011-remove-lcr-created-spec-only-if-create-failed.patch 2.99 KB
一键复制 编辑 原始数据 按行查看 历史
jake 提交于 2024-06-11 16:07 +08:00 . sync from upstream
From d059f53cad4f3063df4f7f93107ad2fbffdb301c Mon Sep 17 00:00:00 2001
From: jikai <jikai11@huawei.com>
Date: Fri, 26 Apr 2024 03:46:43 +0000
Subject: [PATCH 11/14] remove lcr-created spec only if create failed
Signed-off-by: jikai <jikai11@huawei.com>
---
src/runtime/lcrcontainer.c | 8 +++---
src/runtime/lcrcontainer_extend.c | 44 +++++++++++++++++++++++++++++++
src/runtime/lcrcontainer_extend.h | 2 ++
3 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/src/runtime/lcrcontainer.c b/src/runtime/lcrcontainer.c
index 2f0c9dd..c6959aa 100644
--- a/src/runtime/lcrcontainer.c
+++ b/src/runtime/lcrcontainer.c
@@ -186,15 +186,13 @@ bool lcr_create(const char *name, const char *lcrpath, void *oci_config)
bret = true;
out_unlock:
+ if (!bret) {
+ lcr_delete_spec(c, oci_spec);
+ }
if (partial_fd >= 0) {
close(partial_fd);
remove_partial(c);
}
- if (!bret) {
- if (!c->destroy(c)) {
- WARN("Unable to clean lxc resources");
- }
- }
lxc_container_put(c);
isula_libutils_free_log_prefix();
return bret;
diff --git a/src/runtime/lcrcontainer_extend.c b/src/runtime/lcrcontainer_extend.c
index 1409ea4..0b420d2 100644
--- a/src/runtime/lcrcontainer_extend.c
+++ b/src/runtime/lcrcontainer_extend.c
@@ -999,3 +999,47 @@ out_free_conf:
return ret;
}
+static void delete_specific_spec(const char *bundle, const char *name)
+{
+ char filepath[PATH_MAX] = { 0 };
+ int nret = snprintf(filepath, sizeof(filepath), "%s/%s", bundle, name);
+ if (nret < 0 || (size_t)nret >= sizeof(filepath)) {
+ ERROR("Failed to print string");
+ return;
+ }
+
+ if (unlink(filepath) != 0) {
+ SYSERROR("Failed to delete %s", filepath);
+ return;
+ }
+}
+
+void lcr_delete_spec(const struct lxc_container *c, oci_runtime_spec *container)
+{
+ const char *path = NULL;
+ const char *name = NULL;
+ char *bundle = NULL;
+
+ if (c == NULL || c->name == NULL || container == NULL) {
+ ERROR("Invalid arguments");
+ return;
+ }
+
+ path = c->config_path ? c->config_path : LCRPATH;
+ name = c->name;
+ bundle = lcr_get_bundle(path, name);
+ if (bundle == NULL) {
+ return;
+ }
+
+ if (container->hooks != NULL) {
+ delete_specific_spec(bundle, OCIHOOKSFILE);
+ }
+
+ delete_specific_spec(bundle, "config");
+
+ // There might not exist seccomp file, try to delete anyway
+ delete_specific_spec(bundle, "seccomp");
+
+ free(bundle);
+}
diff --git a/src/runtime/lcrcontainer_extend.h b/src/runtime/lcrcontainer_extend.h
index 539747c..c286450 100644
--- a/src/runtime/lcrcontainer_extend.h
+++ b/src/runtime/lcrcontainer_extend.h
@@ -76,6 +76,8 @@ bool lcr_save_spec(const char *name, const char *lcrpath, const struct isula_lin
bool translate_spec(const struct lxc_container *c, oci_runtime_spec *container);
+void lcr_delete_spec(const struct lxc_container *c, oci_runtime_spec *container);
+
#ifdef __cplusplus
}
#endif
--
2.34.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/lcr.git
git@gitee.com:src-openeuler/lcr.git
src-openeuler
lcr
lcr
master

搜索帮助

371d5123 14472233 46e8bd33 14472233