From be0d60f5fa88267afb26125681a217ef9476e133 Mon Sep 17 00:00:00 2001 From: holyfei Date: Sat, 19 Sep 2020 12:47:14 +0800 Subject: [PATCH] runtime: fix del-iface doesn't delete the tap interface in the host problem reason: kata-runtime add-iface support add exist tap device in the host or new created tap device by kata-network add-iface process. If add interface is exist tap device, del-iface will not delete the tap device, so we need to judge the deleted interface is exist device or new created, which is judged by the VMFds of the tap Link and del-iface will load this info from the network.json in 1.7.0 version. However, 1.11.1 version don't write the VMFds into the persiste.json file, del-iface can not figure out which tap is exist already or new created, so cause the this problem. --- virtcontainers/endpoint.go | 2 ++ virtcontainers/persist/api/network.go | 5 +++++ virtcontainers/tap_endpoint.go | 1 + 3 files changed, 8 insertions(+) diff --git a/virtcontainers/endpoint.go b/virtcontainers/endpoint.go index 7efcf49c..3618792e 100644 --- a/virtcontainers/endpoint.go +++ b/virtcontainers/endpoint.go @@ -129,6 +129,7 @@ func saveTapIf(tapif *TapInterface) *persistapi.TapInterface { HardAddr: tapif.TAPIface.HardAddr, Addrs: tapif.TAPIface.Addrs, }, + VMFds: tapif.VMFds, } } @@ -167,6 +168,7 @@ func loadTapIf(tapif *persistapi.TapInterface) *TapInterface { HardAddr: tapif.TAPIface.HardAddr, Addrs: tapif.TAPIface.Addrs, }, + VMFds: tapif.VMFds, } } diff --git a/virtcontainers/persist/api/network.go b/virtcontainers/persist/api/network.go index 53c6de44..c5611767 100644 --- a/virtcontainers/persist/api/network.go +++ b/virtcontainers/persist/api/network.go @@ -7,6 +7,8 @@ package persistapi import ( + "os" + "github.com/vishvananda/netlink" ) @@ -45,6 +47,9 @@ type TapInterface struct { Name string TAPIface NetworkInterface // remove VMFds and VhostFds + // add VMFds back to judge a tap interface is exist before add-iface + // or new created by kata-network add-iface + VMFds []*os.File } // TuntapInterface defines a tap interface diff --git a/virtcontainers/tap_endpoint.go b/virtcontainers/tap_endpoint.go index 5a3e7f7e..0b6002aa 100644 --- a/virtcontainers/tap_endpoint.go +++ b/virtcontainers/tap_endpoint.go @@ -199,6 +199,7 @@ func unTapNetwork(endpoint *TapEndpoint) error { return nil } + networkLogger().Debug("untap the new created tap interface") name := endpoint.TapInterface.TAPIface.Name netHandle, err := netlink.NewHandle() if err != nil { -- 2.11.0