snapshot: require existence before returning success

Blindly returning success is misleading if the object no longer
exists; it is a bit better to check for existence up front before
returning information about that object.  This pattern matches the
fact that most of our other APIs check for existence as a side
effect prior to getting at the real piece of information being
queried.

* src/esx/esx_driver.c (esxDomainIsUpdated, esxDomainIsPersistent):
Add existence checks.
* src/vbox/vbox_tmpl.c (vboxDomainIsPersistent)
(vboxDomainIsUpdated): Likewise.
This commit is contained in:
Eric Blake 2012-05-24 20:28:54 -06:00
parent 33dc8cf018
commit e3fe4102c1
2 changed files with 85 additions and 8 deletions

View File

@ -4243,10 +4243,28 @@ esxDomainIsActive(virDomainPtr domain)
static int
esxDomainIsPersistent(virDomainPtr domain ATTRIBUTE_UNUSED)
esxDomainIsPersistent(virDomainPtr domain)
{
/* ESX has no concept of transient domains, so all of them are persistent */
return 1;
/* ESX has no concept of transient domains, so all of them are
* persistent. However, we do want to check for existence. */
int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
NULL, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0)
goto cleanup;
result = 1;
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
return result;
}
@ -4254,7 +4272,26 @@ esxDomainIsPersistent(virDomainPtr domain ATTRIBUTE_UNUSED)
static int
esxDomainIsUpdated(virDomainPtr domain ATTRIBUTE_UNUSED)
{
return 0;
/* ESX domains never have a persistent state that differs from
* current state. However, we do want to check for existence. */
int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
NULL, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0)
goto cleanup;
result = 0;
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
return result;
}

View File

@ -1490,14 +1490,54 @@ static int vboxDomainIsActive(virDomainPtr dom) {
}
static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED) {
/* All domains are persistent. */
return 1;
static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED)
{
/* All domains are persistent. However, we do want to check for
* existence. */
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxIID iid = VBOX_IID_INITIALIZER;
IMachine *machine = NULL;
nsresult rc;
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;
}
ret = 1;
cleanup:
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
return ret;
}
static int vboxDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED) {
return 0;
/* VBox domains never have a persistent state that differs from
* current state. However, we do want to check for existence. */
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxIID iid = VBOX_IID_INITIALIZER;
IMachine *machine = NULL;
nsresult rc;
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;
}
ret = 0;
cleanup:
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
return ret;
}
static int vboxDomainSuspend(virDomainPtr dom) {