[lxc-devel] [lxd/master] Storage fixes

stgraber on Github lxc-bot at linuxcontainers.org
Fri Jan 3 23:54:01 UTC 2020


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/20200103/82692ebc/attachment.bin>
-------------- next part --------------
From 4d761a8904277780fe8dd31d6f3bd3216bb181b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 20 Dec 2019 10:03:41 -0500
Subject: [PATCH 1/3] lxd/storage/drivers: Rename applyQuota to initVolume
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/generic.go | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lxd/storage/drivers/generic.go b/lxd/storage/drivers/generic.go
index 80acfd2cb7..b0a1855444 100644
--- a/lxd/storage/drivers/generic.go
+++ b/lxd/storage/drivers/generic.go
@@ -15,7 +15,8 @@ import (
 )
 
 // genericCopyVolume copies a volume and its snapshots using a non-optimized method.
-func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vol Volume, srcVol Volume, srcSnapshots []Volume, op *operations.Operation) error {
+// initVolume is run against the main volume (not the snapshots) and is often used for quota initialization.
+func genericCopyVolume(d Driver, initVolume func(vol Volume) (func(), error), vol Volume, srcVol Volume, srcSnapshots []Volume, op *operations.Operation) error {
 	if vol.contentType != ContentTypeFS || srcVol.contentType != ContentTypeFS {
 		return fmt.Errorf("Content type not supported")
 	}
@@ -74,9 +75,9 @@ func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vo
 			}
 		}
 
-		// Apply some quotas if needed.
-		if applyQuota != nil {
-			_, err := applyQuota(vol)
+		// Run volume-specific init logic.
+		if initVolume != nil {
+			_, err := initVolume(vol)
 			if err != nil {
 				return err
 			}
@@ -97,7 +98,8 @@ func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vo
 }
 
 // genericCreateVolumeFromMigration receives a volume and its snapshots over a non-optimized method.
-func genericCreateVolumeFromMigration(d Driver, applyQuota func(vol Volume) (func(), error), vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
+// initVolume is run against the main volume (not the snapshots) and is often used for quota initialization.
+func genericCreateVolumeFromMigration(d Driver, initVolume func(vol Volume) (func(), error), vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
 	// Create the main volume path.
 	if !volTargetArgs.Refresh {
 		err := d.CreateVolume(vol, preFiller, op)
@@ -154,9 +156,9 @@ func genericCreateVolumeFromMigration(d Driver, applyQuota func(vol Volume) (fun
 			revertSnaps = append(revertSnaps, snapName)
 		}
 
-		// Apply quotas.
-		if applyQuota != nil {
-			_, err := applyQuota(vol)
+		// Run volume-specific init logic.
+		if initVolume != nil {
+			_, err := initVolume(vol)
 			if err != nil {
 				return err
 			}

From 2e688133db004c4560acf0df6874f04fc8915468 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jan 2020 14:21:21 -0500
Subject: [PATCH 2/3] lxd/storage/drivers: Fix bad ExpandedConfig
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/volume.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go
index 055b233040..b7ec773dff 100644
--- a/lxd/storage/drivers/volume.go
+++ b/lxd/storage/drivers/volume.go
@@ -83,7 +83,7 @@ func (v Volume) Config() map[string]string {
 // ExpandedConfig returns either the value of the volume's config key or the pool's config "volume.{key}" value.
 func (v Volume) ExpandedConfig(key string) string {
 	volVal, ok := v.config[key]
-	if !ok {
+	if ok {
 		return volVal
 	}
 

From 6a74935ad10fe0a4c68f9246a5de6072216228df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 3 Jan 2020 14:24:45 -0500
Subject: [PATCH 3/3] lxd/storage: Include size in instance update
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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index e8eb4ee115..726f69366c 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1231,7 +1231,13 @@ func (b *lxdBackend) UpdateInstance(inst instance.Instance, newDesc string, newC
 			return fmt.Errorf("Instance volume 'block.filesystem' property cannot be changed")
 		}
 
-		curVol := b.newVolume(volType, contentType, volStorageName, curVol.Config)
+		// Get the root disk device config.
+		rootDiskConf, err := b.instanceRootVolumeConfig(inst)
+		if err != nil {
+			return err
+		}
+
+		curVol := b.newVolume(volType, contentType, volStorageName, rootDiskConf)
 		if !userOnly {
 			err = b.driver.UpdateVolume(curVol, changedConfig)
 			if err != nil {


More information about the lxc-devel mailing list