my $api;
if (exists $apis{"vir$name"}) {
$api = "vir$name";
- } elsif ($name =~ /\w+(Open|Close)/) {
+ } elsif ($name =~ /\w+(Open|Close|URIProbe)/) {
next;
} else {
die "driver $name does not have a public API";
next if $api eq "no" || $api eq "name";
- die "Method $meth in $src is missing version" unless defined $vers;
+ die "Method $meth in $src is missing version" unless defined $vers || $api eq "connectURIProbe";
die "Driver method for $api is NULL in $src" if $meth eq "NULL";
if (!exists($groups{$ingrp}->{apis}->{$api})) {
- next if $api =~ /\w(Open|Close)/;
+ next if $api =~ /\w(Open|Close|URIProbe)/;
die "Found unexpected method $api in $ingrp\n";
}
return vm;
}
+
+static int
+bhyveConnectURIProbe(char **uri)
+{
+ if (bhyve_driver == NULL)
+ return 0;
+
+ return VIR_STRDUP(*uri, "bhyve:///system");
+}
+
+
static virDrvOpenStatus
bhyveConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->uri == NULL) {
- if (bhyve_driver == NULL)
- return VIR_DRV_OPEN_DECLINED;
-
- if (!(conn->uri = virURIParse("bhyve:///system")))
- return VIR_DRV_OPEN_ERROR;
+ return VIR_DRV_OPEN_DECLINED;
} else {
if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "bhyve"))
return VIR_DRV_OPEN_DECLINED;
static virHypervisorDriver bhyveHypervisorDriver = {
.name = "bhyve",
+ .connectURIProbe = bhyveConnectURIProbe,
.connectOpen = bhyveConnectOpen, /* 1.2.2 */
.connectClose = bhyveConnectClose, /* 1.2.2 */
.connectGetVersion = bhyveConnectGetVersion, /* 1.2.2 */
"storageClose" => 1,
"interfaceOpen" => 1,
"interfaceClose" => 1,
+ "connectURIProbe" => 1,
);
# Temp hack - remove it once xen driver is fixed
# error "Don't include this file directly, only use driver.h"
# endif
+typedef int
+(*virDrvConnectURIProbe)(char **uri);
+
typedef virDrvOpenStatus
(*virDrvConnectOpen)(virConnectPtr conn,
virConnectAuthPtr auth,
*/
struct _virHypervisorDriver {
const char *name; /* the name of the driver */
+ virDrvConnectURIProbe connectURIProbe;
virDrvConnectOpen connectOpen;
virDrvConnectClose connectClose;
virDrvConnectSupportsFeature connectSupportsFeature;
} else {
if (virConnectGetDefaultURI(conf, &uristr) < 0)
goto failed;
+
+ if (uristr == NULL) {
+ VIR_DEBUG("Trying to probe for default URI");
+ for (i = 0; i < virConnectDriverTabCount && uristr == NULL; i++) {
+ if (virConnectDriverTab[i]->hypervisorDriver->connectURIProbe) {
+ if (virConnectDriverTab[i]->hypervisorDriver->connectURIProbe(&uristr) < 0)
+ goto failed;
+ VIR_DEBUG("%s driver URI probe returned '%s'",
+ virConnectDriverTab[i]->hypervisorDriver->name,
+ uristr ? uristr : "");
+ }
+ }
+ }
}
if (uristr) {
}
+static int
+libxlConnectURIProbe(char **uri)
+{
+ if (libxl_driver == NULL)
+ return 0;
+
+ return VIR_STRDUP(*uri, "xen:///system");
+}
+
+
static virDrvOpenStatus
libxlConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->uri == NULL) {
- if (libxl_driver == NULL)
- return VIR_DRV_OPEN_DECLINED;
-
- if (!(conn->uri = virURIParse("xen:///system")))
- return VIR_DRV_OPEN_ERROR;
+ return VIR_DRV_OPEN_DECLINED;
} else {
/* Only xen scheme */
if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "xen"))
static virHypervisorDriver libxlHypervisorDriver = {
.name = LIBXL_DRIVER_NAME,
+ .connectURIProbe = libxlConnectURIProbe,
.connectOpen = libxlConnectOpen, /* 0.9.0 */
.connectClose = libxlConnectClose, /* 0.9.0 */
.connectGetType = libxlConnectGetType, /* 0.9.0 */
/* Functions */
+static int
+lxcConnectURIProbe(char **uri)
+{
+ if (lxc_driver == NULL)
+ return 0;
+
+ return VIR_STRDUP(*uri, "lxc:///system");
+}
+
+
static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virConfPtr conf ATTRIBUTE_UNUSED,
/* Verify uri was specified */
if (conn->uri == NULL) {
- if (lxc_driver == NULL)
- return VIR_DRV_OPEN_DECLINED;
-
- if (!(conn->uri = virURIParse("lxc:///system")))
- return VIR_DRV_OPEN_ERROR;
+ return VIR_DRV_OPEN_DECLINED;
} else {
if (conn->uri->scheme == NULL ||
STRNEQ(conn->uri->scheme, "lxc"))
/* Function Tables */
static virHypervisorDriver lxcHypervisorDriver = {
.name = LXC_DRIVER_NAME,
+ .connectURIProbe = lxcConnectURIProbe,
.connectOpen = lxcConnectOpen, /* 0.4.2 */
.connectClose = lxcConnectClose, /* 0.4.2 */
.connectSupportsFeature = lxcConnectSupportsFeature, /* 1.2.2 */
return openvzDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
}
+
+static int
+openvzConnectURIProbe(char **uri)
+{
+ if (!virFileExists("/proc/vz"))
+ return 0;
+
+ if (access("/proc/vz", W_OK) < 0)
+ return 0;
+
+ return VIR_STRDUP(*uri, "openvz:///system");
+}
+
+
static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virConfPtr conf ATTRIBUTE_UNUSED,
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->uri == NULL) {
- if (!virFileExists("/proc/vz"))
- return VIR_DRV_OPEN_DECLINED;
-
- if (access("/proc/vz", W_OK) < 0)
- return VIR_DRV_OPEN_DECLINED;
-
- if (!(conn->uri = virURIParse("openvz:///system")))
- return VIR_DRV_OPEN_ERROR;
+ return VIR_DRV_OPEN_DECLINED;
} else {
/* If scheme isn't 'openvz', then its for another driver */
if (conn->uri->scheme == NULL ||
static virHypervisorDriver openvzHypervisorDriver = {
.name = "OPENVZ",
+ .connectURIProbe = openvzConnectURIProbe,
.connectOpen = openvzConnectOpen, /* 0.3.1 */
.connectClose = openvzConnectClose, /* 0.3.1 */
.connectGetType = openvzConnectGetType, /* 0.3.1 */
}
+static int
+qemuConnectURIProbe(char **uri)
+{
+ virQEMUDriverConfigPtr cfg = NULL;
+ int ret = -1;
+
+ if (qemu_driver == NULL)
+ return 0;
+
+ cfg = virQEMUDriverGetConfig(qemu_driver);
+ if (VIR_STRDUP(*uri, cfg->uri) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ virObjectUnref(cfg);
+ return ret;
+}
+
static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virConfPtr conf ATTRIBUTE_UNUSED,
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->uri == NULL) {
- if (qemu_driver == NULL) {
- ret = VIR_DRV_OPEN_DECLINED;
- goto cleanup;
- }
-
- cfg = virQEMUDriverGetConfig(qemu_driver);
-
- if (!(conn->uri = virURIParse(cfg->uri)))
- goto cleanup;
+ return VIR_DRV_OPEN_DECLINED;
} else {
/* If URI isn't 'qemu' its definitely not for us */
if (conn->uri->scheme == NULL ||
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
+ .connectURIProbe = qemuConnectURIProbe,
.connectOpen = qemuConnectOpen, /* 0.2.0 */
.connectClose = qemuConnectClose, /* 0.2.0 */
.connectSupportsFeature = qemuConnectSupportsFeature, /* 0.5.0 */
}
+static int umlConnectURIProbe(char **uri)
+{
+ if (uml_driver == NULL)
+ return 0;
+
+ return VIR_STRDUP(*uri, uml_driver->privileged ?
+ "uml:///system" :
+ "uml:///session");
+}
+
+
static virDrvOpenStatus umlConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virConfPtr conf ATTRIBUTE_UNUSED,
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->uri == NULL) {
- if (uml_driver == NULL)
- return VIR_DRV_OPEN_DECLINED;
-
- if (!(conn->uri = virURIParse(uml_driver->privileged ?
- "uml:///system" :
- "uml:///session")))
- return VIR_DRV_OPEN_ERROR;
+ return VIR_DRV_OPEN_DECLINED;
} else {
if (conn->uri->scheme == NULL ||
STRNEQ(conn->uri->scheme, "uml"))
static virHypervisorDriver umlHypervisorDriver = {
.name = "UML",
+ .connectURIProbe = umlConnectURIProbe,
.connectOpen = umlConnectOpen, /* 0.5.0 */
.connectClose = umlConnectClose, /* 0.5.0 */
.connectGetType = umlConnectGetType, /* 0.5.0 */
}
+static int
+vboxConnectURIProbe(char **uri)
+{
+ return VIR_STRDUP(*uri, geteuid() ? "vbox:///session" : "vbox:///system");
+}
+
+
static virDrvOpenStatus
vboxConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
- if (conn->uri == NULL &&
- !(conn->uri = virURIParse(uid ? "vbox:///session" : "vbox:///system")))
- return VIR_DRV_OPEN_ERROR;
+ if (conn->uri == NULL)
+ return VIR_DRV_OPEN_DECLINED;
if (conn->uri->scheme == NULL ||
STRNEQ(conn->uri->scheme, "vbox"))
static virHypervisorDriver vboxCommonDriver = {
.name = "VBOX",
+ .connectURIProbe = vboxConnectURIProbe,
.connectOpen = vboxConnectOpen, /* 0.6.3 */
.connectClose = vboxConnectClose, /* 0.6.3 */
.connectGetVersion = vboxConnectGetVersion, /* 0.6.3 */