The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6860
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) === This checks all projects for attached volumes when attempting to delete a storage pool. This fixes #6697. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From f9339c0ac1ab9fd489eb614cd53ac356cec80968 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Mon, 10 Feb 2020 16:38:12 +0100 Subject: [PATCH] lxd: Fix error message when deleting storage pools This checks all projects for attached volumes when attempting to delete a storage pool. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/storage_pools.go | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/lxd/storage_pools.go b/lxd/storage_pools.go index 2bc243885a..c978fc1c82 100644 --- a/lxd/storage_pools.go +++ b/lxd/storage_pools.go @@ -674,27 +674,41 @@ func storagePoolDeleteCheckPreconditions(cluster *db.Cluster, poolName string, p return response.InternalError(err) } + var projects []string + + err = cluster.Transaction(func(tx *db.ClusterTx) error { + projects, err = tx.ProjectNames() + return err + }) + if err != nil { + return response.InternalError(err) + } + if len(volumeNames) > 0 { - volumes, err := cluster.StoragePoolVolumesGet("default", poolID, supportedVolumeTypes) - if err != nil { - return response.InternalError(err) - } + for _, project := range projects { + volumes, err := cluster.StoragePoolVolumesGet(project, poolID, supportedVolumeTypes) + if err != nil { + return response.InternalError(err) + } - for _, volume := range volumes { - if volume.Type != "image" { - return response.BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName)) + for _, volume := range volumes { + if volume.Type != "image" { + return response.BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName)) + } } } } - // Check if the storage pool is still referenced in any profiles. - profiles, err := profilesUsingPoolGetNames(cluster, "default", poolName) - if err != nil { - return response.SmartError(err) - } + for _, project := range projects { + // Check if the storage pool is still referenced in any profiles. + profiles, err := profilesUsingPoolGetNames(cluster, project, poolName) + if err != nil { + return response.SmartError(err) + } - if len(profiles) > 0 { - return response.BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n"))) + if len(profiles) > 0 { + return response.BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n"))) + } } return nil
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel