[libvirt] [PATCH 3/6] Deal with CPU models in []

Eric Blake eblake at redhat.com
Fri Apr 16 19:48:20 UTC 2010


On 04/16/2010 11:01 AM, Jiri Denemark wrote:
> Qemu committed a patch which list some CPU names in [] when asked for
> supported CPUs (qemu -cpu ?). Yet, it needs such CPUs to be passed
> without those square braces. When probing for supported CPU models, we
> can just strip the square braces and pretend we have never seen them.
> ---
>  src/qemu/qemu_conf.c |   17 +++++++++++++----
>  1 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 0cbedf2..8577ff1 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -628,7 +628,9 @@ typedef int
>                         const char ***retcpus);
>  
>  /* Format:
> - * <arch> <model>
> + *      <arch> <model>
> + * recent qemu encloses some model names in []:

This comment can go out of date.  Is it better to write something a bit
more time neutral, as in:

qemu version x.y.z encloses some model names in []:

> + *      <arch> [<model>]
>   */
>  static int
>  qemudParseX86Models(const char *output,
> @@ -661,15 +663,22 @@ qemudParseX86Models(const char *output,
>              continue;
>  
>          if (retcpus) {
> +            unsigned int len;
> +
>              if (VIR_REALLOC_N(cpus, count + 1) < 0)
>                  goto error;
>  
>              if (next)
> -                cpus[count] = strndup(p, next - p - 1);
> +                len = next - p - 1;
>              else
> -                cpus[count] = strdup(p);
> +                len = strlen(p);
> +
> +            if (len > 2 && *p == '[' && p[len - 1] == ']') {
> +                p++;
> +                len -= 2;
> +            }
>  
> -            if (!cpus[count])
> +            if (!(cpus[count] = strndup(p, len)))
>                  goto error;

ACK.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100416/1486f13b/attachment-0001.sig>


More information about the libvir-list mailing list