mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
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:
parent
5d25419188
commit
88f28d6980
@ -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>
|
||||
|
||||
Parse integers more carefully, cont'd.
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "libvirt/libvirt.h"
|
||||
#include "libvirt/virterror.h"
|
||||
|
||||
#include <libxml/uri.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -74,7 +76,7 @@ typedef enum {
|
||||
|
||||
typedef virDrvOpenStatus
|
||||
(*virDrvOpen) (virConnectPtr conn,
|
||||
const char *name,
|
||||
xmlURIPtr uri,
|
||||
int flags);
|
||||
typedef int
|
||||
(*virDrvClose) (virConnectPtr conn);
|
||||
|
@ -149,6 +149,7 @@ struct _virConnect {
|
||||
virHashTablePtr domains;/* hash table for known domains */
|
||||
virHashTablePtr networks;/* hash table for known domains */
|
||||
int flags; /* a set of connection flags */
|
||||
char *name; /* connection URI */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/uri.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "driver.h"
|
||||
@ -398,6 +399,7 @@ do_open (const char *name, int flags)
|
||||
{
|
||||
int i, res;
|
||||
virConnectPtr ret = NULL;
|
||||
xmlURIPtr uri;
|
||||
|
||||
/* Convert NULL or "" to xen:/// for back compat */
|
||||
if (!name || name[0] == '\0')
|
||||
@ -407,6 +409,12 @@ do_open (const char *name, int flags)
|
||||
if (!strcasecmp(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 (virInitialize() < 0)
|
||||
return NULL;
|
||||
@ -414,19 +422,43 @@ do_open (const char *name, int flags)
|
||||
ret = virGetConnect();
|
||||
if (ret == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
ret->name = strdup (name);
|
||||
if (!ret->name) {
|
||||
virLibConnError (ret, VIR_ERR_NO_MEMORY, "allocating conn->name");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
for (i = 0; i < virDriverTabCount; i++) {
|
||||
#ifdef ENABLE_DEBUG
|
||||
fprintf (stderr, "libvirt: do_open: trying driver %d (%s) ...\n",
|
||||
i, virDriverTab[i]->name);
|
||||
#endif
|
||||
res = virDriverTab[i]->open (ret, name, flags);
|
||||
res = virDriverTab[i]->open (ret, uri, flags);
|
||||
#ifdef ENABLE_DEBUG
|
||||
fprintf (stderr, "libvirt: do_open: driver %d %s returned %s\n",
|
||||
i, virDriverTab[i]->name,
|
||||
@ -448,7 +480,7 @@ do_open (const char *name, int flags)
|
||||
}
|
||||
|
||||
for (i = 0; i < virNetworkDriverTabCount; i++) {
|
||||
res = virNetworkDriverTab[i]->open (ret, name, flags);
|
||||
res = virNetworkDriverTab[i]->open (ret, uri, flags);
|
||||
#ifdef ENABLE_DEBUG
|
||||
fprintf (stderr, "libvirt: do_open: network driver %d %s returned %s\n",
|
||||
i, virNetworkDriverTab[i]->name,
|
||||
@ -472,12 +504,16 @@ do_open (const char *name, int flags)
|
||||
ret->flags = VIR_CONNECT_RO;
|
||||
}
|
||||
|
||||
xmlFreeURI (uri);
|
||||
|
||||
return ret;
|
||||
|
||||
failed:
|
||||
if (ret->name) free (ret->name);
|
||||
if (ret->driver) ret->driver->close (ret);
|
||||
if (uri) xmlFreeURI(uri);
|
||||
virFreeConnect(ret);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -540,6 +576,8 @@ virConnectClose(virConnectPtr conn)
|
||||
conn->networkDriver->close (conn);
|
||||
conn->driver->close (conn);
|
||||
|
||||
if (conn->name) free (conn->name);
|
||||
|
||||
if (virFreeConnect(conn) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
@ -670,6 +708,8 @@ virConnectGetHostname (virConnectPtr conn)
|
||||
char *
|
||||
virConnectGetURI (virConnectPtr conn)
|
||||
{
|
||||
char *name;
|
||||
|
||||
DEBUG("conn=%p", conn);
|
||||
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
@ -677,11 +717,18 @@ virConnectGetURI (virConnectPtr conn)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Drivers may override getURI, but if they don't then
|
||||
* we provide a default implementation.
|
||||
*/
|
||||
if (conn->driver->getURI)
|
||||
return conn->driver->getURI (conn);
|
||||
|
||||
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
||||
return NULL;
|
||||
name = strdup (conn->name);
|
||||
if (!name) {
|
||||
virLibConnError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@
|
||||
static int debug = 0;
|
||||
|
||||
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 xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
|
||||
static char *xenProxyGetCapabilities(virConnectPtr conn);
|
||||
@ -521,7 +521,7 @@ retry:
|
||||
* Returns 0 in case of success, and -1 in case of failure
|
||||
*/
|
||||
int
|
||||
xenProxyOpen(virConnectPtr conn, const char *name ATTRIBUTE_UNUSED, int flags)
|
||||
xenProxyOpen(virConnectPtr conn, xmlURIPtr uri ATTRIBUTE_UNUSED, int flags)
|
||||
{
|
||||
virProxyPacket req;
|
||||
int ret;
|
||||
|
@ -1383,15 +1383,13 @@ static int qemudMonitorCommand(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
||||
|
||||
|
||||
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
||||
const char *name,
|
||||
xmlURIPtr uri,
|
||||
int flags ATTRIBUTE_UNUSED) {
|
||||
xmlURIPtr uri = NULL;
|
||||
uid_t uid = getuid();
|
||||
|
||||
if (qemu_driver == NULL)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
goto decline;
|
||||
|
||||
uri = xmlParseURI(name);
|
||||
if (uri == NULL || uri->scheme == NULL || uri->path == NULL)
|
||||
goto decline;
|
||||
|
||||
@ -1409,12 +1407,9 @@ static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
||||
|
||||
conn->privateData = qemu_driver;
|
||||
|
||||
xmlFreeURI(uri);
|
||||
return VIR_DRV_OPEN_SUCCESS;
|
||||
|
||||
decline:
|
||||
if (uri != NULL)
|
||||
xmlFreeURI(uri);
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
@ -2514,7 +2509,7 @@ static virNetworkPtr qemudNetworkLookupByName(virConnectPtr conn ATTRIBUTE_UNUSE
|
||||
}
|
||||
|
||||
static virDrvOpenStatus qemudOpenNetwork(virConnectPtr conn,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
xmlURIPtr uri ATTRIBUTE_UNUSED,
|
||||
int flags ATTRIBUTE_UNUSED) {
|
||||
if (!qemu_driver)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
@ -2783,7 +2778,7 @@ static virDriver qemuDriver = {
|
||||
qemudGetType, /* type */
|
||||
qemudGetVersion, /* version */
|
||||
qemudGetHostname, /* hostname */
|
||||
NULL, /* URI - never called because remote_internal.c answers this */
|
||||
NULL, /* URI */
|
||||
qemudGetMaxVCPUs, /* getMaxVcpus */
|
||||
qemudGetNodeInfo, /* nodeGetInfo */
|
||||
qemudGetCapabilities, /* getCapabilities */
|
||||
|
@ -69,7 +69,6 @@ struct private_data {
|
||||
gnutls_session_t session; /* GnuTLS session (if uses_tls != 0). */
|
||||
char *type; /* Cached return from remoteType. */
|
||||
int counter; /* Generates serial numbers for RPC. */
|
||||
char *uri; /* Original (remote) URI. */
|
||||
int networkOnly; /* Only used for network API */
|
||||
};
|
||||
|
||||
@ -251,15 +250,9 @@ enum virDrvOpenRemoteFlags {
|
||||
};
|
||||
|
||||
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)
|
||||
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)
|
||||
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. */
|
||||
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. */
|
||||
xmlFreeURI (uri);
|
||||
if (name) free (name);
|
||||
if (command) free (command);
|
||||
if (sockname) free (sockname);
|
||||
@ -705,7 +690,7 @@ doRemoteOpen (virConnectPtr conn, struct private_data *priv, const char *uri_str
|
||||
}
|
||||
|
||||
static int
|
||||
remoteOpen (virConnectPtr conn, const char *uri_str, int flags)
|
||||
remoteOpen (virConnectPtr conn, xmlURIPtr uri, int flags)
|
||||
{
|
||||
struct private_data *priv;
|
||||
int ret, rflags = 0;
|
||||
@ -722,10 +707,13 @@ remoteOpen (virConnectPtr conn, const char *uri_str, int flags)
|
||||
if (flags & VIR_DRV_OPEN_RO)
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_RO;
|
||||
|
||||
if (uri_str) {
|
||||
if (STREQ (uri_str, "qemu:///system")) {
|
||||
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_str, "qemu:///session")) {
|
||||
} else if (STREQ (uri->path, "/session")) {
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
|
||||
if (getuid() > 0) {
|
||||
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));
|
||||
priv->magic = DEAD;
|
||||
priv->sock = -1;
|
||||
ret = doRemoteOpen(conn, priv, uri_str, rflags);
|
||||
ret = doRemoteOpen(conn, priv, uri, rflags);
|
||||
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
||||
conn->privateData = NULL;
|
||||
free(priv);
|
||||
@ -1222,9 +1210,6 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
|
||||
/* See comment for remoteType. */
|
||||
if (priv->type) free (priv->type);
|
||||
|
||||
/* Free URI copy. */
|
||||
if (priv->uri) free (priv->uri);
|
||||
|
||||
/* Free private data. */
|
||||
priv->magic = DEAD;
|
||||
|
||||
@ -1324,23 +1309,6 @@ remoteGetHostname (virConnectPtr conn)
|
||||
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
|
||||
remoteGetMaxVcpus (virConnectPtr conn, const char *type)
|
||||
{
|
||||
@ -2374,7 +2342,7 @@ remoteDomainInterfaceStats (virDomainPtr domain, const char *path,
|
||||
|
||||
static int
|
||||
remoteNetworkOpen (virConnectPtr conn,
|
||||
const char *uri_str,
|
||||
xmlURIPtr uri,
|
||||
int flags)
|
||||
{
|
||||
if (inside_daemon)
|
||||
@ -2408,7 +2376,7 @@ remoteNetworkOpen (virConnectPtr conn,
|
||||
memset(priv, 0, sizeof(struct private_data));
|
||||
priv->magic = DEAD;
|
||||
priv->sock = -1;
|
||||
ret = doRemoteOpen(conn, priv, uri_str, rflags);
|
||||
ret = doRemoteOpen(conn, priv, uri, rflags);
|
||||
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
||||
conn->networkPrivateData = NULL;
|
||||
free(priv);
|
||||
@ -3124,7 +3092,6 @@ static virDriver driver = {
|
||||
.type = remoteType,
|
||||
.version = remoteVersion,
|
||||
.getHostname = remoteGetHostname,
|
||||
.getURI = remoteGetURI,
|
||||
.getMaxVcpus = remoteGetMaxVcpus,
|
||||
.nodeGetInfo = remoteNodeGetInfo,
|
||||
.getCapabilities = remoteGetCapabilities,
|
||||
|
26
src/test.c
26
src/test.c
@ -879,35 +879,23 @@ static int getNetworkIndex(virNetworkPtr network) {
|
||||
}
|
||||
|
||||
static int testOpen(virConnectPtr conn,
|
||||
const char *name,
|
||||
xmlURIPtr uri,
|
||||
int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
xmlURIPtr uri;
|
||||
int ret;
|
||||
|
||||
if (!name)
|
||||
if (!uri)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
uri = xmlParseURI(name);
|
||||
if (uri == NULL) {
|
||||
if (!uri->scheme || strcmp(uri->scheme, "test") != 0)
|
||||
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. */
|
||||
if (uri->server) {
|
||||
xmlFreeURI(uri);
|
||||
if (uri->server)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
if (uri->server) {
|
||||
xmlFreeURI(uri);
|
||||
if (uri->server)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
/* From this point on, the connection is for us. */
|
||||
if (!uri->path
|
||||
@ -924,8 +912,6 @@ static int testOpen(virConnectPtr conn,
|
||||
ret = testOpenFromFile(conn,
|
||||
uri->path);
|
||||
|
||||
xmlFreeURI(uri);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@ -1655,7 +1641,7 @@ static int testDomainSetSchedulerParams(virDomainPtr domain,
|
||||
}
|
||||
|
||||
static virDrvOpenStatus testOpenNetwork(virConnectPtr conn,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
xmlURIPtr uri ATTRIBUTE_UNUSED,
|
||||
int flags ATTRIBUTE_UNUSED) {
|
||||
if (STRNEQ(conn->driver->name, "Test"))
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
@ -2149,7 +2149,7 @@ xenHypervisorInit(void)
|
||||
*/
|
||||
int
|
||||
xenHypervisorOpen(virConnectPtr conn,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
xmlURIPtr uri ATTRIBUTE_UNUSED,
|
||||
int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int ret;
|
||||
|
@ -30,7 +30,7 @@ char *
|
||||
xenHypervisorDomainGetOSType (virDomainPtr dom);
|
||||
|
||||
int xenHypervisorOpen (virConnectPtr conn,
|
||||
const char *name,
|
||||
xmlURIPtr uri,
|
||||
int flags);
|
||||
int xenHypervisorClose (virConnectPtr conn);
|
||||
int xenHypervisorGetVersion (virConnectPtr conn,
|
||||
|
@ -217,42 +217,28 @@ done:
|
||||
*/
|
||||
|
||||
static int
|
||||
xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
|
||||
xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, int flags)
|
||||
{
|
||||
int i, j;
|
||||
xenUnifiedPrivatePtr priv;
|
||||
xmlURIPtr uri;
|
||||
|
||||
uri = xmlParseURI(name);
|
||||
if (uri == NULL) {
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
/* Refuse any scheme which isn't "xen://" or "http://". */
|
||||
if (uri->scheme &&
|
||||
strcasecmp(uri->scheme, "xen") != 0 &&
|
||||
strcasecmp(uri->scheme, "http") != 0) {
|
||||
xmlFreeURI(uri);
|
||||
strcasecmp(uri->scheme, "http") != 0)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
/* 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
|
||||
* allow full pathnames (eg. ///var/lib/xen/xend-socket). Decline
|
||||
* anything else.
|
||||
*/
|
||||
if (!uri->scheme && name[0] != '/') {
|
||||
xmlFreeURI(uri);
|
||||
if (!uri->scheme && (!uri->path || uri->path[0] != '/'))
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
/* Refuse any xen:// URI with a server specified - allow remote to do it */
|
||||
if (uri->scheme && strcasecmp(uri->scheme, "xen") == 0 && uri->server) {
|
||||
xmlFreeURI(uri);
|
||||
if (uri->scheme && strcasecmp(uri->scheme, "xen") == 0 && uri->server)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
}
|
||||
|
||||
xmlFreeURI(uri);
|
||||
|
||||
/* Allocate per-connection private data. */
|
||||
priv = calloc (1, sizeof *priv);
|
||||
@ -262,13 +248,6 @@ xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
|
||||
}
|
||||
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->xendConfigVersion = -1;
|
||||
priv->type = -1;
|
||||
@ -293,7 +272,7 @@ xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
|
||||
#ifdef ENABLE_DEBUG
|
||||
fprintf (stderr, "libvirt: xenUnifiedOpen: trying Xen sub-driver %d\n", i);
|
||||
#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;
|
||||
#ifdef ENABLE_DEBUG
|
||||
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)) {
|
||||
for (j = 0; j < i; ++j)
|
||||
if (priv->opened[j]) drivers[j]->close (conn);
|
||||
free (priv->name);
|
||||
free (priv);
|
||||
/* The assumption is that one of the underlying drivers
|
||||
* has set virterror already.
|
||||
@ -332,7 +310,6 @@ xenUnifiedClose (virConnectPtr conn)
|
||||
if (priv->opened[i] && drivers[i]->close)
|
||||
(void) drivers[i]->close (conn);
|
||||
|
||||
free (priv->name);
|
||||
free (conn->privateData);
|
||||
conn->privateData = NULL;
|
||||
|
||||
@ -402,21 +379,6 @@ xenUnifiedGetHostname (virConnectPtr conn)
|
||||
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
|
||||
xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type)
|
||||
{
|
||||
@ -1249,7 +1211,6 @@ static virDriver xenUnifiedDriver = {
|
||||
.type = xenUnifiedType,
|
||||
.version = xenUnifiedVersion,
|
||||
.getHostname = xenUnifiedGetHostname,
|
||||
.getURI = xenUnifiedGetURI,
|
||||
.getMaxVcpus = xenUnifiedGetMaxVcpus,
|
||||
.nodeGetInfo = xenUnifiedNodeGetInfo,
|
||||
.getCapabilities = xenUnifiedGetCapabilities,
|
||||
|
@ -108,9 +108,6 @@ struct _xenUnifiedPrivate {
|
||||
* xen_unified.c.
|
||||
*/
|
||||
int opened[XEN_UNIFIED_NR_DRIVERS];
|
||||
|
||||
/* Canonical URI. */
|
||||
char *name;
|
||||
};
|
||||
|
||||
typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;
|
||||
|
@ -2037,18 +2037,29 @@ error:
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenDaemonOpen(virConnectPtr conn, const char *name,
|
||||
xenDaemonOpen(virConnectPtr conn, xmlURIPtr uri,
|
||||
int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
xmlURIPtr uri = NULL;
|
||||
int ret;
|
||||
|
||||
/* If the name is just "xen" (it might originally have been NULL,
|
||||
* see xenUnifiedOpen) or any URI beginning with "xen:///" then
|
||||
* try default paths and methods to get to the xend socket.
|
||||
|
||||
/* Switch on the scheme, which we expect to be NULL (file),
|
||||
* "http" or "xen".
|
||||
*/
|
||||
if (strcasecmp (name, "xen") == 0 ||
|
||||
strncasecmp (name, "xen:///", 7) == 0) {
|
||||
if (uri->scheme == NULL) {
|
||||
/* 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
|
||||
*/
|
||||
@ -2069,50 +2080,22 @@ xenDaemonOpen(virConnectPtr conn, const char *name,
|
||||
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);
|
||||
if (ret < 0)
|
||||
goto failed;
|
||||
ret = xend_detect_config_version(conn);
|
||||
if (ret == -1)
|
||||
goto failed;
|
||||
} else {
|
||||
/*
|
||||
* 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);
|
||||
if (ret < 0)
|
||||
goto failed;
|
||||
ret = xend_detect_config_version(conn);
|
||||
if (ret == -1)
|
||||
goto failed;
|
||||
} else {
|
||||
virXendError(NULL, VIR_ERR_NO_CONNECT, name);
|
||||
goto failed;
|
||||
}
|
||||
virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
done:
|
||||
if (uri != NULL)
|
||||
xmlFreeURI(uri);
|
||||
return(ret);
|
||||
|
||||
failed:
|
||||
if (uri != NULL)
|
||||
xmlFreeURI(uri);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ char *xenDaemonDomainDumpXMLByName(virConnectPtr xend,
|
||||
char *xend_parse_domain_sexp(virConnectPtr conn, char *root, int xendConfigVersion);
|
||||
|
||||
/* refactored ones */
|
||||
int xenDaemonOpen(virConnectPtr conn, const char *name, int flags);
|
||||
int xenDaemonOpen(virConnectPtr conn, xmlURIPtr uri, int flags);
|
||||
int xenDaemonClose(virConnectPtr conn);
|
||||
int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
|
||||
int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
|
||||
|
@ -470,7 +470,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
|
||||
*/
|
||||
int
|
||||
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) {
|
||||
configCache = virHashCreate(50);
|
||||
|
@ -36,7 +36,7 @@ extern "C" {
|
||||
extern struct xenUnifiedDriver xenXMDriver;
|
||||
int xenXMInit (void);
|
||||
|
||||
int xenXMOpen(virConnectPtr conn, const char *name, int flags);
|
||||
int xenXMOpen(virConnectPtr conn, xmlURIPtr uri, int flags);
|
||||
int xenXMClose(virConnectPtr conn);
|
||||
const char *xenXMGetType(virConnectPtr conn);
|
||||
int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
|
||||
|
@ -326,7 +326,7 @@ virConnectCheckStoreID(virConnectPtr conn, int id)
|
||||
*/
|
||||
int
|
||||
xenStoreOpen(virConnectPtr conn,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
xmlURIPtr uri ATTRIBUTE_UNUSED,
|
||||
int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
|
||||
|
@ -21,7 +21,7 @@ extern struct xenUnifiedDriver xenStoreDriver;
|
||||
int xenStoreInit (void);
|
||||
|
||||
int xenStoreOpen (virConnectPtr conn,
|
||||
const char *name,
|
||||
xmlURIPtr uri,
|
||||
int flags);
|
||||
int xenStoreClose (virConnectPtr conn);
|
||||
int xenStoreGetDomainInfo (virDomainPtr domain,
|
||||
|
Loading…
Reference in New Issue
Block a user