
On 02/15/2018 11:50 AM, Daniel P. Berrangé wrote:
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.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/driver.c | 172 +++++++++++++++++++++++++++++++++++++++++++++-- src/driver.h | 7 ++ src/libvirt_private.syms | 6 ++ 3 files changed, 179 insertions(+), 6 deletions(-)
diff --git a/src/driver.c b/src/driver.c index a6a7ff925a..5e3a2a7d62 100644 --- a/src/driver.c +++ b/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,191 @@ 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)
Could all the new defs use the "newer" model: static int virConnect...(void)
+{ + if (virThreadLocalInit(&connectInterface, NULL) < 0)
There's extra spaces before the 2nd arg in all of these.
+ 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); +
[...] Same for all the virSetConnect* defs too. Could also go w/ 2 empty lines between each if you feel so inclined.
+int virSetConnectInterface(virConnectPtr conn) +{ + if (virConnectCacheInitialize() < 0) + return -1; + + VIR_DEBUG("Override interface connection with %p", conn); + return virThreadLocalSet(&connectInterface, conn); +} +
[...] Reviewed-by: John Ferlan <jferlan@redhat.com> John