[lxc-devel] [lxd/master] Tp instance nic routed cleanup

tomponline on Github lxc-bot at linuxcontainers.org
Wed Dec 16 10:02:51 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 424 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201216/9d788783/attachment.bin>
-------------- next part --------------
From fc834648941c72b9e09d1c9cb220d8da0e060bea Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 16 Dec 2020 09:39:19 +0000
Subject: [PATCH 1/2] lxd/device/nic/routed: Switches to
 network.InterfaceExists for clarity

Makes error quoting consistent.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/device/nic_routed.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lxd/device/nic_routed.go b/lxd/device/nic_routed.go
index ed47d9dbd3..0a9ec6cbc0 100644
--- a/lxd/device/nic_routed.go
+++ b/lxd/device/nic_routed.go
@@ -81,8 +81,8 @@ func (d *nicRouted) validateEnvironment() error {
 		return fmt.Errorf("Requires liblxc has following API extensions: network_veth_router, network_l2proxy")
 	}
 
-	if d.config["parent"] != "" && !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", d.config["parent"])) {
-		return fmt.Errorf("Parent device '%s' doesn't exist", d.config["parent"])
+	if d.config["parent"] != "" && !network.InterfaceExists(d.config["parent"]) {
+		return fmt.Errorf("Parent device %q doesn't exist", d.config["parent"])
 	}
 
 	if d.config["parent"] == "" && d.config["vlan"] != "" {
@@ -119,7 +119,7 @@ func (d *nicRouted) validateEnvironment() error {
 
 	// If the effective parent doesn't exist and the vlan option is specified, it means we are going to create
 	// the VLAN parent at start, and we will configure the needed sysctls so don't need to check them yet.
-	if d.config["vlan"] != "" && !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", effectiveParentName)) {
+	if d.config["vlan"] != "" && network.InterfaceExists(effectiveParentName) {
 		return nil
 	}
 

From 8069dc8a371b1ce642c457be162b9838249d9f7d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 16 Dec 2020 10:02:06 +0000
Subject: [PATCH 2/2] lxd/device/nic/routed: Remove host side veth interface if
 exists in postStop

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/device/nic_routed.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lxd/device/nic_routed.go b/lxd/device/nic_routed.go
index 0a9ec6cbc0..197972ad9d 100644
--- a/lxd/device/nic_routed.go
+++ b/lxd/device/nic_routed.go
@@ -414,8 +414,18 @@ func (d *nicRouted) postStop() error {
 
 	v := d.volatileGet()
 
+	networkVethFillFromVolatile(d.config, v)
+
 	errs := []error{}
 
+	if network.InterfaceExists(d.config["host_name"]) {
+		// Removing host-side end of veth pair will delete the peer end too.
+		err := network.InterfaceRemove(d.config["host_name"])
+		if err != nil {
+			errs = append(errs, errors.Wrapf(err, "Failed to remove interface %q", d.config["host_name"]))
+		}
+	}
+
 	// This will delete the parent interface if we created it for VLAN parent.
 	if shared.IsTrue(v["last_state.created"]) {
 		parentName := network.GetHostDevice(d.config["parent"], d.config["vlan"])


More information about the lxc-devel mailing list