Skip to content

Commit

Permalink
Make sure ethernet interface is DOWN before renaming and changing MAC
Browse files Browse the repository at this point in the history
This is a continuation to fix 6ffa07f

On some devices, we were still encountering the error "Device or resource
busy". It turned out we had overlooked a few cases where NIM attempted
to change the MAC address while the interface was in the UP state.

Signed-off-by: Milan Lenco <[email protected]>
  • Loading branch information
milan-zededa committed Oct 7, 2024
1 parent bf64171 commit 8b23344
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/pillar/dpcreconciler/linuxitems/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ func (c *AdapterConfigurator) Create(ctx context.Context, item depgraph.Item) er
c.Log.Error(err)
return err
}
// Make sure the ethernet interface is DOWN before renaming
// and changing the MAC address, otherwise we get error
// `Device or resource busy`.
if err := netlink.LinkSetDown(link); err != nil {
err = fmt.Errorf("netlink.LinkSetDown(%s) failed: %v",
adapter.IfName, err)
c.Log.Error(err)
return err
}
// Get MAC address and create the alternate with the group bit toggled.
macAddr := link.Attrs().HardwareAddr
altMacAddr := c.alternativeMAC(link.Attrs().HardwareAddr)
Expand Down Expand Up @@ -304,6 +313,15 @@ func (c *AdapterConfigurator) Delete(ctx context.Context, item depgraph.Item) er
c.Log.Error(err)
return err
}
// Make sure the ethernet interface is DOWN before renaming
// and changing the MAC address, otherwise we get error
// `Device or resource busy`.
if err := netlink.LinkSetDown(kernLink); err != nil {
err = fmt.Errorf("netlink.LinkSetDown(%s) failed: %v",
kernIfname, err)
c.Log.Error(err)
return err
}
// Toggle MAC address of the interface back to the original.
altMacAddr := c.alternativeMAC(kernLink.Attrs().HardwareAddr)
if len(altMacAddr) != 0 {
Expand Down

0 comments on commit 8b23344

Please sign in to comment.