From b8cf990079d267d9e34fe03acaad515c623155e4 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Thu, 1 Feb 2018 18:56:04 +0800 Subject: [PATCH] qemu: clear persist flag on tap device In the scenario which tap device was not created by qemu but passed in(e.g, with some cni plugin), there was IFF_PERSIST flag set on it, the flag need to be cleared to make sure tap device removed cleanly on qemu exit. (cherry picked from commit c3fbef2bb406e589c11286807ff6243687c8377a) --- hypervisor/qemu/network.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hypervisor/qemu/network.go b/hypervisor/qemu/network.go index dc58f425..5fa37d71 100644 --- a/hypervisor/qemu/network.go +++ b/hypervisor/qemu/network.go @@ -47,6 +47,11 @@ func GetTapFd(device, bridge, options string) (int, error) { tapFile.Close() return -1, fmt.Errorf("create tap device failed\n") } + _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, tapFile.Fd(), uintptr(syscall.TUNSETPERSIST), 0) + if errno != 0 { + tapFile.Close() + return -1, fmt.Errorf("clear tap device persist flag failed\n") + } err = network.UpAndAddToBridge(device, bridge, options) if err != nil {