[lxc-devel] [lxd/master] Serialize network and storage pool creation
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Jan 9 02:34:29 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180109/e4bfd62d/attachment.bin>
-------------- next part --------------
From 8d768562defe4800e2ab674547042f9a396adc3a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 8 Jan 2018 21:31:58 -0500
Subject: [PATCH 1/2] network: Serialize network creation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/networks.go | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lxd/networks.go b/lxd/networks.go
index 7e78acea2..fb7659955 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -11,6 +11,7 @@ import (
"os/exec"
"strconv"
"strings"
+ "sync"
"github.com/gorilla/mux"
log "github.com/lxc/lxd/shared/log15"
@@ -24,6 +25,9 @@ import (
"github.com/lxc/lxd/shared/version"
)
+// Lock to prevent concurent networks creation
+var networkCreateLock sync.Mutex
+
// API endpoints
func networksGet(d *Daemon, r *http.Request) Response {
recursionStr := r.FormValue("recursion")
@@ -59,6 +63,9 @@ func networksGet(d *Daemon, r *http.Request) Response {
}
func networksPost(d *Daemon, r *http.Request) Response {
+ networkCreateLock.Lock()
+ defer networkCreateLock.Unlock()
+
req := api.NetworksPost{}
// Parse the request
From d97262ce28a8660fdcbdd192c78a0df5f192960d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 8 Jan 2018 21:32:20 -0500
Subject: [PATCH 2/2] storage: Serialize storage pool creation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #4150
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/storage_pools.go | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lxd/storage_pools.go b/lxd/storage_pools.go
index 6d4d80bc8..a676cdcad 100644
--- a/lxd/storage_pools.go
+++ b/lxd/storage_pools.go
@@ -6,6 +6,7 @@ import (
"net/http"
"strconv"
"strings"
+ "sync"
"github.com/gorilla/mux"
"github.com/lxc/lxd/lxd/db"
@@ -14,6 +15,9 @@ import (
"github.com/lxc/lxd/shared/version"
)
+// Lock to prevent concurent storage pools creation
+var storagePoolCreateLock sync.Mutex
+
// /1.0/storage-pools
// List all storage pools.
func storagePoolsGet(d *Daemon, r *http.Request) Response {
@@ -60,6 +64,9 @@ func storagePoolsGet(d *Daemon, r *http.Request) Response {
// /1.0/storage-pools
// Create a storage pool.
func storagePoolsPost(d *Daemon, r *http.Request) Response {
+ storagePoolCreateLock.Lock()
+ defer storagePoolCreateLock.Unlock()
+
req := api.StoragePoolsPost{}
// Parse the request.
More information about the lxc-devel
mailing list