From nobody Sun Feb 8 18:08:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1488981046869763.4261239470978; Wed, 8 Mar 2017 05:50:46 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28Dl9UR020215; Wed, 8 Mar 2017 08:47:09 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v28DkWEv029138 for ; Wed, 8 Mar 2017 08:46:32 -0500 Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28DkTuS029958 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Mar 2017 08:46:31 -0500 Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 5F7D3102C14; Wed, 8 Mar 2017 14:46:29 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 8 Mar 2017 14:46:25 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] cpu: Add list of allowed CPU models to virCPUGetHost 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When creating host CPU definition usable with a given emulator, the CPU should not be defined using an unsupported CPU model. The new @models and @nmodels parameters can be used to limit CPU models which can be used in the result. Signed-off-by: Jiri Denemark --- src/bhyve/bhyve_capabilities.c | 3 ++- src/cpu/cpu.c | 19 +++++++++++++++---- src/cpu/cpu.h | 8 ++++++-- src/cpu/cpu_ppc64.c | 6 ++++-- src/cpu/cpu_x86.c | 6 ++++-- src/qemu/qemu_capabilities.c | 3 ++- src/vmware/vmware_conf.c | 3 ++- src/vz/vz_driver.c | 2 +- 8 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 33e670c5c..60db0b791 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -47,7 +47,8 @@ virBhyveCapsInitCPU(virCapsPtr caps, if (nodeGetInfo(&nodeinfo)) return -1; =20 - if (!(caps->host.cpu =3D virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodei= nfo))) + if (!(caps->host.cpu =3D virCPUGetHost(arch, VIR_CPU_TYPE_HOST, + &nodeinfo, NULL, 0))) return -1; =20 return 0; diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 110bb240c..5b1940b47 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -362,6 +362,8 @@ virCPUDataFree(virCPUDataPtr data) * @arch: CPU architecture * @type: requested type of the CPU * @nodeInfo: simplified CPU topology (optional) + * @models: list of CPU models that can be considered for host CPU + * @nmodels: number of CPU models in @models * * Create CPU definition describing the host's CPU. * @@ -378,18 +380,26 @@ virCPUDataFree(virCPUDataPtr data) * host CPU model. In other words, a CPU definition containing just the * topology is a successful result even if detecting the host CPU model fa= ils. * + * It possible to limit the CPU model which may appear in the created CPU + * definition by passing non-NULL @models list. This is useful when reques= ting + * a CPU model usable on a specific hypervisor. If @models is NULL, any CPU + * model known to libvirt may appear in the result. + * * Returns host CPU definition or NULL on error. */ virCPUDefPtr virCPUGetHost(virArch arch, virCPUType type, - virNodeInfoPtr nodeInfo) + virNodeInfoPtr nodeInfo, + const char **models, + unsigned int nmodels) { struct cpuArchDriver *driver; virCPUDefPtr cpu =3D NULL; =20 - VIR_DEBUG("arch=3D%s, type=3D%s, nodeInfo=3D%p", - virArchToString(arch), virCPUTypeToString(type), nodeInfo); + VIR_DEBUG("arch=3D%s, type=3D%s, nodeInfo=3D%p, models=3D%p, nmodels= =3D%u", + virArchToString(arch), virCPUTypeToString(type), nodeInfo, + models, nmodels); =20 if (!(driver =3D cpuGetSubDriver(arch))) return NULL; @@ -431,7 +441,8 @@ virCPUGetHost(virArch arch, * filled in. */ if (driver->getHost) { - if (driver->getHost(cpu) < 0 && !nodeInfo) + if (driver->getHost(cpu, models, nmodels) < 0 && + !nodeInfo) goto error; } else if (nodeInfo) { VIR_DEBUG("cannot detect host CPU model for %s architecture", diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index e5eca08c3..c329eb134 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -71,7 +71,9 @@ typedef void (*cpuArchDataFree) (virCPUDataPtr data); =20 typedef int -(*virCPUArchGetHost)(virCPUDefPtr cpu); +(*virCPUArchGetHost)(virCPUDefPtr cpu, + const char **models, + unsigned int nmodels); =20 typedef virCPUDefPtr (*cpuArchBaseline) (virCPUDefPtr *cpus, @@ -171,7 +173,9 @@ virCPUDataFree(virCPUDataPtr data); virCPUDefPtr virCPUGetHost(virArch arch, virCPUType type, - virNodeInfoPtr nodeInfo); + virNodeInfoPtr nodeInfo, + const char **models, + unsigned int nmodels); =20 char * cpuBaselineXML(const char **xmlCPUs, diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index bb715546b..6e16ffd13 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -716,7 +716,9 @@ virCPUppc64DataFree(virCPUDataPtr data) =20 =20 static int -virCPUppc64GetHost(virCPUDefPtr cpu) +virCPUppc64GetHost(virCPUDefPtr cpu, + const char **models, + unsigned int nmodels) { virCPUDataPtr cpuData =3D NULL; virCPUppc64Data *data; @@ -738,7 +740,7 @@ virCPUppc64GetHost(virCPUDefPtr cpu) #endif data->pvr[0].mask =3D 0xfffffffful; =20 - ret =3D ppc64DriverDecode(cpu, cpuData, NULL, 0, NULL, 0); + ret =3D ppc64DriverDecode(cpu, cpuData, models, nmodels, NULL, 0); =20 cleanup: virCPUppc64DataFree(cpuData); diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index bddb169ba..6719acee2 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2438,7 +2438,9 @@ cpuidSet(uint32_t base, virCPUDataPtr data) =20 =20 static int -virCPUx86GetHost(virCPUDefPtr cpu) +virCPUx86GetHost(virCPUDefPtr cpu, + const char **models, + unsigned int nmodels) { virCPUDataPtr cpuData =3D NULL; int ret =3D -1; @@ -2450,7 +2452,7 @@ virCPUx86GetHost(virCPUDefPtr cpu) cpuidSet(CPUX86_EXTENDED, cpuData) < 0) goto cleanup; =20 - ret =3D x86DecodeCPUData(cpu, cpuData, NULL, 0, NULL, 0); + ret =3D x86DecodeCPUData(cpu, cpuData, models, nmodels, NULL, 0); =20 cleanup: virCPUx86DataFree(cpuData); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index b39014224..319600c30 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1070,7 +1070,8 @@ virQEMUCapsInitCPU(virCapsPtr caps, if (nodeGetInfo(&nodeinfo)) return -1; =20 - if (!(caps->host.cpu =3D virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodei= nfo))) + if (!(caps->host.cpu =3D virCPUGetHost(arch, VIR_CPU_TYPE_HOST, + &nodeinfo, NULL, 0))) return -1; =20 return 0; diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index cb6d60724..659c4737a 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -82,7 +82,8 @@ vmwareCapsInit(void) NULL, NULL, 0, NULL) =3D=3D NULL) goto error; =20 - if (!(cpu =3D virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, NULL))) + if (!(cpu =3D virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, + NULL, NULL, 0))) goto error; =20 /* x86_64 guests are supported if diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 67ec2727b..b5d2964f3 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -130,7 +130,7 @@ vzBuildCapabilities(void) goto error; =20 if (!(caps->host.cpu =3D virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_H= OST, - &nodeinfo))) + &nodeinfo, NULL, 0))) goto error; =20 if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0) --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list