[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/6] 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.

Signed-off-by: Cole Robinson <crobinso redhat com>
---
 src/conf/domain_conf.c   |   44 +++++++++++++++++++++++++++++++++++++++++++-
 src/conf/domain_conf.h   |    2 ++
 src/libvirt_private.syms |    1 +
 3 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 30c27db..11a6280 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);
@@ -966,6 +969,45 @@ virDomainObjPtr virDomainAssignDef(virCapsPtr caps,
 }
 
 /*
+ * 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
  * is either waiting for 'dom' or still usingn it
@@ -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 7d2d6f5..392e052 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 50eceba..0b62cf1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -224,6 +224,7 @@ virDomainMemballoonModelTypeToString;
 virDomainNetDefFree;
 virDomainNetTypeToString;
 virDomainObjAssignDef;
+virDomainObjSetDefTransient;
 virDomainObjIsDuplicate;
 virDomainObjListDeinit;
 virDomainObjListGetActiveIDs;
-- 
1.7.3.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]