[libvirt] [PATCH 4/5] save domain status during vm creation and remove it on shutdown.

Guido Günther agx at sigxcpu.org
Fri Dec 12 18:27:08 UTC 2008


This patch does the actual saving and removal of the vm status. It does
so only at vm creation time at the moment. We need to update the config
every time the life config changes later.

---
 src/qemu_driver.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 7804094..d8b87e4 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -182,6 +182,44 @@ qemudAutostartConfigs(struct qemud_driver *driver) {
     virConnectClose(conn);
 }
 
+
+/**
+ * qemudRemoveDomainStatus
+ *
+ * remove all state files of a domain from statedir
+ *
+ * Returns 0 on success
+ */
+static int
+qemudRemoveDomainStatus(virConnectPtr conn,
+                        struct qemud_driver *driver,
+                        virDomainObjPtr vm) 
+{
+    int rc = -1;
+    char *file = NULL;
+
+    if (asprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) < 0) {
+        qemudReportError(conn, vm, NULL, VIR_ERR_NO_MEMORY,
+                         "%s", _("failed to allocate space for status file"));
+        goto cleanup;
+    }
+
+    if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR) {
+        qemudReportError(conn, vm, NULL, VIR_ERR_INTERNAL_ERROR,
+                         _("Failed to unlink status file %s"), file);
+        goto cleanup;
+    }
+
+    if(virFileDeletePid(driver->stateDir, vm->def->name))
+        goto cleanup;
+
+    rc = 0;
+cleanup:
+    VIR_FREE(file);
+    return rc;
+}
+
+
 /**
  * qemudStartup:
  *
@@ -532,6 +570,12 @@ static int qemudOpenMonitor(virConnectPtr conn,
                                  qemudCheckMonitorPrompt,
                                  "monitor", 10000);
 
+    if (!(vm->monitorpath = strdup(monitor))) {
+        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
+                         "%s", _("failed to allocate space for monitor path"));
+        goto error;
+    }
+
     /* Keep monitor open upon success */
     if (ret == 0)
         return ret;
@@ -1046,6 +1090,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
             return -1;
         }
     }
+    qemudSaveDomainStatus(conn, qemu_driver, vm);
 
     return ret;
 }
@@ -1108,6 +1153,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     /* shut it off for sure */
     kill(vm->pid, SIGKILL);
+    qemudRemoveDomainStatus(conn, driver, vm);
 
     vm->pid = -1;
     vm->def->id = -1;
-- 
1.6.0.2




More information about the libvir-list mailing list