From nobody Wed Feb 11 10:14:00 2026 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.zoho.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 1490516675329515.2510201218031; Sun, 26 Mar 2017 01:24:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF77F61BA3; Sun, 26 Mar 2017 08:24:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96038A68E3; Sun, 26 Mar 2017 08:24:34 +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 4A3A75ED64; Sun, 26 Mar 2017 08:24:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2PCq8ZB032146 for ; Sat, 25 Mar 2017 08:52:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id BFAA67820A; Sat, 25 Mar 2017 12:52:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B1C680B15; Sat, 25 Mar 2017 12:52:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BF77F61BA3 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BF77F61BA3 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 25 Mar 2017 08:51:58 -0400 Message-Id: <20170325125159.21975-2-jferlan@redhat.com> In-Reply-To: <20170325125159.21975-1-jferlan@redhat.com> References: <20170325125159.21975-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: caoxinhua@huawei.com Subject: [libvirt] [PATCH 1/2] daemon: Rework remoteClientFreeFunc cleanup loops into C macro 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 26 Mar 2017 08:24:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than 'n' repetitive code segments, let's create a single macro which will make the code easier to read. Signed-off-by: John Ferlan --- daemon/remote.c | 120 +++++++++++++++-------------------------------------= ---- 1 file changed, 31 insertions(+), 89 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 1c9708c..6fdafce 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1623,6 +1623,24 @@ void remoteRelayConnectionClosedEvent(virConnectPtr = conn ATTRIBUTE_UNUSED, int r &msg); } =20 +#define CLEAN_EVENT_CALLBACK(conn, eventCallbacks, neventCallbacks, name) = \ + do { = \ + size_t i; = \ + for (i =3D 0; i < neventCallbacks; i++) { = \ + int callbackID =3D eventCallbacks[i]->callbackID; = \ + if (callbackID < 0) { = \ + VIR_WARN("unexpected incomplete %s callback %zu", name, i)= ; \ + continue; = \ + } = \ + VIR_DEBUG("Deregistering remote %s event relay %d", = \ + name, callbackID); = \ + eventCallbacks[i]->callbackID =3D -1; = \ + if (virConnectDomainEventDeregisterAny(conn, callbackID) < 0) = \ + VIR_WARN("unexpected %s event deregister failure", name); = \ + } = \ + VIR_FREE(eventCallbacks); = \ + } while (0); + /* * You must hold lock for at least the client * We don't free stuff here, merely disconnect the client's @@ -1637,98 +1655,21 @@ void remoteClientFreeFunc(void *data) /* Deregister event delivery callback */ if (priv->conn) { virIdentityPtr sysident =3D virIdentityGetSystem(); - size_t i; =20 virIdentitySetCurrent(sysident); =20 - for (i =3D 0; i < priv->ndomainEventCallbacks; i++) { - int callbackID =3D priv->domainEventCallbacks[i]->callbackID; - if (callbackID < 0) { - VIR_WARN("unexpected incomplete domain callback %zu", i); - continue; - } - VIR_DEBUG("Deregistering remote domain event relay %d", - callbackID); - priv->domainEventCallbacks[i]->callbackID =3D -1; - if (virConnectDomainEventDeregisterAny(priv->conn, callbackID)= < 0) - VIR_WARN("unexpected domain event deregister failure"); - } - VIR_FREE(priv->domainEventCallbacks); - - for (i =3D 0; i < priv->nnetworkEventCallbacks; i++) { - int callbackID =3D priv->networkEventCallbacks[i]->callbackID; - if (callbackID < 0) { - VIR_WARN("unexpected incomplete network callback %zu", i); - continue; - } - VIR_DEBUG("Deregistering remote network event relay %d", - callbackID); - priv->networkEventCallbacks[i]->callbackID =3D -1; - if (virConnectNetworkEventDeregisterAny(priv->conn, - callbackID) < 0) - VIR_WARN("unexpected network event deregister failure"); - } - VIR_FREE(priv->networkEventCallbacks); - - for (i =3D 0; i < priv->nstorageEventCallbacks; i++) { - int callbackID =3D priv->storageEventCallbacks[i]->callbackID; - if (callbackID < 0) { - VIR_WARN("unexpected incomplete storage pool callback %zu"= , i); - continue; - } - VIR_DEBUG("Deregistering remote storage pool event relay %d", - callbackID); - priv->storageEventCallbacks[i]->callbackID =3D -1; - if (virConnectStoragePoolEventDeregisterAny(priv->conn, - callbackID) < 0) - VIR_WARN("unexpected storage pool event deregister failure= "); - } - VIR_FREE(priv->storageEventCallbacks); - - for (i =3D 0; i < priv->nnodeDeviceEventCallbacks; i++) { - int callbackID =3D priv->nodeDeviceEventCallbacks[i]->callback= ID; - if (callbackID < 0) { - VIR_WARN("unexpected incomplete node device callback %zu",= i); - continue; - } - VIR_DEBUG("Deregistering remote node device event relay %d", - callbackID); - priv->nodeDeviceEventCallbacks[i]->callbackID =3D -1; - if (virConnectNodeDeviceEventDeregisterAny(priv->conn, - callbackID) < 0) - VIR_WARN("unexpected node device event deregister failure"= ); - } - VIR_FREE(priv->nodeDeviceEventCallbacks); - - for (i =3D 0; i < priv->nsecretEventCallbacks; i++) { - int callbackID =3D priv->secretEventCallbacks[i]->callbackID; - if (callbackID < 0) { - VIR_WARN("unexpected incomplete secret callback %zu", i); - continue; - } - VIR_DEBUG("Deregistering remote secret event relay %d", - callbackID); - priv->secretEventCallbacks[i]->callbackID =3D -1; - if (virConnectSecretEventDeregisterAny(priv->conn, - callbackID) < 0) - VIR_WARN("unexpected secret event deregister failure"); - } - VIR_FREE(priv->secretEventCallbacks); - - for (i =3D 0; i < priv->nqemuEventCallbacks; i++) { - int callbackID =3D priv->qemuEventCallbacks[i]->callbackID; - if (callbackID < 0) { - VIR_WARN("unexpected incomplete qemu monitor callback %zu"= , i); - continue; - } - VIR_DEBUG("Deregistering remote qemu monitor event relay %d", - callbackID); - priv->qemuEventCallbacks[i]->callbackID =3D -1; - if (virConnectDomainQemuMonitorEventDeregister(priv->conn, - callbackID) < 0) - VIR_WARN("unexpected qemu monitor event deregister failure= "); - } - VIR_FREE(priv->qemuEventCallbacks); + CLEAN_EVENT_CALLBACK(priv->conn, priv->domainEventCallbacks, + priv->ndomainEventCallbacks, "domain"); + CLEAN_EVENT_CALLBACK(priv->conn, priv->networkEventCallbacks, + priv->nnetworkEventCallbacks, "network"); + CLEAN_EVENT_CALLBACK(priv->conn, priv->storageEventCallbacks, + priv->nstorageEventCallbacks, "storage"); + CLEAN_EVENT_CALLBACK(priv->conn, priv->nodeDeviceEventCallbacks, + priv->nnodeDeviceEventCallbacks, "node device= "); + CLEAN_EVENT_CALLBACK(priv->conn, priv->secretEventCallbacks, + priv->nsecretEventCallbacks, "secret"); + CLEAN_EVENT_CALLBACK(priv->conn, priv->qemuEventCallbacks, + priv->nqemuEventCallbacks, "qemu monitor"); =20 if (priv->closeRegistered) { if (virConnectUnregisterCloseCallback(priv->conn, @@ -1744,6 +1685,7 @@ void remoteClientFreeFunc(void *data) =20 VIR_FREE(priv); } +#undef CLEAN_EVENT_CALLBACK =20 =20 static void remoteClientCloseFunc(virNetServerClientPtr client) --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list