diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index ebc8061a2e..82251184cb 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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 diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 55502fb2fc..4c0c8c1fbf 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -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); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index be24d88f79..850b92dedd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -864,6 +864,7 @@ virNetworkObjLock; virNetworkObjReplacePersistentDef; virNetworkObjSetDefTransient; virNetworkObjUnlock; +virNetworkObjUnsetDefTransient; virNetworkObjUpdate; virNetworkRemoveInactive; virNetworkSaveConfig; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index e1846ee6d3..4b37a58041 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -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; }