From nobody Thu May 2 07:33:46 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 1493154946476391.5093728129865; Tue, 25 Apr 2017 14:15:46 -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 CAF6C80F97; Tue, 25 Apr 2017 21:15:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5329C60E3E; Tue, 25 Apr 2017 21:15: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 E92975EC62; Tue, 25 Apr 2017 21:15:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFejm018315 for ; Tue, 25 Apr 2017 17:15:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3389C17150; Tue, 25 Apr 2017 21:15:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id E68FF1714E for ; Tue, 25 Apr 2017 21:15:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CAF6C80F97 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 CAF6C80F97 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:25 -0400 Message-Id: <20170425211535.18525-2-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/11] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 25 Apr 2017 21:15:45 +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 | 8 ++++---- src/conf/virsecretobj.h | 18 ------------------ 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 5626387..169a60b 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; @@ -169,7 +169,7 @@ virSecretObjListDispose(void *obj) * * Returns: not locked, but ref'd secret object. */ -virSecretObjPtr +static virSecretObjPtr virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets, const unsigned char *uuid) { @@ -240,7 +240,7 @@ virSecretObjSearchName(const void *payload, * * Returns: not locked, but ref'd secret object. */ -virSecretObjPtr +static virSecretObjPtr virSecretObjListFindByUsageLocked(virSecretObjListPtr secrets, int usageType, const char *usageID) @@ -324,7 +324,7 @@ virSecretObjListRemove(virSecretObjListPtr secrets, * * Returns pointer to 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 Thu May 2 07:33:46 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 1493154947399674.0203225386751; Tue, 25 Apr 2017 14:15:47 -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 ABB90C0567A2; Tue, 25 Apr 2017 21:15:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 866A01749D; Tue, 25 Apr 2017 21:15:45 +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 D83195EC63; Tue, 25 Apr 2017 21:15:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFepc018320 for ; Tue, 25 Apr 2017 17:15:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id A07D317150; Tue, 25 Apr 2017 21:15:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B62E1714E for ; Tue, 25 Apr 2017 21:15:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ABB90C0567A2 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 ABB90C0567A2 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:26 -0400 Message-Id: <20170425211535.18525-3-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/11] secret: Add NULL obj check to virSecretObjListRemove 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.32]); Tue, 25 Apr 2017 21:15:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than have the caller check if !obj before calling, just check in the function for !obj and return. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 169a60b..7c2ad90 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -298,6 +298,9 @@ virSecretObjListRemove(virSecretObjListPtr secrets, { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 + if (!obj) + return; + virUUIDFormat(secret->def->uuid, uuidstr); virObjectRef(secret); virObjectUnlock(secret); @@ -915,8 +918,7 @@ virSecretLoad(virSecretObjListPtr secrets, secret =3D NULL; =20 cleanup: - if (secret) - virSecretObjListRemove(secrets, secret); + virSecretObjListRemove(secrets, secret); virSecretDefFree(def); return ret; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:33:46 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 1493154960951968.1179981922828; Tue, 25 Apr 2017 14:16:00 -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 C85A080485; Tue, 25 Apr 2017 21:15:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9ECCB19161; Tue, 25 Apr 2017 21:15:58 +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 4C77D5EC6B; Tue, 25 Apr 2017 21:15:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFfj4018325 for ; Tue, 25 Apr 2017 17:15:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3127E17150; Tue, 25 Apr 2017 21:15:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8D6C1714E for ; Tue, 25 Apr 2017 21:15:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C85A080485 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 C85A080485 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:27 -0400 Message-Id: <20170425211535.18525-4-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/11] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 25 Apr 2017 21:15:59 +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). Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 271 ++++++++++++++++++++++-------------------= ---- src/conf/virsecretobj.h | 26 ++--- src/secret/secret_driver.c | 139 ++++++++++++----------- 3 files changed, 223 insertions(+), 213 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 7c2ad90..ac3d5be 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 @@ -195,14 +195,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 @@ -211,21 +211,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 @@ -245,14 +245,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 @@ -272,14 +272,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 @@ -294,22 +294,22 @@ virSecretObjListFindByUsage(virSecretObjListPtr secre= ts, */ void virSecretObjListRemove(virSecretObjListPtr secrets, - virSecretObjPtr secret) + virSecretObjPtr obj) { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 if (!obj) return; =20 - virUUIDFormat(secret->def->uuid, uuidstr); - virObjectRef(secret); - virObjectUnlock(secret); + 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 @@ -317,11 +317,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! * @@ -329,11 +329,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; @@ -342,71 +342,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; @@ -415,16 +413,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 @@ -496,23 +494,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; @@ -640,12 +638,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 @@ -654,11 +652,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 @@ -669,15 +667,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; @@ -689,18 +687,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; @@ -712,36 +710,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; @@ -749,7 +747,7 @@ virSecretObjGetValue(virSecretObjPtr secret) =20 =20 int -virSecretObjSetValue(virSecretObjPtr secret, +virSecretObjSetValue(virSecretObjPtr obj, const unsigned char *value, size_t value_size) { @@ -759,14 +757,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 */ @@ -779,8 +777,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; @@ -788,17 +786,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 @@ -822,33 +820,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 @@ -857,7 +855,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 @@ -866,15 +864,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 @@ -899,7 +897,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; @@ -907,18 +906,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: - virSecretObjListRemove(secrets, secret); + virSecretObjListRemove(secrets, obj); virSecretDefFree(def); return ret; } @@ -939,7 +938,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; @@ -947,7 +946,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); @@ -955,7 +954,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 Thu May 2 07:33:46 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 1493154959119538.0861331306787; Tue, 25 Apr 2017 14:15:59 -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 853D67AE85; Tue, 25 Apr 2017 21:15:57 +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 55B2818115; Tue, 25 Apr 2017 21:15:57 +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 07A0A18523D2; Tue, 25 Apr 2017 21:15:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFf5R018333 for ; Tue, 25 Apr 2017 17:15:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C47F1714E; Tue, 25 Apr 2017 21:15:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59B641749D for ; Tue, 25 Apr 2017 21:15:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 853D67AE85 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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 853D67AE85 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:28 -0400 Message-Id: <20170425211535.18525-5-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/11] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Apr 2017 21:15:58 +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 | 63 +++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index ac3d5be..f4ec4ff 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -212,16 +212,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: @@ -297,11 +299,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 @@ -334,6 +338,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; @@ -344,26 +349,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, @@ -372,7 +378,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"), @@ -443,6 +450,7 @@ virSecretObjListGetHelper(void *payload, { struct virSecretObjListGetHelperData *data =3D opaque; virSecretObjPtr obj =3D payload; + virSecretDefPtr def; =20 if (data->error) return 0; @@ -451,8 +459,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) { @@ -463,7 +472,7 @@ virSecretObjListGetHelper(void *payload, goto cleanup; } =20 - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); data->uuids[data->got] =3D uuidstr; } =20 @@ -497,20 +506,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; @@ -534,14 +545,16 @@ virSecretObjListExportCallback(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)) @@ -552,9 +565,9 @@ virSecretObjListExportCallback(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; } @@ -640,7 +653,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); @@ -727,11 +742,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; @@ -751,6 +767,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 @@ -764,7 +781,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 Thu May 2 07:33:46 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 1493154962916718.7464274984384; Tue, 25 Apr 2017 14:16:02 -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 F11D419D38F; Tue, 25 Apr 2017 21:16:00 +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 CC42E1837C; Tue, 25 Apr 2017 21:16:00 +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 7BB0E18523D4; Tue, 25 Apr 2017 21:16:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFgIj018338 for ; Tue, 25 Apr 2017 17:15:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1273117150; Tue, 25 Apr 2017 21:15:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id C691E1714E for ; Tue, 25 Apr 2017 21:15:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F11D419D38F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F11D419D38F From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:29 -0400 Message-Id: <20170425211535.18525-6-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/11] secret: Alter cleanup path for 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 25 Apr 2017 21:16:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than using "ret =3D -1" and cleanup processing, alter the return path on failure to goto error and then just return the data.got. In the error path, we no longer check for ret < 0, we just can free anything added to the array and return -1 directly Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index f4ec4ff..b5a001d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -626,8 +626,6 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, 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 }; @@ -637,16 +635,14 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, virObjectUnlock(secrets); =20 if (data.error) - goto cleanup; + goto error; =20 - ret =3D data.got; + return data.got; =20 - cleanup: - if (ret < 0) { - while (data.got) - VIR_FREE(data.uuids[--data.got]); - } - return ret; + error: + while (data.got) + VIR_FREE(data.uuids[--data.got]); + return -1; } =20 =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:33:46 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 1493154959057373.1992083287465; Tue, 25 Apr 2017 14:15:59 -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 853B4C049D5B; Tue, 25 Apr 2017 21:15:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55AE017BA3; Tue, 25 Apr 2017 21:15:57 +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 078815EC6B; Tue, 25 Apr 2017 21:15:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFgk6018343 for ; Tue, 25 Apr 2017 17:15:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D01817150; Tue, 25 Apr 2017 21:15:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C29F1749D for ; Tue, 25 Apr 2017 21:15:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 853B4C049D5B 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 853B4C049D5B From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:30 -0400 Message-Id: <20170425211535.18525-7-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/11] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 25 Apr 2017 21:15:58 +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. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 28 ++++++++++++++-------------- src/conf/virsecretobj.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index b5a001d..eae735f 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -436,9 +436,9 @@ virSecretObjListAdd(virSecretObjListPtr secrets, struct virSecretObjListGetHelperData { virConnectPtr conn; virSecretObjListACLFilter filter; - int got; - char **uuids; int nuuids; + char **uuids; + int maxuuids; bool error; }; =20 @@ -455,7 +455,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); @@ -473,10 +473,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); @@ -490,14 +490,14 @@ 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 @@ -622,13 +622,13 @@ virSecretObjListExport(virConnectPtr conn, int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, - int nuuids, + int maxuuids, virSecretObjListACLFilter filter, virConnectPtr conn) { 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); @@ -637,11 +637,11 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, if (data.error) goto error; =20 - return data.got; + return data.nuuids; =20 error: - while (data.got) - VIR_FREE(data.uuids[--data.got]); + while (--data.nuuids) + VIR_FREE(data.uuids[data.nuuids]); return -1; } =20 diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 8038faa..2cba731 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -76,7 +76,7 @@ virSecretObjListExport(virConnectPtr conn, 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 Thu May 2 07:33:46 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 1493154963110177.3760888392993; Tue, 25 Apr 2017 14:16:03 -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 26E1E7E9E2; Tue, 25 Apr 2017 21:16:01 +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 005F119175; Tue, 25 Apr 2017 21:16:00 +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 A7E5118523D1; Tue, 25 Apr 2017 21:16:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFgYD018353 for ; Tue, 25 Apr 2017 17:15:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id EAF3F17150; Tue, 25 Apr 2017 21:15:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id A72001714E for ; Tue, 25 Apr 2017 21:15:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 26E1E7E9E2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 26E1E7E9E2 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:31 -0400 Message-Id: <20170425211535.18525-8-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/11] secret: Rename 'filter' to 'aclfilter' 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.26]); Tue, 25 Apr 2017 21:16:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Makes it a bit more clear what it is. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 20 ++++++++++---------- src/conf/virsecretobj.h | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index eae735f..c02558d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -435,7 +435,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets, =20 struct virSecretObjListGetHelperData { virConnectPtr conn; - virSecretObjListACLFilter filter; + virSecretObjListACLFilter aclfilter; int nuuids; char **uuids; int maxuuids; @@ -461,7 +461,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) { @@ -486,11 +486,11 @@ virSecretObjListGetHelper(void *payload, =20 int virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, virConnectPtr conn) { struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .filter =3D filter, .nuuids =3D 0, + .conn =3D conn, .aclfilter =3D aclfilter, .nuuids =3D 0, .uuids =3D NULL, .maxuuids =3D -1, .error =3D false }; =20 virObjectLock(secrets); @@ -532,7 +532,7 @@ virSecretObjMatchFlags(virSecretObjPtr obj, struct virSecretObjListData { virConnectPtr conn; virSecretPtr *secrets; - virSecretObjListACLFilter filter; + virSecretObjListACLFilter aclfilter; unsigned int flags; int nsecrets; bool error; @@ -554,7 +554,7 @@ virSecretObjListExportCallback(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)) @@ -584,12 +584,12 @@ int virSecretObjListExport(virConnectPtr conn, virSecretObjListPtr secretobjs, virSecretPtr **secrets, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, unsigned int flags) { 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); @@ -623,11 +623,11 @@ 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, + .conn =3D conn, .aclfilter =3D aclfilter, .nuuids =3D 0, .uuids =3D uuids, .maxuuids =3D maxuuids, .error =3D false }; =20 virObjectLock(secrets); diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 2cba731..a355da7 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 virSecretObjListExport(virConnectPtr conn, virSecretObjListPtr secretobjs, virSecretPtr **secrets, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, unsigned int flags); =20 int virSecretObjListGetUUIDs(virSecretObjListPtr secrets, char **uuids, int maxuuids, - virSecretObjListACLFilter filter, + virSecretObjListACLFilter aclfilter, virConnectPtr conn); =20 int --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:33:46 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 1493154964173852.3384088517176; Tue, 25 Apr 2017 14:16:04 -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 91E2C80043; Tue, 25 Apr 2017 21:16:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6098E19160; Tue, 25 Apr 2017 21:16:02 +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 007015EC6D; Tue, 25 Apr 2017 21:16:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFhfj018358 for ; Tue, 25 Apr 2017 17:15:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6904A17150; Tue, 25 Apr 2017 21:15:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 250671714E for ; Tue, 25 Apr 2017 21:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91E2C80043 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 91E2C80043 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:32 -0400 Message-Id: <20170425211535.18525-9-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/11] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 25 Apr 2017 21:16:03 +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 | 60 +++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index c02558d..e9a36b2 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -433,7 +433,36 @@ virSecretObjListAdd(virSecretObjListPtr secrets, } =20 =20 -struct virSecretObjListGetHelperData { +struct virSecretCountData { + virConnectPtr conn; + virSecretObjListACLFilter aclfilter; + int count; +}; + +static int +virSecretObjListNumOfSecretsCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + struct virSecretCountData *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; +} + + +struct virSecretListData { virConnectPtr conn; virSecretObjListACLFilter aclfilter; int nuuids; @@ -444,11 +473,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 virSecretListData *data =3D opaque; virSecretObjPtr obj =3D payload; virSecretDefPtr def; =20 @@ -473,11 +502,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; @@ -489,15 +516,14 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secr= ets, virSecretObjListACLFilter aclfilter, virConnectPtr conn) { - struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .aclfilter =3D aclfilter, .nuuids =3D 0, - .uuids =3D NULL, .maxuuids =3D -1, .error =3D false }; + struct virSecretCountData data =3D { + .conn =3D conn, .aclfilter =3D aclfilter, .count =3D 0 }; =20 virObjectLock(secrets); - virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); + virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &d= ata); virObjectUnlock(secrets); =20 - return data.nuuids; + return data.count; } =20 =20 @@ -626,12 +652,12 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, virSecretObjListACLFilter aclfilter, virConnectPtr conn) { - struct virSecretObjListGetHelperData data =3D { - .conn =3D conn, .aclfilter =3D aclfilter, .nuuids =3D 0, - .uuids =3D uuids, .maxuuids =3D maxuuids, .error =3D false }; + struct virSecretListData 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) --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:33:46 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 149315496676538.77869491349884; Tue, 25 Apr 2017 14:16:06 -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 2A01961E5F; Tue, 25 Apr 2017 21:16:05 +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 D40CC19167; Tue, 25 Apr 2017 21:16:04 +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 712F918523D9; Tue, 25 Apr 2017 21:16:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFhgu018365 for ; Tue, 25 Apr 2017 17:15:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id D2D3117150; Tue, 25 Apr 2017 21:15:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9055E1714E for ; Tue, 25 Apr 2017 21:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2A01961E5F 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 2A01961E5F From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:33 -0400 Message-Id: <20170425211535.18525-10-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/11] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 25 Apr 2017 21:16:06 +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 e9a36b2..0311335 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -319,7 +319,7 @@ virSecretObjListRemove(virSecretObjListPtr secrets, =20 =20 /* - * virSecretObjListAddLocked: + * virSecretObjListAdd: * @secrets: list of secret objects * @newdef: new secret definition * @configDir: directory to place secret config files @@ -327,15 +327,13 @@ virSecretObjListRemove(virSecretObjListPtr secrets, * * Add the new @newdef to the secret obj table hash * - * This functions requires @secrets to be locked already! - * - * Returns pointer to 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; @@ -343,6 +341,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 @@ -414,22 +414,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 Thu May 2 07:33:46 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 1493154970390213.17921418716685; Tue, 25 Apr 2017 14:16:10 -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 80C2D3DBC6; Tue, 25 Apr 2017 21:16:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5803D18EE8; Tue, 25 Apr 2017 21:16:08 +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 0E1395EC71; Tue, 25 Apr 2017 21:16:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFi14018370 for ; Tue, 25 Apr 2017 17:15:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E0C51714E; Tue, 25 Apr 2017 21:15:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 076BC1749D for ; Tue, 25 Apr 2017 21:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80C2D3DBC6 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 80C2D3DBC6 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:34 -0400 Message-Id: <20170425211535.18525-11-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/11] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 25 Apr 2017 21:16:09 +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 0311335..62b86b7 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -171,12 +171,8 @@ virSecretObjListDispose(void *obj) */ 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 @@ -184,7 +180,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. @@ -193,12 +189,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); @@ -346,13 +342,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"), @@ -390,7 +387,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 a355da7..0196813 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 Thu May 2 07:33:46 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 1493154967556808.7308951874787; Tue, 25 Apr 2017 14:16:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13F9D7E9F2; Tue, 25 Apr 2017 21:16:06 +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 DF3A67BE4D; Tue, 25 Apr 2017 21:16:05 +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 9461C18523D9; Tue, 25 Apr 2017 21:16:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PLFicF018375 for ; Tue, 25 Apr 2017 17:15:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id B7A8617150; Tue, 25 Apr 2017 21:15:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7789B1714E for ; Tue, 25 Apr 2017 21:15:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13F9D7E9F2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 13F9D7E9F2 From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 17:15:35 -0400 Message-Id: <20170425211535.18525-12-jferlan@redhat.com> In-Reply-To: <20170425211535.18525-1-jferlan@redhat.com> References: <20170425211535.18525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/11] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 25 Apr 2017 21:16:06 +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