From nobody Wed Apr 1 08:45:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1488981010982807.1160723206648; Wed, 8 Mar 2017 05:50:10 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28DkXOs013872; Wed, 8 Mar 2017 08:46:33 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v28DkVl9029119 for ; Wed, 8 Mar 2017 08:46:31 -0500 Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28DkTv2021594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Mar 2017 08:46:30 -0500 Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 5D749102C13; Wed, 8 Mar 2017 14:46:29 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 8 Mar 2017 14:46:24 +0100 Message-Id: <92118d7813f0bcb37ab1b842e4d3ba90bdac4914.1488980728.git.jdenemar@redhat.com> 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.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/7] cpu: Add virCPUType parameter 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" The parameter can be used to request either VIR_CPU_TYPE_HOST (which has been assumed so far) or VIR_CPU_TYPE_GUEST definition. Signed-off-by: Jiri Denemark --- src/bhyve/bhyve_capabilities.c | 2 +- src/cpu/cpu.c | 41 ++++++++++++++++++++++++++++++++++++--= --- src/cpu/cpu.h | 1 + src/qemu/qemu_capabilities.c | 2 +- src/vmware/vmware_conf.c | 2 +- src/vz/vz_driver.c | 3 ++- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index c2c9303d7..33e670c5c 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -47,7 +47,7 @@ virBhyveCapsInitCPU(virCapsPtr caps, if (nodeGetInfo(&nodeinfo)) return -1; =20 - if (!(caps->host.cpu =3D virCPUGetHost(arch, &nodeinfo))) + if (!(caps->host.cpu =3D virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodei= nfo))) return -1; =20 return 0; diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index c1666ed3b..110bb240c 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -360,9 +360,18 @@ virCPUDataFree(virCPUDataPtr data) * virCPUGetHost: * * @arch: CPU architecture + * @type: requested type of the CPU * @nodeInfo: simplified CPU topology (optional) * - * Create CPU definition describing the host's CPU. If @nodeInfo is not NU= LL, + * Create CPU definition describing the host's CPU. + * + * The @type (either VIR_CPU_TYPE_HOST or VIR_CPU_TYPE_GUEST) specifies wh= at + * type of CPU definition should be created. Specifically, VIR_CPU_TYPE_HO= ST + * CPUs may contain only features without any policy attribute. Requesting + * VIR_CPU_TYPE_GUEST provides better results because the CPU is allowed to + * contain disabled features. + * + * If @nodeInfo is not NULL (which is only allowed for VIR_CPU_TYPE_HOST C= PUs), * the CPU definition will have topology (sockets, cores, threads) filled = in * according to the content of @nodeInfo. The function fails only if @node= Info * was not passed in and the assigned CPU driver was not able to detect the @@ -373,13 +382,14 @@ virCPUDataFree(virCPUDataPtr data) */ virCPUDefPtr virCPUGetHost(virArch arch, + virCPUType type, virNodeInfoPtr nodeInfo) { struct cpuArchDriver *driver; virCPUDefPtr cpu =3D NULL; =20 - VIR_DEBUG("arch=3D%s, nodeInfo=3D%p", - virArchToString(arch), nodeInfo); + VIR_DEBUG("arch=3D%s, type=3D%s, nodeInfo=3D%p", + virArchToString(arch), virCPUTypeToString(type), nodeInfo); =20 if (!(driver =3D cpuGetSubDriver(arch))) return NULL; @@ -387,8 +397,29 @@ virCPUGetHost(virArch arch, if (VIR_ALLOC(cpu) < 0) return NULL; =20 - cpu->arch =3D arch; - cpu->type =3D VIR_CPU_TYPE_HOST; + switch (type) { + case VIR_CPU_TYPE_HOST: + cpu->arch =3D arch; + cpu->type =3D type; + break; + + case VIR_CPU_TYPE_GUEST: + if (nodeInfo) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot set topology for CPU type '%s'"), + virCPUTypeToString(type)); + goto error; + } + cpu->type =3D type; + break; + + case VIR_CPU_TYPE_AUTO: + case VIR_CPU_TYPE_LAST: + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported CPU type: %s"), + virCPUTypeToString(type)); + goto error; + } =20 if (nodeInfo) { cpu->sockets =3D nodeInfo->sockets; diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index cbbb45223..e5eca08c3 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -170,6 +170,7 @@ virCPUDataFree(virCPUDataPtr data); =20 virCPUDefPtr virCPUGetHost(virArch arch, + virCPUType type, virNodeInfoPtr nodeInfo); =20 char * diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index b0a4861c3..b39014224 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1070,7 +1070,7 @@ virQEMUCapsInitCPU(virCapsPtr caps, if (nodeGetInfo(&nodeinfo)) return -1; =20 - if (!(caps->host.cpu =3D virCPUGetHost(arch, &nodeinfo))) + if (!(caps->host.cpu =3D virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodei= nfo))) return -1; =20 return 0; diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index d1444e462..cb6d60724 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -82,7 +82,7 @@ vmwareCapsInit(void) NULL, NULL, 0, NULL) =3D=3D NULL) goto error; =20 - if (!(cpu =3D virCPUGetHost(caps->host.arch, NULL))) + if (!(cpu =3D virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, NULL))) goto error; =20 /* x86_64 guests are supported if diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index f97a2045b..67ec2727b 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -129,7 +129,8 @@ vzBuildCapabilities(void) if (nodeGetInfo(&nodeinfo)) goto error; =20 - if (!(caps->host.cpu =3D virCPUGetHost(caps->host.arch, &nodeinfo))) + if (!(caps->host.cpu =3D virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_H= OST, + &nodeinfo))) 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