[lxc-devel] [lxd/master] Improve storage volume config handling

stgraber on Github lxc-bot at linuxcontainers.org
Tue Dec 17 23:52:45 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/20191217/7e1bf6b3/attachment.bin>
-------------- next part --------------
From 69450b6c280144bc04217ff3c11ee5b4718096db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Dec 2019 16:54:30 -0500
Subject: [PATCH 1/3] lxd/storage: Pass state to SupportedDrivers
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/drivers/load.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/drivers/load.go b/lxd/storage/drivers/load.go
index 086d66544b..501b579f34 100644
--- a/lxd/storage/drivers/load.go
+++ b/lxd/storage/drivers/load.go
@@ -30,11 +30,11 @@ func Load(state *state.State, driverName string, name string, config map[string]
 }
 
 // SupportedDrivers returns a list of supported storage drivers.
-func SupportedDrivers() []Info {
+func SupportedDrivers(s *state.State) []Info {
 	supportedDrivers := []Info{}
 
 	for driverName := range drivers {
-		driver, err := Load(nil, driverName, "", nil, nil, nil, nil)
+		driver, err := Load(s, driverName, "", nil, nil, nil, nil)
 		if err != nil {
 			continue
 		}

From c8b3703f16f2b6e6653b73ee7335b9d7819639f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Dec 2019 18:45:49 -0500
Subject: [PATCH 2/3] lxd/storage: Expand volume config in newVolume
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/backend_lxd.go | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 0c89abdaa2..65716b5989 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -117,7 +117,28 @@ func (b *lxdBackend) create(localOnly bool, op *operations.Operation) error {
 
 // newVolume returns a new Volume instance.
 func (b *lxdBackend) newVolume(volType drivers.VolumeType, contentType drivers.ContentType, volName string, volConfig map[string]string) drivers.Volume {
-	return drivers.NewVolume(b.driver, b.name, volType, contentType, volName, volConfig)
+	// Copy the config map.
+	newConfig := map[string]string{}
+	for k, v := range volConfig {
+		newConfig[k] = v
+	}
+
+	// And now expand it with the pool data.
+	for k, v := range b.db.Config {
+		if !strings.HasPrefix(k, "volume.") {
+			continue
+		}
+
+		fields := strings.SplitN(k, "volume.", 2)
+		name := fields[1]
+
+		_, ok := newConfig[name]
+		if !ok {
+			newConfig[name] = v
+		}
+	}
+
+	return drivers.NewVolume(b.driver, b.name, volType, contentType, volName, newConfig)
 }
 
 // GetResources returns utilisation information about the pool.

From 0dfbae65ba7f81e7d0dfb680f2e3e5ae244de4d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Dec 2019 18:51:24 -0500
Subject: [PATCH 3/3] lxd/storage/drivers: Use expanded config
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/drivers/driver_cephfs_volumes.go | 1 +
 lxd/storage/drivers/driver_dir_utils.go      | 8 +-------
 lxd/storage/drivers/driver_dir_volumes.go    | 5 +----
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go
index b0dde7aadd..62119fa5ff 100644
--- a/lxd/storage/drivers/driver_cephfs_volumes.go
+++ b/lxd/storage/drivers/driver_cephfs_volumes.go
@@ -299,6 +299,7 @@ func (d *cephfs) GetVolumeUsage(vol Volume) (int64, error) {
 
 // SetVolumeQuota applies a size limit on volume.
 func (d *cephfs) SetVolumeQuota(vol Volume, size string, op *operations.Operation) error {
+	// If size not specified in volume config, then use pool's default volume.size setting.
 	if size == "" || size == "0" {
 		size = d.config["volume.size"]
 	}
diff --git a/lxd/storage/drivers/driver_dir_utils.go b/lxd/storage/drivers/driver_dir_utils.go
index 1ba9dcfdca..ede9f4006b 100644
--- a/lxd/storage/drivers/driver_dir_utils.go
+++ b/lxd/storage/drivers/driver_dir_utils.go
@@ -107,12 +107,6 @@ func (d *dir) copyVolume(vol Volume, srcVol Volume, srcSnapshots []Volume, op *o
 // setupInitialQuota enables quota on a new volume and sets with an initial quota from config.
 // Returns a revert function that can be used to remove the quota if there is a subsequent error.
 func (d *dir) setupInitialQuota(vol Volume) (func(), error) {
-	// Extract specified size from pool or volume config.
-	size := d.config["volume.size"]
-	if vol.config["size"] != "" {
-		size = vol.config["size"]
-	}
-
 	volPath := vol.MountPath()
 
 	// Get the volume ID for the new volume, which is used to set project quota.
@@ -140,7 +134,7 @@ func (d *dir) setupInitialQuota(vol Volume) (func(), error) {
 	}()
 
 	// Set the quota.
-	err = d.setQuota(volPath, volID, size)
+	err = d.setQuota(volPath, volID, vol.config["size"])
 	if err != nil {
 		return nil, err
 	}
diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go
index 35d04b8dd8..49fc5d9d32 100644
--- a/lxd/storage/drivers/driver_dir_volumes.go
+++ b/lxd/storage/drivers/driver_dir_volumes.go
@@ -68,10 +68,7 @@ func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
 	// We expect the filler function to have converted the qcow2 image to raw into the rootBlockPath.
 	if vol.contentType == ContentTypeBlock {
 		// Extract specified size from pool or volume config.
-		blockSize := d.config["volume.size"]
-		if vol.config["size"] != "" {
-			blockSize = vol.config["size"]
-		}
+		blockSize := vol.config["size"]
 
 		if blockSize == "" {
 			blockSize = "10GB"


More information about the lxc-devel mailing list