From nobody Wed May 14 15:57:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522674408715859.9233806935097; Mon, 2 Apr 2018 06:06:48 -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 E8FB98047E; Mon, 2 Apr 2018 13:06: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 6BEE75D725; Mon, 2 Apr 2018 13:06:46 +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 DEFEF4CAA1; Mon, 2 Apr 2018 13:06:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w32D6Ocq007488 for ; Mon, 2 Apr 2018 09:06:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3D58F600C8; Mon, 2 Apr 2018 13:06:24 +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 EF30C6046B for ; Mon, 2 Apr 2018 13:06:23 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 2 Apr 2018 09:06:14 -0400 Message-Id: <20180402130616.25745-4-jferlan@redhat.com> In-Reply-To: <20180402130616.25745-1-jferlan@redhat.com> References: <20180402130616.25745-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/5] uml: 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 02 Apr 2018 13:06:47 +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. This will also generate a common error message including the failed uuidstr for lookup rather than just returning nothing in some instances. Signed-off-by: John Ferlan Reviewed-by: Daniel P. Berrang=C3=A9 --- src/uml/uml_driver.c | 244 +++++++++++++++--------------------------------= ---- 1 file changed, 70 insertions(+), 174 deletions(-) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index b84585d728..ad526a1e6b 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -163,6 +163,39 @@ umlVMDriverUnlock(void) umlDriverUnlock(uml_driver); } =20 + +static virDomainObjPtr +umlDomObjFromDomainLocked(struct uml_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 +umlDomObjFromDomain(struct uml_driver *driver, + const unsigned char *uuid) +{ + virDomainObjPtr vm; + + umlDriverLock(driver); + vm =3D umlDomObjFromDomainLocked(driver, uuid); + umlDriverUnlock(driver); + return vm; +} + + static virNWFilterCallbackDriver umlCallbackDriver =3D { .name =3D "UML", .vmFilterRebuild =3D umlVMFilterRebuild, @@ -1376,20 +1409,14 @@ static virDomainPtr umlDomainLookupByID(virConnectP= tr conn, } =20 static virDomainPtr umlDomainLookupByUUID(virConnectPtr conn, - const unsigned char *uuid) + const unsigned char *uuid) { struct uml_driver *driver =3D (struct uml_driver *)conn->privateData; virDomainObjPtr vm; virDomainPtr dom =3D NULL; =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, uuid); - umlDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, uuid))) + return NULL; =20 if (virDomainLookupByUUIDEnsureACL(conn, vm->def) < 0) goto cleanup; @@ -1435,13 +1462,8 @@ static int umlDomainIsActive(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - umlDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainIsActiveEnsureACL(dom->conn, obj->def) < 0) goto cleanup; @@ -1461,13 +1483,8 @@ static int umlDomainIsPersistent(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - umlDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainIsPersistentEnsureACL(dom->conn, obj->def) < 0) goto cleanup; @@ -1486,13 +1503,8 @@ static int umlDomainIsUpdated(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - umlDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainIsUpdatedEnsureACL(dom->conn, obj->def) < 0) goto cleanup; @@ -1645,14 +1657,8 @@ static int umlDomainShutdownFlags(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching id %d"), dom->id); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; @@ -1691,12 +1697,8 @@ umlDomainDestroyFlags(virDomainPtr dom, virCheckFlags(0, -1); =20 umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching id %d"), dom->id); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) + return -1; =20 if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1734,14 +1736,8 @@ static char *umlDomainGetOSType(virDomainPtr dom) { virDomainObjPtr vm; char *type =3D NULL; =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return NULL; =20 if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1763,18 +1759,8 @@ umlDomainGetMaxMemory(virDomainPtr dom) virDomainObjPtr vm; unsigned long long ret =3D 0; =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(dom->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainGetMaxMemoryEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1793,18 +1779,8 @@ static int umlDomainSetMaxMemory(virDomainPtr dom, u= nsigned long newmax) virDomainObjPtr vm; int ret =3D -1; =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(dom->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainSetMaxMemoryEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1830,18 +1806,8 @@ static int umlDomainSetMemory(virDomainPtr dom, unsi= gned long newmem) virDomainObjPtr vm; int ret =3D -1; =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(dom->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainSetMemoryEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1874,15 +1840,8 @@ static int umlDomainGetInfo(virDomainPtr dom, virDomainObjPtr vm; int ret =3D -1; =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1923,15 +1882,8 @@ umlDomainGetState(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainGetStateEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -1956,14 +1908,8 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, /* Flags checked by virDomainDefFormat */ =20 umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainGetXMLDescEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; @@ -2023,13 +1969,8 @@ static int umlDomainCreateWithFlags(virDomainPtr dom= , unsigned int flags) =20 virNWFilterReadLockFilterUpdates(); umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2123,12 +2064,8 @@ static int umlDomainUndefineFlags(virDomainPtr dom, virCheckFlags(0, -1); =20 umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainUndefineFlagsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2221,14 +2158,8 @@ static int umlDomainAttachDevice(virDomainPtr dom, c= onst char *xml) =20 umlDriverLock(driver); =20 - 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 umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainAttachDeviceEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2341,14 +2272,8 @@ static int umlDomainDetachDevice(virDomainPtr dom, c= onst char *xml) int ret =3D -1; =20 umlDriverLock(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 umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainDetachDeviceEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2411,13 +2336,8 @@ static int umlDomainGetAutostart(virDomainPtr dom, int ret =3D -1; =20 umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainGetAutostartEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2441,13 +2361,8 @@ static int umlDomainSetAutostart(virDomainPtr dom, int ret =3D -1; =20 umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainSetAutostartEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2517,15 +2432,8 @@ umlDomainBlockPeek(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainBlockPeekEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2581,7 +2489,6 @@ umlDomainOpenConsole(virDomainPtr dom, { struct uml_driver *driver =3D dom->conn->privateData; virDomainObjPtr vm =3D NULL; - char uuidstr[VIR_UUID_STRING_BUFLEN]; int ret =3D -1; virDomainChrDefPtr chr =3D NULL; size_t i; @@ -2589,13 +2496,8 @@ umlDomainOpenConsole(virDomainPtr dom, virCheckFlags(0, -1); =20 umlDriverLock(driver); - virUUIDFormat(dom->uuid, uuidstr); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); + if (!(vm =3D umlDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -2932,14 +2834,8 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsig= ned int flags) =20 virCheckFlags(0, -1); =20 - umlDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - umlDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(vm =3D umlDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (virDomainHasManagedSaveImageEnsureACL(dom->conn, vm->def) < 0) goto cleanup; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list