From nobody Sat Apr 27 09:20:11 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.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 1522271987928646.3936618916787; Wed, 28 Mar 2018 14:19: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 6B192C04BE12; Wed, 28 Mar 2018 21:19:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E0DB5D70A; Wed, 28 Mar 2018 21:19: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 B65734CA9D; Wed, 28 Mar 2018 21:19:44 +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 w2SLJfRa000484 for ; Wed, 28 Mar 2018 17:19:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8EA8463143; Wed, 28 Mar 2018 21:19:41 +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 4F7B563142 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:25 -0400 Message-Id: <20180328211933.8033-2-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 1/9] secret: Rework LoadAllConfigs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 28 Mar 2018 21:19:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the virSecretObjEndAPI into virSecretLoad and alter the processing in order to accomodate that. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 47e0b2896..4aaf47b5d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -906,12 +906,13 @@ virSecretLoadValue(virSecretObjPtr obj) } =20 =20 -static virSecretObjPtr +static int virSecretLoad(virSecretObjListPtr secrets, const char *file, const char *path, const char *configDir) { + int ret =3D -1; virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; =20 @@ -927,13 +928,16 @@ virSecretLoad(virSecretObjListPtr secrets, =20 if (virSecretLoadValue(obj) < 0) { virSecretObjListRemove(secrets, obj); - virObjectUnref(obj); - obj =3D NULL; + virObjectLock(obj); + goto cleanup; } =20 + ret =3D 0; + cleanup: virSecretDefFree(def); - return obj; + virSecretObjEndAPI(&obj); + return ret; } =20 =20 @@ -952,7 +956,6 @@ 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 obj; =20 if (!virFileHasSuffix(de->d_name, ".xml")) continue; @@ -960,15 +963,10 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, if (!(path =3D virFileBuildPath(configDir, de->d_name, NULL))) continue; =20 - if (!(obj =3D virSecretLoad(secrets, de->d_name, path, configDir))= ) { - VIR_ERROR(_("Error reading secret: %s"), - virGetLastErrorMessage()); - VIR_FREE(path); - continue; - } + if (virSecretLoad(secrets, de->d_name, path, configDir) < 0) + VIR_ERROR(_("Error reading secret: %s"), virGetLastErrorMessag= e()); =20 VIR_FREE(path); - virSecretObjEndAPI(&obj); } =20 VIR_DIR_CLOSE(dir); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 From nobody Sat Apr 27 09:20:11 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.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 1522271987398831.3887560088975; Wed, 28 Mar 2018 14:19:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C18008124B; Wed, 28 Mar 2018 21:19:45 +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 729E16A944; Wed, 28 Mar 2018 21:19: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 175DB181BA02; Wed, 28 Mar 2018 21:19:44 +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 w2SLJgx2000499 for ; Wed, 28 Mar 2018 17:19:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9704C63143; 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 57AE063142 for ; Wed, 28 Mar 2018 21:19:42 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:27 -0400 Message-Id: <20180328211933.8033-4-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 3/9] interface: Alter virInterfaceObjListRemove 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.13 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:19:46 +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 @interfaces, and relocking @obj in order to ensure proper lock ordering. This can be avoided by changing virInterfaceObjListRemove to take @name instead of @obj. Then, we can lock the @interfaces list, look up the @obj by @name (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 or obj->def->name) because it's possible that the object could be reaped by two competing remove threads. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 26 +++++++++++++++++--------- src/conf/virinterfaceobj.h | 2 +- src/test/test_driver.c | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index f90c0bd9c..c3a7d4cd8 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -358,20 +358,28 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr i= nterfaces, } =20 =20 +/* + * virInterfaceObjListRemove: + * @interfaces: list of interface objects + * @name: name of interface definition to remove + * + * Find the object by name in the list, remove the object from the + * list hash table, and free the object. + * + * Upon entry it's expected that prior to entry any locks on + * the object related to @name will have been removed. + */ void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj) + const char *name) { - if (!obj) - return; + virInterfaceObjPtr obj; =20 - virObjectRef(obj); - virObjectUnlock(obj); virObjectRWLockWrite(interfaces); - virObjectLock(obj); - virHashRemoveEntry(interfaces->objsName, obj->def->name); - virObjectUnlock(obj); - virObjectUnref(obj); + if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, name))) { + virHashRemoveEntry(interfaces->objsName, name); + virInterfaceObjEndAPI(&obj); + } virObjectRWUnlock(interfaces); } =20 diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 799d38038..82eb2ee87 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -66,7 +66,7 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr inter= faces, =20 void virInterfaceObjListRemove(virInterfaceObjListPtr interfaces, - virInterfaceObjPtr obj); + const char *name); =20 typedef bool (*virInterfaceObjListFilter)(virConnectPtr conn, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 99c27cc0a..ddddd8dcb 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4092,8 +4092,8 @@ testInterfaceUndefine(virInterfacePtr iface) if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - virInterfaceObjListRemove(privconn->ifaces, obj); - virObjectUnref(obj); + virInterfaceObjEndAPI(&obj); + virInterfaceObjListRemove(privconn->ifaces, iface->name); =20 return 0; } --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 1522272009747736.9438829353422; Wed, 28 Mar 2018 14:20:09 -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 1E22C23E6DD; Wed, 28 Mar 2018 21:20:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E37215C2E4; Wed, 28 Mar 2018 21:20:07 +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 395924CAA5; Wed, 28 Mar 2018 21:20:07 +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 w2SLJhOX000504 for ; Wed, 28 Mar 2018 17:19:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D1E563142; Wed, 28 Mar 2018 21:19:43 +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 C039963143 for ; Wed, 28 Mar 2018 21:19:42 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:28 -0400 Message-Id: <20180328211933.8033-5-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 4/9] nodedev: Alter virNodeDeviceObjListRemove 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 28 Mar 2018 21:20:08 +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 @devs, and relocking @obj in order to ensure proper proper lock ordering. This can be avoided by changing virNodeDeviceObjListRemove to take @name instead of @obj. Then, we can lock the @devs list, look up the @obj by @name (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 or obj->def->name) because it's possible that the object could be reaped by two competing remove threads. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 29 +++++++++++++++++------------ src/conf/virnodedeviceobj.h | 2 +- src/node_device/node_device_hal.c | 16 +++++++++------- src/node_device/node_device_udev.c | 13 +++++++++---- src/test/test_driver.c | 28 ++++++++++++++-------------- 5 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index ad0f27ee4..9064a6cfb 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -470,23 +470,28 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr= devs, } =20 =20 +/* + * virNodeDeviceObjListRemove: + * @devs: list of node device objects + * @name: a node device definition + * + * Find the object by name in the list, remove the object from the + * list hash table, and free the object. + * + * Upon entry it's expected that prior to entry any locks on + * the object related to @name will have been removed. + */ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr obj) + const char *name) { - virNodeDeviceDefPtr def; - - if (!obj) - return; - def =3D obj->def; + virNodeDeviceObjPtr obj; =20 - virObjectRef(obj); - virObjectUnlock(obj); virObjectRWLockWrite(devs); - virObjectLock(obj); - virHashRemoveEntry(devs->objs, def->name); - virObjectUnlock(obj); - virObjectUnref(obj); + if ((obj =3D virNodeDeviceObjListFindByNameLocked(devs, name))) { + virHashRemoveEntry(devs->objs, name); + virNodeDeviceObjEndAPI(&obj); + } virObjectRWUnlock(devs); } =20 diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 87f908369..b9752bc62 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -72,7 +72,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr dev= s, =20 void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr dev); + const char *name); =20 int virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index 6ad56f416..46a419a6e 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -511,8 +511,8 @@ dev_refresh(const char *udi) /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ - virNodeDeviceObjListRemove(driver->devs, obj); - virObjectUnref(obj); + virNodeDeviceObjEndAPI(&obj); + virNodeDeviceObjListRemoveDef(driver->devs, name); dev_create(udi); } else { VIR_DEBUG("no device named %s", name); @@ -536,12 +536,14 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, virNodeDeviceObjPtr obj; =20 obj =3D virNodeDeviceObjListFindByName(driver->devs, name); - VIR_DEBUG("%s", name); - if (obj) - virNodeDeviceObjListRemove(driver->devs, obj); - else + if (!obj) { VIR_DEBUG("no device named %s", name); - virObjectUnref(obj); + return; + } + + VIR_DEBUG("%s", name); + virNodeDeviceObjEndAPI(&obj); + virNodeDeviceObjListRemove(driver->devs, name); } =20 =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e87eb32a8..f6d223fe4 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1282,6 +1282,7 @@ udevRemoveOneDevice(struct udev_device *device) virNodeDeviceDefPtr def; virObjectEventPtr event =3D NULL; const char *name =3D NULL; + char *defname =3D NULL; =20 name =3D udev_device_get_syspath(device); if (!(obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, name))= ) { @@ -1290,15 +1291,19 @@ udevRemoveOneDevice(struct udev_device *device) return -1; } def =3D virNodeDeviceObjGetDef(obj); + if (VIR_STRDUP(defname, def->name) < 0) { + virNodeDeviceObjEndAPI(&obj); + return -1; + } =20 event =3D virNodeDeviceEventLifecycleNew(def->name, VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - VIR_DEBUG("Removing device '%s' with sysfs path '%s'", - def->name, name); - virNodeDeviceObjListRemove(driver->devs, obj); - virObjectUnref(obj); + VIR_DEBUG("Removing device '%s' with sysfs path '%s'", defname, name); + virNodeDeviceObjEndAPI(&obj); + virNodeDeviceObjListRemove(driver->devs, defname); + VIR_FREE(defname); =20 if (event) virObjectEventStateQueue(driver->nodeDeviceEventState, event); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ddddd8dcb..568d537e9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4723,8 +4723,8 @@ testDestroyVport(testDriverPtr privconn, VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - virNodeDeviceObjListRemove(privconn->devs, obj); - virObjectUnref(obj); + virNodeDeviceObjEndAPI(&obj); + virNodeDeviceObjListRemove(privconn->devs, "scsi_host12"); =20 testObjectEventQueue(privconn, event); return 0; @@ -5670,6 +5670,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceObjPtr parentobj =3D NULL; virNodeDeviceDefPtr def; + char *parent =3D NULL; char *wwnn =3D NULL, *wwpn =3D NULL; virObjectEventPtr event =3D NULL; =20 @@ -5681,18 +5682,19 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) goto cleanup; =20 /* Unlike the real code we cannot run into the udevAddOneDevice race - * which would replace obj->def, so no need to save off the parent, - * but do need to drop the @obj lock so that the FindByName code doesn= 't - * deadlock on ourselves */ - virObjectUnlock(obj); + * which would replace obj->def, but we still need to save off the + * parent name since we're about to Unref and Unlock the @obj containi= ng + * the @def so that we don't deadlock in virNodeDeviceObjListFindByNam= e. */ + if (VIR_STRDUP(parent, def->parent) < 0) + goto cleanup; + + virNodeDeviceObjEndAPI(&obj); =20 /* We do this just for basic validation and throw away the parentobj * since there's no vport_delete to be run */ - if (!(parentobj =3D virNodeDeviceObjListFindByName(driver->devs, - def->parent))) { + if (!(parentobj =3D virNodeDeviceObjListFindByName(driver->devs, paren= t))) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot find parent '%s' definition"), def->paren= t); - virObjectLock(obj); + _("cannot find parent '%s' definition"), parent); goto cleanup; } virNodeDeviceObjEndAPI(&parentobj); @@ -5701,16 +5703,14 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - virObjectLock(obj); - virNodeDeviceObjListRemove(driver->devs, obj); - virObjectUnref(obj); - obj =3D NULL; + virNodeDeviceObjListRemove(driver->devs, dev->name); =20 cleanup: virNodeDeviceObjEndAPI(&obj); testObjectEventQueue(driver, event); VIR_FREE(wwnn); VIR_FREE(wwpn); + VIR_FREE(parent); return ret; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 1522272011893526.1423785969847; Wed, 28 Mar 2018 14:20:11 -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 7DC637E9ED; Wed, 28 Mar 2018 21:20:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 526AA5E1B5; Wed, 28 Mar 2018 21:20:10 +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 160674CAAA; Wed, 28 Mar 2018 21:20:10 +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 w2SLJhMk000509 for ; Wed, 28 Mar 2018 17:19:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 750FE63143; Wed, 28 Mar 2018 21:19:43 +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 34D0F63142 for ; Wed, 28 Mar 2018 21:19:43 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:29 -0400 Message-Id: <20180328211933.8033-6-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 5/9] conf: Clean up virStoragePoolObjLoad error 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 28 Mar 2018 21:20:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use an error label to converge all the clean up processing options. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 799b8c9fa..471262f29 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1115,8 +1115,8 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, const char *path, const char *autostartLink) { - virStoragePoolDefPtr def; - virStoragePoolObjPtr obj; + virStoragePoolDefPtr def =3D NULL; + virStoragePoolObjPtr obj =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(path))) return NULL; @@ -1126,32 +1126,33 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pool= s, _("Storage pool config filename '%s' does " "not match pool name '%s'"), path, def->name); - virStoragePoolDefFree(def); - return NULL; + goto error; } =20 - if (!(obj =3D virStoragePoolObjAssignDef(pools, def))) { - virStoragePoolDefFree(def); - return NULL; - } + if (!(obj =3D virStoragePoolObjAssignDef(pools, def))) + goto error; + def =3D NULL; =20 VIR_FREE(obj->configFile); /* for driver reload */ - if (VIR_STRDUP(obj->configFile, path) < 0) { - virStoragePoolObjRemove(pools, obj); - virObjectUnref(obj); - return NULL; - } + if (VIR_STRDUP(obj->configFile, path) < 0) + goto error; + VIR_FREE(obj->autostartLink); /* for driver reload */ - if (VIR_STRDUP(obj->autostartLink, autostartLink) < 0) { - virStoragePoolObjRemove(pools, obj); - virObjectUnref(obj); - return NULL; - } + if (VIR_STRDUP(obj->autostartLink, autostartLink) < 0) + goto error; =20 obj->autostart =3D virFileLinkPointsTo(obj->autostartLink, obj->configFile); =20 return obj; + + error: + if (obj) { + virStoragePoolObjRemove(pools, obj); + virObjectUnref(obj); + } + virStoragePoolDefFree(def); + return NULL; } =20 =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 1522272015284498.80481723808; Wed, 28 Mar 2018 14:20:15 -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 B4DA5C0528AC; Wed, 28 Mar 2018 21:20:13 +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 8CE8A60240; Wed, 28 Mar 2018 21:20:13 +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 4E615180BAD3; Wed, 28 Mar 2018 21:20:13 +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 w2SLJhAP000521 for ; Wed, 28 Mar 2018 17:19:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDA4563143; Wed, 28 Mar 2018 21:19:43 +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 9CAA563142 for ; Wed, 28 Mar 2018 21:19:43 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:30 -0400 Message-Id: <20180328211933.8033-7-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 6/9] storage: Clean up storagePoolCreateXML error 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 28 Mar 2018 21:20:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than 3 separate, but same 4 lines of code - let's create an error label to make a common error path. This will help shortly when the error path changes slightly. Signed-off-by: John Ferlan --- src/storage/storage_driver.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index d5e38af5a..6276545eb 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -744,22 +744,14 @@ storagePoolCreateXML(virConnectPtr conn, =20 if (build_flags || (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) { - if (backend->buildPool(obj, build_flags) < 0) { - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); - obj =3D NULL; - goto cleanup; - } + if (backend->buildPool(obj, build_flags) < 0) + goto error; } } =20 if (backend->startPool && - backend->startPool(obj) < 0) { - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); - obj =3D NULL; - goto cleanup; - } + backend->startPool(obj) < 0) + goto error; =20 stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xml"); =20 @@ -770,10 +762,7 @@ storagePoolCreateXML(virConnectPtr conn, unlink(stateFile); if (backend->stopPool) backend->stopPool(obj); - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); - obj =3D NULL; - goto cleanup; + goto error; } =20 event =3D virStoragePoolEventLifecycleNew(def->name, @@ -793,6 +782,12 @@ storagePoolCreateXML(virConnectPtr conn, virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return pool; + + error: + virStoragePoolObjRemove(driver->pools, obj); + virObjectUnref(obj); + obj =3D NULL; + goto cleanup; } =20 static virStoragePoolPtr --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 1522272018554848.9842229098223; Wed, 28 Mar 2018 14:20:18 -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 D289C7F7AE; Wed, 28 Mar 2018 21:20:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A925860C8C; Wed, 28 Mar 2018 21:20:16 +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 6F88A4CAAB; Wed, 28 Mar 2018 21:20:16 +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 w2SLJikO000527 for ; Wed, 28 Mar 2018 17:19:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 508BB63142; Wed, 28 Mar 2018 21:19:44 +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 10DE265AC0 for ; Wed, 28 Mar 2018 21:19:43 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:31 -0400 Message-Id: <20180328211933.8033-8-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 7/9] test: Clean up testStoragePoolCreateXML error 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 28 Mar 2018 21:20:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than 2 separate, but same 4 lines of code - let's create an error label to make a common error path. This will help shortly when the error path changes slightly. Signed-off-by: John Ferlan --- src/test/test_driver.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 568d537e9..0a284e3d1 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4562,20 +4562,12 @@ testStoragePoolCreateXML(virConnectPtr conn, * rename a few fields to mock that. */ if (testCreateVport(privconn, def->source.adapter.data.fchost.wwnn, - def->source.adapter.data.fchost.wwpn) < 0) { - virStoragePoolObjRemove(privconn->pools, obj); - virObjectUnref(obj); - obj =3D NULL; - goto cleanup; - } + def->source.adapter.data.fchost.wwpn) < 0) + goto error; } =20 - if (testStoragePoolObjSetDefaults(obj) =3D=3D -1) { - virStoragePoolObjRemove(privconn->pools, obj); - virObjectUnref(obj); - obj =3D NULL; - goto cleanup; - } + if (testStoragePoolObjSetDefaults(obj) =3D=3D -1) + goto error; =20 /* *SetDefaults fills this in for the persistent pools, but this * would be a transient pool so remove it; otherwise, the Destroy @@ -4596,6 +4588,12 @@ testStoragePoolCreateXML(virConnectPtr conn, virStoragePoolObjEndAPI(&obj); testDriverUnlock(privconn); return pool; + + error: + virStoragePoolObjRemove(privconn->pools, obj); + virObjectUnref(obj); + obj =3D NULL; + goto cleanup; } =20 =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 1522272006110935.4982277751822; Wed, 28 Mar 2018 14:20:06 -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 CB2BFC03D473; Wed, 28 Mar 2018 21:20:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F2CB65AC8; Wed, 28 Mar 2018 21:20: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 61CBF4CAA4; Wed, 28 Mar 2018 21:20:04 +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 w2SLJiGf000532 for ; Wed, 28 Mar 2018 17:19:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9D8C63143; Wed, 28 Mar 2018 21:19:44 +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 79E0C63142 for ; Wed, 28 Mar 2018 21:19:44 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:32 -0400 Message-Id: <20180328211933.8033-9-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 8/9] conf: Move virStoragePoolObjRemove closer to AssignDef 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.31]); Wed, 28 Mar 2018 21:20:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A subsequent patch will need to use the local FindByUUIDLocked, so rather than create a forward decl or move when needed, let's just do it now for ease of future review. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 471262f29..f48f08a64 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -517,25 +517,6 @@ virStoragePoolObjListSearch(virStoragePoolObjListPtr p= ools, } =20 =20 -void -virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr obj) -{ - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(obj->def->uuid, uuidstr); - virObjectRef(obj); - virObjectUnlock(obj); - virObjectRWLockWrite(pools); - virObjectLock(obj); - virHashRemoveEntry(pools->objs, uuidstr); - virHashRemoveEntry(pools->objsName, obj->def->name); - virObjectUnlock(obj); - virObjectUnref(obj); - virObjectRWUnlock(pools); -} - - static virStoragePoolObjPtr virStoragePoolObjFindByUUIDLocked(virStoragePoolObjListPtr pools, const unsigned char *uuid) @@ -1053,6 +1034,25 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn, } =20 =20 +void +virStoragePoolObjRemove(virStoragePoolObjListPtr pools, + virStoragePoolObjPtr obj) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(obj->def->uuid, uuidstr); + virObjectRef(obj); + virObjectUnlock(obj); + virObjectRWLockWrite(pools); + virObjectLock(obj); + virHashRemoveEntry(pools->objs, uuidstr); + virHashRemoveEntry(pools->objsName, obj->def->name); + virObjectUnlock(obj); + virObjectUnref(obj); + virObjectRWUnlock(pools); +} + + /** * virStoragePoolObjAssignDef: * @pools: Storage Pool object list pointer --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:20:11 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.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 1522272021102202.45618106946722; Wed, 28 Mar 2018 14:20:21 -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 CD3747FD47; Wed, 28 Mar 2018 21:20:19 +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 9EF2953B2F; Wed, 28 Mar 2018 21:20:19 +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 64334180BAD6; Wed, 28 Mar 2018 21:20:19 +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 w2SLJjd3000540 for ; Wed, 28 Mar 2018 17:19:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D87463143; Wed, 28 Mar 2018 21:19:45 +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 E1C8063142 for ; Wed, 28 Mar 2018 21:19:44 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 17:19:33 -0400 Message-Id: <20180328211933.8033-10-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 9/9] storagepool: Alter virStoragePoolObjRemove 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 28 Mar 2018 21:20:20 +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 @pools, and relocking @obj in order to ensure proper lock ordering. This can be avoided by changing virStoragePoolObjRemove to take a @name instead of @obj. Then, we can lock the @pools list, look up the @obj by @name (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 or obj->def->name) because it's possible that the object could be reaped by two competing remove threads. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 41 +++++++++++++++++++++++++++++------------ src/conf/virstorageobj.h | 2 +- src/storage/storage_driver.c | 44 +++++++++++++++++++++++++++++-----------= ---- src/test/test_driver.c | 30 +++++++++++++++++++----------- 4 files changed, 78 insertions(+), 39 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index f48f08a64..df6febfd0 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1034,21 +1034,31 @@ virStoragePoolObjVolumeListExport(virConnectPtr con= n, } =20 =20 +/* + * virStoragePoolObjRemove: + * @pools: list of storage pool objects + * @name: name of storage pool to remove + * + * Find the object by name in the list, remove the object from + * each hash table in the list, and free the object. + * + * Upon entry it's expected that prior to entry any locks on + * the object related to @name will have been removed. + */ void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr obj) + const char *name) { + virStoragePoolObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - virUUIDFormat(obj->def->uuid, uuidstr); - virObjectRef(obj); - virObjectUnlock(obj); virObjectRWLockWrite(pools); - virObjectLock(obj); - virHashRemoveEntry(pools->objs, uuidstr); - virHashRemoveEntry(pools->objsName, obj->def->name); - virObjectUnlock(obj); - virObjectUnref(obj); + if ((obj =3D virStoragePoolObjFindByNameLocked(pools, name))) { + virUUIDFormat(obj->def->uuid, uuidstr); + virHashRemoveEntry(pools->objs, uuidstr); + virHashRemoveEntry(pools->objsName, name); + virStoragePoolObjEndAPI(&obj); + } virObjectRWUnlock(pools); } =20 @@ -1117,6 +1127,7 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, { virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr obj =3D NULL; + char *name =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(path))) return NULL; @@ -1129,6 +1140,9 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, goto error; } =20 + if (VIR_STRDUP(name, def->name) < 0) + goto error; + if (!(obj =3D virStoragePoolObjAssignDef(pools, def))) goto error; def =3D NULL; @@ -1144,13 +1158,16 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pool= s, obj->autostart =3D virFileLinkPointsTo(obj->autostartLink, obj->configFile); =20 + VIR_FREE(name); + return obj; =20 error: - if (obj) { - virStoragePoolObjRemove(pools, obj); - virObjectUnref(obj); + if (obj && name) { + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(pools, name); } + VIR_FREE(name); virStoragePoolDefFree(def); return NULL; } diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index dd7001c4b..047b08a92 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -242,7 +242,7 @@ virStoragePoolObjListNew(void); =20 void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr obj); + const char *name); =20 int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools, diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6276545eb..814e5cb97 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -82,19 +82,21 @@ static void storageDriverUnlock(void) /** * virStoragePoolUpdateInactive: * @poolptr: pointer to a variable holding the pool object pointer + * @name: Name of the pool * * This function is supposed to be called after a pool becomes inactive. T= he * function switches to the new config object for persistent pools. Inacti= ve * pools are removed. */ static void -virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr) +virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr, + const char *name) { virStoragePoolObjPtr obj =3D *objptr; =20 if (!virStoragePoolObjGetConfigFile(obj)) { - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(driver->pools, name); *objptr =3D NULL; } else if (virStoragePoolObjGetNewDef(obj)) { virStoragePoolObjDefUseNewDef(obj); @@ -110,6 +112,7 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, bool active =3D false; virStorageBackendPtr backend; char *stateFile; + char *name =3D NULL; =20 if (!(stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xm= l"))) goto cleanup; @@ -120,6 +123,9 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, goto cleanup; } =20 + if (VIR_STRDUP(name, def->name) < 0) + goto cleanup; + /* Backends which do not support 'checkPool' are considered * inactive by default. */ if (backend->checkPool && @@ -149,12 +155,13 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr o= bj, virStoragePoolObjSetActive(obj, active); =20 if (!virStoragePoolObjIsActive(obj)) - virStoragePoolUpdateInactive(&obj); + virStoragePoolUpdateInactive(&obj, name); =20 cleanup: if (!active && stateFile) ignore_value(unlink(stateFile)); VIR_FREE(stateFile); + VIR_FREE(name); =20 return; } @@ -707,6 +714,7 @@ storagePoolCreateXML(virConnectPtr conn, virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; char *stateFile =3D NULL; + char *name =3D NULL; unsigned int build_flags =3D 0; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | @@ -731,6 +739,9 @@ storagePoolCreateXML(virConnectPtr conn, if ((backend =3D virStorageBackendForType(newDef->type)) =3D=3D NULL) goto cleanup; =20 + if (VIR_STRDUP(name, newDef->name) < 0) + goto cleanup; + if (!(obj =3D virStoragePoolObjAssignDef(driver->pools, newDef))) goto cleanup; newDef =3D NULL; @@ -776,6 +787,7 @@ storagePoolCreateXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: + VIR_FREE(name); VIR_FREE(stateFile); virStoragePoolDefFree(newDef); if (event) @@ -784,9 +796,8 @@ storagePoolCreateXML(virConnectPtr conn, return pool; =20 error: - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); - obj =3D NULL; + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(driver->pools, name); goto cleanup; } =20 @@ -800,6 +811,7 @@ storagePoolDefineXML(virConnectPtr conn, virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + char *name =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -821,15 +833,17 @@ storagePoolDefineXML(virConnectPtr conn, if (virStorageBackendForType(newDef->type) =3D=3D NULL) goto cleanup; =20 + if (VIR_STRDUP(name, newDef->name) < 0) + goto cleanup; + if (!(obj =3D virStoragePoolObjAssignDef(driver->pools, newDef))) goto cleanup; newDef =3D NULL; def =3D virStoragePoolObjGetDef(obj); =20 if (virStoragePoolObjSaveDef(driver, obj, def) < 0) { - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); - obj =3D NULL; + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(driver->pools, name); goto cleanup; } =20 @@ -841,6 +855,7 @@ storagePoolDefineXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: + VIR_FREE(name); if (event) virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolDefFree(newDef); @@ -895,9 +910,8 @@ storagePoolUndefine(virStoragePoolPtr pool) 0); =20 VIR_INFO("Undefining storage pool '%s'", def->name); - virStoragePoolObjRemove(driver->pools, obj); - virObjectUnref(obj); - obj =3D NULL; + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(driver->pools, pool->name); ret =3D 0; =20 cleanup: @@ -1089,7 +1103,7 @@ storagePoolDestroy(virStoragePoolPtr pool) =20 virStoragePoolObjSetActive(obj, false); =20 - virStoragePoolUpdateInactive(&obj); + virStoragePoolUpdateInactive(&obj, pool->name); =20 ret =3D 0; =20 @@ -1212,7 +1226,7 @@ storagePoolRefresh(virStoragePoolPtr pool, 0); virStoragePoolObjSetActive(obj, false); =20 - virStoragePoolUpdateInactive(&obj); + virStoragePoolUpdateInactive(&obj, pool->name); =20 goto cleanup; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0a284e3d1..70509a204 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4540,6 +4540,7 @@ testStoragePoolCreateXML(virConnectPtr conn, virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + char *name =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -4550,6 +4551,9 @@ testStoragePoolCreateXML(virConnectPtr conn, if (virStoragePoolObjIsDuplicate(privconn->pools, newDef, true) < 0) goto cleanup; =20 + if (VIR_STRDUP(name, newDef->name) < 0) + goto cleanup; + if (!(obj =3D virStoragePoolObjAssignDef(privconn->pools, newDef))) goto cleanup; newDef =3D NULL; @@ -4583,6 +4587,7 @@ testStoragePoolCreateXML(virConnectPtr conn, pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: + VIR_FREE(name); virStoragePoolDefFree(newDef); testObjectEventQueue(privconn, event); virStoragePoolObjEndAPI(&obj); @@ -4590,9 +4595,8 @@ testStoragePoolCreateXML(virConnectPtr conn, return pool; =20 error: - virStoragePoolObjRemove(privconn->pools, obj); - virObjectUnref(obj); - obj =3D NULL; + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(privconn->pools, name); goto cleanup; } =20 @@ -4608,6 +4612,7 @@ testStoragePoolDefineXML(virConnectPtr conn, virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + char *name =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -4622,6 +4627,9 @@ testStoragePoolDefineXML(virConnectPtr conn, if (virStoragePoolObjIsDuplicate(privconn->pools, newDef, false) < 0) goto cleanup; =20 + if (VIR_STRDUP(name, newDef->name) < 0) + goto cleanup; + if (!(obj =3D virStoragePoolObjAssignDef(privconn->pools, newDef))) goto cleanup; newDef =3D NULL; @@ -4632,15 +4640,15 @@ testStoragePoolDefineXML(virConnectPtr conn, 0); =20 if (testStoragePoolObjSetDefaults(obj) =3D=3D -1) { - virStoragePoolObjRemove(privconn->pools, obj); - virObjectUnref(obj); - obj =3D NULL; + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(privconn->pools, name); goto cleanup; } =20 pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); =20 cleanup: + VIR_FREE(name); virStoragePoolDefFree(newDef); testObjectEventQueue(privconn, event); virStoragePoolObjEndAPI(&obj); @@ -4663,8 +4671,8 @@ testStoragePoolUndefine(virStoragePoolPtr pool) VIR_STORAGE_POOL_EVENT_UNDEFIN= ED, 0); =20 - virStoragePoolObjRemove(privconn->pools, obj); - virObjectUnref(obj); + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(privconn->pools, pool->name); =20 testObjectEventQueue(privconn, event); return 0; @@ -4757,10 +4765,10 @@ testStoragePoolDestroy(virStoragePoolPtr pool) 0); =20 if (!(virStoragePoolObjGetConfigFile(obj))) { - virStoragePoolObjRemove(privconn->pools, obj); - virObjectUnref(obj); - obj =3D NULL; + virStoragePoolObjEndAPI(&obj); + virStoragePoolObjRemove(privconn->pools, pool->name); } + ret =3D 0; =20 cleanup: --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list