From nobody Wed Feb 11 08:40:08 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 149147931749360.74142868889021; Thu, 6 Apr 2017 04:48:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC36919CF24; 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 80D52A9D26; Thu, 6 Apr 2017 11:48:35 +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 C8AD718523CC; 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 v36BmOKB029904 for ; Thu, 6 Apr 2017 07:48:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2EAF3A861B; Thu, 6 Apr 2017 11:48:24 +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 E30DFA8633 for ; Thu, 6 Apr 2017 11:48:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BC36919CF24 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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 BC36919CF24 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 07:48:14 -0400 Message-Id: <20170406114814.31184-8-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 7/7] storage: Create helpers to perform FindByUUID and FindByName 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 06 Apr 2017 11:48:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create a couple of helpers that will perform the same call sequence. Signed-off-by: John Ferlan --- src/storage/storage_driver.c | 144 ++++++++++++++++++---------------------= ---- 1 file changed, 59 insertions(+), 85 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6b8bbb5..8b55acc 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -387,6 +387,56 @@ storageStateCleanup(void) } =20 =20 +static virStoragePoolObjPtr +storagePoolObjFindByUUID(const unsigned char *uuid, + const char *name) +{ + virStoragePoolObjPtr pool; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + if (!(pool =3D virStoragePoolObjFindByUUID(&driver->pools, uuid))) { + virUUIDFormat(uuid, uuidstr); + if (name) + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching uuid '%s' (%s)= "), + uuidstr, name); + else + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching uuid '%s'"), + uuidstr); + } + + return pool; +} + + +static virStoragePoolObjPtr +virStoragePoolObjFromStoragePool(virStoragePoolPtr pool) +{ + virStoragePoolObjPtr ret; + + storageDriverLock(); + ret =3D storagePoolObjFindByUUID(pool->uuid, pool->name); + storageDriverUnlock(); + + return ret; +} + + +static virStoragePoolObjPtr +storagePoolObjFindByName(const char *name) +{ + virStoragePoolObjPtr pool; + + storageDriverLock(); + if (!(pool =3D virStoragePoolObjFindByName(&driver->pools, name))) + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching name '%s'"), name); + storageDriverUnlock(); + + return pool; +} + =20 static virStoragePoolPtr storagePoolLookupByUUID(virConnectPtr conn, @@ -396,16 +446,10 @@ storagePoolLookupByUUID(virConnectPtr conn, virStoragePoolPtr ret =3D NULL; =20 storageDriverLock(); - pool =3D virStoragePoolObjFindByUUID(&driver->pools, uuid); + pool =3D storagePoolObjFindByUUID(uuid, NULL); storageDriverUnlock(); - - if (!pool) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(uuid, uuidstr); - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching uuid '%s'"), uuids= tr); + if (!pool) return NULL; - } =20 if (virStoragePoolLookupByUUIDEnsureACL(conn, pool->def) < 0) goto cleanup; @@ -425,15 +469,8 @@ storagePoolLookupByName(virConnectPtr conn, virStoragePoolObjPtr pool; virStoragePoolPtr ret =3D NULL; =20 - storageDriverLock(); - pool =3D virStoragePoolObjFindByName(&driver->pools, name); - storageDriverUnlock(); - - if (!pool) { - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching name '%s'"), name); + if (!(pool =3D storagePoolObjFindByName(name))) return NULL; - } =20 if (virStoragePoolLookupByNameEnsureACL(conn, pool->def) < 0) goto cleanup; @@ -452,16 +489,8 @@ storagePoolLookupByVolume(virStorageVolPtr vol) virStoragePoolObjPtr pool; virStoragePoolPtr ret =3D NULL; =20 - storageDriverLock(); - pool =3D virStoragePoolObjFindByName(&driver->pools, vol->pool); - storageDriverUnlock(); - - if (!pool) { - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching name '%s'"), - vol->pool); + if (!(pool =3D storagePoolObjFindByName(vol->pool))) return NULL; - } =20 if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, pool->def) < 0) goto cleanup; @@ -588,25 +617,6 @@ storageConnectFindStoragePoolSources(virConnectPtr con= n, } =20 =20 -static virStoragePoolObjPtr -virStoragePoolObjFromStoragePool(virStoragePoolPtr pool) -{ - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virStoragePoolObjPtr ret; - - storageDriverLock(); - if (!(ret =3D virStoragePoolObjFindByUUID(&driver->pools, pool->uuid))= ) { - virUUIDFormat(pool->uuid, uuidstr); - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching uuid '%s' (%s)"), - uuidstr, pool->name); - } - storageDriverUnlock(); - - return ret; -} - - static int storagePoolIsActive(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; @@ -813,14 +823,8 @@ storagePoolUndefine(virStoragePoolPtr obj) int ret =3D -1; =20 storageDriverLock(); - if (!(pool =3D virStoragePoolObjFindByUUID(&driver->pools, obj->uuid))= ) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->uuid, uuidstr); - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching uuid '%s' (%s)"), - uuidstr, obj->name); + if (!(pool =3D storagePoolObjFindByUUID(obj->uuid, obj->name))) goto cleanup; - } =20 if (virStoragePoolUndefineEnsureACL(obj->conn, pool->def) < 0) goto cleanup; @@ -999,14 +1003,8 @@ storagePoolDestroy(virStoragePoolPtr obj) int ret =3D -1; =20 storageDriverLock(); - if (!(pool =3D virStoragePoolObjFindByUUID(&driver->pools, obj->uuid))= ) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->uuid, uuidstr); - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching uuid '%s' (%s)"), - uuidstr, obj->name); + if (!(pool =3D storagePoolObjFindByUUID(obj->uuid, obj->name))) goto cleanup; - } =20 if (virStoragePoolDestroyEnsureACL(obj->conn, pool->def) < 0) goto cleanup; @@ -1133,14 +1131,8 @@ storagePoolRefresh(virStoragePoolPtr obj, virCheckFlags(0, -1); =20 storageDriverLock(); - if (!(pool =3D virStoragePoolObjFindByUUID(&driver->pools, obj->uuid))= ) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->uuid, uuidstr); - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching uuid '%s' (%s)"), - uuidstr, obj->name); + if (!(pool =3D storagePoolObjFindByUUID(obj->uuid, obj->name))) goto cleanup; - } =20 if (virStoragePoolRefreshEnsureACL(obj->conn, pool->def) < 0) goto cleanup; @@ -1283,16 +1275,8 @@ storagePoolSetAutostart(virStoragePoolPtr obj, int ret =3D -1; =20 storageDriverLock(); - pool =3D virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); - - if (!pool) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->uuid, uuidstr); - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching uuid '%s' (%s)"), - uuidstr, obj->name); + if (!(pool =3D storagePoolObjFindByUUID(obj->uuid, obj->name))) goto cleanup; - } =20 if (virStoragePoolSetAutostartEnsureACL(obj->conn, pool->def) < 0) goto cleanup; @@ -1713,18 +1697,8 @@ virStorageVolDefFromVol(virStorageVolPtr obj, { virStorageVolDefPtr vol =3D NULL; =20 - *pool =3D NULL; - - storageDriverLock(); - *pool =3D virStoragePoolObjFindByName(&driver->pools, obj->pool); - storageDriverUnlock(); - - if (!*pool) { - virReportError(VIR_ERR_NO_STORAGE_POOL, - _("no storage pool with matching name '%s'"), - obj->pool); + if (!(*pool =3D storagePoolObjFindByName(obj->pool))) return NULL; - } =20 if (!virStoragePoolObjIsActive(*pool)) { virReportError(VIR_ERR_OPERATION_INVALID, --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list