mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
conf: Write network config to disk after generating UUID
While we generally expect libvirt objects to be defined using the appropriate APIs, there are cases where it's reasonable for an external entity, usually a package manager, to drop a valid configuration file under /etc/libvirt and have libvirt take over from there: notably, this is exactly how the default network is handled. For the most part, whether the configuration is saved back to disk after being parsed by libvirt doesn't matter, because we'll end up with the same values anyway, but an obvious exception to this is data that gets randomly generated when not present, namely MAC address and UUID. Historically, both were handled by our build system, but commit a47ae7c004e9 moved handling of the former inside libvirt proper; this commit extends such behavior to the latter as well. Proper error handling for the virNetworkSaveConfig() call, which was missing until now, is introduced in the process. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
b67c526725
commit
f69e5ea9f7
@ -1001,6 +1001,7 @@ virNetworkLoadConfig(virNetworkObjListPtr nets,
|
||||
char *configFile = NULL, *autostartLink = NULL;
|
||||
virNetworkDefPtr def = NULL;
|
||||
virNetworkObjPtr obj;
|
||||
bool saveConfig = false;
|
||||
int autostart;
|
||||
|
||||
if ((configFile = virNetworkConfigFile(configDir, name)) == NULL)
|
||||
@ -1029,7 +1030,10 @@ virNetworkLoadConfig(virNetworkObjListPtr nets,
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
if (!def->mac_specified) {
|
||||
virNetworkSetBridgeMacAddr(def);
|
||||
virNetworkSaveConfig(configDir, def, xmlopt);
|
||||
/* We just generated a new MAC address, and we need to persist
|
||||
* the configuration to disk to avoid the network getting a
|
||||
* different one the next time the daemon is started */
|
||||
saveConfig = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1049,6 +1053,17 @@ virNetworkLoadConfig(virNetworkObjListPtr nets,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* The network didn't have a UUID so we generated a new one, and
|
||||
* we need to persist the configuration to disk to avoid the network
|
||||
* getting a different one the next time the daemon is started */
|
||||
if (!def->uuid_specified)
|
||||
saveConfig = true;
|
||||
|
||||
if (saveConfig &&
|
||||
virNetworkSaveConfig(configDir, def, xmlopt) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(obj = virNetworkObjAssignDef(nets, def, 0)))
|
||||
goto error;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user