[libvirt] [RFC PATCH 3/4] powerpc: Add support for qemu-system-ppc64 in qemu capabilities

Daniel P. Berrange berrange at redhat.com
Mon Oct 10 09:58:42 UTC 2011


On Sat, Oct 08, 2011 at 12:17:18AM +0530, Prerna Saxena wrote:
> This patch has a small parser which correctly interprets 
> qemu-system-ppc64 output for a specific query.
> This code is independent for powerpc and largely does not interfere
> with x86 implementation.
> 
> ---
>  src/qemu/qemu_capabilities.c |   64 ++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 64 insertions(+), 0 deletions(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 850d46e..5bdb304 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -181,6 +181,7 @@ static const struct qemu_arch_info const arch_info_hvm[] = {
>      {  "mipsel", 32, NULL, "qemu-system-mipsel", NULL, NULL, 0 },
>      {  "sparc",  32, NULL, "qemu-system-sparc",  NULL, NULL, 0 },
>      {  "ppc",    32, NULL, "qemu-system-ppc",    NULL, NULL, 0 },
> +    {  "ppc64",    64, NULL, "qemu-system-ppc64",    NULL, NULL, 0 },
>      {  "itanium", 64, NULL, "qemu-system-ia64",  NULL, NULL, 0 },
>      {  "s390x",  64, NULL, "qemu-system-s390x",  NULL, NULL, 0 },
>  };
> @@ -473,6 +474,67 @@ error:
>      return -1;
>  }
>  
> +/* ppc64 parser.
> + * Format : PowerPC <machine> <description>
> + */
> +static int
> +qemuCapsParsePPCModels(const char *output,
> +                       unsigned int *retcount,
> +                       const char ***retcpus)
> +{
> +    const char *p = output;
> +    const char *next;
> +    unsigned int count = 0;
> +    const char **cpus = NULL;
> +    int i;
> +    do {
> +        const char *t;
> +
> +        if ((next = strchr(p, '\n')))
> +            next++;
> +
> +        if (!STRPREFIX(p, "PowerPC "))
> +            continue;
> +
> +        /* Skip the preceding sub-string "PowerPC " */
> +        p += 8;
> +
> +        /*Malformed string, does not obey the format 'PowerPC <model> <desc>'*/
> +        if (!(t = strchr(p, ' ')) || (next && t >= next))
> +            continue;
> +
> +        if (*p == '\0' || *p == '\n')
> +            continue;
> +
> +        if (retcpus) {
> +            unsigned int len;
> +
> +            if (VIR_REALLOC_N(cpus, count + 1) < 0)
> +                goto error;
> +
> +            if (t)
> +                len = t - p - 1;
> +
> +            if (!(cpus[count] = strndup(p, len)))
> +                goto error;
> +        }
> +        count++;
> +    } while ((p = next));
> +
> +    if (retcount)
> +        *retcount = count;
> +    if (retcpus)
> +        *retcpus = cpus;
> +    return 0;
> +
> +error:
> +    if (cpus) {
> +        for (i = 0; i < count; i++)
> +            VIR_FREE(cpus[i]);
> +    }
> +    VIR_FREE(cpus);
> +    return -1;
> +}
>  
>  int
>  qemuCapsProbeCPUModels(const char *qemu,
> @@ -493,6 +555,8 @@ qemuCapsProbeCPUModels(const char *qemu,
>  
>      if (STREQ(arch, "i686") || STREQ(arch, "x86_64"))
>          parse = qemuCapsParseX86Models;
> +    else if (STREQ(arch, "ppc64"))
> +        parse = qemuCapsParsePPCModels;
>      else {
>          VIR_DEBUG("don't know how to parse %s CPU models", arch);
>          return 0;

Same question about whether we should include 'ppc' in the arch test
here too ?

ACK to the rest of the code anyway.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list