From nobody Thu May 2 06:17:16 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 152267502055739.853560620849635; Mon, 2 Apr 2018 06:17:00 -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 459EE5D687; Mon, 2 Apr 2018 13:16:59 +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 18AE8789AF; Mon, 2 Apr 2018 13:16:59 +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 CD7BC4CA99; Mon, 2 Apr 2018 13:16:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w32DGms6010927 for ; Mon, 2 Apr 2018 09:16:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4BB2F5F7EF; Mon, 2 Apr 2018 13:16:48 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E0055F7F2 for ; Mon, 2 Apr 2018 13:16:47 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 2 Apr 2018 09:16:37 -0400 Message-Id: <20180402131640.15071-2-jferlan@redhat.com> In-Reply-To: <20180402131640.15071-1-jferlan@redhat.com> References: <20180402131640.15071-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/4] vmware: Properly clean up in vmwareDomainLookupByName 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.39]); Mon, 02 Apr 2018 13:16:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virDomainObjListFindByName returns a locked and reffed domain object, all we did was unlock it, leaving an extra ref. Use the virDomainObjEndAPI to cleanup instead. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- src/vmware/vmware_driver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 8b487c4a7c..e1deb35201 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -928,8 +928,7 @@ vmwareDomainLookupByName(virConnectPtr conn, const char= *name) dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:17:16 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 1522675023754160.9172324643472; Mon, 2 Apr 2018 06:17:03 -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 7117A7652F; Mon, 2 Apr 2018 13:17:02 +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 455255F7FA; Mon, 2 Apr 2018 13:17: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 0E1F24CA9F; Mon, 2 Apr 2018 13:17:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w32DGmui010937 for ; Mon, 2 Apr 2018 09:16:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3585608F0; Mon, 2 Apr 2018 13:16:48 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72AF85F7EE for ; Mon, 2 Apr 2018 13:16:48 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 2 Apr 2018 09:16:38 -0400 Message-Id: <20180402131640.15071-3-jferlan@redhat.com> In-Reply-To: <20180402131640.15071-1-jferlan@redhat.com> References: <20180402131640.15071-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/4] vmware: Create accessors to virDomainObjListFindByUUID 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.26]); Mon, 02 Apr 2018 13:17:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than repeat code throughout, create and use a couple of accessors in order to lookup by UUID. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- src/vmware/vmware_driver.c | 180 +++++++++++++++--------------------------= ---- 1 file changed, 61 insertions(+), 119 deletions(-) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index e1deb35201..6c81e5feaa 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -59,6 +59,39 @@ vmwareDriverUnlock(struct vmware_driver *driver) virMutexUnlock(&driver->lock); } =20 + +static virDomainObjPtr +vmwareDomObjFromDomainLocked(struct vmware_driver *driver, + const unsigned char *uuid) +{ + virDomainObjPtr vm; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + if (!(vm =3D virDomainObjListFindByUUID(driver->domains, uuid))) { + virUUIDFormat(uuid, uuidstr); + + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s'"), uuidstr); + return NULL; + } + + return vm; +} + + +static virDomainObjPtr +vmwareDomObjFromDomain(struct vmware_driver *driver, + const unsigned char *uuid) +{ + virDomainObjPtr vm; + + vmwareDriverLock(driver); + vm =3D vmwareDomObjFromDomainLocked(driver, uuid); + vmwareDriverUnlock(driver); + return vm; +} + + static void * vmwareDataAllocFunc(void *opaque ATTRIBUTE_UNUSED) { @@ -460,13 +493,8 @@ vmwareDomainShutdownFlags(virDomainPtr dom, =20 vmwareDriverLock(driver); =20 - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D vmwareDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (vmwareUpdateVMStatus(driver, vm) < 0) goto cleanup; @@ -531,15 +559,8 @@ vmwareDomainSuspend(virDomainPtr dom) return ret; } =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; =20 vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath); @@ -580,15 +601,8 @@ vmwareDomainResume(virDomainPtr dom) return ret; } =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; =20 vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath); @@ -624,15 +638,8 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flag= s) =20 virCheckFlags(0, -1); =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; =20 vmxPath =3D ((vmwareDomainPtr) vm->privateData)->vmxPath; vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); @@ -750,14 +757,8 @@ vmwareDomainCreateWithFlags(virDomainPtr dom, virCheckFlags(0, -1); =20 vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(dom->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("No domain with matching uuid '%s'"), uuidstr); + if (!(vm =3D vmwareDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (vmwareUpdateVMStatus(driver, vm) < 0) goto cleanup; @@ -794,16 +795,8 @@ vmwareDomainUndefineFlags(virDomainPtr dom, virCheckFlags(0, -1); =20 vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(dom->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); + if (!(vm =3D vmwareDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (!vm->persistent) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -867,18 +860,11 @@ vmwareDomainGetOSType(virDomainPtr dom) virDomainObjPtr vm; char *ret =3D NULL; =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return NULL; =20 ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)= )); =20 - cleanup: if (vm) virObjectUnlock(vm); return ret; @@ -892,18 +878,11 @@ vmwareDomainLookupByUUID(virConnectPtr conn, const un= signed char *uuid) virDomainObjPtr vm; virDomainPtr dom =3D NULL; =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, uuid))) + return NULL; =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 - cleanup: if (vm) virObjectUnlock(vm); return dom; @@ -939,16 +918,11 @@ vmwareDomainIsActive(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - vmwareDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; + ret =3D virDomainObjIsActive(obj); =20 - cleanup: if (obj) virObjectUnlock(obj); return ret; @@ -962,16 +936,11 @@ vmwareDomainIsPersistent(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - vmwareDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; + ret =3D obj->persistent; =20 - cleanup: if (obj) virObjectUnlock(obj); return ret; @@ -987,20 +956,12 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int= flags) =20 /* Flags checked by virDomainDefFormat */ =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return NULL; =20 ret =3D virDomainDefFormat(vm->def, driver->caps, virDomainDefFormatConvertXMLFlags(flags)); =20 - cleanup: if (vm) virObjectUnlock(vm); return ret; @@ -1120,15 +1081,8 @@ vmwareDomainGetInfo(virDomainPtr dom, virDomainInfoP= tr info) virDomainObjPtr vm; int ret =3D -1; =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (vmwareUpdateVMStatus(driver, vm) < 0) goto cleanup; @@ -1158,15 +1112,8 @@ vmwareDomainGetState(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (vmwareUpdateVMStatus(driver, vm) < 0) goto cleanup; @@ -1213,16 +1160,11 @@ vmwareDomainHasManagedSaveImage(virDomainPtr dom, u= nsigned int flags) =20 virCheckFlags(0, -1); =20 - vmwareDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - vmwareDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D vmwareDomObjFromDomain(driver, dom->uuid))) + return -1; + ret =3D 0; =20 - cleanup: if (obj) virObjectUnlock(obj); return ret; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:17:16 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 1522675026835799.0237961184614; Mon, 2 Apr 2018 06:17: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 52151C03D471; Mon, 2 Apr 2018 13:17:05 +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 2691B6046B; Mon, 2 Apr 2018 13:17: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 DF7CA4CA9F; Mon, 2 Apr 2018 13:17:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w32DGnWu010942 for ; Mon, 2 Apr 2018 09:16:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 369EC608F0; Mon, 2 Apr 2018 13:16:49 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAFCA5F7EE for ; Mon, 2 Apr 2018 13:16:48 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 2 Apr 2018 09:16:39 -0400 Message-Id: <20180402131640.15071-4-jferlan@redhat.com> In-Reply-To: <20180402131640.15071-1-jferlan@redhat.com> References: <20180402131640.15071-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/4] vmware: Add more descriptive error message on Find failure 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.31]); Mon, 02 Apr 2018 13:17:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If vmwareDomainLookupByID or vmwareDomainLookupByName fails to find a vm, let's be a bit more descriptive by providing the failing id or name in the error message. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- src/vmware/vmware_driver.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 6c81e5feaa..d17fdfe3be 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -841,7 +841,8 @@ vmwareDomainLookupByID(virConnectPtr conn, int id) vmwareDriverUnlock(driver); =20 if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching id '%d'"), id); goto cleanup; } =20 @@ -900,7 +901,8 @@ vmwareDomainLookupByName(virConnectPtr conn, const char= *name) vmwareDriverUnlock(driver); =20 if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching name '%s'"), name); goto cleanup; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:17:16 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 1522675030455749.7443007858702; Mon, 2 Apr 2018 06:17:10 -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 73CB2C206AD7; Mon, 2 Apr 2018 13:17:08 +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 473F85FCA0; Mon, 2 Apr 2018 13:17: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 0076E1800BB5; Mon, 2 Apr 2018 13:17:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w32DGndC010948 for ; Mon, 2 Apr 2018 09:16:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9A306608F0; Mon, 2 Apr 2018 13:16:49 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D9645F7EF for ; Mon, 2 Apr 2018 13:16:49 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 2 Apr 2018 09:16:40 -0400 Message-Id: <20180402131640.15071-5-jferlan@redhat.com> In-Reply-To: <20180402131640.15071-1-jferlan@redhat.com> References: <20180402131640.15071-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/4] vmware: Use virDomainObjListFindBy{UUID|ID}Ref 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]); Mon, 02 Apr 2018 13:17:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For vmwareDomObjFromDomainLocked and vmwareDomainLookupByID let's return a locked and referenced @vm object so that callers can then use the common and more consistent virDomainObjEndAPI in order to handle cleanup rather than needing to know that the returned object is locked and calling virObjectUnlock. The LookupByName already returns the ref counted and locked object, so this will make things more consistent. For vmwareDomainUndefineFlags and vmwareDomainShutdownFlags since virDomainObjListRemove will return an unlocked object, we need to relock before making the EndAPI call. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- src/vmware/vmware_driver.c | 53 +++++++++++++++++-------------------------= ---- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index d17fdfe3be..643c85d4f8 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -67,7 +67,7 @@ vmwareDomObjFromDomainLocked(struct vmware_driver *driver, virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - if (!(vm =3D virDomainObjListFindByUUID(driver->domains, uuid))) { + if (!(vm =3D virDomainObjListFindByUUIDRef(driver->domains, uuid))) { virUUIDFormat(uuid, uuidstr); =20 virReportError(VIR_ERR_NO_DOMAIN, @@ -510,13 +510,12 @@ vmwareDomainShutdownFlags(virDomainPtr dom, =20 if (!vm->persistent) { virDomainObjListRemove(driver->domains, vm); - vm =3D NULL; + virObjectLock(vm); } =20 ret =3D 0; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); vmwareDriverUnlock(driver); return ret; } @@ -577,8 +576,7 @@ vmwareDomainSuspend(virDomainPtr dom) ret =3D 0; =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -619,8 +617,7 @@ vmwareDomainResume(virDomainPtr dom) ret =3D 0; =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -660,8 +657,7 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags) ret =3D 0; =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -772,8 +768,7 @@ vmwareDomainCreateWithFlags(virDomainPtr dom, ret =3D vmwareStartVM(driver, vm); =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); vmwareDriverUnlock(driver); return ret; } @@ -811,14 +806,13 @@ vmwareDomainUndefineFlags(virDomainPtr dom, vm->persistent =3D 0; } else { virDomainObjListRemove(driver->domains, vm); - vm =3D NULL; + virObjectLock(vm); } =20 ret =3D 0; =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); vmwareDriverUnlock(driver); return ret; } @@ -837,7 +831,7 @@ vmwareDomainLookupByID(virConnectPtr conn, int id) virDomainPtr dom =3D NULL; =20 vmwareDriverLock(driver); - vm =3D virDomainObjListFindByID(driver->domains, id); + vm =3D virDomainObjListFindByIDRef(driver->domains, id); vmwareDriverUnlock(driver); =20 if (!vm) { @@ -849,8 +843,7 @@ vmwareDomainLookupByID(virConnectPtr conn, int id) dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } =20 @@ -866,8 +859,7 @@ vmwareDomainGetOSType(virDomainPtr dom) =20 ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)= )); =20 - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -884,8 +876,7 @@ vmwareDomainLookupByUUID(virConnectPtr conn, const unsi= gned char *uuid) =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return dom; } =20 @@ -925,8 +916,7 @@ vmwareDomainIsActive(virDomainPtr dom) =20 ret =3D virDomainObjIsActive(obj); =20 - if (obj) - virObjectUnlock(obj); + virDomainObjEndAPI(&obj); return ret; } =20 @@ -943,8 +933,7 @@ vmwareDomainIsPersistent(virDomainPtr dom) =20 ret =3D obj->persistent; =20 - if (obj) - virObjectUnlock(obj); + virDomainObjEndAPI(&obj); return ret; } =20 @@ -964,8 +953,7 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int f= lags) ret =3D virDomainDefFormat(vm->def, driver->caps, virDomainDefFormatConvertXMLFlags(flags)); =20 - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -1097,8 +1085,7 @@ vmwareDomainGetInfo(virDomainPtr dom, virDomainInfoPt= r info) ret =3D 0; =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -1124,8 +1111,7 @@ vmwareDomainGetState(virDomainPtr dom, ret =3D 0; =20 cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } =20 @@ -1167,8 +1153,7 @@ vmwareDomainHasManagedSaveImage(virDomainPtr dom, uns= igned int flags) =20 ret =3D 0; =20 - if (obj) - virObjectUnlock(obj); + virDomainObjEndAPI(&obj); return ret; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list