Wed Nov 14 11:36:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>

* src/libvirt.c and all internal driver interfaces: Parse the
	  URI only once and pass it to virDrvOpen instead of the
	  unparsed name string.
This commit is contained in:
Richard W.M. Jones 2007-11-14 11:40:57 +00:00
parent 5d25419188
commit 88f28d6980
18 changed files with 127 additions and 182 deletions

View File

@ -1,3 +1,9 @@
Wed Nov 14 11:36:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
* src/libvirt.c and all internal driver interfaces: Parse the
URI only once and pass it to virDrvOpen instead of the
unparsed name string.
Wed Nov 14 11:34:35 CET 2007 Jim Meyering <meyering@redhat.com> Wed Nov 14 11:34:35 CET 2007 Jim Meyering <meyering@redhat.com>
Parse integers more carefully, cont'd. Parse integers more carefully, cont'd.

View File

@ -9,6 +9,8 @@
#include "libvirt/libvirt.h" #include "libvirt/libvirt.h"
#include "libvirt/virterror.h" #include "libvirt/virterror.h"
#include <libxml/uri.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -74,7 +76,7 @@ typedef enum {
typedef virDrvOpenStatus typedef virDrvOpenStatus
(*virDrvOpen) (virConnectPtr conn, (*virDrvOpen) (virConnectPtr conn,
const char *name, xmlURIPtr uri,
int flags); int flags);
typedef int typedef int
(*virDrvClose) (virConnectPtr conn); (*virDrvClose) (virConnectPtr conn);

View File

@ -149,6 +149,7 @@ struct _virConnect {
virHashTablePtr domains;/* hash table for known domains */ virHashTablePtr domains;/* hash table for known domains */
virHashTablePtr networks;/* hash table for known domains */ virHashTablePtr networks;/* hash table for known domains */
int flags; /* a set of connection flags */ int flags; /* a set of connection flags */
char *name; /* connection URI */
}; };
/** /**

View File

@ -22,6 +22,7 @@
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/xpath.h> #include <libxml/xpath.h>
#include <libxml/uri.h>
#include "internal.h" #include "internal.h"
#include "driver.h" #include "driver.h"
@ -398,6 +399,7 @@ do_open (const char *name, int flags)
{ {
int i, res; int i, res;
virConnectPtr ret = NULL; virConnectPtr ret = NULL;
xmlURIPtr uri;
/* Convert NULL or "" to xen:/// for back compat */ /* Convert NULL or "" to xen:/// for back compat */
if (!name || name[0] == '\0') if (!name || name[0] == '\0')
@ -407,6 +409,12 @@ do_open (const char *name, int flags)
if (!strcasecmp(name, "xen")) if (!strcasecmp(name, "xen"))
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:///";
if (!initialized) if (!initialized)
if (virInitialize() < 0) if (virInitialize() < 0)
return NULL; return NULL;
@ -414,19 +422,43 @@ do_open (const char *name, int flags)
ret = virGetConnect(); ret = virGetConnect();
if (ret == NULL) { if (ret == NULL) {
virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection")); virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
return NULL;
}
uri = xmlParseURI (name);
if (!uri) {
virLibConnError (ret, VIR_ERR_INVALID_ARG,
_("could not parse connection URI"));
goto failed; goto failed;
} }
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
fprintf (stderr, "libvirt: do_open: proceeding with name=%s\n", name); fprintf (stderr,
"libvirt: do_open: 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);
#endif #endif
ret->name = strdup (name);
if (!ret->name) {
virLibConnError (ret, VIR_ERR_NO_MEMORY, "allocating conn->name");
goto failed;
}
for (i = 0; i < virDriverTabCount; i++) { for (i = 0; i < virDriverTabCount; i++) {
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
fprintf (stderr, "libvirt: do_open: trying driver %d (%s) ...\n", fprintf (stderr, "libvirt: do_open: trying driver %d (%s) ...\n",
i, virDriverTab[i]->name); i, virDriverTab[i]->name);
#endif #endif
res = virDriverTab[i]->open (ret, name, flags); res = virDriverTab[i]->open (ret, uri, flags);
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
fprintf (stderr, "libvirt: do_open: driver %d %s returned %s\n", fprintf (stderr, "libvirt: do_open: driver %d %s returned %s\n",
i, virDriverTab[i]->name, i, virDriverTab[i]->name,
@ -448,7 +480,7 @@ do_open (const char *name, int flags)
} }
for (i = 0; i < virNetworkDriverTabCount; i++) { for (i = 0; i < virNetworkDriverTabCount; i++) {
res = virNetworkDriverTab[i]->open (ret, name, flags); res = virNetworkDriverTab[i]->open (ret, uri, flags);
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
fprintf (stderr, "libvirt: do_open: network driver %d %s returned %s\n", fprintf (stderr, "libvirt: do_open: network driver %d %s returned %s\n",
i, virNetworkDriverTab[i]->name, i, virNetworkDriverTab[i]->name,
@ -472,12 +504,16 @@ do_open (const char *name, int flags)
ret->flags = VIR_CONNECT_RO; ret->flags = VIR_CONNECT_RO;
} }
xmlFreeURI (uri);
return ret; return ret;
failed: failed:
if (ret->name) free (ret->name);
if (ret->driver) ret->driver->close (ret); if (ret->driver) ret->driver->close (ret);
if (uri) xmlFreeURI(uri);
virFreeConnect(ret); virFreeConnect(ret);
return (NULL); return NULL;
} }
/** /**
@ -540,6 +576,8 @@ virConnectClose(virConnectPtr conn)
conn->networkDriver->close (conn); conn->networkDriver->close (conn);
conn->driver->close (conn); conn->driver->close (conn);
if (conn->name) free (conn->name);
if (virFreeConnect(conn) < 0) if (virFreeConnect(conn) < 0)
return (-1); return (-1);
return (0); return (0);
@ -670,6 +708,8 @@ virConnectGetHostname (virConnectPtr conn)
char * char *
virConnectGetURI (virConnectPtr conn) virConnectGetURI (virConnectPtr conn)
{ {
char *name;
DEBUG("conn=%p", conn); DEBUG("conn=%p", conn);
if (!VIR_IS_CONNECT(conn)) { if (!VIR_IS_CONNECT(conn)) {
@ -677,11 +717,18 @@ virConnectGetURI (virConnectPtr conn)
return NULL; return NULL;
} }
/* Drivers may override getURI, but if they don't then
* we provide a default implementation.
*/
if (conn->driver->getURI) if (conn->driver->getURI)
return conn->driver->getURI (conn); return conn->driver->getURI (conn);
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); name = strdup (conn->name);
if (!name) {
virLibConnError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
return NULL; return NULL;
}
return name;
} }
/** /**

View File

@ -29,7 +29,7 @@
static int debug = 0; static int debug = 0;
static int xenProxyClose(virConnectPtr conn); static int xenProxyClose(virConnectPtr conn);
static int xenProxyOpen(virConnectPtr conn, const char *name, int flags); static int xenProxyOpen(virConnectPtr conn, xmlURIPtr uri, int flags);
static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer); static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer);
static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info); static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
static char *xenProxyGetCapabilities(virConnectPtr conn); static char *xenProxyGetCapabilities(virConnectPtr conn);
@ -521,7 +521,7 @@ retry:
* Returns 0 in case of success, and -1 in case of failure * Returns 0 in case of success, and -1 in case of failure
*/ */
int int
xenProxyOpen(virConnectPtr conn, const char *name ATTRIBUTE_UNUSED, int flags) xenProxyOpen(virConnectPtr conn, xmlURIPtr uri ATTRIBUTE_UNUSED, int flags)
{ {
virProxyPacket req; virProxyPacket req;
int ret; int ret;

View File

@ -1383,15 +1383,13 @@ static int qemudMonitorCommand(struct qemud_driver *driver ATTRIBUTE_UNUSED,
static virDrvOpenStatus qemudOpen(virConnectPtr conn, static virDrvOpenStatus qemudOpen(virConnectPtr conn,
const char *name, xmlURIPtr uri,
int flags ATTRIBUTE_UNUSED) { int flags ATTRIBUTE_UNUSED) {
xmlURIPtr uri = NULL;
uid_t uid = getuid(); uid_t uid = getuid();
if (qemu_driver == NULL) if (qemu_driver == NULL)
return VIR_DRV_OPEN_DECLINED; goto decline;
uri = xmlParseURI(name);
if (uri == NULL || uri->scheme == NULL || uri->path == NULL) if (uri == NULL || uri->scheme == NULL || uri->path == NULL)
goto decline; goto decline;
@ -1409,12 +1407,9 @@ static virDrvOpenStatus qemudOpen(virConnectPtr conn,
conn->privateData = qemu_driver; conn->privateData = qemu_driver;
xmlFreeURI(uri);
return VIR_DRV_OPEN_SUCCESS; return VIR_DRV_OPEN_SUCCESS;
decline: decline:
if (uri != NULL)
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
} }
@ -2514,7 +2509,7 @@ static virNetworkPtr qemudNetworkLookupByName(virConnectPtr conn ATTRIBUTE_UNUSE
} }
static virDrvOpenStatus qemudOpenNetwork(virConnectPtr conn, static virDrvOpenStatus qemudOpenNetwork(virConnectPtr conn,
const char *name ATTRIBUTE_UNUSED, xmlURIPtr uri ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) { int flags ATTRIBUTE_UNUSED) {
if (!qemu_driver) if (!qemu_driver)
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
@ -2783,7 +2778,7 @@ static virDriver qemuDriver = {
qemudGetType, /* type */ qemudGetType, /* type */
qemudGetVersion, /* version */ qemudGetVersion, /* version */
qemudGetHostname, /* hostname */ qemudGetHostname, /* hostname */
NULL, /* URI - never called because remote_internal.c answers this */ NULL, /* URI */
qemudGetMaxVCPUs, /* getMaxVcpus */ qemudGetMaxVCPUs, /* getMaxVcpus */
qemudGetNodeInfo, /* nodeGetInfo */ qemudGetNodeInfo, /* nodeGetInfo */
qemudGetCapabilities, /* getCapabilities */ qemudGetCapabilities, /* getCapabilities */

View File

@ -69,7 +69,6 @@ struct private_data {
gnutls_session_t session; /* GnuTLS session (if uses_tls != 0). */ gnutls_session_t session; /* GnuTLS session (if uses_tls != 0). */
char *type; /* Cached return from remoteType. */ char *type; /* Cached return from remoteType. */
int counter; /* Generates serial numbers for RPC. */ int counter; /* Generates serial numbers for RPC. */
char *uri; /* Original (remote) URI. */
int networkOnly; /* Only used for network API */ int networkOnly; /* Only used for network API */
}; };
@ -251,15 +250,9 @@ enum virDrvOpenRemoteFlags {
}; };
static int static int
doRemoteOpen (virConnectPtr conn, struct private_data *priv, const char *uri_str, int flags) doRemoteOpen (virConnectPtr conn, struct private_data *priv,
xmlURIPtr uri, int flags)
{ {
if (!uri_str) return VIR_DRV_OPEN_DECLINED;
/* We have to parse the URL every time to discover whether
* it contains a transport or remote server name. There's no
* way to get around this.
*/
xmlURIPtr uri = xmlParseURI (uri_str);
if (!uri || !uri->scheme) if (!uri || !uri->scheme)
return VIR_DRV_OPEN_DECLINED; /* Decline - not a URL. */ return VIR_DRV_OPEN_DECLINED; /* Decline - not a URL. */
@ -656,13 +649,6 @@ doRemoteOpen (virConnectPtr conn, struct private_data *priv, const char *uri_str
(xdrproc_t) xdr_void, (char *) NULL) == -1) (xdrproc_t) xdr_void, (char *) NULL) == -1)
goto failed; goto failed;
/* Duplicate and save the uri_str. */
priv->uri = strdup (uri_str);
if (!priv->uri) {
error (NULL, VIR_ERR_NO_MEMORY, "allocating priv->uri");
goto failed;
}
/* Successful. */ /* Successful. */
retcode = VIR_DRV_OPEN_SUCCESS; retcode = VIR_DRV_OPEN_SUCCESS;
@ -684,7 +670,6 @@ doRemoteOpen (virConnectPtr conn, struct private_data *priv, const char *uri_str
} }
/* Free up the URL and strings. */ /* Free up the URL and strings. */
xmlFreeURI (uri);
if (name) free (name); if (name) free (name);
if (command) free (command); if (command) free (command);
if (sockname) free (sockname); if (sockname) free (sockname);
@ -705,7 +690,7 @@ doRemoteOpen (virConnectPtr conn, struct private_data *priv, const char *uri_str
} }
static int static int
remoteOpen (virConnectPtr conn, const char *uri_str, int flags) remoteOpen (virConnectPtr conn, xmlURIPtr uri, int flags)
{ {
struct private_data *priv; struct private_data *priv;
int ret, rflags = 0; int ret, rflags = 0;
@ -722,10 +707,13 @@ remoteOpen (virConnectPtr conn, const char *uri_str, int flags)
if (flags & VIR_DRV_OPEN_RO) if (flags & VIR_DRV_OPEN_RO)
rflags |= VIR_DRV_OPEN_REMOTE_RO; rflags |= VIR_DRV_OPEN_REMOTE_RO;
if (uri_str) { if (uri &&
if (STREQ (uri_str, "qemu:///system")) { uri->scheme && STREQ (uri->scheme, "qemu") &&
(!uri->server || STREQ (uri->server, "")) &&
uri->path) {
if (STREQ (uri->path, "/system")) {
rflags |= VIR_DRV_OPEN_REMOTE_UNIX; rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
} else if (STREQ (uri_str, "qemu:///session")) { } else if (STREQ (uri->path, "/session")) {
rflags |= VIR_DRV_OPEN_REMOTE_UNIX; rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
if (getuid() > 0) { if (getuid() > 0) {
rflags |= VIR_DRV_OPEN_REMOTE_USER; rflags |= VIR_DRV_OPEN_REMOTE_USER;
@ -737,7 +725,7 @@ remoteOpen (virConnectPtr conn, const char *uri_str, int flags)
memset(priv, 0, sizeof(struct private_data)); memset(priv, 0, sizeof(struct private_data));
priv->magic = DEAD; priv->magic = DEAD;
priv->sock = -1; priv->sock = -1;
ret = doRemoteOpen(conn, priv, uri_str, rflags); ret = doRemoteOpen(conn, priv, uri, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) { if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->privateData = NULL; conn->privateData = NULL;
free(priv); free(priv);
@ -1222,9 +1210,6 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
/* See comment for remoteType. */ /* See comment for remoteType. */
if (priv->type) free (priv->type); if (priv->type) free (priv->type);
/* Free URI copy. */
if (priv->uri) free (priv->uri);
/* Free private data. */ /* Free private data. */
priv->magic = DEAD; priv->magic = DEAD;
@ -1324,23 +1309,6 @@ remoteGetHostname (virConnectPtr conn)
return ret.hostname; return ret.hostname;
} }
/* This call is unusual because it doesn't go over RPC. The
* full URI is known (only) at the client end of the connection.
*/
static char *
remoteGetURI (virConnectPtr conn)
{
GET_PRIVATE (conn, NULL);
char *str;
str = strdup (priv->uri);
if (str == NULL) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
return NULL;
}
return str;
}
static int static int
remoteGetMaxVcpus (virConnectPtr conn, const char *type) remoteGetMaxVcpus (virConnectPtr conn, const char *type)
{ {
@ -2374,7 +2342,7 @@ remoteDomainInterfaceStats (virDomainPtr domain, const char *path,
static int static int
remoteNetworkOpen (virConnectPtr conn, remoteNetworkOpen (virConnectPtr conn,
const char *uri_str, xmlURIPtr uri,
int flags) int flags)
{ {
if (inside_daemon) if (inside_daemon)
@ -2408,7 +2376,7 @@ remoteNetworkOpen (virConnectPtr conn,
memset(priv, 0, sizeof(struct private_data)); memset(priv, 0, sizeof(struct private_data));
priv->magic = DEAD; priv->magic = DEAD;
priv->sock = -1; priv->sock = -1;
ret = doRemoteOpen(conn, priv, uri_str, rflags); ret = doRemoteOpen(conn, priv, uri, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) { if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->networkPrivateData = NULL; conn->networkPrivateData = NULL;
free(priv); free(priv);
@ -3124,7 +3092,6 @@ static virDriver driver = {
.type = remoteType, .type = remoteType,
.version = remoteVersion, .version = remoteVersion,
.getHostname = remoteGetHostname, .getHostname = remoteGetHostname,
.getURI = remoteGetURI,
.getMaxVcpus = remoteGetMaxVcpus, .getMaxVcpus = remoteGetMaxVcpus,
.nodeGetInfo = remoteNodeGetInfo, .nodeGetInfo = remoteNodeGetInfo,
.getCapabilities = remoteGetCapabilities, .getCapabilities = remoteGetCapabilities,

View File

@ -879,35 +879,23 @@ static int getNetworkIndex(virNetworkPtr network) {
} }
static int testOpen(virConnectPtr conn, static int testOpen(virConnectPtr conn,
const char *name, xmlURIPtr uri,
int flags ATTRIBUTE_UNUSED) int flags ATTRIBUTE_UNUSED)
{ {
xmlURIPtr uri;
int ret; int ret;
if (!name) if (!uri)
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
uri = xmlParseURI(name); if (!uri->scheme || strcmp(uri->scheme, "test") != 0)
if (uri == NULL) {
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
}
if (!uri->scheme || strcmp(uri->scheme, "test") != 0) {
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED;
}
/* Remote driver should handle these. */ /* Remote driver should handle these. */
if (uri->server) { if (uri->server)
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
}
if (uri->server) { if (uri->server)
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
}
/* From this point on, the connection is for us. */ /* From this point on, the connection is for us. */
if (!uri->path if (!uri->path
@ -924,8 +912,6 @@ static int testOpen(virConnectPtr conn,
ret = testOpenFromFile(conn, ret = testOpenFromFile(conn,
uri->path); uri->path);
xmlFreeURI(uri);
return (ret); return (ret);
} }
@ -1655,7 +1641,7 @@ static int testDomainSetSchedulerParams(virDomainPtr domain,
} }
static virDrvOpenStatus testOpenNetwork(virConnectPtr conn, static virDrvOpenStatus testOpenNetwork(virConnectPtr conn,
const char *name ATTRIBUTE_UNUSED, xmlURIPtr uri ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) { int flags ATTRIBUTE_UNUSED) {
if (STRNEQ(conn->driver->name, "Test")) if (STRNEQ(conn->driver->name, "Test"))
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;

View File

@ -2149,7 +2149,7 @@ xenHypervisorInit(void)
*/ */
int int
xenHypervisorOpen(virConnectPtr conn, xenHypervisorOpen(virConnectPtr conn,
const char *name ATTRIBUTE_UNUSED, xmlURIPtr uri ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) int flags ATTRIBUTE_UNUSED)
{ {
int ret; int ret;

View File

@ -30,7 +30,7 @@ char *
xenHypervisorDomainGetOSType (virDomainPtr dom); xenHypervisorDomainGetOSType (virDomainPtr dom);
int xenHypervisorOpen (virConnectPtr conn, int xenHypervisorOpen (virConnectPtr conn,
const char *name, xmlURIPtr uri,
int flags); int flags);
int xenHypervisorClose (virConnectPtr conn); int xenHypervisorClose (virConnectPtr conn);
int xenHypervisorGetVersion (virConnectPtr conn, int xenHypervisorGetVersion (virConnectPtr conn,

View File

@ -217,42 +217,28 @@ done:
*/ */
static int static int
xenUnifiedOpen (virConnectPtr conn, const char *name, int flags) xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, int flags)
{ {
int i, j; int i, j;
xenUnifiedPrivatePtr priv; xenUnifiedPrivatePtr priv;
xmlURIPtr uri;
uri = xmlParseURI(name);
if (uri == NULL) {
return VIR_DRV_OPEN_DECLINED;
}
/* Refuse any scheme which isn't "xen://" or "http://". */ /* Refuse any scheme which isn't "xen://" or "http://". */
if (uri->scheme && if (uri->scheme &&
strcasecmp(uri->scheme, "xen") != 0 && strcasecmp(uri->scheme, "xen") != 0 &&
strcasecmp(uri->scheme, "http") != 0) { strcasecmp(uri->scheme, "http") != 0)
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
}
/* xmlParseURI will parse a naked string like "foo" as a URI with /* xmlParseURI will parse a naked string like "foo" as a URI with
* a NULL scheme. That's not useful for us because we want to only * a NULL scheme. That's not useful for us because we want to only
* allow full pathnames (eg. ///var/lib/xen/xend-socket). Decline * allow full pathnames (eg. ///var/lib/xen/xend-socket). Decline
* anything else. * anything else.
*/ */
if (!uri->scheme && name[0] != '/') { if (!uri->scheme && (!uri->path || uri->path[0] != '/'))
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
}
/* Refuse any xen:// URI with a server specified - allow remote to do it */ /* Refuse any xen:// URI with a server specified - allow remote to do it */
if (uri->scheme && strcasecmp(uri->scheme, "xen") == 0 && uri->server) { if (uri->scheme && strcasecmp(uri->scheme, "xen") == 0 && uri->server)
xmlFreeURI(uri);
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
}
xmlFreeURI(uri);
/* Allocate per-connection private data. */ /* Allocate per-connection private data. */
priv = calloc (1, sizeof *priv); priv = calloc (1, sizeof *priv);
@ -262,13 +248,6 @@ xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
} }
conn->privateData = priv; conn->privateData = priv;
priv->name = strdup (name);
if (!priv->name) {
xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, "allocating priv->name");
free (priv);
return VIR_DRV_OPEN_ERROR;
}
priv->handle = -1; priv->handle = -1;
priv->xendConfigVersion = -1; priv->xendConfigVersion = -1;
priv->type = -1; priv->type = -1;
@ -293,7 +272,7 @@ xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
fprintf (stderr, "libvirt: xenUnifiedOpen: trying Xen sub-driver %d\n", i); fprintf (stderr, "libvirt: xenUnifiedOpen: trying Xen sub-driver %d\n", i);
#endif #endif
if (drivers[i]->open (conn, name, flags) == VIR_DRV_OPEN_SUCCESS) if (drivers[i]->open (conn, uri, flags) == VIR_DRV_OPEN_SUCCESS)
priv->opened[i] = 1; priv->opened[i] = 1;
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
fprintf (stderr, "libvirt: xenUnifiedOpen: Xen sub-driver %d open %s\n", fprintf (stderr, "libvirt: xenUnifiedOpen: Xen sub-driver %d open %s\n",
@ -307,7 +286,6 @@ xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
(getuid() == 0 || i == XEN_UNIFIED_PROXY_OFFSET)) { (getuid() == 0 || i == XEN_UNIFIED_PROXY_OFFSET)) {
for (j = 0; j < i; ++j) for (j = 0; j < i; ++j)
if (priv->opened[j]) drivers[j]->close (conn); if (priv->opened[j]) drivers[j]->close (conn);
free (priv->name);
free (priv); free (priv);
/* The assumption is that one of the underlying drivers /* The assumption is that one of the underlying drivers
* has set virterror already. * has set virterror already.
@ -332,7 +310,6 @@ xenUnifiedClose (virConnectPtr conn)
if (priv->opened[i] && drivers[i]->close) if (priv->opened[i] && drivers[i]->close)
(void) drivers[i]->close (conn); (void) drivers[i]->close (conn);
free (priv->name);
free (conn->privateData); free (conn->privateData);
conn->privateData = NULL; conn->privateData = NULL;
@ -402,21 +379,6 @@ xenUnifiedGetHostname (virConnectPtr conn)
return str; return str;
} }
/* The name is recorded (canonicalised) in xenUnifiedOpen. */
static char *
xenUnifiedGetURI (virConnectPtr conn)
{
GET_PRIVATE(conn);
char *str;
str = strdup (priv->name);
if (str == NULL) {
xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
return NULL;
}
return str;
}
static int static int
xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type) xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type)
{ {
@ -1249,7 +1211,6 @@ static virDriver xenUnifiedDriver = {
.type = xenUnifiedType, .type = xenUnifiedType,
.version = xenUnifiedVersion, .version = xenUnifiedVersion,
.getHostname = xenUnifiedGetHostname, .getHostname = xenUnifiedGetHostname,
.getURI = xenUnifiedGetURI,
.getMaxVcpus = xenUnifiedGetMaxVcpus, .getMaxVcpus = xenUnifiedGetMaxVcpus,
.nodeGetInfo = xenUnifiedNodeGetInfo, .nodeGetInfo = xenUnifiedNodeGetInfo,
.getCapabilities = xenUnifiedGetCapabilities, .getCapabilities = xenUnifiedGetCapabilities,

View File

@ -108,9 +108,6 @@ struct _xenUnifiedPrivate {
* xen_unified.c. * xen_unified.c.
*/ */
int opened[XEN_UNIFIED_NR_DRIVERS]; int opened[XEN_UNIFIED_NR_DRIVERS];
/* Canonical URI. */
char *name;
}; };
typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr; typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;

View File

@ -2037,18 +2037,29 @@ error:
* Returns 0 in case of success, -1 in case of error. * Returns 0 in case of success, -1 in case of error.
*/ */
int int
xenDaemonOpen(virConnectPtr conn, const char *name, xenDaemonOpen(virConnectPtr conn, xmlURIPtr uri,
int flags ATTRIBUTE_UNUSED) int flags ATTRIBUTE_UNUSED)
{ {
xmlURIPtr uri = NULL;
int ret; int ret;
/* If the name is just "xen" (it might originally have been NULL, /* Switch on the scheme, which we expect to be NULL (file),
* see xenUnifiedOpen) or any URI beginning with "xen:///" then * "http" or "xen".
* try default paths and methods to get to the xend socket.
*/ */
if (strcasecmp (name, "xen") == 0 || if (uri->scheme == NULL) {
strncasecmp (name, "xen:///", 7) == 0) { /* It should be a file access */
if (uri->path == NULL) {
virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
goto failed;
}
ret = xenDaemonOpen_unix(conn, uri->path);
if (ret < 0)
goto failed;
ret = xend_detect_config_version(conn);
if (ret == -1)
goto failed;
}
else if (STRCASEEQ (uri->scheme, "xen")) {
/* /*
* try first to open the unix socket * try first to open the unix socket
*/ */
@ -2069,30 +2080,7 @@ xenDaemonOpen(virConnectPtr conn, const char *name,
ret = xend_detect_config_version(conn); ret = xend_detect_config_version(conn);
if (ret == -1) if (ret == -1)
goto failed; goto failed;
} else { } else if (STRCASEEQ (uri->scheme, "http")) {
/*
* We were given a connection name, expected to be an URL
*/
uri = xmlParseURI(name);
if (uri == NULL) {
virXendError(NULL, VIR_ERR_NO_CONNECT, name);
goto failed;
}
if (uri->scheme == NULL) {
/* It should be a file access */
if (uri->path == NULL) {
virXendError(NULL, VIR_ERR_NO_CONNECT, name);
goto failed;
}
ret = xenDaemonOpen_unix(conn, uri->path);
if (ret < 0)
goto failed;
ret = xend_detect_config_version(conn);
if (ret == -1)
goto failed;
} else if (!strcasecmp(uri->scheme, "http")) {
ret = xenDaemonOpen_tcp(conn, uri->server, uri->port); ret = xenDaemonOpen_tcp(conn, uri->server, uri->port);
if (ret < 0) if (ret < 0)
goto failed; goto failed;
@ -2100,19 +2088,14 @@ xenDaemonOpen(virConnectPtr conn, const char *name,
if (ret == -1) if (ret == -1)
goto failed; goto failed;
} else { } else {
virXendError(NULL, VIR_ERR_NO_CONNECT, name); virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
goto failed; goto failed;
} }
}
done: done:
if (uri != NULL)
xmlFreeURI(uri);
return(ret); return(ret);
failed: failed:
if (uri != NULL)
xmlFreeURI(uri);
return(-1); return(-1);
} }

View File

@ -183,7 +183,7 @@ char *xenDaemonDomainDumpXMLByName(virConnectPtr xend,
char *xend_parse_domain_sexp(virConnectPtr conn, char *root, int xendConfigVersion); char *xend_parse_domain_sexp(virConnectPtr conn, char *root, int xendConfigVersion);
/* refactored ones */ /* refactored ones */
int xenDaemonOpen(virConnectPtr conn, const char *name, int flags); int xenDaemonOpen(virConnectPtr conn, xmlURIPtr uri, int flags);
int xenDaemonClose(virConnectPtr conn); int xenDaemonClose(virConnectPtr conn);
int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer); int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info); int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);

View File

@ -470,7 +470,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
*/ */
int int
xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED, xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED,
const char *name ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) xmlURIPtr uri ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED)
{ {
if (configCache == NULL) { if (configCache == NULL) {
configCache = virHashCreate(50); configCache = virHashCreate(50);

View File

@ -36,7 +36,7 @@ extern "C" {
extern struct xenUnifiedDriver xenXMDriver; extern struct xenUnifiedDriver xenXMDriver;
int xenXMInit (void); int xenXMInit (void);
int xenXMOpen(virConnectPtr conn, const char *name, int flags); int xenXMOpen(virConnectPtr conn, xmlURIPtr uri, int flags);
int xenXMClose(virConnectPtr conn); int xenXMClose(virConnectPtr conn);
const char *xenXMGetType(virConnectPtr conn); const char *xenXMGetType(virConnectPtr conn);
int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info); int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);

View File

@ -326,7 +326,7 @@ virConnectCheckStoreID(virConnectPtr conn, int id)
*/ */
int int
xenStoreOpen(virConnectPtr conn, xenStoreOpen(virConnectPtr conn,
const char *name ATTRIBUTE_UNUSED, xmlURIPtr uri ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) int flags ATTRIBUTE_UNUSED)
{ {
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;

View File

@ -21,7 +21,7 @@ extern struct xenUnifiedDriver xenStoreDriver;
int xenStoreInit (void); int xenStoreInit (void);
int xenStoreOpen (virConnectPtr conn, int xenStoreOpen (virConnectPtr conn,
const char *name, xmlURIPtr uri,
int flags); int flags);
int xenStoreClose (virConnectPtr conn); int xenStoreClose (virConnectPtr conn);
int xenStoreGetDomainInfo (virDomainPtr domain, int xenStoreGetDomainInfo (virDomainPtr domain,