From: Li Yang <liyang.f...@cn.fujitsu.com> cpu-compare command can compare host CPU with a CPU described by an XML file, I think it should belong to host group, so I moved the related source from virsh-domain.c to virsh-host.c
Signed-off-by: Li Yang <liyang.f...@cn.fujitsu.com> --- tools/virsh-domain.c | 100 -------------------------------------------------- tools/virsh-host.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 100 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 8fc6c59..53c5d95 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6013,100 +6013,6 @@ cleanup: } /* - * "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[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("file containing an XML CPU description") - }, - {.name = NULL} -}; - -static bool -cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) -{ - const char *from = NULL; - bool ret = false; - char *buffer; - int result; - char *snippet = NULL; - - xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; - xmlNodePtr node; - - 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(ctl->conn, snippet, 0); - - 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-stats" command */ static const vshCmdInfo info_cpu_stats[] = { @@ -10407,12 +10313,6 @@ const vshCmdDef domManagementCmds[] = { .flags = 0 }, #endif - {.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 b69de7c..2d69450 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -304,6 +304,100 @@ no_memory: } /* + * "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[] = { + {.name = "file", + .type = VSH_OT_DATA, + .flags = VSH_OFLAG_REQ, + .help = N_("file containing an XML CPU description") + }, + {.name = NULL} +}; + +static bool +cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) +{ + const char *from = NULL; + bool ret = false; + char *buffer; + int result; + char *snippet = NULL; + + xmlDocPtr xml = NULL; + xmlXPathContextPtr ctxt = NULL; + xmlNodePtr node; + + 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(ctl->conn, snippet, 0); + + 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; +} + +/* * "maxvcpus" command */ static const vshCmdInfo info_maxvcpus[] = { @@ -1072,6 +1166,12 @@ const vshCmdDef hostAndHypervisorCmds[] = { .info = info_cpu_baseline, .flags = 0 }, + {.name = "cpu-compare", + .handler = cmdCPUCompare, + .opts = opts_cpu_compare, + .info = info_cpu_compare, + .flags = 0 + }, {.name = "maxvcpus", .handler = cmdMaxvcpus, .opts = opts_maxvcpus, -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list