[PATCH v3 5/8] undefine: Implement internal API for libxl driver

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

 



This is just similiar as changes on qemu driver.

* src/libxl/libxl_driver.c: New callback for libxl_driver,
new function libxlDomainUndefineFlags, and changes libxlDomainUndefine
as a wrapper of libxlDomainUndefineFlags.
---
 src/libxl/libxl_driver.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index cc37d05..0bbf113 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2724,13 +2724,17 @@ cleanup:
 }
 
 static int
-libxlDomainUndefine(virDomainPtr dom)
+libxlDomainUndefineFlags(virDomainPtr dom,
+                         unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
     virDomainEventPtr event = NULL;
+    char *name = NULL;
     int ret = -1;
 
+    virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE, -1);
+
     libxlDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
 
@@ -2755,6 +2759,26 @@ libxlDomainUndefine(virDomainPtr dom)
         goto cleanup;
     }
 
+    name = libxlDomainManagedSavePath(driver, vm);
+    if (name == NULL)
+        goto cleanup;
+
+    if (virFileExists(name)) {
+        if (flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE) {
+            if (unlink(name) < 0) {
+                libxlError(VIR_ERR_INTERNAL_ERR, "%s",
+                           _("Failed to remove domain managed save "
+                             "image"));
+                goto cleanup;
+            }
+        } else {
+            libxlError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("Refuse to undefine while managed save "
+                         "image exists"));
+            goto cleanup;
+        }
+    }
+
     if (virDomainDeleteConfig(driver->configDir,
                               driver->autostartDir,
                               vm) < 0)
@@ -2768,6 +2792,7 @@ libxlDomainUndefine(virDomainPtr dom)
     ret = 0;
 
   cleanup:
+    VIR_FREE(name);
     if (vm)
         virDomainObjUnlock(vm);
     if (event)
@@ -2777,6 +2802,12 @@ libxlDomainUndefine(virDomainPtr dom)
 }
 
 static int
+libxlDomainUndefine(virDomainPtr dom)
+{
+    return libxlDomainUndefineFlags(dom, 0);
+}
+
+static int
 libxlDomainChangeEjectableMedia(libxlDomainObjPrivatePtr priv,
                                 virDomainObjPtr vm, virDomainDiskDefPtr disk)
 {
@@ -3836,6 +3867,7 @@ static virDriver libxlDriver = {
     .domainCreateWithFlags = libxlDomainCreateWithFlags, /* 0.9.0 */
     .domainDefineXML = libxlDomainDefineXML, /* 0.9.0 */
     .domainUndefine = libxlDomainUndefine, /* 0.9.0 */
+    .domainUndefineFlags = libxlDomainUndefineFlags, /* 0.9.4 */
     .domainAttachDevice = libxlDomainAttachDevice, /* 0.9.2 */
     .domainAttachDeviceFlags = libxlDomainAttachDeviceFlags, /* 0.9.2 */
     .domainDetachDevice = libxlDomainDetachDevice,    /* 0.9.2 */
-- 
1.7.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]