]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add helper for removing transient definition
authorJiri Denemark <jdenemar@redhat.com>
Thu, 8 Sep 2016 13:16:58 +0000 (15:16 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 8 Sep 2016 20:25:22 +0000 (22:25 +0200)
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>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/libxl/libxl_domain.c
src/lxc/lxc_process.c
src/qemu/qemu_process.c
src/test/test_driver.c
src/uml/uml_driver.c

index c8c4f61cda69dbae2338324a6d5ae95a04050784..db030cc001ef2b17e3a6e3fa749e955334788428 100644 (file)
@@ -2981,6 +2981,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.
index 0fe4154553bd2e9518f9916166dbbe61073b2bf8..79dda1c321fc5d094e093d8b541fb0dfe5490ee5 100644 (file)
@@ -2577,6 +2577,7 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
 int virDomainObjSetDefTransient(virCapsPtr caps,
                                 virDomainXMLOptionPtr xmlopt,
                                 virDomainObjPtr domain);
+void virDomainObjRemoveTransientDef(virDomainObjPtr domain);
 virDomainDefPtr
 virDomainObjGetPersistentDef(virCapsPtr caps,
                              virDomainXMLOptionPtr xmlopt,
index a5fa30562f0c4c82d7e7f89bd4a51fa3455f9ad3..6a77e469f1402b2659813a4c34637ebf75bf60c1 100644 (file)
@@ -421,6 +421,7 @@ virDomainObjGetShortName;
 virDomainObjGetState;
 virDomainObjNew;
 virDomainObjParseNode;
+virDomainObjRemoveTransientDef;
 virDomainObjSetDefTransient;
 virDomainObjSetMetadata;
 virDomainObjSetState;
index a85dd75946e52a3e748d7bf00db80d7954de833f..43f4a7f32b97a696f81a061415db91f96eb1918a 100644 (file)
@@ -811,13 +811,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr 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);
 }
 
index 7703fe18fea7e8cd67cdb2570fe0e9ee81f513ab..bce6a2f70ea892cbe859ee25d08ce9ec647dbcb7 100644 (file)
@@ -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);
 }
 
index e6e91dffd8788f3edc1dfed4f7ee8accc7255d88..75965798e45b5b5944c4a35b620b33a388753706 100644 (file)
@@ -6039,12 +6039,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)
index 53cfa3cf78c05856bf1ff2e22be7c77313c006e8..8dd757987488e076de6a2029445092c4be88a2c2 100644 (file)
@@ -588,14 +588,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;
 }
index b9784538d82d097cb57d0463ba73f5d079a60808..4f25f76c4e4b252bef362eeb531dc027dd178b52 100644 (file)
@@ -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)