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,
+ ¤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, 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;
+
+cleanup:
+ esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
+ return ret;
+}
+
static int
esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
@@ -5021,6 +5090,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/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 39b27b1..fadf804 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10916,6 +10916,87 @@ cleanup:
return xml;
}
+static int
+qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
+ unsigned int flags)
+{
+ struct qemud_driver *driver = snapshot->domain->conn->privateData;
+ virDomainObjPtr vm = NULL;
+ int ret = -1;
+ virDomainSnapshotObjPtr snap = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ virCheckFlags(0, -1);
+
+ qemuDriverLock(driver);
+ virUUIDFormat(snapshot->domain->uuid, uuidstr);
+ vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
+ if (!vm) {
+ qemuReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"),
uuidstr);
+ goto cleanup;
+ }
+
+ snap = virDomainSnapshotFindByName(&vm->snapshots, snapshot->name);
+ if (!snap) {
+ qemuReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
+ _("no domain snapshot with matching name
'%s'"),
+ snapshot->name);
+ goto cleanup;
+ }
+
+ ret = (vm->current_snapshot &&
+ STREQ(snapshot->name, vm->current_snapshot->def->name));
+
+cleanup:
+ if (vm)
+ virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ return ret;
+}
+
+
+static int
+qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
+ unsigned int flags)
+{
+ struct qemud_driver *driver = snapshot->domain->conn->privateData;
+ virDomainObjPtr vm = NULL;
+ int ret = -1;
+ virDomainSnapshotObjPtr snap = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ virCheckFlags(0, -1);
+
+ qemuDriverLock(driver);
+ virUUIDFormat(snapshot->domain->uuid, uuidstr);
+ vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
+ if (!vm) {
+ qemuReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"),
uuidstr);
+ goto cleanup;
+ }
+
+ snap = virDomainSnapshotFindByName(&vm->snapshots, snapshot->name);
+ if (!snap) {
+ qemuReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
+ _("no domain snapshot with matching name
'%s'"),
+ snapshot->name);
+ goto cleanup;
+ }
+
+ /* XXX Someday, we should recognize internal snapshots in qcow2
+ * images that are not tied to a libvirt snapshot; if we ever do
+ * that, then we would have a reason to return 0 here. */
+ ret = 1;
+
+cleanup:
+ if (vm)
+ virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ return ret;
+}
+
/* The domain is expected to be locked and inactive. */
static int
qemuDomainSnapshotRevertInactive(struct qemud_driver *driver,
@@ -13073,6 +13154,8 @@ static virDriver qemuDriver = {
.domainHasCurrentSnapshot = qemuDomainHasCurrentSnapshot, /* 0.8.0 */
.domainSnapshotGetParent = qemuDomainSnapshotGetParent, /* 0.9.7 */
.domainSnapshotCurrent = qemuDomainSnapshotCurrent, /* 0.8.0 */
+ .domainSnapshotIsCurrent = qemuDomainSnapshotIsCurrent, /* 0.9.13 */
+ .domainSnapshotHasMetadata = qemuDomainSnapshotHasMetadata, /* 0.9.13 */
.domainRevertToSnapshot = qemuDomainRevertToSnapshot, /* 0.8.0 */
.domainSnapshotDelete = qemuDomainSnapshotDelete, /* 0.8.0 */
.qemuDomainMonitorCommand = qemuDomainMonitorCommand, /* 0.8.3 */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4b0ee2e..d7ea73b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -6426,6 +6426,101 @@ 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,
+ 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;
+ 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;
+ }
+
+ /* Check that snapshot exists. If so, there is no metadata. */
+ if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
+ goto cleanup;
+
+ ret = 0;
+
+cleanup:
+ VBOX_RELEASE(machine);
+ vboxIIDUnalloc(&iid);
+ return ret;
+}
+
#if VBOX_API_VERSION < 3001
static int
vboxDomainSnapshotRestore(virDomainPtr dom,
@@ -9172,6 +9267,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.7.6