On Tue, Jun 19, 2007 at 05:15:40PM +0100, Richard W.M. Jones wrote: > The attached one-liner adds a xen:/// URI, intended as the normal method > to connect to the Xen hypervisor on the local machine. This is just a > placeholder until I can get around to rewriting the Xen name parsing > code in xen_unified.c. This patch makes local (xen:///) and remote > (xen://hostname/) Xen URI-style calls possible and hopefully doesn't > prevent logical extensions to the Xen URI syntax from being added in future. > > Also, I couldn't get file path URIs to work as they seem to be intended, > but I haven't looked very closely yet: > > $ virsh -c ///var/lib/xend/xend-socket list > libvir: error : no support for hypervisor > virsh: error: failed to connect to the hypervisor This is because those URIs are declined by the xen_unified.c open method before they get anywhere near xend_internal.c I'm attaching a patch which addresses this, making xen_unified.c convert any NULL, 'xen', 'Xen' uri into xen:/// before passing it onto the other Xen drivers. This should make Rich's initial patch redundant. It also explicitly allows through any URI starting with / or http:// as back compat for Xen. Finally, it moves the remote driver to be the last one registered, and ensures the Xen & test drivers explicitly decline any URI with a hostname specified, so that they get passed onwards to the remote driver. I need this because when I move the QEMU driver across then I have an interesting scenario. Initially 'qemu:///session' has to be handled by the remote driver, but once inside the remote daemon that very same URI has to be handled by the QEMU driver. The QEMU driver can detect when its run inside the daemon, so by having the remote driver last I can handle this scenario quite easily. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
diff -r 0121f12aeb0e src/libvirt.c --- a/src/libvirt.c Tue Jun 19 21:15:44 2007 -0400 +++ b/src/libvirt.c Tue Jun 19 22:05:43 2007 -0400 @@ -67,9 +67,6 @@ virInitialize(void) * Note that the order is important: the first ones have a higher * priority when calling virConnectOpen. */ -#ifdef WITH_REMOTE - if (remoteRegister () == -1) return -1; -#endif #ifdef WITH_TEST if (testRegister() == -1) return -1; #endif @@ -78,6 +75,9 @@ virInitialize(void) #endif #ifdef WITH_XEN if (xenUnifiedRegister () == -1) return -1; +#endif +#ifdef WITH_REMOTE + if (remoteRegister () == -1) return -1; #endif return(0); diff -r 0121f12aeb0e src/test.c --- a/src/test.c Tue Jun 19 21:15:44 2007 -0400 +++ b/src/test.c Tue Jun 19 22:00:39 2007 -0400 @@ -730,6 +730,11 @@ int testOpen(virConnectPtr conn, return VIR_DRV_OPEN_DECLINED; } + if (uri->server) { + xmlFreeURI(uri); + return VIR_DRV_OPEN_DECLINED; + } + /* From this point on, the connection is for us. */ if (!uri->path || uri->path[0] == '\0' diff -r 0121f12aeb0e src/xen_unified.c --- a/src/xen_unified.c Tue Jun 19 21:15:44 2007 -0400 +++ b/src/xen_unified.c Tue Jun 19 22:04:50 2007 -0400 @@ -30,6 +30,7 @@ #include <string.h> #include <sys/types.h> #include <xen/dom0_ops.h> +#include <libxml/uri.h> #include "internal.h" @@ -86,12 +87,36 @@ xenUnifiedOpen (virConnectPtr conn, cons { int i, j; xenUnifiedPrivatePtr priv; - - /* If name == NULL, name == "", or begins with "xen", then it's for us. */ + xmlURIPtr uri; + + /* Convert NULL or "" to xen:// for back compat */ if (!name || name[0] == '\0') - name = "Xen"; - if (strncasecmp (name, "Xen", 3) != 0) + name = "xen:///"; + + /* Convert xen -> xen:/// for back compat */ + if (!strcasecmp(name, "xen")) + name = "xen:///"; + + uri = xmlParseURI(name); + if (uri == NULL) { + xenUnifiedError(NULL, VIR_ERR_NO_SUPPORT, name); return VIR_DRV_OPEN_DECLINED; + } + + /* Refuse any URI which doesn't start xen:///, / or http:// */ + if (uri->scheme && + strcasecmp(uri->scheme, "xen") != 0 && + strcasecmp(uri->scheme, "http")) { + xmlFreeURI(uri); + 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") && uri->server) { + xmlFreeURI(uri); + return VIR_DRV_OPEN_DECLINED; + } + xmlFreeURI(uri); /* Allocate per-connection private data. */ priv = malloc (sizeof *priv);