[lxc-devel] [lxd/master] storage: avoid infinite loop
brauner on Github
lxc-bot at linuxcontainers.org
Wed May 10 22:49:36 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 431 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170510/0a690e52/attachment.bin>
-------------- next part --------------
From 1d8e3681f7844a8c7030dc3b9107484634eba9c9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 11 May 2017 00:45:13 +0200
Subject: [PATCH 1/2] storage: avoid infinite loop
ConfigKeySet() called Update() and Update called ConfiKeySet().
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/container.go | 26 ++++++++++++++++----------
lxd/container_lxc.go | 2 +-
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/lxd/container.go b/lxd/container.go
index a5c8624..0ad88b3 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -838,23 +838,29 @@ func containerConfigureInternal(c container) error {
return err
}
+ ourStart, err := c.StorageStart()
+ if err != nil {
+ return err
+ }
+
+ // handle quota: at this point, storage is guaranteed to be ready
+ storage := c.Storage()
if rootDiskDevice["size"] != "" {
- size, err := shared.ParseByteSizeString(rootDiskDevice["size"])
- if err != nil {
- return err
+ storageTypeName := storage.GetStorageTypeName()
+ if storageTypeName == "lvm" && c.IsRunning() {
+ err = c.ConfigKeySet("volatile.apply_quota", rootDiskDevice["size"])
+ } else {
+ size, err := shared.ParseByteSizeString(rootDiskDevice["size"])
+ if err != nil {
+ return err
+ }
+ err = storage.ContainerSetQuota(c, size)
}
-
- // Storage is guaranteed to be ready.
- err = c.Storage().ContainerSetQuota(c, size)
if err != nil {
return err
}
}
- ourStart, err := c.StorageStart()
- if err != nil {
- return err
- }
if ourStart {
defer c.StorageStop()
}
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 537b2ff..32b37a5 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -3395,7 +3395,7 @@ func (c *containerLXC) Update(args containerArgs, userRequested bool) error {
storageTypeName := c.storage.GetStorageTypeName()
storageIsReady := c.storage.ContainerStorageReady(c.Name())
if storageTypeName == "lvm" && isRunning || !storageIsReady {
- err = c.ConfigKeySet("volatile.apply_quota", newRootDiskDeviceSize)
+ c.localConfig["volatile.apply_quota"] = newRootDiskDeviceSize
} else {
size, err := shared.ParseByteSizeString(newRootDiskDeviceSize)
if err != nil {
From ca0a4efe9110e89e9a1e192c6b7176673a1d782b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 11 May 2017 00:46:42 +0200
Subject: [PATCH 2/2] test: add quota tests
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
test/suites/storage.sh | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/test/suites/storage.sh b/test/suites/storage.sh
index 3786668..5f4a069 100644
--- a/test/suites/storage.sh
+++ b/test/suites/storage.sh
@@ -1,4 +1,6 @@
test_storage() {
+ ensure_import_testimage
+
# shellcheck disable=2039
local LXD_STORAGE_DIR lxd_backend
@@ -688,6 +690,41 @@ test_storage() {
fi
)
+ # Test applying quota
+ QUOTA1="10GB"
+ QUOTA2="11GB"
+ if [ "$lxd_backend" = "lvm" ]; then
+ QUOTA1="20MB"
+ QUOTA2="21MB"
+ fi
+
+ if [ "$lxd_backend" != "dir" ]; then
+ lxc launch testimage quota1
+ lxc profile device set default root size "${QUOTA1}"
+ lxc restart quota1
+
+ lxc launch testimage quota2
+ lxc restart quota2
+
+ lxc init testimage quota3
+ lxc start quota3
+
+ lxc profile device set default root size "${QUOTA2}"
+
+ lxc restart quota1
+ lxc restart quota2
+ lxc restart quota3
+
+ lxc profile device unset default root size
+ lxc restart quota1
+ lxc restart quota2
+ lxc restart quota3
+
+ lxc delete -f quota1
+ lxc delete -f quota2
+ lxc delete -f quota3
+ fi
+
# shellcheck disable=SC2031
LXD_DIR="${LXD_DIR}"
kill_lxd "${LXD_STORAGE_DIR}"
More information about the lxc-devel
mailing list