]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: require existence before returning success
authorEric Blake <eblake@redhat.com>
Fri, 25 May 2012 02:28:54 +0000 (20:28 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 20 Jun 2012 16:27:57 +0000 (10:27 -0600)
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.

src/esx/esx_driver.c
src/vbox/vbox_tmpl.c

index b3f19481c3163dc216e7ad26af949d95151d9e98..fd830d8345c32978cb711e9279b4a4683c97376e 100644 (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;
 }
 
 
index 4b0ee2efce99eb5698b029f95367d9437d4e3d2e..1a190e5cabb36dad6ed4b5d6ba9dd9557b99f3a4 100644 (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) {