Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: always cold unplug network devices
Browse files Browse the repository at this point in the history
We don't really need to unplug it from guest because we have
already stopped it. Just detach it and clean it up.

Fixes: #1968
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
  • Loading branch information
bergwolf committed Aug 15, 2019
1 parent d26ff71 commit d90eba8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,22 +1480,16 @@ func (n *Network) PostAdd(ctx context.Context, ns *NetworkNamespace, hotplug boo

// Remove network endpoints in the network namespace. It also deletes the network
// namespace in case the namespace has been created by us.
func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor hypervisor, hotunplug bool) error {
func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor hypervisor) error {
span, _ := n.trace(ctx, "remove")
defer span.Finish()

for _, endpoint := range ns.Endpoints {
// Detach for an endpoint should enter the network namespace
// if required.
networkLogger().WithField("endpoint-type", endpoint.Type()).WithField("hotunplug", hotunplug).Info("Detaching endpoint")
if hotunplug {
if err := endpoint.HotDetach(hypervisor, ns.NetNsCreated, ns.NetNsPath); err != nil {
return err
}
} else {
if err := endpoint.Detach(ns.NetNsCreated, ns.NetNsPath); err != nil {
return err
}
networkLogger().WithField("endpoint-type", endpoint.Type()).Info("Detaching endpoint")
if err := endpoint.Detach(ns.NetNsCreated, ns.NetNsPath); err != nil {
return err
}
}

Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (s *Sandbox) removeNetwork() error {
}
}

return s.network.Remove(s.ctx, &s.networkNS, s.hypervisor, s.factory != nil)
return s.network.Remove(s.ctx, &s.networkNS, s.hypervisor)
}

func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) {
Expand Down

0 comments on commit d90eba8

Please sign in to comment.