From 08a72a7d89d14cae94e676f42b58a107bd5a59ec Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 19 Nov 2010 13:34:19 -0500 Subject: [PATCH] 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. --- src/conf/domain_conf.c | 44 +++++++++++++++++++++++++++++++++++++++- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 606ee50d9f..1ae4840012 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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)) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7d2d6f5edc..392e052008 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -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); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cdd37f7016..41d1a19434 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -225,6 +225,7 @@ virDomainMemballoonModelTypeToString; virDomainNetDefFree; virDomainNetTypeToString; virDomainObjAssignDef; +virDomainObjSetDefTransient; virDomainObjIsDuplicate; virDomainObjListDeinit; virDomainObjListGetActiveIDs; -- GitLab