From nobody Wed May 14 23:08:02 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516641399564807.1483675418158; Mon, 22 Jan 2018 09:16:39 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED174780F2; Mon, 22 Jan 2018 17:16:37 +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 B86AE9CA8; Mon, 22 Jan 2018 17:16:37 +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 60E8C3FC74; Mon, 22 Jan 2018 17:16:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0MHGL1e028537 for ; Mon, 22 Jan 2018 12:16:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1C22C4A3; Mon, 22 Jan 2018 17:16:21 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 435F45C3F7; Mon, 22 Jan 2018 17:16:19 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 22 Jan 2018 18:16:02 +0100 Message-Id: <05e209a9f8943af758028f7750be9a092d0f0b5e.1516640486.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: lars@karlitski.net Subject: [libvirt] [dbus RFC 04/11] connect: implement lazy connection 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: , MIME-Version: 1.0 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 22 Jan 2018 17:16:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Open a connection to libvirt only when it is required. Signed-off-by: Pavel Hrdina Reviewed-by: Daniel P. Berrange --- src/connect.c | 41 +++++++++++++++++++++++++++++++++++------ src/connect.h | 1 + 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/connect.c b/src/connect.c index cb19c39..8d958c2 100644 --- a/src/connect.c +++ b/src/connect.c @@ -6,6 +6,23 @@ #include #include =20 +static int +virtDBusConnectOpen(virtDBusConnect *connect, + sd_bus_error *error) +{ + if (connect->connection) + return 0; + + connect->connection =3D virConnectOpenAuth(connect->uri, + virConnectAuthPtrDefault, 0); + if (!connect->connection) + return virtDBusUtilSetLastVirtError(error); + + virtDBusEventsRegister(connect); + + return 0; +} + static int virtDBusConnectEnumarateDomains(sd_bus *bus VIR_ATTR_UNUSED, const char *path VIR_ATTR_UNUSED, @@ -17,6 +34,11 @@ virtDBusConnectEnumarateDomains(sd_bus *bus VIR_ATTR_UNU= SED, _cleanup_(virtDBusUtilVirDomainListFreep) virDomainPtr *domains =3D NU= LL; _cleanup_(virtDBusUtilStrvFreep) char **paths =3D NULL; int n_domains; + int r; + + r =3D virtDBusConnectOpen(connect, error); + if (r < 0) + return r; =20 n_domains =3D virConnectListAllDomains(connect->connection, &domains, = 0); if (n_domains < 0) @@ -44,6 +66,10 @@ virtDBusConnectListDomains(sd_bus_message *message, uint32_t flags; int r; =20 + r =3D virtDBusConnectOpen(connect, error); + if (r < 0) + return r; + r =3D sd_bus_message_read(message, "u", &flags); if (r < 0) return r; @@ -89,6 +115,10 @@ virtDBusConnectCreateXML(sd_bus_message *message, _cleanup_(virtDBusUtilFreep) char *path =3D NULL; int r; =20 + r =3D virtDBusConnectOpen(connect, error); + if (r < 0) + return r; + r =3D sd_bus_message_read(message, "su", &xml, &flags); if (r < 0) return r; @@ -113,6 +143,10 @@ virtDBusConnectDefineXML(sd_bus_message *message, _cleanup_(virtDBusUtilFreep) char *path =3D NULL; int r; =20 + r =3D virtDBusConnectOpen(connect, error); + if (r < 0) + return r; + r =3D sd_bus_message_read(message, "s", &xml); if (r < 0) return r; @@ -159,12 +193,7 @@ virtDBusConnectNew(virtDBusConnect **connectp, connect->callback_ids[i] =3D -1; =20 connect->bus =3D sd_bus_ref(bus); - - connect->connection =3D virConnectOpenAuth(uri, virConnectAuthPtrDefau= lt, 0); - if (!connect->connection) - return -EINVAL; - - virtDBusEventsRegister(connect); + connect->uri =3D uri; =20 r =3D sd_bus_add_object_vtable(connect->bus, NULL, diff --git a/src/connect.h b/src/connect.h index 5d64a10..52e8279 100644 --- a/src/connect.h +++ b/src/connect.h @@ -7,6 +7,7 @@ =20 struct virtDBusConnect { sd_bus *bus; + const char *uri; virConnectPtr connection; =20 int callback_ids[VIR_DOMAIN_EVENT_ID_LAST]; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list