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

Daniel Veillard veillard at redhat.com
Thu Feb 11 17:09:08 UTC 2010


On Thu, Feb 11, 2010 at 04:43:59PM +0100, Jiri Denemark wrote:
> Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
> ---
>  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++;
> +            }
> +        }
> +    }

  Aye aye aye ...  I understand what you're trying to do but I think
this is a bit weird  ... I think we should be able to come with an
alternative, cleaner based on parsing the content as an XML well
balanced fragment and then reserialize all cpu elements found.
  Your scheme would explode for example if we tried to add a <cpu>
element as one possible child of <cpu> or if we added attributes to
<cpu>, it's too fragile. I can think the other parts can be commited
independantly anyway.

> +    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

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list