Re: [libvirt] PATCH: 4/12: Refactoring URI probing

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

 



This patch changes the way hypervisor URIs are probed when NULL is passed
to the virConnectOpen() method. Previously we had an explicit probe method
called in each driver. This does not work when we move some drivers out of
libvirt.so and into libvirtd daemon. So I've refactored the way this works
so that we simply pass a NULL uri into the individual driver open methods.
If they see a NULL uri, they will make an attempt to open, and return a
VIR_DRV_OPEN_DECLINED code if its not suitable. This also works for the
remote driver, probing supported URI inside the daemon. Quite alot of code
churn but the end result should be functionally the same

Daniel

diff -r d97fa69e255b proxy/libvirt_proxy.c
--- a/proxy/libvirt_proxy.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/proxy/libvirt_proxy.c	Wed Nov 12 21:59:20 2008 +0000
@@ -82,7 +82,7 @@
     priv->xshandle = NULL;
     priv->proxy = -1;
 
-    ret = xenHypervisorOpen(conn, NULL, NULL, 0);
+    ret = xenHypervisorOpen(conn, NULL, 0);
     if (ret < 0) {
         fprintf(stderr, "Failed to open Xen hypervisor\n");
         return(-1);
@@ -98,7 +98,7 @@
         fprintf(stderr, "Failed to connect to Xen daemon\n");
         return(-1);
     }
-    ret = xenStoreOpen(conn, NULL, NULL, VIR_CONNECT_RO);
+    ret = xenStoreOpen(conn, NULL, VIR_CONNECT_RO);
     if (ret < 0) {
         fprintf(stderr, "Failed to open XenStore connection");
         return (-1);
diff -r d97fa69e255b qemud/remote.c
--- a/qemud/remote.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote.c	Wed Nov 12 21:59:20 2008 +0000
@@ -547,6 +547,23 @@
     if (hostname == NULL) return -1;
 
     ret->hostname = hostname;
+    return 0;
+}
+
+static int
+remoteDispatchGetUri (struct qemud_server *server ATTRIBUTE_UNUSED,
+                      struct qemud_client *client,
+                      remote_message_header *req,
+                      void *args ATTRIBUTE_UNUSED,
+                      remote_get_uri_ret *ret)
+{
+    char *uri;
+    CHECK_CONN(client);
+
+    uri = virConnectGetURI (client->conn);
+    if (uri == NULL) return -1;
+
+    ret->uri = uri;
     return 0;
 }
 
diff -r d97fa69e255b qemud/remote_dispatch_localvars.h
--- a/qemud/remote_dispatch_localvars.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote_dispatch_localvars.h	Wed Nov 12 21:59:20 2008 +0000
@@ -138,6 +138,7 @@
 remote_storage_vol_get_path_ret lv_remote_storage_vol_get_path_ret;
 remote_domain_lookup_by_id_args lv_remote_domain_lookup_by_id_args;
 remote_domain_lookup_by_id_ret lv_remote_domain_lookup_by_id_ret;
+remote_get_uri_ret lv_remote_get_uri_ret;
 remote_domain_attach_device_args lv_remote_domain_attach_device_args;
 remote_num_of_networks_ret lv_remote_num_of_networks_ret;
 remote_storage_pool_get_info_args lv_remote_storage_pool_get_info_args;
diff -r d97fa69e255b qemud/remote_dispatch_proc_switch.h
--- a/qemud/remote_dispatch_proc_switch.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote_dispatch_proc_switch.h	Wed Nov 12 21:59:20 2008 +0000
@@ -388,6 +388,12 @@
         ret_filter = (xdrproc_t) xdr_remote_get_type_ret;
         ret = (char *) &lv_remote_get_type_ret;
         memset (&lv_remote_get_type_ret, 0, sizeof lv_remote_get_type_ret);
+        break;
+case REMOTE_PROC_GET_URI:
+        fn = (dispatch_fn) remoteDispatchGetUri;
+        ret_filter = (xdrproc_t) xdr_remote_get_uri_ret;
+        ret = (char *) &lv_remote_get_uri_ret;
+        memset (&lv_remote_get_uri_ret, 0, sizeof lv_remote_get_uri_ret);
         break;
 case REMOTE_PROC_GET_VERSION:
         fn = (dispatch_fn) remoteDispatchGetVersion;
diff -r d97fa69e255b qemud/remote_dispatch_prototypes.h
--- a/qemud/remote_dispatch_prototypes.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote_dispatch_prototypes.h	Wed Nov 12 21:59:20 2008 +0000
@@ -55,6 +55,7 @@
 static int remoteDispatchGetHostname (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_get_hostname_ret *ret);
 static int remoteDispatchGetMaxVcpus (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_get_max_vcpus_args *args, remote_get_max_vcpus_ret *ret);
 static int remoteDispatchGetType (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_get_type_ret *ret);
+static int remoteDispatchGetUri (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_get_uri_ret *ret);
 static int remoteDispatchGetVersion (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_get_version_ret *ret);
 static int remoteDispatchListDefinedDomains (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_list_defined_domains_args *args, remote_list_defined_domains_ret *ret);
 static int remoteDispatchListDefinedNetworks (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_list_defined_networks_args *args, remote_list_defined_networks_ret *ret);
diff -r d97fa69e255b qemud/remote_protocol.c
--- a/qemud/remote_protocol.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote_protocol.c	Wed Nov 12 21:59:20 2008 +0000
@@ -271,6 +271,15 @@
 {
 
          if (!xdr_remote_nonnull_string (xdrs, &objp->hostname))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
+xdr_remote_get_uri_ret (XDR *xdrs, remote_get_uri_ret *objp)
+{
+
+         if (!xdr_remote_nonnull_string (xdrs, &objp->uri))
                  return FALSE;
         return TRUE;
 }
diff -r d97fa69e255b qemud/remote_protocol.h
--- a/qemud/remote_protocol.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote_protocol.h	Wed Nov 12 21:59:20 2008 +0000
@@ -153,6 +153,11 @@
         remote_nonnull_string hostname;
 };
 typedef struct remote_get_hostname_ret remote_get_hostname_ret;
+
+struct remote_get_uri_ret {
+        remote_nonnull_string uri;
+};
+typedef struct remote_get_uri_ret remote_get_uri_ret;
 
 struct remote_get_max_vcpus_args {
         remote_string type;
@@ -1208,6 +1213,7 @@
         REMOTE_PROC_DOMAIN_EVENTS_REGISTER = 105,
         REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER = 106,
         REMOTE_PROC_DOMAIN_EVENT = 107,
+        REMOTE_PROC_GET_URI = 108,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -1260,6 +1266,7 @@
 extern  bool_t xdr_remote_get_type_ret (XDR *, remote_get_type_ret*);
 extern  bool_t xdr_remote_get_version_ret (XDR *, remote_get_version_ret*);
 extern  bool_t xdr_remote_get_hostname_ret (XDR *, remote_get_hostname_ret*);
+extern  bool_t xdr_remote_get_uri_ret (XDR *, remote_get_uri_ret*);
 extern  bool_t xdr_remote_get_max_vcpus_args (XDR *, remote_get_max_vcpus_args*);
 extern  bool_t xdr_remote_get_max_vcpus_ret (XDR *, remote_get_max_vcpus_ret*);
 extern  bool_t xdr_remote_node_get_info_ret (XDR *, remote_node_get_info_ret*);
@@ -1444,6 +1451,7 @@
 extern bool_t xdr_remote_get_type_ret ();
 extern bool_t xdr_remote_get_version_ret ();
 extern bool_t xdr_remote_get_hostname_ret ();
+extern bool_t xdr_remote_get_uri_ret ();
 extern bool_t xdr_remote_get_max_vcpus_args ();
 extern bool_t xdr_remote_get_max_vcpus_ret ();
 extern bool_t xdr_remote_node_get_info_ret ();
diff -r d97fa69e255b qemud/remote_protocol.x
--- a/qemud/remote_protocol.x	Wed Nov 12 21:05:13 2008 +0000
+++ b/qemud/remote_protocol.x	Wed Nov 12 21:59:20 2008 +0000
@@ -243,6 +243,10 @@
 
 struct remote_get_hostname_ret {
     remote_nonnull_string hostname;
+};
+
+struct remote_get_uri_ret {
+    remote_nonnull_string uri;
 };
 
 struct remote_get_max_vcpus_args {
@@ -1103,13 +1107,12 @@
 
     REMOTE_PROC_NODE_GET_CELLS_FREE_MEMORY = 101,
     REMOTE_PROC_NODE_GET_FREE_MEMORY = 102,
-
     REMOTE_PROC_DOMAIN_BLOCK_PEEK = 103,
     REMOTE_PROC_DOMAIN_MEMORY_PEEK = 104,
-
     REMOTE_PROC_DOMAIN_EVENTS_REGISTER = 105,
     REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER = 106,
-    REMOTE_PROC_DOMAIN_EVENT = 107
+    REMOTE_PROC_DOMAIN_EVENT = 107,
+    REMOTE_PROC_GET_URI = 108
 };
 
 /* Custom RPC structure. */
diff -r d97fa69e255b src/datatypes.c
--- a/src/datatypes.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/datatypes.c	Wed Nov 12 21:59:20 2008 +0000
@@ -174,7 +174,7 @@
  */
 static void
 virReleaseConnect(virConnectPtr conn) {
-    DEBUG("release connection %p %s", conn, conn->name);
+    DEBUG("release connection %p", conn);
     if (conn->domains != NULL)
         virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
     if (conn->networks != NULL)
@@ -188,7 +188,7 @@
     if (virLastErr.conn == conn)
         virLastErr.conn = NULL;
 
-    VIR_FREE(conn->name);
+    xmlFreeURI(conn->uri);
 
     pthread_mutex_unlock(&conn->lock);
     pthread_mutex_destroy(&conn->lock);
@@ -213,7 +213,7 @@
         return(-1);
     }
     pthread_mutex_lock(&conn->lock);
-    DEBUG("unref connection %p %s %d", conn, conn->name, conn->refs);
+    DEBUG("unref connection %p %d", conn, conn->refs);
     conn->refs--;
     refs = conn->refs;
     if (refs == 0) {
@@ -322,7 +322,7 @@
     VIR_FREE(domain->name);
     VIR_FREE(domain);
 
-    DEBUG("unref connection %p %s %d", conn, conn->name, conn->refs);
+    DEBUG("unref connection %p %d", conn, conn->refs);
     conn->refs--;
     if (conn->refs == 0) {
         virReleaseConnect(conn);
@@ -458,7 +458,7 @@
     VIR_FREE(network->name);
     VIR_FREE(network);
 
-    DEBUG("unref connection %p %s %d", conn, conn->name, conn->refs);
+    DEBUG("unref connection %p %d", conn, conn->refs);
     conn->refs--;
     if (conn->refs == 0) {
         virReleaseConnect(conn);
@@ -591,7 +591,7 @@
     VIR_FREE(pool->name);
     VIR_FREE(pool);
 
-    DEBUG("unref connection %p %s %d", conn, conn->name, conn->refs);
+    DEBUG("unref connection %p %d", conn, conn->refs);
     conn->refs--;
     if (conn->refs == 0) {
         virReleaseConnect(conn);
@@ -729,7 +729,7 @@
     VIR_FREE(vol->pool);
     VIR_FREE(vol);
 
-    DEBUG("unref connection %p %s %d", conn, conn->name, conn->refs);
+    DEBUG("unref connection %p %d", conn, conn->refs);
     conn->refs--;
     if (conn->refs == 0) {
         virReleaseConnect(conn);
diff -r d97fa69e255b src/datatypes.h
--- a/src/datatypes.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/datatypes.h	Wed Nov 12 21:59:20 2008 +0000
@@ -87,7 +87,7 @@
 struct _virConnect {
     unsigned int magic;     /* specific value to check */
     int flags;              /* a set of connection flags */
-    char *name;                 /* connection URI */
+    xmlURIPtr uri;          /* connection URI */
 
     /* The underlying hypervisor driver and network driver. */
     virDriverPtr      driver;
diff -r d97fa69e255b src/driver.h
--- a/src/driver.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/driver.h	Wed Nov 12 21:59:20 2008 +0000
@@ -63,11 +63,8 @@
 #define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature)                      \
     ((drv)->supports_feature ? (drv)->supports_feature((conn),(feature)) : 0)
 
-typedef const char *
-        (*virDrvProbe)			(void);
 typedef virDrvOpenStatus
         (*virDrvOpen)			(virConnectPtr conn,
-                             xmlURIPtr uri,
                              virConnectAuthPtr auth,
                              int flags);
 typedef int
@@ -302,7 +299,6 @@
     int	       no;	/* the number virDrvNo */
     const char * name;	/* the name of the driver */
     unsigned long ver;	/* the version of the backend */
-    virDrvProbe			probe;
     virDrvOpen			open;
     virDrvClose			close;
     virDrvDrvSupportsFeature   supports_feature;
diff -r d97fa69e255b src/libvirt.c
--- a/src/libvirt.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/libvirt.c	Wed Nov 12 21:59:20 2008 +0000
@@ -685,8 +685,11 @@
          int flags)
 {
     int i, res;
-    virConnectPtr ret = NULL;
-    xmlURIPtr uri;
+    virConnectPtr ret;
+
+    ret = virGetConnect();
+    if (ret == NULL)
+        return NULL;
 
     /*
      *  If no URI is passed, then check for an environment string if not
@@ -699,74 +702,43 @@
             DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname);
             name = defname;
         } else {
-            const char *use = NULL;
-            const char *latest;
-            int probes = 0;
-            for (i = 0; i < virDriverTabCount; i++) {
-                if ((virDriverTab[i]->probe != NULL) &&
-                    ((latest = virDriverTab[i]->probe()) != NULL)) {
-                    probes++;
-
-                    DEBUG("Probed %s", latest);
-                    /*
-                     * if running a xen kernel, give it priority over
-                     * QEmu emulation
-                     */
-                    if (STREQ(latest, "xen:///"))
-                        use = latest;
-                    else if (use == NULL)
-                        use = latest;
-                }
-            }
-            if (use == NULL) {
-                name = "xen:///";
-                DEBUG("Could not probe any hypervisor defaulting to %s",
-                      name);
-            } else {
-                name = use;
-                DEBUG("Using %s as default URI, %d hypervisor found",
-                      use, probes);
-            }
-        }
-    }
-
-    /* Convert xen -> xen:/// for back compat */
-    if (STRCASEEQ(name, "xen"))
-        name = "xen:///";
-
-    /* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
-     * former.  This allows URIs such as xen://localhost to work.
-     */
-    if (STREQ (name, "xen://"))
-        name = "xen:///";
-
-    ret = virGetConnect();
-    if (ret == NULL)
-        return NULL;
-
-    uri = xmlParseURI (name);
-    if (!uri) {
-        virLibConnError (ret, VIR_ERR_INVALID_ARG,
-                         _("could not parse connection URI"));
-        goto failed;
-    }
-
-    DEBUG("name \"%s\" to URI components:\n"
-          "  scheme %s\n"
-          "  opaque %s\n"
-          "  authority %s\n"
-          "  server %s\n"
-          "  user %s\n"
-          "  port %d\n"
-          "  path %s\n",
-          name,
-          uri->scheme, uri->opaque, uri->authority, uri->server,
-          uri->user, uri->port, uri->path);
-
-    ret->name = strdup (name);
-    if (!ret->name) {
-        virLibConnError (ret, VIR_ERR_NO_MEMORY, _("allocating conn->name"));
-        goto failed;
+            name = NULL;
+        }
+    }
+
+    if (name) {
+        /* Convert xen -> xen:/// for back compat */
+        if (STRCASEEQ(name, "xen"))
+            name = "xen:///";
+
+        /* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
+         * former.  This allows URIs such as xen://localhost to work.
+         */
+        if (STREQ (name, "xen://"))
+            name = "xen:///";
+
+        ret->uri = xmlParseURI (name);
+        if (!ret->uri) {
+            virLibConnError (ret, VIR_ERR_INVALID_ARG,
+                             _("could not parse connection URI"));
+            goto failed;
+        }
+
+        DEBUG("name \"%s\" to URI components:\n"
+              "  scheme %s\n"
+              "  opaque %s\n"
+              "  authority %s\n"
+              "  server %s\n"
+              "  user %s\n"
+              "  port %d\n"
+              "  path %s\n",
+              name,
+              ret->uri->scheme, ret->uri->opaque,
+              ret->uri->authority, ret->uri->server,
+              ret->uri->user, ret->uri->port,
+              ret->uri->path);
+    } else {
+        DEBUG0("no name, allowing driver auto-select");
     }
 
     /* Cleansing flags */
@@ -775,7 +747,7 @@
     for (i = 0; i < virDriverTabCount; i++) {
         DEBUG("trying driver %d (%s) ...",
               i, virDriverTab[i]->name);
-        res = virDriverTab[i]->open (ret, uri, auth, flags);
+        res = virDriverTab[i]->open (ret, auth, flags);
         DEBUG("driver %d %s returned %s",
               i, virDriverTab[i]->name,
               res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
@@ -795,7 +767,7 @@
     }
 
     for (i = 0; i < virNetworkDriverTabCount; i++) {
-        res = virNetworkDriverTab[i]->open (ret, uri, auth, flags);
+        res = virNetworkDriverTab[i]->open (ret, auth, flags);
         DEBUG("network driver %d %s returned %s",
               i, virNetworkDriverTab[i]->name,
               res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
@@ -816,7 +788,7 @@
 
     /* Secondary driver for storage. Optional */
     for (i = 0; i < virStorageDriverTabCount; i++) {
-        res = virStorageDriverTab[i]->open (ret, uri, auth, flags);
+        res = virStorageDriverTab[i]->open (ret, auth, flags);
 #ifdef ENABLE_DEBUG
         DEBUG("storage driver %d %s returned %s",
               i, virStorageDriverTab[i]->name,
@@ -836,13 +808,10 @@
         }
     }
 
-    xmlFreeURI (uri);
-
     return ret;
 
 failed:
     if (ret->driver) ret->driver->close (ret);
-    if (uri) xmlFreeURI(uri);
 
     /* If no global error was set, copy any error set
        in the connection object we're about to dispose of */
@@ -1103,7 +1072,7 @@
     if (conn->driver->getURI)
         return conn->driver->getURI (conn);
 
-    name = strdup (conn->name);
+    name = (char *)xmlSaveUri(conn->uri);
     if (!name) {
         virLibConnError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
         return NULL;
diff -r d97fa69e255b src/lxc_driver.c
--- a/src/lxc_driver.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/lxc_driver.c	Wed Nov 12 21:59:20 2008 +0000
@@ -55,36 +55,34 @@
 
 /* Functions */
 
-static const char *lxcProbe(void)
+static int lxcProbe(void)
 {
-    if (lxcContainerAvailable(0) < 0)
-        return NULL;
+    if (getuid() != 0 ||
+        lxcContainerAvailable(0) < 0)
+        return 0;
 
-    return("lxc:///");
+    return 1;
 }
 
 static virDrvOpenStatus lxcOpen(virConnectPtr conn,
-                                xmlURIPtr uri,
                                 virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                 int flags ATTRIBUTE_UNUSED)
 {
-    uid_t uid = getuid();
-
-    /* Check that the user is root */
-    if (0 != uid) {
+    if (!lxcProbe())
         goto declineConnection;
-    }
 
     if (lxc_driver == NULL)
         goto declineConnection;
 
     /* Verify uri was specified */
-    if ((NULL == uri) || (NULL == uri->scheme)) {
-        goto declineConnection;
-    }
-
-    /* Check that the uri scheme is lxc */
-    if (STRNEQ(uri->scheme, "lxc")) {
+    if (conn->uri == NULL) {
+        conn->uri = xmlParseURI("lxc:///");
+        if (!conn->uri) {
+            lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL);
+            return VIR_DRV_OPEN_ERROR;
+        }
+    } else if (conn->uri->scheme == NULL ||
+               STRNEQ(conn->uri->scheme, "lxc")) {
         goto declineConnection;
     }
 
@@ -1226,7 +1224,6 @@
     VIR_DRV_LXC, /* the number virDrvNo */
     "LXC", /* the name of the driver */
     LIBVIR_VERSION_NUMBER, /* the version of the backend */
-    lxcProbe, /* probe */
     lxcOpen, /* open */
     lxcClose, /* close */
     NULL, /* supports_feature */
diff -r d97fa69e255b src/network_driver.c
--- a/src/network_driver.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/network_driver.c	Wed Nov 12 21:59:20 2008 +0000
@@ -836,7 +836,6 @@
 }
 
 static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn,
-                                           xmlURIPtr uri ATTRIBUTE_UNUSED,
                                            virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                            int flags ATTRIBUTE_UNUSED) {
     if (!driverState)
diff -r d97fa69e255b src/openvz_driver.c
--- a/src/openvz_driver.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/openvz_driver.c	Wed Nov 12 21:59:20 2008 +0000
@@ -861,35 +861,33 @@
     return 0;
 }
 
-static const char *openvzProbe(void)
+static int openvzProbe(void)
 {
-#ifdef __linux__
-    if ((geteuid() == 0) && (virFileExists("/proc/vz")))
-        return("openvz:///system");
-#endif
-    return(NULL);
+    if (geteuid() == 0 &&
+        virFileExists("/proc/vz"))
+        return 1;
+
+    return 0;
 }
 
 static virDrvOpenStatus openvzOpen(virConnectPtr conn,
-                                 xmlURIPtr uri,
-                                 virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-                                 int flags ATTRIBUTE_UNUSED)
+                                   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+                                   int flags ATTRIBUTE_UNUSED)
 {
     struct openvz_driver *driver;
-    /*Just check if the user is root. Nothing really to open for OpenVZ */
-    if (geteuid()) { // OpenVZ tools can only be used by r00t
+    if (!openvzProbe())
         return VIR_DRV_OPEN_DECLINED;
-    } else {
-        if (uri == NULL ||
-            uri->scheme == NULL ||
-            uri->path == NULL ||
-            STRNEQ (uri->scheme, "openvz") ||
-            STRNEQ (uri->path, "/system"))
-            return VIR_DRV_OPEN_DECLINED;
-    }
-    /* See if we are running an OpenVZ enabled kernel */
-    if(access("/proc/vz/veinfo", F_OK) == -1 ||
-       access("/proc/user_beancounters", F_OK) == -1) {
+
+    if (conn->uri == NULL) {
+        conn->uri = xmlParseURI("openvz:///system");
+        if (conn->uri == NULL) {
+            openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
+            return VIR_DRV_OPEN_ERROR;
+        }
+    } else if (conn->uri->scheme == NULL ||
+               conn->uri->path == NULL ||
+               STRNEQ (conn->uri->scheme, "openvz") ||
+               STRNEQ (conn->uri->path, "/system")) {
         return VIR_DRV_OPEN_DECLINED;
     }
 
@@ -1086,7 +1084,6 @@
     VIR_DRV_OPENVZ,
     "OPENVZ",
     LIBVIR_VERSION_NUMBER,
-    openvzProbe, /* probe */
     openvzOpen, /* open */
     openvzClose, /* close */
     NULL, /* supports_feature */
diff -r d97fa69e255b src/proxy_internal.c
--- a/src/proxy_internal.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/proxy_internal.c	Wed Nov 12 21:59:20 2008 +0000
@@ -36,7 +36,7 @@
 static int debug = 0;
 
 static int xenProxyClose(virConnectPtr conn);
-static int xenProxyOpen(virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags);
+static int xenProxyOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
 static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer);
 static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
 static char *xenProxyGetCapabilities(virConnectPtr conn);
@@ -480,7 +480,6 @@
  */
 int
 xenProxyOpen(virConnectPtr conn,
-             xmlURIPtr uri ATTRIBUTE_UNUSED,
              virConnectAuthPtr auth ATTRIBUTE_UNUSED,
              int flags)
 {
diff -r d97fa69e255b src/qemu_driver.c
--- a/src/qemu_driver.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/qemu_driver.c	Wed Nov 12 21:59:20 2008 +0000
@@ -1150,22 +1150,17 @@
  * Probe for the availability of the qemu driver, assume the
  * presence of QEmu emulation if the binaries are installed
  */
-static const char *qemudProbe(void)
+static int qemudProbe(void)
 {
     if ((virFileExists("/usr/bin/qemu")) ||
         (virFileExists("/usr/bin/qemu-kvm")) ||
-        (virFileExists("/usr/bin/xenner"))) {
-        if (getuid() == 0) {
-            return("qemu:///system");
-        } else {
-            return("qemu:///session");
-        }
-    }
-    return(NULL);
+        (virFileExists("/usr/bin/xenner")))
+        return 1;
+
+    return 0;
 }
 
 static virDrvOpenStatus qemudOpen(virConnectPtr conn,
-                                  xmlURIPtr uri,
                                   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                   int flags ATTRIBUTE_UNUSED) {
     uid_t uid = getuid();
@@ -1173,18 +1168,28 @@
     if (qemu_driver == NULL)
         goto decline;
 
-    if (uri == NULL || uri->scheme == NULL || uri->path == NULL)
+    if (!qemudProbe())
         goto decline;
 
-    if (STRNEQ (uri->scheme, "qemu"))
+    if (conn->uri == NULL) {
+        conn->uri = xmlParseURI(uid ? "qemu:///session" : "qemu:///system");
+        if (!conn->uri) {
+            qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,NULL);
+            return VIR_DRV_OPEN_ERROR;
+        }
+    } else if (conn->uri->scheme == NULL ||
+               conn->uri->path == NULL)
+        goto decline;
+
+    if (STRNEQ (conn->uri->scheme, "qemu"))
         goto decline;
 
     if (uid != 0) {
-        if (STRNEQ (uri->path, "/session"))
+        if (STRNEQ (conn->uri->path, "/session"))
             goto decline;
     } else { /* root */
-        if (STRNEQ (uri->path, "/system") &&
-            STRNEQ (uri->path, "/session"))
+        if (STRNEQ (conn->uri->path, "/system") &&
+            STRNEQ (conn->uri->path, "/session"))
             goto decline;
     }
 
@@ -3358,7 +3363,6 @@
     VIR_DRV_QEMU,
     "QEMU",
     LIBVIR_VERSION_NUMBER,
-    qemudProbe, /* probe */
     qemudOpen, /* open */
     qemudClose, /* close */
     NULL, /* supports_feature */
diff -r d97fa69e255b src/remote_internal.c
--- a/src/remote_internal.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/remote_internal.c	Wed Nov 12 21:59:20 2008 +0000
@@ -273,46 +273,51 @@
     VIR_DRV_OPEN_REMOTE_AUTOSTART = (1 << 3),
 };
 
+/* What transport? */
+enum {
+    trans_tls,
+    trans_unix,
+    trans_ssh,
+    trans_ext,
+    trans_tcp,
+} transport;
+
+
 static int
 doRemoteOpen (virConnectPtr conn,
               struct private_data *priv,
-              xmlURIPtr uri,
               virConnectAuthPtr auth ATTRIBUTE_UNUSED,
               int flags)
 {
-    if (!uri || !uri->scheme)
-        return VIR_DRV_OPEN_DECLINED; /* Decline - not a URL. */
-
-    char *transport_str = get_transport_from_scheme (uri->scheme);
-
-    /* What transport? */
-    enum {
-        trans_tls,
-        trans_unix,
-        trans_ssh,
-        trans_ext,
-        trans_tcp,
-    } transport;
-
-    if (!transport_str || STRCASEEQ (transport_str, "tls"))
-        transport = trans_tls;
-    else if (STRCASEEQ (transport_str, "unix"))
-        transport = trans_unix;
-    else if (STRCASEEQ (transport_str, "ssh"))
-        transport = trans_ssh;
-    else if (STRCASEEQ (transport_str, "ext"))
-        transport = trans_ext;
-    else if (STRCASEEQ (transport_str, "tcp"))
-        transport = trans_tcp;
-    else {
-        error (conn, VIR_ERR_INVALID_ARG,
-               _("remote_open: transport in URL not recognised "
-                 "(should be tls|unix|ssh|ext|tcp)"));
-        return VIR_DRV_OPEN_ERROR;
-    }
-
-    if (!uri->server && !transport_str) {
-        if (flags & VIR_DRV_OPEN_REMOTE_UNIX)
+    char *transport_str = NULL;
+
+    if (conn->uri) {
+        if (!conn->uri->scheme)
+            return VIR_DRV_OPEN_DECLINED;
+
+        transport_str = get_transport_from_scheme (conn->uri->scheme);
+
+        if (!transport_str || STRCASEEQ (transport_str, "tls"))
+            transport = trans_tls;
+        else if (STRCASEEQ (transport_str, "unix"))
+            transport = trans_unix;
+        else if (STRCASEEQ (transport_str, "ssh"))
+            transport = trans_ssh;
+        else if (STRCASEEQ (transport_str, "ext"))
+            transport = trans_ext;
+        else if (STRCASEEQ (transport_str, "tcp"))
+            transport = trans_tcp;
+        else {
+            error (conn, VIR_ERR_INVALID_ARG,
+                   _("remote_open: transport in URL not recognised "
+                     "(should be tls|unix|ssh|ext|tcp)"));
+            return VIR_DRV_OPEN_ERROR;
+        }
+    }
+
+    if (!transport_str) {
+        if ((!conn->uri || !conn->uri->server) &&
+            (flags & VIR_DRV_OPEN_REMOTE_UNIX))
             transport = trans_unix;
         else
             return VIR_DRV_OPEN_DECLINED; /* Decline - not a remote URL. */
@@ -330,8 +335,8 @@
     int retcode = VIR_DRV_OPEN_ERROR;
 
     /* Remote server defaults to "localhost" if not specified. */
-    if (uri->port != 0) {
-        if (asprintf (&port, "%d", uri->port) == -1) goto out_of_memory;
+    if (conn->uri && conn->uri->port != 0) {
+        if (asprintf (&port, "%d", conn->uri->port) == -1) goto out_of_memory;
     } else if (transport == trans_tls) {
         port = strdup (LIBVIRTD_TLS_PORT);
         if (!port) goto out_of_memory;
@@ -345,11 +350,12 @@
         port = NULL;           /* Port not used for unix, ext. */
 
 
-    priv->hostname = strdup (uri->server ? uri->server : "localhost");
+    priv->hostname = strdup (conn->uri && conn->uri->server ?
+                             conn->uri->server : "localhost");
     if (!priv->hostname)
         goto out_of_memory;
-    if (uri->user) {
-        username = strdup (uri->user);
+    if (conn->uri && conn->uri->user) {
+        username = strdup (conn->uri->user);
         if (!username)
             goto out_of_memory;
     }
@@ -363,67 +369,93 @@
     struct qparam *var;
     int i;
     char *query;
+
+    if (conn->uri) {
 #ifdef HAVE_XMLURI_QUERY_RAW
-    query = uri->query_raw;
+        query = conn->uri->query_raw;
 #else
-    query = uri->query;
-#endif
-    vars = qparam_query_parse (query);
-    if (vars == NULL) goto failed;
-
-    for (i = 0; i < vars->n; i++) {
-        var = &vars->p[i];
-        if (STRCASEEQ (var->name, "name")) {
-            name = strdup (var->value);
-            if (!name) goto out_of_memory;
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "command")) {
-            command = strdup (var->value);
-            if (!command) goto out_of_memory;
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "socket")) {
-            sockname = strdup (var->value);
-            if (!sockname) goto out_of_memory;
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "auth")) {
-            authtype = strdup (var->value);
-            if (!authtype) goto out_of_memory;
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "netcat")) {
-            netcat = strdup (var->value);
-            if (!netcat) goto out_of_memory;
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "no_verify")) {
-            no_verify = atoi (var->value);
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "no_tty")) {
-            no_tty = atoi (var->value);
-            var->ignore = 1;
-        } else if (STRCASEEQ (var->name, "debug")) {
-            if (var->value &&
-                STRCASEEQ (var->value, "stdout"))
-                priv->debugLog = stdout;
-            else
-                priv->debugLog = stderr;
-        } else
-            DEBUG("passing through variable '%s' ('%s') to remote end",
-                  var->name, var->value);
-    }
-
+        query = conn->uri->query;
+#endif
+        vars = qparam_query_parse (query);
+        if (vars == NULL) goto failed;
+
+        for (i = 0; i < vars->n; i++) {
+            var = &vars->p[i];
+            if (STRCASEEQ (var->name, "name")) {
+                name = strdup (var->value);
+                if (!name) goto out_of_memory;
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "command")) {
+                command = strdup (var->value);
+                if (!command) goto out_of_memory;
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "socket")) {
+                sockname = strdup (var->value);
+                if (!sockname) goto out_of_memory;
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "auth")) {
+                authtype = strdup (var->value);
+                if (!authtype) goto out_of_memory;
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "netcat")) {
+                netcat = strdup (var->value);
+                if (!netcat) goto out_of_memory;
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "no_verify")) {
+                no_verify = atoi (var->value);
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "no_tty")) {
+                no_tty = atoi (var->value);
+                var->ignore = 1;
+            } else if (STRCASEEQ (var->name, "debug")) {
+                if (var->value &&
+                    STRCASEEQ (var->value, "stdout"))
+                    priv->debugLog = stdout;
+                else
+                    priv->debugLog = stderr;
+            } else
+                DEBUG("passing through variable '%s' ('%s') to remote end",
+                      var->name, var->value);
+        }
+
+        /* Construct the original name. */
+        if (!name) {
+            xmlURI tmpuri = {
+                .scheme = conn->uri->scheme,
 #ifdef HAVE_XMLURI_QUERY_RAW
-    xmlFree (uri->query_raw);
+                .query_raw = qparam_get_query (vars),
 #else
-    xmlFree (uri->query);
-#endif
-
-#ifdef HAVE_XMLURI_QUERY_RAW
-    uri->query_raw =
-#else
-    uri->query =
-#endif
-         qparam_get_query (vars);
-
-    free_qparam_set (vars);
+                .query = qparam_get_query (vars),
+#endif
+                .path = conn->uri->path,
+                .fragment = conn->uri->fragment,
+            };
+
+            /* Evil, blank out transport scheme temporarily */
+            if (transport_str) {
+                assert (transport_str[-1] == '+');
+                transport_str[-1] = '\0';
+            }
+
+            name = (char *) xmlSaveUri (&tmpuri);
+
+            /* Restore transport scheme */
+            if (transport_str)
+                transport_str[-1] = '+';
+        }
+
+        free_qparam_set (vars);
+    } else {
+        /* Probe URI server side */
+        name = strdup("");
+    }
+
+    if (!name) {
+        error(conn, VIR_ERR_NO_MEMORY, NULL);
+        goto failed;
+    }
+
+    DEBUG("proceeding with name = %s", name);
 
     /* For ext transport, command is required. */
     if (transport == trans_ext && !command) {
@@ -431,28 +463,6 @@
                _("remote_open: for 'ext' transport, command is required"));
         goto failed;
     }
-
-    /* Construct the original name. */
-    if (!name) {
-        /* Remove the transport (if any) from the scheme. */
-        if (transport_str) {
-            assert (transport_str[-1] == '+');
-            transport_str[-1] = '\0';
-        }
-        /* Remove the username, server name and port number. */
-        xmlFree (uri->user);
-        uri->user = 0;
-
-        xmlFree (uri->server);
-        uri->server = 0;
-
-        uri->port = 0;
-
-        name = (char *) xmlSaveUri (uri);
-    }
-
-    assert (name);
-    DEBUG("proceeding with name = %s", name);
 
     /* Connect to the remote service. */
     switch (transport) {
@@ -702,6 +712,38 @@
               (xdrproc_t) xdr_void, (char *) NULL) == -1)
         goto failed;
 
+    /* Now try and find out what URI the daemon used */
+    if (conn->uri == NULL) {
+        remote_get_uri_ret uriret;
+        int urierr;
+
+        memset (&uriret, 0, sizeof uriret);
+        urierr = call (conn, priv,
+                       REMOTE_CALL_IN_OPEN | REMOTE_CALL_QUIET_MISSING_RPC,
+                       REMOTE_PROC_GET_URI,
+                       (xdrproc_t) xdr_void, (char *) NULL,
+                       (xdrproc_t) xdr_remote_get_uri_ret, (char *) &uriret);
+        if (urierr == -2) {
+            /* Should not really happen, since we only probe local libvirtd's,
+               & the library should always match the daemon. Only case is post
+               RPM upgrade where an old daemon instance is still running with
+               new client. Too bad. It is not worth the hassle to fix this */
+            error (conn, VIR_ERR_INTERNAL_ERROR, _("unable to auto-detect URI"));
+            goto failed;
+        }
+        if (urierr == -1) {
+            goto failed;
+        }
+
+        DEBUG("Auto-probed URI is %s", uriret.uri);
+        conn->uri = xmlParseURI(uriret.uri);
+        VIR_FREE(uriret.uri);
+        if (!conn->uri) {
+            error (conn, VIR_ERR_NO_MEMORY, NULL);
+            goto failed;
+        }
+    }
+
     if(VIR_ALLOC(priv->callbackList)<0) {
         error(conn, VIR_ERR_INVALID_ARG, _("Error allocating callbacks list"));
         goto failed;
@@ -788,7 +830,6 @@
 
 static int
 remoteOpen (virConnectPtr conn,
-            xmlURIPtr uri,
             virConnectAuthPtr auth,
             int flags)
 {
@@ -806,40 +847,54 @@
     if (flags & VIR_CONNECT_RO)
         rflags |= VIR_DRV_OPEN_REMOTE_RO;
 
-#if WITH_QEMU
-    if (uri &&
-        uri->scheme && STREQ (uri->scheme, "qemu") &&
-        (!uri->server || STREQ (uri->server, "")) &&
-        uri->path) {
-        if (STREQ (uri->path, "/system")) {
-            rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-        } else if (STREQ (uri->path, "/session")) {
-            rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-            if (getuid() > 0) {
-                rflags |= VIR_DRV_OPEN_REMOTE_USER;
-                rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
-            }
-        }
-    }
-#endif
-#if WITH_XEN
-    if (uri &&
-        uri->scheme && STREQ (uri->scheme, "xen") &&
-        (!uri->server || STREQ (uri->server, "")) &&
-        (!uri->path || STREQ(uri->path, "/"))) {
+    /*
+     * If no servername is given, and no +XXX
+     * transport is listed, then force to a
+     * local UNIX socket connection
+     */
+    if (conn->uri &&
+        !conn->uri->server &&
+        !strchr(conn->uri->scheme, '+')) {
+        DEBUG0("Auto-remote UNIX socket");
         rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
     }
-#endif
-#if WITH_LXC
-    if (uri &&
-        uri->scheme && STREQ (uri->scheme, "lxc")) {
+
+    /*
+     * If no servername is given, and no +XXX
+     * transport is listed, or transport is unix,
+     * and path is /session, and uid is unprivileged
+     * then auto-spawn a daemon.
+     */
+    if (conn->uri &&
+        !conn->uri->server &&
+        conn->uri->path &&
+        ((strchr(conn->uri->scheme, '+') == 0)||
+         (strstr(conn->uri->scheme, "+unix") != NULL)) &&
+        STREQ(conn->uri->path, "/session") &&
+        getuid() > 0) {
+        DEBUG0("Auto-spawn user daemon instance");
+        rflags |= VIR_DRV_OPEN_REMOTE_USER;
+        rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
+    }
+
+    /*
+     * If URI is NULL, then do a UNIX connection
+     * possibly auto-spawning unprivileged server
+     * and probe remote server for URI
+     */
+    if (!conn->uri) {
+        DEBUG0("Auto-probe remote URI");
         rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-    }
-#endif
+        if (getuid() > 0) {
+            DEBUG0("Auto-spawn user daemon instance");
+            rflags |= VIR_DRV_OPEN_REMOTE_USER;
+            rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
+        }
+    }
 
     priv->magic = DEAD;
     priv->sock = -1;
-    ret = doRemoteOpen(conn, priv, uri, auth, rflags);
+    ret = doRemoteOpen(conn, priv, auth, rflags);
     if (ret != VIR_DRV_OPEN_SUCCESS) {
         conn->privateData = NULL;
         VIR_FREE(priv);
@@ -2486,7 +2541,6 @@
 
 static int
 remoteNetworkOpen (virConnectPtr conn,
-                   xmlURIPtr uri,
                    virConnectAuthPtr auth,
                    int flags)
 {
@@ -2520,7 +2574,7 @@
 
         priv->magic = DEAD;
         priv->sock = -1;
-        ret = doRemoteOpen(conn, priv, uri, auth, rflags);
+        ret = doRemoteOpen(conn, priv, auth, rflags);
         if (ret != VIR_DRV_OPEN_SUCCESS) {
             conn->networkPrivateData = NULL;
             VIR_FREE(priv);
@@ -2887,7 +2941,6 @@
 
 static int
 remoteStorageOpen (virConnectPtr conn,
-                   xmlURIPtr uri,
                    virConnectAuthPtr auth,
                    int flags)
 {
@@ -2926,7 +2979,7 @@
 
         priv->magic = DEAD;
         priv->sock = -1;
-        ret = doRemoteOpen(conn, priv, uri, auth, rflags);
+        ret = doRemoteOpen(conn, priv, auth, rflags);
         if (ret != VIR_DRV_OPEN_SUCCESS) {
             conn->storagePrivateData = NULL;
             VIR_FREE(priv);
@@ -4935,7 +4988,6 @@
     .no = VIR_DRV_REMOTE,
     .name = "remote",
     .ver = REMOTE_PROTOCOL_VERSION,
-    .probe = NULL,
     .open = remoteOpen,
     .close = remoteClose,
     .supports_feature = remoteSupportsFeature,
diff -r d97fa69e255b src/storage_driver.c
--- a/src/storage_driver.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/storage_driver.c	Wed Nov 12 21:59:20 2008 +0000
@@ -294,7 +294,6 @@
 
 static virDrvOpenStatus
 storageOpen(virConnectPtr conn,
-            xmlURIPtr uri ATTRIBUTE_UNUSED,
             virConnectAuthPtr auth ATTRIBUTE_UNUSED,
             int flags ATTRIBUTE_UNUSED) {
     if (!driverState)
diff -r d97fa69e255b src/test.c
--- a/src/test.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/test.c	Wed Nov 12 21:59:20 2008 +0000
@@ -635,39 +635,38 @@
 
 
 static int testOpen(virConnectPtr conn,
-                    xmlURIPtr uri,
                     virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                     int flags ATTRIBUTE_UNUSED)
 {
     int ret;
 
-    if (!uri)
+    if (!conn->uri)
         return VIR_DRV_OPEN_DECLINED;
 
-    if (!uri->scheme || STRNEQ(uri->scheme, "test"))
+    if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "test"))
         return VIR_DRV_OPEN_DECLINED;
 
     /* Remote driver should handle these. */
-    if (uri->server)
+    if (conn->uri->server)
         return VIR_DRV_OPEN_DECLINED;
 
-    if (uri->server)
+    if (conn->uri->server)
         return VIR_DRV_OPEN_DECLINED;
 
     /* From this point on, the connection is for us. */
-    if (!uri->path
-        || uri->path[0] == '\0'
-        || (uri->path[0] == '/' && uri->path[1] == '\0')) {
+    if (!conn->uri->path
+        || conn->uri->path[0] == '\0'
+        || (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) {
         testError (NULL, VIR_ERR_INVALID_ARG,
                    "%s", _("testOpen: supply a path or use test:///default"));
         return VIR_DRV_OPEN_ERROR;
     }
 
-    if (STREQ(uri->path, "/default"))
+    if (STREQ(conn->uri->path, "/default"))
         ret = testOpenDefault(conn);
     else
         ret = testOpenFromFile(conn,
-                               uri->path);
+                               conn->uri->path);
 
     return (ret);
 }
@@ -711,19 +710,6 @@
         return NULL;
     }
     return str;
-}
-
-static char * testGetURI (virConnectPtr conn)
-{
-    char *uri;
-    GET_CONNECTION(conn);
-
-    if (asprintf (&uri, "test://%s", privconn->path) == -1) {
-        testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
-                   strerror (errno));
-        return NULL;
-    }
-    return uri;
 }
 
 static int testGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -1398,7 +1384,6 @@
 }
 
 static virDrvOpenStatus testOpenNetwork(virConnectPtr conn,
-                                        xmlURIPtr uri ATTRIBUTE_UNUSED,
                                         virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                         int flags ATTRIBUTE_UNUSED) {
     if (STRNEQ(conn->driver->name, "Test"))
@@ -1631,7 +1616,6 @@
 }
 
 static virDrvOpenStatus testStorageOpen(virConnectPtr conn,
-                                        xmlURIPtr uri ATTRIBUTE_UNUSED,
                                         virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                         int flags ATTRIBUTE_UNUSED) {
     if (STRNEQ(conn->driver->name, "Test"))
@@ -2211,14 +2195,13 @@
     VIR_DRV_TEST,
     "Test",
     LIBVIR_VERSION_NUMBER,
-    NULL, /* probe */
     testOpen, /* open */
     testClose, /* close */
     NULL, /* supports_feature */
     NULL, /* type */
     testGetVersion, /* version */
     testGetHostname, /* hostname */
-    testGetURI, /* URI */
+    NULL, /* URI */
     testGetMaxVCPUs, /* getMaxVcpus */
     testNodeGetInfo, /* nodeGetInfo */
     testGetCapabilities, /* getCapabilities */
diff -r d97fa69e255b src/xen_internal.c
--- a/src/xen_internal.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xen_internal.c	Wed Nov 12 21:59:20 2008 +0000
@@ -2033,7 +2033,6 @@
  */
 int
 xenHypervisorOpen(virConnectPtr conn,
-                  xmlURIPtr uri ATTRIBUTE_UNUSED,
                   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                   int flags ATTRIBUTE_UNUSED)
 {
diff -r d97fa69e255b src/xen_internal.h
--- a/src/xen_internal.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xen_internal.h	Wed Nov 12 21:59:20 2008 +0000
@@ -33,7 +33,6 @@
         xenHypervisorDomainGetOSType (virDomainPtr dom);
 
 int	xenHypervisorOpen		(virConnectPtr conn,
-                                         xmlURIPtr uri,
                                          virConnectAuthPtr auth,
                                          int flags);
 int	xenHypervisorClose		(virConnectPtr conn);
diff -r d97fa69e255b src/xen_unified.c
--- a/src/xen_unified.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xen_unified.c	Wed Nov 12 21:59:20 2008 +0000
@@ -200,34 +200,45 @@
  * in the low level drivers directly.
  */
 
-static const char *
+static int
 xenUnifiedProbe (void)
 {
 #ifdef __linux__
     if (virFileExists("/proc/xen"))
-        return("xen:///");
+        return 1;
 #endif
 #ifdef __sun__
     FILE *fh;
 
     if (fh = fopen("/dev/xen/domcaps", "r")) {
         fclose(fh);
-        return("xen:///");
+        return 1;
     }
 #endif
-    return(NULL);
+    return 0;
 }
 
 static int
-xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags)
+xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags)
 {
     int i, ret = VIR_DRV_OPEN_DECLINED;
     xenUnifiedPrivatePtr priv;
 
+    if (conn->uri == NULL) {
+        if (!xenUnifiedProbe())
+            return VIR_DRV_OPEN_DECLINED;
+
+        conn->uri = xmlParseURI("xen:///");
+        if (!conn->uri) {
+            xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, NULL);
+            return VIR_DRV_OPEN_ERROR;
+        }
+    }
+
     /* Refuse any scheme which isn't "xen://" or "http://";. */
-    if (uri->scheme &&
-        STRCASENEQ(uri->scheme, "xen") &&
-        STRCASENEQ(uri->scheme, "http"))
+    if (conn->uri->scheme &&
+        STRCASENEQ(conn->uri->scheme, "xen") &&
+        STRCASENEQ(conn->uri->scheme, "http"))
         return VIR_DRV_OPEN_DECLINED;
 
     /* xmlParseURI will parse a naked string like "foo" as a URI with
@@ -235,11 +246,11 @@
      * allow full pathnames (eg. ///var/lib/xen/xend-socket).  Decline
      * anything else.
      */
-    if (!uri->scheme && (!uri->path || uri->path[0] != '/'))
+    if (!conn->uri->scheme && (!conn->uri->path || conn->uri->path[0] != '/'))
         return VIR_DRV_OPEN_DECLINED;
 
     /* Refuse any xen:// URI with a server specified - allow remote to do it */
-    if (uri->scheme && STRCASEEQ(uri->scheme, "xen") && uri->server)
+    if (conn->uri->scheme && STRCASEEQ(conn->uri->scheme, "xen") && conn->uri->server)
         return VIR_DRV_OPEN_DECLINED;
 
     /* Allocate per-connection private data. */
@@ -261,7 +272,7 @@
     /* Hypervisor is only run as root & required to succeed */
     if (getuid() == 0) {
         DEBUG0("Trying hypervisor sub-driver");
-        if (drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->open(conn, uri, auth, flags) ==
+        if (drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->open(conn, auth, flags) ==
             VIR_DRV_OPEN_SUCCESS) {
             DEBUG0("Activated hypervisor sub-driver");
             priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET] = 1;
@@ -272,7 +283,7 @@
      * If it fails as non-root, then the proxy driver may take over
      */
     DEBUG0("Trying XenD sub-driver");
-    if (drivers[XEN_UNIFIED_XEND_OFFSET]->open(conn, uri, auth, flags) ==
+    if (drivers[XEN_UNIFIED_XEND_OFFSET]->open(conn, auth, flags) ==
         VIR_DRV_OPEN_SUCCESS) {
         DEBUG0("Activated XenD sub-driver");
         priv->opened[XEN_UNIFIED_XEND_OFFSET] = 1;
@@ -281,14 +292,14 @@
          * succeed if root, optional otherwise */
         if (priv->xendConfigVersion <= 2) {
             DEBUG0("Trying XM sub-driver");
-            if (drivers[XEN_UNIFIED_XM_OFFSET]->open(conn, uri, auth, flags) ==
+            if (drivers[XEN_UNIFIED_XM_OFFSET]->open(conn, auth, flags) ==
                 VIR_DRV_OPEN_SUCCESS) {
                 DEBUG0("Activated XM sub-driver");
                 priv->opened[XEN_UNIFIED_XM_OFFSET] = 1;
             }
         }
         DEBUG0("Trying XS sub-driver");
-        if (drivers[XEN_UNIFIED_XS_OFFSET]->open(conn, uri, auth, flags) ==
+        if (drivers[XEN_UNIFIED_XS_OFFSET]->open(conn, auth, flags) ==
             VIR_DRV_OPEN_SUCCESS) {
             DEBUG0("Activated XS sub-driver");
             priv->opened[XEN_UNIFIED_XS_OFFSET] = 1;
@@ -302,7 +313,7 @@
         } else {
 #if WITH_PROXY
             DEBUG0("Trying proxy sub-driver");
-            if (drivers[XEN_UNIFIED_PROXY_OFFSET]->open(conn, uri, auth, flags) ==
+            if (drivers[XEN_UNIFIED_PROXY_OFFSET]->open(conn, auth, flags) ==
                 VIR_DRV_OPEN_SUCCESS) {
                 DEBUG0("Activated proxy sub-driver");
                 priv->opened[XEN_UNIFIED_PROXY_OFFSET] = 1;
@@ -1292,7 +1303,6 @@
     .no = VIR_DRV_XEN_UNIFIED,
     .name = "Xen",
     .ver = HV_VERSION,
-    .probe 			= xenUnifiedProbe,
     .open 			= xenUnifiedOpen,
     .close 			= xenUnifiedClose,
     .supports_feature   = xenUnifiedSupportsFeature,
diff -r d97fa69e255b src/xend_internal.c
--- a/src/xend_internal.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xend_internal.c	Wed Nov 12 21:59:20 2008 +0000
@@ -2706,7 +2706,6 @@
  */
 int
 xenDaemonOpen(virConnectPtr conn,
-              xmlURIPtr uri,
               virConnectAuthPtr auth ATTRIBUTE_UNUSED,
               int flags ATTRIBUTE_UNUSED)
 {
@@ -2715,13 +2714,13 @@
     /* Switch on the scheme, which we expect to be NULL (file),
      * "http" or "xen".
      */
-    if (uri->scheme == NULL) {
+    if (conn->uri->scheme == NULL) {
         /* It should be a file access */
-        if (uri->path == NULL) {
+        if (conn->uri->path == NULL) {
             virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
             goto failed;
         }
-        ret = xenDaemonOpen_unix(conn, uri->path);
+        ret = xenDaemonOpen_unix(conn, conn->uri->path);
         if (ret < 0)
             goto failed;
 
@@ -2729,7 +2728,7 @@
         if (ret == -1)
             goto failed;
     }
-    else if (STRCASEEQ (uri->scheme, "xen")) {
+    else if (STRCASEEQ (conn->uri->scheme, "xen")) {
         /*
          * try first to open the unix socket
          */
@@ -2750,8 +2749,8 @@
         ret = xend_detect_config_version(conn);
         if (ret == -1)
             goto failed;
-    } else if (STRCASEEQ (uri->scheme, "http")) {
-        ret = xenDaemonOpen_tcp(conn, uri->server, uri->port);
+    } else if (STRCASEEQ (conn->uri->scheme, "http")) {
+        ret = xenDaemonOpen_tcp(conn, conn->uri->server, conn->uri->port);
         if (ret < 0)
             goto failed;
         ret = xend_detect_config_version(conn);
diff -r d97fa69e255b src/xend_internal.h
--- a/src/xend_internal.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xend_internal.h	Wed Nov 12 21:59:20 2008 +0000
@@ -129,7 +129,7 @@
 
 
 /* refactored ones */
-int xenDaemonOpen(virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags);
+int xenDaemonOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
 int xenDaemonClose(virConnectPtr conn);
 int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
 int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
diff -r d97fa69e255b src/xm_internal.c
--- a/src/xm_internal.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xm_internal.c	Wed Nov 12 21:59:20 2008 +0000
@@ -529,7 +529,6 @@
  */
 int
 xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED,
-           xmlURIPtr uri ATTRIBUTE_UNUSED,
            virConnectAuthPtr auth ATTRIBUTE_UNUSED,
            int flags ATTRIBUTE_UNUSED)
 {
diff -r d97fa69e255b src/xm_internal.h
--- a/src/xm_internal.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xm_internal.h	Wed Nov 12 21:59:20 2008 +0000
@@ -32,7 +32,7 @@
 extern struct xenUnifiedDriver xenXMDriver;
 int xenXMInit (void);
 
-int xenXMOpen(virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags);
+int xenXMOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
 int xenXMClose(virConnectPtr conn);
 const char *xenXMGetType(virConnectPtr conn);
 int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
diff -r d97fa69e255b src/xs_internal.c
--- a/src/xs_internal.c	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xs_internal.c	Wed Nov 12 21:59:20 2008 +0000
@@ -276,7 +276,6 @@
  */
 int
 xenStoreOpen(virConnectPtr conn,
-             xmlURIPtr uri ATTRIBUTE_UNUSED,
              virConnectAuthPtr auth ATTRIBUTE_UNUSED,
              int flags ATTRIBUTE_UNUSED)
 {
diff -r d97fa69e255b src/xs_internal.h
--- a/src/xs_internal.h	Wed Nov 12 21:05:13 2008 +0000
+++ b/src/xs_internal.h	Wed Nov 12 21:59:20 2008 +0000
@@ -17,7 +17,6 @@
 int xenStoreInit (void);
 
 int		xenStoreOpen		(virConnectPtr conn,
-                                         xmlURIPtr uri,
                                          virConnectAuthPtr auth,
                                          int flags);
 int		xenStoreClose		(virConnectPtr conn);


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
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]