mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
driver: allow override of connection for secondary drivers
When the test suite is running, we don't want to be triggering the startup of daemons for the secondary drivers. Thus we must provide a way to set a custom connection for the secondary drivers, to override the default logic which opens a new connection. This will also be useful for code where we have a whole set of separate functions calls all needing the secret driver. Currently the connection to the secret driver is opened & closed many times in quick succession. This will allow us to pre-open a connection temporarily, improving the performance of startup. Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
fb0db76a47
commit
70854ea3bc
184
src/driver.c
184
src/driver.c
@ -28,6 +28,7 @@
|
||||
#include "viralloc.h"
|
||||
#include "virfile.h"
|
||||
#include "virlog.h"
|
||||
#include "virthread.h"
|
||||
#include "configmake.h"
|
||||
|
||||
VIR_LOG_INIT("driver");
|
||||
@ -168,32 +169,203 @@ virDriverLoadModule(const char *name,
|
||||
|
||||
/* XXX unload modules, but we can't until we can unregister libvirt drivers */
|
||||
|
||||
virThreadLocal connectInterface;
|
||||
virThreadLocal connectNetwork;
|
||||
virThreadLocal connectNWFilter;
|
||||
virThreadLocal connectNodeDev;
|
||||
virThreadLocal connectSecret;
|
||||
virThreadLocal connectStorage;
|
||||
|
||||
static int
|
||||
virConnectCacheOnceInit(void)
|
||||
{
|
||||
if (virThreadLocalInit(&connectInterface, NULL) < 0)
|
||||
return -1;
|
||||
if (virThreadLocalInit(&connectNetwork, NULL) < 0)
|
||||
return -1;
|
||||
if (virThreadLocalInit(&connectNWFilter, NULL) < 0)
|
||||
return -1;
|
||||
if (virThreadLocalInit(&connectNodeDev, NULL) < 0)
|
||||
return -1;
|
||||
if (virThreadLocalInit(&connectSecret, NULL) < 0)
|
||||
return -1;
|
||||
if (virThreadLocalInit(&connectStorage, NULL) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virConnectCache);
|
||||
|
||||
virConnectPtr virGetConnectInterface(void)
|
||||
{
|
||||
return virConnectOpen(geteuid() == 0 ? "interface:///system" : "interface:///session");
|
||||
virConnectPtr conn;
|
||||
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
conn = virThreadLocalGet(&connectInterface);
|
||||
if (conn) {
|
||||
VIR_DEBUG("Return cached interface connection %p", conn);
|
||||
virObjectRef(conn);
|
||||
} else {
|
||||
conn = virConnectOpen(geteuid() == 0 ? "interface:///system" : "interface:///session");
|
||||
VIR_DEBUG("Opened new interface connection %p", conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
virConnectPtr virGetConnectNetwork(void)
|
||||
{
|
||||
return virConnectOpen(geteuid() == 0 ? "network:///system" : "network:///session");
|
||||
virConnectPtr conn;
|
||||
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
conn = virThreadLocalGet(&connectNetwork);
|
||||
if (conn) {
|
||||
VIR_DEBUG("Return cached network connection %p", conn);
|
||||
virObjectRef(conn);
|
||||
} else {
|
||||
conn = virConnectOpen(geteuid() == 0 ? "network:///system" : "network:///session");
|
||||
VIR_DEBUG("Opened new network connection %p", conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
virConnectPtr virGetConnectNWFilter(void)
|
||||
{
|
||||
return virConnectOpen(geteuid() == 0 ? "nwfilter:///system" : "nwfilter:///session");
|
||||
virConnectPtr conn;
|
||||
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
conn = virThreadLocalGet(&connectNWFilter);
|
||||
if (conn) {
|
||||
VIR_DEBUG("Return cached nwfilter connection %p", conn);
|
||||
virObjectRef(conn);
|
||||
} else {
|
||||
conn = virConnectOpen(geteuid() == 0 ? "nwfilter:///system" : "nwfilter:///session");
|
||||
VIR_DEBUG("Opened new nwfilter connection %p", conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
virConnectPtr virGetConnectNodeDev(void)
|
||||
{
|
||||
return virConnectOpen(geteuid() == 0 ? "nodedev:///system" : "nodedev:///session");
|
||||
virConnectPtr conn;
|
||||
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
conn = virThreadLocalGet(&connectNodeDev);
|
||||
if (conn) {
|
||||
VIR_DEBUG("Return cached nodedev connection %p", conn);
|
||||
virObjectRef(conn);
|
||||
} else {
|
||||
conn = virConnectOpen(geteuid() == 0 ? "nodedev:///system" : "nodedev:///session");
|
||||
VIR_DEBUG("Opened new nodedev connection %p", conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
virConnectPtr virGetConnectSecret(void)
|
||||
{
|
||||
return virConnectOpen(geteuid() == 0 ? "secret:///system" : "secret:///session");
|
||||
virConnectPtr conn;
|
||||
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
conn = virThreadLocalGet(&connectSecret);
|
||||
if (conn) {
|
||||
VIR_DEBUG("Return cached secret connection %p", conn);
|
||||
virObjectRef(conn);
|
||||
} else {
|
||||
conn = virConnectOpen(geteuid() == 0 ? "secret:///system" : "secret:///session");
|
||||
VIR_DEBUG("Opened new secret connection %p", conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
virConnectPtr virGetConnectStorage(void)
|
||||
{
|
||||
return virConnectOpen(geteuid() == 0 ? "storage:///system" : "storage:///session");
|
||||
virConnectPtr conn;
|
||||
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
conn = virThreadLocalGet(&connectStorage);
|
||||
if (conn) {
|
||||
VIR_DEBUG("Return cached storage connection %p", conn);
|
||||
virObjectRef(conn);
|
||||
} else {
|
||||
conn = virConnectOpen(geteuid() == 0 ? "storage:///system" : "storage:///session");
|
||||
VIR_DEBUG("Opened new storage connection %p", conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSetConnectInterface(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Override interface connection with %p", conn);
|
||||
return virThreadLocalSet(&connectInterface, conn);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSetConnectNetwork(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Override network connection with %p", conn);
|
||||
return virThreadLocalSet(&connectNetwork, conn);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSetConnectNWFilter(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Override nwfilter connection with %p", conn);
|
||||
return virThreadLocalSet(&connectNWFilter, conn);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSetConnectNodeDev(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Override nodedev connection with %p", conn);
|
||||
return virThreadLocalSet(&connectNodeDev, conn);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSetConnectSecret(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Override secret connection with %p", conn);
|
||||
return virThreadLocalSet(&connectSecret, conn);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSetConnectStorage(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectCacheInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Override storage connection with %p", conn);
|
||||
return virThreadLocalSet(&connectStorage, conn);
|
||||
}
|
||||
|
@ -112,4 +112,11 @@ virConnectPtr virGetConnectNodeDev(void);
|
||||
virConnectPtr virGetConnectSecret(void);
|
||||
virConnectPtr virGetConnectStorage(void);
|
||||
|
||||
int virSetConnectInterface(virConnectPtr conn);
|
||||
int virSetConnectNetwork(virConnectPtr conn);
|
||||
int virSetConnectNWFilter(virConnectPtr conn);
|
||||
int virSetConnectNodeDev(virConnectPtr conn);
|
||||
int virSetConnectSecret(virConnectPtr conn);
|
||||
int virSetConnectStorage(virConnectPtr conn);
|
||||
|
||||
#endif /* __VIR_DRIVER_H__ */
|
||||
|
@ -1204,6 +1204,12 @@ virGetConnectNodeDev;
|
||||
virGetConnectNWFilter;
|
||||
virGetConnectSecret;
|
||||
virGetConnectStorage;
|
||||
virSetConnectInterface;
|
||||
virSetConnectNetwork;
|
||||
virSetConnectNodeDev;
|
||||
virSetConnectNWFilter;
|
||||
virSetConnectSecret;
|
||||
virSetConnectStorage;
|
||||
|
||||
|
||||
# libvirt_internal.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user