diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 606ee50d9f5396122b2d07297fcad5ecbc2e6739..1ae48400120d382617dda2fcc2f293a2461cff06 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 7d2d6f5edcfea4c9cef2ad67bc02aea634c21732..392e0520082ce94830adbb0691e9ed5771307703 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 cdd37f70169b9af19a886637825e9b964bbde27e..41d1a194347a631239b729709c3e7f5a3614c90d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -225,6 +225,7 @@ virDomainMemballoonModelTypeToString; virDomainNetDefFree; virDomainNetTypeToString; virDomainObjAssignDef; +virDomainObjSetDefTransient; virDomainObjIsDuplicate; virDomainObjListDeinit; virDomainObjListGetActiveIDs;