[PATCH] #7: Change the virDomainLookup* calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This changes the three virDomainLookup* calls to make direct calls to
the underlying drivers, and to return VIR_ERR_NO_DOMAIN error if the
domain is not found.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903

diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-domain-lookup-1/src/xen_unified.c libvirt-domain-lookup-2/src/xen_unified.c
--- libvirt-domain-lookup-1/src/xen_unified.c	2007-07-03 11:21:59.000000000 +0100
+++ libvirt-domain-lookup-2/src/xen_unified.c	2007-07-03 14:51:21.000000000 +0100
@@ -367,19 +355,37 @@
     return NULL;
 }
 
+/* Assumption made in underlying drivers:
+ * If the domain is "not found" and there is no other error, then
+ * the Lookup* functions return a NULL but do not set virterror.
+ */
 static virDomainPtr
 xenUnifiedDomainLookupByID (virConnectPtr conn, int id)
 {
     GET_PRIVATE(conn);
-    int i;
     virDomainPtr ret;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->domainLookupByID) {
-            ret = drivers[i]->domainLookupByID (conn, id);
-            if (ret) return ret;
-        }
+    /* Reset any connection-level errors in virterror first, in case
+     * there is one hanging around from a previous call.
+     */
+    virConnResetLastError (conn);
+
+    /* Try proxy. */
+    if (priv->opened[XEN_UNIFIED_PROXY_OFFSET]) {
+        ret = xenProxyLookupByID (conn, id);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
 
+    /* Try xend. */
+    if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) {
+        ret = xenDaemonLookupByID (conn, id);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
+
+    /* Not found. */
+    xenUnifiedError (conn, VIR_ERR_NO_DOMAIN, __FUNCTION__);
     return NULL;
 }
 
@@ -388,15 +394,36 @@
                               const unsigned char *uuid)
 {
     GET_PRIVATE(conn);
-    int i;
     virDomainPtr ret;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->domainLookupByUUID) {
-            ret = drivers[i]->domainLookupByUUID (conn, uuid);
-            if (ret) return ret;
-        }
+    /* Reset any connection-level errors in virterror first, in case
+     * there is one hanging around from a previous call.
+     */
+    virConnResetLastError (conn);
+
+    /* Try proxy. */
+    if (priv->opened[XEN_UNIFIED_PROXY_OFFSET]) {
+        ret = xenProxyLookupByUUID (conn, uuid);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
+
+    /* Try xend. */
+    if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) {
+        ret = xenDaemonLookupByUUID (conn, uuid);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
 
+    /* Try XM for inactive domains. */
+    if (priv->opened[XEN_UNIFIED_XM_OFFSET]) {
+        ret = xenXMDomainLookupByUUID (conn, uuid);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
+
+    /* Not found. */
+    xenUnifiedError (conn, VIR_ERR_NO_DOMAIN, __FUNCTION__);
     return NULL;
 }
 
@@ -405,15 +432,43 @@
                               const char *name)
 {
     GET_PRIVATE(conn);
-    int i;
     virDomainPtr ret;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->domainLookupByName) {
-            ret = drivers[i]->domainLookupByName (conn, name);
-            if (ret) return ret;
-        }
+    /* Reset any connection-level errors in virterror first, in case
+     * there is one hanging around from a previous call.
+     */
+    virConnResetLastError (conn);
+
+    /* Try proxy. */
+    if (priv->opened[XEN_UNIFIED_PROXY_OFFSET]) {
+        ret = xenProxyLookupByName (conn, name);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
+
+    /* Try xend. */
+    if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) {
+        ret = xenDaemonLookupByName (conn, name);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
+
+    /* Try xenstore for inactive domains. */
+    if (priv->opened[XEN_UNIFIED_XS_OFFSET]) {
+        ret = xenStoreLookupByName (conn, name);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
+
+    /* Try XM for inactive domains. */
+    if (priv->opened[XEN_UNIFIED_XM_OFFSET]) {
+        ret = xenXMDomainLookupByName (conn, name);
+        if (ret || conn->err.code != VIR_ERR_OK)
+            return ret;
+    }
 
+    /* Not found. */
+    xenUnifiedError (conn, VIR_ERR_NO_DOMAIN, __FUNCTION__);
     return NULL;
 }
 

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]