From 8f1e38f9a182a5baa0ef275976c5d35360b384a4 Mon Sep 17 00:00:00 2001
Message-Id: <8f1e38f9a182a5baa0ef275976c5d35360b384a4.1351266167.git.hahn@univention.de>
In-Reply-To: <1314937528-8318-25-git-send-email-eblake@redhat.com>
References: <1314937528-8318-25-git-send-email-eblake@redhat.com>
From: Philipp Hahn <hahn@univention.de>
Date: Fri, 26 Oct 2012 16:43:10 +0200
Subject: [PATCH] Prevent undefine of QEMU domains with snapshots
Organization: Univention GmbH, Bremen, Germany
To: libvir-list@redhat.com

Commit 282fe1f08c89189e36142fc2d12bae0175038bdd added a test to prevent
un-defining domains with snapshots, which causes problems with QEMU when
a new domain re-uses the name of those domains.
The check is currently only performed for running domains, while still
leaving behind the data for inactive domains.

Remove the check for running domains and always refuse to undefine
a domain with snapshots unless forced by
VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA.

Signed-off-by: Philipp Hahn <hahn@univention.de>
---
 src/libvirt.c          |    6 +++---
 src/qemu/qemu_driver.c |    3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 7e79470..2a5cfe6 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8039,11 +8039,11 @@ error:
  * then including VIR_DOMAIN_UNDEFINE_MANAGED_SAVE in @flags will also remove
  * that file, and omitting the flag will cause the undefine process to fail.
  *
- * If the domain is inactive and has any snapshot metadata (see
+ * If the domain has any snapshot metadata (see
  * virDomainSnapshotNum()), then including
  * VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA in @flags will also remove
- * that metadata.  Omitting the flag will cause the undefine of an
- * inactive domain to fail.  Active snapshots will retain snapshot
+ * that metadata.  Omitting the flag will cause the undefine of the
+ * domain to fail.  Active snapshots will retain snapshot
  * metadata until the (now-transient) domain halts, regardless of
  * whether this flag is present.  On hypervisors where snapshots do
  * not use libvirt metadata, this flag has no effect.
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 18be7d9..a09376e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5736,8 +5736,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (!virDomainObjIsActive(vm) &&
-        (nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0))) {
+    if ((nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0))) {
         if (!(flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)) {
             virReportError(VIR_ERR_OPERATION_INVALID,
                            _("cannot delete inactive domain with %d "
-- 
1.7.1

