[lxc-devel] [lxd/master] copy: wait asynchronously
brauner on Github
lxc-bot at linuxcontainers.org
Fri Apr 14 19:47:32 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170414/62c22966/attachment.bin>
-------------- next part --------------
From 73e0c2122545f61c4d40c4ef07b1ce54370ddd31 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 14 Apr 2017 12:06:56 +0200
Subject: [PATCH] copy: wait asynchronously
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxc/copy.go | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/lxc/copy.go b/lxc/copy.go
index 63c49d0..d2ebf4e 100644
--- a/lxc/copy.go
+++ b/lxc/copy.go
@@ -209,6 +209,18 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR
* course, if all the errors are websocket errors, let's just
* report that.
*/
+ waitchan := make(chan map[int]error, 2)
+ wait := func(cli *lxd.Client, op string, ch chan map[int]error, senderid int) {
+ msg := make(map[int]error, 1)
+ err := cli.WaitForSuccess(op)
+ if err != nil {
+ msg[senderid] = err
+ ch <- msg
+ }
+
+ msg[senderid] = nil
+ ch <- msg
+ }
for _, addr := range addresses {
var migration *api.Response
@@ -221,11 +233,22 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR
// If push mode is implemented then MigrateFrom will return a
// non-waitable operation. So this needs to be conditionalized
// on pull mode.
- if err = dest.WaitForSuccess(migration.Operation); err != nil {
+ destOpId := 0
+ go wait(dest, migration.Operation, waitchan, destOpId)
+ sourceOpId := 1
+ go wait(source, sourceWSResponse.Operation, waitchan, sourceOpId)
+
+ opStatus := make([]map[int]error, 2)
+ for i := 0; i < cap(waitchan); i++ {
+ opStatus[i] = <-waitchan
+ }
+
+ if opStatus[0][destOpId] != nil {
continue
}
- if err = source.WaitForSuccess(sourceWSResponse.Operation); err != nil {
+ err = opStatus[1][sourceOpId]
+ if err != nil {
return err
}
More information about the lxc-devel
mailing list