The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7800
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) === And replaces functionality by stripping the snapshot name if supplied in the instance name to GetInstancePool() so that the parent instance's pool is returned. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From ddd18dc4a705427b52b561bcc507afb6ee576633 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 24 Aug 2020 14:51:14 +0100 Subject: [PATCH] lxd/db/instances: Removes instancePoolSnapshot function And replaces functionality by stripping the snapshot name if supplied in the instance name to GetInstancePool() so that the parent instance's pool is returned. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/db/instances.go | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/lxd/db/instances.go b/lxd/db/instances.go index b4362c4d11..c964aa81fd 100644 --- a/lxd/db/instances.go +++ b/lxd/db/instances.go @@ -658,11 +658,11 @@ func (c *ClusterTx) GetInstanceSnapshotsWithName(project string, name string) ([ return instances, nil } -// GetInstancePool returns the storage pool of a given instance. -func (c *ClusterTx) GetInstancePool(project, instanceName string) (string, error) { - if strings.Contains(instanceName, shared.SnapshotDelimiter) { - return c.instancePoolSnapshot(project, instanceName) - } +// GetInstancePool returns the storage pool of a given instance (or snapshot). +func (c *ClusterTx) GetInstancePool(projectName string, instanceName string) (string, error) { + // Strip snapshot name if supplied in instanceName, and lookup the storage pool of the parent instance + // as that must always be the same as the snapshot's storage pool. + instanceName, _, _ = shared.InstanceGetParentAndSnapshotName(instanceName) // Get container storage volume. Since container names are globally // unique, and their storage volumes carry the same name, their storage @@ -679,33 +679,7 @@ SELECT storage_pools.name FROM storage_pools AND storage_volumes_all.type IN(?,?) AND storage_volumes_all.project_id = instances.project_id ` - inargs := []interface{}{project, c.nodeID, instanceName, StoragePoolVolumeTypeContainer, StoragePoolVolumeTypeVM} - outargs := []interface{}{&poolName} - - err := c.tx.QueryRow(query, inargs...).Scan(outargs...) - if err != nil { - if err == sql.ErrNoRows { - return "", ErrNoSuchObject - } - - return "", err - } - - return poolName, nil -} - -func (c *ClusterTx) instancePoolSnapshot(project, fullName string) (string, error) { - poolName := "" - query := ` -SELECT storage_pools.name FROM storage_pools - JOIN storage_volumes_all ON storage_pools.id=storage_volumes_all.storage_pool_id - JOIN projects ON projects.id=storage_volumes_all.project_id - WHERE projects.name=? - AND storage_volumes_all.node_id=? - AND storage_volumes_all.name=? - AND storage_volumes_all.type IN(?,?) -` - inargs := []interface{}{project, c.nodeID, fullName, StoragePoolVolumeTypeContainer, StoragePoolVolumeTypeVM} + inargs := []interface{}{projectName, c.nodeID, instanceName, StoragePoolVolumeTypeContainer, StoragePoolVolumeTypeVM} outargs := []interface{}{&poolName} err := c.tx.QueryRow(query, inargs...).Scan(outargs...)
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel