[libvirt] [PATCH] virsh: Move 'cpu-baseline' to host command group

Li Yang liyang.fnst at cn.fujitsu.com
Fri Apr 25 02:05:28 UTC 2014


As manual said, 'cpu-baseline' isn't specific to a domain,
it should not belong to domain command group, and it's
used for host usually, so move it to host command group.

Signed-off-by: Li Yang <liyang.fnst at cn.fujitsu.com>
---
 tools/virsh-domain.c |  115 -------------------------------------------------
 tools/virsh-host.c   |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 115 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 73414f8..16a8854 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6223,115 +6223,6 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
     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[] = {
-    {.name = "file",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = 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 = 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;
-
-    if (vshCommandOptBool(cmd, "features"))
-        flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES;
-
-    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(ctl->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
@@ -11472,12 +11363,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,
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index cac6086..8273654 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
@@ -939,6 +940,115 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
     goto cleanup;
 }
 
+/*
+ * "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[] = {
+    {.name = "file",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = 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 = 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;
+
+    if (vshCommandOptBool(cmd, "features"))
+        flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES;
+
+    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(ctl->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;
+}
 const vshCmdDef hostAndHypervisorCmds[] = {
     {.name = "capabilities",
      .handler = cmdCapabilities,
@@ -952,6 +1062,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_cpu_models,
      .flags = 0
     },
+    {.name = "cpu-baseline",
+     .handler = cmdCPUBaseline,
+     .opts = opts_cpu_baseline,
+     .info = info_cpu_baseline,
+     .flags = 0
+    },
     {.name = "freecell",
      .handler = cmdFreecell,
      .opts = opts_freecell,
-- 
1.7.1




More information about the libvir-list mailing list