From nobody Wed May 14 15:22:48 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; 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 1520614242843630.5213375354796; Fri, 9 Mar 2018 08:50:42 -0800 (PST) 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 7BA154ACA4; Fri, 9 Mar 2018 16:50:41 +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 54E2A5D78E; Fri, 9 Mar 2018 16:50:41 +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 1EEAA4CAA2; Fri, 9 Mar 2018 16:50:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w29GmYPT000488 for ; Fri, 9 Mar 2018 11:48:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9312818661; Fri, 9 Mar 2018 16:48:34 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-138.phx2.redhat.com [10.3.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A63118664 for ; Fri, 9 Mar 2018 16:48:34 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 9 Mar 2018 11:48:05 -0500 Message-Id: <20180309164816.837-10-jferlan@redhat.com> In-Reply-To: <20180309164816.837-1-jferlan@redhat.com> References: <20180309164816.837-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/20] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 09 Mar 2018 16:50:41 +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 --- 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 ab7fa7f27..ea8fca38b 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, @@ -1368,20 +1401,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; @@ -1427,13 +1454,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; @@ -1453,13 +1475,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; @@ -1478,13 +1495,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; @@ -1637,14 +1649,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; @@ -1683,12 +1689,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; @@ -1726,14 +1728,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; @@ -1755,18 +1751,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; @@ -1785,18 +1771,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; @@ -1822,18 +1798,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; @@ -1866,15 +1832,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; @@ -1915,15 +1874,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; @@ -1948,14 +1900,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; @@ -2015,13 +1961,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; @@ -2115,12 +2056,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; @@ -2213,14 +2150,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; @@ -2333,14 +2264,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; @@ -2403,13 +2328,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; @@ -2433,13 +2353,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; @@ -2509,15 +2424,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; @@ -2573,7 +2481,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; @@ -2581,13 +2488,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; @@ -2924,14 +2826,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