]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: allow deletion of just snapshot metadata
authorEric Blake <eblake@redhat.com>
Fri, 12 Aug 2011 03:12:05 +0000 (21:12 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 2 Sep 2011 22:51:33 +0000 (16:51 -0600)
A future patch will make it impossible to remove a domain if it
would leave behind any libvirt-tracked metadata about snapshots,
since stale metadata interferes with a new domain by the same name.
But requiring snaphot contents to be deleted before removing a
domain is harsh; with qemu, qemu-img can still make use of the
contents after the libvirt domain is gone.  Therefore, we need
an option to get rid of libvirt tracking information, but not
the actual contents.  For hypervisors that do not track any
metadata in libvirt, the implementation is trivial; all remaining
hypervisors (really, just qemu) will be dealt with separately.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY): New flag.
* src/libvirt.c (virDomainSnapshotDelete): Document it.
* src/esx/esx_driver.c (esxDomainSnapshotDelete): Trivially
supported when there is no libvirt metadata.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotDelete): Likewise.

include/libvirt/libvirt.h.in
src/esx/esx_driver.c
src/libvirt.c
src/vbox/vbox_tmpl.c

index aa64fa59481ac8ce433a8f8a255440a09e924a1d..765488413fe23cbef6df94464f75380afb77405c 100644 (file)
@@ -2596,7 +2596,8 @@ int virDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 
 /* Delete a snapshot */
 typedef enum {
-    VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN = (1 << 0),
+    VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN      = (1 << 0), /* Also delete children */
+    VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY = (1 << 1), /* Delete just metadata */
 } virDomainSnapshotDeleteFlags;
 
 int virDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
index e6033994e534b5849fcba6d126d5b7a67b53ec70..846a777b96ce390cf7da34871b451b8ca8e3b0cf 100644 (file)
@@ -4543,7 +4543,8 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
     esxVI_TaskInfoState taskInfoState;
     char *taskInfoErrorMessage = NULL;
 
-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+                  VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1);
 
     if (esxVI_EnsureSession(priv->primary) < 0) {
         return -1;
@@ -4561,6 +4562,13 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
         goto cleanup;
     }
 
+    /* ESX snapshots do not require any libvirt metadata, making this
+     * flag trivial once we know we have a valid snapshot.  */
+    if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY) {
+        result = 0;
+        goto cleanup;
+    }
+
     if (esxVI_RemoveSnapshot_Task(priv->primary, snapshotTree->snapshot,
                                   removeChildren, &task) < 0 ||
         esxVI_WaitForTaskCompletion(priv->primary, task, snapshot->domain->uuid,
index 8e569ab8bd3dccb39c8b8f68c355e57002e7c492..0f3399c822c5b24a0fad2fbd6b3bce47d43621f9 100644 (file)
@@ -15962,14 +15962,18 @@ error:
 /**
  * virDomainSnapshotDelete:
  * @snapshot: a domain snapshot object
- * @flags: flag parameters
+ * @flags: bitwise-or of supported virDomainSnapshotDeleteFlags
  *
  * Delete the snapshot.
  *
  * If @flags is 0, then just this snapshot is deleted, and changes from
  * this snapshot are automatically merged into children snapshots.  If
- * flags is VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, then this snapshot
- * and any children snapshots are deleted.
+ * @flags includes VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, then this snapshot
+ * and any children snapshots are deleted.  If @flags includes
+ * VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, then any snapshot metadata
+ * tracked by libvirt is removed while keeping the snapshot contents
+ * intact; if a hypervisor does not require any libvirt metadata to
+ * track snapshots, then this flag is silently ignored.
  *
  * Returns 0 if the snapshot was successfully deleted, -1 on error.
  */
index 822e8992b313b9fdfefe3dd2619b81ef1269d1a4..8de2bae8ce9f1c0d991363e1168617e69249a24b 100644 (file)
@@ -6361,7 +6361,8 @@ vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
     PRUint32 state;
     nsresult rc;
 
-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+                  VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1);
 
     vboxIIDFromUUID(&domiid, dom->uuid);
     rc = VBOX_OBJECT_GET_MACHINE(domiid.value, &machine);
@@ -6382,6 +6383,13 @@ vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
         goto cleanup;
     }
 
+    /* VBOX snapshots do not require any libvirt metadata, making this
+     * flag trivial once we know we have a valid snapshot.  */
+    if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY) {
+        ret = 0;
+        goto cleanup;
+    }
+
     if (state >= MachineState_FirstOnline
         && state <= MachineState_LastOnline) {
         vboxError(VIR_ERR_OPERATION_INVALID, "%s",