summaryrefslogtreecommitdiff
path: root/0004-2162-Fix-rename-issue-for-id-manager.patch
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-10-25 03:19:39 +0000
committerCoprDistGit <infra@openeuler.org>2023-10-25 03:19:39 +0000
commit723a12433aa7309e1eb0618be08d9b9fea389b81 (patch)
tree6e73a07585bfafeae4404d2247436ed13d337457 /0004-2162-Fix-rename-issue-for-id-manager.patch
parente3a65d47f4dae59923d032065e9c335fcdd7a0a8 (diff)
automatic import of iSuladopeneuler22.03_LTS_SP2
Diffstat (limited to '0004-2162-Fix-rename-issue-for-id-manager.patch')
-rw-r--r--0004-2162-Fix-rename-issue-for-id-manager.patch113
1 files changed, 113 insertions, 0 deletions
diff --git a/0004-2162-Fix-rename-issue-for-id-manager.patch b/0004-2162-Fix-rename-issue-for-id-manager.patch
new file mode 100644
index 0000000..93e099e
--- /dev/null
+++ b/0004-2162-Fix-rename-issue-for-id-manager.patch
@@ -0,0 +1,113 @@
+From 0dbf21e22d51721e43fa2c1abecf30da271501c5 Mon Sep 17 00:00:00 2001
+From: xuxuepeng <xuxuepeng1@huawei.com>
+Date: Thu, 31 Aug 2023 04:11:22 +0000
+Subject: [PATCH 04/33] !2162 Fix rename issue for id manager Merge pull
+ request !2162 from xuxuepeng/master
+
+---
+ src/daemon/common/id_name_manager.c | 21 ++++++++++++++++++-
+ src/daemon/common/id_name_manager.h | 1 +
+ .../container_cb/execution_information.c | 12 +++++++++++
+ src/daemon/sandbox/sandbox_manager.cc | 6 ++++--
+ 4 files changed, 37 insertions(+), 3 deletions(-)
+
+diff --git a/src/daemon/common/id_name_manager.c b/src/daemon/common/id_name_manager.c
+index e6b24798..3fc1c443 100644
+--- a/src/daemon/common/id_name_manager.c
++++ b/src/daemon/common/id_name_manager.c
+@@ -382,4 +382,23 @@ bool id_name_manager_remove_entry(const char *id, const char *name)
+ }
+
+ return ret;
+-}
+\ No newline at end of file
++}
++
++bool id_name_manager_rename(const char *new_name, const char *old_name)
++{
++ if (old_name == NULL || new_name == NULL) {
++ ERROR("Failed to rename empty name");
++ return false;
++ }
++
++ if (!try_add_name(new_name)) {
++ ERROR("Failed to add %s to name map", new_name);
++ return false;
++ }
++
++ if (!try_remove_name(old_name)) {
++ WARN("Failed to remove %s from name map", old_name);
++ }
++
++ return true;
++}
+diff --git a/src/daemon/common/id_name_manager.h b/src/daemon/common/id_name_manager.h
+index 3c9f6d45..09f0867e 100644
+--- a/src/daemon/common/id_name_manager.h
++++ b/src/daemon/common/id_name_manager.h
+@@ -27,6 +27,7 @@ bool id_name_manager_add_entry_with_existing_id(const char *id, const char *name
+ bool id_name_manager_add_entry_with_new_id(const char *name, char **id);
+ bool id_name_manager_add_entry_with_new_id_and_name(char **id, char **name);
+ bool id_name_manager_remove_entry(const char *id, const char *name);
++bool id_name_manager_rename(const char *new_name, const char *old_name);
+
+ #ifdef __cplusplus
+ }
+diff --git a/src/daemon/executor/container_cb/execution_information.c b/src/daemon/executor/container_cb/execution_information.c
+index 28480224..93e5032e 100644
+--- a/src/daemon/executor/container_cb/execution_information.c
++++ b/src/daemon/executor/container_cb/execution_information.c
+@@ -60,6 +60,7 @@
+ #include "utils_convert.h"
+ #include "utils_string.h"
+ #include "utils_verify.h"
++#include "id_name_manager.h"
+
+ static int container_version_cb(const container_version_request *request, container_version_response **response)
+ {
+@@ -1075,11 +1076,22 @@ static int container_rename(container_t *cont, const char *new_name)
+ goto out;
+ }
+
++ if (!id_name_manager_rename(new_name, old_name)) {
++ ERROR("Failed to rename %s to %s in id-name manager", old_name, new_name);
++ isulad_set_error_message("Failed to rename %s to %s in id-name manager", old_name, new_name);
++ ret = -1;
++ goto out;
++ }
++
+ if (!container_name_index_rename(new_name, old_name, id)) {
+ ERROR("Name %s is in use", new_name);
+ 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.",
+ new_name, new_name);
++ // restore name in id-name manager
++ if (!id_name_manager_rename(old_name, new_name)) {
++ ERROR("Failed to restore name from \"%s\" to \"%s\" in id-name manager", new_name, old_name);
++ }
+ ret = -1;
+ goto out;
+ }
+diff --git a/src/daemon/sandbox/sandbox_manager.cc b/src/daemon/sandbox/sandbox_manager.cc
+index 527a9aec..e258320a 100644
+--- a/src/daemon/sandbox/sandbox_manager.cc
++++ b/src/daemon/sandbox/sandbox_manager.cc
+@@ -210,11 +210,13 @@ bool SandboxManager::IDNameManagerRemoveEntry(const std::string &id, const std::
+ // Save the id and name of the sandbox to the map of the id_name_manager module
+ bool SandboxManager::IDNameManagerNewEntry(std::string &id, const std::string &name)
+ {
+- __isula_auto_free char *tmpId = NULL;
+ bool ret = false;
+ if (id.empty()) {
++ __isula_auto_free char *tmpId = NULL;
+ ret = id_name_manager_add_entry_with_new_id(name.c_str(), &tmpId);
+- id = tmpId;
++ if (tmpId != NULL) {
++ id = tmpId;
++ }
+ } else {
+ ret = id_name_manager_add_entry_with_existing_id(id.c_str(), name.c_str());
+ }
+--
+2.40.1
+