From eb410208cb5f5a4296d7e1d51b1213a257a1b0ea Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Wed, 25 Apr 2018 20:27:23 +0200 Subject: [PATCH] host-device: Ensure device is down before rename If the device is in state up trying to set the name fails with "device or resource busy" --- plugins/main/host-device/host-device.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/main/host-device/host-device.go b/plugins/main/host-device/host-device.go index 0b9e7a81..fea5b980 100644 --- a/plugins/main/host-device/host-device.go +++ b/plugins/main/host-device/host-device.go @@ -143,6 +143,11 @@ func moveLinkOut(containerNs ns.NetNS, ifName string) error { if err != nil { return fmt.Errorf("failed to find %q: %v", ifName, err) } + + // Devices can be renamed only when down + if err := netlink.LinkSetDown(dev); err != nil { + return fmt.Errorf("failed to set %q down: %v", ifName, err) + } // Rename device to it's original name if err := netlink.LinkSetName(dev, dev.Attrs().Alias); err != nil { return fmt.Errorf("failed to restore %q to original name %q: %v", ifName, dev.Attrs().Alias, err)