[lxc-devel] [lxd/master] lxd: Fix StoragePoolVolumesGetNames

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Jul 17 18:55:15 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 419 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180717/8f93d0ba/attachment.bin>
-------------- next part --------------
From 8c0ff86b67014b9c177694be86aad123e69823d2 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 17 Jul 2018 20:53:56 +0200
Subject: [PATCH] lxd: Fix StoragePoolVolumesGetNames

The function should return the actual names, not the amount.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/db/storage_pools.go | 12 +++++++-----
 lxd/storage_pools.go    |  4 ++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index 5fffdf55b..d977f31cc 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -657,7 +657,7 @@ func (c *Cluster) StoragePoolDelete(poolName string) (*api.StoragePool, error) {
 
 // StoragePoolVolumesGetNames gets the names of all storage volumes attached to
 // a given storage pool.
-func (c *Cluster) StoragePoolVolumesGetNames(poolID int64) (int, error) {
+func (c *Cluster) StoragePoolVolumesGetNames(poolID int64) ([]string, error) {
 	var volumeName string
 	query := "SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=?"
 	inargs := []interface{}{poolID, c.nodeID}
@@ -665,14 +665,16 @@ func (c *Cluster) StoragePoolVolumesGetNames(poolID int64) (int, error) {
 
 	result, err := queryScan(c.db, query, inargs, outargs)
 	if err != nil {
-		return -1, err
+		return []string{}, err
 	}
 
-	if len(result) == 0 {
-		return 0, nil
+	var out []string
+
+	for _, r := range result {
+		out = append(out, r[0].(string))
 	}
 
-	return len(result), nil
+	return out, nil
 }
 
 // StoragePoolVolumesGet returns all storage volumes attached to a given
diff --git a/lxd/storage_pools.go b/lxd/storage_pools.go
index 35a33a14b..192f20afd 100644
--- a/lxd/storage_pools.go
+++ b/lxd/storage_pools.go
@@ -599,12 +599,12 @@ func storagePoolDelete(d *Daemon, r *http.Request) Response {
 }
 
 func storagePoolDeleteCheckPreconditions(cluster *db.Cluster, poolName string, poolID int64) Response {
-	volumeCount, err := cluster.StoragePoolVolumesGetNames(poolID)
+	volumeNames, err := cluster.StoragePoolVolumesGetNames(poolID)
 	if err != nil {
 		return InternalError(err)
 	}
 
-	if volumeCount > 0 {
+	if len(volumeNames) > 0 {
 		return BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName))
 	}
 


More information about the lxc-devel mailing list