From nobody Thu May 15 19:23:01 2025 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.zohomail.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 1503580173939487.35255644081644; Thu, 24 Aug 2017 06:09:33 -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 E840B267F7; Thu, 24 Aug 2017 13:09:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1C287F7FA; Thu, 24 Aug 2017 13:09: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 842203FAD1; Thu, 24 Aug 2017 13:09:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7OD9CDN027780 for ; Thu, 24 Aug 2017 09:09:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73A957B8D7; Thu, 24 Aug 2017 13:09:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-123-165.rdu2.redhat.com [10.10.123.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 444537B9CB for ; Thu, 24 Aug 2017 13:09:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E840B267F7 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=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Thu, 24 Aug 2017 09:08:55 -0400 Message-Id: <20170824130905.5199-3-jferlan@redhat.com> In-Reply-To: <20170824130905.5199-1-jferlan@redhat.com> References: <20170824130905.5199-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/12] storage: Introduce virStoragePoolObjNew 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.30]); Thu, 24 Aug 2017 13:09:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create/use a helper to perform object allocation. Adjust storagevolxml2argvtest.c in order to use the allocator and setting of the obj->def. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 31 +++++++++++++++++++++---------- src/conf/virstorageobj.h | 3 +++ src/libvirt_private.syms | 1 + tests/storagevolxml2argvtest.c | 20 +++++++++++--------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index ebda9fe..eb7664c 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,26 @@ VIR_LOG_INIT("conf.virstorageobj"); =20 =20 +virStoragePoolObjPtr +virStoragePoolObjNew(void) +{ + virStoragePoolObjPtr obj; + + if (VIR_ALLOC(obj) < 0) + return NULL; + + if (virMutexInit(&obj->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot initialize mutex")); + VIR_FREE(obj); + return NULL; + } + virStoragePoolObjLock(obj); + obj->active =3D 0; + return obj; +} + + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj) { @@ -421,17 +441,8 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr po= ols, return obj; } =20 - if (VIR_ALLOC(obj) < 0) - return NULL; - - if (virMutexInit(&obj->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot initialize mutex")); - VIR_FREE(obj); + if (!(obj =3D virStoragePoolObjNew())) return NULL; - } - virStoragePoolObjLock(obj); - obj->active =3D 0; =20 if (VIR_APPEND_ELEMENT_COPY(pools->objs, pools->count, obj) < 0) { virStoragePoolObjUnlock(obj); diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index a5ed8f8..401c4d5 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -70,6 +70,9 @@ typedef bool (*virStoragePoolObjListFilter)(virConnectPtr conn, virStoragePoolDefPtr def); =20 +virStoragePoolObjPtr +virStoragePoolObjNew(void); + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8bb1cbc..fc884fa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1071,6 +1071,7 @@ virStoragePoolObjListFree; virStoragePoolObjLoadAllConfigs; virStoragePoolObjLoadAllState; virStoragePoolObjLock; +virStoragePoolObjNew; virStoragePoolObjNumOfStoragePools; virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 9e43204..2ee3dba 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -50,18 +50,19 @@ testCompareXMLToArgvFiles(bool shouldFail, virConnectPtr conn; =20 virStorageVolDefPtr vol =3D NULL, inputvol =3D NULL; - virStoragePoolDefPtr pool =3D NULL; + virStoragePoolDefPtr def =3D NULL; virStoragePoolDefPtr inputpool =3D NULL; - virStoragePoolObj poolobj =3D {.def =3D NULL }; - + virStoragePoolObjPtr obj =3D NULL; =20 if (!(conn =3D virGetConnect())) goto cleanup; =20 - if (!(pool =3D virStoragePoolDefParseFile(poolxml))) + if (!(def =3D virStoragePoolDefParseFile(poolxml))) goto cleanup; =20 - poolobj.def =3D pool; + if (!(obj =3D virStoragePoolObjNew())) + goto cleanup; + virStoragePoolObjSetDef(obj, def); =20 if (inputpoolxml) { if (!(inputpool =3D virStoragePoolDefParseFile(inputpoolxml))) @@ -71,17 +72,17 @@ testCompareXMLToArgvFiles(bool shouldFail, if (inputvolxml) parse_flags |=3D VIR_VOL_XML_PARSE_NO_CAPACITY; =20 - if (!(vol =3D virStorageVolDefParseFile(pool, volxml, parse_flags))) + if (!(vol =3D virStorageVolDefParseFile(def, volxml, parse_flags))) goto cleanup; =20 if (inputvolxml && !(inputvol =3D virStorageVolDefParseFile(inputpool, inputvolxml, 0= ))) goto cleanup; =20 - testSetVolumeType(vol, pool); + testSetVolumeType(vol, def); testSetVolumeType(inputvol, inputpool); =20 - cmd =3D virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol, + cmd =3D virStorageBackendCreateQemuImgCmdFromVol(conn, obj, vol, inputvol, flags, create_tool, imgformat, NULL); @@ -102,12 +103,13 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - virStoragePoolDefFree(pool); + virStoragePoolDefFree(def); virStoragePoolDefFree(inputpool); virStorageVolDefFree(vol); virStorageVolDefFree(inputvol); virCommandFree(cmd); VIR_FREE(actualCmdline); + virStoragePoolObjUnlock(obj); virObjectUnref(conn); return ret; } --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list