mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
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.
This commit is contained in:
parent
e3fe4102c1
commit
d4edc089f5
@ -4744,6 +4744,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)
|
||||
@ -5058,6 +5127,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 */
|
||||
};
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user