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