From nobody Wed May 14 15:43:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522272004312967.3997115459697; Wed, 28 Mar 2018 14:20:04 -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 0576181253; Wed, 28 Mar 2018 21:20:03 +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 C6D405D759; Wed, 28 Mar 2018 21:20: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 49B49181BA06; Wed, 28 Mar 2018 21:20:02 +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 w2SLJgZS000489 for ; Wed, 28 Mar 2018 17:19:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 08B3163142; Wed, 28 Mar 2018 21:19:42 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-109.phx2.redhat.com [10.3.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA58B65AC0 for ; Wed, 28 Mar 2018 21:19:41 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:26 -0400 Message-Id: <20180328211933.8033-3-jferlan@redhat.com> In-Reply-To: <20180328211933.8033-1-jferlan@redhat.com> References: <20180328211933.8033-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/9] secret: Alter virSecretObjListRemove processing 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.25]); Wed, 28 Mar 2018 21:20:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current processing requires a "fire dance" unlocking the @obj, adding an @obj ref, locking the @secrets, and relocking @obj in order to ensure proper lock ordering. This can be avoided by changing virSecretObjListRemove to take a @uuidstr instead of @obj. Then, we can lock the @secrets list, look up the @obj by @uuidstr (like we do when adding), and remove the @obj from the list. This removes the last reference to the object effectively reaping it. NB: Since prior to calling we remove the reference to the object we cannot pass anything contained within the object (such as the obj->def) because it's possible that the object could be reaped by two competing remove threads. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 38 +++++++++++++++++--------------------- src/conf/virsecretobj.h | 2 +- src/secret/secret_driver.c | 15 +++++++++------ 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 4aaf47b5d..09f6ead64 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -284,32 +284,25 @@ virSecretObjListFindByUsage(virSecretObjListPtr secre= ts, /* * virSecretObjListRemove: * @secrets: list of secret objects - * @secret: a secret object + * @uuidstr: secret uuid to find + * + * Find the object by the @uuidstr in the list, remove the object from + * the list hash table, and free the object. * - * Remove the object from the hash table. The caller must hold the lock - * on the driver owning @secrets and must have also locked @secret to - * ensure no one else is either waiting for @secret or still using it. + * Upon entry it's expected that prior to entry any locks on + * the object related to @uuidstr will have been removed. */ void virSecretObjListRemove(virSecretObjListPtr secrets, - virSecretObjPtr obj) + const char *uuidstr) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virSecretDefPtr def; - - if (!obj) - return; - def =3D obj->def; - - virUUIDFormat(def->uuid, uuidstr); - virObjectRef(obj); - virObjectUnlock(obj); + virSecretObjPtr obj; =20 virObjectRWLockWrite(secrets); - virObjectLock(obj); - virHashRemoveEntry(secrets->objs, uuidstr); - virObjectUnlock(obj); - virObjectUnref(obj); + if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr))) { + virHashRemoveEntry(secrets->objs, uuidstr); + virSecretObjEndAPI(&obj); + } virObjectRWUnlock(secrets); } =20 @@ -927,8 +920,11 @@ virSecretLoad(virSecretObjListPtr secrets, def =3D NULL; =20 if (virSecretLoadValue(obj) < 0) { - virSecretObjListRemove(secrets, obj); - virObjectLock(obj); + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(obj->def->uuid, uuidstr); + virSecretObjEndAPI(&obj); + virSecretObjListRemove(secrets, uuidstr); goto cleanup; } =20 diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index d412ee6a7..68bafc718 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -49,7 +49,7 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets, =20 void virSecretObjListRemove(virSecretObjListPtr secrets, - virSecretObjPtr obj); + const char *uuidstr); =20 virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 23a3c9bda..75bc2b0cf 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -270,9 +270,11 @@ secretDefineXML(virConnectPtr conn, virSecretObjSetDef(obj, backup); VIR_STEAL_PTR(def, objDef); } else { - virSecretObjListRemove(driver->secrets, obj); - virObjectUnref(obj); - obj =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(objDef->uuid, uuidstr); + virSecretObjEndAPI(&obj); + virSecretObjListRemove(driver->secrets, uuidstr); } =20 cleanup: @@ -392,6 +394,7 @@ secretUndefine(virSecretPtr secret) int ret =3D -1; virSecretObjPtr obj; virSecretDefPtr def; + char uuidstr[VIR_UUID_STRING_BUFLEN]; virObjectEventPtr event =3D NULL; =20 if (!(obj =3D secretObjFromSecret(secret))) @@ -412,9 +415,9 @@ secretUndefine(virSecretPtr secret) =20 virSecretObjDeleteData(obj); =20 - virSecretObjListRemove(driver->secrets, obj); - virObjectUnref(obj); - obj =3D NULL; + virUUIDFormat(def->uuid, uuidstr); + virSecretObjEndAPI(&obj); + virSecretObjListRemove(driver->secrets, uuidstr); =20 ret =3D 0; =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list