Add helper for removing transient definition

The code for replacing domain's transient definition with the persistent
one is repeated in several places and we'll need to add one more. Let's
make a nice helper for it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2016-09-08 15:16:58 +02:00
parent 10aec4b046
commit 97a87333a0
8 changed files with 28 additions and 38 deletions

View File

@ -2981,6 +2981,25 @@ virDomainObjSetDefTransient(virCapsPtr caps,
return ret; return ret;
} }
/*
* Remove the running configuration and replace it with the persistent one.
*
* @param domain domain object pointer
*/
void
virDomainObjRemoveTransientDef(virDomainObjPtr domain)
{
if (!domain->newDef)
return;
virDomainDefFree(domain->def);
domain->def = domain->newDef;
domain->def->id = -1;
domain->newDef = NULL;
}
/* /*
* Return the persistent domain configuration. If domain is transient, * Return the persistent domain configuration. If domain is transient,
* return the running config. * return the running config.

View File

@ -2577,6 +2577,7 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
int virDomainObjSetDefTransient(virCapsPtr caps, int virDomainObjSetDefTransient(virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
virDomainObjPtr domain); virDomainObjPtr domain);
void virDomainObjRemoveTransientDef(virDomainObjPtr domain);
virDomainDefPtr virDomainDefPtr
virDomainObjGetPersistentDef(virCapsPtr caps, virDomainObjGetPersistentDef(virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,

View File

@ -421,6 +421,7 @@ virDomainObjGetShortName;
virDomainObjGetState; virDomainObjGetState;
virDomainObjNew; virDomainObjNew;
virDomainObjParseNode; virDomainObjParseNode;
virDomainObjRemoveTransientDef;
virDomainObjSetDefTransient; virDomainObjSetDefTransient;
virDomainObjSetMetadata; virDomainObjSetMetadata;
virDomainObjSetState; virDomainObjSetState;

View File

@ -811,13 +811,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
VIR_FREE(xml); VIR_FREE(xml);
} }
if (vm->newDef) { virDomainObjRemoveTransientDef(vm);
virDomainDefFree(vm->def);
vm->def = vm->newDef;
vm->def->id = -1;
vm->newDef = NULL;
}
virObjectUnref(cfg); virObjectUnref(cfg);
} }

View File

@ -246,12 +246,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
VIR_FREE(xml); VIR_FREE(xml);
} }
if (vm->newDef) { virDomainObjRemoveTransientDef(vm);
virDomainDefFree(vm->def);
vm->def = vm->newDef;
vm->def->id = -1;
vm->newDef = NULL;
}
virObjectUnref(cfg); virObjectUnref(cfg);
} }

View File

@ -6039,12 +6039,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
VIR_FREE(xml); VIR_FREE(xml);
} }
if (vm->newDef) { virDomainObjRemoveTransientDef(vm);
virDomainDefFree(vm->def);
vm->def = vm->newDef;
vm->def->id = -1;
vm->newDef = NULL;
}
endjob: endjob:
if (asyncJob != QEMU_ASYNC_JOB_NONE) if (asyncJob != QEMU_ASYNC_JOB_NONE)

View File

@ -588,14 +588,9 @@ testDomainShutdownState(virDomainPtr domain,
virDomainObjPtr privdom, virDomainObjPtr privdom,
virDomainShutoffReason reason) virDomainShutoffReason reason)
{ {
if (privdom->newDef) { virDomainObjRemoveTransientDef(privdom);
virDomainDefFree(privdom->def);
privdom->def = privdom->newDef;
privdom->newDef = NULL;
}
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF, reason); virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF, reason);
privdom->def->id = -1;
if (domain) if (domain)
domain->id = -1; domain->id = -1;
} }

View File

@ -1135,12 +1135,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
if (ret < 0) { if (ret < 0) {
virDomainConfVMNWFilterTeardown(vm); virDomainConfVMNWFilterTeardown(vm);
umlCleanupTapDevices(vm); umlCleanupTapDevices(vm);
if (vm->newDef) { virDomainObjRemoveTransientDef(vm);
virDomainDefFree(vm->def);
vm->def = vm->newDef;
vm->def->id = -1;
vm->newDef = NULL;
}
} }
/* NB we don't mark it running here - we do that async /* NB we don't mark it running here - we do that async
@ -1182,12 +1177,7 @@ static void umlShutdownVMDaemon(struct uml_driver *driver,
/* Stop autodestroy in case guest is restarted */ /* Stop autodestroy in case guest is restarted */
umlProcessAutoDestroyRemove(driver, vm); umlProcessAutoDestroyRemove(driver, vm);
if (vm->newDef) { virDomainObjRemoveTransientDef(vm);
virDomainDefFree(vm->def);
vm->def = vm->newDef;
vm->def->id = -1;
vm->newDef = NULL;
}
driver->nactive--; driver->nactive--;
if (!driver->nactive && driver->inhibitCallback) if (!driver->nactive && driver->inhibitCallback)