From nobody Wed May 14 02:32:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 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