[lxc-devel] [lxd/master] container/lxc: Fixes scenario where invalid device config cannot be fixed
tomponline on Github
lxc-bot at linuxcontainers.org
Wed Aug 14 21:56:03 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 438 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190814/9af46f68/attachment.bin>
-------------- next part --------------
From 47c6d4e1300e1a78d4c4fdb21f617d3497b94a39 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 14 Aug 2019 22:54:53 +0100
Subject: [PATCH] container/lxc: Fixes scenario where invalid device config
cannot be fixed
Allows devices to be stopped and removed even if their config is invalid.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/container_lxc.go | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 25e6789648..73213848d8 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -3392,7 +3392,9 @@ func (c *containerLXC) cleanupDevices(netns string) {
if err == device.ErrUnsupportedDevType {
continue
} else if err != nil {
- logger.Errorf("Failed to stop device: %v", err)
+ // If device fails to stop, just log error and move onto next device.
+ logger.Errorf("Failed to stop device %s: %v", k, err)
+ continue
}
}
}
@@ -3994,7 +3996,9 @@ func (c *containerLXC) Delete() error {
for k, m := range c.expandedDevices {
err = c.deviceRemove(k, m)
if err != nil && err != device.ErrUnsupportedDevType {
- return err
+ // If deviceRemove fails, just log error and move on to next device.
+ logger.Errorf("Failed to remove device", log.Ctx{"name": c.Name(), "device": k, "err": err})
+ continue
}
}
}
@@ -5437,13 +5441,17 @@ func (c *containerLXC) updateDevices(removeDevices map[string]config.Device, add
if err == device.ErrUnsupportedDevType {
continue // No point in trying to remove device below.
} else if err != nil {
- return err
+ // If deviceStop fails, just log error and proceed to try and
+ // remove device cleanly below.
+ logger.Errorf("Failed to stop device %s: %v", k, err)
}
}
err := c.deviceRemove(k, m)
if err != nil && err != device.ErrUnsupportedDevType {
- return err
+ // If deviceRemove fails, just log error and move on to next device.
+ logger.Errorf("Failed to remove device %s: %v", k, err)
+ continue
}
}
More information about the lxc-devel
mailing list