The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6080
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) ===
From 8124558c59158f0dbfc0ad70edfb54ee94485461 Mon Sep 17 00:00:00 2001 From: Free Ekanayaka <free.ekanay...@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") }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel