[lxc-devel] [lxd/master] Properly account for project when moving ceph-based containers
freeekanayaka on Github
lxc-bot at linuxcontainers.org
Wed Aug 14 13:44:49 UTC 2019
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/20190814/d3123032/attachment.bin>
-------------- next part --------------
From 8124558c59158f0dbfc0ad70edfb54ee94485461 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Wed, 14 Aug 2019 15:43:57 +0200
Subject: [PATCH] Properly account for project when moving ceph-based
containers
---
lxd/container_post.go | 2 +-
lxd/db/containers.go | 19 ++++++++++++-------
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/lxd/container_post.go b/lxd/container_post.go
index b822432676..f9a3b57619 100644
--- a/lxd/container_post.go
+++ b/lxd/container_post.go
@@ -428,7 +428,7 @@ func containerPostClusteringMigrateWithCeph(d *Daemon, c container, project, old
// Re-link the database entries against the new node name.
var poolName string
err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
- err := tx.ContainerNodeMove(oldName, newName, newNode)
+ err := tx.ContainerNodeMove(project, oldName, newName, newNode)
if err != nil {
return err
}
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 051c49b6a6..9021129baf 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -352,7 +352,7 @@ SELECT instances.name, nodes.name
// SnapshotIDsAndNames returns a map of snapshot IDs to snapshot names for the
// container with the given name.
-func (c *ClusterTx) SnapshotIDsAndNames(name string) (map[int]string, error) {
+func (c *ClusterTx) SnapshotIDsAndNames(project, name string) (map[int]string, error) {
prefix := name + shared.SnapshotDelimiter
length := len(prefix)
objects := make([]struct {
@@ -366,12 +366,17 @@ func (c *ClusterTx) SnapshotIDsAndNames(name string) (map[int]string, error) {
}{})
return []interface{}{&objects[i].ID, &objects[i].Name}
}
- stmt, err := c.tx.Prepare("SELECT id, name FROM instances WHERE SUBSTR(name,1,?)=? AND type=?")
+ stmt, err := c.tx.Prepare(`
+SELECT instances.id, instances.name
+FROM instances
+JOIN projects WHERE project.id = instances.project_id
+WHERE SUBSTR(name,1,?)=? AND type=? AND project.name=?
+`)
if err != nil {
return nil, err
}
defer stmt.Close()
- err = query.SelectObjects(stmt, dest, length, prefix, CTypeSnapshot)
+ err = query.SelectObjects(stmt, dest, length, prefix, CTypeSnapshot, project)
if err != nil {
return nil, err
}
@@ -386,10 +391,10 @@ func (c *ClusterTx) SnapshotIDsAndNames(name string) (map[int]string, error) {
//
// It's meant to be used when moving a non-running container backed by ceph
// from one cluster node to another.
-func (c *ClusterTx) ContainerNodeMove(oldName, newName, newNode string) error {
+func (c *ClusterTx) ContainerNodeMove(project, oldName, newName, newNode string) error {
// First check that the container to be moved is backed by a ceph
// volume.
- poolName, err := c.ContainerPool("default", oldName)
+ poolName, err := c.ContainerPool(project, oldName)
if err != nil {
return errors.Wrap(err, "failed to get container's storage pool name")
}
@@ -407,11 +412,11 @@ func (c *ClusterTx) ContainerNodeMove(oldName, newName, newNode string) error {
// Update the name of the container and of its snapshots, and the node
// ID they are associated with.
- containerID, err := c.InstanceID("default", oldName)
+ containerID, err := c.InstanceID(project, oldName)
if err != nil {
return errors.Wrap(err, "failed to get container's ID")
}
- snapshots, err := c.SnapshotIDsAndNames(oldName)
+ snapshots, err := c.SnapshotIDsAndNames(project, oldName)
if err != nil {
return errors.Wrap(err, "failed to get container's snapshots")
}
More information about the lxc-devel
mailing list