[lxc-devel] [lxd/master] Fix apply_quota

stgraber on Github lxc-bot at linuxcontainers.org
Tue Nov 5 05:53:40 UTC 2019


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/20191104/de19c2c5/attachment-0001.bin>
-------------- next part --------------
From 2f09cb029f8dfce5bd45325ab3b9e549dd2aadc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 5 Nov 2019 00:46:40 -0500
Subject: [PATCH 1/2] lxd/container: Fix apply_quota
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>
---
 doc/containers.md   | 2 +-
 lxd/container.go    | 4 ++--
 lxd/device/disk.go  | 8 ++++----
 shared/container.go | 4 ++++
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/doc/containers.md b/doc/containers.md
index e6d3d4081b..88a095a67e 100644
--- a/doc/containers.md
+++ b/doc/containers.md
@@ -93,7 +93,6 @@ The following volatile keys are currently internally used by LXD:
 
 Key                                         | Type      | Default       | Description
 :--                                         | :---      | :------       | :----------
-volatile.apply\_quota                       | string    | -             | Disk quota to be applied on next container start
 volatile.apply\_template                    | string    | -             | The name of a template hook which should be triggered upon next startup
 volatile.base\_image                        | string    | -             | The hash of the image the container was created from, if any.
 volatile.idmap.base                         | integer   | -             | The first id in the container's primary idmap range
@@ -101,6 +100,7 @@ volatile.idmap.current                      | string    | -             | The id
 volatile.idmap.next                         | string    | -             | The idmap to use next time the container starts
 volatile.last\_state.idmap                  | string    | -             | Serialized container uid/gid map
 volatile.last\_state.power                  | string    | -             | Container state as of last host shutdown
+volatile.\<name\>.apply\_quota              | string    | -             | Disk quota to be applied on next container start
 volatile.\<name\>.host\_name                | string    | -             | Network device name on the host
 volatile.\<name\>.hwaddr                    | string    | -             | Network device MAC address (when no hwaddr property is set on the device itself)
 volatile.\<name\>.last\_state.created       | string    | -             | Whether or not the network device physical device was created ("true" or "false")
diff --git a/lxd/container.go b/lxd/container.go
index 8f52cc1a8f..cb9b5976fc 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -977,7 +977,7 @@ func containerCreateInternal(s *state.State, args db.InstanceArgs) (container, e
 
 func containerConfigureInternal(c Instance) error {
 	// Find the root device
-	_, rootDiskDevice, err := shared.GetRootDiskDevice(c.ExpandedDevices().CloneNative())
+	rootDiskDeviceKey, rootDiskDevice, err := shared.GetRootDiskDevice(c.ExpandedDevices().CloneNative())
 	if err != nil {
 		return err
 	}
@@ -992,7 +992,7 @@ func containerConfigureInternal(c Instance) error {
 	if rootDiskDevice["size"] != "" {
 		storageTypeName := storage.GetStorageTypeName()
 		if (storageTypeName == "lvm" || storageTypeName == "ceph") && c.IsRunning() {
-			err = c.VolatileSet(map[string]string{"volatile.apply_quota": rootDiskDevice["size"]})
+			err = c.VolatileSet(map[string]string{fmt.Sprintf("volatile.%s.apply_quota", rootDiskDeviceKey): rootDiskDevice["size"]})
 			if err != nil {
 				return err
 			}
diff --git a/lxd/device/disk.go b/lxd/device/disk.go
index 853598006b..fe1db520bd 100644
--- a/lxd/device/disk.go
+++ b/lxd/device/disk.go
@@ -225,14 +225,14 @@ func (d *disk) Start() (*RunConfig, error) {
 		v := d.volatileGet()
 
 		// Handle previous requests for setting new quotas.
-		if v["volatile.apply_quota"] != "" {
-			applied, err := d.applyQuota(v["volatile.apply_quota"])
+		if v["apply_quota"] != "" {
+			applied, err := d.applyQuota(v["apply_quota"])
 			if err != nil || !applied {
 				return nil, err
 			}
 
 			// Remove volatile apply_quota key if successful.
-			err = d.volatileSet(map[string]string{"volatile.apply_quota": ""})
+			err = d.volatileSet(map[string]string{"apply_quota": ""})
 			if err != nil {
 				return nil, err
 			}
@@ -376,7 +376,7 @@ func (d *disk) Update(oldDevices deviceConfig.Devices, isRunning bool) error {
 
 			if !applied {
 				// Save volatile apply_quota key for next boot if cannot apply now.
-				err = d.volatileSet(map[string]string{"volatile.apply_quota": newRootDiskDeviceSize})
+				err = d.volatileSet(map[string]string{"apply_quota": newRootDiskDeviceSize})
 				if err != nil {
 					return err
 				}
diff --git a/shared/container.go b/shared/container.go
index c67f52940f..869c6c1fc5 100644
--- a/shared/container.go
+++ b/shared/container.go
@@ -387,6 +387,10 @@ func ConfigKeyChecker(key string) (func(value string) error, error) {
 		if strings.HasSuffix(key, ".spoofcheck") {
 			return IsAny, nil
 		}
+
+		if strings.HasSuffix(key, ".apply_quota") {
+			return IsAny, nil
+		}
 	}
 
 	if strings.HasPrefix(key, "environment.") {

From 6647f4185a08a6b3f24e6a9122183e6853ede980 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 5 Nov 2019 00:53:08 -0500
Subject: [PATCH 2/2] lxd/storage/lvm: Fix version parsing
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/storage_lvm.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index a16bdb4811..894e91e7c3 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -61,6 +61,11 @@ func (s *storageLvm) StorageCoreInit() error {
 		if len(fields) < 2 {
 			continue
 		}
+
+		if !strings.Contains(line, "version:") {
+			continue
+		}
+
 		if idx > 0 {
 			s.sTypeVersion += " / "
 		}


More information about the lxc-devel mailing list