[libvirt] [PATCHv3 07/43] snapshot: allow deletion of just snapshot metadata

Daniel P. Berrange berrange at redhat.com
Wed Aug 24 16:28:55 UTC 2011


On Wed, Aug 24, 2011 at 09:22:24AM -0600, Eric Blake wrote:
> 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 |    3 ++-
>  src/esx/esx_driver.c         |   10 +++++++++-
>  src/libvirt.c                |   10 +++++++---
>  src/vbox/vbox_tmpl.c         |   10 +++++++++-
>  4 files changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index a625479..eae0a10 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -2579,7 +2579,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,
> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
> index c097651..beeafbd 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -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,
> diff --git a/src/libvirt.c b/src/libvirt.c
> index a1197e0..a80c140 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -15798,14 +15798,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.
>   */
> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
> index 822e899..8de2bae 100644
> --- a/src/vbox/vbox_tmpl.c
> +++ b/src/vbox/vbox_tmpl.c
> @@ -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",

ACK


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list