From nobody Mon May 6 19:30:02 2024 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 1493056838647666.0887625740309; Mon, 24 Apr 2017 11:00:38 -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 0A7E661B85; Mon, 24 Apr 2017 18:00:36 +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 BB4AC183C0; Mon, 24 Apr 2017 18:00: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 CE54A18523D1; Mon, 24 Apr 2017 18:00:33 +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 v3OI0WSx004673 for ; Mon, 24 Apr 2017 14:00:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F31F17A79; Mon, 24 Apr 2017 18:00:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBFF9183C0 for ; Mon, 24 Apr 2017 18:00:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A7E661B85 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 0A7E661B85 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:10 -0400 Message-Id: <20170424180023.4695-2-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/14] secret: Need to set data->error on VIR_ALLOC_N failure 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.39]); Mon, 24 Apr 2017 18:00:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit id 'bb1fba629' neglected to set when creating the function. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 049cab3..cc18459 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -457,8 +457,10 @@ virSecretObjListGetHelper(void *payload, if (data->uuids) { char *uuidstr; =20 - if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) + if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) { + data->error =3D true; goto cleanup; + } =20 virUUIDFormat(obj->def->uuid, uuidstr); data->uuids[data->got] =3D uuidstr; --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056837909853.7865229711363; Mon, 24 Apr 2017 11:00:37 -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 08C34624BE; Mon, 24 Apr 2017 18:00:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB94783E84; Mon, 24 Apr 2017 18:00: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 D944C5EC67; Mon, 24 Apr 2017 18:00:33 +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 v3OI0WbG004678 for ; Mon, 24 Apr 2017 14:00:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 715BC17A79; Mon, 24 Apr 2017 18:00:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E5A877ECA for ; Mon, 24 Apr 2017 18:00:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 08C34624BE Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 08C34624BE From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:11 -0400 Message-Id: <20170424180023.4695-3-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/14] secret: Convert virsecretobjs.h to use "newer" formatting style 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.39]); Mon, 24 Apr 2017 18:00:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter the prototypes to use the newer formatting style Signed-off-by: John Ferlan --- src/conf/virsecretobj.h | 147 +++++++++++++++++++++++++++++---------------= ---- 1 file changed, 88 insertions(+), 59 deletions(-) diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index fa45b42..b26061a 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -29,82 +29,111 @@ typedef struct _virSecretObj virSecretObj; typedef virSecretObj *virSecretObjPtr; =20 -virSecretObjPtr virSecretObjNew(void); +virSecretObjPtr +virSecretObjNew(void); =20 -void virSecretObjEndAPI(virSecretObjPtr *secret); +void +virSecretObjEndAPI(virSecretObjPtr *secret); =20 typedef struct _virSecretObjList virSecretObjList; typedef virSecretObjList *virSecretObjListPtr; =20 -virSecretObjListPtr virSecretObjListNew(void); - -virSecretObjPtr virSecretObjListFindByUUIDLocked(virSecretObjListPtr secre= ts, - const unsigned char *uuid= ); - -virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, - const unsigned char *uuid); - -virSecretObjPtr virSecretObjListFindByUsageLocked(virSecretObjListPtr secr= ets, - int usageType, - const char *usageID); - -virSecretObjPtr virSecretObjListFindByUsage(virSecretObjListPtr secrets, - int usageType, - const char *usageID); - -void virSecretObjListRemove(virSecretObjListPtr secrets, - virSecretObjPtr secret); - -virSecretObjPtr virSecretObjListAddLocked(virSecretObjListPtr secrets, - virSecretDefPtr def, - const char *configDir, - virSecretDefPtr *oldDef); - -virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, - virSecretDefPtr def, - const char *configDir, - virSecretDefPtr *oldDef); - -typedef bool (*virSecretObjListACLFilter)(virConnectPtr conn, - virSecretDefPtr def); +virSecretObjListPtr +virSecretObjListNew(void); + +virSecretObjPtr +virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets, + const unsigned char *uuid); + +virSecretObjPtr +virSecretObjListFindByUUID(virSecretObjListPtr secrets, + const unsigned char *uuid); + +virSecretObjPtr +virSecretObjListFindByUsageLocked(virSecretObjListPtr secrets, + int usageType, + const char *usageID); + +virSecretObjPtr +virSecretObjListFindByUsage(virSecretObjListPtr secrets, + int usageType, + const char *usageID); + +void +virSecretObjListRemove(virSecretObjListPtr secrets, + virSecretObjPtr secret); + +virSecretObjPtr +virSecretObjListAddLocked(virSecretObjListPtr secrets, + virSecretDefPtr def, + const char *configDir, + virSecretDefPtr *oldDef); + +virSecretObjPtr +virSecretObjListAdd(virSecretObjListPtr secrets, + virSecretDefPtr def, + const char *configDir, + virSecretDefPtr *oldDef); + +typedef bool +(*virSecretObjListACLFilter)(virConnectPtr conn, + virSecretDefPtr def); + +int +virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, + virSecretObjListACLFilter filter, + virConnectPtr conn); =20 -int virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, - virSecretObjListACLFilter filter, - virConnectPtr conn); +int +virSecretObjListExport(virConnectPtr conn, + virSecretObjListPtr secretobjs, + virSecretPtr **secrets, + virSecretObjListACLFilter filter, + unsigned int flags); =20 -int virSecretObjListExport(virConnectPtr conn, - virSecretObjListPtr secretobjs, - virSecretPtr **secrets, - virSecretObjListACLFilter filter, - unsigned int flags); +int +virSecretObjListGetUUIDs(virSecretObjListPtr secrets, + char **uuids, + int nuuids, + virSecretObjListACLFilter filter, + virConnectPtr conn); =20 -int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, - char **uuids, - int nuuids, - virSecretObjListACLFilter filter, - virConnectPtr conn); +int +virSecretObjDeleteConfig(virSecretObjPtr secret); =20 -int virSecretObjDeleteConfig(virSecretObjPtr secret); +void +virSecretObjDeleteData(virSecretObjPtr secret); =20 -void virSecretObjDeleteData(virSecretObjPtr secret); +int +virSecretObjSaveConfig(virSecretObjPtr secret); =20 -int virSecretObjSaveConfig(virSecretObjPtr secret); +int +virSecretObjSaveData(virSecretObjPtr secret); =20 -int virSecretObjSaveData(virSecretObjPtr secret); +virSecretDefPtr +virSecretObjGetDef(virSecretObjPtr secret); =20 -virSecretDefPtr virSecretObjGetDef(virSecretObjPtr secret); +void +virSecretObjSetDef(virSecretObjPtr secret, + virSecretDefPtr def); =20 -void virSecretObjSetDef(virSecretObjPtr secret, virSecretDefPtr def); +unsigned char * +virSecretObjGetValue(virSecretObjPtr secret); =20 -unsigned char *virSecretObjGetValue(virSecretObjPtr secret); +int +virSecretObjSetValue(virSecretObjPtr secret, + const unsigned char *value, + size_t value_size); =20 -int virSecretObjSetValue(virSecretObjPtr secret, - const unsigned char *value, size_t value_size); +size_t +virSecretObjGetValueSize(virSecretObjPtr secret); =20 -size_t virSecretObjGetValueSize(virSecretObjPtr secret); +void +virSecretObjSetValueSize(virSecretObjPtr secret, + size_t value_size); =20 -void virSecretObjSetValueSize(virSecretObjPtr secret, size_t value_size); +int +virSecretLoadAllConfigs(virSecretObjListPtr secrets, + const char *configDir); =20 -int virSecretLoadAllConfigs(virSecretObjListPtr secrets, - const char *configDir); #endif /* __VIRSECRETOBJ_H__ */ --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056846063721.7297885482515; Mon, 24 Apr 2017 11:00:46 -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 24B74B1CAF; Mon, 24 Apr 2017 18:00:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAD9183864; Mon, 24 Apr 2017 18:00:42 +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 8CBC55EC6A; Mon, 24 Apr 2017 18:00:42 +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 v3OI0XUY004687 for ; Mon, 24 Apr 2017 14:00:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 656E478DF7; Mon, 24 Apr 2017 18:00:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28F1E77ED5 for ; Mon, 24 Apr 2017 18:00:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 24B74B1CAF 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 24B74B1CAF From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:12 -0400 Message-Id: <20170424180023.4695-4-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/14] secret: Make some virSecretObj* functions static 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]); Mon, 24 Apr 2017 18:00:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make various virSecretObjList*Locked functions static and make virSecretObjNew static since they're only called within virtsecretobj.c Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 33 +++++++-------------------------- src/conf/virsecretobj.h | 18 ------------------ 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index cc18459..064e66c 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -86,7 +86,7 @@ virSecretObjOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(virSecretObj) =20 -virSecretObjPtr +static virSecretObjPtr virSecretObjNew(void) { virSecretObjPtr secret; @@ -158,16 +158,7 @@ virSecretObjListDispose(void *obj) } =20 =20 -/** - * virSecretObjFindByUUIDLocked: - * @secrets: list of secret objects - * @uuid: secret uuid to find - * - * This functions requires @secrets to be locked already! - * - * Returns: not locked, but ref'd secret object. - */ -virSecretObjPtr +static virSecretObjPtr virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets, const unsigned char *uuid) { @@ -187,7 +178,7 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr se= crets, * This function locks @secrets and finds the secret object which * corresponds to @uuid. * - * Returns: locked and ref'd secret object. + * Returns: locked and ref'd secret object on success, NULL on failure. */ virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, @@ -228,17 +219,7 @@ virSecretObjSearchName(const void *payload, } =20 =20 -/** - * virSecretObjFindByUsageLocked: - * @secrets: list of secret objects - * @usageType: secret usageType to find - * @usageID: secret usage string - * - * This functions requires @secrets to be locked already! - * - * Returns: not locked, but ref'd secret object. - */ -virSecretObjPtr +static virSecretObjPtr virSecretObjListFindByUsageLocked(virSecretObjListPtr secrets, int usageType, const char *usageID) @@ -263,7 +244,7 @@ virSecretObjListFindByUsageLocked(virSecretObjListPtr s= ecrets, * This function locks @secrets and finds the secret object which * corresponds to @usageID of @usageType. * - * Returns: locked and ref'd secret object. + * Returns: locked and ref'd secret object on success, NULL on failure. */ virSecretObjPtr virSecretObjListFindByUsage(virSecretObjListPtr secrets, @@ -320,9 +301,9 @@ virSecretObjListRemove(virSecretObjListPtr secrets, * * This functions requires @secrets to be locked already! * - * Returns pointer to secret or NULL if failure to add + * Returns: locked secret or NULL if failure to add */ -virSecretObjPtr +static virSecretObjPtr virSecretObjListAddLocked(virSecretObjListPtr secrets, virSecretDefPtr def, const char *configDir, diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index b26061a..9638b69 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -29,9 +29,6 @@ typedef struct _virSecretObj virSecretObj; typedef virSecretObj *virSecretObjPtr; =20 -virSecretObjPtr -virSecretObjNew(void); - void virSecretObjEndAPI(virSecretObjPtr *secret); =20 @@ -42,19 +39,10 @@ virSecretObjListPtr virSecretObjListNew(void); =20 virSecretObjPtr -virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets, - const unsigned char *uuid); - -virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, const unsigned char *uuid); =20 virSecretObjPtr -virSecretObjListFindByUsageLocked(virSecretObjListPtr secrets, - int usageType, - const char *usageID); - -virSecretObjPtr virSecretObjListFindByUsage(virSecretObjListPtr secrets, int usageType, const char *usageID); @@ -64,12 +52,6 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr secret); =20 virSecretObjPtr -virSecretObjListAddLocked(virSecretObjListPtr secrets, - virSecretDefPtr def, - const char *configDir, - virSecretDefPtr *oldDef); - -virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefPtr def, const char *configDir, --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056849431513.6939585803708; Mon, 24 Apr 2017 11:00:49 -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 83BEE80F93; Mon, 24 Apr 2017 18:00:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34EFF18A7B; Mon, 24 Apr 2017 18:00:47 +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 D84EE5EC6D; Mon, 24 Apr 2017 18:00:46 +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 v3OI0Yml004701 for ; Mon, 24 Apr 2017 14:00:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 277AA17A79; Mon, 24 Apr 2017 18:00:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id E49DA77ECA for ; Mon, 24 Apr 2017 18:00:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83BEE80F93 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 83BEE80F93 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:13 -0400 Message-Id: <20170424180023.4695-5-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/14] secret: Have virSecretObjNew return locked object 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.27]); Mon, 24 Apr 2017 18:00:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than have caller need to do it, have the object returned locked. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 064e66c..348feb3 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -97,6 +97,8 @@ virSecretObjNew(void) if (!(secret =3D virObjectLockableNew(virSecretObjClass))) return NULL; =20 + virObjectLock(secret); + return secret; } =20 @@ -367,8 +369,6 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, if (!(secret =3D virSecretObjNew())) goto cleanup; =20 - virObjectLock(secret); - if (virHashAddEntry(secrets->objs, uuidstr, secret) < 0) goto cleanup; =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056845856548.1083154535; Mon, 24 Apr 2017 11:00:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21DEDC049D5C; Mon, 24 Apr 2017 18:00:43 +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 E8F3E17132; Mon, 24 Apr 2017 18:00:42 +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 898F818523D2; Mon, 24 Apr 2017 18:00:42 +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 v3OI0Zsn004713 for ; Mon, 24 Apr 2017 14:00:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5652817A79; Mon, 24 Apr 2017 18:00:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E024183C0 for ; Mon, 24 Apr 2017 18:00:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 21DEDC049D5C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 21DEDC049D5C From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:14 -0400 Message-Id: <20170424180023.4695-6-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/14] secret: Use consistent naming for variables 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Apr 2017 18:00:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When processing a virSecretPtr use 'secret' as a variable name. When processing a virSecretObjPtr use 'obj' as a variable name. When processing a virSecretDefPtr use 'def' as a variable name, unless a distinction needs to be made with a 'newdef' such as virSecretObjListAddLocked (which also used the VIR_STEAL_PTR macro for the configFile and base64File). NB: Also made a slight algorithm adjustment for virSecretObjListRemove to check if the passed obj was NULL rather than having the caller virSecretLoad need to check prior to calling. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 275 +++++++++++++++++++++++------------------= ---- src/conf/virsecretobj.h | 26 ++--- src/secret/secret_driver.c | 139 ++++++++++++----------- 3 files changed, 226 insertions(+), 214 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 348feb3..42f36c8 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -89,29 +89,29 @@ VIR_ONCE_GLOBAL_INIT(virSecretObj) static virSecretObjPtr virSecretObjNew(void) { - virSecretObjPtr secret; + virSecretObjPtr obj; =20 if (virSecretObjInitialize() < 0) return NULL; =20 - if (!(secret =3D virObjectLockableNew(virSecretObjClass))) + if (!(obj =3D virObjectLockableNew(virSecretObjClass))) return NULL; =20 - virObjectLock(secret); + virObjectLock(obj); =20 - return secret; + return obj; } =20 =20 void -virSecretObjEndAPI(virSecretObjPtr *secret) +virSecretObjEndAPI(virSecretObjPtr *obj) { - if (!*secret) + if (!*obj) return; =20 - virObjectUnlock(*secret); - virObjectUnref(*secret); - *secret =3D NULL; + virObjectUnlock(*obj); + virObjectUnref(*obj); + *obj =3D NULL; } =20 =20 @@ -136,18 +136,18 @@ virSecretObjListNew(void) =20 =20 static void -virSecretObjDispose(void *obj) +virSecretObjDispose(void *opaque) { - virSecretObjPtr secret =3D obj; + virSecretObjPtr obj =3D opaque; =20 - virSecretDefFree(secret->def); - if (secret->value) { + virSecretDefFree(obj->def); + if (obj->value) { /* Wipe before free to ensure we don't leave a secret on the heap = */ - memset(secret->value, 0, secret->value_size); - VIR_FREE(secret->value); + memset(obj->value, 0, obj->value_size); + VIR_FREE(obj->value); } - VIR_FREE(secret->configFile); - VIR_FREE(secret->base64File); + VIR_FREE(obj->configFile); + VIR_FREE(obj->base64File); } =20 =20 @@ -186,14 +186,14 @@ virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, const unsigned char *uuid) { - virSecretObjPtr ret; + virSecretObjPtr obj; =20 virObjectLock(secrets); - ret =3D virSecretObjListFindByUUIDLocked(secrets, uuid); + obj =3D virSecretObjListFindByUUIDLocked(secrets, uuid); virObjectUnlock(secrets); - if (ret) - virObjectLock(ret); - return ret; + if (obj) + virObjectLock(obj); + return obj; } =20 =20 @@ -202,21 +202,21 @@ virSecretObjSearchName(const void *payload, const void *name ATTRIBUTE_UNUSED, const void *opaque) { - virSecretObjPtr secret =3D (virSecretObjPtr) payload; + virSecretObjPtr obj =3D (virSecretObjPtr) payload; struct virSecretSearchData *data =3D (struct virSecretSearchData *) op= aque; int found =3D 0; =20 - virObjectLock(secret); + virObjectLock(obj); =20 - if (secret->def->usage_type !=3D data->usageType) + if (obj->def->usage_type !=3D data->usageType) goto cleanup; =20 if (data->usageType !=3D VIR_SECRET_USAGE_TYPE_NONE && - STREQ(secret->def->usage_id, data->usageID)) + STREQ(obj->def->usage_id, data->usageID)) found =3D 1; =20 cleanup: - virObjectUnlock(secret); + virObjectUnlock(obj); return found; } =20 @@ -226,14 +226,14 @@ virSecretObjListFindByUsageLocked(virSecretObjListPtr= secrets, int usageType, const char *usageID) { - virSecretObjPtr ret =3D NULL; + virSecretObjPtr obj =3D NULL; struct virSecretSearchData data =3D { .usageType =3D usageType, .usageID =3D usageID }; =20 - ret =3D virHashSearch(secrets->objs, virSecretObjSearchName, &data); - if (ret) - virObjectRef(ret); - return ret; + obj =3D virHashSearch(secrets->objs, virSecretObjSearchName, &data); + if (obj) + virObjectRef(obj); + return obj; } =20 =20 @@ -253,14 +253,14 @@ virSecretObjListFindByUsage(virSecretObjListPtr secre= ts, int usageType, const char *usageID) { - virSecretObjPtr ret; + virSecretObjPtr obj; =20 virObjectLock(secrets); - ret =3D virSecretObjListFindByUsageLocked(secrets, usageType, usageID); + obj =3D virSecretObjListFindByUsageLocked(secrets, usageType, usageID); virObjectUnlock(secrets); - if (ret) - virObjectLock(ret); - return ret; + if (obj) + virObjectLock(obj); + return obj; } =20 =20 @@ -275,19 +275,22 @@ virSecretObjListFindByUsage(virSecretObjListPtr secre= ts, */ void virSecretObjListRemove(virSecretObjListPtr secrets, - virSecretObjPtr secret) + virSecretObjPtr obj) { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - virUUIDFormat(secret->def->uuid, uuidstr); - virObjectRef(secret); - virObjectUnlock(secret); + if (!obj) + return; + + virUUIDFormat(obj->def->uuid, uuidstr); + virObjectRef(obj); + virObjectUnlock(obj); =20 virObjectLock(secrets); - virObjectLock(secret); + virObjectLock(obj); virHashRemoveEntry(secrets->objs, uuidstr); - virObjectUnlock(secret); - virObjectUnref(secret); + virObjectUnlock(obj); + virObjectUnref(obj); virObjectUnlock(secrets); } =20 @@ -295,11 +298,11 @@ virSecretObjListRemove(virSecretObjListPtr secrets, /* * virSecretObjListAddLocked: * @secrets: list of secret objects - * @def: new secret definition + * @newdef: new secret definition * @configDir: directory to place secret config files * @oldDef: Former secret def (e.g. a reload path perhaps) * - * Add the new def to the secret obj table hash + * Add the new @newdef to the secret obj table hash * * This functions requires @secrets to be locked already! * @@ -307,11 +310,11 @@ virSecretObjListRemove(virSecretObjListPtr secrets, */ static virSecretObjPtr virSecretObjListAddLocked(virSecretObjListPtr secrets, - virSecretDefPtr def, + virSecretDefPtr newdef, const char *configDir, virSecretDefPtr *oldDef) { - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; @@ -320,71 +323,69 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, *oldDef =3D NULL; =20 /* Is there a secret already matching this UUID */ - if ((secret =3D virSecretObjListFindByUUIDLocked(secrets, def->uuid)))= { - virObjectLock(secret); + if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, newdef->uuid)))= { + virObjectLock(obj); =20 - if (STRNEQ_NULLABLE(secret->def->usage_id, def->usage_id)) { - virUUIDFormat(secret->def->uuid, uuidstr); + if (STRNEQ_NULLABLE(obj->def->usage_id, newdef->usage_id)) { + virUUIDFormat(obj->def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), - uuidstr, secret->def->usage_id); + uuidstr, obj->def->usage_id); goto cleanup; } =20 - if (secret->def->isprivate && !def->isprivate) { + if (obj->def->isprivate && !newdef->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); goto cleanup; } =20 if (oldDef) - *oldDef =3D secret->def; + *oldDef =3D obj->def; else - virSecretDefFree(secret->def); - secret->def =3D def; + virSecretDefFree(obj->def); + obj->def =3D newdef; } else { /* No existing secret with same UUID, * try look for matching usage instead */ - if ((secret =3D virSecretObjListFindByUsageLocked(secrets, - def->usage_type, - def->usage_id))) { - virObjectLock(secret); - virUUIDFormat(secret->def->uuid, uuidstr); + if ((obj =3D virSecretObjListFindByUsageLocked(secrets, + newdef->usage_type, + newdef->usage_id))) { + virObjectLock(obj); + virUUIDFormat(obj->def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for " "use with %s"), - uuidstr, def->usage_id); + uuidstr, newdef->usage_id); goto cleanup; } =20 /* Generate the possible configFile and base64File strings * using the configDir, uuidstr, and appropriate suffix */ - virUUIDFormat(def->uuid, uuidstr); + virUUIDFormat(newdef->uuid, uuidstr); if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml"))= || !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64= "))) goto cleanup; =20 - if (!(secret =3D virSecretObjNew())) + if (!(obj =3D virSecretObjNew())) goto cleanup; =20 - if (virHashAddEntry(secrets->objs, uuidstr, secret) < 0) + if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) goto cleanup; =20 - secret->def =3D def; - secret->configFile =3D configFile; - secret->base64File =3D base64File; - configFile =3D NULL; - base64File =3D NULL; - virObjectRef(secret); + obj->def =3D newdef; + VIR_STEAL_PTR(obj->configFile, configFile); + VIR_STEAL_PTR(obj->base64File, base64File); + virObjectRef(obj); } =20 - ret =3D secret; - secret =3D NULL; + ret =3D obj; + obj =3D NULL; =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); VIR_FREE(configFile); VIR_FREE(base64File); return ret; @@ -393,16 +394,16 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, =20 virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, - virSecretDefPtr def, + virSecretDefPtr newdef, const char *configDir, virSecretDefPtr *oldDef) { - virSecretObjPtr ret; + virSecretObjPtr obj; =20 virObjectLock(secrets); - ret =3D virSecretObjListAddLocked(secrets, def, configDir, oldDef); + obj =3D virSecretObjListAddLocked(secrets, newdef, configDir, oldDef); virObjectUnlock(secrets); - return ret; + return obj; } =20 =20 @@ -474,23 +475,23 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secr= ets, =20 #define MATCH(FLAG) (flags & (FLAG)) static bool -virSecretObjMatchFlags(virSecretObjPtr secret, +virSecretObjMatchFlags(virSecretObjPtr obj, unsigned int flags) { /* filter by whether it's ephemeral */ if (MATCH(VIR_CONNECT_LIST_SECRETS_FILTERS_EPHEMERAL) && !((MATCH(VIR_CONNECT_LIST_SECRETS_EPHEMERAL) && - secret->def->isephemeral) || + obj->def->isephemeral) || (MATCH(VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL) && - !secret->def->isephemeral))) + !obj->def->isephemeral))) return false; =20 /* filter by whether it's private */ if (MATCH(VIR_CONNECT_LIST_SECRETS_FILTERS_PRIVATE) && !((MATCH(VIR_CONNECT_LIST_SECRETS_PRIVATE) && - secret->def->isprivate) || + obj->def->isprivate) || (MATCH(VIR_CONNECT_LIST_SECRETS_NO_PRIVATE) && - !secret->def->isprivate))) + !obj->def->isprivate))) return false; =20 return true; @@ -621,12 +622,12 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, =20 =20 int -virSecretObjDeleteConfig(virSecretObjPtr secret) +virSecretObjDeleteConfig(virSecretObjPtr obj) { - if (!secret->def->isephemeral && - unlink(secret->configFile) < 0 && errno !=3D ENOENT) { + if (!obj->def->isephemeral && + unlink(obj->configFile) < 0 && errno !=3D ENOENT) { virReportSystemError(errno, _("cannot unlink '%s'"), - secret->configFile); + obj->configFile); return -1; } =20 @@ -635,11 +636,11 @@ virSecretObjDeleteConfig(virSecretObjPtr secret) =20 =20 void -virSecretObjDeleteData(virSecretObjPtr secret) +virSecretObjDeleteData(virSecretObjPtr obj) { /* The configFile will already be removed, so secret won't be * loaded again if this fails */ - (void)unlink(secret->base64File); + (void)unlink(obj->base64File); } =20 =20 @@ -650,15 +651,15 @@ virSecretObjDeleteData(virSecretObjPtr secret) secret is defined, it is stored as base64 (with no formatting) in "$basename.base64". "$basename" is in both cases the base64-encoded UU= ID. */ int -virSecretObjSaveConfig(virSecretObjPtr secret) +virSecretObjSaveConfig(virSecretObjPtr obj) { char *xml =3D NULL; int ret =3D -1; =20 - if (!(xml =3D virSecretDefFormat(secret->def))) + if (!(xml =3D virSecretDefFormat(obj->def))) goto cleanup; =20 - if (virFileRewriteStr(secret->configFile, S_IRUSR | S_IWUSR, xml) < 0) + if (virFileRewriteStr(obj->configFile, S_IRUSR | S_IWUSR, xml) < 0) goto cleanup; =20 ret =3D 0; @@ -670,18 +671,18 @@ virSecretObjSaveConfig(virSecretObjPtr secret) =20 =20 int -virSecretObjSaveData(virSecretObjPtr secret) +virSecretObjSaveData(virSecretObjPtr obj) { char *base64 =3D NULL; int ret =3D -1; =20 - if (!secret->value) + if (!obj->value) return 0; =20 - if (!(base64 =3D virStringEncodeBase64(secret->value, secret->value_si= ze))) + if (!(base64 =3D virStringEncodeBase64(obj->value, obj->value_size))) goto cleanup; =20 - if (virFileRewriteStr(secret->base64File, S_IRUSR | S_IWUSR, base64) <= 0) + if (virFileRewriteStr(obj->base64File, S_IRUSR | S_IWUSR, base64) < 0) goto cleanup; =20 ret =3D 0; @@ -693,36 +694,36 @@ virSecretObjSaveData(virSecretObjPtr secret) =20 =20 virSecretDefPtr -virSecretObjGetDef(virSecretObjPtr secret) +virSecretObjGetDef(virSecretObjPtr obj) { - return secret->def; + return obj->def; } =20 =20 void -virSecretObjSetDef(virSecretObjPtr secret, +virSecretObjSetDef(virSecretObjPtr obj, virSecretDefPtr def) { - secret->def =3D def; + obj->def =3D def; } =20 =20 unsigned char * -virSecretObjGetValue(virSecretObjPtr secret) +virSecretObjGetValue(virSecretObjPtr obj) { unsigned char *ret =3D NULL; =20 - if (!secret->value) { + if (!obj->value) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(secret->def->uuid, uuidstr); + virUUIDFormat(obj->def->uuid, uuidstr); virReportError(VIR_ERR_NO_SECRET, _("secret '%s' does not have a value"), uuidstr); goto cleanup; } =20 - if (VIR_ALLOC_N(ret, secret->value_size) < 0) + if (VIR_ALLOC_N(ret, obj->value_size) < 0) goto cleanup; - memcpy(ret, secret->value, secret->value_size); + memcpy(ret, obj->value, obj->value_size); =20 cleanup: return ret; @@ -730,7 +731,7 @@ virSecretObjGetValue(virSecretObjPtr secret) =20 =20 int -virSecretObjSetValue(virSecretObjPtr secret, +virSecretObjSetValue(virSecretObjPtr obj, const unsigned char *value, size_t value_size) { @@ -740,14 +741,14 @@ virSecretObjSetValue(virSecretObjPtr secret, if (VIR_ALLOC_N(new_value, value_size) < 0) return -1; =20 - old_value =3D secret->value; - old_value_size =3D secret->value_size; + old_value =3D obj->value; + old_value_size =3D obj->value_size; =20 memcpy(new_value, value, value_size); - secret->value =3D new_value; - secret->value_size =3D value_size; + obj->value =3D new_value; + obj->value_size =3D value_size; =20 - if (!secret->def->isephemeral && virSecretObjSaveData(secret) < 0) + if (!obj->def->isephemeral && virSecretObjSaveData(obj) < 0) goto error; =20 /* Saved successfully - drop old value */ @@ -760,8 +761,8 @@ virSecretObjSetValue(virSecretObjPtr secret, =20 error: /* Error - restore previous state and free new value */ - secret->value =3D old_value; - secret->value_size =3D old_value_size; + obj->value =3D old_value; + obj->value_size =3D old_value_size; memset(new_value, 0, value_size); VIR_FREE(new_value); return -1; @@ -769,17 +770,17 @@ virSecretObjSetValue(virSecretObjPtr secret, =20 =20 size_t -virSecretObjGetValueSize(virSecretObjPtr secret) +virSecretObjGetValueSize(virSecretObjPtr obj) { - return secret->value_size; + return obj->value_size; } =20 =20 void -virSecretObjSetValueSize(virSecretObjPtr secret, +virSecretObjSetValueSize(virSecretObjPtr obj, size_t value_size) { - secret->value_size =3D value_size; + obj->value_size =3D value_size; } =20 =20 @@ -803,33 +804,33 @@ virSecretLoadValidateUUID(virSecretDefPtr def, =20 =20 static int -virSecretLoadValue(virSecretObjPtr secret) +virSecretLoadValue(virSecretObjPtr obj) { int ret =3D -1, fd =3D -1; struct stat st; char *contents =3D NULL, *value =3D NULL; size_t value_size; =20 - if ((fd =3D open(secret->base64File, O_RDONLY)) =3D=3D -1) { + if ((fd =3D open(obj->base64File, O_RDONLY)) =3D=3D -1) { if (errno =3D=3D ENOENT) { ret =3D 0; goto cleanup; } virReportSystemError(errno, _("cannot open '%s'"), - secret->base64File); + obj->base64File); goto cleanup; } =20 if (fstat(fd, &st) < 0) { virReportSystemError(errno, _("cannot stat '%s'"), - secret->base64File); + obj->base64File); goto cleanup; } =20 if ((size_t)st.st_size !=3D st.st_size) { virReportError(VIR_ERR_INTERNAL_ERROR, _("'%s' file does not fit in memory"), - secret->base64File); + obj->base64File); goto cleanup; } =20 @@ -838,7 +839,7 @@ virSecretLoadValue(virSecretObjPtr secret) =20 if (saferead(fd, contents, st.st_size) !=3D st.st_size) { virReportSystemError(errno, _("cannot read '%s'"), - secret->base64File); + obj->base64File); goto cleanup; } =20 @@ -847,15 +848,15 @@ virSecretLoadValue(virSecretObjPtr secret) if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid base64 in '%s'"), - secret->base64File); + obj->base64File); goto cleanup; } if (value =3D=3D NULL) goto cleanup; =20 - secret->value =3D (unsigned char *)value; + obj->value =3D (unsigned char *)value; value =3D NULL; - secret->value_size =3D value_size; + obj->value_size =3D value_size; =20 ret =3D 0; =20 @@ -880,7 +881,8 @@ virSecretLoad(virSecretObjListPtr secrets, const char *configDir) { virSecretDefPtr def =3D NULL; - virSecretObjPtr secret =3D NULL, ret =3D NULL; + virSecretObjPtr obj =3D NULL; + virSecretObjPtr ret =3D NULL; =20 if (!(def =3D virSecretDefParseFile(path))) goto cleanup; @@ -888,19 +890,18 @@ virSecretLoad(virSecretObjListPtr secrets, if (virSecretLoadValidateUUID(def, file) < 0) goto cleanup; =20 - if (!(secret =3D virSecretObjListAdd(secrets, def, configDir, NULL))) + if (!(obj =3D virSecretObjListAdd(secrets, def, configDir, NULL))) goto cleanup; def =3D NULL; =20 - if (virSecretLoadValue(secret) < 0) + if (virSecretLoadValue(obj) < 0) goto cleanup; =20 - ret =3D secret; - secret =3D NULL; + ret =3D obj; + obj =3D NULL; =20 cleanup: - if (secret) - virSecretObjListRemove(secrets, secret); + virSecretObjListRemove(secrets, obj); virSecretDefFree(def); return ret; } @@ -921,7 +922,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, * loop (if any). It's better to keep the secrets we managed to find.= */ while (virDirRead(dir, &de, NULL) > 0) { char *path; - virSecretObjPtr secret; + virSecretObjPtr obj; =20 if (!virFileHasSuffix(de->d_name, ".xml")) continue; @@ -929,7 +930,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, if (!(path =3D virFileBuildPath(configDir, de->d_name, NULL))) continue; =20 - if (!(secret =3D virSecretLoad(secrets, de->d_name, path, configDi= r))) { + if (!(obj =3D virSecretLoad(secrets, de->d_name, path, configDir))= ) { VIR_ERROR(_("Error reading secret: %s"), virGetLastErrorMessage()); VIR_FREE(path); @@ -937,7 +938,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, } =20 VIR_FREE(path); - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); } =20 VIR_DIR_CLOSE(dir); diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 9638b69..8038faa 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -30,7 +30,7 @@ typedef struct _virSecretObj virSecretObj; typedef virSecretObj *virSecretObjPtr; =20 void -virSecretObjEndAPI(virSecretObjPtr *secret); +virSecretObjEndAPI(virSecretObjPtr *obj); =20 typedef struct _virSecretObjList virSecretObjList; typedef virSecretObjList *virSecretObjListPtr; @@ -49,11 +49,11 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets, =20 void virSecretObjListRemove(virSecretObjListPtr secrets, - virSecretObjPtr secret); + virSecretObjPtr obj); =20 virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, - virSecretDefPtr def, + virSecretDefPtr newdef, const char *configDir, virSecretDefPtr *oldDef); =20 @@ -81,37 +81,37 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, virConnectPtr conn); =20 int -virSecretObjDeleteConfig(virSecretObjPtr secret); +virSecretObjDeleteConfig(virSecretObjPtr obj); =20 void -virSecretObjDeleteData(virSecretObjPtr secret); +virSecretObjDeleteData(virSecretObjPtr obj); =20 int -virSecretObjSaveConfig(virSecretObjPtr secret); +virSecretObjSaveConfig(virSecretObjPtr obj); =20 int -virSecretObjSaveData(virSecretObjPtr secret); +virSecretObjSaveData(virSecretObjPtr obj); =20 virSecretDefPtr -virSecretObjGetDef(virSecretObjPtr secret); +virSecretObjGetDef(virSecretObjPtr obj); =20 void -virSecretObjSetDef(virSecretObjPtr secret, +virSecretObjSetDef(virSecretObjPtr obj, virSecretDefPtr def); =20 unsigned char * -virSecretObjGetValue(virSecretObjPtr secret); +virSecretObjGetValue(virSecretObjPtr obj); =20 int -virSecretObjSetValue(virSecretObjPtr secret, +virSecretObjSetValue(virSecretObjPtr obj, const unsigned char *value, size_t value_size); =20 size_t -virSecretObjGetValueSize(virSecretObjPtr secret); +virSecretObjGetValueSize(virSecretObjPtr obj); =20 void -virSecretObjSetValueSize(virSecretObjPtr secret, +virSecretObjSetValueSize(virSecretObjPtr obj, size_t value_size); =20 int diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 2a371b6..cc050ff 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -72,6 +72,7 @@ secretDriverLock(void) virMutexLock(&driver->lock); } =20 + static void secretDriverUnlock(void) { @@ -79,7 +80,6 @@ secretDriverUnlock(void) } =20 =20 - static virSecretObjPtr secretObjFromSecret(virSecretPtr secret) { @@ -120,6 +120,7 @@ secretConnectNumOfSecrets(virConnectPtr conn) conn); } =20 + static int secretConnectListSecrets(virConnectPtr conn, char **uuids, @@ -156,10 +157,10 @@ secretLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { virSecretPtr ret =3D NULL; - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretDefPtr def; =20 - if (!(secret =3D virSecretObjListFindByUUID(driver->secrets, uuid))) { + if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuid))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(uuid, uuidstr); virReportError(VIR_ERR_NO_SECRET, @@ -167,7 +168,7 @@ secretLookupByUUID(virConnectPtr conn, goto cleanup; } =20 - def =3D virSecretObjGetDef(secret); + def =3D virSecretObjGetDef(obj); if (virSecretLookupByUUIDEnsureACL(conn, def) < 0) goto cleanup; =20 @@ -177,7 +178,7 @@ secretLookupByUUID(virConnectPtr conn, def->usage_id); =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); return ret; } =20 @@ -188,17 +189,17 @@ secretLookupByUsage(virConnectPtr conn, const char *usageID) { virSecretPtr ret =3D NULL; - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretDefPtr def; =20 - if (!(secret =3D virSecretObjListFindByUsage(driver->secrets, - usageType, usageID))) { + if (!(obj =3D virSecretObjListFindByUsage(driver->secrets, + usageType, usageID))) { virReportError(VIR_ERR_NO_SECRET, _("no secret with matching usage '%s'"), usageID); goto cleanup; } =20 - def =3D virSecretObjGetDef(secret); + def =3D virSecretObjGetDef(obj); if (virSecretLookupByUsageEnsureACL(conn, def) < 0) goto cleanup; =20 @@ -208,7 +209,7 @@ secretLookupByUsage(virConnectPtr conn, def->usage_id); =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); return ret; } =20 @@ -219,129 +220,131 @@ secretDefineXML(virConnectPtr conn, unsigned int flags) { virSecretPtr ret =3D NULL; - virSecretObjPtr secret =3D NULL; + virSecretObjPtr obj =3D NULL; virSecretDefPtr backup =3D NULL; - virSecretDefPtr new_attrs; + virSecretDefPtr def; virObjectEventPtr event =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (!(new_attrs =3D virSecretDefParseString(xml))) + if (!(def =3D virSecretDefParseString(xml))) return NULL; =20 - if (virSecretDefineXMLEnsureACL(conn, new_attrs) < 0) + if (virSecretDefineXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(secret =3D virSecretObjListAdd(driver->secrets, new_attrs, - driver->configDir, &backup))) + if (!(obj =3D virSecretObjListAdd(driver->secrets, def, + driver->configDir, &backup))) goto cleanup; =20 - if (!new_attrs->isephemeral) { + if (!def->isephemeral) { if (secretEnsureDirectory() < 0) goto cleanup; =20 if (backup && backup->isephemeral) { - if (virSecretObjSaveData(secret) < 0) + if (virSecretObjSaveData(obj) < 0) goto restore_backup; } =20 - if (virSecretObjSaveConfig(secret) < 0) { + if (virSecretObjSaveConfig(obj) < 0) { if (backup && backup->isephemeral) { /* Undo the virSecretObjSaveData() above; ignore errors */ - virSecretObjDeleteData(secret); + virSecretObjDeleteData(obj); } goto restore_backup; } } else if (backup && !backup->isephemeral) { - if (virSecretObjDeleteConfig(secret) < 0) + if (virSecretObjDeleteConfig(obj) < 0) goto restore_backup; =20 - virSecretObjDeleteData(secret); + virSecretObjDeleteData(obj); } /* Saved successfully - drop old values */ virSecretDefFree(backup); =20 - event =3D virSecretEventLifecycleNew(new_attrs->uuid, - new_attrs->usage_type, - new_attrs->usage_id, + event =3D virSecretEventLifecycleNew(def->uuid, + def->usage_type, + def->usage_id, VIR_SECRET_EVENT_DEFINED, 0); =20 ret =3D virGetSecret(conn, - new_attrs->uuid, - new_attrs->usage_type, - new_attrs->usage_id); - new_attrs =3D NULL; + def->uuid, + def->usage_type, + def->usage_id); + def =3D NULL; goto cleanup; =20 restore_backup: /* If we have a backup, then secret was defined before, so just restore - * the backup. The current (new_attrs) will be handled below. + * the backup. The current def will be handled below. * Otherwise, this is a new secret, thus remove it. */ if (backup) - virSecretObjSetDef(secret, backup); + virSecretObjSetDef(obj, backup); else - virSecretObjListRemove(driver->secrets, secret); + virSecretObjListRemove(driver->secrets, obj); =20 cleanup: - virSecretDefFree(new_attrs); - virSecretObjEndAPI(&secret); + virSecretDefFree(def); + virSecretObjEndAPI(&obj); if (event) virObjectEventStateQueue(driver->secretEventState, event); =20 return ret; } =20 + static char * -secretGetXMLDesc(virSecretPtr obj, +secretGetXMLDesc(virSecretPtr secret, unsigned int flags) { char *ret =3D NULL; - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretDefPtr def; =20 virCheckFlags(0, NULL); =20 - if (!(secret =3D secretObjFromSecret(obj))) + if (!(obj =3D secretObjFromSecret(secret))) goto cleanup; =20 - def =3D virSecretObjGetDef(secret); - if (virSecretGetXMLDescEnsureACL(obj->conn, def) < 0) + def =3D virSecretObjGetDef(obj); + if (virSecretGetXMLDescEnsureACL(secret->conn, def) < 0) goto cleanup; =20 ret =3D virSecretDefFormat(def); =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); =20 return ret; } =20 + static int -secretSetValue(virSecretPtr obj, +secretSetValue(virSecretPtr secret, const unsigned char *value, size_t value_size, unsigned int flags) { int ret =3D -1; - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretDefPtr def; virObjectEventPtr event =3D NULL; =20 virCheckFlags(0, -1); =20 - if (!(secret =3D secretObjFromSecret(obj))) + if (!(obj =3D secretObjFromSecret(secret))) goto cleanup; =20 - def =3D virSecretObjGetDef(secret); - if (virSecretSetValueEnsureACL(obj->conn, def) < 0) + def =3D virSecretObjGetDef(obj); + if (virSecretSetValueEnsureACL(secret->conn, def) < 0) goto cleanup; =20 if (secretEnsureDirectory() < 0) goto cleanup; =20 - if (virSecretObjSetValue(secret, value, value_size) < 0) + if (virSecretObjSetValue(obj, value, value_size) < 0) goto cleanup; =20 event =3D virSecretEventValueChangedNew(def->uuid, @@ -350,30 +353,31 @@ secretSetValue(virSecretPtr obj, ret =3D 0; =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); if (event) virObjectEventStateQueue(driver->secretEventState, event); =20 return ret; } =20 + static unsigned char * -secretGetValue(virSecretPtr obj, +secretGetValue(virSecretPtr secret, size_t *value_size, unsigned int flags, unsigned int internalFlags) { unsigned char *ret =3D NULL; - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretDefPtr def; =20 virCheckFlags(0, NULL); =20 - if (!(secret =3D secretObjFromSecret(obj))) + if (!(obj =3D secretObjFromSecret(secret))) goto cleanup; =20 - def =3D virSecretObjGetDef(secret); - if (virSecretGetValueEnsureACL(obj->conn, def) < 0) + def =3D virSecretObjGetDef(obj); + if (virSecretGetValueEnsureACL(secret->conn, def) < 0) goto cleanup; =20 if ((internalFlags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) =3D=3D 0 && @@ -383,33 +387,34 @@ secretGetValue(virSecretPtr obj, goto cleanup; } =20 - if (!(ret =3D virSecretObjGetValue(secret))) + if (!(ret =3D virSecretObjGetValue(obj))) goto cleanup; =20 - *value_size =3D virSecretObjGetValueSize(secret); + *value_size =3D virSecretObjGetValueSize(obj); =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); =20 return ret; } =20 + static int -secretUndefine(virSecretPtr obj) +secretUndefine(virSecretPtr secret) { int ret =3D -1; - virSecretObjPtr secret; + virSecretObjPtr obj; virSecretDefPtr def; virObjectEventPtr event =3D NULL; =20 - if (!(secret =3D secretObjFromSecret(obj))) + if (!(obj =3D secretObjFromSecret(secret))) goto cleanup; =20 - def =3D virSecretObjGetDef(secret); - if (virSecretUndefineEnsureACL(obj->conn, def) < 0) + def =3D virSecretObjGetDef(obj); + if (virSecretUndefineEnsureACL(secret->conn, def) < 0) goto cleanup; =20 - if (virSecretObjDeleteConfig(secret) < 0) + if (virSecretObjDeleteConfig(obj) < 0) goto cleanup; =20 event =3D virSecretEventLifecycleNew(def->uuid, @@ -418,20 +423,21 @@ secretUndefine(virSecretPtr obj) VIR_SECRET_EVENT_UNDEFINED, 0); =20 - virSecretObjDeleteData(secret); + virSecretObjDeleteData(obj); =20 - virSecretObjListRemove(driver->secrets, secret); + virSecretObjListRemove(driver->secrets, obj); =20 ret =3D 0; =20 cleanup: - virSecretObjEndAPI(&secret); + virSecretObjEndAPI(&obj); if (event) virObjectEventStateQueue(driver->secretEventState, event); =20 return ret; } =20 + static int secretStateCleanup(void) { @@ -452,6 +458,7 @@ secretStateCleanup(void) return 0; } =20 + static int secretStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, @@ -497,6 +504,7 @@ secretStateInitialize(bool privileged, return -1; } =20 + static int secretStateReload(void) { @@ -511,6 +519,7 @@ secretStateReload(void) return 0; } =20 + static int secretConnectSecretEventRegisterAny(virConnectPtr conn, virSecretPtr secret, @@ -532,6 +541,7 @@ secretConnectSecretEventRegisterAny(virConnectPtr conn, return callbackID; } =20 + static int secretConnectSecretEventDeregisterAny(virConnectPtr conn, int callbackID) @@ -576,6 +586,7 @@ static virStateDriver stateDriver =3D { .stateReload =3D secretStateReload, }; =20 + int secretRegister(void) { --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056859052517.0097388078182; Mon, 24 Apr 2017 11:00:59 -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 1B15FC05975A; Mon, 24 Apr 2017 18:00:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E683C81F81; Mon, 24 Apr 2017 18:00:56 +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 EA2F65EC71; Mon, 24 Apr 2017 18:00:50 +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 v3OI0abI004720 for ; Mon, 24 Apr 2017 14:00:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 36B5C77ECA; Mon, 24 Apr 2017 18:00:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01CD317A7B for ; Mon, 24 Apr 2017 18:00:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B15FC05975A 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 1B15FC05975A From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:15 -0400 Message-Id: <20170424180023.4695-7-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/14] secret: Use virSecretDefPtr rather than deref from virSecretObjPtr 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]); Mon, 24 Apr 2017 18:00:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than dereferencing obj->def->X, create a local 'def' variable variable that will dereference the def and use directly. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 69 +++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 42f36c8..413955d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -139,8 +139,9 @@ static void virSecretObjDispose(void *opaque) { virSecretObjPtr obj =3D opaque; + virSecretDefPtr def =3D obj->def; =20 - virSecretDefFree(obj->def); + virSecretDefFree(def); if (obj->value) { /* Wipe before free to ensure we don't leave a secret on the heap = */ memset(obj->value, 0, obj->value_size); @@ -203,16 +204,18 @@ virSecretObjSearchName(const void *payload, const void *opaque) { virSecretObjPtr obj =3D (virSecretObjPtr) payload; + virSecretDefPtr def; struct virSecretSearchData *data =3D (struct virSecretSearchData *) op= aque; int found =3D 0; =20 virObjectLock(obj); + def =3D obj->def; =20 - if (obj->def->usage_type !=3D data->usageType) + if (def->usage_type !=3D data->usageType) goto cleanup; =20 if (data->usageType !=3D VIR_SECRET_USAGE_TYPE_NONE && - STREQ(obj->def->usage_id, data->usageID)) + STREQ(def->usage_id, data->usageID)) found =3D 1; =20 cleanup: @@ -278,11 +281,13 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr obj) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + virSecretDefPtr def; =20 if (!obj) return; + def =3D obj->def; =20 - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); virObjectRef(obj); virObjectUnlock(obj); =20 @@ -315,6 +320,7 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, virSecretDefPtr *oldDef) { virSecretObjPtr obj; + virSecretDefPtr def; virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; @@ -325,26 +331,27 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, /* Is there a secret already matching this UUID */ if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, newdef->uuid)))= { virObjectLock(obj); + def =3D obj->def; =20 - if (STRNEQ_NULLABLE(obj->def->usage_id, newdef->usage_id)) { - virUUIDFormat(obj->def->uuid, uuidstr); + if (STRNEQ_NULLABLE(def->usage_id, newdef->usage_id)) { + virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), - uuidstr, obj->def->usage_id); + uuidstr, def->usage_id); goto cleanup; } =20 - if (obj->def->isprivate && !newdef->isprivate) { + if (def->isprivate && !newdef->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); goto cleanup; } =20 if (oldDef) - *oldDef =3D obj->def; + *oldDef =3D def; else - virSecretDefFree(obj->def); + virSecretDefFree(def); obj->def =3D newdef; } else { /* No existing secret with same UUID, @@ -353,7 +360,8 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, newdef->usage_type, newdef->usage_id))) { virObjectLock(obj); - virUUIDFormat(obj->def->uuid, uuidstr); + def =3D obj->def; + virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for " "use with %s"), @@ -424,6 +432,7 @@ virSecretObjListGetHelper(void *payload, { struct virSecretObjListGetHelperData *data =3D opaque; virSecretObjPtr obj =3D payload; + virSecretDefPtr def; =20 if (data->error) return 0; @@ -432,8 +441,9 @@ virSecretObjListGetHelper(void *payload, return 0; =20 virObjectLock(obj); + def =3D obj->def; =20 - if (data->filter && !data->filter(data->conn, obj->def)) + if (data->filter && !data->filter(data->conn, def)) goto cleanup; =20 if (data->uuids) { @@ -444,7 +454,7 @@ virSecretObjListGetHelper(void *payload, goto cleanup; } =20 - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); data->uuids[data->got] =3D uuidstr; } =20 @@ -478,20 +488,22 @@ static bool virSecretObjMatchFlags(virSecretObjPtr obj, unsigned int flags) { + virSecretDefPtr def =3D obj->def; + /* filter by whether it's ephemeral */ if (MATCH(VIR_CONNECT_LIST_SECRETS_FILTERS_EPHEMERAL) && !((MATCH(VIR_CONNECT_LIST_SECRETS_EPHEMERAL) && - obj->def->isephemeral) || + def->isephemeral) || (MATCH(VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL) && - !obj->def->isephemeral))) + !def->isephemeral))) return false; =20 /* filter by whether it's private */ if (MATCH(VIR_CONNECT_LIST_SECRETS_FILTERS_PRIVATE) && !((MATCH(VIR_CONNECT_LIST_SECRETS_PRIVATE) && - obj->def->isprivate) || + def->isprivate) || (MATCH(VIR_CONNECT_LIST_SECRETS_NO_PRIVATE) && - !obj->def->isprivate))) + !def->isprivate))) return false; =20 return true; @@ -515,14 +527,16 @@ virSecretObjListPopulate(void *payload, { struct virSecretObjListData *data =3D opaque; virSecretObjPtr obj =3D payload; + virSecretDefPtr def; virSecretPtr secret =3D NULL; =20 if (data->error) return 0; =20 virObjectLock(obj); + def =3D obj->def; =20 - if (data->filter && !data->filter(data->conn, obj->def)) + if (data->filter && !data->filter(data->conn, def)) goto cleanup; =20 if (!virSecretObjMatchFlags(obj, data->flags)) @@ -533,9 +547,9 @@ virSecretObjListPopulate(void *payload, goto cleanup; } =20 - if (!(secret =3D virGetSecret(data->conn, obj->def->uuid, - obj->def->usage_type, - obj->def->usage_id))) { + if (!(secret =3D virGetSecret(data->conn, def->uuid, + def->usage_type, + def->usage_id))) { data->error =3D true; goto cleanup; } @@ -624,7 +638,9 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, int virSecretObjDeleteConfig(virSecretObjPtr obj) { - if (!obj->def->isephemeral && + virSecretDefPtr def =3D obj->def; + + if (!def->isephemeral && unlink(obj->configFile) < 0 && errno !=3D ENOENT) { virReportSystemError(errno, _("cannot unlink '%s'"), obj->configFile); @@ -653,10 +669,11 @@ virSecretObjDeleteData(virSecretObjPtr obj) int virSecretObjSaveConfig(virSecretObjPtr obj) { + virSecretDefPtr def =3D obj->def; char *xml =3D NULL; int ret =3D -1; =20 - if (!(xml =3D virSecretDefFormat(obj->def))) + if (!(xml =3D virSecretDefFormat(def))) goto cleanup; =20 if (virFileRewriteStr(obj->configFile, S_IRUSR | S_IWUSR, xml) < 0) @@ -711,11 +728,12 @@ virSecretObjSetDef(virSecretObjPtr obj, unsigned char * virSecretObjGetValue(virSecretObjPtr obj) { + virSecretDefPtr def =3D obj->def; unsigned char *ret =3D NULL; =20 if (!obj->value) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_NO_SECRET, _("secret '%s' does not have a value"), uuidstr); goto cleanup; @@ -735,6 +753,7 @@ virSecretObjSetValue(virSecretObjPtr obj, const unsigned char *value, size_t value_size) { + virSecretDefPtr def =3D obj->def; unsigned char *old_value, *new_value; size_t old_value_size; =20 @@ -748,7 +767,7 @@ virSecretObjSetValue(virSecretObjPtr obj, obj->value =3D new_value; obj->value_size =3D value_size; =20 - if (!obj->def->isephemeral && virSecretObjSaveData(obj) < 0) + if (!def->isephemeral && virSecretObjSaveData(obj) < 0) goto error; =20 /* Saved successfully - drop old value */ --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056847596157.5847397284881; Mon, 24 Apr 2017 11:00:47 -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 1216414B0F9; Mon, 24 Apr 2017 18:00:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D85B818A7B; Mon, 24 Apr 2017 18:00:44 +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 770495EC6A; Mon, 24 Apr 2017 18:00:44 +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 v3OI0biW004728 for ; Mon, 24 Apr 2017 14:00:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B82777ED5; Mon, 24 Apr 2017 18:00:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id D237B17A7B for ; Mon, 24 Apr 2017 18:00:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1216414B0F9 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 1216414B0F9 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:16 -0400 Message-Id: <20170424180023.4695-8-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/14] secret: Move virSecretObjListGetUUIDs 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.38]); Mon, 24 Apr 2017 18:00:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move code closer to usage. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 62 ++++++++++++++++++++++++---------------------= ---- src/conf/virsecretobj.h | 14 +++++------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 413955d..998f815 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -483,6 +483,37 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secre= ts, } =20 =20 +int +virSecretObjListGetUUIDs(virSecretObjListPtr secrets, + char **uuids, + int nuuids, + virSecretObjListACLFilter filter, + virConnectPtr conn) +{ + int ret =3D -1; + + struct virSecretObjListGetHelperData data =3D { + .conn =3D conn, .filter =3D filter, .got =3D 0, + .uuids =3D uuids, .nuuids =3D nuuids, .error =3D false }; + + virObjectLock(secrets); + virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); + virObjectUnlock(secrets); + + if (data.error) + goto cleanup; + + ret =3D data.got; + + cleanup: + if (ret < 0) { + while (data.got) + VIR_FREE(data.uuids[--data.got]); + } + return ret; +} + + #define MATCH(FLAG) (flags & (FLAG)) static bool virSecretObjMatchFlags(virSecretObjPtr obj, @@ -605,37 +636,6 @@ virSecretObjListExport(virConnectPtr conn, =20 =20 int -virSecretObjListGetUUIDs(virSecretObjListPtr secrets, - char **uuids, - int nuuids, - virSecretObjListACLFilter filter, - virConnectPtr conn) -{ - int ret =3D -1; - - struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .filter =3D filter, .got =3D 0, - .uuids =3D uuids, .nuuids =3D nuuids, .error =3D false }; - - virObjectLock(secrets); - virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); - virObjectUnlock(secrets); - - if (data.error) - goto cleanup; - - ret =3D data.got; - - cleanup: - if (ret < 0) { - while (data.got) - VIR_FREE(data.uuids[--data.got]); - } - return ret; -} - - -int virSecretObjDeleteConfig(virSecretObjPtr obj) { virSecretDefPtr def =3D obj->def; diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 8038faa..82915d0 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -67,13 +67,6 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, virConnectPtr conn); =20 int -virSecretObjListExport(virConnectPtr conn, - virSecretObjListPtr secretobjs, - virSecretPtr **secrets, - virSecretObjListACLFilter filter, - unsigned int flags); - -int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, int nuuids, @@ -81,6 +74,13 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, virConnectPtr conn); =20 int +virSecretObjListExport(virConnectPtr conn, + virSecretObjListPtr secretobjs, + virSecretPtr **secrets, + virSecretObjListACLFilter filter, + unsigned int flags); + +int virSecretObjDeleteConfig(virSecretObjPtr obj); =20 void --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056852136120.53247273855595; Mon, 24 Apr 2017 11:00:52 -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 4E591C04B94E; Mon, 24 Apr 2017 18:00:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2428B8367F; Mon, 24 Apr 2017 18:00:49 +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 C05E65EC6F; Mon, 24 Apr 2017 18:00:48 +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 v3OI0dRH004743 for ; Mon, 24 Apr 2017 14:00:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4442E183C0; Mon, 24 Apr 2017 18:00:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05CCD17A7B for ; Mon, 24 Apr 2017 18:00:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E591C04B94E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 4E591C04B94E From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:17 -0400 Message-Id: <20170424180023.4695-9-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/14] secret: Change variable names for list traversals 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.31]); Mon, 24 Apr 2017 18:00:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than 'nuuids' it should be 'maxuuids' and rather than 'got' it should be 'nuuids'. Alter the logic of the list traversal to utilize those names. Also alter the cleanup in virSecretObjListGetUUIDs to return on success and handle failure with a -1 return instead of the if (ret < 0) logic. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 38 +++++++++++++++++--------------------- src/conf/virsecretobj.h | 2 +- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 998f815..c410a6b 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -418,9 +418,9 @@ virSecretObjListAdd(virSecretObjListPtr secrets, struct virSecretObjListGetHelperData { virConnectPtr conn; virSecretObjListACLFilter filter; - int got; - char **uuids; int nuuids; + char **uuids; + int maxuuids; bool error; }; =20 @@ -437,7 +437,7 @@ virSecretObjListGetHelper(void *payload, if (data->error) return 0; =20 - if (data->nuuids >=3D 0 && data->got =3D=3D data->nuuids) + if (data->maxuuids >=3D 0 && data->nuuids =3D=3D data->maxuuids) return 0; =20 virObjectLock(obj); @@ -455,10 +455,10 @@ virSecretObjListGetHelper(void *payload, } =20 virUUIDFormat(def->uuid, uuidstr); - data->uuids[data->got] =3D uuidstr; + data->uuids[data->nuuids] =3D uuidstr; } =20 - data->got++; + data->nuuids++; =20 cleanup: virObjectUnlock(obj); @@ -472,45 +472,41 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secr= ets, virConnectPtr conn) { struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .filter =3D filter, .got =3D 0, - .uuids =3D NULL, .nuuids =3D -1, .error =3D false }; + .conn =3D conn, .filter =3D filter, .nuuids =3D 0, + .uuids =3D NULL, .maxuuids =3D -1, .error =3D false }; =20 virObjectLock(secrets); virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); virObjectUnlock(secrets); =20 - return data.got; + return data.nuuids; } =20 =20 int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, - int nuuids, + int maxuuids, virSecretObjListACLFilter filter, virConnectPtr conn) { - int ret =3D -1; - struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .filter =3D filter, .got =3D 0, - .uuids =3D uuids, .nuuids =3D nuuids, .error =3D false }; + .conn =3D conn, .filter =3D filter, .nuuids =3D 0, + .uuids =3D uuids, .maxuuids =3D maxuuids, .error =3D false }; =20 virObjectLock(secrets); virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); virObjectUnlock(secrets); =20 if (data.error) - goto cleanup; + goto error; =20 - ret =3D data.got; + return data.nuuids; =20 - cleanup: - if (ret < 0) { - while (data.got) - VIR_FREE(data.uuids[--data.got]); - } - return ret; + error: + while (--data.nuuids) + VIR_FREE(data.uuids[data.nuuids]); + return -1; } =20 =20 diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 82915d0..7582913 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -69,7 +69,7 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, - int nuuids, + int maxuuids, virSecretObjListACLFilter filter, virConnectPtr conn); =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056850065668.4334374088561; Mon, 24 Apr 2017 11:00:50 -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 97B8479350; Mon, 24 Apr 2017 18:00:47 +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 71322179F4; Mon, 24 Apr 2017 18:00:47 +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 1ADFC18523D4; Mon, 24 Apr 2017 18:00:47 +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 v3OI0fYZ004753 for ; Mon, 24 Apr 2017 14:00:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5D0D077ECA; Mon, 24 Apr 2017 18:00:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B461183C0 for ; Mon, 24 Apr 2017 18:00:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 97B8479350 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 97B8479350 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:18 -0400 Message-Id: <20170424180023.4695-10-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/14] secret: Split apart NumOfSecrets and GetUUIDs callback function 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.28]); Mon, 24 Apr 2017 18:00:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than overloading one function - split apart the logic to have separate interfaces and local/private structures to manage the data for which the helper is collecting. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 98 +++++++++++++++++++++++++++++++--------------= ---- src/conf/virsecretobj.h | 6 +-- 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index c410a6b..3717552 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -415,9 +415,54 @@ virSecretObjListAdd(virSecretObjListPtr secrets, } =20 =20 -struct virSecretObjListGetHelperData { +struct secretCountData { virConnectPtr conn; - virSecretObjListACLFilter filter; + virSecretObjListACLFilter aclfilter; + int count; +}; + +static int +virSecretObjListNumOfSecretsCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + struct secretCountData *data =3D opaque; + virSecretObjPtr obj =3D payload; + virSecretDefPtr def; + + virObjectLock(obj); + def =3D obj->def; + + if (data->aclfilter && !data->aclfilter(data->conn, def)) + goto cleanup; + + data->count++; + + cleanup: + virObjectUnlock(obj); + return 0; +} + + +int +virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, + virSecretObjListACLFilter aclfilter, + virConnectPtr conn) +{ + struct secretCountData data =3D { + .conn =3D conn, .aclfilter =3D aclfilter, .count =3D 0 }; + + virObjectLock(secrets); + virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &d= ata); + virObjectUnlock(secrets); + + return data.count; +} + + +struct secretListData { + virConnectPtr conn; + virSecretObjListACLFilter aclfilter; int nuuids; char **uuids; int maxuuids; @@ -426,11 +471,11 @@ struct virSecretObjListGetHelperData { =20 =20 static int -virSecretObjListGetHelper(void *payload, - const void *name ATTRIBUTE_UNUSED, - void *opaque) +virSecretObjListGetUUIDsCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) { - struct virSecretObjListGetHelperData *data =3D opaque; + struct secretListData *data =3D opaque; virSecretObjPtr obj =3D payload; virSecretDefPtr def; =20 @@ -443,7 +488,7 @@ virSecretObjListGetHelper(void *payload, virObjectLock(obj); def =3D obj->def; =20 - if (data->filter && !data->filter(data->conn, def)) + if (data->aclfilter && !data->aclfilter(data->conn, def)) goto cleanup; =20 if (data->uuids) { @@ -455,11 +500,9 @@ virSecretObjListGetHelper(void *payload, } =20 virUUIDFormat(def->uuid, uuidstr); - data->uuids[data->nuuids] =3D uuidstr; + data->uuids[data->nuuids++] =3D uuidstr; } =20 - data->nuuids++; - cleanup: virObjectUnlock(obj); return 0; @@ -467,35 +510,18 @@ virSecretObjListGetHelper(void *payload, =20 =20 int -virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, - virSecretObjListACLFilter filter, - virConnectPtr conn) -{ - struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .filter =3D filter, .nuuids =3D 0, - .uuids =3D NULL, .maxuuids =3D -1, .error =3D false }; - - virObjectLock(secrets); - virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); - virObjectUnlock(secrets); - - return data.nuuids; -} - - -int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, int maxuuids, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, virConnectPtr conn) { - struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .filter =3D filter, .nuuids =3D 0, - .uuids =3D uuids, .maxuuids =3D maxuuids, .error =3D false }; + struct secretListData data =3D { + .conn =3D conn, .aclfilter =3D aclfilter, .uuids =3D uuids, .nuuid= s =3D 0, + .maxuuids =3D maxuuids, .error =3D false }; =20 virObjectLock(secrets); - virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); + virHashForEach(secrets->objs, virSecretObjListGetUUIDsCallback, &data); virObjectUnlock(secrets); =20 if (data.error) @@ -541,7 +567,7 @@ virSecretObjMatchFlags(virSecretObjPtr obj, struct virSecretObjListData { virConnectPtr conn; virSecretPtr *secrets; - virSecretObjListACLFilter filter; + virSecretObjListACLFilter aclfilter; unsigned int flags; int nsecrets; bool error; @@ -563,7 +589,7 @@ virSecretObjListPopulate(void *payload, virObjectLock(obj); def =3D obj->def; =20 - if (data->filter && !data->filter(data->conn, def)) + if (data->aclfilter && !data->aclfilter(data->conn, def)) goto cleanup; =20 if (!virSecretObjMatchFlags(obj, data->flags)) @@ -593,13 +619,13 @@ int virSecretObjListExport(virConnectPtr conn, virSecretObjListPtr secretobjs, virSecretPtr **secrets, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, unsigned int flags) { int ret =3D -1; struct virSecretObjListData data =3D { .conn =3D conn, .secrets =3D NULL, - .filter =3D filter, .flags =3D flags, + .aclfilter =3D aclfilter, .flags =3D flags, .nsecrets =3D 0, .error =3D false }; =20 virObjectLock(secretobjs); diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 7582913..bd38f52 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -63,21 +63,21 @@ typedef bool =20 int virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, virConnectPtr conn); =20 int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, int maxuuids, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, virConnectPtr conn); =20 int virSecretObjListExport(virConnectPtr conn, virSecretObjListPtr secretobjs, virSecretPtr **secrets, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, unsigned int flags); =20 int --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056856084806.7634993861781; Mon, 24 Apr 2017 11:00:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A030761B90; Mon, 24 Apr 2017 18:00:53 +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 597EE77714; Mon, 24 Apr 2017 18:00:53 +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 0608E18523D8; Mon, 24 Apr 2017 18:00:53 +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 v3OI0h5Q004769 for ; Mon, 24 Apr 2017 14:00:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3080877ECA; Mon, 24 Apr 2017 18:00:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC870183C0 for ; Mon, 24 Apr 2017 18:00:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A030761B90 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 A030761B90 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:19 -0400 Message-Id: <20170424180023.4695-11-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/14] secret: Combine virSecretObjListAdd with Locked function 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Apr 2017 18:00:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There's no need to separate, so just have one. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 3717552..5acda4c 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -301,7 +301,7 @@ virSecretObjListRemove(virSecretObjListPtr secrets, =20 =20 /* - * virSecretObjListAddLocked: + * virSecretObjListAdd: * @secrets: list of secret objects * @newdef: new secret definition * @configDir: directory to place secret config files @@ -309,15 +309,13 @@ virSecretObjListRemove(virSecretObjListPtr secrets, * * Add the new @newdef to the secret obj table hash * - * This functions requires @secrets to be locked already! - * - * Returns: locked secret or NULL if failure to add + * Returns: locked and ref'd secret or NULL if failure to add */ -static virSecretObjPtr -virSecretObjListAddLocked(virSecretObjListPtr secrets, - virSecretDefPtr newdef, - const char *configDir, - virSecretDefPtr *oldDef) +virSecretObjPtr +virSecretObjListAdd(virSecretObjListPtr secrets, + virSecretDefPtr newdef, + const char *configDir, + virSecretDefPtr *oldDef) { virSecretObjPtr obj; virSecretDefPtr def; @@ -325,6 +323,8 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; =20 + virObjectLock(secrets); + if (oldDef) *oldDef =3D NULL; =20 @@ -396,22 +396,8 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, virSecretObjEndAPI(&obj); VIR_FREE(configFile); VIR_FREE(base64File); - return ret; -} - - -virSecretObjPtr -virSecretObjListAdd(virSecretObjListPtr secrets, - virSecretDefPtr newdef, - const char *configDir, - virSecretDefPtr *oldDef) -{ - virSecretObjPtr obj; - - virObjectLock(secrets); - obj =3D virSecretObjListAddLocked(secrets, newdef, configDir, oldDef); virObjectUnlock(secrets); - return obj; + return ret; } =20 =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056889699686.6258975990813; Mon, 24 Apr 2017 11:01:29 -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 CB8E5B1C98; Mon, 24 Apr 2017 18:01:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A58F7179D0; Mon, 24 Apr 2017 18:01:27 +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 3DB555ED63; Mon, 24 Apr 2017 18:00:55 +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 v3OI0jbr004779 for ; Mon, 24 Apr 2017 14:00:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 314BF183C0; Mon, 24 Apr 2017 18:00:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id F01E17E2C2 for ; Mon, 24 Apr 2017 18:00:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CB8E5B1C98 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 CB8E5B1C98 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:20 -0400 Message-Id: <20170424180023.4695-12-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/14] secret: Alter FindByUUID to expect the formatted uuidstr 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.30]); Mon, 24 Apr 2017 18:01:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since we're storing a virUUIDFormat'd string in our Hash Table, let's modify the Lookup API to receive a formatted string as well. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 18 +++++++----------- src/conf/virsecretobj.h | 2 +- src/secret/secret_driver.c | 10 +++++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 5acda4c..ae2b287 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -163,12 +163,8 @@ virSecretObjListDispose(void *obj) =20 static virSecretObjPtr virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets, - const unsigned char *uuid) + const char *uuidstr) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(uuid, uuidstr); - return virObjectRef(virHashLookup(secrets->objs, uuidstr)); } =20 @@ -176,7 +172,7 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr se= crets, /** * virSecretObjFindByUUID: * @secrets: list of secret objects - * @uuid: secret uuid to find + * @uuidstr: secret uuid to find * * This function locks @secrets and finds the secret object which * corresponds to @uuid. @@ -185,12 +181,12 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr = secrets, */ virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, - const unsigned char *uuid) + const char *uuidstr) { virSecretObjPtr obj; =20 virObjectLock(secrets); - obj =3D virSecretObjListFindByUUIDLocked(secrets, uuid); + obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr); virObjectUnlock(secrets); if (obj) virObjectLock(obj); @@ -328,13 +324,14 @@ virSecretObjListAdd(virSecretObjListPtr secrets, if (oldDef) *oldDef =3D NULL; =20 + virUUIDFormat(newdef->uuid, uuidstr); + /* Is there a secret already matching this UUID */ - if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, newdef->uuid)))= { + if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr))) { virObjectLock(obj); def =3D obj->def; =20 if (STRNEQ_NULLABLE(def->usage_id, newdef->usage_id)) { - virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), @@ -372,7 +369,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, /* Generate the possible configFile and base64File strings * using the configDir, uuidstr, and appropriate suffix */ - virUUIDFormat(newdef->uuid, uuidstr); if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml"))= || !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64= "))) goto cleanup; diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index bd38f52..092f23c 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -40,7 +40,7 @@ virSecretObjListNew(void); =20 virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, - const unsigned char *uuid); + const char *uuidstr); =20 virSecretObjPtr virSecretObjListFindByUsage(virSecretObjListPtr secrets, diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index cc050ff..2d4091d 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -86,8 +86,8 @@ secretObjFromSecret(virSecretPtr secret) virSecretObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, secret->uuid= ))) { - virUUIDFormat(secret->uuid, uuidstr); + virUUIDFormat(secret->uuid, uuidstr); + if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuidstr))) { virReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); return NULL; @@ -159,10 +159,10 @@ secretLookupByUUID(virConnectPtr conn, virSecretPtr ret =3D NULL; virSecretObjPtr obj; virSecretDefPtr def; + char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuid))) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(uuid, uuidstr); + virUUIDFormat(uuid, uuidstr); + if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuidstr))) { virReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056854287441.13062280593147; Mon, 24 Apr 2017 11:00:54 -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 655C0C0467E5; Mon, 24 Apr 2017 18:00:52 +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 296CF88F33; Mon, 24 Apr 2017 18:00:52 +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 CC0D018523D6; Mon, 24 Apr 2017 18:00:51 +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 v3OI0nhN004796 for ; Mon, 24 Apr 2017 14:00:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7CA2177ECD; Mon, 24 Apr 2017 18:00:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 355A777EE1 for ; Mon, 24 Apr 2017 18:00:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 655C0C0467E5 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 655C0C0467E5 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:21 -0400 Message-Id: <20170424180023.4695-13-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/14] secret: Generate configDir during driver initialization 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.31]); Mon, 24 Apr 2017 18:00:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than waiting for the first save to fail, let's generate the directory with the correct privs during initialization Signed-off-by: John Ferlan --- src/secret/secret_driver.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 2d4091d..8ddae57 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -96,17 +96,6 @@ secretObjFromSecret(virSecretPtr secret) } =20 =20 -static int -secretEnsureDirectory(void) -{ - if (mkdir(driver->configDir, S_IRWXU) < 0 && errno !=3D EEXIST) { - virReportSystemError(errno, _("cannot create '%s'"), - driver->configDir); - return -1; - } - return 0; -} - /* Driver functions */ =20 static int @@ -238,9 +227,6 @@ secretDefineXML(virConnectPtr conn, goto cleanup; =20 if (!def->isephemeral) { - if (secretEnsureDirectory() < 0) - goto cleanup; - if (backup && backup->isephemeral) { if (virSecretObjSaveData(obj) < 0) goto restore_backup; @@ -341,9 +327,6 @@ secretSetValue(virSecretPtr secret, if (virSecretSetValueEnsureACL(secret->conn, def) < 0) goto cleanup; =20 - if (secretEnsureDirectory() < 0) - goto cleanup; - if (virSecretObjSetValue(obj, value, value_size) < 0) goto cleanup; =20 @@ -488,6 +471,12 @@ secretStateInitialize(bool privileged, goto error; VIR_FREE(base); =20 + if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create config directory '%s'= "), + driver->configDir); + goto error; + } + if (!(driver->secrets =3D virSecretObjListNew())) goto error; =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056891089293.7087474806307; Mon, 24 Apr 2017 11:01:31 -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 136C2C04BD28; Mon, 24 Apr 2017 18:01:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB36477EC5; Mon, 24 Apr 2017 18:01:28 +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 EFC2B5ED67; Mon, 24 Apr 2017 18:00:56 +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 v3OI0on6004801 for ; Mon, 24 Apr 2017 14:00:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 117F777ED3; Mon, 24 Apr 2017 18:00:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id B18B3183C0 for ; Mon, 24 Apr 2017 18:00:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 136C2C04BD28 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 136C2C04BD28 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:22 -0400 Message-Id: <20170424180023.4695-14-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/14] secret: Alter configFile/base64File mgmt 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.31]); Mon, 24 Apr 2017 18:01:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than being generated during virSecretObjListAdd, generate the file paths in each of the callers and then copy those paths into the object rather than stealing their pointers. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 53 ++++++++++++++++++++++++------------------= ---- src/conf/virsecretobj.h | 3 ++- src/secret/secret_driver.c | 14 ++++++++++-- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index ae2b287..7a9908d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -300,7 +300,8 @@ virSecretObjListRemove(virSecretObjListPtr secrets, * virSecretObjListAdd: * @secrets: list of secret objects * @newdef: new secret definition - * @configDir: directory to place secret config files + * @configFile: secret config file + * @base64File: secret data file * @oldDef: Former secret def (e.g. a reload path perhaps) * * Add the new @newdef to the secret obj table hash @@ -310,14 +311,14 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefPtr newdef, - const char *configDir, + const char *configFile, + const char *base64File, virSecretDefPtr *oldDef) { virSecretObjPtr obj; virSecretDefPtr def; virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile =3D NULL, *base64File =3D NULL; =20 virObjectLock(secrets); =20 @@ -366,13 +367,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto cleanup; } =20 - /* Generate the possible configFile and base64File strings - * using the configDir, uuidstr, and appropriate suffix - */ - if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml"))= || - !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64= "))) - goto cleanup; - if (!(obj =3D virSecretObjNew())) goto cleanup; =20 @@ -380,8 +374,10 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto cleanup; =20 obj->def =3D newdef; - VIR_STEAL_PTR(obj->configFile, configFile); - VIR_STEAL_PTR(obj->base64File, base64File); + if ((VIR_STRDUP(obj->configFile, configFile) < 0) || + (VIR_STRDUP(obj->base64File, base64File) < 0)) + goto cleanup; + virObjectRef(obj); } =20 @@ -390,8 +386,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, =20 cleanup: virSecretObjEndAPI(&obj); - VIR_FREE(configFile); - VIR_FREE(base64File); virObjectUnlock(secrets); return ret; } @@ -899,21 +893,22 @@ virSecretLoadValue(virSecretObjPtr obj) =20 static virSecretObjPtr virSecretLoad(virSecretObjListPtr secrets, - const char *file, - const char *path, - const char *configDir) + const char *fname, + const char *configFile, + const char *base64File) { virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; virSecretObjPtr ret =3D NULL; =20 - if (!(def =3D virSecretDefParseFile(path))) + if (!(def =3D virSecretDefParseFile(configFile))) goto cleanup; =20 - if (virSecretLoadValidateUUID(def, file) < 0) + if (virSecretLoadValidateUUID(def, fname) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(secrets, def, configDir, NULL))) + if (!(obj =3D virSecretObjListAdd(secrets, def, configFile, base64File, + NULL))) goto cleanup; def =3D NULL; =20 @@ -936,6 +931,8 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, { DIR *dir =3D NULL; struct dirent *de; + char *configFile =3D NULL; + char *base64File =3D NULL; int rc; =20 if ((rc =3D virDirOpenIfExists(&dir, configDir)) <=3D 0) @@ -944,26 +941,32 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, /* Ignore errors reported by readdir or other calls within the * loop (if any). It's better to keep the secrets we managed to find.= */ while (virDirRead(dir, &de, NULL) > 0) { - char *path; virSecretObjPtr obj; =20 + VIR_FREE(configFile); + VIR_FREE(base64File); + if (!virFileHasSuffix(de->d_name, ".xml")) continue; =20 - if (!(path =3D virFileBuildPath(configDir, de->d_name, NULL))) + if (!(configFile =3D virFileBuildPath(configDir, de->d_name, ".xml= "))) + continue; + + if (!(base64File =3D virFileBuildPath(configDir, de->d_name, "base= 64"))) continue; =20 - if (!(obj =3D virSecretLoad(secrets, de->d_name, path, configDir))= ) { + if (!(obj =3D virSecretLoad(secrets, de->d_name, configFile, + base64File))) { VIR_ERROR(_("Error reading secret: %s"), virGetLastErrorMessage()); - VIR_FREE(path); continue; } =20 - VIR_FREE(path); virSecretObjEndAPI(&obj); } =20 + VIR_FREE(configFile); + VIR_FREE(base64File); VIR_DIR_CLOSE(dir); return 0; } diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 092f23c..51adc98 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -54,7 +54,8 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefPtr newdef, - const char *configDir, + const char *configFile, + const char *base64File, virSecretDefPtr *oldDef); =20 typedef bool diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 8ddae57..3f8671b 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -213,6 +213,9 @@ secretDefineXML(virConnectPtr conn, virSecretDefPtr backup =3D NULL; virSecretDefPtr def; virObjectEventPtr event =3D NULL; + char *configFile =3D NULL; + char *base64File =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 virCheckFlags(0, NULL); =20 @@ -222,8 +225,13 @@ secretDefineXML(virConnectPtr conn, if (virSecretDefineXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(driver->secrets, def, - driver->configDir, &backup))) + virUUIDFormat(def->uuid, uuidstr); + if (!(configFile =3D virFileBuildPath(driver->configDir, uuidstr, ".xm= l")) || + !(base64File =3D virFileBuildPath(driver->configDir, uuidstr, ".ba= se64"))) + goto cleanup; + + if (!(obj =3D virSecretObjListAdd(driver->secrets, def, configFile, + base64File, &backup))) goto cleanup; =20 if (!def->isephemeral) { @@ -272,6 +280,8 @@ secretDefineXML(virConnectPtr conn, virSecretObjListRemove(driver->secrets, obj); =20 cleanup: + VIR_FREE(configFile); + VIR_FREE(base64File); virSecretDefFree(def); virSecretObjEndAPI(&obj); if (event) --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 19:30:02 2024 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 1493056877335518.8180912634444; Mon, 24 Apr 2017 11:01:17 -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 240F413BF70; Mon, 24 Apr 2017 18:01:15 +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 681CE823CE; Mon, 24 Apr 2017 18:01:14 +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 55E9818523D3; Mon, 24 Apr 2017 18:00:59 +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 v3OI0qrr004810 for ; Mon, 24 Apr 2017 14:00:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E0D77E2C9; Mon, 24 Apr 2017 18:00:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4F5677ED1 for ; Mon, 24 Apr 2017 18:00:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 240F413BF70 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 240F413BF70 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:23 -0400 Message-Id: <20170424180023.4695-15-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/14] secret: Clean up virSecretObjListExport logic 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.38]); Mon, 24 Apr 2017 18:01:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Shorten the time needed to keep the list lock and alter the cleanup path to be more of an error path. Utilize the the virObjectListFree function to handle the calls for virObjectUnref on each list element and the VIR_FREE of the list instead of open coding it. Change the name of the virHashForEach callback to match the name of the Export function with the Callback added onto it. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 7a9908d..caed156 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -550,9 +550,9 @@ struct virSecretObjListData { }; =20 static int -virSecretObjListPopulate(void *payload, - const void *name ATTRIBUTE_UNUSED, - void *opaque) +virSecretObjListExportCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) { struct virSecretObjListData *data =3D opaque; virSecretObjPtr obj =3D payload; @@ -598,7 +598,6 @@ virSecretObjListExport(virConnectPtr conn, virSecretObjListACLFilter aclfilter, unsigned int flags) { - int ret =3D -1; struct virSecretObjListData data =3D { .conn =3D conn, .secrets =3D NULL, .aclfilter =3D aclfilter, .flags =3D flags, @@ -606,30 +605,28 @@ virSecretObjListExport(virConnectPtr conn, =20 virObjectLock(secretobjs); if (secrets && - VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) - goto cleanup; + VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) { + virObjectUnlock(secretobjs); + return -1; + } =20 - virHashForEach(secretobjs->objs, virSecretObjListPopulate, &data); + virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data= ); + virObjectUnlock(secretobjs); =20 if (data.error) - goto cleanup; + goto error; =20 if (data.secrets) { /* trim the array to the final size */ ignore_value(VIR_REALLOC_N(data.secrets, data.nsecrets + 1)); *secrets =3D data.secrets; - data.secrets =3D NULL; } =20 - ret =3D data.nsecrets; + return data.nsecrets; =20 - cleanup: - virObjectUnlock(secretobjs); - while (data.secrets && data.nsecrets) - virObjectUnref(data.secrets[--data.nsecrets]); - - VIR_FREE(data.secrets); - return ret; + error: + virObjectListFree(data.secrets); + return -1; } =20 =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list