From nobody Sun Feb 8 14:52:00 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524573106617979.5506096225699; Tue, 24 Apr 2018 05:31:46 -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 C54BA3004413; Tue, 24 Apr 2018 12:31:44 +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 3512581CD4; Tue, 24 Apr 2018 12:31: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 EED1AB3487; Tue, 24 Apr 2018 12:31:42 +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 w3OCSH0A014664 for ; Tue, 24 Apr 2018 08:28:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id BF66E7AC8A; Tue, 24 Apr 2018 12:28:17 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-64.phx2.redhat.com [10.3.116.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B7A27AC85 for ; Tue, 24 Apr 2018 12:28:17 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 24 Apr 2018 08:28:05 -0400 Message-Id: <20180424122809.12534-3-jferlan@redhat.com> In-Reply-To: <20180424122809.12534-1-jferlan@redhat.com> References: <20180424122809.12534-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] conf: Use virDomainObjListFindBy*Locked for virDomainObjListAdd 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.44]); Tue, 24 Apr 2018 12:31:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the FindBy{UUID|Name}Locked helpers which will return a locked and ref counted object rather than the direct virHashLookup and virObjectLock of the returned object. We'll need to temporarily virObjectUnref when we assign a new domain @def, but that will change shortly when virDomainObjListAddObjLocked returns the correct reference counted object. Use the virDomainObjEndAPI in the error path to Unref/Unlock for the corresponding Unref/Unlock of either the FindBy* return or the virDomainObjNew since both return a reffed/locked object. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- src/conf/virdomainobjlist.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 9aa2abd8c3..6752f6c572 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -280,11 +280,8 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, if (oldDef) *oldDef =3D NULL; =20 - virUUIDFormat(def->uuid, uuidstr); - /* See if a VM with matching UUID already exists */ - if ((vm =3D virHashLookup(doms->objs, uuidstr))) { - virObjectLock(vm); + if ((vm =3D virDomainObjListFindByUUIDLocked(doms, def->uuid))) { /* UUID matches, but if names don't match, refuse it */ if (STRNEQ(vm->def->name, def->name)) { virUUIDFormat(vm->def->uuid, uuidstr); @@ -314,10 +311,12 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, def, !!(flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE), oldDef); + /* XXX: Temporary until this API is fixed to return a locked and + * refcnt'd object */ + virObjectUnref(vm); } else { /* UUID does not match, but if a name matches, refuse it */ - if ((vm =3D virHashLookup(doms->objsName, def->name))) { - virObjectLock(vm); + if ((vm =3D virDomainObjListFindByNameLocked(doms, def->name))) { virUUIDFormat(vm->def->uuid, uuidstr); virReportError(VIR_ERR_OPERATION_FAILED, _("domain '%s' already exists with uuid %s"), @@ -329,18 +328,15 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, goto cleanup; vm->def =3D def; =20 - if (virDomainObjListAddObjLocked(doms, vm) < 0) { - virDomainObjEndAPI(&vm); - return NULL; - } + if (virDomainObjListAddObjLocked(doms, vm) < 0) + goto error; } cleanup: return vm; =20 error: - virObjectUnlock(vm); - vm =3D NULL; - goto cleanup; + virDomainObjEndAPI(&vm); + return NULL; } =20 =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list