提交 e87af617 编写于 作者: P Peter Krempa

net: Remove dnsmasq and radvd files also when destroying transient nets

The network driver didn't care about config files when a network was
destroyed, just when it was undefined leaving behind files for transient
networks.

This patch splits out the cleanup code to a helper function that handles
the cleanup if the inactive network object is being removed and re-uses
this code when getting rid of inactive networks.
上级 23ae3fe4
...@@ -155,6 +155,57 @@ networkRadvdConfigFileName(const char *netname) ...@@ -155,6 +155,57 @@ networkRadvdConfigFileName(const char *netname)
return configfile; return configfile;
} }
/* do needed cleanup steps and remove the network from the list */
static int
networkRemoveInactive(struct network_driver *driver,
virNetworkObjPtr net)
{
char *leasefile = NULL;
char *radvdconfigfile = NULL;
char *radvdpidbase = NULL;
dnsmasqContext *dctx = NULL;
virNetworkDefPtr def = virNetworkObjGetPersistentDef(net);
int ret = -1;
/* remove the (possibly) existing dnsmasq and radvd files */
if (!(dctx = dnsmasqContextNew(def->name, DNSMASQ_STATE_DIR)))
goto cleanup;
if (!(leasefile = networkDnsmasqLeaseFileName(def->name)))
goto cleanup;
if (!(radvdconfigfile = networkRadvdConfigFileName(def->name)))
goto no_memory;
if (!(radvdpidbase = networkRadvdPidfileBasename(def->name)))
goto no_memory;
/* dnsmasq */
dnsmasqDelete(dctx);
unlink(leasefile);
/* radvd */
unlink(radvdconfigfile);
virPidFileDelete(NETWORK_PID_DIR, radvdpidbase);
/* remove the network definition */
virNetworkRemoveInactive(&driver->networks, net);
ret = 0;
cleanup:
VIR_FREE(leasefile);
VIR_FREE(radvdconfigfile);
VIR_FREE(radvdpidbase);
dnsmasqContextFree(dctx);
return ret;
no_memory:
virReportOOMError();
goto cleanup;
}
static char * static char *
networkBridgeDummyNicName(const char *brname) networkBridgeDummyNicName(const char *brname)
{ {
...@@ -2824,12 +2875,11 @@ cleanup: ...@@ -2824,12 +2875,11 @@ cleanup:
return ret; return ret;
} }
static int networkUndefine(virNetworkPtr net) { static int
networkUndefine(virNetworkPtr net) {
struct network_driver *driver = net->conn->networkPrivateData; struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network; virNetworkObjPtr network;
virNetworkIpDefPtr ipdef; int ret = -1;
bool dhcp_present = false, v6present = false;
int ret = -1, ii;
networkDriverLock(driver); networkDriverLock(driver);
...@@ -2851,58 +2901,12 @@ static int networkUndefine(virNetworkPtr net) { ...@@ -2851,58 +2901,12 @@ static int networkUndefine(virNetworkPtr net) {
network) < 0) network) < 0)
goto cleanup; goto cleanup;
/* we only support dhcp on one IPv4 address per defined network */ VIR_INFO("Undefining network '%s'", network->def->name);
for (ii = 0; if (networkRemoveInactive(driver, network) < 0) {
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii)); network = NULL;
ii++) {
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
if (ipdef->nranges || ipdef->nhosts)
dhcp_present = true;
} else if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6)) {
v6present = true;
}
}
if (dhcp_present) {
char *leasefile;
dnsmasqContext *dctx = dnsmasqContextNew(network->def->name, DNSMASQ_STATE_DIR);
if (dctx == NULL)
goto cleanup;
dnsmasqDelete(dctx);
dnsmasqContextFree(dctx);
leasefile = networkDnsmasqLeaseFileName(network->def->name);
if (!leasefile)
goto cleanup;
unlink(leasefile);
VIR_FREE(leasefile);
}
if (v6present) {
char *configfile = networkRadvdConfigFileName(network->def->name);
if (!configfile) {
virReportOOMError();
goto cleanup;
}
unlink(configfile);
VIR_FREE(configfile);
char *radvdpidbase = networkRadvdPidfileBasename(network->def->name);
if (!(radvdpidbase)) {
virReportOOMError();
goto cleanup; goto cleanup;
} }
virPidFileDelete(NETWORK_PID_DIR, radvdpidbase);
VIR_FREE(radvdpidbase);
}
VIR_INFO("Undefining network '%s'", network->def->name);
virNetworkRemoveInactive(&driver->networks,
network);
network = NULL; network = NULL;
ret = 0; ret = 0;
...@@ -3103,10 +3107,15 @@ static int networkDestroy(virNetworkPtr net) { ...@@ -3103,10 +3107,15 @@ static int networkDestroy(virNetworkPtr net) {
goto cleanup; goto cleanup;
} }
ret = networkShutdownNetwork(driver, network); if ((ret = networkShutdownNetwork(driver, network)) < 0)
goto cleanup;
if (!network->persistent) { if (!network->persistent) {
virNetworkRemoveInactive(&driver->networks, if (networkRemoveInactive(driver, network) < 0) {
network); network = NULL;
ret = -1;
goto cleanup;
}
network = NULL; network = NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册