From nobody Thu Apr 25 08:23:32 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=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 152646001766044.33352766921428; Wed, 16 May 2018 01:40:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F62C114702; Wed, 16 May 2018 08:40:14 +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 0D80017B3D; Wed, 16 May 2018 08:40:14 +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 93A113FA5B; Wed, 16 May 2018 08:40:13 +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 w4G8dk4Z018386 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 52B3BD1EA7; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAC83D1EB5 for ; Wed, 16 May 2018 08:39:43 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A26DF102ED8; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:20 +0200 Message-Id: <85251ff539ac77deaddf6376d89a7c32b377630a.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/22] virsh: Move cpu-{baseline, compare} commands 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 16 May 2018 08:40:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similarly to cpu-models these two commands do not operate on a domain and should be listed in the "Host and Hypervisor" commands section. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-domain.c | 223 ------------------------------------------ tools/virsh-host.c | 224 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 224 insertions(+), 223 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 30da953446..3bb894a425 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7672,217 +7672,6 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) return ret; } =20 -/* - * "cpu-compare" command - */ -static const vshCmdInfo info_cpu_compare[] =3D { - {.name =3D "help", - .data =3D N_("compare host CPU with a CPU described by an XML file") - }, - {.name =3D "desc", - .data =3D N_("compare CPU with host CPU") - }, - {.name =3D NULL} -}; - -static const vshCmdOptDef opts_cpu_compare[] =3D { - VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")), - {.name =3D "error", - .type =3D VSH_OT_BOOL, - .help =3D N_("report error if CPUs are incompatible") - }, - {.name =3D NULL} -}; - -static bool -cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) -{ - const char *from =3D NULL; - bool ret =3D false; - char *buffer; - int result; - char *snippet =3D NULL; - unsigned int flags =3D 0; - xmlDocPtr xml =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; - xmlNodePtr node; - virshControlPtr priv =3D ctl->privData; - - if (vshCommandOptBool(cmd, "error")) - flags |=3D VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE; - - if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - return false; - - if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) - return false; - - /* try to extract the CPU element from as it would appear in a domain = XML*/ - if (!(xml =3D virXMLParseStringCtxt(buffer, from, &ctxt))) - goto cleanup; - - if ((node =3D virXPathNode("/cpu|" - "/domain/cpu|" - "/capabilities/host/cpu", ctxt))) { - if (!(snippet =3D virXMLNodeToString(xml, node))) { - vshSaveLibvirtError(); - goto cleanup; - } - } else { - vshError(ctl, _("File '%s' does not contain a element or is = not " - "a valid domain or capabilities XML"), from); - goto cleanup; - } - - result =3D virConnectCompareCPU(priv->conn, snippet, flags); - - switch (result) { - case VIR_CPU_COMPARE_INCOMPATIBLE: - vshPrint(ctl, _("CPU described in %s is incompatible with host CPU= \n"), - from); - goto cleanup; - break; - - case VIR_CPU_COMPARE_IDENTICAL: - vshPrint(ctl, _("CPU described in %s is identical to host CPU\n"), - from); - break; - - case VIR_CPU_COMPARE_SUPERSET: - vshPrint(ctl, _("Host CPU is a superset of CPU described in %s\n"), - from); - break; - - case VIR_CPU_COMPARE_ERROR: - default: - vshError(ctl, _("Failed to compare host CPU with %s"), from); - goto cleanup; - } - - ret =3D true; - - cleanup: - VIR_FREE(buffer); - VIR_FREE(snippet); - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); - - return ret; -} - -/* - * "cpu-baseline" command - */ -static const vshCmdInfo info_cpu_baseline[] =3D { - {.name =3D "help", - .data =3D N_("compute baseline CPU") - }, - {.name =3D "desc", - .data =3D N_("Compute baseline CPU for a set of given CPUs.") - }, - {.name =3D NULL} -}; - -static const vshCmdOptDef opts_cpu_baseline[] =3D { - VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")), - {.name =3D "features", - .type =3D VSH_OT_BOOL, - .help =3D N_("Show features that are part of the CPU model type") - }, - {.name =3D "migratable", - .type =3D VSH_OT_BOOL, - .help =3D N_("Do not include features that block migration") - }, - {.name =3D NULL} -}; - -static bool -cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) -{ - const char *from =3D NULL; - bool ret =3D false; - char *buffer; - char *result =3D NULL; - char **list =3D NULL; - unsigned int flags =3D 0; - int count =3D 0; - - xmlDocPtr xml =3D NULL; - xmlNodePtr *node_list =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - size_t i; - virshControlPtr priv =3D ctl->privData; - - if (vshCommandOptBool(cmd, "features")) - flags |=3D VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; - if (vshCommandOptBool(cmd, "migratable")) - flags |=3D VIR_CONNECT_BASELINE_CPU_MIGRATABLE; - - if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - return false; - - if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) - return false; - - /* add a separate container around the xml */ - virBufferStrcat(&buf, "", buffer, "", NULL); - if (virBufferError(&buf)) - goto no_memory; - - VIR_FREE(buffer); - buffer =3D virBufferContentAndReset(&buf); - - - if (!(xml =3D virXMLParseStringCtxt(buffer, from, &ctxt))) - goto cleanup; - - if ((count =3D virXPathNodeSet("//cpu[not(ancestor::cpus)]", - ctxt, &node_list)) =3D=3D -1) - goto cleanup; - - if (count =3D=3D 0) { - vshError(ctl, _("No host CPU specified in '%s'"), from); - goto cleanup; - } - - list =3D vshCalloc(ctl, count, sizeof(const char *)); - - for (i =3D 0; i < count; i++) { - if (!(list[i] =3D virXMLNodeToString(xml, node_list[i]))) { - vshSaveLibvirtError(); - goto cleanup; - } - } - - result =3D virConnectBaselineCPU(priv->conn, - (const char **)list, count, flags); - - if (result) { - vshPrint(ctl, "%s", result); - ret =3D true; - } - - cleanup: - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); - VIR_FREE(result); - if (list !=3D NULL && count > 0) { - for (i =3D 0; i < count; i++) - VIR_FREE(list[i]); - } - VIR_FREE(list); - VIR_FREE(buffer); - VIR_FREE(node_list); - - return ret; - - no_memory: - vshError(ctl, "%s", _("Out of memory")); - ret =3D false; - goto cleanup; -} - /* * "cpu-stats" command */ @@ -13942,18 +13731,6 @@ const vshCmdDef domManagementCmds[] =3D { .flags =3D 0 }, #endif - {.name =3D "cpu-baseline", - .handler =3D cmdCPUBaseline, - .opts =3D opts_cpu_baseline, - .info =3D info_cpu_baseline, - .flags =3D 0 - }, - {.name =3D "cpu-compare", - .handler =3D cmdCPUCompare, - .opts =3D opts_cpu_compare, - .info =3D info_cpu_compare, - .flags =3D 0 - }, {.name =3D "cpu-stats", .handler =3D cmdCPUStats, .opts =3D opts_cpu_stats, diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ecaf830e35..6d6e3cfc85 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -38,6 +38,7 @@ #include "virxml.h" #include "virtypedparam.h" #include "virstring.h" +#include "virfile.h" =20 /* * "capabilities" command @@ -1105,6 +1106,217 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE= _UNUSED) return true; } =20 +/* + * "cpu-compare" command + */ +static const vshCmdInfo info_cpu_compare[] =3D { + {.name =3D "help", + .data =3D N_("compare host CPU with a CPU described by an XML file") + }, + {.name =3D "desc", + .data =3D N_("compare CPU with host CPU") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_cpu_compare[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")), + {.name =3D "error", + .type =3D VSH_OT_BOOL, + .help =3D N_("report error if CPUs are incompatible") + }, + {.name =3D NULL} +}; + +static bool +cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) +{ + const char *from =3D NULL; + bool ret =3D false; + char *buffer; + int result; + char *snippet =3D NULL; + unsigned int flags =3D 0; + xmlDocPtr xml =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + xmlNodePtr node; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptBool(cmd, "error")) + flags |=3D VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + return false; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + return false; + + /* try to extract the CPU element from as it would appear in a domain = XML*/ + if (!(xml =3D virXMLParseStringCtxt(buffer, from, &ctxt))) + goto cleanup; + + if ((node =3D virXPathNode("/cpu|" + "/domain/cpu|" + "/capabilities/host/cpu", ctxt))) { + if (!(snippet =3D virXMLNodeToString(xml, node))) { + vshSaveLibvirtError(); + goto cleanup; + } + } else { + vshError(ctl, _("File '%s' does not contain a element or is = not " + "a valid domain or capabilities XML"), from); + goto cleanup; + } + + result =3D virConnectCompareCPU(priv->conn, snippet, flags); + + switch (result) { + case VIR_CPU_COMPARE_INCOMPATIBLE: + vshPrint(ctl, _("CPU described in %s is incompatible with host CPU= \n"), + from); + goto cleanup; + break; + + case VIR_CPU_COMPARE_IDENTICAL: + vshPrint(ctl, _("CPU described in %s is identical to host CPU\n"), + from); + break; + + case VIR_CPU_COMPARE_SUPERSET: + vshPrint(ctl, _("Host CPU is a superset of CPU described in %s\n"), + from); + break; + + case VIR_CPU_COMPARE_ERROR: + default: + vshError(ctl, _("Failed to compare host CPU with %s"), from); + goto cleanup; + } + + ret =3D true; + + cleanup: + VIR_FREE(buffer); + VIR_FREE(snippet); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + + return ret; +} + +/* + * "cpu-baseline" command + */ +static const vshCmdInfo info_cpu_baseline[] =3D { + {.name =3D "help", + .data =3D N_("compute baseline CPU") + }, + {.name =3D "desc", + .data =3D N_("Compute baseline CPU for a set of given CPUs.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_cpu_baseline[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")), + {.name =3D "features", + .type =3D VSH_OT_BOOL, + .help =3D N_("Show features that are part of the CPU model type") + }, + {.name =3D "migratable", + .type =3D VSH_OT_BOOL, + .help =3D N_("Do not include features that block migration") + }, + {.name =3D NULL} +}; + +static bool +cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) +{ + const char *from =3D NULL; + bool ret =3D false; + char *buffer; + char *result =3D NULL; + char **list =3D NULL; + unsigned int flags =3D 0; + int count =3D 0; + + xmlDocPtr xml =3D NULL; + xmlNodePtr *node_list =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + size_t i; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptBool(cmd, "features")) + flags |=3D VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; + if (vshCommandOptBool(cmd, "migratable")) + flags |=3D VIR_CONNECT_BASELINE_CPU_MIGRATABLE; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + return false; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + return false; + + /* add a separate container around the xml */ + virBufferStrcat(&buf, "", buffer, "", NULL); + if (virBufferError(&buf)) + goto no_memory; + + VIR_FREE(buffer); + buffer =3D virBufferContentAndReset(&buf); + + + if (!(xml =3D virXMLParseStringCtxt(buffer, from, &ctxt))) + goto cleanup; + + if ((count =3D virXPathNodeSet("//cpu[not(ancestor::cpus)]", + ctxt, &node_list)) =3D=3D -1) + goto cleanup; + + if (count =3D=3D 0) { + vshError(ctl, _("No host CPU specified in '%s'"), from); + goto cleanup; + } + + list =3D vshCalloc(ctl, count, sizeof(const char *)); + + for (i =3D 0; i < count; i++) { + if (!(list[i] =3D virXMLNodeToString(xml, node_list[i]))) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + result =3D virConnectBaselineCPU(priv->conn, + (const char **)list, count, flags); + + if (result) { + vshPrint(ctl, "%s", result); + ret =3D true; + } + + cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(result); + if (list !=3D NULL && count > 0) { + for (i =3D 0; i < count; i++) + VIR_FREE(list[i]); + } + VIR_FREE(list); + VIR_FREE(buffer); + VIR_FREE(node_list); + + return ret; + + no_memory: + vshError(ctl, "%s", _("Out of memory")); + ret =3D false; + goto cleanup; +} + /* * "cpu-models" command */ @@ -1388,6 +1600,18 @@ const vshCmdDef hostAndHypervisorCmds[] =3D { .info =3D info_capabilities, .flags =3D 0 }, + {.name =3D "cpu-baseline", + .handler =3D cmdCPUBaseline, + .opts =3D opts_cpu_baseline, + .info =3D info_cpu_baseline, + .flags =3D 0 + }, + {.name =3D "cpu-compare", + .handler =3D cmdCPUCompare, + .opts =3D opts_cpu_compare, + .info =3D info_cpu_compare, + .flags =3D 0 + }, {.name =3D "cpu-models", .handler =3D cmdCPUModelNames, .opts =3D opts_cpu_models, --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526459995422344.96718727844484; Wed, 16 May 2018 01:39:55 -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 B5C4D3115852; Wed, 16 May 2018 08:39:53 +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 6BF95600C9; Wed, 16 May 2018 08:39: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 ED5F9180B536; Wed, 16 May 2018 08:39:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8diFV018328 for ; Wed, 16 May 2018 04:39:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2183200BC1E; Wed, 16 May 2018 08:39:43 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A46142026E0E for ; Wed, 16 May 2018 08:39:43 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A43F3102EDB; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:21 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/22] virsh: Extract common code from cmdCPU{Compare, Baseline} 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.47]); Wed, 16 May 2018 08:39:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Both cpu-compare and cpu-baseline commands accept more that just CPU definition XML(s). For users' convenience they are able to extract the CPU definition(s) even from domain XML or capabilities XML. The main differences between the two commands is in the number of CPU definitions they expect: cpu-compare wants only one CPU definition while cpu-baseline expects one or more CPUs. The extracted code forms a new vshExtractCPUDefXML function. Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-host.c | 160 +++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 85 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 6d6e3cfc85..51497db385 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1106,6 +1106,72 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_= UNUSED) return true; } =20 + +/* Extracts the CPU definition XML strings from a file which may contain e= ither + * - just the CPU definitions, + * - domain XMLs, or + * - capabilities XMLs. + * + * Returns NULL terminated string list. + */ +static char ** +vshExtractCPUDefXMLs(vshControl *ctl, + const char *xmlFile) +{ + char **cpus =3D NULL; + char *buffer =3D NULL; + char *xmlStr =3D NULL; + xmlDocPtr xml =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + + if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0) + goto error; + + if (virAsprintf(&xmlStr, "%s", buffer) < 0) + goto error; + + if (!(xml =3D virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt))) + goto error; + + n =3D virXPathNodeSet("/container/cpu|" + "/container/domain/cpu|" + "/container/capabilities/host/cpu", + ctxt, &nodes); + if (n < 0) + goto error; + + if (n =3D=3D 0) { + vshError(ctl, _("File '%s' does not contain any element or " + "valid domain or capabilities XML"), xmlFile); + goto error; + } + + cpus =3D vshCalloc(ctl, n + 1, sizeof(const char *)); + + for (i =3D 0; i < n; i++) { + if (!(cpus[i] =3D virXMLNodeToString(xml, nodes[i]))) { + vshSaveLibvirtError(); + goto error; + } + } + + cleanup: + VIR_FREE(buffer); + VIR_FREE(xmlStr); + xmlFreeDoc(xml); + xmlXPathFreeContext(ctxt); + VIR_FREE(nodes); + return cpus; + + error: + virStringListFree(cpus); + goto cleanup; +} + + /* * "cpu-compare" command */ @@ -1133,13 +1199,9 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) { const char *from =3D NULL; bool ret =3D false; - char *buffer; int result; - char *snippet =3D NULL; + char **cpus =3D NULL; unsigned int flags =3D 0; - xmlDocPtr xml =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; - xmlNodePtr node; virshControlPtr priv =3D ctl->privData; =20 if (vshCommandOptBool(cmd, "error")) @@ -1148,27 +1210,10 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; =20 - if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + if (!(cpus =3D vshExtractCPUDefXMLs(ctl, from))) return false; =20 - /* try to extract the CPU element from as it would appear in a domain = XML*/ - if (!(xml =3D virXMLParseStringCtxt(buffer, from, &ctxt))) - goto cleanup; - - if ((node =3D virXPathNode("/cpu|" - "/domain/cpu|" - "/capabilities/host/cpu", ctxt))) { - if (!(snippet =3D virXMLNodeToString(xml, node))) { - vshSaveLibvirtError(); - goto cleanup; - } - } else { - vshError(ctl, _("File '%s' does not contain a element or is = not " - "a valid domain or capabilities XML"), from); - goto cleanup; - } - - result =3D virConnectCompareCPU(priv->conn, snippet, flags); + result =3D virConnectCompareCPU(priv->conn, cpus[0], flags); =20 switch (result) { case VIR_CPU_COMPARE_INCOMPATIBLE: @@ -1196,10 +1241,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - VIR_FREE(buffer); - VIR_FREE(snippet); - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); + virStringListFree(cpus); =20 return ret; } @@ -1235,17 +1277,9 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) { const char *from =3D NULL; bool ret =3D false; - char *buffer; char *result =3D NULL; char **list =3D NULL; unsigned int flags =3D 0; - int count =3D 0; - - xmlDocPtr xml =3D NULL; - xmlNodePtr *node_list =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - size_t i; virshControlPtr priv =3D ctl->privData; =20 if (vshCommandOptBool(cmd, "features")) @@ -1256,65 +1290,21 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; =20 - if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + if (!(list =3D vshExtractCPUDefXMLs(ctl, from))) return false; =20 - /* add a separate container around the xml */ - virBufferStrcat(&buf, "", buffer, "", NULL); - if (virBufferError(&buf)) - goto no_memory; - - VIR_FREE(buffer); - buffer =3D virBufferContentAndReset(&buf); - - - if (!(xml =3D virXMLParseStringCtxt(buffer, from, &ctxt))) - goto cleanup; - - if ((count =3D virXPathNodeSet("//cpu[not(ancestor::cpus)]", - ctxt, &node_list)) =3D=3D -1) - goto cleanup; - - if (count =3D=3D 0) { - vshError(ctl, _("No host CPU specified in '%s'"), from); - goto cleanup; - } - - list =3D vshCalloc(ctl, count, sizeof(const char *)); - - for (i =3D 0; i < count; i++) { - if (!(list[i] =3D virXMLNodeToString(xml, node_list[i]))) { - vshSaveLibvirtError(); - goto cleanup; - } - } - - result =3D virConnectBaselineCPU(priv->conn, - (const char **)list, count, flags); + result =3D virConnectBaselineCPU(priv->conn, (const char **)list, + virStringListLength((const char **)list= ), + flags); =20 if (result) { vshPrint(ctl, "%s", result); ret =3D true; } =20 - cleanup: - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); VIR_FREE(result); - if (list !=3D NULL && count > 0) { - for (i =3D 0; i < count; i++) - VIR_FREE(list[i]); - } - VIR_FREE(list); - VIR_FREE(buffer); - VIR_FREE(node_list); - + virStringListFree(list); return ret; - - no_memory: - vshError(ctl, "%s", _("Out of memory")); - ret =3D false; - goto cleanup; } =20 /* --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526459988887519.0758884399961; Wed, 16 May 2018 01:39:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 294816A59A; Wed, 16 May 2018 08:39:47 +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 D6F3217577; Wed, 16 May 2018 08:39:46 +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 71224180B536; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dh0Q018324 for ; Wed, 16 May 2018 04:39:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id C136C10EE6DD; Wed, 16 May 2018 08:39:43 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A07F510EE6D6 for ; Wed, 16 May 2018 08:39:43 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A692A102EDC; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:22 +0200 Message-Id: <152b37414ec79e62d4edf99e8d85b89553d4cfa8.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/22] virsh: Enhance documentation of cpu-compare command 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 16 May 2018 08:39:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko Reviewed-by: Kashyap Chamarthy --- tools/virsh.pod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 929958a953..5f72e11dec 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -589,7 +589,9 @@ Compare CPU definition from XML with host CPU. T= he XML may contain either host or guest CPU definition. The host CPU definition is the element and its contents as printed by B command. The guest CPU definition is the element and its contents from domain XML -definition. For more information on guest CPU definition see: +definition. In addition to the element itself, this command accepts +full domain or capabilities XML containing the element. For more +information on guest CPU definition see: L. If I<--error> is specified, the command will return an error when the given CPU is incompatible with host CPU and a message providing more details about the --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460001328350.45065907849755; Wed, 16 May 2018 01:40:01 -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 CAFB230D03BA; Wed, 16 May 2018 08:39:58 +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 6EC526090C; Wed, 16 May 2018 08:39:58 +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 83768180B5B4; Wed, 16 May 2018 08:39:57 +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 w4G8djv1018370 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id B7225AFD62; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95EB46B59E for ; Wed, 16 May 2018 08:39:43 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A9459102EDD; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:23 +0200 Message-Id: <6c6453691b01bdaaccf29acc9322b993a765252f.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/22] virsh: Enhance documentation of cpu-models command 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.44]); Wed, 16 May 2018 08:40:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko Reviewed-by: Kashyap Chamarthy --- tools/virsh.pod | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 5f72e11dec..5fc8201893 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -599,7 +599,13 @@ incompatibility will be printed out. =20 =3Ditem B I =20 -Print the list of CPU models known for the specified architecture. +Print the list of CPU models known by libvirt for the specified architectu= re. +Whether a specific hypervisor is able to create a domain which uses any of +the printed CPU models is a separate question which can be answered by +looking the domain capabilities XML returned by B command. +Moreover, for some architectures libvirt does not know any CPU models and +the usable CPU models are only limited by the hypervisor. This command will +print that all CPU models are accepted for these architectures. =20 =3Ditem B [I<--shell>] [I<--xml>] [I...] =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526459992897769.3073356877959; Wed, 16 May 2018 01:39:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70ED030C021B; Wed, 16 May 2018 08:39:51 +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 DCBB91778D; Wed, 16 May 2018 08:39:50 +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 82B474CAA8; Wed, 16 May 2018 08:39:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djfT018342 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id EB06610AF9D9; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9DF110EE6DD for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id AB83B102EDE; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:24 +0200 Message-Id: <5acb02a8ef017f709e5887ce637d3c1b5fafaa96.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/22] Improve documentation of virConnectGetCPUModelNames 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 16 May 2018 08:39:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko Reviewed-by: Kashyap Chamarthy --- src/libvirt-host.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libvirt-host.c b/src/libvirt-host.c index 76087badd8..ed689b9ec2 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -1003,7 +1003,13 @@ virConnectCompareCPU(virConnectPtr conn, * NULL if only the list length is needed. * @flags: extra flags; not used yet, so callers should always pass 0. * - * Get the list of supported CPU models for a specific architecture. + * Get the list of CPU models supported by libvirt for a specific architec= ture. + * + * The returned list limits CPU models usable with libvirt (empty list mea= ns, + * there's no limit imposed by libvirt) and it does not reflect capabaliti= es of + * any hypervisor. See the XML returned by virConnectGetDomainCapabilities= () + * for a list of CPU models supported by libvirt for domains created on a + * specific hypervisor. * * Returns -1 on error, number of elements in @models on success (0 means * libvirt accepts any CPU model). --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460010149308.2573282148617; Wed, 16 May 2018 01:40:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43A643117B59; Wed, 16 May 2018 08:40:08 +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 F04F29935B; Wed, 16 May 2018 08:40:07 +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 8EEE3180B5B3; Wed, 16 May 2018 08:40:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djUg018344 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13BCF2017D0D; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA5E22024CBB for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id AE089102EDF; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:25 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/22] vshExtractCPUDefXML: Accept domain capabilities XML 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 16 May 2018 08:40:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The domain capabilities XML contains host CPU model tailored to a specific hypervisor and since it's enclosed in element rather then the required it's impossible to directly use the host CPU model as an input to, e.g., cpu-compare command. To make this more convenient, vshExtractCPUDefXML now accepts full domain capabilities XML and automatically transforms the host CPU models into the form accepted by libvirt APIs. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-host.c | 26 ++++++++++++++++++++++---- tools/virsh.pod | 8 +++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 51497db385..ea2c411c02 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1109,8 +1109,9 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_U= NUSED) =20 /* Extracts the CPU definition XML strings from a file which may contain e= ither * - just the CPU definitions, - * - domain XMLs, or - * - capabilities XMLs. + * - domain XMLs, + * - capabilities XMLs, or + * - domain capabilities XMLs. * * Returns NULL terminated string list. */ @@ -1138,20 +1139,37 @@ vshExtractCPUDefXMLs(vshControl *ctl, =20 n =3D virXPathNodeSet("/container/cpu|" "/container/domain/cpu|" - "/container/capabilities/host/cpu", + "/container/capabilities/host/cpu|" + "/container/domainCapabilities/cpu/" + "mode[@name=3D'host-model' and @supported=3D'y= es']", ctxt, &nodes); if (n < 0) goto error; =20 if (n =3D=3D 0) { vshError(ctl, _("File '%s' does not contain any element or " - "valid domain or capabilities XML"), xmlFile); + "valid domain XML, host capabilities XML, or " + "domain capabilities XML"), xmlFile); goto error; } =20 cpus =3D vshCalloc(ctl, n + 1, sizeof(const char *)); =20 for (i =3D 0; i < n; i++) { + /* If the user provided domain capabilities XML, we need to replace + * element with . */ + if (xmlStrEqual(nodes[i]->name, BAD_CAST "mode")) { + xmlNodeSetName(nodes[i], (const xmlChar *)"cpu"); + while (nodes[i]->properties) { + if (xmlRemoveProp(nodes[i]->properties) < 0) { + vshError(ctl, + _("Cannot extract CPU definition from domain " + "capabilities XML")); + goto error; + } + } + } + if (!(cpus[i] =3D virXMLNodeToString(xml, nodes[i]))) { vshSaveLibvirtError(); goto error; diff --git a/tools/virsh.pod b/tools/virsh.pod index 5fc8201893..ea10e1ad43 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -589,9 +589,11 @@ Compare CPU definition from XML with host CPU. = The XML may contain either host or guest CPU definition. The host CPU definition is the element and its contents as printed by B command. The guest CPU definition is the element and its contents from domain XML -definition. In addition to the element itself, this command accepts -full domain or capabilities XML containing the element. For more -information on guest CPU definition see: +definition or the CPU definition created from the host CPU model found in +domain capabilities XML (printed by B command). In +addition to the element itself, this command accepts +full domain XML, capabilities XML, or domain capabilities XML containing +the CPU definition. For more information on guest CPU definition see: L. If I<--error> is specified, the command will return an error when the given CPU is incompatible with host CPU and a message providing more details about the --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460002639485.4223875027146; Wed, 16 May 2018 01:40:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 545DE30D24E2; Wed, 16 May 2018 08:40:00 +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 15FB698F7E; Wed, 16 May 2018 08:40:00 +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 B4E6EEEF7; Wed, 16 May 2018 08:39:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djhP018343 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1365B10AF9F6; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9CE910EE6D6 for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B0316102EE1; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:26 +0200 Message-Id: <8c7f8789ef1dee72378c4c1f3af062d05bac9bad.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/22] qemu_capabilities: Introduce virQEMUCapsCacheLookupDefault 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 16 May 2018 08:40:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virConnectGetDomainCapabilities needs to lookup QEMU capabilities matching a specified binary, architecture, virt type, and machine type while using default values when any of the parameters are not provided by the user. Let's extract the lookup code into virQEMUCapsCacheLookupDefault to make it reusable. Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_capabilities.c | 118 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 8 +++ src/qemu/qemu_driver.c | 86 ++++--------------------- 3 files changed, 137 insertions(+), 75 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a5cb24fec6..77a4b4154e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4546,6 +4546,124 @@ virQEMUCapsCacheLookupByArch(virFileCachePtr cache, } =20 =20 +/** + * virQEMUCapsCacheLookupDefault: + * @cache: QEMU capabilities cache + * @binary: optional path to QEMU binary + * @archStr: optional guest architecture + * @virttypeStr: optional virt type + * @machine: optional machine type + * @retArch: if non-NULL, guest architecture will be returned here + * @retVirttype: if non-NULL, domain virt type will be returned here + * @retMachine: if non-NULL, canonical machine type will be returned here + * + * Looks up the QEMU binary specified by @binary and @archStr, checks it c= an + * provide the required @virttypeStr and @machine and returns its capabili= ties. + * Sensible defaults are used for any argument which is NULL (the function= can + * even be called with all NULL arguments). + * + * Returns QEMU capabilities matching the requirements, NULL on error. + */ +virQEMUCapsPtr +virQEMUCapsCacheLookupDefault(virFileCachePtr cache, + const char *binary, + const char *archStr, + const char *virttypeStr, + const char *machine, + virArch *retArch, + virDomainVirtType *retVirttype, + const char **retMachine) +{ + int virttype =3D VIR_DOMAIN_VIRT_NONE; + int arch =3D virArchFromHost(); + virDomainVirtType capsType; + virQEMUCapsPtr qemuCaps =3D NULL; + virQEMUCapsPtr ret =3D NULL; + + if (virttypeStr && + (virttype =3D virDomainVirtTypeFromString(virttypeStr)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown virttype: %s"), virttypeStr); + goto cleanup; + } + + if (archStr && + (arch =3D virArchFromString(archStr)) =3D=3D VIR_ARCH_NONE) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown architecture: %s"), archStr); + goto cleanup; + } + + if (binary) { + virArch arch_from_caps; + + if (!(qemuCaps =3D virQEMUCapsCacheLookup(cache, binary))) + goto cleanup; + + arch_from_caps =3D virQEMUCapsGetArch(qemuCaps); + + if (arch_from_caps !=3D arch && + !((ARCH_IS_X86(arch) && ARCH_IS_X86(arch_from_caps)) || + (ARCH_IS_PPC(arch) && ARCH_IS_PPC(arch_from_caps)) || + (ARCH_IS_ARM(arch) && ARCH_IS_ARM(arch_from_caps)) || + (ARCH_IS_S390(arch) && ARCH_IS_S390(arch_from_caps)))) { + virReportError(VIR_ERR_INVALID_ARG, + _("architecture from emulator '%s' doesn't " + "match given architecture '%s'"), + virArchToString(arch_from_caps), + virArchToString(arch)); + goto cleanup; + } + } else { + if (!(qemuCaps =3D virQEMUCapsCacheLookupByArch(cache, arch))) + goto cleanup; + + binary =3D virQEMUCapsGetBinary(qemuCaps); + } + + if (machine) { + /* Turn @machine into canonical name */ + machine =3D virQEMUCapsGetCanonicalMachine(qemuCaps, machine); + + if (!virQEMUCapsIsMachineSupported(qemuCaps, machine)) { + virReportError(VIR_ERR_INVALID_ARG, + _("the machine '%s' is not supported by emulato= r '%s'"), + machine, binary); + goto cleanup; + } + } else { + machine =3D virQEMUCapsGetDefaultMachine(qemuCaps); + } + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) + capsType =3D VIR_DOMAIN_VIRT_KVM; + else + capsType =3D VIR_DOMAIN_VIRT_QEMU; + + if (virttype =3D=3D VIR_DOMAIN_VIRT_NONE) + virttype =3D capsType; + + if (virttype =3D=3D VIR_DOMAIN_VIRT_KVM && capsType =3D=3D VIR_DOMAIN_= VIRT_QEMU) { + virReportError(VIR_ERR_INVALID_ARG, + _("KVM is not supported by '%s' on this host"), + binary); + goto cleanup; + } + + if (retArch) + *retArch =3D arch; + if (retVirttype) + *retVirttype =3D virttype; + if (retMachine) + *retMachine =3D machine; + + VIR_STEAL_PTR(ret, qemuCaps); + + cleanup: + virObjectUnref(qemuCaps); + return ret; +} + bool virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps, const virDomainDef *def) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index d23c34c24d..6f095bfbfe 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -559,6 +559,14 @@ virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCache= Ptr cache, const char *machineType); virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virFileCachePtr cache, virArch arch); +virQEMUCapsPtr virQEMUCapsCacheLookupDefault(virFileCachePtr cache, + const char *binary, + const char *archStr, + const char *virttypeStr, + const char *machine, + virArch *retArch, + virDomainVirtType *retVirttyp= e, + const char **retMachine); =20 virCapsPtr virQEMUCapsInit(virFileCachePtr cache); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9037818e2a..6c086b9ef8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19249,10 +19249,9 @@ qemuConnectGetDomainCapabilities(virConnectPtr con= n, char *ret =3D NULL; virQEMUDriverPtr driver =3D conn->privateData; virQEMUCapsPtr qemuCaps =3D NULL; - int virttype =3D VIR_DOMAIN_VIRT_NONE; - virDomainVirtType capsType; + virArch arch; + virDomainVirtType virttype; virDomainCapsPtr domCaps =3D NULL; - int arch =3D virArchFromHost(); /* virArch */ virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; =20 @@ -19266,80 +19265,17 @@ qemuConnectGetDomainCapabilities(virConnectPtr co= nn, if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; =20 - if (virttype_str && - (virttype =3D virDomainVirtTypeFromString(virttype_str)) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown virttype: %s"), - virttype_str); + qemuCaps =3D virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, + emulatorbin, + arch_str, + virttype_str, + machine, + &arch, &virttype, &machine); + if (!qemuCaps) goto cleanup; - } =20 - if (arch_str && (arch =3D virArchFromString(arch_str)) =3D=3D VIR_ARCH= _NONE) { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown architecture: %s"), - arch_str); - goto cleanup; - } - - if (emulatorbin) { - virArch arch_from_caps; - - if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, - emulatorbin))) - goto cleanup; - - arch_from_caps =3D virQEMUCapsGetArch(qemuCaps); - - if (arch_from_caps !=3D arch && - !((ARCH_IS_X86(arch) && ARCH_IS_X86(arch_from_caps)) || - (ARCH_IS_PPC(arch) && ARCH_IS_PPC(arch_from_caps)) || - (ARCH_IS_ARM(arch) && ARCH_IS_ARM(arch_from_caps)) || - (ARCH_IS_S390(arch) && ARCH_IS_S390(arch_from_caps)))) { - virReportError(VIR_ERR_INVALID_ARG, - _("architecture from emulator '%s' doesn't " - "match given architecture '%s'"), - virArchToString(arch_from_caps), - virArchToString(arch)); - goto cleanup; - } - } else { - if (!(qemuCaps =3D virQEMUCapsCacheLookupByArch(driver->qemuCapsCa= che, - arch))) - goto cleanup; - - emulatorbin =3D virQEMUCapsGetBinary(qemuCaps); - } - - if (machine) { - /* Turn @machine into canonical name */ - machine =3D virQEMUCapsGetCanonicalMachine(qemuCaps, machine); - - if (!virQEMUCapsIsMachineSupported(qemuCaps, machine)) { - virReportError(VIR_ERR_INVALID_ARG, - _("the machine '%s' is not supported by emulato= r '%s'"), - machine, emulatorbin); - goto cleanup; - } - } else { - machine =3D virQEMUCapsGetDefaultMachine(qemuCaps); - } - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) - capsType =3D VIR_DOMAIN_VIRT_KVM; - else - capsType =3D VIR_DOMAIN_VIRT_QEMU; - - if (virttype =3D=3D VIR_DOMAIN_VIRT_NONE) - virttype =3D capsType; - - if (virttype =3D=3D VIR_DOMAIN_VIRT_KVM && capsType =3D=3D VIR_DOMAIN_= VIRT_QEMU) { - virReportError(VIR_ERR_INVALID_ARG, - _("KVM is not supported by '%s' on this host"), - emulatorbin); - goto cleanup; - } - - if (!(domCaps =3D virDomainCapsNew(emulatorbin, machine, arch, virttyp= e))) + if (!(domCaps =3D virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), mac= hine, + arch, virttype))) goto cleanup; =20 if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526459998102694.2807009636552; Wed, 16 May 2018 01:39:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A77C230C34AD; Wed, 16 May 2018 08:39:56 +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 69F6817B4C; Wed, 16 May 2018 08:39:56 +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 0A7E64A467; Wed, 16 May 2018 08:39:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djJS018346 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 171A72166BAE; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCEE52166BAD for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B2839102EE2; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:27 +0200 Message-Id: <7e35a993aa0af18a2226801a48a78538d9c672da.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/22] Introduce virConnectCompareHypervisorCPU public API 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 16 May 2018 08:39:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This new API compares the given CPU description with the CPU the specified hypervisor is able to provide on the host. It is a more useful version of virConnectCompareCPU, which compares the CPU definition with the host CPU without considering any specific hypervisor and its abilities. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- include/libvirt/libvirt-host.h | 7 ++++ src/driver-hypervisor.h | 10 +++++ src/libvirt-host.c | 72 +++++++++++++++++++++++++++++++++- src/libvirt_public.syms | 5 +++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index 07b5d15943..e2054baebc 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -640,6 +640,13 @@ typedef enum { int virConnectCompareCPU(virConnectPtr conn, const char *xmlDesc, unsigned int flags); +int virConnectCompareHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char *xmlCPU, + unsigned int flags); =20 int virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index e71a72a441..d64de2d54c 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -673,6 +673,15 @@ typedef int const char *cpu, unsigned int flags); =20 +typedef int +(*virDrvConnectCompareHypervisorCPU)(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char *xmlCPU, + unsigned int flags); + typedef char * (*virDrvConnectBaselineCPU)(virConnectPtr conn, const char **xmlCPUs, @@ -1532,6 +1541,7 @@ struct _virHypervisorDriver { virDrvDomainSetVcpu domainSetVcpu; virDrvDomainSetBlockThreshold domainSetBlockThreshold; virDrvDomainSetLifecycleAction domainSetLifecycleAction; + virDrvConnectCompareHypervisorCPU connectCompareHypervisorCPU; }; =20 =20 diff --git a/src/libvirt-host.c b/src/libvirt-host.c index ed689b9ec2..17cf183499 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -954,7 +954,11 @@ virConnectIsSecure(virConnectPtr conn) * @xmlDesc: XML describing the CPU to compare with host CPU * @flags: bitwise-OR of virConnectCompareCPUFlags * - * Compares the given CPU description with the host CPU + * Compares the given CPU description with the host CPU. + * + * See vitConnectCompareHypervisorCPU() if you want to consider hypervisor + * abilities and compare the CPU to the CPU which a hypervisor is able to + * provide on the host. * * Returns comparison result according to enum virCPUCompareResult. If * VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlDesc CPU is @@ -992,6 +996,72 @@ virConnectCompareCPU(virConnectPtr conn, } =20 =20 +/** + * virConnectCompareHypervisorCPU: + * @conn: pointer to the hypervisor connection + * @emulator: path to the emulator binary + * @arch: domain architecture + * @machine: machine type + * @virttype: virtualization type + * @xmlCPU: XML describing the CPU to be compared + * @flags: bitwise-OR of virConnectCompareCPUFlags + * + * Compares the given CPU description with the CPU the specified hyperviso= r is + * able to provide on the host. Any of @emulator, @arch, @machine, and + * @virttype parameters may be NULL; libvirt will choose sensible defaults + * tailored to the host and its current configuration. + * + * This is different from virConnectCompareCPU() which compares the CPU + * definition with the host CPU without considering any specific hyperviso= r and + * its abilities. + * + * Returns comparison result according to enum virCPUCompareResult. If + * VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlCPU is + * incompatible with the CPU the specified hypervisor is able to provide o= n the + * host, this function will return VIR_CPU_COMPARE_ERROR (instead of + * VIR_CPU_COMPARE_INCOMPATIBLE) and the error will use the + * VIR_ERR_CPU_INCOMPATIBLE code with a message providing more details abo= ut + * the incompatibility. + */ +int +virConnectCompareHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char *xmlCPU, + unsigned int flags) +{ + VIR_DEBUG("conn=3D%p, emulator=3D%s, arch=3D%s, machine=3D%s, " + "virttype=3D%s, xmlCPU=3D%s, flags=3D0x%x", + conn, NULLSTR(emulator), NULLSTR(arch), NULLSTR(machine), + NULLSTR(virttype), NULLSTR(xmlCPU), flags); + + virResetLastError(); + + virCheckConnectReturn(conn, VIR_CPU_COMPARE_ERROR); + virCheckNonNullArgGoto(xmlCPU, error); + + if (conn->driver->connectCompareHypervisorCPU) { + int ret; + + ret =3D conn->driver->connectCompareHypervisorCPU(conn, emulator, = arch, + machine, virttype, + xmlCPU, flags); + if (ret =3D=3D VIR_CPU_COMPARE_ERROR) + goto error; + + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return VIR_CPU_COMPARE_ERROR; +} + + /** * virConnectGetCPUModelNames: * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 95df3a0dbc..97597d7708 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -785,4 +785,9 @@ LIBVIRT_4.1.0 { virStoragePoolLookupByTargetPath; } LIBVIRT_3.9.0; =20 +LIBVIRT_4.4.0 { + global: + virConnectCompareHypervisorCPU; +} LIBVIRT_4.1.0; + # .... define new API here using predicted next version number .... --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526459994073572.9380939372759; Wed, 16 May 2018 01:39:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97E0530C09EE; Wed, 16 May 2018 08:39:52 +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 5689F30012C7; Wed, 16 May 2018 08:39:52 +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 0A7514BB78; Wed, 16 May 2018 08:39:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dj7a018345 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15F682166BB1; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8E282166BAE for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B81FE102EE3; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:28 +0200 Message-Id: <557ffdd25b5e8325e184628c3b3357b302646579.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/22] remote: Implement virConnectCompareHypervisorCPU 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 16 May 2018 08:39:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/remote/remote_driver.c | 3 ++- src/remote/remote_protocol.x | 21 ++++++++++++++++++++- src/remote_protocol-structs | 12 ++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 95437b4365..acefe8c457 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8448,7 +8448,8 @@ static virHypervisorDriver hypervisor_driver =3D { .domainSetGuestVcpus =3D remoteDomainSetGuestVcpus, /* 2.0.0 */ .domainSetVcpu =3D remoteDomainSetVcpu, /* 3.1.0 */ .domainSetBlockThreshold =3D remoteDomainSetBlockThreshold, /* 3.2.0 */ - .domainSetLifecycleAction =3D remoteDomainSetLifecycleAction /* 3.9.0 = */ + .domainSetLifecycleAction =3D remoteDomainSetLifecycleAction, /* 3.9.0= */ + .connectCompareHypervisorCPU =3D remoteConnectCompareHypervisorCPU, /*= 4.4.0 */ }; =20 static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 296a087181..0aa123b5ac 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3448,6 +3448,19 @@ struct remote_domain_set_lifecycle_action_args { unsigned int flags; }; =20 +struct remote_connect_compare_hypervisor_cpu_args { + remote_string emulator; + remote_string arch; + remote_string machine; + remote_string virttype; + remote_nonnull_string xmlCPU; + unsigned int flags; +}; + +struct remote_connect_compare_hypervisor_cpu_ret { + int result; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6135,5 +6148,11 @@ enum remote_procedure { * @priority: high * @acl: storage_pool:getattr */ - REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH =3D 391 + REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH =3D 391, + + /** + * @generate: both + * @acl: connect:write + */ + REMOTE_PROC_CONNECT_COMPARE_HYPERVISOR_CPU =3D 392 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index fe163db73f..64e48c52ba 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2877,6 +2877,17 @@ struct remote_domain_set_lifecycle_action_args { u_int action; u_int flags; }; +struct remote_connect_compare_hypervisor_cpu_args { + remote_string emulator; + remote_string arch; + remote_string machine; + remote_string virttype; + remote_nonnull_string xmlCPU; + u_int flags; +}; +struct remote_connect_compare_hypervisor_cpu_ret { + int result; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3269,4 +3280,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML =3D 389, REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION =3D 390, REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH =3D 391, + REMOTE_PROC_CONNECT_COMPARE_HYPERVISOR_CPU =3D 392, }; --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460011971901.9816847812875; Wed, 16 May 2018 01:40:11 -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 76321CC9B3; Wed, 16 May 2018 08:40:10 +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 320A730012C1; Wed, 16 May 2018 08:40:10 +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 B3138180BACD; Wed, 16 May 2018 08:40:09 +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 w4G8dkL4018380 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3489B6B59E; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA354D1EA7 for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id BD8F6102EE4; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:29 +0200 Message-Id: <47f68e079c68c1edceaaf6d534913615cf634fc8.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/22] virsh: Introduce new hypervisor-cpu-compare command 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.25]); Wed, 16 May 2018 08:40:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This command is a virsh wrapper for virConnectCompareHypervisorCPU. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-host.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 29 +++++++++++- 2 files changed, 141 insertions(+), 1 deletion(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ea2c411c02..1e7cfcbd5e 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1595,6 +1595,113 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cm= d) goto cleanup; } =20 + +/* + * "hypervisor-cpu-compare" command + */ +static const vshCmdInfo info_hypervisor_cpu_compare[] =3D { + {.name =3D "help", + .data =3D N_("compare a CPU with the CPU created by a hypervisor on t= he host") + }, + {.name =3D "desc", + .data =3D N_("compare CPU with hypervisor CPU") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_hypervisor_cpu_compare[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")), + {.name =3D "virttype", + .type =3D VSH_OT_STRING, + .help =3D N_("virtualization type (/domain/@type)"), + }, + {.name =3D "emulator", + .type =3D VSH_OT_STRING, + .help =3D N_("path to emulator binary (/domain/devices/emulator)"), + }, + {.name =3D "arch", + .type =3D VSH_OT_STRING, + .help =3D N_("domain architecture (/domain/os/type/@arch)"), + }, + {.name =3D "machine", + .type =3D VSH_OT_STRING, + .help =3D N_("machine type (/domain/os/type/@machine)"), + }, + {.name =3D "error", + .type =3D VSH_OT_BOOL, + .help =3D N_("report error if CPUs are incompatible") + }, + {.name =3D NULL} +}; + +static bool +cmdHypervisorCPUCompare(vshControl *ctl, + const vshCmd *cmd) +{ + const char *from =3D NULL; + const char *virttype =3D NULL; + const char *emulator =3D NULL; + const char *arch =3D NULL; + const char *machine =3D NULL; + bool ret =3D false; + int result; + char **cpus =3D NULL; + unsigned int flags =3D 0; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptBool(cmd, "error")) + flags |=3D VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0 || + vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 || + vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 || + vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || + vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) + return false; + + if (!(cpus =3D vshExtractCPUDefXMLs(ctl, from))) + return false; + + result =3D virConnectCompareHypervisorCPU(priv->conn, emulator, arch, + machine, virttype, cpus[0], fl= ags); + + switch (result) { + case VIR_CPU_COMPARE_INCOMPATIBLE: + vshPrint(ctl, + _("CPU described in %s is incompatible with the CPU provi= ded " + "by hypervisor on the host\n"), + from); + goto cleanup; + break; + + case VIR_CPU_COMPARE_IDENTICAL: + vshPrint(ctl, + _("CPU described in %s is identical to the CPU provided b= y " + "hypervisor on the host\n"), + from); + break; + + case VIR_CPU_COMPARE_SUPERSET: + vshPrint(ctl, + _("The CPU provided by hypervisor on the host is a supers= et " + "of CPU described in %s\n"), + from); + break; + + case VIR_CPU_COMPARE_ERROR: + default: + vshError(ctl, _("Failed to compare hypervisor CPU with %s"), from); + goto cleanup; + } + + ret =3D true; + + cleanup: + virStringListFree(cpus); + return ret; +} + + const vshCmdDef hostAndHypervisorCmds[] =3D { {.name =3D "allocpages", .handler =3D cmdAllocpages, @@ -1650,6 +1757,12 @@ const vshCmdDef hostAndHypervisorCmds[] =3D { .info =3D info_hostname, .flags =3D 0 }, + {.name =3D "hypervisor-cpu-compare", + .handler =3D cmdHypervisorCPUCompare, + .opts =3D opts_hypervisor_cpu_compare, + .info =3D info_hypervisor_cpu_compare, + .flags =3D 0 + }, {.name =3D "maxvcpus", .handler =3D cmdMaxvcpus, .opts =3D opts_maxvcpus, diff --git a/tools/virsh.pod b/tools/virsh.pod index ea10e1ad43..1a55092efd 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -585,7 +585,9 @@ features that block migration will not be included in t= he resulting CPU. =20 =3Ditem B I [I<--error>] =20 -Compare CPU definition from XML with host CPU. The XML may +Compare CPU definition from XML with host CPU. (See +B command for comparing the CPU definition with th= e CPU +which a specific hypervisor is able to provide on the host.) The XML may contain either host or guest CPU definition. The host CPU definition is the element and its contents as printed by B command. The guest CPU definition is the element and its contents from domain XML @@ -616,6 +618,31 @@ specified, then the output will be single-quoted where= needed, so that it is suitable for reuse in a shell context. If I<--xml> is specified, then the output will be escaped for use in XML. =20 +=3Ditem B I [I] [I] [I] +[I] [I<--error>] + +Compare CPU definition from XML with the CPU the specified hypervis= or +is able to provide on the host. (This is different from B whi= ch +compares the CPU definition with the host CPU without considering any spec= ific +hypervisor and its abilities.) + +The XML I may contain either host or guest CPU definition. The host = CPU +definition is the element and its contents as printed by B +command. The guest CPU definition is the element and its contents fr= om +domain XML definition or the CPU definition created from the host CPU model +found in domain capabilities XML (printed by B command). = In +addition to the element itself, this command accepts full domain XML, +capabilities XML, or domain capabilities XML containing the CPU definition= . For +more information on guest CPU definition see: +L. + +The I option specifies the virtualization type (usable in the 't= ype' +attribute of the top level element from the domain XML). I +specifies the path to the emulator, I specifies the CPU architecture= , and +I specifies the machine type. If I<--error> is specified, the com= mand +will return an error when the given CPU is incompatible with host CPU and a +message providing more details about the incompatibility will be printed o= ut. + =3Dback =20 =3Dhead1 DOMAIN COMMANDS --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460044450643.2322005605215; Wed, 16 May 2018 01:40:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 851BA315AE35; Wed, 16 May 2018 08:40:42 +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 49D2517B3A; Wed, 16 May 2018 08:40:42 +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 D0271180B5B4; Wed, 16 May 2018 08:40:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dm0t018444 for ; Wed, 16 May 2018 04:39:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E36010EE6D6; Wed, 16 May 2018 08:39:48 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E13BB11422DA for ; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id C316B102EE5; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:30 +0200 Message-Id: <80f70a760ebda26262250119c249ce785189edf0.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/22] qemu: Implement virConnectCompareHypervisorCPU 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 16 May 2018 08:40:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_driver.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6c086b9ef8..4b48afdad1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13100,6 +13100,65 @@ qemuConnectCompareCPU(virConnectPtr conn, } =20 =20 +static int +qemuConnectCompareHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *archStr, + const char *machine, + const char *virttypeStr, + const char *xmlCPU, + unsigned int flags) +{ + int ret =3D VIR_CPU_COMPARE_ERROR; + virQEMUDriverPtr driver =3D conn->privateData; + virQEMUCapsPtr qemuCaps =3D NULL; + bool failIncompatible; + virCPUDefPtr hvCPU; + virArch arch; + virDomainVirtType virttype; + + virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE, + VIR_CPU_COMPARE_ERROR); + + if (virConnectCompareHypervisorCPUEnsureACL(conn) < 0) + goto cleanup; + + failIncompatible =3D !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATI= BLE); + + qemuCaps =3D virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, + emulator, + archStr, + virttypeStr, + machine, + &arch, &virttype, NULL); + if (!qemuCaps) + goto cleanup; + + hvCPU =3D virQEMUCapsGetHostModel(qemuCaps, virttype, + VIR_QEMU_CAPS_HOST_CPU_REPORTED); + if (!hvCPU || hvCPU->fallback !=3D VIR_CPU_FALLBACK_FORBID) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("QEMU '%s' does not support reporting CPU model f= or " + "virttype '%s'"), + virQEMUCapsGetBinary(qemuCaps), + virDomainVirtTypeToString(virttype)); + goto cleanup; + } + + if (ARCH_IS_X86(arch)) { + ret =3D virCPUCompareXML(arch, hvCPU, xmlCPU, failIncompatible); + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("comparing hypervisor CPUs is not supported for " + "arch %s"), virArchToString(arch)); + } + + cleanup: + virObjectUnref(qemuCaps); + return ret; +} + + static char * qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED, const char **xmlCPUs, @@ -21326,6 +21385,7 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainSetVcpu =3D qemuDomainSetVcpu, /* 3.1.0 */ .domainSetBlockThreshold =3D qemuDomainSetBlockThreshold, /* 3.2.0 */ .domainSetLifecycleAction =3D qemuDomainSetLifecycleAction, /* 3.9.0 */ + .connectCompareHypervisorCPU =3D qemuConnectCompareHypervisorCPU, /* 4= .4.0 */ }; =20 =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460025027784.6913982425364; Wed, 16 May 2018 01:40:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A588A703B; Wed, 16 May 2018 08:40:23 +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 B8A3E2B476; Wed, 16 May 2018 08:40:22 +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 3C4093D385; Wed, 16 May 2018 08:40:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkct018384 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C9DE2024CBE; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F23DF2024CBB for ; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id C887B102EE9; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:31 +0200 Message-Id: <5c6cef8a6d570656113531fefbc1d9458a3193e4.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/22] Introduce virConnectBaselineHypervisorCPU public API 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 16 May 2018 08:40:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The new API computes the most feature-rich CPU which is compatible with all given CPUs and can be provided by the specified hypervisor. It is a more useful version of vitConnectBaselineCPU, which doesn't consider any hypervisor capabilities when computing the best CPU. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- include/libvirt/libvirt-host.h | 8 ++++ src/driver-hypervisor.h | 10 +++++ src/libvirt-host.c | 81 ++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 100 insertions(+) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index e2054baebc..84f4858169 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -667,6 +667,14 @@ char *virConnectBaselineCPU(virConnectPtr conn, const char **xmlCPUs, unsigned int ncpus, unsigned int flags); +char *virConnectBaselineHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags); =20 =20 int virNodeGetFreePages(virConnectPtr conn, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index d64de2d54c..9ce0d7e5de 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -687,6 +687,15 @@ typedef char * const char **xmlCPUs, unsigned int ncpus, unsigned int flags); +typedef char * +(*virDrvConnectBaselineHypervisorCPU)(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags); =20 typedef int (*virDrvConnectGetCPUModelNames)(virConnectPtr conn, @@ -1542,6 +1551,7 @@ struct _virHypervisorDriver { virDrvDomainSetBlockThreshold domainSetBlockThreshold; virDrvDomainSetLifecycleAction domainSetLifecycleAction; virDrvConnectCompareHypervisorCPU connectCompareHypervisorCPU; + virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; }; =20 =20 diff --git a/src/libvirt-host.c b/src/libvirt-host.c index 17cf183499..cdbbe35e5a 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -1127,6 +1127,9 @@ virConnectGetCPUModelNames(virConnectPtr conn, const = char *arch, char ***models, * Computes the most feature-rich CPU which is compatible with all given * host CPUs. * + * See vitConnectBaselineHypervisorCPU() to get a CPU which can be provided + * by a specific hypervisor. + * * If @flags includes VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES then libvirt * will explicitly list all CPU features that are part of the host CPU, * without this flag features that are part of the CPU model will not be @@ -1174,6 +1177,84 @@ virConnectBaselineCPU(virConnectPtr conn, } =20 =20 +/** + * virConnectBaselineHypervisorCPU: + * + * @conn: pointer to the hypervisor connection + * @emulator: path to the emulator binary + * @arch: domain architecture + * @machine: machine type + * @virttype: virtualization type + * @xmlCPUs: array of XML descriptions of CPUs + * @ncpus: number of CPUs in xmlCPUs + * @flags: bitwise-OR of virConnectBaselineCPUFlags + * + * Computes the most feature-rich CPU which is compatible with all given C= PUs + * and can be provided by the specified hypervisor. For best results the + * host-model CPUs as advertised by virConnectGetDomainCapabilities() shou= ld be + * passed in @xmlCPUs. Any of @emulator, @arch, @machine, and @virttype + * parameters may be NULL; libvirt will choose sensible defaults tailored = to + * the host and its current configuration. + * + * This is different from vitConnectBaselineCPU() which doesn't consider a= ny + * hypervisor abilities when computing the best CPU. + * + * If @flags includes VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES then libvirt + * will explicitly list all CPU features that are part of the computed CPU, + * without this flag features that are part of the CPU model will not be + * listed. + * + * If @flags includes VIR_CONNECT_BASELINE_CPU_MIGRATABLE, the resulting + * CPU will not include features that block migration. + * + * Returns XML description of the computed CPU (caller frees) or NULL on e= rror. + */ +char * +virConnectBaselineHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags) +{ + size_t i; + + VIR_DEBUG("conn=3D%p, emulator=3D%s, arch=3D%s, machine=3D%s, " + "virttype=3D%s, xmlCPUs=3D%p, ncpus=3D%u, flags=3D0x%x", + conn, NULLSTR(emulator), NULLSTR(arch), NULLSTR(machine), + NULLSTR(virttype), xmlCPUs, ncpus, flags); + if (xmlCPUs) { + for (i =3D 0; i < ncpus; i++) + VIR_DEBUG("xmlCPUs[%zu]=3D%s", i, NULLSTR(xmlCPUs[i])); + } + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckNonNullArgGoto(xmlCPUs, error); + + if (conn->driver->connectBaselineHypervisorCPU) { + char *cpu; + + cpu =3D conn->driver->connectBaselineHypervisorCPU(conn, emulator,= arch, + machine, virttype, + xmlCPUs, ncpus, f= lags); + if (!cpu) + goto error; + + return cpu; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + /** * virConnectSetKeepAlive: * @conn: pointer to a hypervisor connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 97597d7708..05ab077fb4 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -788,6 +788,7 @@ LIBVIRT_4.1.0 { LIBVIRT_4.4.0 { global: virConnectCompareHypervisorCPU; + virConnectBaselineHypervisorCPU; } LIBVIRT_4.1.0; =20 # .... define new API here using predicted next version number .... --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 15264600088251019.7878190824332; Wed, 16 May 2018 01:40:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2E7C3177BD6; Wed, 16 May 2018 08:40:06 +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 6908D98F76; Wed, 16 May 2018 08:40:06 +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 CA0F31801250; Wed, 16 May 2018 08:40:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dk99018381 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C8D92166BCC; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1ABE02166BAD for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id CDBB7102EEA; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:32 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/22] remote: Implement virConnectBaselineHypervisorCPU 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 16 May 2018 08:40:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 21 ++++++++++++++++++++- src/remote_protocol-structs | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index acefe8c457..d106a18510 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8450,6 +8450,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainSetBlockThreshold =3D remoteDomainSetBlockThreshold, /* 3.2.0 */ .domainSetLifecycleAction =3D remoteDomainSetLifecycleAction, /* 3.9.0= */ .connectCompareHypervisorCPU =3D remoteConnectCompareHypervisorCPU, /*= 4.4.0 */ + .connectBaselineHypervisorCPU =3D remoteConnectBaselineHypervisorCPU, = /* 4.4.0 */ }; =20 static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 0aa123b5ac..ff28cec50f 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3461,6 +3461,19 @@ struct remote_connect_compare_hypervisor_cpu_ret { int result; }; =20 +struct remote_connect_baseline_hypervisor_cpu_args { + remote_string emulator; + remote_string arch; + remote_string machine; + remote_string virttype; + remote_nonnull_string xmlCPUs; /* (const char= **) */ + unsigned int flags; +}; + +struct remote_connect_baseline_hypervisor_cpu_ret { + remote_nonnull_string cpu; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6154,5 +6167,11 @@ enum remote_procedure { * @generate: both * @acl: connect:write */ - REMOTE_PROC_CONNECT_COMPARE_HYPERVISOR_CPU =3D 392 + REMOTE_PROC_CONNECT_COMPARE_HYPERVISOR_CPU =3D 392, + + /** + * @generate: both + * @acl: connect:write + */ + REMOTE_PROC_CONNECT_BASELINE_HYPERVISOR_CPU =3D 393 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 64e48c52ba..99251ac0e8 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2888,6 +2888,20 @@ struct remote_connect_compare_hypervisor_cpu_args { struct remote_connect_compare_hypervisor_cpu_ret { int result; }; +struct remote_connect_baseline_hypervisor_cpu_args { + remote_string emulator; + remote_string arch; + remote_string machine; + remote_string virttype; + struct { + u_int xmlCPUs_len; + remote_nonnull_string * xmlCPUs_val; + } xmlCPUs; + u_int flags; +}; +struct remote_connect_baseline_hypervisor_cpu_ret { + remote_nonnull_string cpu; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3281,4 +3295,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION =3D 390, REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH =3D 391, REMOTE_PROC_CONNECT_COMPARE_HYPERVISOR_CPU =3D 392, + REMOTE_PROC_CONNECT_BASELINE_HYPERVISOR_CPU =3D 393, }; --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460027418355.7886751477075; Wed, 16 May 2018 01:40:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19BF430C1325; Wed, 16 May 2018 08:40:24 +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 D0CED2B472; Wed, 16 May 2018 08:40:23 +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 6A8B9180BAD1; Wed, 16 May 2018 08:40:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dmaf018447 for ; Wed, 16 May 2018 04:39:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4793210AF9F6; Wed, 16 May 2018 08:39:48 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E15211142374 for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id D1AB9102EDA; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:33 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/22] virsh: Introduce new hypervisor-cpu-baseline command 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 16 May 2018 08:40:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This command is a virsh wrapper for virConnectBaselineHypervisorCPU. Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-host.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 47 ++++++++++++++++++++--- 2 files changed, 137 insertions(+), 6 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 1e7cfcbd5e..8fde5da50e 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1702,6 +1702,96 @@ cmdHypervisorCPUCompare(vshControl *ctl, } =20 =20 +/* + * "hypervisor-cpu-baseline" command + */ +static const vshCmdInfo info_hypervisor_cpu_baseline[] =3D { + {.name =3D "help", + .data =3D N_("compute baseline CPU usable by a specific hypervisor") + }, + {.name =3D "desc", + .data =3D N_("Compute baseline CPU for a set of given CPUs. The resul= t " + "will be tailored to the specified hypervisor.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_hypervisor_cpu_baseline[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")), + {.name =3D "virttype", + .type =3D VSH_OT_STRING, + .help =3D N_("virtualization type (/domain/@type)"), + }, + {.name =3D "emulator", + .type =3D VSH_OT_STRING, + .help =3D N_("path to emulator binary (/domain/devices/emulator)"), + }, + {.name =3D "arch", + .type =3D VSH_OT_STRING, + .help =3D N_("domain architecture (/domain/os/type/@arch)"), + }, + {.name =3D "machine", + .type =3D VSH_OT_STRING, + .help =3D N_("machine type (/domain/os/type/@machine)"), + }, + {.name =3D "features", + .type =3D VSH_OT_BOOL, + .help =3D N_("Show features that are part of the CPU model type") + }, + {.name =3D "migratable", + .type =3D VSH_OT_BOOL, + .help =3D N_("Do not include features that block migration") + }, + {.name =3D NULL} +}; + +static bool +cmdHypervisorCPUBaseline(vshControl *ctl, + const vshCmd *cmd) +{ + const char *from =3D NULL; + const char *virttype =3D NULL; + const char *emulator =3D NULL; + const char *arch =3D NULL; + const char *machine =3D NULL; + bool ret =3D false; + char *result =3D NULL; + char **list =3D NULL; + unsigned int flags =3D 0; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptBool(cmd, "features")) + flags |=3D VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; + if (vshCommandOptBool(cmd, "migratable")) + flags |=3D VIR_CONNECT_BASELINE_CPU_MIGRATABLE; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0 || + vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 || + vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 || + vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || + vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) + return false; + + if (!(list =3D vshExtractCPUDefXMLs(ctl, from))) + return false; + + result =3D virConnectBaselineHypervisorCPU(priv->conn, emulator, arch, + machine, virttype, + (const char **)list, + virStringListLength((const ch= ar **)list), + flags); + + if (result) { + vshPrint(ctl, "%s", result); + ret =3D true; + } + + VIR_FREE(result); + virStringListFree(list); + return ret; +} + + const vshCmdDef hostAndHypervisorCmds[] =3D { {.name =3D "allocpages", .handler =3D cmdAllocpages, @@ -1757,6 +1847,12 @@ const vshCmdDef hostAndHypervisorCmds[] =3D { .info =3D info_hostname, .flags =3D 0 }, + {.name =3D "hypervisor-cpu-baseline", + .handler =3D cmdHypervisorCPUBaseline, + .opts =3D opts_hypervisor_cpu_baseline, + .info =3D info_hypervisor_cpu_baseline, + .flags =3D 0 + }, {.name =3D "hypervisor-cpu-compare", .handler =3D cmdHypervisorCPUCompare, .opts =3D opts_hypervisor_cpu_compare, diff --git a/tools/virsh.pod b/tools/virsh.pod index 1a55092efd..d57ebadee6 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -574,12 +574,13 @@ I<--all> which executes the modification on all NUMA = cells. =3Ditem B I [I<--features>] [I<--migratable>] =20 Compute baseline CPU which will be supported by all host CPUs given in . -The list of host CPUs is built by extracting all elements from the -. Thus, the can contain either a set of elements separa= ted -by new lines or even a set of complete elements printed by -B command. If I<--features> is specified then the -resulting XML description will explicitly include all features that make -up the CPU, without this option features that are part of the CPU model +(See B command to get a CPU which can be provided= by a +specific hypervisor.) The list of host CPUs is built by extracting all +elements from the . Thus, the can contain either a set of +elements separated by new lines or even a set of complete +elements printed by B command. If I<--features> is specified +then the resulting XML description will explicitly include all features th= at +make up the CPU, without this option features that are part of the CPU mod= el will not be listed in the XML description. If I<--migratable> is specifi= ed, features that block migration will not be included in the resulting CPU. =20 @@ -643,6 +644,40 @@ I specifies the machine type. If I<--error> i= s specified, the command will return an error when the given CPU is incompatible with host CPU and a message providing more details about the incompatibility will be printed o= ut. =20 +=3Ditem B I [I] [I] [I<= arch>] +[I] [I<--features>] [I<--migratable>] + +Compute baseline CPU which will be compatible with all CPUs given in I +and can be provided by the specified hypervisor. (This is different from +B which does not consider any hypervisor abilities when comp= uting +the baseline CPU.) + +The XML I may contain either host or guest CPU definitions describin= g the +host CPU model. The host CPU definition is the element and its conte= nts +as printed by B command. The guest CPU definition may be cre= ated +from the host CPU model found in domain capabilities XML (printed by +B command). In addition to the elements, this comma= nd +accepts full capabilities XMLs, or domain capabilities XMLs containing the= CPU +definitions. For best results, use only the CPU definitions from domain +capabilities. + +When I contains only a single CPU definition, the command will print= the +same CPU updated according to additional options and restricted to the +capabilities of the specified hypervisor. Specifically, running +B command with no additional options on the +result of B will return transform the host CPU model +from domain capabilities XML to the form directly usable in domain XML. + +The I option specifies the virtualization type (usable in the 't= ype' +attribute of the top level element from the domain XML). I +specifies the path to the emulator, I specifies the CPU architecture= , and +I specifies the machine type. If I<--features> is specified then = the +resulting XML description will explicitly include all features that make u= p the +CPU, without this option features that are part of the CPU model will not = be +listed in the XML description. If I<--migratable> is specified, features t= hat +block migration will not be included in the resulting CPU. + + =3Dback =20 =3Dhead1 DOMAIN COMMANDS --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460035017136.5948381240405; Wed, 16 May 2018 01:40:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47338347DD2; Wed, 16 May 2018 08:40:33 +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 11DF898F78; Wed, 16 May 2018 08:40:33 +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 AAA533D389; Wed, 16 May 2018 08:40:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dmIj018446 for ; Wed, 16 May 2018 04:39:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2AC1110AF9D9; Wed, 16 May 2018 08:39:48 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E13E71142372 for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id D66DE102EEC; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:34 +0200 Message-Id: <1d691dec189c4219750b8e46649a1066d664a9b9.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/22] cpu: Rename cpuBaseline as virCPUBaseline 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 16 May 2018 08:40:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/bhyve/bhyve_driver.c | 4 ++-- src/cpu/cpu.c | 10 +++++----- src/cpu/cpu.h | 18 +++++++++--------- src/cpu/cpu_arm.c | 10 +++++----- src/cpu/cpu_ppc64.c | 4 ++-- src/cpu/cpu_x86.c | 10 +++++----- src/libvirt_private.syms | 2 +- src/libxl/libxl_driver.c | 4 ++-- src/qemu/qemu_driver.c | 4 ++-- src/test/test_driver.c | 2 +- src/vz/vz_driver.c | 2 +- tests/cputest.c | 6 +++--- 12 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index d2a538337f..72c51434c7 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1398,8 +1398,8 @@ bhyveConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D cpuBaseline(cpus, ncpus, NULL, - !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE= )))) + if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, + !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATA= BLE)))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 047e3b1112..81b93a991b 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -479,7 +479,7 @@ virCPUProbeHost(virArch arch) =20 =20 /** - * cpuBaseline: + * virCPUBaseline: * * @cpus: list of host CPU definitions * @ncpus: number of CPUs in @cpus @@ -494,10 +494,10 @@ virCPUProbeHost(virArch arch) * Returns baseline CPU definition or NULL on error. */ virCPUDefPtr -cpuBaseline(virCPUDefPtr *cpus, - unsigned int ncpus, - virDomainCapsCPUModelsPtr models, - bool migratable) +virCPUBaseline(virCPUDefPtr *cpus, + unsigned int ncpus, + virDomainCapsCPUModelsPtr models, + bool migratable) { struct cpuArchDriver *driver; size_t i; diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 83d5bcb63f..529068a618 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -73,10 +73,10 @@ typedef int virDomainCapsCPUModelsPtr models); =20 typedef virCPUDefPtr -(*cpuArchBaseline) (virCPUDefPtr *cpus, - unsigned int ncpus, - virDomainCapsCPUModelsPtr models, - bool migratable); +(*virCPUArchBaseline)(virCPUDefPtr *cpus, + unsigned int ncpus, + virDomainCapsCPUModelsPtr models, + bool migratable); =20 typedef int (*virCPUArchUpdate)(virCPUDefPtr guest, @@ -129,7 +129,7 @@ struct cpuArchDriver { cpuArchEncode encode; cpuArchDataFree dataFree; virCPUArchGetHost getHost; - cpuArchBaseline baseline; + virCPUArchBaseline baseline; virCPUArchUpdate update; virCPUArchUpdateLive updateLive; virCPUArchCheckFeature checkFeature; @@ -194,10 +194,10 @@ virCPUDefPtr virCPUProbeHost(virArch arch); =20 virCPUDefPtr -cpuBaseline (virCPUDefPtr *cpus, - unsigned int ncpus, - virDomainCapsCPUModelsPtr models, - bool migratable); +virCPUBaseline(virCPUDefPtr *cpus, + unsigned int ncpus, + virDomainCapsCPUModelsPtr models, + bool migratable); =20 int virCPUUpdate(virArch arch, diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 44cb4fea68..a9aa065f9f 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -73,10 +73,10 @@ virCPUarmUpdate(virCPUDefPtr guest, =20 =20 static virCPUDefPtr -armBaseline(virCPUDefPtr *cpus, - unsigned int ncpus ATTRIBUTE_UNUSED, - virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, - bool migratable ATTRIBUTE_UNUSED) +virCPUarmBaseline(virCPUDefPtr *cpus, + unsigned int ncpus ATTRIBUTE_UNUSED, + virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, + bool migratable ATTRIBUTE_UNUSED) { virCPUDefPtr cpu =3D NULL; =20 @@ -107,6 +107,6 @@ struct cpuArchDriver cpuDriverArm =3D { .compare =3D virCPUarmCompare, .decode =3D NULL, .encode =3D NULL, - .baseline =3D armBaseline, + .baseline =3D virCPUarmBaseline, .update =3D virCPUarmUpdate, }; diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 76582d4083..c213245fc9 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -767,7 +767,7 @@ virCPUppc64Update(virCPUDefPtr guest, } =20 static virCPUDefPtr -ppc64DriverBaseline(virCPUDefPtr *cpus, +virCPUppc64Baseline(virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, bool migratable ATTRIBUTE_UNUSED) @@ -901,7 +901,7 @@ struct cpuArchDriver cpuDriverPPC64 =3D { .encode =3D NULL, .dataFree =3D virCPUppc64DataFree, .getHost =3D virCPUppc64GetHost, - .baseline =3D ppc64DriverBaseline, + .baseline =3D virCPUppc64Baseline, .update =3D virCPUppc64Update, .getModels =3D virCPUppc64DriverGetModels, .convertLegacy =3D virCPUppc64ConvertLegacy, diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index b2398c5ad2..188d1eba75 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2464,10 +2464,10 @@ virCPUx86GetHost(virCPUDefPtr cpu, =20 =20 static virCPUDefPtr -x86Baseline(virCPUDefPtr *cpus, - unsigned int ncpus, - virDomainCapsCPUModelsPtr models, - bool migratable) +virCPUx86Baseline(virCPUDefPtr *cpus, + unsigned int ncpus, + virDomainCapsCPUModelsPtr models, + bool migratable) { virCPUx86MapPtr map =3D NULL; virCPUx86ModelPtr base_model =3D NULL; @@ -3050,7 +3050,7 @@ struct cpuArchDriver cpuDriverX86 =3D { #if defined(__i386__) || defined(__x86_64__) .getHost =3D virCPUx86GetHost, #endif - .baseline =3D x86Baseline, + .baseline =3D virCPUx86Baseline, .update =3D virCPUx86Update, .updateLive =3D virCPUx86UpdateLive, .checkFeature =3D virCPUx86CheckFeature, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3dece252df..912676ec7a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1139,9 +1139,9 @@ virStoragePoolObjVolumeListExport; =20 =20 # cpu/cpu.h -cpuBaseline; cpuDecode; cpuEncode; +virCPUBaseline; virCPUCheckFeature; virCPUCompare; virCPUCompareXML; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index df53dead0a..e11969dca7 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -6349,8 +6349,8 @@ libxlConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D cpuBaseline(cpus, ncpus, NULL, - !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE= )))) + if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, + !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATA= BLE)))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4b48afdad1..17167129da 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13179,8 +13179,8 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE= _UNUSED, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(baseline =3D cpuBaseline(cpus, ncpus, NULL, - !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRA= TABLE)))) + if (!(baseline =3D virCPUBaseline(cpus, ncpus, NULL, + !!(flags & VIR_CONNECT_BASELINE_CPU_MI= GRATABLE)))) goto cleanup; =20 if (!(cpu =3D virCPUDefCopyWithoutModel(baseline))) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 467587b19f..abb856a5b2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1536,7 +1536,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_U= NUSED, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D cpuBaseline(cpus, ncpus, NULL, false))) + if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, false))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 48a9a866d9..d4cf2d5f62 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -934,7 +934,7 @@ vzConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D cpuBaseline(cpus, ncpus, NULL, false))) + if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, false))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/tests/cputest.c b/tests/cputest.c index e86cd0b9bc..beb9afabdf 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -321,8 +321,8 @@ cpuTestBaseline(const void *arg) if (!(cpus =3D cpuTestLoadMultiXML(data->arch, data->name, &ncpus))) goto cleanup; =20 - baseline =3D cpuBaseline(cpus, ncpus, NULL, - !!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRA= TABLE)); + baseline =3D virCPUBaseline(cpus, ncpus, NULL, + !!(data->flags & VIR_CONNECT_BASELINE_CPU_MI= GRATABLE)); =20 if (baseline && (data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && @@ -337,7 +337,7 @@ cpuTestBaseline(const void *arg) ret =3D 0; } else { VIR_TEST_VERBOSE("\n%-70s... ", - "cpuBaseline was expected to fail but it succeeded"); + "virCPUBaseline was expected to fail but it succeeded"= ); } goto cleanup; } --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460018011632.1281328348332; Wed, 16 May 2018 01:40:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D2C930CA27E; Wed, 16 May 2018 08:40:16 +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 DAAA71778D; Wed, 16 May 2018 08:40:15 +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 153CA180BACF; Wed, 16 May 2018 08:40:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkMQ018383 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3F9F62024CBB; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E37F2024CBC for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id DAAA2102EED; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:35 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/22] cpu_x86: Add support for passing guest CPUs to virCPUx86Baseline 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 16 May 2018 08:40:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modern host CPU models from domain capabilities XMLs are reported as guest CPU definitions with feature policies. This patch updates virCPUx86Baseline to properly handle such CPU models. Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- src/cpu/cpu_x86.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 188d1eba75..6bef4089e9 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2482,13 +2482,12 @@ virCPUx86Baseline(virCPUDefPtr *cpus, if (!(map =3D virCPUx86GetMap())) goto error; =20 - if (!(base_model =3D x86ModelFromCPU(cpus[0], map, VIR_CPU_FEATURE_REQ= UIRE))) + if (!(base_model =3D x86ModelFromCPU(cpus[0], map, -1))) goto error; =20 if (VIR_ALLOC(cpu) < 0) goto error; =20 - cpu->arch =3D cpus[0]->arch; cpu->type =3D VIR_CPU_TYPE_GUEST; cpu->match =3D VIR_CPU_MATCH_EXACT; =20 @@ -2513,7 +2512,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus, } } =20 - if (!(model =3D x86ModelFromCPU(cpus[i], map, VIR_CPU_FEATURE_REQU= IRE))) + if (!(model =3D x86ModelFromCPU(cpus[i], map, -1))) goto error; =20 if (cpus[i]->vendor && model->vendor && @@ -2570,8 +2569,6 @@ virCPUx86Baseline(virCPUDefPtr *cpus, if (!outputVendor) VIR_FREE(cpu->vendor); =20 - cpu->arch =3D VIR_ARCH_NONE; - cleanup: x86ModelFree(base_model); =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460031272483.3985836743766; Wed, 16 May 2018 01:40:31 -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 50431315366A; Wed, 16 May 2018 08:40:29 +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 029146017C; Wed, 16 May 2018 08:40:29 +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 8A02F180BAE4; Wed, 16 May 2018 08:40:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkLe018387 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CC0B2166BB1; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F2612166BAE for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id DEE3E102EEE; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:36 +0200 Message-Id: <9485268543c29f756fb54a3a734675c1bcba7758.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 17/22] cpu: Add explicit arch parameter for virCPUBaseline 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.49]); Wed, 16 May 2018 08:40:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is required for virCPUBaseline to accept a list of guest CPU definitions since they do not have arch set. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- src/bhyve/bhyve_driver.c | 2 +- src/cpu/cpu.c | 16 +++++++++++----- src/cpu/cpu.h | 3 ++- src/libxl/libxl_driver.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/test/test_driver.c | 2 +- src/vz/vz_driver.c | 2 +- tests/cputest.c | 2 +- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 72c51434c7..26047d31e2 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1398,7 +1398,7 @@ bhyveConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATA= BLE)))) goto cleanup; =20 diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 81b93a991b..2c60d27b17 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -481,20 +481,22 @@ virCPUProbeHost(virArch arch) /** * virCPUBaseline: * + * @arch: CPU architecture, use VIR_ARCH_NONE to autodetect from @cpus * @cpus: list of host CPU definitions * @ncpus: number of CPUs in @cpus * @models: list of CPU models that can be considered for the baseline CPU * @migratable: requests non-migratable features to be removed from the re= sult * * Computes the most feature-rich CPU which is compatible with all given - * host CPUs. If @models is NULL, all models supported by libvirt will + * CPUs. If @models is NULL, all models supported by libvirt will * be considered when computing the baseline CPU model, otherwise the base= line * CPU model will be one of the provided CPU @models. * * Returns baseline CPU definition or NULL on error. */ virCPUDefPtr -virCPUBaseline(virCPUDefPtr *cpus, +virCPUBaseline(virArch arch, + virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models, bool migratable) @@ -502,7 +504,8 @@ virCPUBaseline(virCPUDefPtr *cpus, struct cpuArchDriver *driver; size_t i; =20 - VIR_DEBUG("ncpus=3D%u, models=3D%p, migratable=3D%d", ncpus, models, m= igratable); + VIR_DEBUG("arch=3D%s, ncpus=3D%u, models=3D%p, migratable=3D%d", + virArchToString(arch), ncpus, models, migratable); if (cpus) { for (i =3D 0; i < ncpus; i++) VIR_DEBUG("cpus[%zu]=3D%p", i, cpus[i]); @@ -536,13 +539,16 @@ virCPUBaseline(virCPUDefPtr *cpus, } } =20 - if ((driver =3D cpuGetSubDriver(cpus[0]->arch)) =3D=3D NULL) + if (arch =3D=3D VIR_ARCH_NONE) + arch =3D cpus[0]->arch; + + if ((driver =3D cpuGetSubDriver(arch)) =3D=3D NULL) return NULL; =20 if (driver->baseline =3D=3D NULL) { virReportError(VIR_ERR_NO_SUPPORT, _("cannot compute baseline CPU of %s architecture"), - virArchToString(cpus[0]->arch)); + virArchToString(arch)); return NULL; } =20 diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 529068a618..8c45bf8b31 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -194,7 +194,8 @@ virCPUDefPtr virCPUProbeHost(virArch arch); =20 virCPUDefPtr -virCPUBaseline(virCPUDefPtr *cpus, +virCPUBaseline(virArch arch, + virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models, bool migratable); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index e11969dca7..a85ce84404 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -6349,7 +6349,7 @@ libxlConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATA= BLE)))) goto cleanup; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 17167129da..b95e1f5296 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13179,7 +13179,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE= _UNUSED, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(baseline =3D virCPUBaseline(cpus, ncpus, NULL, + if (!(baseline =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, !!(flags & VIR_CONNECT_BASELINE_CPU_MI= GRATABLE)))) goto cleanup; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index abb856a5b2..3b4acaf7fe 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1536,7 +1536,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_U= NUSED, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, false))) + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index d4cf2d5f62..50cd0acfdf 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -934,7 +934,7 @@ vzConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(cpus, ncpus, NULL, false))) + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/tests/cputest.c b/tests/cputest.c index beb9afabdf..9b84ffea86 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -321,7 +321,7 @@ cpuTestBaseline(const void *arg) if (!(cpus =3D cpuTestLoadMultiXML(data->arch, data->name, &ncpus))) goto cleanup; =20 - baseline =3D virCPUBaseline(cpus, ncpus, NULL, + baseline =3D virCPUBaseline(data->arch, cpus, ncpus, NULL, !!(data->flags & VIR_CONNECT_BASELINE_CPU_MI= GRATABLE)); =20 if (baseline && --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460029180798.229356360165; Wed, 16 May 2018 01:40:29 -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 A608D30D0304; Wed, 16 May 2018 08:40:27 +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 619FB600CD; Wed, 16 May 2018 08:40:27 +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 B73CC3D387; Wed, 16 May 2018 08:40:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dmrG018445 for ; Wed, 16 May 2018 04:39:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1127610EE6DD; Wed, 16 May 2018 08:39:48 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4C7110AF9FE for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id E3313102EEF; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:37 +0200 Message-Id: <954a36f569c5a1b3d90a9fea5886340190eb04d7.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/22] cpu: Update style in virCPUBaseline 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.47]); Wed, 16 May 2018 08:40:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" To make it more consistent with the rest of the CPU driver code. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- src/cpu/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 2c60d27b17..b6c1695f2a 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -515,14 +515,14 @@ virCPUBaseline(virArch arch, VIR_DEBUG("models[%zu]=3D%s", i, models->models[i].name); } =20 - if (cpus =3D=3D NULL && ncpus !=3D 0) { + if (!cpus && ncpus !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nonzero ncpus doesn't match with NULL cpus= ")); return NULL; } =20 if (ncpus < 1) { - virReportError(VIR_ERR_INVALID_ARG, "%s", _("No CPUs given")); + virReportError(VIR_ERR_INVALID_ARG, "%s", _("no CPUs given")); return NULL; } =20 @@ -542,10 +542,10 @@ virCPUBaseline(virArch arch, if (arch =3D=3D VIR_ARCH_NONE) arch =3D cpus[0]->arch; =20 - if ((driver =3D cpuGetSubDriver(arch)) =3D=3D NULL) + if (!(driver =3D cpuGetSubDriver(arch))) return NULL; =20 - if (driver->baseline =3D=3D NULL) { + if (!driver->baseline) { virReportError(VIR_ERR_NO_SUPPORT, _("cannot compute baseline CPU of %s architecture"), virArchToString(arch)); --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460038662464.85792776914207; Wed, 16 May 2018 01:40:38 -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 402EBB6D23; Wed, 16 May 2018 08:40:36 +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 F111430012CE; Wed, 16 May 2018 08:40:35 +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 5C4CC3D38F; Wed, 16 May 2018 08:40:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkjB018391 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6BF5A2024CBC; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E48C2024CBD for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id E7817102EF0; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:38 +0200 Message-Id: <1116f33c50f64286ff45fc82581807f9a4b668ab.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/22] cpu: Add optional list of allowed features to virCPUBaseline 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.25]); Wed, 16 May 2018 08:40:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When computing a baseline CPU for a specific hypervisor we have to make sure to include only CPU features supported by the hypervisor. Otherwise the computed CPU could not be used for starting a new domain. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- src/bhyve/bhyve_driver.c | 2 +- src/cpu/cpu.c | 8 +++++--- src/cpu/cpu.h | 2 ++ src/cpu/cpu_arm.c | 1 + src/cpu/cpu_ppc64.c | 1 + src/cpu/cpu_x86.c | 18 ++++++++++++++++++ src/libxl/libxl_driver.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/test/test_driver.c | 2 +- src/vz/vz_driver.c | 2 +- tests/cputest.c | 2 +- 11 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 26047d31e2..97e8d4eb37 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1398,7 +1398,7 @@ bhyveConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATA= BLE)))) goto cleanup; =20 diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index b6c1695f2a..cc93c49418 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -485,6 +485,7 @@ virCPUProbeHost(virArch arch) * @cpus: list of host CPU definitions * @ncpus: number of CPUs in @cpus * @models: list of CPU models that can be considered for the baseline CPU + * @features: optional NULL terminated list of allowed features * @migratable: requests non-migratable features to be removed from the re= sult * * Computes the most feature-rich CPU which is compatible with all given @@ -499,13 +500,14 @@ virCPUBaseline(virArch arch, virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models, + const char **features, bool migratable) { struct cpuArchDriver *driver; size_t i; =20 - VIR_DEBUG("arch=3D%s, ncpus=3D%u, models=3D%p, migratable=3D%d", - virArchToString(arch), ncpus, models, migratable); + VIR_DEBUG("arch=3D%s, ncpus=3D%u, models=3D%p, features=3D%p, migratab= le=3D%d", + virArchToString(arch), ncpus, models, features, migratable); if (cpus) { for (i =3D 0; i < ncpus; i++) VIR_DEBUG("cpus[%zu]=3D%p", i, cpus[i]); @@ -552,7 +554,7 @@ virCPUBaseline(virArch arch, return NULL; } =20 - return driver->baseline(cpus, ncpus, models, migratable); + return driver->baseline(cpus, ncpus, models, features, migratable); } =20 =20 diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 8c45bf8b31..81119b6aeb 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -76,6 +76,7 @@ typedef virCPUDefPtr (*virCPUArchBaseline)(virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models, + const char **features, bool migratable); =20 typedef int @@ -198,6 +199,7 @@ virCPUBaseline(virArch arch, virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models, + const char **features, bool migratable); =20 int diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index a9aa065f9f..cc7da44ac4 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -76,6 +76,7 @@ static virCPUDefPtr virCPUarmBaseline(virCPUDefPtr *cpus, unsigned int ncpus ATTRIBUTE_UNUSED, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, + const char **features ATTRIBUTE_UNUSED, bool migratable ATTRIBUTE_UNUSED) { virCPUDefPtr cpu =3D NULL; diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index c213245fc9..d562677fa3 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -770,6 +770,7 @@ static virCPUDefPtr virCPUppc64Baseline(virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, + const char **features ATTRIBUTE_UNUSED, bool migratable ATTRIBUTE_UNUSED) { struct ppc64_map *map; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 6bef4089e9..809da94117 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2467,6 +2467,7 @@ static virCPUDefPtr virCPUx86Baseline(virCPUDefPtr *cpus, unsigned int ncpus, virDomainCapsCPUModelsPtr models, + const char **features, bool migratable) { virCPUx86MapPtr map =3D NULL; @@ -2478,6 +2479,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus, bool outputVendor =3D true; const char *modelName; bool matchingNames =3D true; + virCPUDataPtr featData =3D NULL; =20 if (!(map =3D virCPUx86GetMap())) goto error; @@ -2550,6 +2552,21 @@ virCPUx86Baseline(virCPUDefPtr *cpus, model =3D NULL; } =20 + if (features) { + virCPUx86FeaturePtr feat; + + if (!(featData =3D virCPUDataNew(archs[0]))) + goto cleanup; + + for (i =3D 0; features[i]; i++) { + if ((feat =3D x86FeatureFind(map, features[i])) && + x86DataAdd(&featData->data.x86, &feat->data) < 0) + goto cleanup; + } + + x86DataIntersect(&base_model->data, &featData->data.x86); + } + if (x86DataIsEmpty(&base_model->data)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("CPUs are incompatible")); @@ -2571,6 +2588,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus, =20 cleanup: x86ModelFree(base_model); + virCPUx86DataFree(featData); =20 return cpu; =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index a85ce84404..8c40661e5a 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -6349,7 +6349,7 @@ libxlConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATA= BLE)))) goto cleanup; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b95e1f5296..e036764f92 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13179,7 +13179,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE= _UNUSED, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(baseline =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, + if (!(baseline =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NU= LL, !!(flags & VIR_CONNECT_BASELINE_CPU_MI= GRATABLE)))) goto cleanup; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3b4acaf7fe..09f17bc8f9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1536,7 +1536,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_U= NUSED, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false))) + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, f= alse))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 50cd0acfdf..c9520d4a58 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -934,7 +934,7 @@ vzConnectBaselineCPU(virConnectPtr conn, if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) goto cleanup; =20 - if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false))) + if (!(cpu =3D virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, f= alse))) goto cleanup; =20 if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && diff --git a/tests/cputest.c b/tests/cputest.c index 9b84ffea86..baf2b3c648 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -321,7 +321,7 @@ cpuTestBaseline(const void *arg) if (!(cpus =3D cpuTestLoadMultiXML(data->arch, data->name, &ncpus))) goto cleanup; =20 - baseline =3D virCPUBaseline(data->arch, cpus, ncpus, NULL, + baseline =3D virCPUBaseline(data->arch, cpus, ncpus, NULL, NULL, !!(data->flags & VIR_CONNECT_BASELINE_CPU_MI= GRATABLE)); =20 if (baseline && --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460006667169.16069484692605; Wed, 16 May 2018 01:40:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68BEBD8187; Wed, 16 May 2018 08:40:03 +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 2565998F7C; Wed, 16 May 2018 08:40:03 +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 6DC993FCFC; Wed, 16 May 2018 08:40:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkW7018385 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4F7692166BAD; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E3472166BB1 for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id EB956102EF1; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:39 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 20/22] qemu_capabilities: Introduce virQEMUCapsGetCPUFeatures 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 16 May 2018 08:40:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function creates a lost of all (or migratable only) CPU features supported by QEMU. It works by looking at the CPU model info returned by query-cpu-model-expansion QMP command. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_capabilities.c | 52 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 4 +++ 2 files changed, 56 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 77a4b4154e..e8c5940210 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2367,6 +2367,58 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, return ret; } =20 + +/** + * Get NULL terminated list of features supported by QEMU. + * + * Returns -1 on error, + * 0 on success (@features will be NULL if QEMU does not support = this), + * 1 when @features is filled in, but migratability info is not a= vailable. + */ +int +virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, + virDomainVirtType virtType, + bool migratable, + char ***features) +{ + virQEMUCapsHostCPUDataPtr data; + char **list; + size_t i; + size_t n; + int ret =3D -1; + + *features =3D NULL; + data =3D virQEMUCapsGetHostCPUData(qemuCaps, virtType); + + if (!data->info) + return 0; + + if (VIR_ALLOC_N(list, data->info->nprops + 1) < 0) + return -1; + + n =3D 0; + for (i =3D 0; i < data->info->nprops; i++) { + qemuMonitorCPUPropertyPtr prop =3D data->info->props + i; + + if (migratable && prop->migratable =3D=3D VIR_TRISTATE_BOOL_NO) + continue; + + if (VIR_STRDUP(list[n++], prop->name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(*features, list); + if (migratable && !data->info->migratability) + ret =3D 1; + else + ret =3D 0; + + cleanup: + virStringListFree(list); + return ret; +} + + struct tpmTypeToCaps { int type; virQEMUCapsFlags caps; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 6f095bfbfe..eee989559e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -529,6 +529,10 @@ typedef enum { virCPUDefPtr virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, virDomainVirtType type, virQEMUCapsHostCPUType cpuType); +int virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, + virDomainVirtType virtType, + bool migratable, + char ***features); =20 bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps, virCapsPtr caps, --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 1526460019929812.2861128521484; Wed, 16 May 2018 01:40:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2D44F56F1; Wed, 16 May 2018 08:40:17 +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 9274720155E6; Wed, 16 May 2018 08:40:17 +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 28803EEF7; Wed, 16 May 2018 08:40:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dlxK018437 for ; Wed, 16 May 2018 04:39:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 371FC2166BAE; Wed, 16 May 2018 08:39:47 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 164332166BAD for ; Wed, 16 May 2018 08:39:47 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id EF9F4102EF2; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:40 +0200 Message-Id: <73706d940919cff2cc5ae18bef47e941edab81af.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 21/22] qemu: Implement virConnectBaselineHypervisorCPU 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 16 May 2018 08:40:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_driver.c | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e036764f92..d702e8a8ff 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13206,6 +13206,96 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUT= E_UNUSED, } =20 =20 +static char * +qemuConnectBaselineHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *archStr, + const char *machine, + const char *virttypeStr, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D conn->privateData; + virCPUDefPtr *cpus =3D NULL; + virQEMUCapsPtr qemuCaps =3D NULL; + virArch arch; + virDomainVirtType virttype; + virDomainCapsCPUModelsPtr cpuModels; + bool migratable; + virCPUDefPtr cpu =3D NULL; + char *cpustr =3D NULL; + char **features =3D NULL; + + virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | + VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); + + if (virConnectBaselineHypervisorCPUEnsureACL(conn) < 0) + goto cleanup; + + migratable =3D !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE); + + if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_AUTO))) + goto cleanup; + + qemuCaps =3D virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, + emulator, + archStr, + virttypeStr, + machine, + &arch, &virttype, NULL); + if (!qemuCaps) + goto cleanup; + + if (!(cpuModels =3D virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) = || + cpuModels->nmodels =3D=3D 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("QEMU '%s' does not support any CPU models for " + "virttype '%s'"), + virQEMUCapsGetBinary(qemuCaps), + virDomainVirtTypeToString(virttype)); + goto cleanup; + } + + if (ARCH_IS_X86(arch)) { + int rc =3D virQEMUCapsGetCPUFeatures(qemuCaps, virttype, + migratable, &features); + if (rc < 0) + goto cleanup; + if (features && rc =3D=3D 0) { + /* We got only migratable features from QEMU if we asked for t= hem, + * no further filtering in virCPUBaseline is desired. */ + migratable =3D false; + } + + if (!(cpu =3D virCPUBaseline(arch, cpus, ncpus, cpuModels, + (const char **)features, migratable))) + goto cleanup; + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("computing baseline hypervisor CPU is not support= ed " + "for arch %s"), virArchToString(arch)); + goto cleanup; + } + + cpu->fallback =3D VIR_CPU_FALLBACK_FORBID; + + if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && + virCPUExpandFeatures(arch, cpu) < 0) + goto cleanup; + + cpustr =3D virCPUDefFormat(cpu, NULL); + + cleanup: + virCPUDefListFree(cpus); + virCPUDefFree(cpu); + virObjectUnref(qemuCaps); + virStringListFree(features); + + return cpustr; +} + + static int qemuDomainGetJobInfoMigrationStats(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -21386,6 +21476,7 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainSetBlockThreshold =3D qemuDomainSetBlockThreshold, /* 3.2.0 */ .domainSetLifecycleAction =3D qemuDomainSetLifecycleAction, /* 3.9.0 */ .connectCompareHypervisorCPU =3D qemuConnectCompareHypervisorCPU, /* 4= .4.0 */ + .connectBaselineHypervisorCPU =3D qemuConnectBaselineHypervisorCPU, /*= 4.4.0 */ }; =20 =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 08:23:32 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=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 15264600233919.883690611409065; Wed, 16 May 2018 01:40:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DE4573553; Wed, 16 May 2018 08:40:21 +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 BCAD520155E6; Wed, 16 May 2018 08:40:20 +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 16A1D3D381; Wed, 16 May 2018 08:40:20 +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 w4G8dl8U018427 for ; Wed, 16 May 2018 04:39:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id E1AE76B59E; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0BB5D74A9 for ; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id F3924102EF4; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:41 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 22/22] news: Mention new CPU related APIs 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 16 May 2018 08:40:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- docs/news.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index 7d40e85b9a..bd7885e91a 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -54,6 +54,15 @@ a QEMU virtual machine. + + + Introduce new virConnectBaselineHypervisorCPU and virConnectBase= lineHypervisorCPU APIs + + + Unlike the old virConnectBaselineCPU and virConnectBaselineCPU A= PIs, + both new APIs consider capabilities of a specific hypervisor. + +
--=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list