From nobody Wed Feb 11 08:39: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 1491479316691980.6672598508283; Thu, 6 Apr 2017 04:48:36 -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 26F1580F95; Thu, 6 Apr 2017 11:48:35 +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 D3AF59A59B; Thu, 6 Apr 2017 11:48: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 872D718523C8; Thu, 6 Apr 2017 11:48:34 +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 v36BmLfl029861 for ; Thu, 6 Apr 2017 07:48:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 70B41A8623; 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 300C0A861B for ; Thu, 6 Apr 2017 11:48:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 26F1580F95 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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 26F1580F95 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 07:48:09 -0400 Message-Id: <20170406114814.31184-3-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 2/7] storage: Introduce virStoragePoolObjVolumeGetNames 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.27]); Thu, 06 Apr 2017 11:48:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Mostly code motion to move storagePoolListVolumes code into virstorageobj.c and rename to virStoragePoolObjVolumeGetNames. Also includes a couple of variable name adjustments to keep code consistent with other drivers. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 30 ++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 8 ++++++++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 24 ++++++------------------ src/test/test_driver.c | 21 ++++++--------------- 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index e57694c..5933618 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -214,6 +214,36 @@ virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr = volumes, } =20 =20 +int +virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes, + virConnectPtr conn, + virStoragePoolDefPtr pooldef, + virStoragePoolVolumeACLFilter aclfilter, + char **const names, + int maxnames) +{ + int nnames =3D 0; + size_t i; + + for (i =3D 0; i < volumes->count && nnames < maxnames; i++) { + virStorageVolDefPtr def =3D volumes->objs[i]; + if (aclfilter && !aclfilter(conn, pooldef, def)) + continue; + if (VIR_STRDUP(names[nnames++], def->name) < 0) + goto failure; + } + + return nnames; + + failure: + while (--nnames >=3D 0) + VIR_FREE(names[nnames]); + memset(names, 0, maxnames * sizeof(*names)); + + return -1; +} + + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 3effe7a..bf88094 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -119,6 +119,14 @@ virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr = volumes, virStoragePoolDefPtr pooldef, virStoragePoolVolumeACLFilter aclfilter); =20 +int +virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes, + virConnectPtr conn, + virStoragePoolDefPtr pooldef, + virStoragePoolVolumeACLFilter aclfilter, + char **const names, + int maxnames); + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9580622..a635cac 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1007,6 +1007,7 @@ virStoragePoolObjRemove; virStoragePoolObjSaveDef; virStoragePoolObjSourceFindDuplicate; virStoragePoolObjUnlock; +virStoragePoolObjVolumeGetNames; =20 =20 # cpu/cpu.h diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 7d2f74d..ce77fe1 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1411,14 +1411,14 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj) return ret; } =20 + static int storagePoolListVolumes(virStoragePoolPtr obj, char **const names, int maxnames) { virStoragePoolObjPtr pool; - size_t i; - int n =3D 0; + int n =3D -1; =20 memset(names, 0, maxnames * sizeof(*names)); =20 @@ -1434,24 +1434,12 @@ storagePoolListVolumes(virStoragePoolPtr obj, goto cleanup; } =20 - for (i =3D 0; i < pool->volumes.count && n < maxnames; i++) { - if (!virStoragePoolListVolumesCheckACL(obj->conn, pool->def, - pool->volumes.objs[i])) - continue; - if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0) - goto cleanup; - } - - virStoragePoolObjUnlock(pool); - return n; - + n =3D virStoragePoolObjVolumeGetNames(&pool->volumes, obj->conn, pool-= >def, + virStoragePoolListVolumesCheckACL, + names, maxnames); cleanup: virStoragePoolObjUnlock(pool); - for (n =3D 0; n < maxnames; n++) - VIR_FREE(names[n]); - - memset(names, 0, maxnames * sizeof(*names)); - return -1; + return n; } =20 static int diff --git a/src/test/test_driver.c b/src/test/test_driver.c index a4b5833..b2840fa 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4830,6 +4830,7 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool) return ret; } =20 + static int testStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, @@ -4837,8 +4838,7 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, { testDriverPtr privconn =3D pool->conn->privateData; virStoragePoolObjPtr privpool; - size_t i =3D 0; - int n =3D 0; + int n =3D -1; =20 memset(names, 0, maxnames * sizeof(*names)); =20 @@ -4851,24 +4851,15 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, goto cleanup; } =20 - for (i =3D 0; i < privpool->volumes.count && n < maxnames; i++) { - if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0) - goto cleanup; - } + n =3D virStoragePoolObjVolumeGetNames(&privpool->volumes, pool->conn, + privpool->def, NULL, names, maxnam= es); =20 + cleanup: virStoragePoolObjUnlock(privpool); return n; - - cleanup: - for (n =3D 0; n < maxnames; n++) - VIR_FREE(names[i]); - - memset(names, 0, maxnames * sizeof(*names)); - if (privpool) - virStoragePoolObjUnlock(privpool); - return -1; } =20 + static int testStoragePoolListAllVolumes(virStoragePoolPtr obj, virStorageVolPtr **vols, --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list