Discussion:
[lxc-devel] [lxd/master] lxd/containers: Improve hwaddr retry logic
stgraber on Github
2018-11-26 17:47:28 UTC
Permalink
From 4381c7ea24653679cbfa7c016c83c7d8e5ae3566 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <***@ubuntu.com>
Date: Mon, 26 Nov 2018 12:47:04 -0500
Subject: [PATCH] lxd/containers: Improve hwaddr retry logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <***@ubuntu.com>
---
lxd/container_lxc.go | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 5822874387..d4c3833794 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -7650,20 +7650,24 @@ func (c *containerLXC) fillNetworkDevice(name string, m types.Device) (types.Dev
}

// Update the database
- err = query.Retry(func() error { return updateKey(configKey, volatileHwaddr) })
- if err != nil {
- // Check if something else filled it in behind our back
- value, err1 := c.state.Cluster.ContainerConfigGet(c.id, configKey)
- if err1 != nil || value == "" {
- return nil, err
+ err = query.Retry(func() error {
+ err := updateKey(configKey, volatileHwaddr)
+ if err != nil {
+ // Check if something else filled it in behind our back
+ value, err1 := c.state.Cluster.ContainerConfigGet(c.id, configKey)
+ if err1 != nil || value == "" {
+ return err
+ }
+
+ c.localConfig[configKey] = value
+ c.expandedConfig[configKey] = value
+ return nil
}

- c.localConfig[configKey] = value
- c.expandedConfig[configKey] = value
- } else {
c.localConfig[configKey] = volatileHwaddr
c.expandedConfig[configKey] = volatileHwaddr
- }
+ return nil
+ })
}
newDevice["hwaddr"] = volatileHwaddr
}

Loading...