diff options
author | Eric Blake <eblake@redhat.com> | 2012-05-24 20:28:54 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2012-06-20 11:18:48 -0600 |
commit | d4edc089f582dc060762242d08c48f9bddb1ba9d (patch) | |
tree | 5bff71c262c2579f7f0d719b6fce0d7b3cf35929 /src/vbox | |
parent | snapshot: require existence before returning success (diff) | |
download | libvirt-d4edc089f582dc060762242d08c48f9bddb1ba9d.tar.gz libvirt-d4edc089f582dc060762242d08c48f9bddb1ba9d.tar.bz2 libvirt-d4edc089f582dc060762242d08c48f9bddb1ba9d.zip |
snapshot: implement new APIs for esx and vbox
The two new APIs are rather trivial; based on bits and pieces of
other existing APIs. But rather than blindly return 0 or 1 for
HasMetadata, I chose to first validate that the snapshot in
question in fact exists.
* src/esx/esx_driver.c (esxDomainSnapshotIsCurrent)
(esxDomainSnapshotHasMetadata): New functions.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotIsCurrent)
(vboxDomainSnapshotHasMetadata): Likewise.
Diffstat (limited to 'src/vbox')
-rw-r--r-- | src/vbox/vbox_tmpl.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 1a190e5ca..f082b153f 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -6466,6 +6466,103 @@ 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(snap); + 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(snap); + VBOX_RELEASE(machine); + vboxIIDUnalloc(&iid); + return ret; +} + #if VBOX_API_VERSION < 3001 static int vboxDomainSnapshotRestore(virDomainPtr dom, @@ -9212,6 +9309,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 */ |