]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
snapshot: qemu: Fix detection of external snapshots when deleting
authorPeter Krempa <pkrempa@redhat.com>
Fri, 19 Oct 2012 09:55:36 +0000 (11:55 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 13 Nov 2012 19:36:26 +0000 (20:36 +0100)
This patch adds a helper to determine if snapshots are external and uses
the helper to fix detection of those in snapshot deletion code.

Snapshots are external if they have an external memory image or if the
disk locations are external. As mixed snapshots are forbidden for now
we need to check just one disk to know.

src/conf/snapshot_conf.c
src/conf/snapshot_conf.h
src/libvirt_private.syms
src/qemu/qemu_driver.c

index 691950af7b99205f49800c4cb41631841fde0440..aa2b5268b47ab8ff3d4f776565f08e5671398648 100644 (file)
@@ -1023,3 +1023,20 @@ cleanup:
     }
     return ret;
 }
+
+
+bool
+virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap)
+{
+    int i;
+
+    if (snap->def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
+        return true;
+
+    for (i = 0; i < snap->def->ndisks; i++) {
+        if (snap->def->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
+            return true;
+    }
+
+    return false;
+}
index 00775ae71a7bc92aa434411284690956588bedd6..b5c6e259151b4b1edf6d48792aaf1b7ca8af2beb 100644 (file)
@@ -155,6 +155,8 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
                            virDomainSnapshotPtr **snaps,
                            unsigned int flags);
 
+bool virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap);
+
 VIR_ENUM_DECL(virDomainSnapshotLocation)
 VIR_ENUM_DECL(virDomainSnapshotState)
 
index e94b47802a2fbdc7ac0053c14320b6c8ca71be38..5a0713981d9d9b882f095e8c6eeafe806215ed36 100644 (file)
@@ -1083,6 +1083,7 @@ virDomainSnapshotFindByName;
 virDomainSnapshotForEach;
 virDomainSnapshotForEachChild;
 virDomainSnapshotForEachDescendant;
+virDomainSnapshotIsExternal;
 virDomainSnapshotLocationTypeFromString;
 virDomainSnapshotLocationTypeToString;
 virDomainSnapshotObjListGetNames;
index 5556f1e5953fa25697eee325065888c27e0bc3ec..01d8cb3cb5f05de174b84031c5e7d0c8fb98bacc 100644 (file)
@@ -2025,7 +2025,7 @@ cleanup:
 }
 
 
-/* Count how many snapshots in a set have external disk snapshots.  */
+/* Count how many snapshots in a set are external snapshots or checkpoints.  */
 static void
 qemuDomainSnapshotCountExternal(void *payload,
                                 const void *name ATTRIBUTE_UNUSED,
@@ -2034,7 +2034,7 @@ qemuDomainSnapshotCountExternal(void *payload,
     virDomainSnapshotObjPtr snap = payload;
     int *count = data;
 
-    if (snap->def->state == VIR_DOMAIN_DISK_SNAPSHOT)
+    if (virDomainSnapshotIsExternal(snap))
         (*count)++;
 }
 
@@ -12512,7 +12512,7 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
 
     if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)) {
         if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) &&
-            snap->def->state == VIR_DOMAIN_DISK_SNAPSHOT)
+            virDomainSnapshotIsExternal(snap))
             external++;
         if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)
             virDomainSnapshotForEachDescendant(snap,