From nobody Sun Feb 8 21:33:46 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 1491487754850879.1196874572424; Thu, 6 Apr 2017 07:09:14 -0700 (PDT) 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 7F15F8E3E6; Thu, 6 Apr 2017 14:09:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C74CAA3058; Thu, 6 Apr 2017 14:09:11 +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 BE8E818521C6; Thu, 6 Apr 2017 14:09:09 +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 v36E99Xl018219 for ; Thu, 6 Apr 2017 10:09:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id F16189E915; Thu, 6 Apr 2017 14:09:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-19.phx2.redhat.com [10.3.116.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFA4F9E8F2 for ; Thu, 6 Apr 2017 14:09:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7F15F8E3E6 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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 7F15F8E3E6 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 10:08:53 -0400 Message-Id: <20170406140855.31205-2-jferlan@redhat.com> In-Reply-To: <20170406140855.31205-1-jferlan@redhat.com> References: <20170406140855.31205-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] interface: Introduce virInterfaceObjNumOfInterfaces 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 06 Apr 2017 14:09:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Unlike other drivers, this is a test driver only API. Still combining the logic of testConnectNumOfInterfaces and testConnectNumOfDefinedInterfac= es makes things a bit easier in the long run. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 20 ++++++++++++++++++++ src/conf/virinterfaceobj.h | 4 ++++ src/libvirt_private.syms | 1 + src/test/test_driver.c | 24 ++++++------------------ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 3af972b..0407c1f 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -215,3 +215,23 @@ virInterfaceObjRemove(virInterfaceObjListPtr interface= s, virInterfaceObjUnlock(interfaces->objs[i]); } } + + +int +virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces, + bool wantActive) +{ + size_t i; + int ninterfaces =3D 0; + + for (i =3D 0; (i < interfaces->count); i++) { + virInterfaceObjPtr obj =3D interfaces->objs[i]; + virInterfaceObjLock(obj); + if ((wantActive && virInterfaceObjIsActive(obj)) || + (!wantActive && !virInterfaceObjIsActive(obj))) + ninterfaces++; + virInterfaceObjUnlock(obj); + } + + return ninterfaces; +} diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 6c5e2e7..2f07174 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -81,4 +81,8 @@ typedef bool (*virInterfaceObjListFilter)(virConnectPtr conn, virInterfaceDefPtr def); =20 +int +virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces, + bool wantActive); + #endif /* __VIRINTERFACEOBJ_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 92083e5..96aacaa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -938,6 +938,7 @@ virInterfaceObjFindByName; virInterfaceObjListClone; virInterfaceObjListFree; virInterfaceObjLock; +virInterfaceObjNumOfInterfaces; virInterfaceObjRemove; virInterfaceObjUnlock; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cce4d2d..6910681 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3649,18 +3649,12 @@ testInterfaceObjFindByName(testDriverPtr privconn, static int testConnectNumOfInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; - size_t i; - int count =3D 0; + int ninterfaces; =20 testDriverLock(privconn); - for (i =3D 0; (i < privconn->ifaces.count); i++) { - virInterfaceObjLock(privconn->ifaces.objs[i]); - if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) - count++; - virInterfaceObjUnlock(privconn->ifaces.objs[i]); - } + ninterfaces =3D virInterfaceObjNumOfInterfaces(&privconn->ifaces, true= ); testDriverUnlock(privconn); - return count; + return ninterfaces; } =20 static int testConnectListInterfaces(virConnectPtr conn, char **const name= s, int nnames) @@ -3695,18 +3689,12 @@ static int testConnectListInterfaces(virConnectPtr = conn, char **const names, int static int testConnectNumOfDefinedInterfaces(virConnectPtr conn) { testDriverPtr privconn =3D conn->privateData; - size_t i; - int count =3D 0; + int ninterfaces; =20 testDriverLock(privconn); - for (i =3D 0; i < privconn->ifaces.count; i++) { - virInterfaceObjLock(privconn->ifaces.objs[i]); - if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) - count++; - virInterfaceObjUnlock(privconn->ifaces.objs[i]); - } + ninterfaces =3D virInterfaceObjNumOfInterfaces(&privconn->ifaces, fals= e); testDriverUnlock(privconn); - return count; + return ninterfaces; } =20 static int testConnectListDefinedInterfaces(virConnectPtr conn, char **con= st names, int nnames) --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list