mirror of https://gitee.com/openkylin/libvirt.git
network: eliminate lag in updating dnsmasq hosts files
This addresses https://bugzilla.redhat.com/show_bug.cgi?id=713728 When "defining" a new network (or one that exists but isn't currently active) the new definition is stored in network->def, but for a network that already exists and is active, the new definition is stored in network->newDef, and then moved over to network->def as soon as the network is destroyed. However, the code that writes the dhcp and dns hosts files used by dnsmasq was always using network->def for its information, even when the new data was actually in network->newDef, so the hosts files always lagged one edit behind the definition. This patch changes the code to keep the pointer to the new definition after it's been assigned into the network, and use it directly (regardless of whether it's stored in network->newDef or network->def) to construct the hosts files.
This commit is contained in:
parent
2c4d7b5fa4
commit
3aa84653d1
src/network
|
@ -2338,6 +2338,7 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
||||||
struct network_driver *driver = conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
virNetworkIpDefPtr ipdef, ipv4def = NULL;
|
virNetworkIpDefPtr ipdef, ipv4def = NULL;
|
||||||
virNetworkDefPtr def;
|
virNetworkDefPtr def;
|
||||||
|
bool freeDef = true;
|
||||||
virNetworkObjPtr network = NULL;
|
virNetworkObjPtr network = NULL;
|
||||||
virNetworkPtr ret = NULL;
|
virNetworkPtr ret = NULL;
|
||||||
int ii;
|
int ii;
|
||||||
|
@ -2367,21 +2368,19 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
||||||
if (!(network = virNetworkAssignDef(&driver->networks,
|
if (!(network = virNetworkAssignDef(&driver->networks,
|
||||||
def)))
|
def)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
def = NULL;
|
freeDef = false;
|
||||||
|
|
||||||
network->persistent = 1;
|
network->persistent = 1;
|
||||||
|
|
||||||
if (virNetworkSaveConfig(driver->networkConfigDir,
|
if (virNetworkSaveConfig(driver->networkConfigDir, def) < 0) {
|
||||||
network->newDef ? network->newDef : network->def) < 0) {
|
virNetworkRemoveInactive(&driver->networks, network);
|
||||||
virNetworkRemoveInactive(&driver->networks,
|
|
||||||
network);
|
|
||||||
network = NULL;
|
network = NULL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We only support dhcp on one IPv4 address per defined network */
|
/* We only support dhcp on one IPv4 address per defined network */
|
||||||
for (ii = 0;
|
for (ii = 0;
|
||||||
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii));
|
(ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, ii));
|
||||||
ii++) {
|
ii++) {
|
||||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET)) {
|
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET)) {
|
||||||
if (ipdef->nranges || ipdef->nhosts) {
|
if (ipdef->nranges || ipdef->nhosts) {
|
||||||
|
@ -2396,18 +2395,19 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ipv4def) {
|
if (ipv4def) {
|
||||||
dctx = dnsmasqContextNew(network->def->name, DNSMASQ_STATE_DIR);
|
dctx = dnsmasqContextNew(def->name, DNSMASQ_STATE_DIR);
|
||||||
if (dctx == NULL ||
|
if (dctx == NULL ||
|
||||||
networkBuildDnsmasqHostsfile(dctx, ipv4def, network->def->dns) < 0 ||
|
networkBuildDnsmasqHostsfile(dctx, ipv4def, def->dns) < 0 ||
|
||||||
dnsmasqSave(dctx) < 0)
|
dnsmasqSave(dctx) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_INFO("Defining network '%s'", network->def->name);
|
VIR_INFO("Defining network '%s'", def->name);
|
||||||
ret = virGetNetwork(conn, network->def->name, network->def->uuid);
|
ret = virGetNetwork(conn, def->name, def->uuid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetworkDefFree(def);
|
if (freeDef)
|
||||||
|
virNetworkDefFree(def);
|
||||||
dnsmasqContextFree(dctx);
|
dnsmasqContextFree(dctx);
|
||||||
if (network)
|
if (network)
|
||||||
virNetworkObjUnlock(network);
|
virNetworkObjUnlock(network);
|
||||||
|
|
Loading…
Reference in New Issue