From nobody Sun Feb 8 16:30:59 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 1491479313351526.2018997942769; Thu, 6 Apr 2017 04:48:33 -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 0659D7D0CE; Thu, 6 Apr 2017 11:48:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7486CA3033; Thu, 6 Apr 2017 11:48:31 +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 300FE4BB75; Thu, 6 Apr 2017 11:48:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v36BmL6e029856 for ; Thu, 6 Apr 2017 07:48:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 08E4AA861B; Thu, 6 Apr 2017 11:48:21 +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 BC4BBA8623 for ; Thu, 6 Apr 2017 11:48:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0659D7D0CE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 0659D7D0CE From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 07:48:08 -0400 Message-Id: <20170406114814.31184-2-jferlan@redhat.com> In-Reply-To: <20170406114814.31184-1-jferlan@redhat.com> References: <20170406114814.31184-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] storage: Introduce virStoragePoolObjNumOfVolumes 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.26]); Thu, 06 Apr 2017 11:48:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Unify the NumOfVolumes API into virstorageobj.c from storage_driver and test_driver. The only real difference between the two is the test driver doesn't call using the aclfilter API. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 19 +++++++++++++++++++ src/conf/virstorageobj.h | 11 +++++++++++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 10 +++------- src/test/test_driver.c | 3 ++- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 34f2eb7..e57694c 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -195,6 +195,25 @@ virStorageVolDefFindByName(virStoragePoolObjPtr pool, } =20 =20 +int +virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, + virConnectPtr conn, + virStoragePoolDefPtr pooldef, + virStoragePoolVolumeACLFilter aclfilter) +{ + int nvolumes =3D 0; + size_t i; + + for (i =3D 0; i < volumes->count; i++) { + virStorageVolDefPtr def =3D volumes->objs[i]; + if (aclfilter && aclfilter(conn, pooldef, def)) + nvolumes++; + } + + return nvolumes; +} + + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index ecba94e..3effe7a 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -108,6 +108,17 @@ virStorageVolDefFindByName(virStoragePoolObjPtr pool, void virStoragePoolObjClearVols(virStoragePoolObjPtr pool); =20 +typedef bool +(*virStoragePoolVolumeACLFilter)(virConnectPtr conn, + virStoragePoolDefPtr pool, + virStorageVolDefPtr def); + +int +virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, + virConnectPtr conn, + virStoragePoolDefPtr pooldef, + virStoragePoolVolumeACLFilter aclfilter); + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 92083e5..9580622 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1002,6 +1002,7 @@ virStoragePoolObjListFree; virStoragePoolObjLoadAllConfigs; virStoragePoolObjLoadAllState; virStoragePoolObjLock; +virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; virStoragePoolObjSaveDef; virStoragePoolObjSourceFindDuplicate; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index fea7698..7d2f74d 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1390,7 +1390,6 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj) { virStoragePoolObjPtr pool; int ret =3D -1; - size_t i; =20 if (!(pool =3D virStoragePoolObjFromStoragePool(obj))) return -1; @@ -1403,12 +1402,9 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj) _("storage pool '%s' is not active"), pool->def->na= me); goto cleanup; } - ret =3D 0; - for (i =3D 0; i < pool->volumes.count; i++) { - if (virStoragePoolNumOfVolumesCheckACL(obj->conn, pool->def, - pool->volumes.objs[i])) - ret++; - } + + ret =3D virStoragePoolObjNumOfVolumes(&pool->volumes, obj->conn, pool-= >def, + virStoragePoolNumOfVolumesCheckACL= ); =20 cleanup: virStoragePoolObjUnlock(pool); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cce4d2d..a4b5833 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4821,7 +4821,8 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool) goto cleanup; } =20 - ret =3D privpool->volumes.count; + ret =3D virStoragePoolObjNumOfVolumes(&privpool->volumes, pool->conn, + privpool->def, NULL); =20 cleanup: if (privpool) --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list