Blob Blame History Raw
From 3cd00003acb680159d7825c6ff1745319a6f5f1a Mon Sep 17 00:00:00 2001
Message-Id: <3cd00003acb680159d7825c6ff1745319a6f5f1a@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Thu, 8 Sep 2016 15:16:58 +0200
Subject: [PATCH] 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>
(cherry picked from commit 97a87333a0ac8b6b33bf4c45a7b1a526caa554cb)

https://bugzilla.redhat.com/show_bug.cgi?id=1368774

Conflicts:
	src/libxl/libxl_domain.c -- context

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c   | 19 +++++++++++++++++++
 src/conf/domain_conf.h   |  1 +
 src/libvirt_private.syms |  1 +
 src/libxl/libxl_domain.c |  8 +-------
 src/lxc/lxc_process.c    |  7 +------
 src/qemu/qemu_process.c  |  7 +------
 src/test/test_driver.c   |  9 ++-------
 src/uml/uml_driver.c     | 14 ++------------
 8 files changed, 28 insertions(+), 38 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 67c7971..edf5de2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2958,6 +2958,25 @@ virDomainObjSetDefTransient(virCapsPtr caps,
     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 running config.
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 61ca8bd..305ae96 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2573,6 +2573,7 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
 int virDomainObjSetDefTransient(virCapsPtr caps,
                                 virDomainXMLOptionPtr xmlopt,
                                 virDomainObjPtr domain);
+void virDomainObjRemoveTransientDef(virDomainObjPtr domain);
 virDomainDefPtr
 virDomainObjGetPersistentDef(virCapsPtr caps,
                              virDomainXMLOptionPtr xmlopt,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7535064..92475a2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -422,6 +422,7 @@ virDomainObjGetShortName;
 virDomainObjGetState;
 virDomainObjNew;
 virDomainObjParseNode;
+virDomainObjRemoveTransientDef;
 virDomainObjSetDefTransient;
 virDomainObjSetMetadata;
 virDomainObjSetState;
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 0e26b91..ca37a33 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -788,13 +788,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
         VIR_FREE(file);
     }
 
-    if (vm->newDef) {
-        virDomainDefFree(vm->def);
-        vm->def = vm->newDef;
-        vm->def->id = -1;
-        vm->newDef = NULL;
-    }
-
+    virDomainObjRemoveTransientDef(vm);
     virObjectUnref(cfg);
 }
 
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 07eb22a..5d124ff 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -246,12 +246,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
         VIR_FREE(xml);
     }
 
-    if (vm->newDef) {
-        virDomainDefFree(vm->def);
-        vm->def = vm->newDef;
-        vm->def->id = -1;
-        vm->newDef = NULL;
-    }
+    virDomainObjRemoveTransientDef(vm);
     virObjectUnref(cfg);
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0777c0c..e13db38 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5999,12 +5999,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         VIR_FREE(xml);
     }
 
-    if (vm->newDef) {
-        virDomainDefFree(vm->def);
-        vm->def = vm->newDef;
-        vm->def->id = -1;
-        vm->newDef = NULL;
-    }
+    virDomainObjRemoveTransientDef(vm);
 
  endjob:
     if (asyncJob != QEMU_ASYNC_JOB_NONE)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 36bbd7f..5ec27c3 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -577,14 +577,9 @@ testDomainShutdownState(virDomainPtr domain,
                         virDomainObjPtr privdom,
                         virDomainShutoffReason reason)
 {
-    if (privdom->newDef) {
-        virDomainDefFree(privdom->def);
-        privdom->def = privdom->newDef;
-        privdom->newDef = NULL;
-    }
-
+    virDomainObjRemoveTransientDef(privdom);
     virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF, reason);
-    privdom->def->id = -1;
+
     if (domain)
         domain->id = -1;
 }
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index b978453..4f25f76 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1135,12 +1135,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
     if (ret < 0) {
         virDomainConfVMNWFilterTeardown(vm);
         umlCleanupTapDevices(vm);
-        if (vm->newDef) {
-            virDomainDefFree(vm->def);
-            vm->def = vm->newDef;
-            vm->def->id = -1;
-            vm->newDef = NULL;
-        }
+        virDomainObjRemoveTransientDef(vm);
     }
 
     /* 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 */
     umlProcessAutoDestroyRemove(driver, vm);
 
-    if (vm->newDef) {
-        virDomainDefFree(vm->def);
-        vm->def = vm->newDef;
-        vm->def->id = -1;
-        vm->newDef = NULL;
-    }
+    virDomainObjRemoveTransientDef(vm);
 
     driver->nactive--;
     if (!driver->nactive && driver->inhibitCallback)
-- 
2.10.0