summaryrefslogtreecommitdiff
path: root/0081-set-the-sandbox-status-to-not-ready-under-abnormal-c.patch
blob: 91a57f20cb03adce957e7408a9032b40529b45e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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