From nobody Sun Feb 8 21:12:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637687405; cv=none; d=zohomail.com; s=zohoarc; b=YjFI3EfMRgaC2P/6CCktlOkzlYPbcJbkYXCNUkVTUEb0e1gbe/o/4mpjZP7VO30w0bwn3nfk6ogfxaNbKaRhXArmJF7kbxbKA2ENM9xYT87DNTTuAAJcEzN/2HFJqp/VYn3wSXEm/8lgmkouIHyEZGEq3/gYfxTSk+P7URS6N1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687405; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9/3I0ANb2+pGkdf1NnxmDLg2cNbYwRQ3BCX30+/3h74=; b=CKk/p2lGZN12lxI1dp4O9h4iKH33kW5AnVCRNzQfjUGJAOSsN3U28pePy528LHlQ+ybSqEY1/7YQlZcJFDxGqIITs16iy+Raf2WEa4z0d5cvvygEzSttcsJ43hd1DXUwgSuIUABw6p10aLpju+FSM4Ah4xJWNfNeM9m06tSWT+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1637687405792188.51835736950318; Tue, 23 Nov 2021 09:10:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-skao-aknMdaYVk3yM4Ey9g-1; Tue, 23 Nov 2021 12:10:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E63D8799F1; Tue, 23 Nov 2021 17:09:55 +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 5C37219D9F; Tue, 23 Nov 2021 17:09:55 +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 1490E1809C81; Tue, 23 Nov 2021 17:09:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ANH9qMt023136 for ; Tue, 23 Nov 2021 12:09:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id C8EB95FC25; Tue, 23 Nov 2021 17:09:52 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AF8B5C1D5; Tue, 23 Nov 2021 17:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637687404; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9/3I0ANb2+pGkdf1NnxmDLg2cNbYwRQ3BCX30+/3h74=; b=Kx01H9/zXt8PWRviBOwuABM4QSdl7PUSGfdoz1np5ikDu9PoGHSAY4V/BFEPWggapma0fG VC0USpa/6c3aaYXiIH0IQyuqC7ESUyJV3Cmc9HDctK1JwGQceANoIdqYTrt9dFfcXDOatg CBeEAYD82OdJyjCbrOmiffbYVvNiyjE= X-MC-Unique: skao-aknMdaYVk3yM4Ey9g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] virSecretObjListAdd: Transfer definition ownership Date: Tue, 23 Nov 2021 18:09:38 +0100 Message-Id: <0c6c7a3a5b10789689da22bc74cddbf70242cc91.1637686811.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637687406564100003 Content-Type: text/plain; charset="utf-8" Upon successful return from virSecretObjListAdd() the virSecretObj is the owner of secret definition. To make this ownership transfer even more visible, lets pass the definition as a double pointer and use g_steal_pointer(). Signed-off-by: Michal Privoznik --- src/conf/virsecretobj.c | 26 ++++++++++++++------------ src/conf/virsecretobj.h | 2 +- src/secret/secret_driver.c | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 212cfe103c..3fbee6f6ec 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -313,13 +313,16 @@ virSecretObjListRemove(virSecretObjList *secrets, * @configDir: directory to place secret config files * @oldDef: Former secret def (e.g. a reload path perhaps) * - * Add the new @newdef to the secret obj table hash + * Add the new @newdef to the secret obj table hash. Upon + * successful the virSecret object is the owner of @newdef and + * callers should use virSecretObjGetDef() if they need to access + * the definition as @newdef is set to NULL. * * Returns: locked and ref'd secret or NULL if failure to add */ virSecretObj * virSecretObjListAdd(virSecretObjList *secrets, - virSecretDef *newdef, + virSecretDef **newdef, const char *configDir, virSecretDef **oldDef) { @@ -333,14 +336,14 @@ virSecretObjListAdd(virSecretObjList *secrets, if (oldDef) *oldDef =3D NULL; =20 - virUUIDFormat(newdef->uuid, uuidstr); + virUUIDFormat((*newdef)->uuid, uuidstr); =20 /* Is there a secret already matching this UUID */ if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr))) { virObjectLock(obj); objdef =3D obj->def; =20 - if (STRNEQ_NULLABLE(objdef->usage_id, newdef->usage_id)) { + if (STRNEQ_NULLABLE(objdef->usage_id, (*newdef)->usage_id)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), @@ -348,7 +351,7 @@ virSecretObjListAdd(virSecretObjList *secrets, goto cleanup; } =20 - if (objdef->isprivate && !newdef->isprivate) { + if (objdef->isprivate && !(*newdef)->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); goto cleanup; @@ -358,20 +361,20 @@ virSecretObjListAdd(virSecretObjList *secrets, *oldDef =3D objdef; else virSecretDefFree(objdef); - obj->def =3D newdef; + obj->def =3D g_steal_pointer(newdef); } else { /* No existing secret with same UUID, * try look for matching usage instead */ if ((obj =3D virSecretObjListFindByUsageLocked(secrets, - newdef->usage_type, - newdef->usage_id))) { + (*newdef)->usage_type, + (*newdef)->usage_id))= ) { virObjectLock(obj); objdef =3D obj->def; virUUIDFormat(objdef->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for " "use with %s"), - uuidstr, newdef->usage_id); + uuidstr, (*newdef)->usage_id); goto cleanup; } =20 @@ -388,7 +391,7 @@ virSecretObjListAdd(virSecretObjList *secrets, if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) goto cleanup; =20 - obj->def =3D newdef; + obj->def =3D g_steal_pointer(newdef); virObjectRef(obj); } =20 @@ -874,9 +877,8 @@ virSecretLoad(virSecretObjList *secrets, if (virSecretLoadValidateUUID(def, file) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(secrets, def, configDir, NULL))) + if (!(obj =3D virSecretObjListAdd(secrets, &def, configDir, NULL))) goto cleanup; - def =3D NULL; =20 if (virSecretLoadValue(obj) < 0) { virSecretObjListRemove(secrets, obj); diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index e91b9518eb..93b4a46acf 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -50,7 +50,7 @@ virSecretObjListRemove(virSecretObjList *secrets, =20 virSecretObj * virSecretObjListAdd(virSecretObjList *secrets, - virSecretDef *newdef, + virSecretDef **newdef, const char *configDir, virSecretDef **oldDef); =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 43aeae9568..de635bba3a 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -228,10 +228,10 @@ secretDefineXML(virConnectPtr conn, if (virSecretDefineXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(driver->secrets, def, + if (!(obj =3D virSecretObjListAdd(driver->secrets, &def, driver->configDir, &backup))) goto cleanup; - objDef =3D g_steal_pointer(&def); + objDef =3D virSecretObjGetDef(obj); =20 if (!objDef->isephemeral) { if (backup && backup->isephemeral) { --=20 2.32.0