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

[libvirt] [RFC PATCH 2/4] qemu: support VIR_DOMAIN_START_PERSISTENT



Adds support to the qemu driver for the VIR_DOMAIN_START_PERSISTENT flag

---

Figured this would be better to "define" the domain before starting it,
rather than starting and then defining but I can change as people prefer.

---
 src/qemu/qemu_driver.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 76b2800..0a3bbc2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1448,14 +1448,17 @@ static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml,
     virDomainDefPtr def = NULL;
     virDomainObjPtr vm = NULL;
     virDomainPtr dom = NULL;
-    virDomainEventPtr event = NULL;
-    virDomainEventPtr event2 = NULL;
+    virDomainEventPtr event_define = NULL;
+    virDomainEventPtr event_start = NULL;
+    virDomainEventPtr event_pause = NULL;
     unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD;
     virQEMUCapsPtr qemuCaps = NULL;
     virCapsPtr caps = NULL;
+    virQEMUDriverConfigPtr cfg = NULL;
 
     virCheckFlags(VIR_DOMAIN_START_PAUSED |
-                  VIR_DOMAIN_START_AUTODESTROY, NULL);
+                  VIR_DOMAIN_START_AUTODESTROY |
+                  VIR_DOMAIN_START_PERSISTENT, NULL);
 
     if (flags & VIR_DOMAIN_START_PAUSED)
         start_flags |= VIR_QEMU_PROCESS_START_PAUSED;
@@ -1491,6 +1494,24 @@ static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml,
 
     def = NULL;
 
+    /* Attempt to make the domain persistent before we start it */
+    if (flags & VIR_DOMAIN_START_PERSISTENT) {
+        vm->persistent = 1;
+
+        cfg = virQEMUDriverGetConfig(driver);
+
+        if (virDomainSaveConfig(cfg->configDir, vm->newDef) < 0) {
+            VIR_INFO("Deleting domain '%s'", vm->def->name);
+            qemuDomainRemoveInactive(driver, vm);
+            vm = NULL;
+            goto cleanup;
+        }
+
+        event_define = virDomainEventNewFromObj(vm,
+                                                VIR_DOMAIN_EVENT_DEFINED,
+                                                VIR_DOMAIN_EVENT_DEFINED_ADDED);
+    }
+
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
         goto cleanup; /* XXXX free the 'vm' we created ? */
 
@@ -1504,21 +1525,22 @@ static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml,
         goto cleanup;
     }
 
-    event = virDomainEventNewFromObj(vm,
+    event_start = virDomainEventNewFromObj(vm,
                                      VIR_DOMAIN_EVENT_STARTED,
                                      VIR_DOMAIN_EVENT_STARTED_BOOTED);
-    if (event && (flags & VIR_DOMAIN_START_PAUSED)) {
+    if (event_start && (flags & VIR_DOMAIN_START_PAUSED)) {
         /* There are two classes of event-watching clients - those
          * that only care about on/off (and must see a started event
          * no matter what, but don't care about suspend events), and
          * those that also care about running/paused.  To satisfy both
          * client types, we have to send two events.  */
-        event2 = virDomainEventNewFromObj(vm,
+        event_pause = virDomainEventNewFromObj(vm,
                                           VIR_DOMAIN_EVENT_SUSPENDED,
                                           VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
     }
     virDomainAuditStart(vm, "booted", true);
 
+    VIR_INFO("Creating domain '%s'", vm->def->name);
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
     if (dom) dom->id = vm->def->id;
 
@@ -1530,13 +1552,16 @@ cleanup:
     virDomainDefFree(def);
     if (vm)
         virObjectUnlock(vm);
-    if (event) {
-        qemuDomainEventQueue(driver, event);
-        if (event2)
-            qemuDomainEventQueue(driver, event2);
+    if (event_define)
+        qemuDomainEventQueue(driver, event_define);
+    if (event_start) {
+        qemuDomainEventQueue(driver, event_start);
+        if (event_pause)
+            qemuDomainEventQueue(driver, event_pause);
     }
     virObjectUnref(caps);
     virObjectUnref(qemuCaps);
+    virObjectUnref(cfg);
     return dom;
 }
 
-- 
1.7.12.4


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