Move network device cleanup code from libxlDomainCleanup to a helper
function for use in a subsequent patch.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/libxl/libxl_domain.c | 49 +++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index e906495b64..f957c29d0d 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -826,6 +826,33 @@ libxlDomainSaveImageOpen(libxlDriverPrivate *driver,
return -1;
}
+static void
+libxlNetworkUnwindDevices(virDomainDef *def)
+{
+ if (def->nnets) {
+ size_t i;
+
+ for (i = 0; i < def->nnets; i++) {
+ virDomainNetDef *net = def->nets[i];
+
+ if (net->ifname &&
+ STRPREFIX(net->ifname, LIBXL_GENERATED_PREFIX_XEN))
+ VIR_FREE(net->ifname);
+
+ /* cleanup actual device */
+ virDomainNetRemoveHostdev(def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+ g_autoptr(virConnect) conn = virGetConnectNetwork();
+
+ if (conn)
+ virDomainNetReleaseActualDevice(conn, def, net);
+ else
+ VIR_WARN("Unable to release network device '%s'",
NULLSTR(net->ifname));
+ }
+ }
+ }
+}
+
/*
* Internal domain destroy function.
*
@@ -923,29 +950,9 @@ libxlDomainCleanup(libxlDriverPrivate *driver,
}
}
- if ((vm->def->nnets)) {
- size_t i;
-
- for (i = 0; i < vm->def->nnets; i++) {
- virDomainNetDef *net = vm->def->nets[i];
-
- if (net->ifname &&
- STRPREFIX(net->ifname, LIBXL_GENERATED_PREFIX_XEN))
- VIR_FREE(net->ifname);
-
- /* cleanup actual device */
- virDomainNetRemoveHostdev(vm->def, net);
- if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
- if (conn || (conn = virGetConnectNetwork()))
- virDomainNetReleaseActualDevice(conn, vm->def, net);
- else
- VIR_WARN("Unable to release network device '%s'",
NULLSTR(net->ifname));
- }
- }
- }
+ libxlNetworkUnwindDevices(vm->def);
file = g_strdup_printf("%s/%s.xml", cfg->stateDir,
vm->def->name);
-
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
VIR_FREE(file);
--
2.31.1