]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: support new undefine flags in qemu
authorEric Blake <eblake@redhat.com>
Fri, 12 Aug 2011 16:20:24 +0000 (10:20 -0600)
committerEric Blake <eblake@redhat.com>
Sat, 3 Sep 2011 03:57:34 +0000 (21:57 -0600)
A nice benefit of deleting all snapshots at undefine time is that
you don't have to do any reparenting or subtree identification - since
everything goes, this is an O(n) process, whereas using multiple
virDomainSnapshotDelete calls would be O(n^2) or worse.  But it is
only doable for snapshot metadata, where we are in control of the
data being deleted; for the actual snapshots, there's too much
likelihood of something going wrong, and requiring even more API
calls to figure out what failed in the meantime, so callers are
better off deleting the snapshot data themselves one snapshot at
a time where they can deal with failures as they happen.

* src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Honor new flags.

src/qemu/qemu_driver.c

index a4f7c62dc8a1a022b763cdf961b92f89c5bea522..0e022ad4aab91dd6b509a5839c65ec5e0b9694fe 100644 (file)
@@ -5073,7 +5073,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
     int ret = -1;
     int nsnapshots;
 
-    virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE, -1);
+    virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
+                  VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -5088,10 +5089,23 @@ qemuDomainUndefineFlags(virDomainPtr dom,
 
     if (!virDomainObjIsActive(vm) &&
         (nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, 0))) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        _("cannot delete inactive domain with %d snapshots"),
-                        nsnapshots);
-        goto cleanup;
+        struct snap_remove rem;
+
+        if (flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA) {
+            qemuReportError(VIR_ERR_OPERATION_INVALID,
+                            _("cannot delete inactive domain with %d "
+                              "snapshots"),
+                            nsnapshots);
+            goto cleanup;
+        }
+
+        rem.driver = driver;
+        rem.vm = vm;
+        rem.metadata_only = true;
+        rem.err = 0;
+        virHashForEach(vm->snapshots.objs, qemuDomainSnapshotDiscardAll, &rem);
+        if (rem.err < 0)
+            goto cleanup;
     }
 
     if (!vm->persistent) {