Add a localOnly flag to the virConnectDriver struct which allows a
driver to indicate whether it is local-only, or permits remote
connections. Stateful drivers running inside libvirtd are generally
local only. This allows us to remote the check for uri->server != NULL
from most drivers.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/bhyve/bhyve_driver.c | 4 +---
src/driver.h | 2 ++
src/interface/interface_backend_netcf.c | 5 +----
src/interface/interface_backend_udev.c | 5 +----
src/libvirt.c | 5 +++++
src/libxl/libxl_driver.c | 5 +----
src/lxc/lxc_driver.c | 5 +----
src/network/bridge_driver.c | 5 +----
src/node_device/node_device_driver.c | 4 ----
src/node_device/node_device_hal.c | 1 +
src/node_device/node_device_udev.c | 1 +
src/nwfilter/nwfilter_driver.c | 5 +----
src/openvz/openvz_driver.c | 5 +----
src/qemu/qemu_driver.c | 7 +------
src/secret/secret_driver.c | 5 +----
src/storage/storage_driver.c | 5 +----
src/test/test_driver.c | 5 +----
src/uml/uml_driver.c | 6 +-----
src/vbox/vbox_common.c | 4 ----
src/vbox/vbox_driver.c | 8 +++++---
src/vmware/vmware_driver.c | 5 +----
src/vz/vz_driver.c | 5 +----
22 files changed, 29 insertions(+), 73 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index a0bc400480..cc1d4ba6fb 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -205,9 +205,6 @@ bhyveConnectOpen(virConnectPtr conn,
if (!conn->uri->scheme || STRNEQ(conn->uri->scheme,
"bhyve"))
return VIR_DRV_OPEN_DECLINED;
- if (conn->uri->server)
- return VIR_DRV_OPEN_DECLINED;
-
if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected bhyve URI path '%s', try
bhyve:///system"),
@@ -1754,6 +1751,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
static virConnectDriver bhyveConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &bhyveHypervisorDriver,
};
diff --git a/src/driver.h b/src/driver.h
index c86da85481..5fb0b523c8 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -79,6 +79,8 @@ typedef struct _virConnectDriver virConnectDriver;
typedef virConnectDriver *virConnectDriverPtr;
struct _virConnectDriver {
+ /* Wether driver permits a server in the URI */
+ bool localOnly;
virHypervisorDriverPtr hypervisorDriver;
virInterfaceDriverPtr interfaceDriver;
virNetworkDriverPtr networkDriver;
diff --git a/src/interface/interface_backend_netcf.c
b/src/interface/interface_backend_netcf.c
index fb75a33280..3da958980f 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -167,10 +167,6 @@ netcfConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "interface"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("interface state driver is not active"));
@@ -1224,6 +1220,7 @@ static virHypervisorDriver interfaceHypervisorDriver = {
static virConnectDriver interfaceConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &interfaceHypervisorDriver,
.interfaceDriver = &interfaceDriver,
};
diff --git a/src/interface/interface_backend_udev.c
b/src/interface/interface_backend_udev.c
index 47e850bc2a..2b8a9da682 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1211,10 +1211,6 @@ udevConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "interface"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("interface state driver is not active"));
@@ -1295,6 +1291,7 @@ static virHypervisorDriver udevHypervisorDriver = {
static virConnectDriver udevConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &udevHypervisorDriver,
.interfaceDriver = &udevIfaceDriver,
};
diff --git a/src/libvirt.c b/src/libvirt.c
index d87efca625..2b2b3ed425 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -1068,6 +1068,11 @@ virConnectOpenInternal(const char *name,
VIR_DEBUG("trying driver %zu (%s) ...",
i, virConnectDriverTab[i]->hypervisorDriver->name);
+ if (virConnectDriverTab[i]->localOnly && ret->uri &&
ret->uri->server) {
+ VIR_DEBUG("Server present, skipping local only driver");
+ continue;
+ }
+
ret->driver = virConnectDriverTab[i]->hypervisorDriver;
ret->interfaceDriver = virConnectDriverTab[i]->interfaceDriver;
ret->networkDriver = virConnectDriverTab[i]->networkDriver;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d574fa446e..ce4741cf4c 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -852,10 +852,6 @@ libxlConnectOpen(virConnectPtr conn,
if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme,
"xen"))
return VIR_DRV_OPEN_DECLINED;
- /* If server name is given, its for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
/* Error if xen or libxl scheme specified but driver not started. */
if (libxl_driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -6582,6 +6578,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
};
static virConnectDriver libxlConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &libxlHypervisorDriver,
};
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 7fbeabc994..7a3e720d16 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -177,10 +177,6 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn,
STRNEQ(conn->uri->scheme, "lxc"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
/* If path isn't '/' then they typoed, tell them correct path */
if (conn->uri->path != NULL &&
STRNEQ(conn->uri->path, "/") &&
@@ -5633,6 +5629,7 @@ static virHypervisorDriver lxcHypervisorDriver = {
};
static virConnectDriver lxcConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &lxcHypervisorDriver,
};
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index d326923d81..ca48a0358c 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -886,10 +886,6 @@ networkConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "network"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (network_driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("network state driver is not active"));
@@ -5616,6 +5612,7 @@ static virHypervisorDriver networkHypervisorDriver = {
static virConnectDriver networkConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &networkHypervisorDriver,
.networkDriver = &networkDriver,
};
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 1347ce0c86..ad4938fcd6 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -62,10 +62,6 @@ nodeConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "nodedev"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("nodedev state driver is not active"));
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 6ad56f4166..4c251da88a 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -783,6 +783,7 @@ static virHypervisorDriver halHypervisorDriver = {
static virConnectDriver halConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &halHypervisorDriver,
.nodeDeviceDriver = &halNodeDeviceDriver,
};
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index e87eb32a85..d89b5ff7cc 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1957,6 +1957,7 @@ static virHypervisorDriver udevHypervisorDriver = {
static virConnectDriver udevConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &udevHypervisorDriver,
.nodeDeviceDriver = &udevNodeDeviceDriver,
};
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 6cc7ca699a..71aca5a968 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -379,10 +379,6 @@ nwfilterConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "nwfilter"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("nwfilter state driver is not active"));
@@ -712,6 +708,7 @@ static virHypervisorDriver nwfilterHypervisorDriver = {
static virConnectDriver nwfilterConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &nwfilterHypervisorDriver,
.nwfilterDriver = &nwfilterDriver,
};
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f30db8eec3..a56476475e 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1451,10 +1451,6 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
STRNEQ(conn->uri->scheme, "openvz"))
return VIR_DRV_OPEN_DECLINED;
- /* If server name is given, its for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
/* If path isn't /system, then they typoed, so tell them correct path */
if (conn->uri->path == NULL ||
STRNEQ(conn->uri->path, "/system")) {
@@ -2659,6 +2655,7 @@ static virHypervisorDriver openvzHypervisorDriver = {
};
static virConnectDriver openvzConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &openvzHypervisorDriver,
};
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 99ec51f304..ef890916dc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1153,12 +1153,6 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn,
goto cleanup;
}
- /* Allow remote driver to deal with URIs with hostname server */
- if (conn->uri->server != NULL) {
- ret = VIR_DRV_OPEN_DECLINED;
- goto cleanup;
- }
-
if (qemu_driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("qemu state driver is not active"));
@@ -21573,6 +21567,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
static virConnectDriver qemuConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &qemuHypervisorDriver,
};
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 23a3c9bdad..06d116f07f 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -532,10 +532,6 @@ secretConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "secret"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("secret state driver is not active"));
@@ -662,6 +658,7 @@ static virHypervisorDriver secretHypervisorDriver = {
static virConnectDriver secretConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &secretHypervisorDriver,
.secretDriver = &secretDriver,
};
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 173b91b61b..7eb5fad929 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -392,10 +392,6 @@ storageConnectOpen(virConnectPtr conn,
if (STRNEQ_NULLABLE(conn->uri->scheme, "storage"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (driver == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("storage state driver is not active"));
@@ -2855,6 +2851,7 @@ static virHypervisorDriver storageHypervisorDriver = {
};
static virConnectDriver storageConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &storageHypervisorDriver,
.storageDriver = &storageDriver,
};
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 856869c9d3..de3943406e 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1460,10 +1460,6 @@ testConnectOpen(virConnectPtr conn,
if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "test"))
return VIR_DRV_OPEN_DECLINED;
- /* Remote driver should handle these. */
- if (conn->uri->server)
- return VIR_DRV_OPEN_DECLINED;
-
/* From this point on, the connection is for us. */
if (!conn->uri->path
|| conn->uri->path[0] == '\0'
@@ -7065,6 +7061,7 @@ static virNodeDeviceDriver testNodeDeviceDriver = {
};
static virConnectDriver testConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &testHypervisorDriver,
.interfaceDriver = &testInterfaceDriver,
.networkDriver = &testNetworkDriver,
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 63350908dd..7fae561aff 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1210,11 +1210,6 @@ static virDrvOpenStatus umlConnectOpen(virConnectPtr conn,
STRNEQ(conn->uri->scheme, "uml"))
return VIR_DRV_OPEN_DECLINED;
- /* Allow remote driver to deal with URIs with hostname server */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
-
/* Check path and tell them correct path if they made a mistake */
if (uml_driver->privileged) {
if (STRNEQ(conn->uri->path, "/system") &&
@@ -3018,6 +3013,7 @@ static virHypervisorDriver umlHypervisorDriver = {
};
static virConnectDriver umlConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = ¨HypervisorDriver,
};
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index ef71e650c6..886b41b0b9 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -524,10 +524,6 @@ vboxConnectOpen(virConnectPtr conn,
STRNEQ(conn->uri->scheme, "vbox"))
return VIR_DRV_OPEN_DECLINED;
- /* Leave for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no VirtualBox driver path specified (try
vbox:///session)"));
diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c
index c10c0c492b..e3880b4826 100644
--- a/src/vbox/vbox_driver.c
+++ b/src/vbox/vbox_driver.c
@@ -60,8 +60,7 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn,
if (conn->uri == NULL ||
conn->uri->scheme == NULL ||
- STRNEQ(conn->uri->scheme, "vbox") ||
- conn->uri->server != NULL)
+ STRNEQ(conn->uri->scheme, "vbox"))
return VIR_DRV_OPEN_DECLINED;
if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) {
@@ -95,7 +94,10 @@ static virHypervisorDriver vboxDriverDummy = {
.connectOpen = dummyConnectOpen, /* 0.6.3 */
};
-static virConnectDriver vboxConnectDriver;
+static virConnectDriver vboxConnectDriver = {
+ .localOnly = true,
+ .hypervisorDriver = NULL,
+};
int vboxRegister(void)
{
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 8b487c4a7c..435b9ee6ff 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -140,10 +140,6 @@ vmwareConnectOpen(virConnectPtr conn,
STRNEQ(conn->uri->scheme, "vmwarefusion")))
return VIR_DRV_OPEN_DECLINED;
- /* If server name is given, its for remote driver */
- if (conn->uri->server != NULL)
- return VIR_DRV_OPEN_DECLINED;
-
/* If path isn't /session, then they typoed, so tell them correct path */
if (conn->uri->path == NULL || STRNEQ(conn->uri->path,
"/session")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1271,6 +1267,7 @@ static virHypervisorDriver vmwareHypervisorDriver = {
};
static virConnectDriver vmwareConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &vmwareHypervisorDriver,
};
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index a425bc8552..8842056ea4 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -374,10 +374,6 @@ vzConnectOpen(virConnectPtr conn,
if (STREQ(conn->uri->scheme, "parallels") &&
STRNEQ(conn->driver->name, "Parallels"))
return VIR_DRV_OPEN_DECLINED;
- /* Remote driver should handle these. */
- if (conn->uri->server)
- return VIR_DRV_OPEN_DECLINED;
-
/* From this point on, the connection is for us. */
if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -4143,6 +4139,7 @@ static virHypervisorDriver vzHypervisorDriver = {
};
static virConnectDriver vzConnectDriver = {
+ .localOnly = true,
.hypervisorDriver = &vzHypervisorDriver,
};
--
2.14.3