lcr/0013-improve-error-of-lcr-apis.patch
openeuler-sync-bot dd2d06b3b3 !276 [sync] PR-273: sync from upstream
* sync from upstream
2023-12-11 14:34:37 +00:00

170 lines
7.2 KiB
Diff

From ffd58bff069d0d1bde6a6ad14f4c2b81fac237c8 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 16 Nov 2023 10:58:52 +0800
Subject: [PATCH 13/20] improve error of lcr apis
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/error.h | 1 +
src/lcrcontainer.c | 41 +++++++++++++++++++++++++++--------------
2 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/src/error.h b/src/error.h
index bc7bcb3..e2ad20b 100644
--- a/src/error.h
+++ b/src/error.h
@@ -50,6 +50,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/lcrcontainer.c b/src/lcrcontainer.c
index 5c69c8e..4256799 100644
--- a/src/lcrcontainer.c
+++ b/src/lcrcontainer.c
@@ -353,7 +353,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;
}
@@ -401,7 +402,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;
}
@@ -474,7 +476,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;
}
@@ -519,7 +522,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;
}
@@ -563,7 +567,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;
}
@@ -600,7 +605,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;
}
@@ -651,7 +657,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;
}
@@ -694,7 +701,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;
}
@@ -738,7 +746,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;
}
@@ -761,7 +770,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;
}
@@ -788,7 +797,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;
}
@@ -837,7 +847,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