[libvirt] [PATCH 4/4] snapshot: implement new APIs for qemu, esx, and vbox

Osier Yang jyang at redhat.com
Mon Jun 11 07:14:32 UTC 2012


On 2012年05月25日 11:33, Eric Blake wrote:
> The two APIs are rather trivial; based on bits and pieces of other
> existing APIs.  Rather than blindly return 0 or 1 for HasMetadata,
> I chose to first validate that the snapshot in question in fact
> exists.
>
> * src/qemu/qemu_driver.c (qemuDomainSnapshotIsCurrent)
> (qemuDomainSnapshotHasMetadata): New functions.
> * src/esx/esx_driver.c (esxDomainSnapshotIsCurrent)
> (esxDomainSnapshotHasMetadata): Likewise.
> * src/vbox/vbox_tmpl.c (vboxDomainSnapshotIsCurrent)
> (vboxDomainSnapshotHasMetadata): Likewise.
> ---
>   src/esx/esx_driver.c   |   71 +++++++++++++++++++++++++++++++++++
>   src/qemu/qemu_driver.c |   83 +++++++++++++++++++++++++++++++++++++++++
>   src/vbox/vbox_tmpl.c   |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 251 insertions(+), 0 deletions(-)
>
> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
> index b3f1948..7de86ab 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -4707,6 +4707,75 @@ esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags)
>   }
>
>
> +static int
> +esxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, unsigned int flags)
> +{
> +    esxPrivate *priv = snapshot->domain->conn->privateData;
> +    esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
> +    esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
> +    esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
> +    int ret = -1;
> +
> +    virCheckFlags(0, -1);
> +
> +    if (esxVI_EnsureSession(priv->primary)<  0) {
> +        return -1;
> +    }
> +
> +    /* Check that snapshot exists.  */
> +    if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
> +&rootSnapshotList)<  0 ||
> +        esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
> +&snapshotTree, NULL,
> +                                    esxVI_Occurrence_RequiredItem)<  0) {
> +        goto cleanup;
> +    }
> +
> +    if (esxVI_LookupCurrentSnapshotTree(priv->primary, snapshot->domain->uuid,
> +&currentSnapshotTree,
> +                                        esxVI_Occurrence_RequiredItem)<  0) {
> +        goto cleanup;
> +    }
> +
> +    ret = STREQ(snapshot->name, currentSnapshotTree->name);
> +
> +cleanup:
> +    esxVI_VirtualMachineSnapshotTree_Free(&currentSnapshotTree);
> +    esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
> +    return ret;
> +}
> +
> +
> +static int
> +esxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, unsigned int flags)
> +{
> +    esxPrivate *priv = snapshot->domain->conn->privateData;
> +    esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
> +    esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
> +    int ret = -1;
> +
> +    virCheckFlags(0, -1);
> +
> +    if (esxVI_EnsureSession(priv->primary)<  0) {
> +        return -1;
> +    }
> +
> +    /* Check that snapshot exists.  If so, there is no metadata.  */
> +    if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
> +&rootSnapshotList)<  0 ||
> +        esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
> +&snapshotTree, NULL,
> +                                    esxVI_Occurrence_RequiredItem)<  0) {
> +        goto cleanup;
> +    }
> +
> +    ret = 0;
> +

Looks like it doesn't have metadata anyway for esx and vbox driver,
is it useful then?

Osier




More information about the libvir-list mailing list