[lxc-devel] [lxd/master] container/lxc: Moves NIC hotplugging into own functions

tomponline on Github lxc-bot at linuxcontainers.org
Thu Jul 4 16:23:20 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 425 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190704/02787d79/attachment.bin>
-------------- next part --------------
From 3fbc27e2b4ba55a2cdad09eca72dc31acdec5f98 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 4 Jul 2019 16:07:45 +0100
Subject: [PATCH] container/lxc: Moves all nic hot plug functionality into
 separate functions

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/container_lxc.go | 47 ++++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index d739e7523c..0859bb0b5e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -5535,19 +5535,6 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 						return err
 					}
 				}
-
-				if m["type"] == "nic" && shared.StringInSlice(m["nictype"], []string{"bridged", "p2p"}) {
-					// Populate network device with container nic names.
-					m, err := c.fillNetworkDevice(k, m)
-					if err != nil {
-						return err
-					}
-
-					err = c.setupHostVethDevice(k, m, types.Device{})
-					if err != nil {
-						return err
-					}
-				}
 			} else if m["type"] == "usb" {
 				if usbs == nil {
 					usbs, err = deviceLoadUsb()
@@ -5652,14 +5639,8 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 		for k, m := range updateDevices {
 			if m["type"] == "disk" {
 				updateDiskLimit = true
-			} else if m["type"] == "nic" && shared.StringInSlice(m["nictype"], []string{"bridged", "p2p"}) {
-				// Populate network device with container nic names.
-				m, err := c.fillNetworkDevice(k, m)
-				if err != nil {
-					return err
-				}
-
-				err = c.setupHostVethDevice(k, m, oldExpandedDevices[k])
+			} else if m["type"] == "nic" {
+				c.updateNetworkDevice(k, m, oldExpandedDevices[k])
 				if err != nil {
 					return err
 				}
@@ -9049,6 +9030,13 @@ func (c *containerLXC) insertNetworkDevice(name string, m types.Device) (types.D
 		return nil, fmt.Errorf("Failed to attach interface: %s: %s", devName, err)
 	}
 
+	if m["type"] == "nic" && shared.StringInSlice(m["nictype"], []string{"bridged", "p2p"}) {
+		err = c.setupHostVethDevice(name, m, types.Device{})
+		if err != nil {
+			return nil, err
+		}
+	}
+
 	return m, nil
 }
 
@@ -9062,6 +9050,23 @@ func (c *containerLXC) checkIPVLANSupport() error {
 	return errors.New("LXC is missing one or more API extensions: network_ipvlan, network_l2proxy, network_gateway_device_route")
 }
 
+func (c *containerLXC) updateNetworkDevice(name string, m types.Device, oldDevice types.Device) error {
+	if shared.StringInSlice(m["nictype"], []string{"bridged", "p2p"}) {
+		// Populate network device with container nic names.
+		m, err := c.fillNetworkDevice(name, m)
+		if err != nil {
+			return err
+		}
+
+		err = c.setupHostVethDevice(name, m, oldDevice)
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
 func (c *containerLXC) removeNetworkDevice(name string, m types.Device) error {
 	// Fill in some fields from volatile
 	m, err := c.fillNetworkDevice(name, m)


More information about the lxc-devel mailing list