From nobody Wed May 14 18:21:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518780152150187.61346300150012; Fri, 16 Feb 2018 03:22:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20BF781DEB; Fri, 16 Feb 2018 11:22:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83C145D6A3; Fri, 16 Feb 2018 11:22:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 25CBB4A46D; Fri, 16 Feb 2018 11:22:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1GBMQco012887 for ; Fri, 16 Feb 2018 06:22:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 13664202699C; Fri, 16 Feb 2018 11:22:26 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id E64762026DFD; Fri, 16 Feb 2018 11:22:24 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 16 Feb 2018 11:22:13 +0000 Message-Id: <20180216112222.26572-2-berrange@redhat.com> In-Reply-To: <20180216112222.26572-1-berrange@redhat.com> References: <20180216112222.26572-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/10] driver: allow override of connection for secondary drivers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 16 Feb 2018 11:22:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 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 Signed-off-by: Daniel P. Berrang=C3=A9 --- src/driver.c | 184 +++++++++++++++++++++++++++++++++++++++++++= ++-- src/driver.h | 7 ++ src/libvirt_private.syms | 6 ++ 3 files changed, 191 insertions(+), 6 deletions(-) diff --git a/src/driver.c b/src/driver.c index a6a7ff925a..52e1ae345a 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" =20 VIR_LOG_INIT("driver"); @@ -168,32 +169,203 @@ virDriverLoadModule(const char *name, =20 /* XXX unload modules, but we can't until we can unregister libvirt driver= s */ =20 +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() =3D=3D 0 ? "interface:///system" : "in= terface:///session"); + virConnectPtr conn; + + if (virConnectCacheInitialize() < 0) + return NULL; + + conn =3D virThreadLocalGet(&connectInterface); + if (conn) { + VIR_DEBUG("Return cached interface connection %p", conn); + virObjectRef(conn); + } else { + conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "interface:///system"= : "interface:///session"); + VIR_DEBUG("Opened new interface connection %p", conn); + } + return conn; } =20 virConnectPtr virGetConnectNetwork(void) { - return virConnectOpen(geteuid() =3D=3D 0 ? "network:///system" : "netw= ork:///session"); + virConnectPtr conn; + + if (virConnectCacheInitialize() < 0) + return NULL; + + conn =3D virThreadLocalGet(&connectNetwork); + if (conn) { + VIR_DEBUG("Return cached network connection %p", conn); + virObjectRef(conn); + } else { + conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "network:///system" := "network:///session"); + VIR_DEBUG("Opened new network connection %p", conn); + } + return conn; } =20 virConnectPtr virGetConnectNWFilter(void) { - return virConnectOpen(geteuid() =3D=3D 0 ? "nwfilter:///system" : "nwf= ilter:///session"); + virConnectPtr conn; + + if (virConnectCacheInitialize() < 0) + return NULL; + + conn =3D virThreadLocalGet(&connectNWFilter); + if (conn) { + VIR_DEBUG("Return cached nwfilter connection %p", conn); + virObjectRef(conn); + } else { + conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "nwfilter:///system" = : "nwfilter:///session"); + VIR_DEBUG("Opened new nwfilter connection %p", conn); + } + return conn; } =20 virConnectPtr virGetConnectNodeDev(void) { - return virConnectOpen(geteuid() =3D=3D 0 ? "nodedev:///system" : "node= dev:///session"); + virConnectPtr conn; + + if (virConnectCacheInitialize() < 0) + return NULL; + + conn =3D virThreadLocalGet(&connectNodeDev); + if (conn) { + VIR_DEBUG("Return cached nodedev connection %p", conn); + virObjectRef(conn); + } else { + conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "nodedev:///system" := "nodedev:///session"); + VIR_DEBUG("Opened new nodedev connection %p", conn); + } + return conn; } =20 virConnectPtr virGetConnectSecret(void) { - return virConnectOpen(geteuid() =3D=3D 0 ? "secret:///system" : "secre= t:///session"); + virConnectPtr conn; + + if (virConnectCacheInitialize() < 0) + return NULL; + + conn =3D virThreadLocalGet(&connectSecret); + if (conn) { + VIR_DEBUG("Return cached secret connection %p", conn); + virObjectRef(conn); + } else { + conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "secret:///system" : = "secret:///session"); + VIR_DEBUG("Opened new secret connection %p", conn); + } + return conn; } =20 virConnectPtr virGetConnectStorage(void) { - return virConnectOpen(geteuid() =3D=3D 0 ? "storage:///system" : "stor= age:///session"); + virConnectPtr conn; + + if (virConnectCacheInitialize() < 0) + return NULL; + + conn =3D virThreadLocalGet(&connectStorage); + if (conn) { + VIR_DEBUG("Return cached storage connection %p", conn); + virObjectRef(conn); + } else { + conn =3D virConnectOpen(geteuid() =3D=3D 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); } diff --git a/src/driver.h b/src/driver.h index fe0cec0923..c86da85481 100644 --- a/src/driver.h +++ b/src/driver.h @@ -112,4 +112,11 @@ virConnectPtr virGetConnectNodeDev(void); virConnectPtr virGetConnectSecret(void); virConnectPtr virGetConnectStorage(void); =20 +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__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3b14d7d158..7b05e4418f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1202,6 +1202,12 @@ virGetConnectNodeDev; virGetConnectNWFilter; virGetConnectSecret; virGetConnectStorage; +virSetConnectInterface; +virSetConnectNetwork; +virSetConnectNodeDev; +virSetConnectNWFilter; +virSetConnectSecret; +virSetConnectStorage; =20 =20 # libvirt_internal.h --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list