From nobody Thu Jul 10 00:27:55 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 1507129975295307.19906600733214; Wed, 4 Oct 2017 08:12:55 -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 423167EAA5; Wed, 4 Oct 2017 15:12:54 +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 1428860467; Wed, 4 Oct 2017 15:12:54 +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 C8FDA1806100; Wed, 4 Oct 2017 15:12:53 +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 v94Ewvbt006886 for ; Wed, 4 Oct 2017 10:58:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id B92F960491; Wed, 4 Oct 2017 14:58:57 +0000 (UTC) Received: from mamuti.net (unknown [10.34.246.102]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C14F60472 for ; Wed, 4 Oct 2017 14:58:55 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 40155102353; Wed, 4 Oct 2017 16:58:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 423167EAA5 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 4 Oct 2017 16:58:31 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/23] cpu: Return model from virCPUModelIsAllowed 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.28]); Wed, 04 Oct 2017 15:12:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If a given CPU model is supported by the hypervisor, we want to know more about it, e.g., what features may block its usage on the current host and such details are stored in the virDomainCapsCPUModelsPtr list which virCPUModelIsAllowed uses to check whether the CPU model is supported. Thus if the CPU model is found in the list we can directly return a pointer to the corresponding virDomainCapsCPUModel if the caller needs to look at the details. Signed-off-by: Jiri Denemark Reviewed-by: John Ferlan --- src/cpu/cpu.c | 18 ++++++++++++++---- src/cpu/cpu.h | 3 ++- src/cpu/cpu_ppc64.c | 2 +- src/cpu/cpu_x86.c | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index b815ed383a..48290a471b 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -819,24 +819,34 @@ virCPUDataParse(const char *xmlStr) * * @model: CPU model to be checked * @models: list of supported CPU models + * @hvModel: pointer to matching model from @models will be returned here * * Checks whether @model can be found in the list of supported @models. - * If @models is NULL, all models are supported. + * If @models is NULL, all models are supported. If both @models and @hvMo= del + * are non-NULL and @model is found in the list of supported models, @hvMo= del + * will be filled with the pointer to the matching CPU model from @models. * * Returns true if @model is supported, false otherwise. */ bool virCPUModelIsAllowed(const char *model, - virDomainCapsCPUModelsPtr models) + virDomainCapsCPUModelsPtr models, + virDomainCapsCPUModelPtr *hvModel) { size_t i; =20 + if (hvModel) + *hvModel =3D NULL; + if (!models) return true; =20 for (i =3D 0; i < models->nmodels; i++) { - if (STREQ(models->models[i].name, model)) + if (STREQ(models->models[i].name, model)) { + if (hvModel) + *hvModel =3D models->models + i; return true; + } } return false; } @@ -908,7 +918,7 @@ virCPUTranslate(virArch arch, cpu->mode =3D=3D VIR_CPU_MODE_HOST_PASSTHROUGH) return 0; =20 - if (virCPUModelIsAllowed(cpu->model, models)) + if (virCPUModelIsAllowed(cpu->model, models, NULL)) return 0; =20 if (cpu->fallback !=3D VIR_CPU_FALLBACK_ALLOW) { diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 83d5bcb63f..2d81927a0b 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -227,7 +227,8 @@ virCPUDataCheckFeature(const virCPUData *data, =20 bool virCPUModelIsAllowed(const char *model, - virDomainCapsCPUModelsPtr models) + virDomainCapsCPUModelsPtr models, + virDomainCapsCPUModelPtr *hvModel) ATTRIBUTE_NONNULL(1); =20 int diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 7eb27c59bd..9f990a3fb5 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -679,7 +679,7 @@ ppc64DriverDecode(virCPUDefPtr cpu, goto cleanup; } =20 - if (!virCPUModelIsAllowed(model->name, models)) { + if (!virCPUModelIsAllowed(model->name, models, NULL)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("CPU model %s is not supported by hypervisor"), model->name); diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 84ec878d1b..198e80a5c2 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1854,7 +1854,7 @@ x86Decode(virCPUDefPtr cpu, */ for (i =3D map->nmodels - 1; i >=3D 0; i--) { candidate =3D map->models[i]; - if (!virCPUModelIsAllowed(candidate->name, models)) { + if (!virCPUModelIsAllowed(candidate->name, models, NULL)) { if (preferred && STREQ(candidate->name, preferred)) { if (cpu->fallback !=3D VIR_CPU_FALLBACK_ALLOW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list