From nobody Wed May 14 17:15:37 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 1526460002639485.4223875027146; Wed, 16 May 2018 01:40:02 -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 545DE30D24E2; Wed, 16 May 2018 08:40:00 +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 15FB698F7E; Wed, 16 May 2018 08:40:00 +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 B4E6EEEF7; Wed, 16 May 2018 08:39:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djhP018343 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1365B10AF9F6; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9CE910EE6D6 for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B0316102EE1; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:26 +0200 Message-Id: <8c7f8789ef1dee72378c4c1f3af062d05bac9bad.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/22] qemu_capabilities: Introduce virQEMUCapsCacheLookupDefault 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.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.44]); Wed, 16 May 2018 08:40:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virConnectGetDomainCapabilities needs to lookup QEMU capabilities matching a specified binary, architecture, virt type, and machine type while using default values when any of the parameters are not provided by the user. Let's extract the lookup code into virQEMUCapsCacheLookupDefault to make it reusable. Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_capabilities.c | 118 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 8 +++ src/qemu/qemu_driver.c | 86 ++++--------------------- 3 files changed, 137 insertions(+), 75 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a5cb24fec6..77a4b4154e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4546,6 +4546,124 @@ virQEMUCapsCacheLookupByArch(virFileCachePtr cache, } =20 =20 +/** + * virQEMUCapsCacheLookupDefault: + * @cache: QEMU capabilities cache + * @binary: optional path to QEMU binary + * @archStr: optional guest architecture + * @virttypeStr: optional virt type + * @machine: optional machine type + * @retArch: if non-NULL, guest architecture will be returned here + * @retVirttype: if non-NULL, domain virt type will be returned here + * @retMachine: if non-NULL, canonical machine type will be returned here + * + * Looks up the QEMU binary specified by @binary and @archStr, checks it c= an + * provide the required @virttypeStr and @machine and returns its capabili= ties. + * Sensible defaults are used for any argument which is NULL (the function= can + * even be called with all NULL arguments). + * + * Returns QEMU capabilities matching the requirements, NULL on error. + */ +virQEMUCapsPtr +virQEMUCapsCacheLookupDefault(virFileCachePtr cache, + const char *binary, + const char *archStr, + const char *virttypeStr, + const char *machine, + virArch *retArch, + virDomainVirtType *retVirttype, + const char **retMachine) +{ + int virttype =3D VIR_DOMAIN_VIRT_NONE; + int arch =3D virArchFromHost(); + virDomainVirtType capsType; + virQEMUCapsPtr qemuCaps =3D NULL; + virQEMUCapsPtr ret =3D NULL; + + if (virttypeStr && + (virttype =3D virDomainVirtTypeFromString(virttypeStr)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown virttype: %s"), virttypeStr); + goto cleanup; + } + + if (archStr && + (arch =3D virArchFromString(archStr)) =3D=3D VIR_ARCH_NONE) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown architecture: %s"), archStr); + goto cleanup; + } + + if (binary) { + virArch arch_from_caps; + + if (!(qemuCaps =3D virQEMUCapsCacheLookup(cache, binary))) + goto cleanup; + + arch_from_caps =3D virQEMUCapsGetArch(qemuCaps); + + if (arch_from_caps !=3D arch && + !((ARCH_IS_X86(arch) && ARCH_IS_X86(arch_from_caps)) || + (ARCH_IS_PPC(arch) && ARCH_IS_PPC(arch_from_caps)) || + (ARCH_IS_ARM(arch) && ARCH_IS_ARM(arch_from_caps)) || + (ARCH_IS_S390(arch) && ARCH_IS_S390(arch_from_caps)))) { + virReportError(VIR_ERR_INVALID_ARG, + _("architecture from emulator '%s' doesn't " + "match given architecture '%s'"), + virArchToString(arch_from_caps), + virArchToString(arch)); + goto cleanup; + } + } else { + if (!(qemuCaps =3D virQEMUCapsCacheLookupByArch(cache, arch))) + goto cleanup; + + binary =3D virQEMUCapsGetBinary(qemuCaps); + } + + if (machine) { + /* Turn @machine into canonical name */ + machine =3D virQEMUCapsGetCanonicalMachine(qemuCaps, machine); + + if (!virQEMUCapsIsMachineSupported(qemuCaps, machine)) { + virReportError(VIR_ERR_INVALID_ARG, + _("the machine '%s' is not supported by emulato= r '%s'"), + machine, binary); + goto cleanup; + } + } else { + machine =3D virQEMUCapsGetDefaultMachine(qemuCaps); + } + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) + capsType =3D VIR_DOMAIN_VIRT_KVM; + else + capsType =3D VIR_DOMAIN_VIRT_QEMU; + + if (virttype =3D=3D VIR_DOMAIN_VIRT_NONE) + virttype =3D capsType; + + if (virttype =3D=3D VIR_DOMAIN_VIRT_KVM && capsType =3D=3D VIR_DOMAIN_= VIRT_QEMU) { + virReportError(VIR_ERR_INVALID_ARG, + _("KVM is not supported by '%s' on this host"), + binary); + goto cleanup; + } + + if (retArch) + *retArch =3D arch; + if (retVirttype) + *retVirttype =3D virttype; + if (retMachine) + *retMachine =3D machine; + + VIR_STEAL_PTR(ret, qemuCaps); + + cleanup: + virObjectUnref(qemuCaps); + return ret; +} + bool virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps, const virDomainDef *def) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index d23c34c24d..6f095bfbfe 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -559,6 +559,14 @@ virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCache= Ptr cache, const char *machineType); virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virFileCachePtr cache, virArch arch); +virQEMUCapsPtr virQEMUCapsCacheLookupDefault(virFileCachePtr cache, + const char *binary, + const char *archStr, + const char *virttypeStr, + const char *machine, + virArch *retArch, + virDomainVirtType *retVirttyp= e, + const char **retMachine); =20 virCapsPtr virQEMUCapsInit(virFileCachePtr cache); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9037818e2a..6c086b9ef8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19249,10 +19249,9 @@ qemuConnectGetDomainCapabilities(virConnectPtr con= n, char *ret =3D NULL; virQEMUDriverPtr driver =3D conn->privateData; virQEMUCapsPtr qemuCaps =3D NULL; - int virttype =3D VIR_DOMAIN_VIRT_NONE; - virDomainVirtType capsType; + virArch arch; + virDomainVirtType virttype; virDomainCapsPtr domCaps =3D NULL; - int arch =3D virArchFromHost(); /* virArch */ virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; =20 @@ -19266,80 +19265,17 @@ qemuConnectGetDomainCapabilities(virConnectPtr co= nn, if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; =20 - if (virttype_str && - (virttype =3D virDomainVirtTypeFromString(virttype_str)) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown virttype: %s"), - virttype_str); + qemuCaps =3D virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, + emulatorbin, + arch_str, + virttype_str, + machine, + &arch, &virttype, &machine); + if (!qemuCaps) goto cleanup; - } =20 - if (arch_str && (arch =3D virArchFromString(arch_str)) =3D=3D VIR_ARCH= _NONE) { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown architecture: %s"), - arch_str); - goto cleanup; - } - - if (emulatorbin) { - virArch arch_from_caps; - - if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, - emulatorbin))) - goto cleanup; - - arch_from_caps =3D virQEMUCapsGetArch(qemuCaps); - - if (arch_from_caps !=3D arch && - !((ARCH_IS_X86(arch) && ARCH_IS_X86(arch_from_caps)) || - (ARCH_IS_PPC(arch) && ARCH_IS_PPC(arch_from_caps)) || - (ARCH_IS_ARM(arch) && ARCH_IS_ARM(arch_from_caps)) || - (ARCH_IS_S390(arch) && ARCH_IS_S390(arch_from_caps)))) { - virReportError(VIR_ERR_INVALID_ARG, - _("architecture from emulator '%s' doesn't " - "match given architecture '%s'"), - virArchToString(arch_from_caps), - virArchToString(arch)); - goto cleanup; - } - } else { - if (!(qemuCaps =3D virQEMUCapsCacheLookupByArch(driver->qemuCapsCa= che, - arch))) - goto cleanup; - - emulatorbin =3D virQEMUCapsGetBinary(qemuCaps); - } - - if (machine) { - /* Turn @machine into canonical name */ - machine =3D virQEMUCapsGetCanonicalMachine(qemuCaps, machine); - - if (!virQEMUCapsIsMachineSupported(qemuCaps, machine)) { - virReportError(VIR_ERR_INVALID_ARG, - _("the machine '%s' is not supported by emulato= r '%s'"), - machine, emulatorbin); - goto cleanup; - } - } else { - machine =3D virQEMUCapsGetDefaultMachine(qemuCaps); - } - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) - capsType =3D VIR_DOMAIN_VIRT_KVM; - else - capsType =3D VIR_DOMAIN_VIRT_QEMU; - - if (virttype =3D=3D VIR_DOMAIN_VIRT_NONE) - virttype =3D capsType; - - if (virttype =3D=3D VIR_DOMAIN_VIRT_KVM && capsType =3D=3D VIR_DOMAIN_= VIRT_QEMU) { - virReportError(VIR_ERR_INVALID_ARG, - _("KVM is not supported by '%s' on this host"), - emulatorbin); - goto cleanup; - } - - if (!(domCaps =3D virDomainCapsNew(emulatorbin, machine, arch, virttyp= e))) + if (!(domCaps =3D virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), mac= hine, + arch, virttype))) goto cleanup; =20 if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list