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

[libvirt] [PATCH v3 4/8] undefine: Implement internal API for qemu driver



* src/qemu/qemu_driver.c: New call back for qemu_driver,
New function qemudDomainUndefineFlags, and changes on
qemudDomainUndefine.
---
 src/qemu/qemu_driver.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8d54e58..0310b45 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4311,12 +4311,18 @@ cleanup:
     return dom;
 }
 
-static int qemudDomainUndefine(virDomainPtr dom) {
+static int
+qemuDomainUndefineFlags(virDomainPtr dom,
+                         unsigned int flags)
+{
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     virDomainEventPtr event = NULL;
+    char *name = NULL;
     int ret = -1;
 
+    virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_STATE, -1);
+
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
 
@@ -4340,6 +4346,26 @@ static int qemudDomainUndefine(virDomainPtr dom) {
         goto cleanup;
     }
 
+    name = qemuDomainManagedSavePath(driver, vm);
+    if (name == NULL)
+        goto cleanup;
+
+    if (virFileExists(name)) {
+        if (flags & VIR_DOMAIN_UNDEFINE_MANAGED_STATE) {
+            if (unlink(name) < 0) {
+                qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                _("Failed to remove domain managed "
+                                  "save image"));
+                goto cleanup;
+            }
+        } else {
+            qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                            _("Refusing to undefine while managed save "
+                              "image exists"));
+            goto cleanup;
+        }
+    }
+
     if (virDomainDeleteConfig(driver->configDir, driver->autostartDir, vm) < 0)
         goto cleanup;
 
@@ -4354,6 +4380,7 @@ static int qemudDomainUndefine(virDomainPtr dom) {
     ret = 0;
 
 cleanup:
+    VIR_FREE(name);
     if (vm)
         virDomainObjUnlock(vm);
     if (event)
@@ -4363,6 +4390,12 @@ cleanup:
 }
 
 static int
+qemudDomainUndefine(virDomainPtr dom)
+{
+    return qemuDomainUndefineFlags(dom, 0);
+}
+
+static int
 qemuDomainAttachDeviceDiskLive(struct qemud_driver *driver,
                                virDomainObjPtr vm,
                                virDomainDeviceDefPtr dev)
@@ -8550,6 +8583,7 @@ static virDriver qemuDriver = {
     .domainCreateWithFlags = qemudDomainStartWithFlags, /* 0.8.2 */
     .domainDefineXML = qemudDomainDefine, /* 0.2.0 */
     .domainUndefine = qemudDomainUndefine, /* 0.2.0 */
+    .domainUndefineFlags = qemuDomainUndefineFlags, /* 0.9.4 */
     .domainAttachDevice = qemuDomainAttachDevice, /* 0.4.1 */
     .domainAttachDeviceFlags = qemuDomainAttachDeviceFlags, /* 0.7.7 */
     .domainDetachDevice = qemuDomainDetachDevice, /* 0.5.0 */
-- 
1.7.6


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