On failures, virBhyveProcessStart() does not cleanup network interfaces that could be created by virBhyveProcessBuildBhyveCmd(), which results in a leaked tap device. To fix that, extract network cleanup code to bhyveNetCleanup() and use it in cleanup stage of virBhyveProcessStart(). --- src/bhyve/bhyve_process.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index b37855e..a557bc5 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -63,6 +63,24 @@ bhyveProcessAutoDestroy(virDomainObjPtr vm, return vm; } +static void +bhyveNetCleanup(virDomainObjPtr vm) +{ + size_t i; + + for (i = 0; i < vm->def->nnets; i++) { + virDomainNetDefPtr net = vm->def->nets[i]; + int actualType = virDomainNetGetActualType(net); + + if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) { + ignore_value(virNetDevBridgeRemovePort( + virDomainNetGetActualBridgeName(net), + net->ifname)); + ignore_value(virNetDevTapDelete(net->ifname)); + } + } +} + int virBhyveProcessStart(virConnectPtr conn, bhyveConnPtr driver, @@ -167,6 +185,8 @@ virBhyveProcessStart(virConnectPtr conn, ignore_value(virCommandRun(destroy_cmd, NULL)); virCommandFree(destroy_cmd); } + + bhyveNetCleanup(vm); } virCommandFree(load_cmd); @@ -181,7 +201,6 @@ virBhyveProcessStop(bhyveConnPtr driver, virDomainObjPtr vm, virDomainShutoffReason reason ATTRIBUTE_UNUSED) { - size_t i; int ret = -1; virCommandPtr cmd = NULL; @@ -203,17 +222,8 @@ virBhyveProcessStop(bhyveConnPtr driver, vm->def->name, (int)vm->pid); - for (i = 0; i < vm->def->nnets; i++) { - virDomainNetDefPtr net = vm->def->nets[i]; - int actualType = virDomainNetGetActualType(net); - - if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) { - ignore_value(virNetDevBridgeRemovePort( - virDomainNetGetActualBridgeName(net), - net->ifname)); - ignore_value(virNetDevTapDelete(net->ifname)); - } - } + /* Cleanup network interfaces */ + bhyveNetCleanup(vm); /* No matter if shutdown was successful or not, we * need to unload the VM */ -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list