From nobody Wed May 14 06:06:11 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525542571632602.522738174779; Sat, 5 May 2018 10:49:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9001330C8097; Sat, 5 May 2018 17:49:24 +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 6504930012AA; Sat, 5 May 2018 17:49: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 297764CAAD; Sat, 5 May 2018 17:49:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w45Hmx1v004349 for ; Sat, 5 May 2018 13:48:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id A96A610848C; Sat, 5 May 2018 17:48:59 +0000 (UTC) Received: from cv1.home.network (ovpn-120-127.rdu2.redhat.com [10.10.120.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB3BC108486; Sat, 5 May 2018 17:48:58 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Sat, 5 May 2018 12:48:44 -0500 Message-Id: <20180505174849.31136-3-cventeic@redhat.com> In-Reply-To: <20180505174849.31136-1-cventeic@redhat.com> References: <20180505174849.31136-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv1 2/7] qemu_capabilities: CPUModelInfo: XML/QMP format conversion 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 05 May 2018 17:49:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Functions converting directly between virsh XML and QMEU QMP forms of CPUModelInfo. --- src/qemu/qemu_capabilities.c | 159 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 159 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 0265d83028..afce3eb2b7 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3341,6 +3341,165 @@ virQEMUCapsLoadCache(virArch hostArch, } =20 =20 +/* + * s390x + * z13-base + * + * ... + * + * + * + * returns 0, (*model), Success + * returns 0, !(*model), Content not found + * returns -1, !(*model), Failure + */ +static int +virQEMUCapsCPUModelInfoFromXML(xmlXPathContextPtr ctxt, + const char *xpath, + qemuMonitorCPUModelInfoPtr *model) +{ + size_t i; + int ret =3D -1; + qemuMonitorCPUModelInfoPtr cpuModel =3D NULL; + xmlNodePtr *nodes =3D NULL; + xmlNodePtr oldnode =3D ctxt->node; + + VIR_DEBUG("xpath =3D%s", NULLSTR(xpath)); + + *model =3D NULL; + + /* optional xpath query for cpu node with nonerror exit on miss */ + if (xpath && !(ctxt->node =3D virXPathNode(xpath, ctxt))) { + ret =3D 0; + goto cleanup; + } + + if (!virXMLNodeNameEqual(ctxt->node, "cpu")) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("XML does not contain expected 'cpu' element")); + goto cleanup; + } + + if (VIR_ALLOC(cpuModel) < 0) + goto cleanup; + + if (!(cpuModel->name =3D virXPathString("string(./model[1])", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing CPU model name"= )); + goto cleanup; + } + + cpuModel->nprops =3D virXPathNodeSet("./feature", ctxt, &nodes); + + if (VIR_ALLOC_N(cpuModel->props, cpuModel->nprops) < 0) + goto cleanup; + + for (i =3D 0; i < cpuModel->nprops; i++) { + qemuMonitorCPUPropertyPtr prop =3D &(cpuModel->props[i]); + + prop->type =3D QEMU_MONITOR_CPU_PROPERTY_BOOLEAN; + prop->value.boolean =3D true; + prop->migratable =3D VIR_TRISTATE_BOOL_ABSENT; + + if (!(prop->name =3D virXMLPropString(nodes[i], "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid CPU feature= name")); + goto cleanup; + } + } + + *model =3D qemuMonitorCPUModelInfoCopy(cpuModel); + + ret =3D 0; + + VIR_DEBUG("model->name =3D %s", NULLSTR((*model)->name)); + + cleanup: + ctxt->node =3D oldnode; + VIR_FREE(nodes); + qemuMonitorCPUModelInfoFree(cpuModel); + return ret; +} + + +/* + * returns 0, (*model), Success + * returns 0, !(*model), Content not found + * returns -1, !(*model), Failure + */ +static int +virQEMUCapsLoadCPUModelInfoFromXMLString(const char *xml, + const char *xpath, + qemuMonitorCPUModelInfoPtr *model) +{ + int ret =3D -1; + + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + + *model =3D NULL; + + VIR_DEBUG("input =3D %s", NULLSTR(xml)); + + if (!(doc =3D virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)= )) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definitio= n")); + goto cleanup; + } + + if (virQEMUCapsCPUModelInfoFromXML(ctxt, xpath, model) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("XML does not contain expected 'cpu' element")); + goto cleanup; + } + + ret =3D 0; + + cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); + + return ret; +} + + +/* + * z13-base + * + * + * + */ +static void +virQEMUCapsCPUModelInfoToXML(qemuMonitorCPUModelInfoPtr model, virBufferPt= r buf) +{ + size_t i; + + if (!model) + return; + + virBufferAddLit(buf, "\n"); + + virBufferAdjustIndent(buf, 2); + + virBufferAsprintf(buf, "%s\n", model->name); + + for (i =3D 0; i < model->nprops; i++) { + qemuMonitorCPUPropertyPtr prop =3D &(model->props[i]); + + virBufferAsprintf(buf, "\= n", + prop->name); + } + + virBufferAdjustIndent(buf, -2); + + virBufferAddLit(buf, "\n"); +} + + +/* + * + * + * ... + * + * + */ static void virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps, virBufferPtr buf, --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list