From nobody Mon Mar 30 03:20:57 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 1488981043123435.5673354728581; Wed, 8 Mar 2017 05:50:43 -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 v28Dl9HW020212; Wed, 8 Mar 2017 08:47:09 -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 v28DkV43029128 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 v28DkTqE021592 (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 5C1C8102C12; Wed, 8 Mar 2017 14:46:29 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 8 Mar 2017 14:46:23 +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.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] cpu: Replace cpuNodeData with 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" cpuNodeData has always been followed by cpuDecode as no hypervisor driver is really interested in raw CPUID data for a host CPU. Let's create a new CPU driver API which returns virCPUDefPtr directly. Signed-off-by: Jiri Denemark --- src/bhyve/bhyve_capabilities.c | 34 ++++--------------------- src/cpu/cpu.c | 58 ++++++++++++++++++++++++++++++++++----= ---- src/cpu/cpu.h | 11 ++++---- src/cpu/cpu_arm.c | 1 - src/cpu/cpu_ppc64.c | 28 ++++++++++---------- src/cpu/cpu_s390.c | 1 - src/cpu/cpu_x86.c | 27 +++++++++----------- src/libvirt_private.syms | 2 +- src/qemu/qemu_capabilities.c | 32 +++-------------------- src/vmware/vmware_conf.c | 19 +++----------- src/vz/vz_driver.c | 21 ++------------- 11 files changed, 95 insertions(+), 139 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 52d6ca782..c2c9303d7 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -40,41 +40,17 @@ VIR_LOG_INIT("bhyve.bhyve_capabilities"); =20 static int virBhyveCapsInitCPU(virCapsPtr caps, - virArch arch) + virArch arch) { - virCPUDefPtr cpu =3D NULL; - virCPUDataPtr data =3D NULL; virNodeInfo nodeinfo; - int ret =3D -1; - - if (VIR_ALLOC(cpu) < 0) - goto error; - - cpu->arch =3D arch; =20 if (nodeGetInfo(&nodeinfo)) - goto error; + return -1; =20 - cpu->type =3D VIR_CPU_TYPE_HOST; - cpu->sockets =3D nodeinfo.sockets; - cpu->cores =3D nodeinfo.cores; - cpu->threads =3D nodeinfo.threads; - caps->host.cpu =3D cpu; + if (!(caps->host.cpu =3D virCPUGetHost(arch, &nodeinfo))) + return -1; =20 - if (!(data =3D cpuNodeData(arch)) || - cpuDecode(cpu, data, NULL, 0, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCPUDataFree(data); - - return ret; - - error: - virCPUDefFree(cpu); - goto cleanup; + return 0; } =20 virCapsPtr diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 051a58040..c1666ed3b 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -357,30 +357,66 @@ virCPUDataFree(virCPUDataPtr data) =20 =20 /** - * cpuNodeData: + * virCPUGetHost: * * @arch: CPU architecture + * @nodeInfo: simplified CPU topology (optional) * - * Returns CPU data for host CPU or NULL on error. + * Create CPU definition describing the host's CPU. If @nodeInfo is not NU= LL, + * 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 + * 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. + * + * Returns host CPU definition or NULL on error. */ -virCPUDataPtr -cpuNodeData(virArch arch) +virCPUDefPtr +virCPUGetHost(virArch arch, + virNodeInfoPtr nodeInfo) { struct cpuArchDriver *driver; + virCPUDefPtr cpu =3D NULL; =20 - VIR_DEBUG("arch=3D%s", virArchToString(arch)); + VIR_DEBUG("arch=3D%s, nodeInfo=3D%p", + virArchToString(arch), nodeInfo); =20 - if ((driver =3D cpuGetSubDriver(arch)) =3D=3D NULL) + if (!(driver =3D cpuGetSubDriver(arch))) return NULL; =20 - if (driver->nodeData =3D=3D NULL) { - virReportError(VIR_ERR_NO_SUPPORT, - _("cannot get node CPU data for %s architecture"), - virArchToString(arch)); + if (VIR_ALLOC(cpu) < 0) return NULL; + + cpu->arch =3D arch; + cpu->type =3D VIR_CPU_TYPE_HOST; + + if (nodeInfo) { + cpu->sockets =3D nodeInfo->sockets; + cpu->cores =3D nodeInfo->cores; + cpu->threads =3D nodeInfo->threads; } =20 - return driver->nodeData(arch); + /* Try to get the host CPU model, but don't really fail if nodeInfo is + * filled in. + */ + if (driver->getHost) { + if (driver->getHost(cpu) < 0 && !nodeInfo) + goto error; + } else if (nodeInfo) { + VIR_DEBUG("cannot detect host CPU model for %s architecture", + virArchToString(arch)); + } else { + virReportError(VIR_ERR_NO_SUPPORT, + _("cannot detect host CPU model for %s architecture= "), + virArchToString(arch)); + goto error; + } + + return cpu; + + error: + virCPUDefFree(cpu); + return NULL; } =20 =20 diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 0324284b9..cbbb45223 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -70,8 +70,8 @@ typedef int typedef void (*cpuArchDataFree) (virCPUDataPtr data); =20 -typedef virCPUDataPtr -(*cpuArchNodeData) (virArch arch); +typedef int +(*virCPUArchGetHost)(virCPUDefPtr cpu); =20 typedef virCPUDefPtr (*cpuArchBaseline) (virCPUDefPtr *cpus, @@ -117,7 +117,7 @@ struct cpuArchDriver { cpuArchDecode decode; cpuArchEncode encode; cpuArchDataFree dataFree; - cpuArchNodeData nodeData; + virCPUArchGetHost getHost; cpuArchBaseline baseline; virCPUArchUpdate update; virCPUArchCheckFeature checkFeature; @@ -168,8 +168,9 @@ virCPUDataNew(virArch arch); void virCPUDataFree(virCPUDataPtr data); =20 -virCPUDataPtr -cpuNodeData (virArch arch); +virCPUDefPtr +virCPUGetHost(virArch arch, + virNodeInfoPtr nodeInfo); =20 char * cpuBaselineXML(const char **xmlCPUs, diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 3a0ee2b14..a1aba2554 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -111,7 +111,6 @@ struct cpuArchDriver cpuDriverArm =3D { .compare =3D virCPUarmCompare, .decode =3D NULL, .encode =3D NULL, - .nodeData =3D NULL, .baseline =3D armBaseline, .update =3D virCPUarmUpdate, }; diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index a7c8545db..bb715546b 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -714,19 +714,21 @@ virCPUppc64DataFree(virCPUDataPtr data) VIR_FREE(data); } =20 -static virCPUDataPtr -ppc64DriverNodeData(virArch arch) + +static int +virCPUppc64GetHost(virCPUDefPtr cpu) { - virCPUDataPtr nodeData; + virCPUDataPtr cpuData =3D NULL; virCPUppc64Data *data; + int ret =3D -1; =20 - if (VIR_ALLOC(nodeData) < 0) - goto error; + if (!(cpuData =3D virCPUDataNew(archs[0]))) + goto cleanup; =20 - data =3D &nodeData->data.ppc64; + data =3D &cpuData->data.ppc64; =20 if (VIR_ALLOC_N(data->pvr, 1) < 0) - goto error; + goto cleanup; =20 data->len =3D 1; =20 @@ -736,13 +738,11 @@ ppc64DriverNodeData(virArch arch) #endif data->pvr[0].mask =3D 0xfffffffful; =20 - nodeData->arch =3D arch; + ret =3D ppc64DriverDecode(cpu, cpuData, NULL, 0, NULL, 0); =20 - return nodeData; - - error: - virCPUppc64DataFree(nodeData); - return NULL; + cleanup: + virCPUppc64DataFree(cpuData); + return ret; } =20 =20 @@ -902,7 +902,7 @@ struct cpuArchDriver cpuDriverPPC64 =3D { .decode =3D ppc64DriverDecode, .encode =3D NULL, .dataFree =3D virCPUppc64DataFree, - .nodeData =3D ppc64DriverNodeData, + .getHost =3D virCPUppc64GetHost, .baseline =3D ppc64DriverBaseline, .update =3D virCPUppc64Update, .getModels =3D virCPUppc64DriverGetModels, diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c index 9503e8e2b..c08a24a53 100644 --- a/src/cpu/cpu_s390.c +++ b/src/cpu/cpu_s390.c @@ -109,7 +109,6 @@ struct cpuArchDriver cpuDriverS390 =3D { .compare =3D virCPUs390Compare, .decode =3D NULL, .encode =3D NULL, - .nodeData =3D NULL, .baseline =3D NULL, .update =3D virCPUs390Update, }; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index bcf50cb9e..bddb169ba 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2437,25 +2437,24 @@ cpuidSet(uint32_t base, virCPUDataPtr data) } =20 =20 -static virCPUDataPtr -x86NodeData(virArch arch) +static int +virCPUx86GetHost(virCPUDefPtr cpu) { virCPUDataPtr cpuData =3D NULL; + int ret =3D -1; =20 - if (!(cpuData =3D virCPUDataNew(arch))) - goto error; + if (!(cpuData =3D virCPUDataNew(archs[0]))) + goto cleanup; =20 - if (cpuidSet(CPUX86_BASIC, cpuData) < 0) - goto error; + if (cpuidSet(CPUX86_BASIC, cpuData) < 0 || + cpuidSet(CPUX86_EXTENDED, cpuData) < 0) + goto cleanup; =20 - if (cpuidSet(CPUX86_EXTENDED, cpuData) < 0) - goto error; + ret =3D x86DecodeCPUData(cpu, cpuData, NULL, 0, NULL, 0); =20 - return cpuData; - - error: + cleanup: virCPUx86DataFree(cpuData); - return NULL; + return ret; } #endif =20 @@ -2849,9 +2848,7 @@ struct cpuArchDriver cpuDriverX86 =3D { .encode =3D x86Encode, .dataFree =3D virCPUx86DataFree, #if defined(__i386__) || defined(__x86_64__) - .nodeData =3D x86NodeData, -#else - .nodeData =3D NULL, + .getHost =3D virCPUx86GetHost, #endif .baseline =3D x86Baseline, .update =3D virCPUx86Update, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6c89d44e2..4efea0098 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -996,7 +996,6 @@ cpuBaseline; cpuBaselineXML; cpuDecode; cpuEncode; -cpuNodeData; virCPUCheckFeature; virCPUCompare; virCPUCompareXML; @@ -1006,6 +1005,7 @@ virCPUDataFormat; virCPUDataFree; virCPUDataNew; virCPUDataParse; +virCPUGetHost; virCPUGetModels; virCPUTranslate; virCPUUpdate; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 5a3b4ac50..b0a4861c3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1065,39 +1065,15 @@ static int virQEMUCapsInitCPU(virCapsPtr caps, virArch arch) { - virCPUDefPtr cpu =3D NULL; - virCPUDataPtr data =3D NULL; virNodeInfo nodeinfo; - int ret =3D -1; - - if (VIR_ALLOC(cpu) < 0) - goto error; - - cpu->arch =3D arch; =20 if (nodeGetInfo(&nodeinfo)) - goto error; + return -1; =20 - cpu->type =3D VIR_CPU_TYPE_HOST; - cpu->sockets =3D nodeinfo.sockets; - cpu->cores =3D nodeinfo.cores; - cpu->threads =3D nodeinfo.threads; - caps->host.cpu =3D cpu; + if (!(caps->host.cpu =3D virCPUGetHost(arch, &nodeinfo))) + return -1; =20 - if (!(data =3D cpuNodeData(arch)) - || cpuDecode(cpu, data, NULL, 0, NULL) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCPUDataFree(data); - - return ret; - - error: - virCPUDefFree(cpu); - goto cleanup; + return 0; } =20 =20 diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 5b1b5f5fd..d1444e462 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -62,7 +62,6 @@ vmwareCapsInit(void) virCapsPtr caps =3D NULL; virCapsGuestPtr guest =3D NULL; virCPUDefPtr cpu =3D NULL; - virCPUDataPtr data =3D NULL; =20 if ((caps =3D virCapabilitiesNew(virArchFromHost(), false, false)) =3D=3D NULL) @@ -83,26 +82,18 @@ vmwareCapsInit(void) NULL, NULL, 0, NULL) =3D=3D NULL) goto error; =20 - if (VIR_ALLOC(cpu) < 0) + if (!(cpu =3D virCPUGetHost(caps->host.arch, NULL))) goto error; =20 - cpu->arch =3D caps->host.arch; - cpu->type =3D VIR_CPU_TYPE_HOST; - - if (!(data =3D cpuNodeData(cpu->arch)) - || cpuDecode(cpu, data, NULL, 0, NULL) < 0) { - goto error; - } - /* x86_64 guests are supported if * - Host arch is x86_64 * Or * - Host CPU is x86_64 with virtualization extensions */ if (caps->host.arch =3D=3D VIR_ARCH_X86_64 || - (virCPUDataCheckFeature(data, "lm") && - (virCPUDataCheckFeature(data, "vmx") || - virCPUDataCheckFeature(data, "svm")))) { + (virCPUCheckFeature(cpu->arch, cpu, "lm") && + (virCPUCheckFeature(cpu->arch, cpu, "vmx") || + virCPUCheckFeature(cpu->arch, cpu, "svm")))) { =20 if ((guest =3D virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, @@ -118,8 +109,6 @@ vmwareCapsInit(void) =20 cleanup: virCPUDefFree(cpu); - virCPUDataFree(data); - return caps; =20 error: diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 1ca9fd726..f97a2045b 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -99,8 +99,6 @@ static virCapsPtr vzBuildCapabilities(void) { virCapsPtr caps =3D NULL; - virCPUDefPtr cpu =3D NULL; - virCPUDataPtr data =3D NULL; virNodeInfo nodeinfo; virDomainOSType ostypes[] =3D { VIR_DOMAIN_OSTYPE_HVM, @@ -131,32 +129,17 @@ vzBuildCapabilities(void) if (nodeGetInfo(&nodeinfo)) goto error; =20 - if (VIR_ALLOC(cpu) < 0) + if (!(caps->host.cpu =3D virCPUGetHost(caps->host.arch, &nodeinfo))) goto error; =20 - cpu->arch =3D caps->host.arch; - cpu->type =3D VIR_CPU_TYPE_HOST; - cpu->sockets =3D nodeinfo.sockets; - cpu->cores =3D nodeinfo.cores; - cpu->threads =3D nodeinfo.threads; - - caps->host.cpu =3D cpu; - if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0) goto error; =20 - if (!(data =3D cpuNodeData(cpu->arch)) - || cpuDecode(cpu, data, NULL, 0, NULL) < 0) { - goto cleanup; - } - - cleanup: - virCPUDataFree(data); return caps; =20 error: virObjectUnref(caps); - goto cleanup; + return NULL; } =20 static void vzDriverDispose(void * obj) --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list