mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-27 16:15:23 +00:00
network: free/null newDef if network fails to start
https://bugzilla.redhat.com/show_bug.cgi?id=866364 pointed out a crash due to virNetworkObjAssignDef free'ing network->newDef without NULLing it afterward. A fix for this is in upstream commitb7e9202401
. While the NULLing of newDef was a legitimate fix, newDef should have already been empty (NULL) anyway (as indicated in the comment that was deleted by that commit). The reason that newDef had a non-NULL value (i.e. the root cause) was that networkStartNetwork() had failed after populating network->newDef, but then neglected to free/NULL newDef in the cleanup. (A bit of background here: network->newDef should contain the persistent config of a network when a network is active (and of course only when it is persisten), and NULL at all other times. There is also a network->def which should contain the persistent definition of the network when it is inactive, and the current live state at all other times. The idea is that you can make changes to network->newDef which will take effect the next time the network is restarted, but won't mess with the current state of the network (virDomainObj has a similar pair of virDomainDefs that behave in the same fashion). Personally I think there should be a network->live and network->config, and the location of the persistent config should *always* be in network->config, but that's for a later cleanup). Since I love things to be symmetric, I created a new function called virNetworkObjUnsetDefTransient(), which reverses the effects of virNetworkObjSetDefTransient(). I don't really like the name of the new function, but then I also didn't really like the name of the old one either (it's just named that way to match a similar function in the domain conf code). (cherry picked from commit78fab2770b
)
This commit is contained in:
parent
11b13b3619
commit
f1de8d3beb
@ -352,6 +352,20 @@ virNetworkObjSetDefTransient(virNetworkObjPtr network, bool live)
|
||||
return network->newDef ? 0 : -1;
|
||||
}
|
||||
|
||||
/* virNetworkObjUnsetDefTransient:
|
||||
*
|
||||
* This *undoes* what virNetworkObjSetDefTransient did.
|
||||
*/
|
||||
void
|
||||
virNetworkObjUnsetDefTransient(virNetworkObjPtr network)
|
||||
{
|
||||
if (network->def) {
|
||||
virNetworkDefFree(network->def);
|
||||
network->def = network->newDef;
|
||||
network->newDef = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* virNetworkObjGetPersistentDef:
|
||||
* @network: network object pointer
|
||||
|
@ -253,6 +253,7 @@ int virNetworkObjAssignDef(virNetworkObjPtr network,
|
||||
const virNetworkDefPtr def,
|
||||
bool live);
|
||||
int virNetworkObjSetDefTransient(virNetworkObjPtr network, bool live);
|
||||
void virNetworkObjUnsetDefTransient(virNetworkObjPtr network);
|
||||
virNetworkDefPtr virNetworkObjGetPersistentDef(virNetworkObjPtr network);
|
||||
int virNetworkObjReplacePersistentDef(virNetworkObjPtr network,
|
||||
virNetworkDefPtr def);
|
||||
|
@ -864,6 +864,7 @@ virNetworkObjLock;
|
||||
virNetworkObjReplacePersistentDef;
|
||||
virNetworkObjSetDefTransient;
|
||||
virNetworkObjUnlock;
|
||||
virNetworkObjUnsetDefTransient;
|
||||
virNetworkObjUpdate;
|
||||
virNetworkRemoveInactive;
|
||||
virNetworkSaveConfig;
|
||||
|
@ -2327,8 +2327,10 @@ networkStartNetwork(struct network_driver *driver,
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
virNetworkObjUnsetDefTransient(network);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Persist the live configuration now that anything autogenerated
|
||||
* is setup.
|
||||
@ -2388,13 +2390,7 @@ static int networkShutdownNetwork(struct network_driver *driver,
|
||||
}
|
||||
|
||||
network->active = 0;
|
||||
|
||||
if (network->newDef) {
|
||||
virNetworkDefFree(network->def);
|
||||
network->def = network->newDef;
|
||||
network->newDef = NULL;
|
||||
}
|
||||
|
||||
virNetworkObjUnsetDefTransient(network);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user