From 618276de19328a84124a88de2fa990854b00306c Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 17 Nov 2008 11:44:51 +0000 Subject: [PATCH] Push URI probing logic down into individual drivers --- ChangeLog | 22 ++ proxy/libvirt_proxy.c | 4 +- qemud/remote.c | 17 ++ qemud/remote_dispatch_localvars.h | 1 + qemud/remote_dispatch_proc_switch.h | 6 + qemud/remote_dispatch_prototypes.h | 1 + qemud/remote_protocol.c | 9 + qemud/remote_protocol.h | 8 + qemud/remote_protocol.x | 10 +- src/datatypes.c | 14 +- src/datatypes.h | 2 +- src/driver.h | 4 - src/libvirt.c | 111 ++++----- src/lxc_driver.c | 31 ++- src/network_driver.c | 1 - src/openvz_driver.c | 43 ++-- src/proxy_internal.c | 3 +- src/qemu_driver.c | 36 +-- src/remote_internal.c | 348 ++++++++++++++++------------ src/storage_driver.c | 1 - src/test.c | 37 +-- src/xen_internal.c | 1 - src/xen_internal.h | 1 - src/xen_unified.c | 42 ++-- src/xend_internal.c | 13 +- src/xend_internal.h | 2 +- src/xm_internal.c | 1 - src/xm_internal.h | 2 +- src/xs_internal.c | 1 - src/xs_internal.h | 1 - 30 files changed, 419 insertions(+), 354 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1f92a91c1..0496516b6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +Mon Nov 17 11:40:00 GMT 2008 Daniel Berrange + + Push URI probing down into individual drivers' open methods + * qemud/remote.c: Implement virConnectGetURI dispatcher + * qemud/remote_protocol.x: Add API definition for virConnectGetURI + * qemud/remote_dispatch_localvars.h, qemud/remote_dispatch_proc_switch.h, + qemud/remote_dispatch_prototypes.h, qemud/remote_protocol.c, + qemud/remote_protocol.h: Re-generate from protocol definition + * src/datatypes.c, src/datatypes.h: Store connection name as a + xmlURIPtr object instead of char * + * src/driver.h: Remove explicit URI parameter to open function + * src/libvirt.c: Delegrate URI probing into drivers + * src/lxc_driver.c, src/network_driver.c, src/openvz_driver.c, + src/proxy_internal.c, src/qemu_driver.c, src/remote_internal.c, + src/storage_driver.c, src/test.c, src/xen_internal.c, + src/xen_internal.h, src/xen_unified.c, src/xend_internal.c, + src/xend_internal.h, src/xm_internal.c, src/xm_internal.h, + src/xs_internal.c, src/xs_internal.h: Refactor open driver + methods to deal with automatic URI probing as required + * proxy/libvirt_proxy.c: Remove extra args to xs/xen driver + open calls + Mon Nov 17 11:19:00 GMT 2008 Daniel Berrange Refactor storage backend to remove dependancy from diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c index b9de42534d..3b0dc42d95 100644 --- a/proxy/libvirt_proxy.c +++ b/proxy/libvirt_proxy.c @@ -82,7 +82,7 @@ proxyInitXen(void) { 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 @@ proxyInitXen(void) { 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 --git a/qemud/remote.c b/qemud/remote.c index a3dd7ecba5..035c9e2314 100644 --- a/qemud/remote.c +++ b/qemud/remote.c @@ -550,6 +550,23 @@ remoteDispatchGetHostname (struct qemud_server *server ATTRIBUTE_UNUSED, 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; +} + static int remoteDispatchGetMaxVcpus (struct qemud_server *server ATTRIBUTE_UNUSED, struct qemud_client *client, diff --git a/qemud/remote_dispatch_localvars.h b/qemud/remote_dispatch_localvars.h index a669dd8e49..84134dfc89 100644 --- a/qemud/remote_dispatch_localvars.h +++ b/qemud/remote_dispatch_localvars.h @@ -142,6 +142,7 @@ remote_storage_vol_get_path_args lv_remote_storage_vol_get_path_args; 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 --git a/qemud/remote_dispatch_proc_switch.h b/qemud/remote_dispatch_proc_switch.h index 30193ef630..3c788a47de 100644 --- a/qemud/remote_dispatch_proc_switch.h +++ b/qemud/remote_dispatch_proc_switch.h @@ -407,6 +407,12 @@ case REMOTE_PROC_GET_TYPE: 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; ret_filter = (xdrproc_t) xdr_remote_get_version_ret; diff --git a/qemud/remote_dispatch_prototypes.h b/qemud/remote_dispatch_prototypes.h index e949ed9ea9..ae50416963 100644 --- a/qemud/remote_dispatch_prototypes.h +++ b/qemud/remote_dispatch_prototypes.h @@ -57,6 +57,7 @@ static int remoteDispatchGetCapabilities (struct qemud_server *server, struct qe 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 --git a/qemud/remote_protocol.c b/qemud/remote_protocol.c index 5ee58c1c49..5e573fe878 100644 --- a/qemud/remote_protocol.c +++ b/qemud/remote_protocol.c @@ -275,6 +275,15 @@ xdr_remote_get_hostname_ret (XDR *xdrs, remote_get_hostname_ret *objp) 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; +} + bool_t xdr_remote_get_max_vcpus_args (XDR *xdrs, remote_get_max_vcpus_args *objp) { diff --git a/qemud/remote_protocol.h b/qemud/remote_protocol.h index 52151166c6..a0e8a9df56 100644 --- a/qemud/remote_protocol.h +++ b/qemud/remote_protocol.h @@ -154,6 +154,11 @@ struct remote_get_hostname_ret { }; 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; }; @@ -1245,6 +1250,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENT = 107, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE2 = 108, REMOTE_PROC_DOMAIN_MIGRATE_FINISH2 = 109, + REMOTE_PROC_GET_URI = 110, }; typedef enum remote_procedure remote_procedure; @@ -1297,6 +1303,7 @@ extern bool_t xdr_remote_supports_feature_ret (XDR *, remote_supports_feature_r 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*); @@ -1485,6 +1492,7 @@ extern bool_t xdr_remote_supports_feature_ret (); 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 --git a/qemud/remote_protocol.x b/qemud/remote_protocol.x index 4190cce7d7..e337944a34 100644 --- a/qemud/remote_protocol.x +++ b/qemud/remote_protocol.x @@ -245,6 +245,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 { /* The only backend which supports this call is Xen HV, and * there the type is ignored so it could be NULL. @@ -1128,16 +1132,14 @@ enum remote_procedure { 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_MIGRATE_PREPARE2 = 108, - REMOTE_PROC_DOMAIN_MIGRATE_FINISH2 = 109 + REMOTE_PROC_DOMAIN_MIGRATE_FINISH2 = 109, + REMOTE_PROC_GET_URI = 110 }; /* Custom RPC structure. */ diff --git a/src/datatypes.c b/src/datatypes.c index e8cb5b445f..560154b86a 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -174,7 +174,7 @@ failed: */ 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 @@ virReleaseConnect(virConnectPtr conn) { 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 @@ virUnrefConnect(virConnectPtr conn) { 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 @@ virReleaseDomain(virDomainPtr domain) { 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 @@ virReleaseNetwork(virNetworkPtr network) { 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 @@ virReleaseStoragePool(virStoragePoolPtr pool) { 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 @@ virReleaseStorageVol(virStorageVolPtr vol) { 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 --git a/src/datatypes.h b/src/datatypes.h index 7bb4d92ed0..f06f41f639 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -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 --git a/src/driver.h b/src/driver.h index 013cad8b61..98a2763d0f 100644 --- a/src/driver.h +++ b/src/driver.h @@ -68,11 +68,8 @@ typedef enum { #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 @@ -329,7 +326,6 @@ struct _virDriver { 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 --git a/src/libvirt.c b/src/libvirt.c index 9c7e5a9e42..10e9142e08 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -685,8 +685,11 @@ do_open (const char *name, 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 @@ do_open (const char *name, 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); - } + name = NULL; } } - /* Convert xen -> xen:/// for back compat */ - if (STRCASEEQ(name, "xen")) - name = "xen:///"; + 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:///"; + /* 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; + ret->uri = xmlParseURI (name); + if (!ret->uri) { + virLibConnError (ret, VIR_ERR_INVALID_ARG, + _("could not parse connection URI")); + goto failed; + } - 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; + 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 @@ do_open (const char *name, 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 @@ do_open (const char *name, } 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 @@ do_open (const char *name, /* 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 @@ do_open (const char *name, } } - 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 @@ virConnectGetURI (virConnectPtr conn) 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 --git a/src/lxc_driver.c b/src/lxc_driver.c index fbfa60add5..4e7ae10efa 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -55,36 +55,34 @@ static lxc_driver_t *lxc_driver = NULL; /* 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 @@ static virDriver lxcDriver = { 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 --git a/src/network_driver.c b/src/network_driver.c index 0026606166..96d3ddf7ec 100644 --- a/src/network_driver.c +++ b/src/network_driver.c @@ -836,7 +836,6 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn ATTRIBUTE_UNUSED, } static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn, - xmlURIPtr uri ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { if (!driverState) diff --git a/src/openvz_driver.c b/src/openvz_driver.c index 95631eebac..6ea3557685 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -861,35 +861,33 @@ static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { 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 @@ static virDriver openvzDriver = { VIR_DRV_OPENVZ, "OPENVZ", LIBVIR_VERSION_NUMBER, - openvzProbe, /* probe */ openvzOpen, /* open */ openvzClose, /* close */ NULL, /* supports_feature */ diff --git a/src/proxy_internal.c b/src/proxy_internal.c index ca717f5dd7..2e801d9725 100644 --- a/src/proxy_internal.c +++ b/src/proxy_internal.c @@ -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 @@ retry: */ int xenProxyOpen(virConnectPtr conn, - xmlURIPtr uri ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags) { diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 47167b7249..9cf625d263 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -1153,22 +1153,17 @@ qemudMonitorCommand (const struct qemud_driver *driver ATTRIBUTE_UNUSED, * 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(); @@ -1176,18 +1171,28 @@ static virDrvOpenStatus qemudOpen(virConnectPtr conn, 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; } @@ -3625,7 +3630,6 @@ static virDriver qemuDriver = { VIR_DRV_QEMU, "QEMU", LIBVIR_VERSION_NUMBER, - qemudProbe, /* probe */ qemudOpen, /* open */ qemudClose, /* close */ qemudSupportsFeature, /* supports_feature */ diff --git a/src/remote_internal.c b/src/remote_internal.c index ffe80742db..9b85242c4a 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -273,46 +273,51 @@ enum virDrvOpenRemoteFlags { 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 = NULL; - char *transport_str = get_transport_from_scheme (uri->scheme); + if (conn->uri) { + if (!conn->uri->scheme) + return VIR_DRV_OPEN_DECLINED; - /* What transport? */ - enum { - trans_tls, - trans_unix, - trans_ssh, - trans_ext, - trans_tcp, - } transport; + 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 || 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) + 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 @@ doRemoteOpen (virConnectPtr conn, 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 @@ doRemoteOpen (virConnectPtr conn, 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 @@ doRemoteOpen (virConnectPtr conn, struct qparam *var; int i; char *query; -#ifdef HAVE_XMLURI_QUERY_RAW - query = 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); + if (conn->uri) { +#ifdef HAVE_XMLURI_QUERY_RAW + query = conn->uri->query_raw; +#else + 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 + .query_raw = qparam_get_query (vars), +#else + .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(""); } -#ifdef HAVE_XMLURI_QUERY_RAW - xmlFree (uri->query_raw); -#else - xmlFree (uri->query); -#endif + if (!name) { + error(conn, VIR_ERR_NO_MEMORY, NULL); + goto failed; + } -#ifdef HAVE_XMLURI_QUERY_RAW - uri->query_raw = -#else - uri->query = -#endif - qparam_get_query (vars); - - free_qparam_set (vars); + DEBUG("proceeding with name = %s", name); /* For ext transport, command is required. */ if (transport == trans_ext && !command) { @@ -432,28 +464,6 @@ doRemoteOpen (virConnectPtr conn, 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) { case trans_tls: @@ -702,6 +712,38 @@ doRemoteOpen (virConnectPtr conn, (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 @@ doRemoteOpen (virConnectPtr conn, static int remoteOpen (virConnectPtr conn, - xmlURIPtr uri, virConnectAuthPtr auth, int flags) { @@ -806,40 +847,54 @@ remoteOpen (virConnectPtr conn, 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; - } + /* + * 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; + } + + /* + * 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; + if (getuid() > 0) { + DEBUG0("Auto-spawn user daemon instance"); + 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, "/"))) { - rflags |= VIR_DRV_OPEN_REMOTE_UNIX; - } -#endif -#if WITH_LXC - if (uri && - uri->scheme && STREQ (uri->scheme, "lxc")) { - rflags |= VIR_DRV_OPEN_REMOTE_UNIX; - } -#endif 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); @@ -2553,7 +2608,6 @@ remoteDomainMemoryPeek (virDomainPtr domain, static int remoteNetworkOpen (virConnectPtr conn, - xmlURIPtr uri, virConnectAuthPtr auth, int flags) { @@ -2587,7 +2641,7 @@ remoteNetworkOpen (virConnectPtr conn, 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); @@ -2954,7 +3008,6 @@ remoteNetworkSetAutostart (virNetworkPtr network, int autostart) static int remoteStorageOpen (virConnectPtr conn, - xmlURIPtr uri, virConnectAuthPtr auth, int flags) { @@ -2993,7 +3046,7 @@ remoteStorageOpen (virConnectPtr conn, 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); @@ -5002,7 +5055,6 @@ static virDriver driver = { .no = VIR_DRV_REMOTE, .name = "remote", .ver = REMOTE_PROTOCOL_VERSION, - .probe = NULL, .open = remoteOpen, .close = remoteClose, .supports_feature = remoteSupportsFeature, diff --git a/src/storage_driver.c b/src/storage_driver.c index 6e7623882c..366820b623 100644 --- a/src/storage_driver.c +++ b/src/storage_driver.c @@ -294,7 +294,6 @@ storagePoolLookupByVolume(virStorageVolPtr vol) { static virDrvOpenStatus storageOpen(virConnectPtr conn, - xmlURIPtr uri ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { if (!driverState) diff --git a/src/test.c b/src/test.c index 11e57f6647..3648c05788 100644 --- a/src/test.c +++ b/src/test.c @@ -635,39 +635,38 @@ static int testOpenFromFile(virConnectPtr conn, 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); } @@ -713,19 +712,6 @@ static char *testGetHostname (virConnectPtr conn) 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, const char *type ATTRIBUTE_UNUSED) { @@ -1398,7 +1384,6 @@ static int testDomainSetSchedulerParams(virDomainPtr domain, } 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 int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { } 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 @@ static virDriver testDriver = { 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 --git a/src/xen_internal.c b/src/xen_internal.c index 04b41b4ac7..89081eaa66 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -2033,7 +2033,6 @@ xenHypervisorInit(void) */ int xenHypervisorOpen(virConnectPtr conn, - xmlURIPtr uri ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { diff --git a/src/xen_internal.h b/src/xen_internal.h index c00d4d8651..16b1495439 100644 --- a/src/xen_internal.h +++ b/src/xen_internal.h @@ -33,7 +33,6 @@ char * xenHypervisorDomainGetOSType (virDomainPtr dom); int xenHypervisorOpen (virConnectPtr conn, - xmlURIPtr uri, virConnectAuthPtr auth, int flags); int xenHypervisorClose (virConnectPtr conn); diff --git a/src/xen_unified.c b/src/xen_unified.c index dd3887580d..20c413abe9 100644 --- a/src/xen_unified.c +++ b/src/xen_unified.c @@ -200,34 +200,45 @@ done: * 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 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f * 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 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f /* 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 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f * 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 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f * 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 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f } 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 @@ static virDriver xenUnifiedDriver = { .no = VIR_DRV_XEN_UNIFIED, .name = "Xen", .ver = HV_VERSION, - .probe = xenUnifiedProbe, .open = xenUnifiedOpen, .close = xenUnifiedClose, .supports_feature = xenUnifiedSupportsFeature, diff --git a/src/xend_internal.c b/src/xend_internal.c index 6d2291b78e..55eaf94302 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -2706,7 +2706,6 @@ error: */ int xenDaemonOpen(virConnectPtr conn, - xmlURIPtr uri, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { @@ -2715,13 +2714,13 @@ xenDaemonOpen(virConnectPtr conn, /* 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 @@ xenDaemonOpen(virConnectPtr conn, 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 @@ xenDaemonOpen(virConnectPtr conn, 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 --git a/src/xend_internal.h b/src/xend_internal.h index a2515eed84..20645fb79f 100644 --- a/src/xend_internal.h +++ b/src/xend_internal.h @@ -129,7 +129,7 @@ xenDaemonFormatSxpr(virConnectPtr conn, /* 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 --git a/src/xm_internal.c b/src/xm_internal.c index c298888a9b..b899454853 100644 --- a/src/xm_internal.c +++ b/src/xm_internal.c @@ -529,7 +529,6 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) { */ int xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED, - xmlURIPtr uri ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { diff --git a/src/xm_internal.h b/src/xm_internal.h index 012a8fced6..e3cea00520 100644 --- a/src/xm_internal.h +++ b/src/xm_internal.h @@ -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 --git a/src/xs_internal.c b/src/xs_internal.c index b096acdeb2..f43a217e69 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -276,7 +276,6 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name) */ int xenStoreOpen(virConnectPtr conn, - xmlURIPtr uri ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { diff --git a/src/xs_internal.h b/src/xs_internal.h index 6163ebc80b..c3c402fe3e 100644 --- a/src/xs_internal.h +++ b/src/xs_internal.h @@ -17,7 +17,6 @@ extern struct xenUnifiedDriver xenStoreDriver; int xenStoreInit (void); int xenStoreOpen (virConnectPtr conn, - xmlURIPtr uri, virConnectAuthPtr auth, int flags); int xenStoreClose (virConnectPtr conn);