From nobody Tue Apr 30 22:28:50 2024 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=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523920589064535.7097047070715; Mon, 16 Apr 2018 16:16:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02FD34E040; Mon, 16 Apr 2018 23:16:26 +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 E38147A40B; Mon, 16 Apr 2018 23:16:24 +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 57C93180215F; Mon, 16 Apr 2018 23:16:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3GNGIR1008273 for ; Mon, 16 Apr 2018 19:16:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 588FB7A41D; Mon, 16 Apr 2018 23:16:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 511237A41B for ; Mon, 16 Apr 2018 23:16:16 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2527E315008F for ; Mon, 16 Apr 2018 23:16:15 +0000 (UTC) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3GN9VZq062866 for ; Mon, 16 Apr 2018 19:16:14 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hd2b7xuw3-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 16 Apr 2018 19:16:14 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Apr 2018 19:16:13 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Apr 2018 19:16:11 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3GNGBe252232352; Mon, 16 Apr 2018 23:16:11 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A64B7B204E; Mon, 16 Apr 2018 20:18:15 -0400 (EDT) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.57]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id A461CB204D; Mon, 16 Apr 2018 20:18:15 -0400 (EDT) From: Collin Walling To: libvir-list@redhat.com Date: Mon, 16 Apr 2018 19:16:06 -0400 In-Reply-To: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> References: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041623-2213-0000-0000-00000292B9DE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008866; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018943; UDB=6.00519786; IPR=6.00798184; MB=3.00020604; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-16 23:16:12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041623-2214-0000-0000-000059C7CDF1 Message-Id: <1523920569-9386-2-git-send-email-walling@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-16_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804160192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 16 Apr 2018 23:16:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 16 Apr 2018 23:16:15 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'walling@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: cventeic@redhat.com Subject: [libvirt] [PATCH v1 1/4] qemu: place qemuCaps host cpu model in virCaps 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 16 Apr 2018 23:16:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some architectures retrieve their host CPU model data from QEMU via qmp-query-cpu-model-expansion and stores it in the QEMU cache files. Let's take this data and also store it in virCaps so we can easily retrieve the host CPU model for later use. We should also take care to ensure that we always query the same cache file consistently between libvirtd executions, so let's query the qemuCaps from the first qemu-system-ARCH found in $PATH (via virQEMUCapsCacheLookup). Signed-off-by: Collin Walling --- src/qemu/qemu_capabilities.c | 53 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 53 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index cb716ff..d2eb813 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -896,6 +896,54 @@ virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, } =20 =20 +static int +virQEMUProbeHostCPUModelFromBinary(virFileCachePtr cache, + virArch hostarch, + virCPUDefPtr *hostCPU) +{ + char *binary; + virQEMUCapsPtr qemuCaps =3D NULL; + virCPUDefPtr qemuCpu; + virCPUDefPtr tmp =3D NULL; + int ret =3D -1; + + if (!(binary =3D virQEMUCapsFindBinaryForArch(hostarch, hostarch))) + goto cleanup; + + if (!(qemuCaps =3D virQEMUCapsCacheLookup(cache, binary))) + goto cleanup; + + /* If QEMU does not report the host's cpu model, then fail gracefully = */ + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION)) { + ret =3D 0; + goto cleanup; + } + + if (!(qemuCpu =3D virQEMUCapsGetHostModel(qemuCaps, VIR_DOMAIN_VIRT_KV= M, + VIR_QEMU_CAPS_HOST_CPU_REPORTE= D))) + goto cleanup; + + if (VIR_ALLOC(tmp) < 0) + goto cleanup; + + if (!(tmp =3D virCPUDefCopyWithoutModel(*hostCPU))) + goto cleanup; + + if (virCPUDefCopyModel(tmp, qemuCpu, false) < 0) + goto cleanup; + + virCPUDefFree(*hostCPU); + VIR_STEAL_PTR(*hostCPU, tmp); + ret =3D 0; + + cleanup: + VIR_FREE(binary); + virCPUDefFree(tmp); + virObjectUnref(qemuCaps); + return ret; +} + + virCapsPtr virQEMUCapsInit(virFileCachePtr cache) { @@ -922,6 +970,11 @@ virQEMUCapsInit(virFileCachePtr cache) if (!(caps->host.cpu =3D virCPUProbeHost(caps->host.arch))) VIR_WARN("Failed to get host CPU"); =20 + /* Some archs get host cpu information via QEMU */ + if (caps->host.cpu && !caps->host.cpu->model && + virQEMUProbeHostCPUModelFromBinary(cache, hostarch, &caps->host.cp= u) < 0) + VIR_WARN("Failed to get host CPU model from QEMU"); + /* Add the power management features of the host */ if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0) VIR_WARN("Failed to get host power management capabilities"); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 22:28:50 2024 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=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523920590098914.8607358712028; Mon, 16 Apr 2018 16:16:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86C6E3153791; Mon, 16 Apr 2018 23:16:26 +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 53B3B5E9D1; Mon, 16 Apr 2018 23:16:26 +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 641234CA97; Mon, 16 Apr 2018 23:16:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3GNGNnJ008598 for ; Mon, 16 Apr 2018 19:16:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21F788EEBB; Mon, 16 Apr 2018 23:16:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 191968EEB2 for ; Mon, 16 Apr 2018 23:16:17 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09BC33004415 for ; Mon, 16 Apr 2018 23:16:17 +0000 (UTC) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3GNFiS2045434 for ; Mon, 16 Apr 2018 19:16:16 -0400 Received: from e18.ny.us.ibm.com (e18.ny.us.ibm.com [129.33.205.208]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hd4m89gey-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 16 Apr 2018 19:16:16 -0400 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Apr 2018 19:16:15 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e18.ny.us.ibm.com (146.89.104.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Apr 2018 19:16:12 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3GNGCKQ43450472; Mon, 16 Apr 2018 23:16:12 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B2BD1B2050; Mon, 16 Apr 2018 20:18:16 -0400 (EDT) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.57]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id A6F65B204D; Mon, 16 Apr 2018 20:18:16 -0400 (EDT) From: Collin Walling To: libvir-list@redhat.com Date: Mon, 16 Apr 2018 19:16:07 -0400 In-Reply-To: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> References: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041623-0044-0000-0000-00000404E592 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008866; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018943; UDB=6.00519786; IPR=6.00798184; MB=3.00020604; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-16 23:16:13 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041623-0045-0000-0000-00000836E932 Message-Id: <1523920569-9386-3-git-send-email-walling@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-16_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804160192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 16 Apr 2018 23:16:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 16 Apr 2018 23:16:17 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'walling@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: cventeic@redhat.com Subject: [libvirt] [PATCH v1 2/4] cpu_conf: xml to cpu definition parse helper 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 16 Apr 2018 23:16:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Implement an xml to virCPUDefPtr helper that handles the ctxt prerequisite for virCPUDefParseXML. Signed-off-by: Collin Walling --- src/conf/cpu_conf.c | 30 ++++++++++++++++++++++++++++++ src/conf/cpu_conf.h | 6 ++++++ src/cpu/cpu.c | 14 +------------- src/libvirt_private.syms | 1 + 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 43a3ab5..b2e726a 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -250,6 +250,36 @@ virCPUDefCopy(const virCPUDef *cpu) } =20 =20 +int +virCPUDefParseXMLHelper(const char *xml, + const char *xpath, + virCPUType type, + virCPUDefPtr *cpu) +{ + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + int ret =3D -1; + + if (!xml) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definitio= n")); + goto cleanup; + } + + if (!(doc =3D virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)= )) + goto cleanup; + + if (virCPUDefParseXML(ctxt, xpath, type, cpu) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + xmlFreeDoc(doc); + xmlXPathFreeContext(ctxt); + return ret; +} + + /* * Parses CPU definition XML from a node pointed to by @xpath. If @xpath is * NULL, the current node of @ctxt is used (i.e., it is a shortcut to "."). diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 9f2e7ee..f8f57fa 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -184,6 +184,12 @@ virCPUDefPtr virCPUDefCopyWithoutModel(const virCPUDef *cpu); =20 int +virCPUDefParseXMLHelper(const char *xml, + const char *xpath, + virCPUType type, + virCPUDefPtr *cpu); + +int virCPUDefParseXML(xmlXPathContextPtr ctxt, const char *xpath, virCPUType mode, diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 047e3b1..8b829a3 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -114,31 +114,19 @@ virCPUCompareXML(virArch arch, const char *xml, bool failIncompatible) { - xmlDocPtr doc =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; virCPUDefPtr cpu =3D NULL; virCPUCompareResult ret =3D VIR_CPU_COMPARE_ERROR; =20 VIR_DEBUG("arch=3D%s, host=3D%p, xml=3D%s", virArchToString(arch), host, NULLSTR(xml)); =20 - if (!xml) { - virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definitio= n")); - goto cleanup; - } - - if (!(doc =3D virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)= )) - goto cleanup; - - if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu) < 0) + if (virCPUDefParseXMLHelper(xml, NULL, VIR_CPU_TYPE_AUTO, &cpu) < 0) goto cleanup; =20 ret =3D virCPUCompare(arch, host, cpu, failIncompatible); =20 cleanup: virCPUDefFree(cpu); - xmlXPathFreeContext(ctxt); - xmlFreeDoc(doc); =20 return ret; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cab324c..502fe48 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -86,6 +86,7 @@ virCPUDefIsEqual; virCPUDefListFree; virCPUDefListParse; virCPUDefParseXML; +virCPUDefParseXMLHelper; virCPUDefStealModel; virCPUDefUpdateFeature; virCPUModeTypeToString; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 22:28:50 2024 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=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523920617370985.7562095008327; Mon, 16 Apr 2018 16:16:57 -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 ADE815D68B; Mon, 16 Apr 2018 23:16:53 +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 85C3867EE7; Mon, 16 Apr 2018 23:16:53 +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 2AD494CA9C; Mon, 16 Apr 2018 23:16: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 w3GNGQJF008625 for ; Mon, 16 Apr 2018 19:16:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id E82D088301; Mon, 16 Apr 2018 23:16:26 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E11C960182 for ; Mon, 16 Apr 2018 23:16:21 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56D813142296 for ; Mon, 16 Apr 2018 23:16:20 +0000 (UTC) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3GNG3oa138850 for ; Mon, 16 Apr 2018 19:16:20 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hd3vb343c-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 16 Apr 2018 19:16:19 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Apr 2018 19:16:15 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Apr 2018 19:16:13 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3GNGDZc55378130; Mon, 16 Apr 2018 23:16:13 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFF8EB204E; Mon, 16 Apr 2018 20:18:17 -0400 (EDT) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.57]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id A9680B204D; Mon, 16 Apr 2018 20:18:17 -0400 (EDT) From: Collin Walling To: libvir-list@redhat.com Date: Mon, 16 Apr 2018 19:16:08 -0400 In-Reply-To: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> References: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041623-0040-0000-0000-0000041BE31E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008866; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018943; UDB=6.00519786; IPR=6.00798184; MB=3.00020604; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-16 23:16:15 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041623-0041-0000-0000-00000821E6EE Message-Id: <1523920569-9386-4-git-send-email-walling@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-16_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804160192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 16 Apr 2018 23:16:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 16 Apr 2018 23:16:20 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'walling@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: cventeic@redhat.com Subject: [libvirt] [PATCH v1 3/4] qemu: implement query-cpu-model-comparison via qemu 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.39]); Mon, 16 Apr 2018 23:16:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Interfaces with QEMU to compare two CPU models. The command takes two CPU models, A and B, that are given a model name and an optional list of CPU features. Through the query-cpu-model-comparison command sent to QEMU via QMP, a third CPU model, C, is returned that contains the comparison result (identical, superset, subset, incompatible) as its model name as well as a list of properties (aka CPU features) responsible for this result. Signed-off-by: Collin Walling --- src/qemu/qemu_capabilities.c | 53 ++++++++++++++++++ src/qemu/qemu_capabilities.h | 6 ++ src/qemu/qemu_monitor.c | 14 +++++ src/qemu/qemu_monitor.h | 6 ++ src/qemu/qemu_monitor_json.c | 128 +++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_monitor_json.h | 6 ++ 6 files changed, 213 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d2eb813..d385ad8 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -468,6 +468,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "virtio-tablet-ccw", "qcow2-luks", "pcie-pci-bridge", + "query-cpu-model-comparison", ); =20 =20 @@ -1030,6 +1031,7 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] = =3D { { "query-hotpluggable-cpus", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS }, { "query-qmp-schema", QEMU_CAPS_QUERY_QMP_SCHEMA }, { "query-cpu-model-expansion", QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION }, + { "query-cpu-model-comparison", QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON }, { "query-cpu-definitions", QEMU_CAPS_QUERY_CPU_DEFINITIONS }, { "query-named-block-nodes", QEMU_CAPS_QUERY_NAMED_BLOCK_NODES }, }; @@ -4930,3 +4932,54 @@ virQEMUCapsSetMicrocodeVersion(virQEMUCapsPtr qemuCa= ps, { qemuCaps->microcodeVersion =3D microcodeVersion; } + + +static virQEMUCapsInitQMPCommandPtr +virQEMUCapsSetupBinary(char *binary) +{ + virQEMUCapsInitQMPCommandPtr cmd; + char *qmperr =3D NULL; + + if (!(cmd =3D virQEMUCapsInitQMPCommandNew(binary, "/tmp", -1, -1, &qm= perr))) + goto cleanup; + + if (virQEMUCapsInitQMPCommandRun(cmd, false) !=3D 0) + goto cleanup; + + if (qemuMonitorSetCapabilities(cmd->mon) < 0) { + VIR_DEBUG("Failed to set monitor capabilities %s", + virGetLastErrorMessage()); + goto cleanup; + } + + return cmd; + + cleanup: + virQEMUCapsInitQMPCommandFree(cmd); + return NULL; +} + + +qemuMonitorCPUModelInfoPtr +virQEMUCapsProbeQMPCPUModelComparison(char *binary, + virCPUDefPtr cpuA, + virCPUDefPtr cpuB) +{ + virQEMUCapsInitQMPCommandPtr cmd; + qemuMonitorCPUModelInfoPtr cpuC =3D NULL; + qemuMonitorCPUModelInfoPtr ret =3D NULL; + + if (!(cmd =3D virQEMUCapsSetupBinary(binary))) + goto cleanup; + + if (qemuMonitorGetCPUModelComparison(cmd->mon, cpuA, cpuB, &cpuC) < 0) + goto cleanup; + + ret =3D cpuC; + cpuC =3D NULL; + + cleanup: + virQEMUCapsInitQMPCommandFree(cmd); + qemuMonitorCPUModelInfoFree(cpuC); + return ret; +} diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a959931..f27a359 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -452,6 +452,7 @@ typedef enum { QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW, /* -device virtio-tablet-ccw */ QEMU_CAPS_QCOW2_LUKS, /* qcow2 format support LUKS encryption */ QEMU_CAPS_DEVICE_PCIE_PCI_BRIDGE, /* -device pcie-pci-bridge */ + QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON, /* qmp query-cpu-model-compariso= n */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; @@ -578,4 +579,9 @@ bool virQEMUCapsGuestIsNative(virArch host, bool virQEMUCapsCPUFilterFeatures(const char *name, void *opaque); =20 +qemuMonitorCPUModelInfoPtr +virQEMUCapsProbeQMPCPUModelComparison(char *binary, + virCPUDefPtr cpuA, + virCPUDefPtr cpuB); + #endif /* __QEMU_CAPABILITIES_H__*/ diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 22f0522..1981b62 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3792,6 +3792,20 @@ qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoP= tr model_info) } =20 =20 +int +qemuMonitorGetCPUModelComparison(qemuMonitorPtr mon, + virCPUDefPtr cpuA, + virCPUDefPtr cpuB, + qemuMonitorCPUModelInfoPtr *cpuC) +{ + VIR_DEBUG("cpuA=3D%p cpuB=3D%p", cpuA, cpuB); + + QEMU_CHECK_MONITOR_JSON(mon); + + return qemuMonitorJSONGetCPUModelComparison(mon, cpuA, cpuB, cpuC); +} + + qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 9556a51..cc30184 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1072,6 +1072,12 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr m= on, =20 void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info); =20 +int +qemuMonitorGetCPUModelComparison(qemuMonitorPtr mon, + virCPUDefPtr modelA, + virCPUDefPtr modelB, + qemuMonitorCPUModelInfoPtr *cpuC); + qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 57c2c4d..c1759ec 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5466,6 +5466,134 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr = mon, } =20 =20 +static virJSONValuePtr +qemuMonitorJSONConvertCPUDefToJSON(virCPUDefPtr cpu) +{ + virJSONValuePtr value; + virJSONValuePtr feats =3D NULL; + size_t i; + + if (!(value =3D virJSONValueNewObject()) || + !(feats =3D virJSONValueNewObject())) + goto cleanup; + + if (virJSONValueObjectAppendString(value, "name", cpu->model) < 0) + goto cleanup; + + for (i =3D 0; i < cpu->nfeatures; i++) { + char *name =3D cpu->features[i].name; + bool enabled =3D false; + + if (cpu->type =3D=3D VIR_CPU_TYPE_HOST || + cpu->features[i].policy =3D=3D VIR_CPU_FEATURE_REQUIRE) + enabled =3D true; + + if (virJSONValueObjectAppendBoolean(feats, name, enabled) < 0) + goto cleanup; + } + + if (virJSONValueObjectAppend(value, "props", feats) < 0) + goto cleanup; + + return value; + + cleanup: + virJSONValueFree(value); + virJSONValueFree(feats); + return NULL; +} + + +static int +qemuMonitorJSONParseCPUModelPropName(size_t pos ATTRIBUTE_UNUSED, + virJSONValuePtr item, + void *opaque) +{ + return qemuMonitorJSONParseCPUModelProperty(virJSONValueGetString(item= ), + item, opaque); +} + + +int +qemuMonitorJSONGetCPUModelComparison(qemuMonitorPtr mon, + virCPUDefPtr modelA, + virCPUDefPtr modelB, + qemuMonitorCPUModelInfoPtr *cpuC) +{ + int ret =3D -1; + virJSONValuePtr modela; + virJSONValuePtr modelb =3D NULL; + virJSONValuePtr cmd =3D NULL; + virJSONValuePtr reply =3D NULL; + virJSONValuePtr data; + const char *result; + virJSONValuePtr props; + qemuMonitorCPUModelInfoPtr modelc =3D NULL; + + if (!(modela =3D qemuMonitorJSONConvertCPUDefToJSON(modelA)) || + !(modelb =3D qemuMonitorJSONConvertCPUDefToJSON(modelB))) + goto cleanup; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("query-cpu-model-comparison", + "a:modela", &modela, + "a:modelb", &modelb, + NULL))) + goto cleanup; + + /* Clean up of cmd will free the below virJSONValuePtrs */ + modela =3D NULL; + modelb =3D NULL; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + data =3D virJSONValueObjectGetObject(reply, "return"); + + if (!(result =3D virJSONValueObjectGetString(data, "result"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-cpu-model-expansion reply data was missing= " + "'result'")); + goto cleanup; + } + + if (!(props =3D virJSONValueObjectGetArray(data, "responsible-properti= es"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-cpu-model-expansion reply data was missing= " + "'responsible-properties'")); + goto cleanup; + } + + if (VIR_ALLOC(modelc) < 0) + goto cleanup; + + if (VIR_STRDUP(modelc->name, result) < 0) + goto cleanup; + + if (VIR_ALLOC_N(modelc->props, virJSONValueArraySize(props)) < 0) + goto cleanup; + + if (virJSONValueArrayForeachSteal(props, + qemuMonitorJSONParseCPUModelPropName, + modelc) < 0) + goto cleanup; + + ret =3D 0; + *cpuC =3D modelc; + modelc =3D NULL; + + cleanup: + qemuMonitorCPUModelInfoFree(modelc); + virJSONValueFree(cmd); + virJSONValueFree(reply); + virJSONValueFree(modela); + virJSONValueFree(modelb); + return ret; +} + + int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, char ***commands) { diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 045df49..ad9ae73 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -361,6 +361,12 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr= mon, qemuMonitorCPUModelInfoPtr *model_= info) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5); =20 +int qemuMonitorJSONGetCPUModelComparison(qemuMonitorPtr mon, + virCPUDefPtr modelA, + virCPUDefPtr modelB, + qemuMonitorCPUModelInfoPtr *cpuC) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); + int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, char ***commands) ATTRIBUTE_NONNULL(2); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 22:28:50 2024 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=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523920588866507.4943102620456; Mon, 16 Apr 2018 16:16:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D289326227A; Mon, 16 Apr 2018 23:16:26 +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 0C0876E412; Mon, 16 Apr 2018 23:16:26 +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 144FE180BAD3; Mon, 16 Apr 2018 23:16:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3GNGNPL008603 for ; Mon, 16 Apr 2018 19:16:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3F6C76E412; Mon, 16 Apr 2018 23:16:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38EFE7A41B for ; Mon, 16 Apr 2018 23:16:20 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50161C057F4E for ; Mon, 16 Apr 2018 23:16:19 +0000 (UTC) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3GN9Wqm099584 for ; Mon, 16 Apr 2018 19:16:18 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hd23gytr8-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 16 Apr 2018 19:16:18 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Apr 2018 19:16:17 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Apr 2018 19:16:14 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3GNGEte52035732; Mon, 16 Apr 2018 23:16:14 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC64FB2050; Mon, 16 Apr 2018 20:18:18 -0400 (EDT) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.57]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id B698AB204D; Mon, 16 Apr 2018 20:18:18 -0400 (EDT) From: Collin Walling To: libvir-list@redhat.com Date: Mon, 16 Apr 2018 19:16:09 -0400 In-Reply-To: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> References: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041623-2213-0000-0000-00000292B9E2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008866; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018943; UDB=6.00519786; IPR=6.00798184; MB=3.00020604; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-16 23:16:15 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041623-2214-0000-0000-000059C7CDF8 Message-Id: <1523920569-9386-5-git-send-email-walling@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-16_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804160192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 16 Apr 2018 23:16:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 16 Apr 2018 23:16:19 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'walling@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: cventeic@redhat.com Subject: [libvirt] [PATCH v1 4/4] qemu: hook up cpu-comparison to qemu driver 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 16 Apr 2018 23:16:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virsh cpu-compare command accepts an xml file that describes a cpu definition and compares it to a master xml file containing the host CPU. Not all architectures follow this procedure, and instead compare CPU's via QEMU. Let's hook up this capability to the QEMU driver and, if the capabilitiy is available, compare the host CPU with the CPU defined in the xml file. Signed-off-by: Collin Walling --- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_capabilities.h | 3 ++ src/qemu/qemu_driver.c | 96 ++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d385ad8..e4ce086 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -657,7 +657,7 @@ virQEMUCapsFindBinary(const char *format, return ret; } =20 -static char * +char * virQEMUCapsFindBinaryForArch(virArch hostarch, virArch guestarch) { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f27a359..01770f9 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -579,6 +579,9 @@ bool virQEMUCapsGuestIsNative(virArch host, bool virQEMUCapsCPUFilterFeatures(const char *name, void *opaque); =20 +char *virQEMUCapsFindBinaryForArch(virArch hostarch, + virArch guestarch); + qemuMonitorCPUModelInfoPtr virQEMUCapsProbeQMPCPUModelComparison(char *binary, virCPUDefPtr cpuA, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 92f5fe6..c87792b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13100,6 +13100,85 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) return ret; } =20 + +/** + * qemuCompareCPU: + * @binary: QEMU binary to issue the comparison command to + * @host: host CPU definition + * @xml: XML description of either guest or host CPU to be compared with @= host + * @failIncompatible: return an error instead of VIR_CPU_COMPARE_INCOMPATI= BLE + * + * Compares the target CPU described by @xml with @host CPU to produce a t= hird + * model containing the comparison result and the list of features respons= ible + * format the result. This function discards the responsible features. + * + * Compared model results: + * + * "incompatible": target cpu cannot run on @host. + * + * "subset": @host is an older cpu model than target, or @host does not + * support all features enabled on target. + * + * This result is considered incompatible. + * + * "identical": @host and target are identical; target can run on @host. + * + * "superset": @host is a newer cpu model than target, or @host supports = some + * features not supported by target; target can run on @host. + * + * Returns: virCPUCompareResult based on the produced "compared" model's n= ame, + * or VIR_CPU_COMPARE_ERROR upon error. + */ +static virCPUCompareResult +qemuCompareCPU(char *binary, + virCPUDefPtr hostCPU, + const char *xml, + bool failIncompatible) +{ + virCPUDefPtr targetCPU =3D NULL; + qemuMonitorCPUModelInfoPtr result =3D NULL; + virCPUCompareResult ret =3D VIR_CPU_COMPARE_ERROR; + + VIR_DEBUG("binary=3D%s, hostCPU=3D%p, xml=3D%s", binary, hostCPU, NULL= STR(xml)); + + if (!hostCPU || !hostCPU->model) { + if (failIncompatible) { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", + _("cannot get host CPU capabilities")); + } else { + VIR_WARN("cannot get host CPU capabilities"); + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + } + goto cleanup; + } + + if (virCPUDefParseXMLHelper(xml, NULL, VIR_CPU_TYPE_AUTO, &targetCPU) = < 0) + goto cleanup; + + if (!(result =3D virQEMUCapsProbeQMPCPUModelComparison(binary, hostCPU, + targetCPU))) + goto cleanup; + + if (STREQ(result->name, "incompatible") || + STREQ(result->name, "subset")) + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + else if (STREQ(result->name, "identical")) + ret =3D VIR_CPU_COMPARE_IDENTICAL; + else if (STREQ(result->name, "superset")) + ret =3D VIR_CPU_COMPARE_SUPERSET; + + if (failIncompatible && ret =3D=3D VIR_CPU_COMPARE_INCOMPATIBLE) { + ret =3D VIR_CPU_COMPARE_ERROR; + virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); + } + + cleanup: + virCPUDefFree(targetCPU); + qemuMonitorCPUModelInfoFree(result); + return ret; +} + + static int qemuConnectCompareCPU(virConnectPtr conn, const char *xmlDesc, @@ -13109,6 +13188,8 @@ qemuConnectCompareCPU(virConnectPtr conn, int ret =3D VIR_CPU_COMPARE_ERROR; virCapsPtr caps =3D NULL; bool failIncompatible; + char *binary =3D NULL; + virQEMUCapsPtr qemuCaps =3D NULL; =20 virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE, VIR_CPU_COMPARE_ERROR); @@ -13121,11 +13202,26 @@ qemuConnectCompareCPU(virConnectPtr conn, if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; =20 + binary =3D virQEMUCapsFindBinaryForArch(caps->host.arch, caps->host.ar= ch); + + if (binary) { + qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, binary); + + if (qemuCaps && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON)= ) { + ret =3D qemuCompareCPU(binary, caps->host.cpu, xmlDesc, + failIncompatible); + goto cleanup; + } + } + ret =3D virCPUCompareXML(caps->host.arch, caps->host.cpu, xmlDesc, failIncompatible); =20 cleanup: + VIR_FREE(binary); virObjectUnref(caps); + virObjectUnref(qemuCaps); return ret; } =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list