From nobody Sun Feb 8 14:52:04 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 1491852986941165.7840167652663; Mon, 10 Apr 2017 12:36:26 -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 308E08048D; Mon, 10 Apr 2017 19:35:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0375D182C0; Mon, 10 Apr 2017 19:35:55 +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 A2C52410AF; Mon, 10 Apr 2017 19:35:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3AJZnYA017125 for ; Mon, 10 Apr 2017 15:35:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 20CDA17B46; Mon, 10 Apr 2017 19:35:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-15.phx2.redhat.com [10.3.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id D20D317AD2 for ; Mon, 10 Apr 2017 19:35:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 308E08048D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 308E08048D From: John Ferlan To: libvir-list@redhat.com Date: Mon, 10 Apr 2017 15:35:43 -0400 Message-Id: <20170410193544.1347-3-jferlan@redhat.com> In-Reply-To: <20170410193544.1347-1-jferlan@redhat.com> References: <20170410193544.1347-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/3] nwfilter: Introduce virNWFilterObjGetNames 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.28]); Mon, 10 Apr 2017 19:35:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Mostly code motion to move nwfilterConnectListNWFilters into nwfilterobj.c and rename to virNWFilterObjGetNames. Also includes a couple of variable name adjustments to keep code consistent with other drivers. Signed-off-by: John Ferlan --- src/conf/virnwfilterobj.c | 33 +++++++++++++++++++++++++++++++++ src/conf/virnwfilterobj.h | 7 +++++++ src/libvirt_private.syms | 1 + src/nwfilter/nwfilter_driver.c | 29 ++++++----------------------- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index 5f5da5a..ce19e60 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -325,6 +325,39 @@ virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwf= ilters, } =20 =20 +int +virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters, + virConnectPtr conn, + virNWFilterObjListFilter aclfilter, + char **const names, + int maxnames) +{ + int nnames =3D 0; + size_t i; + + for (i =3D 0; i < nwfilters->count && nnames < maxnames; i++) { + virNWFilterObjPtr obj =3D nwfilters->objs[i]; + virNWFilterObjLock(obj); + if (!aclfilter || aclfilter(conn, obj->def)) { + if (VIR_STRDUP(names[nnames], obj->def->name) < 0) { + virNWFilterObjUnlock(obj); + goto failure; + } + nnames++; + } + virNWFilterObjUnlock(obj); + } + + return nnames; + + failure: + while (--nnames >=3D 0) + VIR_FREE(names[nnames]); + + return -1; +} + + static virNWFilterObjPtr virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters, const char *configDir, diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index a8ecc35..cd1600c 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -91,6 +91,13 @@ virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfil= ters, virNWFilterObjListFilter aclfilter); =20 int +virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters, + virConnectPtr conn, + virNWFilterObjListFilter aclfilter, + char **const names, + int maxnames); + +int virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters, const char *configDir); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dfc7d10..033cdc6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -962,6 +962,7 @@ virNodeDeviceObjUnlock; virNWFilterObjAssignDef; virNWFilterObjFindByName; virNWFilterObjFindByUUID; +virNWFilterObjGetNames; virNWFilterObjListFree; virNWFilterObjLoadAllConfigs; virNWFilterObjLock; diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 70bdea2..0d164a2 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -425,36 +425,19 @@ nwfilterConnectNumOfNWFilters(virConnectPtr conn) static int nwfilterConnectListNWFilters(virConnectPtr conn, char **const names, - int nnames) + int maxnames) { - int got =3D 0; - size_t i; + int nnames; =20 if (virConnectListNWFiltersEnsureACL(conn) < 0) return -1; =20 nwfilterDriverLock(); - for (i =3D 0; i < driver->nwfilters.count && got < nnames; i++) { - virNWFilterObjPtr obj =3D driver->nwfilters.objs[i]; - virNWFilterObjLock(obj); - if (virConnectListNWFiltersCheckACL(conn, obj->def)) { - if (VIR_STRDUP(names[got], obj->def->name) < 0) { - virNWFilterObjUnlock(obj); - goto cleanup; - } - got++; - } - virNWFilterObjUnlock(obj); - } - nwfilterDriverUnlock(); - return got; - - cleanup: + nnames =3D virNWFilterObjGetNames(&driver->nwfilters, conn, + virConnectListNWFiltersCheckACL, + names, maxnames); nwfilterDriverUnlock(); - for (i =3D 0; i < got; i++) - VIR_FREE(names[i]); - memset(names, 0, nnames * sizeof(*names)); - return -1; + return nnames; } =20 =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list