From nobody Wed May 14 23:29:52 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 1516641394819896.0826304462963; Mon, 22 Jan 2018 09:16:34 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A73CC056789; Mon, 22 Jan 2018 17:16:33 +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 EFCD667641; Mon, 22 Jan 2018 17:16:32 +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 B60DB3FAEA; Mon, 22 Jan 2018 17:16:32 +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 w0MHGNFI028708 for ; Mon, 22 Jan 2018 12:16:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id BA2D65F704; Mon, 22 Jan 2018 17:16:23 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id E42FC5E1D3; Mon, 22 Jan 2018 17:16:22 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 22 Jan 2018 18:16:04 +0100 Message-Id: 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 06/11] connect: implement reconnect functionality to libvirt 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 22 Jan 2018 17:16:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If the connection dies for some reason between D-Bus calls we need to properly reconnect because the current connection is not usable anymore. Without this the only solution would be to restart the libvirt-dbus daemon. Signed-off-by: Pavel Hrdina Reviewed-by: Daniel P. Berrange --- src/connect.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/connect.c b/src/connect.c index 9de764c..10183f3 100644 --- a/src/connect.c +++ b/src/connect.c @@ -4,6 +4,7 @@ #include "util.h" =20 #include +#include #include =20 static int virtDBusConnectCredType[] =3D { @@ -34,12 +35,34 @@ static virConnectAuth virtDBusConnectAuth =3D { NULL, }; =20 +static void +virtDBusConnectClose(virtDBusConnect *connect, + bool deregisterEvents) +{ + + for (int i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i +=3D 1) { + if (connect->callback_ids[i] >=3D 0) { + if (deregisterEvents) { + virConnectDomainEventDeregisterAny(connect->connection, + connect->callback_ids[i= ]); + } + connect->callback_ids[i] =3D -1; + } + } + + virConnectClose(connect->connection); +} + static int virtDBusConnectOpen(virtDBusConnect *connect, sd_bus_error *error) { - if (connect->connection) - return 0; + if (connect->connection) { + if (virConnectIsAlive(connect->connection)) + return 0; + else + virtDBusConnectClose(connect, false); + } =20 virtDBusConnectAuth.cbdata =3D error; =20 @@ -254,14 +277,8 @@ virtDBusConnectFree(virtDBusConnect *connect) if (connect->bus) sd_bus_unref(connect->bus); =20 - if (connect->connection) { - for (int i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i +=3D 1) { - if (connect->callback_ids[i] >=3D 0) - virConnectDomainEventDeregisterAny(connect->connection, co= nnect->callback_ids[i]); - } - - virConnectClose(connect->connection); - } + if (connect->connection) + virtDBusConnectClose(connect, true); =20 free(connect); =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list