1 Star 0 Fork 44

严莹/iSulad

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0081-set-the-sandbox-status-to-not-ready-under-abnormal-c.patch 3.12 KB
一键复制 编辑 原始数据 按行查看 历史
liuxu 提交于 2024-05-11 16:29 . upgrade from upstream
From 934d289aa535bbb87bfe484c4de34275b968fb87 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Wed, 8 May 2024 11:40:40 +0800
Subject: [PATCH 81/85] set the sandbox status to not ready under abnormal
circumstances
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
src/daemon/sandbox/sandbox.cc | 34 +++++++++++++++++++++++++---------
src/daemon/sandbox/sandbox.h | 1 +
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc
index bae5b8db..279bf628 100644
--- a/src/daemon/sandbox/sandbox.cc
+++ b/src/daemon/sandbox/sandbox.cc
@@ -371,6 +371,8 @@ void Sandbox::DoUpdateStatus(std::unique_ptr<ControllerSandboxStatus> status, Er
m_state.exitedAt = status->exitedAt;
if (status->state == std::string(SANDBOX_READY_STATE_STR)) {
m_state.status = SANDBOX_STATUS_RUNNING;
+ } else {
+ m_state.status = SANDBOX_STATUS_STOPPED;
}
}
@@ -459,6 +461,24 @@ auto Sandbox::Save(Errors &error) -> bool
return true;
}
+bool Sandbox::DoStatusUpdateAndWaitInLoad(const std::string &sandboxID, Errors &error)
+{
+ if (!UpdateStatus(error)) {
+ ERROR("Failed to update status of Sandbox, id='%s'", sandboxID.c_str());
+ return false;
+ }
+
+ // Regardless of whether the sandbox is ready,
+ // Wait() is required to call to monitor whether the kuasar sandbox is ready or exits.
+ // TODO: distinguish the meaning of Wait() return value in different states of sandbox
+ if (!m_controller->Wait(shared_from_this(), sandboxID, error)) {
+ ERROR("Failed to restore wait callback");
+ return false;
+ }
+
+ return true;
+}
+
auto Sandbox::Load(Errors &error) -> bool
{
if (!LoadState(error)) {
@@ -478,15 +498,11 @@ auto Sandbox::Load(Errors &error) -> bool
LoadNetworkSetting();
- if (!UpdateStatus(error)) {
- ERROR("Failed to update status of Sandbox, id='%s'", m_id.c_str());
- return false;
- }
-
- // TODO: distinguish the meaning of Wait() return value in different states of sandbox
- if (!m_controller->Wait(shared_from_this(), m_id, error)) {
- ERROR("Failed to restore wait callback");
- return false;
+ // When the sandbox status acquisition fails or wait fails, the sandbox status is set to not ready,
+ // and the user decides whether to delete the sandbox.
+ if (!DoStatusUpdateAndWaitInLoad(m_id, error)) {
+ WriteGuard<RWMutex> lock(m_stateMutex);
+ m_state.status = SANDBOX_STATUS_STOPPED;
}
return true;
diff --git a/src/daemon/sandbox/sandbox.h b/src/daemon/sandbox/sandbox.h
index 20a8e338..42fbee2a 100644
--- a/src/daemon/sandbox/sandbox.h
+++ b/src/daemon/sandbox/sandbox.h
@@ -156,6 +156,7 @@ private:
auto SetupSandboxFiles(Errors &error) -> bool;
void DoUpdateStatus(std::unique_ptr<ControllerSandboxStatus> status, Errors &error);
void DoUpdateExitedStatus(const ControllerExitInfo &exitInfo);
+ bool DoStatusUpdateAndWaitInLoad(const std::string &sandboxID, Errors &error);
auto GetMetadataJsonPath() -> std::string;
auto GetStatePath() -> std::string;
--
2.34.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yanyir/iSulad.git
git@gitee.com:yanyir/iSulad.git
yanyir
iSulad
iSulad
master

搜索帮助