The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/4803

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
The function should return the actual names, not the amount.

Signed-off-by: Thomas Hipp <[email protected]>
From 8c0ff86b67014b9c177694be86aad123e69823d2 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <[email protected]>
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 <[email protected]>
---
 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))
        }
 
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to