From nobody Sun Feb 8 19: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 1491479319854642.3088326722984; Thu, 6 Apr 2017 04:48:39 -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 94F963DBCA; Thu, 6 Apr 2017 11:48:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A49F99677; Thu, 6 Apr 2017 11:48:38 +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 0ECBBB3480; Thu, 6 Apr 2017 11:48:38 +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 v36BmNh6029881 for ; Thu, 6 Apr 2017 07:48:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id F11F4A861B; Thu, 6 Apr 2017 11:48:22 +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 AF3C4A8637 for ; Thu, 6 Apr 2017 11:48:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94F963DBCA Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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 94F963DBCA From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 07:48:12 -0400 Message-Id: <20170406114814.31184-6-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 5/7] storage: Introduce virStoragePoolObjGetNames 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.30]); Thu, 06 Apr 2017 11:48:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Mostly code motion to move storageConnectList[Defined]StoragePools and similar test driver code into virstorageobj.c and rename to virStoragePoolObjGetNames. Also includes a couple of variable name adjustments to keep code consistent with other drivers. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 37 ++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 8 ++++++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 58 +++++++++++-----------------------------= ---- src/test/test_driver.c | 48 +++++++++--------------------------- 5 files changed, 72 insertions(+), 80 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index f0201aa..a9367a2 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -580,6 +580,43 @@ virStoragePoolObjNumOfStoragePools(virStoragePoolObjLi= stPtr pools, } =20 =20 +int +virStoragePoolObjGetNames(virStoragePoolObjListPtr pools, + virConnectPtr conn, + bool wantActive, + virStoragePoolObjListACLFilter aclfilter, + char **const names, + int maxnames) +{ + int nnames =3D 0; + size_t i; + + for (i =3D 0; i < pools->count && nnames < maxnames; i++) { + virStoragePoolObjPtr obj =3D pools->objs[i]; + virStoragePoolObjLock(obj); + if (!aclfilter || aclfilter(conn, obj->def)) { + if ((wantActive && virStoragePoolObjIsActive(obj)) || + (!wantActive && !virStoragePoolObjIsActive(obj))) { + if (VIR_STRDUP(names[nnames++], obj->def->name) < 0) { + virStoragePoolObjUnlock(obj); + goto failure; + } + } + } + virStoragePoolObjUnlock(obj); + } + + return nnames; + + failure: + while (--nnames >=3D 0) + VIR_FREE(names[nnames]); + memset(names, 0, maxnames * sizeof(*names)); + + return -1; +} + + /* * virStoragePoolObjIsDuplicate: * @doms : virStoragePoolObjListPtr to search diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 5eeda1e..b651865 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -155,6 +155,14 @@ virStoragePoolObjNumOfStoragePools(virStoragePoolObjLi= stPtr pools, bool wantActive, virStoragePoolObjListACLFilter aclfilte= r); =20 +int +virStoragePoolObjGetNames(virStoragePoolObjListPtr pools, + virConnectPtr conn, + bool wantActive, + virStoragePoolObjListACLFilter aclfilter, + char **const names, + int maxnames); + void virStoragePoolObjFree(virStoragePoolObjPtr pool); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7bc3bc4..233110a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -996,6 +996,7 @@ virStoragePoolObjClearVols; virStoragePoolObjDeleteDef; virStoragePoolObjFindByName; virStoragePoolObjFindByUUID; +virStoragePoolObjGetNames; virStoragePoolObjIsDuplicate; virStoragePoolObjListExport; virStoragePoolObjListFree; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 065380b..9493da8 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -490,40 +490,25 @@ storageConnectNumOfStoragePools(virConnectPtr conn) return nactive; } =20 + static int storageConnectListStoragePools(virConnectPtr conn, char **const names, - int nnames) + int maxnames) { int got =3D 0; - size_t i; + + memset(names, 0, maxnames * sizeof(*names)); =20 if (virConnectListStoragePoolsEnsureACL(conn) < 0) return -1; =20 storageDriverLock(); - for (i =3D 0; i < driver->pools.count && got < nnames; i++) { - virStoragePoolObjPtr obj =3D driver->pools.objs[i]; - virStoragePoolObjLock(obj); - if (virConnectListStoragePoolsCheckACL(conn, obj->def) && - virStoragePoolObjIsActive(obj)) { - if (VIR_STRDUP(names[got], obj->def->name) < 0) { - virStoragePoolObjUnlock(obj); - goto cleanup; - } - got++; - } - virStoragePoolObjUnlock(obj); - } + got =3D virStoragePoolObjGetNames(&driver->pools, conn, true, + virConnectListStoragePoolsCheckACL, + names, maxnames); storageDriverUnlock(); return got; - - cleanup: - storageDriverUnlock(); - for (i =3D 0; i < got; i++) - VIR_FREE(names[i]); - memset(names, 0, nnames * sizeof(*names)); - return -1; } =20 static int @@ -542,40 +527,25 @@ storageConnectNumOfDefinedStoragePools(virConnectPtr = conn) return nactive; } =20 + static int storageConnectListDefinedStoragePools(virConnectPtr conn, char **const names, - int nnames) + int maxnames) { int got =3D 0; - size_t i; + + memset(names, 0, maxnames * sizeof(*names)); =20 if (virConnectListDefinedStoragePoolsEnsureACL(conn) < 0) return -1; =20 storageDriverLock(); - for (i =3D 0; i < driver->pools.count && got < nnames; i++) { - virStoragePoolObjPtr obj =3D driver->pools.objs[i]; - virStoragePoolObjLock(obj); - if (virConnectListDefinedStoragePoolsCheckACL(conn, obj->def) && - !virStoragePoolObjIsActive(obj)) { - if (VIR_STRDUP(names[got], obj->def->name) < 0) { - virStoragePoolObjUnlock(obj); - goto cleanup; - } - got++; - } - virStoragePoolObjUnlock(obj); - } + got =3D virStoragePoolObjGetNames(&driver->pools, conn, false, + virConnectListDefinedStoragePoolsCheck= ACL, + names, maxnames); storageDriverUnlock(); return got; - - cleanup: - storageDriverUnlock(); - for (i =3D 0; i < got; i++) - VIR_FREE(names[i]); - memset(names, 0, nnames * sizeof(*names)); - return -1; } =20 /* This method is required to be re-entrant / thread safe, so diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4fb9915..1a6601e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4130,35 +4130,23 @@ testConnectNumOfStoragePools(virConnectPtr conn) return numActive; } =20 + static int testConnectListStoragePools(virConnectPtr conn, char **const names, - int nnames) + int maxnames) { testDriverPtr privconn =3D conn->privateData; int n =3D 0; - size_t i; + + memset(names, 0, maxnames * sizeof(*names)); =20 testDriverLock(privconn); - memset(names, 0, sizeof(*names)*nnames); - for (i =3D 0; i < privconn->pools.count && n < nnames; i++) { - virStoragePoolObjLock(privconn->pools.objs[i]); - if (virStoragePoolObjIsActive(privconn->pools.objs[i]) && - VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0= ) { - virStoragePoolObjUnlock(privconn->pools.objs[i]); - goto error; - } - virStoragePoolObjUnlock(privconn->pools.objs[i]); - } + n =3D virStoragePoolObjGetNames(&privconn->pools, conn, true, NULL, + names, maxnames); testDriverUnlock(privconn); =20 return n; - - error: - for (n =3D 0; n < nnames; n++) - VIR_FREE(names[n]); - testDriverUnlock(privconn); - return -1; } =20 =20 @@ -4176,35 +4164,23 @@ testConnectNumOfDefinedStoragePools(virConnectPtr c= onn) return numInactive; } =20 + static int testConnectListDefinedStoragePools(virConnectPtr conn, char **const names, - int nnames) + int maxnames) { testDriverPtr privconn =3D conn->privateData; int n =3D 0; - size_t i; + + memset(names, 0, maxnames * sizeof(*names)); =20 testDriverLock(privconn); - memset(names, 0, sizeof(*names)*nnames); - for (i =3D 0; i < privconn->pools.count && n < nnames; i++) { - virStoragePoolObjLock(privconn->pools.objs[i]); - if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) && - VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0= ) { - virStoragePoolObjUnlock(privconn->pools.objs[i]); - goto error; - } - virStoragePoolObjUnlock(privconn->pools.objs[i]); - } + n =3D virStoragePoolObjGetNames(&privconn->pools, conn, false, NULL, + names, maxnames); testDriverUnlock(privconn); =20 return n; - - error: - for (n =3D 0; n < nnames; n++) - VIR_FREE(names[n]); - testDriverUnlock(privconn); - return -1; } =20 static int --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list