blob: 21d519c1ef7cafc694eb3b943d45124f92673e42 (
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
|
From dcceff17d6c2e1c97cb18c65260edfd2d6a3a60a Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
Date: Tue, 12 Sep 2023 03:20:33 +0000
Subject: [PATCH 15/33] !2182 Add mutex for container list in sandbox * Add
mutex for container list in sandbox
---
src/daemon/sandbox/sandbox.cc | 4 ++++
src/daemon/sandbox/sandbox.h | 1 +
2 files changed, 5 insertions(+)
diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc
index 1723e95e..f391e809 100644
--- a/src/daemon/sandbox/sandbox.cc
+++ b/src/daemon/sandbox/sandbox.cc
@@ -131,6 +131,7 @@ auto Sandbox::GetRuntimeHandle() const -> const std::string &
auto Sandbox::GetContainers() -> std::vector<std::string>
{
+ ReadGuard<RWMutex> lock(m_containersMutex);
return m_containers;
}
@@ -394,16 +395,19 @@ void Sandbox::RemoveLabels(const std::string &key)
void Sandbox::AddContainer(const std::string &id)
{
+ WriteGuard<RWMutex> lock(m_containersMutex);
m_containers.push_back(id);
}
void Sandbox::SetConatiners(const std::vector<std::string> &cons)
{
+ WriteGuard<RWMutex> lock(m_containersMutex);
m_containers = cons;
}
void Sandbox::RemoveContainer(const std::string &id)
{
+ WriteGuard<RWMutex> lock(m_containersMutex);
auto it = std::find(m_containers.begin(), m_containers.end(), id);
if (it != m_containers.end()) {
m_containers.erase(it);
diff --git a/src/daemon/sandbox/sandbox.h b/src/daemon/sandbox/sandbox.h
index 0f135e70..89350131 100644
--- a/src/daemon/sandbox/sandbox.h
+++ b/src/daemon/sandbox/sandbox.h
@@ -200,6 +200,7 @@ private:
std::string m_networkSettings;
// container id lists
std::vector<std::string> m_containers;
+ RWMutex m_containersMutex;
// TOOD: m_sandboxConfig is a protobuf message, it can be converted to json string directly
// if save json string directly for sandbox recover, we need to consider hot
// upgrade between different CRI versions
--
2.40.1
|