The two new APIs are rather trivial; based on bits and pieces of other existing APIs. I chose to blindly return 0 for HasMetadata, since we already do that for other APIs like domainIsPersistent. * src/esx/esx_driver.c (esxDomainSnapshotIsCurrent) (esxDomainSnapshotHasMetadata): New functions. * src/vbox/vbox_tmpl.c (vboxDomainSnapshotIsCurrent) (vboxDomainSnapshotHasMetadata): Likewise. --- This version avoids existence checks. I don't like it, but it is shorter, so it's worth posting. src/esx/esx_driver.c | 50 ++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index b3f1948..65569c8 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -4707,6 +4707,54 @@ 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, + ¤tSnapshotTree, + esxVI_Occurrence_RequiredItem) < 0) { + goto cleanup; + } + + ret = STREQ(snapshot->name, currentSnapshotTree->name); + +cleanup: + esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree); + esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList); + return ret; +} + + +static int +esxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot ATTRIBUTE_UNUSED, + unsigned int flags) +{ + /* Libvirt does not maintain snapshot metadata. */ + virCheckFlags(0, -1); + return 0; +} + static int esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) @@ -5021,6 +5069,8 @@ static virDriver esxDriver = { .domainSnapshotGetParent = esxDomainSnapshotGetParent, /* 0.9.7 */ .domainSnapshotCurrent = esxDomainSnapshotCurrent, /* 0.8.0 */ .domainRevertToSnapshot = esxDomainRevertToSnapshot, /* 0.8.0 */ + .domainSnapshotIsCurrent = esxDomainSnapshotIsCurrent, /* 0.9.13 */ + .domainSnapshotHasMetadata = esxDomainSnapshotHasMetadata, /* 0.9.13 */ .domainSnapshotDelete = esxDomainSnapshotDelete, /* 0.8.0 */ .isAlive = esxIsAlive, /* 0.9.8 */ }; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 4b0ee2e..c613d7c 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -6426,6 +6426,77 @@ cleanup: return ret; } +static int +vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, + unsigned int flags) +{ + virDomainPtr dom = snapshot->domain; + VBOX_OBJECT_CHECK(dom->conn, int, -1); + vboxIID iid = VBOX_IID_INITIALIZER; + IMachine *machine = NULL; + ISnapshot *snap = NULL; + ISnapshot *current = NULL; + PRUnichar *nameUtf16 = NULL; + char *name = NULL; + nsresult rc; + + virCheckFlags(0, -1); + + vboxIIDFromUUID(&iid, dom->uuid); + rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine); + if (NS_FAILED(rc)) { + vboxError(VIR_ERR_NO_DOMAIN, "%s", + _("no domain with matching UUID")); + goto cleanup; + } + + if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + goto cleanup; + + rc = machine->vtbl->GetCurrentSnapshot(machine, ¤t); + if (NS_FAILED(rc)) { + vboxError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not get current snapshot")); + goto cleanup; + } + if (!current) { + ret = 0; + goto cleanup; + } + + rc = current->vtbl->GetName(current, &nameUtf16); + if (NS_FAILED(rc) || !nameUtf16) { + vboxError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not get current snapshot name")); + goto cleanup; + } + + VBOX_UTF16_TO_UTF8(nameUtf16, &name); + if (!name) { + virReportOOMError(); + goto cleanup; + } + + ret = STREQ(snapshot->name, name); + +cleanup: + VBOX_UTF8_FREE(name); + VBOX_UTF16_FREE(nameUtf16); + VBOX_RELEASE(current); + VBOX_RELEASE(machine); + vboxIIDUnalloc(&iid); + return ret; +} + +static int +vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot ATTRIBUTE_UNUSED, + unsigned int flags) +{ + /* Libvirt does not maintain snapshot metadata. */ + virCheckFlags(0, -1); + return 0; +} + #if VBOX_API_VERSION < 3001 static int vboxDomainSnapshotRestore(virDomainPtr dom, @@ -9172,6 +9243,8 @@ virDriver NAME(Driver) = { .domainHasCurrentSnapshot = vboxDomainHasCurrentSnapshot, /* 0.8.0 */ .domainSnapshotGetParent = vboxDomainSnapshotGetParent, /* 0.9.7 */ .domainSnapshotCurrent = vboxDomainSnapshotCurrent, /* 0.8.0 */ + .domainSnapshotIsCurrent = vboxDomainSnapshotIsCurrent, /* 0.9.13 */ + .domainSnapshotHasMetadata = vboxDomainSnapshotHasMetadata, /* 0.9.13 */ .domainRevertToSnapshot = vboxDomainRevertToSnapshot, /* 0.8.0 */ .domainSnapshotDelete = vboxDomainSnapshotDelete, /* 0.8.0 */ .isAlive = vboxIsAlive, /* 0.9.8 */ -- 1.7.10.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list