On Mon, Dec 15, 2008 at 11:22:52AM +0000, Daniel P. Berrange wrote: > On Fri, Dec 12, 2008 at 07:27:08PM +0100, Guido G?nther wrote: > > 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. > > ACK The attached version uses virAsprintf and calles virSaveDomainStatus in more places - this should cover most of it. O.k. to apply? Cheers, -- Guido
>From 89c491a2fc2cbfd6b90b35d5f84a0205f0f0e86b Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx> Date: Fri, 12 Dec 2008 16:28:57 +0100 Subject: [PATCH] save domain status during vm creation and remove it on shutdown. --- src/qemu_driver.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 51 insertions(+), 1 deletions(-) diff --git a/src/qemu_driver.c b/src/qemu_driver.c index d42b4c0..fe4c56a 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 (virAsprintf(&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: * @@ -531,6 +569,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; @@ -1030,6 +1074,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, return -1; } } + qemudSaveDomainStatus(conn, qemu_driver, vm); return ret; } @@ -1095,6 +1140,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED, "%s", _("Got unexpected pid, damn\n")); } } + qemudRemoveDomainStatus(conn, driver, vm); vm->pid = -1; vm->def->id = -1; @@ -1736,6 +1782,7 @@ static int qemudDomainSuspend(virDomainPtr dom) { VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); VIR_FREE(info); } + qemudSaveDomainStatus(dom->conn, driver, vm); ret = 0; cleanup: @@ -1785,6 +1832,7 @@ static int qemudDomainResume(virDomainPtr dom) { VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); VIR_FREE(info); } + qemudSaveDomainStatus(dom->conn, driver, vm); ret = 0; cleanup: @@ -3219,6 +3267,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom, goto error; } + qemudSaveDomainStatus(dom->conn, driver, vm); cleanup: if (vm) virDomainObjUnlock(vm); @@ -3337,6 +3386,7 @@ static int qemudDomainDetachDevice(virDomainPtr dom, qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s", _("only SCSI or virtio disk device can be detached dynamically")); + qemudSaveDomainStatus(dom->conn, driver, vm); cleanup: virDomainDeviceDefFree(dev); if (vm) -- 1.6.0.2
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list