render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
6ae9ed
From 3cd00003acb680159d7825c6ff1745319a6f5f1a Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <3cd00003acb680159d7825c6ff1745319a6f5f1a@dist-git>
6ae9ed
From: Jiri Denemark <jdenemar@redhat.com>
6ae9ed
Date: Thu, 8 Sep 2016 15:16:58 +0200
6ae9ed
Subject: [PATCH] Add helper for removing transient definition
6ae9ed
6ae9ed
The code for replacing domain's transient definition with the persistent
6ae9ed
one is repeated in several places and we'll need to add one more. Let's
6ae9ed
make a nice helper for it.
6ae9ed
6ae9ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6ae9ed
(cherry picked from commit 97a87333a0ac8b6b33bf4c45a7b1a526caa554cb)
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1368774
6ae9ed
6ae9ed
Conflicts:
6ae9ed
	src/libxl/libxl_domain.c -- context
6ae9ed
6ae9ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6ae9ed
---
6ae9ed
 src/conf/domain_conf.c   | 19 +++++++++++++++++++
6ae9ed
 src/conf/domain_conf.h   |  1 +
6ae9ed
 src/libvirt_private.syms |  1 +
6ae9ed
 src/libxl/libxl_domain.c |  8 +-------
6ae9ed
 src/lxc/lxc_process.c    |  7 +------
6ae9ed
 src/qemu/qemu_process.c  |  7 +------
6ae9ed
 src/test/test_driver.c   |  9 ++-------
6ae9ed
 src/uml/uml_driver.c     | 14 ++------------
6ae9ed
 8 files changed, 28 insertions(+), 38 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
6ae9ed
index 67c7971..edf5de2 100644
6ae9ed
--- a/src/conf/domain_conf.c
6ae9ed
+++ b/src/conf/domain_conf.c
6ae9ed
@@ -2958,6 +2958,25 @@ virDomainObjSetDefTransient(virCapsPtr caps,
6ae9ed
     return ret;
6ae9ed
 }
6ae9ed
 
6ae9ed
+
6ae9ed
+/*
6ae9ed
+ * Remove the running configuration and replace it with the persistent one.
6ae9ed
+ *
6ae9ed
+ * @param domain domain object pointer
6ae9ed
+ */
6ae9ed
+void
6ae9ed
+virDomainObjRemoveTransientDef(virDomainObjPtr domain)
6ae9ed
+{
6ae9ed
+    if (!domain->newDef)
6ae9ed
+        return;
6ae9ed
+
6ae9ed
+    virDomainDefFree(domain->def);
6ae9ed
+    domain->def = domain->newDef;
6ae9ed
+    domain->def->id = -1;
6ae9ed
+    domain->newDef = NULL;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
 /*
6ae9ed
  * Return the persistent domain configuration. If domain is transient,
6ae9ed
  * return the running config.
6ae9ed
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
6ae9ed
index 61ca8bd..305ae96 100644
6ae9ed
--- a/src/conf/domain_conf.h
6ae9ed
+++ b/src/conf/domain_conf.h
6ae9ed
@@ -2573,6 +2573,7 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
6ae9ed
 int virDomainObjSetDefTransient(virCapsPtr caps,
6ae9ed
                                 virDomainXMLOptionPtr xmlopt,
6ae9ed
                                 virDomainObjPtr domain);
6ae9ed
+void virDomainObjRemoveTransientDef(virDomainObjPtr domain);
6ae9ed
 virDomainDefPtr
6ae9ed
 virDomainObjGetPersistentDef(virCapsPtr caps,
6ae9ed
                              virDomainXMLOptionPtr xmlopt,
6ae9ed
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
6ae9ed
index 7535064..92475a2 100644
6ae9ed
--- a/src/libvirt_private.syms
6ae9ed
+++ b/src/libvirt_private.syms
6ae9ed
@@ -422,6 +422,7 @@ virDomainObjGetShortName;
6ae9ed
 virDomainObjGetState;
6ae9ed
 virDomainObjNew;
6ae9ed
 virDomainObjParseNode;
6ae9ed
+virDomainObjRemoveTransientDef;
6ae9ed
 virDomainObjSetDefTransient;
6ae9ed
 virDomainObjSetMetadata;
6ae9ed
 virDomainObjSetState;
6ae9ed
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
6ae9ed
index 0e26b91..ca37a33 100644
6ae9ed
--- a/src/libxl/libxl_domain.c
6ae9ed
+++ b/src/libxl/libxl_domain.c
6ae9ed
@@ -788,13 +788,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
6ae9ed
         VIR_FREE(file);
6ae9ed
     }
6ae9ed
 
6ae9ed
-    if (vm->newDef) {
6ae9ed
-        virDomainDefFree(vm->def);
6ae9ed
-        vm->def = vm->newDef;
6ae9ed
-        vm->def->id = -1;
6ae9ed
-        vm->newDef = NULL;
6ae9ed
-    }
6ae9ed
-
6ae9ed
+    virDomainObjRemoveTransientDef(vm);
6ae9ed
     virObjectUnref(cfg);
6ae9ed
 }
6ae9ed
 
6ae9ed
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
6ae9ed
index 07eb22a..5d124ff 100644
6ae9ed
--- a/src/lxc/lxc_process.c
6ae9ed
+++ b/src/lxc/lxc_process.c
6ae9ed
@@ -246,12 +246,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
6ae9ed
         VIR_FREE(xml);
6ae9ed
     }
6ae9ed
 
6ae9ed
-    if (vm->newDef) {
6ae9ed
-        virDomainDefFree(vm->def);
6ae9ed
-        vm->def = vm->newDef;
6ae9ed
-        vm->def->id = -1;
6ae9ed
-        vm->newDef = NULL;
6ae9ed
-    }
6ae9ed
+    virDomainObjRemoveTransientDef(vm);
6ae9ed
     virObjectUnref(cfg);
6ae9ed
 }
6ae9ed
 
6ae9ed
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
6ae9ed
index 0777c0c..e13db38 100644
6ae9ed
--- a/src/qemu/qemu_process.c
6ae9ed
+++ b/src/qemu/qemu_process.c
6ae9ed
@@ -5999,12 +5999,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
6ae9ed
         VIR_FREE(xml);
6ae9ed
     }
6ae9ed
 
6ae9ed
-    if (vm->newDef) {
6ae9ed
-        virDomainDefFree(vm->def);
6ae9ed
-        vm->def = vm->newDef;
6ae9ed
-        vm->def->id = -1;
6ae9ed
-        vm->newDef = NULL;
6ae9ed
-    }
6ae9ed
+    virDomainObjRemoveTransientDef(vm);
6ae9ed
 
6ae9ed
  endjob:
6ae9ed
     if (asyncJob != QEMU_ASYNC_JOB_NONE)
6ae9ed
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
6ae9ed
index 36bbd7f..5ec27c3 100644
6ae9ed
--- a/src/test/test_driver.c
6ae9ed
+++ b/src/test/test_driver.c
6ae9ed
@@ -577,14 +577,9 @@ testDomainShutdownState(virDomainPtr domain,
6ae9ed
                         virDomainObjPtr privdom,
6ae9ed
                         virDomainShutoffReason reason)
6ae9ed
 {
6ae9ed
-    if (privdom->newDef) {
6ae9ed
-        virDomainDefFree(privdom->def);
6ae9ed
-        privdom->def = privdom->newDef;
6ae9ed
-        privdom->newDef = NULL;
6ae9ed
-    }
6ae9ed
-
6ae9ed
+    virDomainObjRemoveTransientDef(privdom);
6ae9ed
     virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF, reason);
6ae9ed
-    privdom->def->id = -1;
6ae9ed
+
6ae9ed
     if (domain)
6ae9ed
         domain->id = -1;
6ae9ed
 }
6ae9ed
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
6ae9ed
index b978453..4f25f76 100644
6ae9ed
--- a/src/uml/uml_driver.c
6ae9ed
+++ b/src/uml/uml_driver.c
6ae9ed
@@ -1135,12 +1135,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
6ae9ed
     if (ret < 0) {
6ae9ed
         virDomainConfVMNWFilterTeardown(vm);
6ae9ed
         umlCleanupTapDevices(vm);
6ae9ed
-        if (vm->newDef) {
6ae9ed
-            virDomainDefFree(vm->def);
6ae9ed
-            vm->def = vm->newDef;
6ae9ed
-            vm->def->id = -1;
6ae9ed
-            vm->newDef = NULL;
6ae9ed
-        }
6ae9ed
+        virDomainObjRemoveTransientDef(vm);
6ae9ed
     }
6ae9ed
 
6ae9ed
     /* NB we don't mark it running here - we do that async
6ae9ed
@@ -1182,12 +1177,7 @@ static void umlShutdownVMDaemon(struct uml_driver *driver,
6ae9ed
     /* Stop autodestroy in case guest is restarted */
6ae9ed
     umlProcessAutoDestroyRemove(driver, vm);
6ae9ed
 
6ae9ed
-    if (vm->newDef) {
6ae9ed
-        virDomainDefFree(vm->def);
6ae9ed
-        vm->def = vm->newDef;
6ae9ed
-        vm->def->id = -1;
6ae9ed
-        vm->newDef = NULL;
6ae9ed
-    }
6ae9ed
+    virDomainObjRemoveTransientDef(vm);
6ae9ed
 
6ae9ed
     driver->nactive--;
6ae9ed
     if (!driver->nactive && driver->inhibitCallback)
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed