driver: allow drivers to indicate if they permit remote connections

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@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-03-28 10:53:31 +01:00
parent 20ad55a8fd
commit 3714cc952d
23 changed files with 30 additions and 73 deletions

View File

@ -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"),
@ -1738,6 +1735,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
static virConnectDriver bhyveConnectDriver = {
.localOnly = true,
.hypervisorDriver = &bhyveHypervisorDriver,
};

View File

@ -60,6 +60,7 @@ my %whitelist = (
"interfaceOpen" => 1,
"interfaceClose" => 1,
"connectURIProbe" => 1,
"localOnly" => 1,
);
# Temp hack - remove it once xen driver is fixed

View File

@ -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;

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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;

View File

@ -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,
};

View File

@ -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, "/") &&
@ -5637,6 +5633,7 @@ static virHypervisorDriver lxcHypervisorDriver = {
};
static virConnectDriver lxcConnectDriver = {
.localOnly = true,
.hypervisorDriver = &lxcHypervisorDriver,
};

View File

@ -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,
};

View File

@ -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"));

View File

@ -783,6 +783,7 @@ static virHypervisorDriver halHypervisorDriver = {
static virConnectDriver halConnectDriver = {
.localOnly = true,
.hypervisorDriver = &halHypervisorDriver,
.nodeDeviceDriver = &halNodeDeviceDriver,
};

View File

@ -1957,6 +1957,7 @@ static virHypervisorDriver udevHypervisorDriver = {
static virConnectDriver udevConnectDriver = {
.localOnly = true,
.hypervisorDriver = &udevHypervisorDriver,
.nodeDeviceDriver = &udevNodeDeviceDriver,
};

View File

@ -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,
};

View File

@ -1362,10 +1362,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")) {
@ -2524,6 +2520,7 @@ static virHypervisorDriver openvzHypervisorDriver = {
};
static virConnectDriver openvzConnectDriver = {
.localOnly = true,
.hypervisorDriver = &openvzHypervisorDriver,
};

View File

@ -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"));
@ -21569,6 +21563,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
static virConnectDriver qemuConnectDriver = {
.localOnly = true,
.hypervisorDriver = &qemuHypervisorDriver,
};

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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,

View File

@ -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 = &umlHypervisorDriver,
};

View File

@ -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)"));

View File

@ -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)
{

View File

@ -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,
};

View File

@ -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,
};