From nobody Sun Feb 8 16:24:13 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 1491479306069252.59980195440517; Thu, 6 Apr 2017 04:48:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6146AC0094F0; Thu, 6 Apr 2017 11:48:24 +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 2F51899672; Thu, 6 Apr 2017 11:48:24 +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 BA14C18523C7; Thu, 6 Apr 2017 11:48:23 +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 v36BmLfN029869 for ; Thu, 6 Apr 2017 07:48:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9C9AA8633; 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 9760AA861B for ; Thu, 6 Apr 2017 11:48:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6146AC0094F0 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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 6146AC0094F0 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 07:48:10 -0400 Message-Id: <20170406114814.31184-4-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 3/7] storage: Introduce virStoragePoolObjVolumeListExport 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 06 Apr 2017 11:48:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Essentially code motion to move the storage/test driver ListAllVolumes logic into virstorageobj.c Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 47 ++++++++++++++++++++++++++++++++++++++++= ++++ src/conf/virstorageobj.h | 7 +++++++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 37 ++++------------------------------ src/test/test_driver.c | 40 ++++--------------------------------- 5 files changed, 63 insertions(+), 69 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 5933618..2484517 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -244,6 +244,53 @@ virStoragePoolObjVolumeGetNames(virStorageVolDefListPt= r volumes, } =20 =20 +int +virStoragePoolObjVolumeListExport(virConnectPtr conn, + virStorageVolDefListPtr volumes, + virStoragePoolDefPtr pooldef, + virStorageVolPtr **vols, + virStoragePoolVolumeACLFilter aclfilter) +{ + int ret =3D -1; + size_t i; + virStorageVolPtr *tmp_vols =3D NULL; + virStorageVolPtr vol =3D NULL; + int nvols =3D 0; + + /* Just returns the volumes count */ + if (!vols) { + ret =3D volumes->count; + goto cleanup; + } + + if (VIR_ALLOC_N(tmp_vols, volumes->count + 1) < 0) + goto cleanup; + + for (i =3D 0; i < volumes->count; i++) { + virStorageVolDefPtr def =3D volumes->objs[i]; + if (aclfilter && !aclfilter(conn, pooldef, def)) + continue; + if (!(vol =3D virGetStorageVol(conn, pooldef->name, def->name, def= ->key, + NULL, NULL))) + goto cleanup; + tmp_vols[nvols++] =3D vol; + } + + *vols =3D tmp_vols; + tmp_vols =3D NULL; + ret =3D nvols; + + cleanup: + if (tmp_vols) { + for (i =3D 0; i < nvols; i++) + virObjectUnref(tmp_vols[i]); + VIR_FREE(tmp_vols); + } + + return ret; +} + + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index bf88094..72daa5a 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -127,6 +127,13 @@ virStoragePoolObjVolumeGetNames(virStorageVolDefListPt= r volumes, char **const names, int maxnames); =20 +int +virStoragePoolObjVolumeListExport(virConnectPtr conn, + virStorageVolDefListPtr volumes, + virStoragePoolDefPtr pooldef, + virStorageVolPtr **vols, + virStoragePoolVolumeACLFilter aclfilter); + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a635cac..6298019 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1008,6 +1008,7 @@ virStoragePoolObjSaveDef; virStoragePoolObjSourceFindDuplicate; virStoragePoolObjUnlock; virStoragePoolObjVolumeGetNames; +virStoragePoolObjVolumeListExport; =20 =20 # cpu/cpu.h diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index ce77fe1..475e332 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1442,16 +1442,13 @@ storagePoolListVolumes(virStoragePoolPtr obj, return n; } =20 + static int storagePoolListAllVolumes(virStoragePoolPtr pool, virStorageVolPtr **vols, unsigned int flags) { virStoragePoolObjPtr obj; - size_t i; - virStorageVolPtr *tmp_vols =3D NULL; - virStorageVolPtr vol =3D NULL; - int nvols =3D 0; int ret =3D -1; =20 virCheckFlags(0, -1); @@ -1468,38 +1465,12 @@ storagePoolListAllVolumes(virStoragePoolPtr pool, goto cleanup; } =20 - /* Just returns the volumes count */ - if (!vols) { - ret =3D obj->volumes.count; - goto cleanup; - } + ret =3D virStoragePoolObjVolumeListExport(pool->conn, &obj->volumes, + obj->def, vols, + virStoragePoolListAllVolumesCh= eckACL); =20 - if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0) - goto cleanup; - - for (i =3D 0; i < obj->volumes.count; i++) { - if (!virStoragePoolListAllVolumesCheckACL(pool->conn, obj->def, - obj->volumes.objs[i])) - continue; - if (!(vol =3D virGetStorageVol(pool->conn, obj->def->name, - obj->volumes.objs[i]->name, - obj->volumes.objs[i]->key, - NULL, NULL))) - goto cleanup; - tmp_vols[nvols++] =3D vol; - } - - *vols =3D tmp_vols; - tmp_vols =3D NULL; - ret =3D nvols; =20 cleanup: - if (tmp_vols) { - for (i =3D 0; i < nvols; i++) - virObjectUnref(tmp_vols[i]); - VIR_FREE(tmp_vols); - } - virStoragePoolObjUnlock(obj); =20 return ret; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b2840fa..44bd47c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4867,16 +4867,12 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj, { testDriverPtr privconn =3D obj->conn->privateData; virStoragePoolObjPtr pool; - size_t i; - virStorageVolPtr *tmp_vols =3D NULL; - virStorageVolPtr vol =3D NULL; - int nvols =3D 0; int ret =3D -1; =20 virCheckFlags(0, -1); =20 if (!(pool =3D testStoragePoolObjFindByUUID(privconn, obj->uuid))) - goto cleanup; + return -1; =20 if (!virStoragePoolObjIsActive(pool)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4884,39 +4880,11 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj, goto cleanup; } =20 - /* Just returns the volumes count */ - if (!vols) { - ret =3D pool->volumes.count; - goto cleanup; - } - - if (VIR_ALLOC_N(tmp_vols, pool->volumes.count + 1) < 0) - goto cleanup; - - for (i =3D 0; i < pool->volumes.count; i++) { - if (!(vol =3D virGetStorageVol(obj->conn, pool->def->name, - pool->volumes.objs[i]->name, - pool->volumes.objs[i]->key, - NULL, NULL))) - goto cleanup; - tmp_vols[nvols++] =3D vol; - } - - *vols =3D tmp_vols; - tmp_vols =3D NULL; - ret =3D nvols; + ret =3D virStoragePoolObjVolumeListExport(obj->conn, &pool->volumes, + pool->def, vols, NULL); =20 cleanup: - if (tmp_vols) { - for (i =3D 0; i < nvols; i++) { - if (tmp_vols[i]) - virStorageVolFree(tmp_vols[i]); - } - VIR_FREE(tmp_vols); - } - - if (pool) - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(pool); =20 return ret; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list