From nobody Sun May 19 05:00:08 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; 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 153345928299244.26974437660215; Sun, 5 Aug 2018 01:54:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F6F831524C0; Sun, 5 Aug 2018 08:54:41 +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 EB34AD58B8; Sun, 5 Aug 2018 08:54:40 +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 91FF71841C57; Sun, 5 Aug 2018 08:54:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w73ESKRH005305 for ; Fri, 3 Aug 2018 10:28:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 296A2213ED80; Fri, 3 Aug 2018 14:28:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-135.ams2.redhat.com [10.36.117.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 555C1213ED6A; Fri, 3 Aug 2018 14:28:19 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 3 Aug 2018 15:28:16 +0100 Message-Id: <20180803142816.12796-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] conf: rewrite filtering for capabilities lookup 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sun, 05 Aug 2018 08:54:41 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 The virCapabilitiesDomainDataLookupInternal() is given a list of parameters representing the desired domain characteristics. It then has to look throught the capabilities to identify an acceptable match. The virCapsDomainDataCompare() method is used for filtering out candidates which don't match the desired criteria. It is called primarily from the innermost loops and as such is doing many repeated checks. For example if architcture and os type were checked at the top level loop the two inner loops could be avoided entirely. If emulator and domain type were checked in the 2nd level loop the 3rd level loop can be avoided too. This change thus removes the virCapsDomainDataCompare() method and puts suitable checks at the start of each loop to ensure it executes the minimal number of loop iterations possible. The code becomes clearer to understand as a nice side-effect. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/capabilities.c | 100 ++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 0f96500294..cfd5132329 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -604,46 +604,6 @@ virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSec= ModelPtr secmodel, return -1; } =20 -static bool -virCapsDomainDataCompare(virCapsGuestPtr guest, - virCapsGuestDomainPtr domain, - virCapsGuestMachinePtr machine, - int ostype, - virArch arch, - virDomainVirtType domaintype, - const char *emulator, - const char *machinetype) -{ - const char *check_emulator =3D NULL; - - if (ostype !=3D -1 && guest->ostype !=3D ostype) - return false; - if ((arch !=3D VIR_ARCH_NONE) && (guest->arch.id !=3D arch)) - return false; - - if (domaintype !=3D VIR_DOMAIN_VIRT_NONE && - (!domain || domain->type !=3D domaintype)) - return false; - - if (emulator) { - if (domain) - check_emulator =3D domain->info.emulator; - if (!check_emulator) - check_emulator =3D guest->arch.defaultInfo.emulator; - if (STRNEQ_NULLABLE(check_emulator, emulator)) - return false; - } - - if (machinetype) { - if (!machine) - return false; - if (STRNEQ(machine->name, machinetype) && - (STRNEQ_NULLABLE(machine->canonical, machinetype))) - return false; - } - - return true; -} =20 static virCapsDomainDataPtr virCapabilitiesDomainDataLookupInternal(virCapsPtr caps, @@ -659,13 +619,45 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr ca= ps, virCapsDomainDataPtr ret =3D NULL; size_t i, j, k; =20 + VIR_DEBUG("Lookup ostype=3D%d arch=3D%d domaintype=3D%d emulator=3D%s = machine=3D%s", + ostype, arch, domaintype, NULLSTR(emulator), NULLSTR(machine= type)); for (i =3D 0; i < caps->nguests; i++) { virCapsGuestPtr guest =3D caps->guests[i]; =20 + if (ostype !=3D -1 && guest->ostype !=3D ostype) { + VIR_DEBUG("Skip os type want=3D%d vs got=3D%d", ostype, guest-= >ostype); + continue; + } + VIR_DEBUG("Match os type %d", ostype); + + if ((arch !=3D VIR_ARCH_NONE) && (guest->arch.id !=3D arch)) { + VIR_DEBUG("Skip arch want=3D%d vs got=3D%d", arch, guest->arch= .id); + continue; + } + VIR_DEBUG("Match arch %d", arch); + for (j =3D 0; j < guest->arch.ndomains; j++) { virCapsGuestDomainPtr domain =3D guest->arch.domains[j]; virCapsGuestMachinePtr *machinelist; int nmachines; + const char *check_emulator =3D NULL; + + if (domaintype !=3D VIR_DOMAIN_VIRT_NONE && + (domain->type !=3D domaintype)) { + VIR_DEBUG("Skip domain type want=3D%d vs got=3D%d", domain= type, domain->type); + continue; + } + VIR_DEBUG("Match domain type %d", domaintype); + + check_emulator =3D domain->info.emulator; + if (!check_emulator) + check_emulator =3D guest->arch.defaultInfo.emulator; + if (emulator && STRNEQ_NULLABLE(check_emulator, emulator)) { + VIR_DEBUG("Skip emulator got=3D%s vs want=3D%s", + emulator, NULLSTR(check_emulator)); + continue; + } + VIR_DEBUG("Match emulator %s", NULLSTR(emulator)); =20 if (domain->info.nmachines) { nmachines =3D domain->info.nmachines; @@ -677,32 +669,29 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr ca= ps, =20 for (k =3D 0; k < nmachines; k++) { virCapsGuestMachinePtr machine =3D machinelist[k]; - if (!virCapsDomainDataCompare(guest, domain, machine, - ostype, arch, domaintype, - emulator, machinetype)) + + if (machinetype && + STRNEQ(machine->name, machinetype) && + STRNEQ_NULLABLE(machine->canonical, machinetype)) { + VIR_DEBUG("Skip machine type want=3D%s vs got=3D%s got= =3D%s", + machinetype, machine->name, NULLSTR(machine-= >canonical)); continue; + } + VIR_DEBUG("Match machine type machine %s\n", NULLSTR(machi= netype)); =20 foundmachine =3D machine; break; } =20 - if (!foundmachine) { - if (!virCapsDomainDataCompare(guest, domain, NULL, - ostype, arch, domaintype, - emulator, machinetype)) - continue; - } + if (!foundmachine && nmachines) + continue; =20 founddomain =3D domain; break; } =20 - if (!founddomain) { - if (!virCapsDomainDataCompare(guest, NULL, NULL, - ostype, arch, domaintype, - emulator, machinetype)) - continue; - } + if (!founddomain) + continue; =20 foundguest =3D guest; break; @@ -731,6 +720,7 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps, goto error; } =20 + VIR_DEBUG("No match %s", virBufferCurrentContent(&buf)); virReportError(VIR_ERR_INVALID_ARG, _("could not find capabilities for %s"), virBufferCurrentContent(&buf)); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list