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 <jdenemar(a)redhat.com>
---
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;
}
-/*
- * "cpu-compare" command
- */
-static const vshCmdInfo info_cpu_compare[] = {
- {.name = "help",
- .data = N_("compare host CPU with a CPU described by an XML file")
- },
- {.name = "desc",
- .data = N_("compare CPU with host CPU")
- },
- {.name = NULL}
-};
-
-static const vshCmdOptDef opts_cpu_compare[] = {
- VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")),
- {.name = "error",
- .type = VSH_OT_BOOL,
- .help = N_("report error if CPUs are incompatible")
- },
- {.name = NULL}
-};
-
-static bool
-cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
-{
- const char *from = NULL;
- bool ret = false;
- char *buffer;
- int result;
- char *snippet = NULL;
- unsigned int flags = 0;
- xmlDocPtr xml = NULL;
- xmlXPathContextPtr ctxt = NULL;
- xmlNodePtr node;
- virshControlPtr priv = ctl->privData;
-
- if (vshCommandOptBool(cmd, "error"))
- flags |= 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 = virXMLParseStringCtxt(buffer, from, &ctxt)))
- goto cleanup;
-
- if ((node = virXPathNode("/cpu|"
- "/domain/cpu|"
- "/capabilities/host/cpu", ctxt))) {
- if (!(snippet = virXMLNodeToString(xml, node))) {
- vshSaveLibvirtError();
- goto cleanup;
- }
- } else {
- vshError(ctl, _("File '%s' does not contain a <cpu> element or
is not "
- "a valid domain or capabilities XML"), from);
- goto cleanup;
- }
-
- result = 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 = true;
-
- cleanup:
- VIR_FREE(buffer);
- VIR_FREE(snippet);
- xmlXPathFreeContext(ctxt);
- xmlFreeDoc(xml);
-
- return ret;
-}
-
-/*
- * "cpu-baseline" command
- */
-static const vshCmdInfo info_cpu_baseline[] = {
- {.name = "help",
- .data = N_("compute baseline CPU")
- },
- {.name = "desc",
- .data = N_("Compute baseline CPU for a set of given CPUs.")
- },
- {.name = NULL}
-};
-
-static const vshCmdOptDef opts_cpu_baseline[] = {
- VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")),
- {.name = "features",
- .type = VSH_OT_BOOL,
- .help = N_("Show features that are part of the CPU model type")
- },
- {.name = "migratable",
- .type = VSH_OT_BOOL,
- .help = N_("Do not include features that block migration")
- },
- {.name = NULL}
-};
-
-static bool
-cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
-{
- const char *from = NULL;
- bool ret = false;
- char *buffer;
- char *result = NULL;
- char **list = NULL;
- unsigned int flags = 0;
- int count = 0;
-
- xmlDocPtr xml = NULL;
- xmlNodePtr *node_list = NULL;
- xmlXPathContextPtr ctxt = NULL;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
- size_t i;
- virshControlPtr priv = ctl->privData;
-
- if (vshCommandOptBool(cmd, "features"))
- flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES;
- if (vshCommandOptBool(cmd, "migratable"))
- flags |= 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, "<container>", buffer,
"</container>", NULL);
- if (virBufferError(&buf))
- goto no_memory;
-
- VIR_FREE(buffer);
- buffer = virBufferContentAndReset(&buf);
-
-
- if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt)))
- goto cleanup;
-
- if ((count = virXPathNodeSet("//cpu[not(ancestor::cpus)]",
- ctxt, &node_list)) == -1)
- goto cleanup;
-
- if (count == 0) {
- vshError(ctl, _("No host CPU specified in '%s'"), from);
- goto cleanup;
- }
-
- list = vshCalloc(ctl, count, sizeof(const char *));
-
- for (i = 0; i < count; i++) {
- if (!(list[i] = virXMLNodeToString(xml, node_list[i]))) {
- vshSaveLibvirtError();
- goto cleanup;
- }
- }
-
- result = virConnectBaselineCPU(priv->conn,
- (const char **)list, count, flags);
-
- if (result) {
- vshPrint(ctl, "%s", result);
- ret = true;
- }
-
- cleanup:
- xmlXPathFreeContext(ctxt);
- xmlFreeDoc(xml);
- VIR_FREE(result);
- if (list != NULL && count > 0) {
- for (i = 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 = false;
- goto cleanup;
-}
-
/*
* "cpu-stats" command
*/
@@ -13942,18 +13731,6 @@ const vshCmdDef domManagementCmds[] = {
.flags = 0
},
#endif
- {.name = "cpu-baseline",
- .handler = cmdCPUBaseline,
- .opts = opts_cpu_baseline,
- .info = info_cpu_baseline,
- .flags = 0
- },
- {.name = "cpu-compare",
- .handler = cmdCPUCompare,
- .opts = opts_cpu_compare,
- .info = info_cpu_compare,
- .flags = 0
- },
{.name = "cpu-stats",
.handler = cmdCPUStats,
.opts = 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"
/*
* "capabilities" command
@@ -1105,6 +1106,217 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return true;
}
+/*
+ * "cpu-compare" command
+ */
+static const vshCmdInfo info_cpu_compare[] = {
+ {.name = "help",
+ .data = N_("compare host CPU with a CPU described by an XML file")
+ },
+ {.name = "desc",
+ .data = N_("compare CPU with host CPU")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_cpu_compare[] = {
+ VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")),
+ {.name = "error",
+ .type = VSH_OT_BOOL,
+ .help = N_("report error if CPUs are incompatible")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
+{
+ const char *from = NULL;
+ bool ret = false;
+ char *buffer;
+ int result;
+ char *snippet = NULL;
+ unsigned int flags = 0;
+ xmlDocPtr xml = NULL;
+ xmlXPathContextPtr ctxt = NULL;
+ xmlNodePtr node;
+ virshControlPtr priv = ctl->privData;
+
+ if (vshCommandOptBool(cmd, "error"))
+ flags |= 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 = virXMLParseStringCtxt(buffer, from, &ctxt)))
+ goto cleanup;
+
+ if ((node = virXPathNode("/cpu|"
+ "/domain/cpu|"
+ "/capabilities/host/cpu", ctxt))) {
+ if (!(snippet = virXMLNodeToString(xml, node))) {
+ vshSaveLibvirtError();
+ goto cleanup;
+ }
+ } else {
+ vshError(ctl, _("File '%s' does not contain a <cpu> element or
is not "
+ "a valid domain or capabilities XML"), from);
+ goto cleanup;
+ }
+
+ result = 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 = true;
+
+ cleanup:
+ VIR_FREE(buffer);
+ VIR_FREE(snippet);
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(xml);
+
+ return ret;
+}
+
+/*
+ * "cpu-baseline" command
+ */
+static const vshCmdInfo info_cpu_baseline[] = {
+ {.name = "help",
+ .data = N_("compute baseline CPU")
+ },
+ {.name = "desc",
+ .data = N_("Compute baseline CPU for a set of given CPUs.")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_cpu_baseline[] = {
+ VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")),
+ {.name = "features",
+ .type = VSH_OT_BOOL,
+ .help = N_("Show features that are part of the CPU model type")
+ },
+ {.name = "migratable",
+ .type = VSH_OT_BOOL,
+ .help = N_("Do not include features that block migration")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
+{
+ const char *from = NULL;
+ bool ret = false;
+ char *buffer;
+ char *result = NULL;
+ char **list = NULL;
+ unsigned int flags = 0;
+ int count = 0;
+
+ xmlDocPtr xml = NULL;
+ xmlNodePtr *node_list = NULL;
+ xmlXPathContextPtr ctxt = NULL;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ size_t i;
+ virshControlPtr priv = ctl->privData;
+
+ if (vshCommandOptBool(cmd, "features"))
+ flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES;
+ if (vshCommandOptBool(cmd, "migratable"))
+ flags |= 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, "<container>", buffer,
"</container>", NULL);
+ if (virBufferError(&buf))
+ goto no_memory;
+
+ VIR_FREE(buffer);
+ buffer = virBufferContentAndReset(&buf);
+
+
+ if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt)))
+ goto cleanup;
+
+ if ((count = virXPathNodeSet("//cpu[not(ancestor::cpus)]",
+ ctxt, &node_list)) == -1)
+ goto cleanup;
+
+ if (count == 0) {
+ vshError(ctl, _("No host CPU specified in '%s'"), from);
+ goto cleanup;
+ }
+
+ list = vshCalloc(ctl, count, sizeof(const char *));
+
+ for (i = 0; i < count; i++) {
+ if (!(list[i] = virXMLNodeToString(xml, node_list[i]))) {
+ vshSaveLibvirtError();
+ goto cleanup;
+ }
+ }
+
+ result = virConnectBaselineCPU(priv->conn,
+ (const char **)list, count, flags);
+
+ if (result) {
+ vshPrint(ctl, "%s", result);
+ ret = true;
+ }
+
+ cleanup:
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(xml);
+ VIR_FREE(result);
+ if (list != NULL && count > 0) {
+ for (i = 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 = false;
+ goto cleanup;
+}
+
/*
* "cpu-models" command
*/
@@ -1388,6 +1600,18 @@ const vshCmdDef hostAndHypervisorCmds[] = {
.info = info_capabilities,
.flags = 0
},
+ {.name = "cpu-baseline",
+ .handler = cmdCPUBaseline,
+ .opts = opts_cpu_baseline,
+ .info = info_cpu_baseline,
+ .flags = 0
+ },
+ {.name = "cpu-compare",
+ .handler = cmdCPUCompare,
+ .opts = opts_cpu_compare,
+ .info = info_cpu_compare,
+ .flags = 0
+ },
{.name = "cpu-models",
.handler = cmdCPUModelNames,
.opts = opts_cpu_models,
--
2.17.0