[libvirt] [PATCH v2 9/9] cpu-baseline command for virsh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 tools/virsh.c   |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |    8 ++++++
 2 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 7db48d9..8337477 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7025,6 +7025,77 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+/*
+ * "cpu-baseline" command
+ */
+static const vshCmdInfo info_cpu_baseline[] = {
+    {"help", gettext_noop("compute baseline CPU")},
+    {"desc", gettext_noop("Compute baseline CPU for a set of given CPUs.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_cpu_baseline[] = {
+    {"file", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("file containing XML CPU descriptions")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
+{
+    char *from;
+    int found;
+    int ret = TRUE;
+    char *buffer;
+    char *p;
+    char *result = NULL;
+    const char **list = NULL;
+    unsigned int count = 0;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    from = vshCommandOptString(cmd, "file", &found);
+    if (!found)
+        return FALSE;
+
+    if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+        return FALSE;
+
+    p = buffer;
+    while ((p = strstr(p, "<cpu>"))) {
+        list = vshRealloc(ctl, list, sizeof(char *) * (count + 1));
+        list[count++] = p;
+
+        if ((p = strstr(p, "</cpu>"))) {
+            p += strlen("</cpu>");
+            if (*p != '\0') {
+                *p = '\0';
+                p++;
+            }
+        }
+    }
+
+    if (count == 0) {
+        vshError(ctl, _("No host CPU specified in '%s'"), from);
+        ret = FALSE;
+        goto cleanup;
+    }
+
+    result = virConnectBaselineCPU(ctl->conn, list, count, 0);
+
+    if (result)
+        vshPrint(ctl, "%s", result);
+    else
+        ret = FALSE;
+
+cleanup:
+    VIR_FREE(result);
+    VIR_FREE(list);
+    VIR_FREE(buffer);
+
+    return ret;
+}
+
 /* Common code for the edit / net-edit / pool-edit functions which follow. */
 static char *
 editWriteToTempFile (vshControl *ctl, const char *doc)
@@ -7396,6 +7467,7 @@ static const vshCmdDef commands[] = {
 #ifndef WIN32
     {"console", cmdConsole, opts_console, info_console},
 #endif
+    {"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline},
     {"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare},
     {"create", cmdCreate, opts_create, info_create},
     {"start", cmdStart, opts_start, info_start},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 10f622f..8f6df19 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -213,6 +213,14 @@ crashed.
 Prints the available amount of memory on the machine or within a
 NUMA cell if I<cellno> is provided.
 
+=item B<cpu-baseline> I<FILE>
+
+Compute baseline CPU which will be supported by all host CPUs given in <file>.
+The list of host CPUs is built by extracting all <cpu> elements from the
+<file>. Thus, the <file> can contain either a set of <cpu> elements separated
+by new lines or even a set of complete <capabilities> elements printed by
+B<capabilities> command.
+
 =item B<cpu-compare> I<FILE>
 
 Compare CPU definition from XML <file> with host CPU. The XML <file> may
-- 
1.6.6.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]