domain_conf: Add virDomainObjSetDefTransient

This function sets the running domain definition as transient, by reparsing
the persistent config and assigning it to newDef. This ensures that any
changes made to the running definition and not the persistent config are
discarded when the VM is shutdown.
This commit is contained in:
Cole Robinson 2010-11-19 13:34:19 -05:00
parent 3afe5d402b
commit 08a72a7d89
3 changed files with 46 additions and 1 deletions

View File

@ -352,6 +352,9 @@ VIR_ENUM_IMPL(virDomainTimerMode, VIR_DOMAIN_TIMER_MODE_LAST,
virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
#define VIR_DOMAIN_XML_WRITE_FLAGS VIR_DOMAIN_XML_SECURE
#define VIR_DOMAIN_XML_READ_FLAGS VIR_DOMAIN_XML_INACTIVE
int virDomainObjListInit(virDomainObjListPtr doms)
{
doms->objs = virHashCreate(50);
@ -965,6 +968,45 @@ virDomainObjPtr virDomainAssignDef(virCapsPtr caps,
return domain;
}
/*
* Mark the running VM config as transient. Ensures transient hotplug
* operations do not persist past shutdown.
*
* @param caps pointer to capabilities info
* @param domain domain object pointer
* @return 0 on success, -1 on failure
*/
int
virDomainObjSetDefTransient(virCapsPtr caps,
virDomainObjPtr domain)
{
int ret = -1;
char *xml = NULL;
virDomainDefPtr newDef = NULL;
if (!virDomainObjIsActive(domain))
return 0;
if (!domain->persistent)
return 0;
if (domain->newDef)
return 0;
if (!(xml = virDomainDefFormat(domain->def, VIR_DOMAIN_XML_WRITE_FLAGS)))
goto out;
if (!(newDef = virDomainDefParseString(caps, xml,
VIR_DOMAIN_XML_READ_FLAGS)))
goto out;
domain->newDef = newDef;
ret = 0;
out:
VIR_FREE(xml);
return ret;
}
/*
* The caller must hold a lock on the driver owning 'doms',
* and must also have locked 'dom', to ensure no one else
@ -7256,7 +7298,7 @@ int virDomainSaveConfig(const char *configDir,
char *xml;
if (!(xml = virDomainDefFormat(def,
VIR_DOMAIN_XML_SECURE)))
VIR_DOMAIN_XML_WRITE_FLAGS)))
goto cleanup;
if (virDomainSaveXML(configDir, def, xml))

View File

@ -1092,6 +1092,8 @@ virDomainObjPtr virDomainAssignDef(virCapsPtr caps,
void virDomainObjAssignDef(virDomainObjPtr domain,
const virDomainDefPtr def,
bool live);
int virDomainObjSetDefTransient(virCapsPtr caps,
virDomainObjPtr domain);
void virDomainRemoveInactive(virDomainObjListPtr doms,
virDomainObjPtr dom);

View File

@ -225,6 +225,7 @@ virDomainMemballoonModelTypeToString;
virDomainNetDefFree;
virDomainNetTypeToString;
virDomainObjAssignDef;
virDomainObjSetDefTransient;
virDomainObjIsDuplicate;
virDomainObjListDeinit;
virDomainObjListGetActiveIDs;