diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/xen_unified.c libvirt-open-noisy/src/xen_unified.c
--- libvirt-cvs/src/xen_unified.c	2007-04-17 19:49:32.000000000 +0100
+++ libvirt-open-noisy/src/xen_unified.c	2007-04-30 12:02:45.000000000 +0100
@@ -41,14 +41,13 @@
 #include "xm_internal.h"
 
 /* The five Xen drivers below us. */
-static virDriverPtr drivers[] = {
+static virDriverPtr drivers[XEN_UNIFIED_NR_DRIVERS] = {
     &xenHypervisorDriver,
     &xenProxyDriver,
     &xenDaemonDriver,
     &xenStoreDriver,
     &xenXMDriver
 };
-static const int nb_drivers = sizeof drivers / sizeof drivers[0];
 static const int hypervisor_offset = 0;
 static const int proxy_offset = 1;
 
@@ -109,8 +108,8 @@
     priv->xshandle = NULL;
     priv->proxy = -1;
 
-    for (i = 0; i < nb_drivers; ++i) {
-        int failed_to_open = 1;
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) {
+        priv->opened[i] = 0;
 
         /* Ignore proxy for root */
         if (i == proxy_offset && getuid() == 0)
@@ -118,13 +117,13 @@
 
         if (drivers[i]->open &&
             drivers[i]->open (conn, name, flags) == VIR_DRV_OPEN_SUCCESS)
-            failed_to_open = 0;
+            priv->opened[i] = 1;
 
         /* If as root, then all drivers must succeed.
            If non-root, then only proxy must succeed */
-        if (failed_to_open && (getuid() == 0 || i == proxy_offset)) {
+        if (!priv->opened[i] && (getuid() == 0 || i == proxy_offset)) {
             for (j = 0; j < i; ++j)
-                drivers[j]->close (conn);
+                if (priv->opened[j]) drivers[j]->close (conn);
             return VIR_DRV_OPEN_ERROR;
         }
     }
@@ -132,13 +131,17 @@
     return VIR_DRV_OPEN_SUCCESS;
 }
 
+#define GET_PRIVATE(conn) \
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) (conn)->privateData
+
 static int
 xenUnifiedClose (virConnectPtr conn)
 {
+    GET_PRIVATE(conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->close)
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->close)
             (void) drivers[i]->close (conn);
 
     free (conn->privateData);
@@ -150,11 +153,12 @@
 static const char *
 xenUnifiedType (virConnectPtr conn)
 {
+    GET_PRIVATE(conn);
     int i;
     const char *ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->type) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->type) {
             ret = drivers[i]->type (conn);
             if (ret) return ret;
         }
@@ -165,10 +169,12 @@
 static int
 xenUnifiedVersion (virConnectPtr conn, unsigned long *hvVer)
 {
+    GET_PRIVATE(conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->version &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->version &&
             drivers[i]->version (conn, hvVer) == 0)
             return 0;
 
@@ -178,13 +184,14 @@
 static int
 xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type)
 {
+    GET_PRIVATE(conn);
     int i;
 
     if (!type)
         type = "Xen";
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (strcmp (drivers[i]->name, type) == 0)
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && strcmp (drivers[i]->name, type) == 0)
             return drivers[i]->getMaxVcpus (conn, type);
 
     return -1;
@@ -193,10 +200,12 @@
 static int
 xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info)
 {
+    GET_PRIVATE(conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->nodeGetInfo &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->nodeGetInfo &&
             drivers[i]->nodeGetInfo (conn, info) == 0)
             return 0;
 
@@ -206,11 +215,12 @@
 static char *
 xenUnifiedGetCapabilities (virConnectPtr conn)
 {
+    GET_PRIVATE(conn);
     int i;
     char *ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->getCapabilities) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->getCapabilities) {
             ret = drivers[i]->getCapabilities (conn);
             if (ret) return ret;
         }
@@ -221,10 +231,11 @@
 static int
 xenUnifiedListDomains (virConnectPtr conn, int *ids, int maxids)
 {
+    GET_PRIVATE(conn);
     int i, ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->listDomains) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->listDomains) {
             ret = drivers[i]->listDomains (conn, ids, maxids);
             if (ret >= 0) return ret;
         }
@@ -235,10 +246,11 @@
 static int
 xenUnifiedNumOfDomains (virConnectPtr conn)
 {
+    GET_PRIVATE(conn);
     int i, ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->numOfDomains) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->numOfDomains) {
             ret = drivers[i]->numOfDomains (conn);
             if (ret >= 0) return ret;
         }
@@ -250,11 +262,12 @@
 xenUnifiedDomainCreateLinux (virConnectPtr conn,
                              const char *xmlDesc, unsigned int flags)
 {
+    GET_PRIVATE(conn);
     int i;
     virDomainPtr ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainCreateLinux) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainCreateLinux) {
             ret = drivers[i]->domainCreateLinux (conn, xmlDesc, flags);
             if (ret) return ret;
         }
@@ -265,11 +278,12 @@
 static virDomainPtr
 xenUnifiedDomainLookupByID (virConnectPtr conn, int id)
 {
+    GET_PRIVATE(conn);
     int i;
     virDomainPtr ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainLookupByID) {
+    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;
         }
@@ -281,11 +295,12 @@
 xenUnifiedDomainLookupByUUID (virConnectPtr conn,
                               const unsigned char *uuid)
 {
+    GET_PRIVATE(conn);
     int i;
     virDomainPtr ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainLookupByUUID) {
+    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;
         }
@@ -297,11 +312,12 @@
 xenUnifiedDomainLookupByName (virConnectPtr conn,
                               const char *name)
 {
+    GET_PRIVATE(conn);
     int i;
     virDomainPtr ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainLookupByName) {
+    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;
         }
@@ -312,18 +328,21 @@
 static int
 xenUnifiedDomainSuspend (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
     /* Try non-hypervisor methods first, then hypervisor direct method
      * as a last resort.
      */
-    for (i = 0; i < nb_drivers; ++i)
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (i != hypervisor_offset &&
+            priv->opened[i] &&
             drivers[i]->domainSuspend &&
             drivers[i]->domainSuspend (dom) == 0)
             return 0;
 
-    if (drivers[hypervisor_offset]->domainSuspend &&
+    if (priv->opened[hypervisor_offset] &&
+        drivers[hypervisor_offset]->domainSuspend &&
         drivers[hypervisor_offset]->domainSuspend (dom) == 0)
         return 0;
 
@@ -333,18 +352,21 @@
 static int
 xenUnifiedDomainResume (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
     /* Try non-hypervisor methods first, then hypervisor direct method
      * as a last resort.
      */
-    for (i = 0; i < nb_drivers; ++i)
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (i != hypervisor_offset &&
+            priv->opened[i] &&
             drivers[i]->domainResume &&
             drivers[i]->domainResume (dom) == 0)
             return 0;
 
-    if (drivers[hypervisor_offset]->domainResume &&
+    if (priv->opened[hypervisor_offset] &&
+        drivers[hypervisor_offset]->domainResume &&
         drivers[hypervisor_offset]->domainResume (dom) == 0)
         return 0;
 
@@ -354,10 +376,12 @@
 static int
 xenUnifiedDomainShutdown (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainShutdown &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainShutdown &&
             drivers[i]->domainShutdown (dom) == 0)
             return 0;
 
@@ -367,10 +391,12 @@
 static int
 xenUnifiedDomainReboot (virDomainPtr dom, unsigned int flags)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainReboot &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainReboot &&
             drivers[i]->domainReboot (dom, flags) == 0)
             return 0;
 
@@ -380,18 +406,21 @@
 static int
 xenUnifiedDomainDestroy (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
     /* Try non-hypervisor methods first, then hypervisor direct method
      * as a last resort.
      */
-    for (i = 0; i < nb_drivers; ++i)
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (i != hypervisor_offset &&
+            priv->opened[i] &&
             drivers[i]->domainDestroy &&
             drivers[i]->domainDestroy (dom) == 0)
             return 0;
 
-    if (drivers[hypervisor_offset]->domainDestroy &&
+    if (priv->opened[i] &&
+        drivers[hypervisor_offset]->domainDestroy &&
         drivers[hypervisor_offset]->domainDestroy (dom) == 0)
         return 0;
 
@@ -401,11 +430,12 @@
 static char *
 xenUnifiedDomainGetOSType (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
     char *ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainGetOSType) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainGetOSType) {
             ret = drivers[i]->domainGetOSType (dom);
             if (ret) return ret;
         }
@@ -416,11 +446,12 @@
 static unsigned long
 xenUnifiedDomainGetMaxMemory (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
     unsigned long ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainGetMaxMemory) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainGetMaxMemory) {
             ret = drivers[i]->domainGetMaxMemory (dom);
             if (ret != 0) return ret;
         }
@@ -431,10 +462,12 @@
 static int
 xenUnifiedDomainSetMaxMemory (virDomainPtr dom, unsigned long memory)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainSetMaxMemory &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainSetMaxMemory &&
             drivers[i]->domainSetMaxMemory (dom, memory) == 0)
             return 0;
 
@@ -444,10 +477,12 @@
 static int
 xenUnifiedDomainSetMemory (virDomainPtr dom, unsigned long memory)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainSetMemory &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainSetMemory &&
             drivers[i]->domainSetMemory (dom, memory) == 0)
             return 0;
 
@@ -457,10 +492,12 @@
 static int
 xenUnifiedDomainGetInfo (virDomainPtr dom, virDomainInfoPtr info)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainGetInfo &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainGetInfo &&
             drivers[i]->domainGetInfo (dom, info) == 0)
             return 0;
 
@@ -470,10 +507,12 @@
 static int
 xenUnifiedDomainSave (virDomainPtr dom, const char *to)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainSave &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainSave &&
             drivers[i]->domainSave (dom, to) == 0)
             return 0;
 
@@ -483,10 +522,12 @@
 static int
 xenUnifiedDomainRestore (virConnectPtr conn, const char *from)
 {
+    GET_PRIVATE(conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainRestore &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainRestore &&
             drivers[i]->domainRestore (conn, from) == 0)
             return 0;
 
@@ -496,10 +537,12 @@
 static int
 xenUnifiedDomainCoreDump (virDomainPtr dom, const char *to, int flags)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainCoreDump &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainCoreDump &&
             drivers[i]->domainCoreDump (dom, to, flags) == 0)
             return 0;
 
@@ -509,18 +552,21 @@
 static int
 xenUnifiedDomainSetVcpus (virDomainPtr dom, unsigned int nvcpus)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
     /* Try non-hypervisor methods first, then hypervisor direct method
      * as a last resort.
      */
-    for (i = 0; i < nb_drivers; ++i)
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (i != hypervisor_offset &&
+            priv->opened[i] &&
             drivers[i]->domainSetVcpus &&
             drivers[i]->domainSetVcpus (dom, nvcpus) == 0)
             return 0;
 
-    if (drivers[hypervisor_offset]->domainSetVcpus &&
+    if (priv->opened[hypervisor_offset] &&
+        drivers[hypervisor_offset]->domainSetVcpus &&
         drivers[hypervisor_offset]->domainSetVcpus (dom, nvcpus) == 0)
         return 0;
 
@@ -531,10 +577,12 @@
 xenUnifiedDomainPinVcpu (virDomainPtr dom, unsigned int vcpu,
                          unsigned char *cpumap, int maplen)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainPinVcpu &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] &&
+            drivers[i]->domainPinVcpu &&
             drivers[i]->domainPinVcpu (dom, vcpu, cpumap, maplen) == 0)
             return 0;
 
@@ -546,10 +594,11 @@
                           virVcpuInfoPtr info, int maxinfo,
                           unsigned char *cpumaps, int maplen)
 {
+    GET_PRIVATE(dom->conn);
     int i, ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainGetVcpus) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainGetVcpus) {
             ret = drivers[i]->domainGetVcpus (dom, info, maxinfo, cpumaps, maplen);
             if (ret > 0)
                 return ret;
@@ -560,10 +609,11 @@
 static int
 xenUnifiedDomainGetMaxVcpus (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i, ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainGetMaxVcpus) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainGetMaxVcpus) {
             ret = drivers[i]->domainGetMaxVcpus (dom);
             if (ret != 0) return ret;
         }
@@ -574,11 +624,12 @@
 static char *
 xenUnifiedDomainDumpXML (virDomainPtr dom, int flags)
 {
+    GET_PRIVATE(dom->conn);
     int i;
     char *ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainDumpXML) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainDumpXML) {
             ret = drivers[i]->domainDumpXML (dom, flags);
             if (ret) return ret;
         }
@@ -590,11 +641,12 @@
 xenUnifiedListDefinedDomains (virConnectPtr conn, char **const names,
                               int maxnames)
 {
+    GET_PRIVATE(conn);
     int i;
     int ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->listDefinedDomains) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->listDefinedDomains) {
             ret = drivers[i]->listDefinedDomains (conn, names, maxnames);
             if (ret >= 0) return ret;
         }
@@ -605,11 +657,12 @@
 static int
 xenUnifiedNumOfDefinedDomains (virConnectPtr conn)
 {
+    GET_PRIVATE(conn);
     int i;
     int ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->numOfDefinedDomains) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->numOfDefinedDomains) {
             ret = drivers[i]->numOfDefinedDomains (conn);
             if (ret >= 0) return ret;
         }
@@ -620,10 +673,11 @@
 static int
 xenUnifiedDomainCreate (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainCreate &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainCreate &&
             drivers[i]->domainCreate (dom) == 0)
             return 0;
 
@@ -633,11 +687,12 @@
 static virDomainPtr
 xenUnifiedDomainDefineXML (virConnectPtr conn, const char *xml)
 {
+    GET_PRIVATE(conn);
     int i;
     virDomainPtr ret;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainDefineXML) {
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainDefineXML) {
             ret = drivers[i]->domainDefineXML (conn, xml);
             if (ret) return ret;
         }
@@ -648,10 +703,11 @@
 static int
 xenUnifiedDomainUndefine (virDomainPtr dom)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainUndefine &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainUndefine &&
             drivers[i]->domainUndefine (dom) == 0)
             return 0;
 
@@ -661,10 +717,11 @@
 static int
 xenUnifiedDomainAttachDevice (virDomainPtr dom, char *xml)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainAttachDevice &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainAttachDevice &&
             drivers[i]->domainAttachDevice (dom, xml) == 0)
             return 0;
 
@@ -674,10 +731,11 @@
 static int
 xenUnifiedDomainDetachDevice (virDomainPtr dom, char *xml)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainDetachDevice &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainDetachDevice &&
             drivers[i]->domainDetachDevice (dom, xml) == 0)
             return 0;
 
@@ -687,10 +745,11 @@
 static int
 xenUnifiedDomainGetAutostart (virDomainPtr dom, int *autostart)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainGetAutostart &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainGetAutostart &&
             drivers[i]->domainGetAutostart (dom, autostart) == 0)
             return 0;
 
@@ -700,10 +759,11 @@
 static int
 xenUnifiedDomainSetAutostart (virDomainPtr dom, int autostart)
 {
+    GET_PRIVATE(dom->conn);
     int i;
 
-    for (i = 0; i < nb_drivers; ++i)
-        if (drivers[i]->domainSetAutostart &&
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (priv->opened[i] && drivers[i]->domainSetAutostart &&
             drivers[i]->domainSetAutostart (dom, autostart) == 0)
             return 0;
 
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/xen_unified.h libvirt-open-noisy/src/xen_unified.h
--- libvirt-cvs/src/xen_unified.h	2007-04-10 12:17:18.000000000 +0100
+++ libvirt-open-noisy/src/xen_unified.h	2007-04-30 11:55:56.000000000 +0100
@@ -19,6 +19,8 @@
 
 extern int xenUnifiedRegister (void);
 
+#define XEN_UNIFIED_NR_DRIVERS 5
+
 /* xenUnifiedPrivatePtr:
  *
  * Per-connection private data, stored in conn->privateData.  All Xen
@@ -42,6 +44,12 @@
 #endif /* WITH_XEN */
 
     int proxy;                  /* fd of proxy. */
+
+    /* Keep track of the drivers which opened.  We keep a yes/no flag
+     * here for each driver, corresponding to the array drivers in
+     * xen_unified.c.
+     */
+    int opened[XEN_UNIFIED_NR_DRIVERS];
 };
 
 typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;
