提交 20ad55a8 编写于 作者: D Daniel P. Berrangé

driver: introduce a driver method for probing default URIs

Currently the virDrvConnectOpen method is supposed to handle both
opening an explicit URI and auto-probing a driver if no URI is
given. Introduce a dedicated virDrvConnectURIProbe method to enable the
probing functionality to be split from the driver opening functionality.

It is still possible for NULL to be passed to the virDrvConnectOpen
method after this change, because the remote driver needs special
handling to enable probing of the URI against a remote libvirtd daemon.
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 a2fd657b
......@@ -184,7 +184,7 @@ foreach my $drivertable (@drivertable) {
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";
......@@ -241,12 +241,12 @@ foreach my $src (@srcs) {
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";
}
......
......@@ -180,6 +180,17 @@ bhyveDomObjFromDomain(virDomainPtr domain)
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,
......@@ -189,11 +200,7 @@ bhyveConnectOpen(virConnectPtr conn,
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;
......@@ -1673,6 +1680,7 @@ bhyveConnectGetDomainCapabilities(virConnectPtr conn,
static virHypervisorDriver bhyveHypervisorDriver = {
.name = "bhyve",
.connectURIProbe = bhyveConnectURIProbe,
.connectOpen = bhyveConnectOpen, /* 1.2.2 */
.connectClose = bhyveConnectClose, /* 1.2.2 */
.connectGetVersion = bhyveConnectGetVersion, /* 1.2.2 */
......
......@@ -59,6 +59,7 @@ my %whitelist = (
"storageClose" => 1,
"interfaceOpen" => 1,
"interfaceClose" => 1,
"connectURIProbe" => 1,
);
# Temp hack - remove it once xen driver is fixed
......
......@@ -25,6 +25,9 @@
# error "Don't include this file directly, only use driver.h"
# endif
typedef int
(*virDrvConnectURIProbe)(char **uri);
typedef virDrvOpenStatus
(*virDrvConnectOpen)(virConnectPtr conn,
virConnectAuthPtr auth,
......@@ -1300,6 +1303,7 @@ typedef virHypervisorDriver *virHypervisorDriverPtr;
*/
struct _virHypervisorDriver {
const char *name; /* the name of the driver */
virDrvConnectURIProbe connectURIProbe;
virDrvConnectOpen connectOpen;
virDrvConnectClose connectClose;
virDrvConnectSupportsFeature connectSupportsFeature;
......
......@@ -975,6 +975,19 @@ virConnectOpenInternal(const char *name,
} 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) {
......
......@@ -827,6 +827,16 @@ libxlStateReload(void)
}
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,
......@@ -836,11 +846,7 @@ libxlConnectOpen(virConnectPtr conn,
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"))
......@@ -6466,6 +6472,7 @@ libxlConnectBaselineCPU(virConnectPtr conn,
static virHypervisorDriver libxlHypervisorDriver = {
.name = LIBXL_DRIVER_NAME,
.connectURIProbe = libxlConnectURIProbe,
.connectOpen = libxlConnectOpen, /* 0.9.0 */
.connectClose = libxlConnectClose, /* 0.9.0 */
.connectGetType = libxlConnectGetType, /* 0.9.0 */
......
......@@ -152,6 +152,16 @@ lxcDomObjFromDomain(virDomainPtr domain)
/* 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,
......@@ -161,11 +171,7 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn,
/* 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"))
......@@ -5537,6 +5543,7 @@ lxcDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
/* 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 */
......
......@@ -1331,6 +1331,20 @@ openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
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,
......@@ -1341,14 +1355,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
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 ||
......@@ -2450,6 +2457,7 @@ openvzDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
static virHypervisorDriver openvzHypervisorDriver = {
.name = "OPENVZ",
.connectURIProbe = openvzConnectURIProbe,
.connectOpen = openvzConnectOpen, /* 0.3.1 */
.connectClose = openvzConnectClose, /* 0.3.1 */
.connectGetType = openvzConnectGetType, /* 0.3.1 */
......
......@@ -1115,6 +1115,25 @@ qemuStateCleanup(void)
}
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,
......@@ -1125,15 +1144,7 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn,
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 ||
......@@ -21336,6 +21347,7 @@ qemuDomainSetLifecycleAction(virDomainPtr dom,
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
.connectURIProbe = qemuConnectURIProbe,
.connectOpen = qemuConnectOpen, /* 0.2.0 */
.connectClose = qemuConnectClose, /* 0.2.0 */
.connectSupportsFeature = qemuConnectSupportsFeature, /* 0.5.0 */
......
......@@ -1185,6 +1185,17 @@ static void umlShutdownVMDaemon(struct uml_driver *driver,
}
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,
......@@ -1193,13 +1204,7 @@ static virDrvOpenStatus umlConnectOpen(virConnectPtr conn,
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"))
......@@ -2947,6 +2952,7 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
static virHypervisorDriver umlHypervisorDriver = {
.name = "UML",
.connectURIProbe = umlConnectURIProbe,
.connectOpen = umlConnectOpen, /* 0.5.0 */
.connectClose = umlConnectClose, /* 0.5.0 */
.connectGetType = umlConnectGetType, /* 0.5.0 */
......
......@@ -499,6 +499,13 @@ vboxAttachStorageControllers(virDomainDefPtr def,
}
static int
vboxConnectURIProbe(char **uri)
{
return VIR_STRDUP(*uri, geteuid() ? "vbox:///session" : "vbox:///system");
}
static virDrvOpenStatus
vboxConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
......@@ -510,9 +517,8 @@ vboxConnectOpen(virConnectPtr conn,
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"))
......@@ -7980,6 +7986,7 @@ vboxDomainSendKey(virDomainPtr dom,
static virHypervisorDriver vboxCommonDriver = {
.name = "VBOX",
.connectURIProbe = vboxConnectURIProbe,
.connectOpen = vboxConnectOpen, /* 0.6.3 */
.connectClose = vboxConnectClose, /* 0.6.3 */
.connectGetVersion = vboxConnectGetVersion, /* 0.6.3 */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册