[lxc-devel] [lxd/master] lxc: Only target if --target is passed

stgraber on Github lxc-bot at linuxcontainers.org
Wed Aug 22 20:36:40 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 503 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180822/024d6157/attachment.bin>
-------------- next part --------------
From 6c80fbb93422b83a18aea8b393d1cc6201f13b9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 22 Aug 2018 16:35:35 -0400
Subject: [PATCH] lxc: Only target if --target is passed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Otherwise we end up with differing structs pointing to the same server,
bypassing handling for copy/move within the same server.

Closes #4956

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/copy.go | 11 ++++++++---
 lxc/init.go |  5 ++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lxc/copy.go b/lxc/copy.go
index d9e65ec2be..fff2d7040c 100644
--- a/lxc/copy.go
+++ b/lxc/copy.go
@@ -100,7 +100,6 @@ func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 			return err
 		}
 	}
-
 	// Confirm that --target is only used with a cluster
 	if c.flagTarget != "" && !dest.IsClustered() {
 		return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster"))
@@ -214,7 +213,10 @@ func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 		}
 
 		// Do the actual copy
-		dest = dest.UseTarget(c.flagTarget)
+		if c.flagTarget != "" {
+			dest = dest.UseTarget(c.flagTarget)
+		}
+
 		op, err = dest.CopyContainerSnapshot(source, srcFields[0], *entry, &args)
 		if err != nil {
 			return err
@@ -298,7 +300,10 @@ func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 		}
 
 		// Do the actual copy
-		dest = dest.UseTarget(c.flagTarget)
+		if c.flagTarget != "" {
+			dest = dest.UseTarget(c.flagTarget)
+		}
+
 		op, err = dest.CopyContainer(source, *entry, &args)
 		if err != nil {
 			return err
diff --git a/lxc/init.go b/lxc/init.go
index 755b0c44b8..4b562fc0e7 100644
--- a/lxc/init.go
+++ b/lxc/init.go
@@ -86,7 +86,10 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.ContainerServe
 	if err != nil {
 		return nil, "", err
 	}
-	d = d.UseTarget(c.flagTarget)
+
+	if c.flagTarget != "" {
+		d = d.UseTarget(c.flagTarget)
+	}
 
 	profiles := []string{}
 	for _, p := range c.flagProfile {


More information about the lxc-devel mailing list