[lxc-devel] [lxd/stable-4.0] Storage: Ensure Location field is empty when storage driver is remote in storagePoolVolumeGetType

tomponline on Github lxc-bot at linuxcontainers.org
Tue Nov 10 10:29:36 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/20201110/ca8bd46a/attachment.bin>
-------------- next part --------------
From c6084f03be3efe425b10edcc190bcb33e8c2474d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 10 Nov 2020 10:26:34 +0000
Subject: [PATCH 1/2] lxd/db/storage/pools: Adds isRemoteStorage function

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/db/storage_pools.go | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index 14f72683d6..4a07bdbef4 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -869,3 +869,20 @@ var StoragePoolNodeConfigKeys = []string{
 	"lvm.thinpool_name",
 	"lvm.vg_name",
 }
+
+func (c *Cluster) isRemoteStorage(poolID int64) (bool, error) {
+	isRemoteStorage := false
+
+	err := c.Transaction(func(tx *ClusterTx) error {
+		driver, err := tx.GetStoragePoolDriver(poolID)
+		if err != nil {
+			return err
+		}
+
+		isRemoteStorage = shared.StringInSlice(driver, StorageRemoteDriverNames())
+
+		return nil
+	})
+
+	return isRemoteStorage, err
+}

From 91c72686fcbe3e5c155f8e9e9c50e1d7e413f6f8 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 10 Nov 2020 10:26:52 +0000
Subject: [PATCH 2/2] lxd/db/storage/volumes: Updates storagePoolVolumeGetType
 to not populate Location when driver is remote

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/db/storage_volumes.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index 240a33556b..19ba3a3045 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -241,11 +241,20 @@ func (c *Cluster) storagePoolVolumeGetType(project string, volumeName string, vo
 		return -1, nil, err
 	}
 
-	volumeNode, err := c.storageVolumeNodeGet(volumeID)
+	isRemoteStorage, err := c.isRemoteStorage(poolID)
 	if err != nil {
 		return -1, nil, err
 	}
 
+	volumeNode := ""
+
+	if !isRemoteStorage {
+		volumeNode, err = c.storageVolumeNodeGet(volumeID)
+		if err != nil {
+			return -1, nil, err
+		}
+	}
+
 	volumeConfig, err := c.storageVolumeConfigGet(volumeID, isSnapshot)
 	if err != nil {
 		return -1, nil, err


More information about the lxc-devel mailing list