qemu-block
[Top][All Lists]
Advanced

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

Re: [Qemu-block] [Qemu-devel] [PATCH v2 01/49] opts: produce valid comma


From: Eric Blake
Subject: Re: [Qemu-block] [Qemu-devel] [PATCH v2 01/49] opts: produce valid command line in qemu_opts_print
Date: Fri, 4 Sep 2015 14:20:54 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0

On 08/21/2015 09:36 AM, Kővágó, Zoltán wrote:
> This will let us print options in a format that the user would actually
> write it on the command line (foo=bar,baz=asd,etc=def), without
> prepending a spurious comma at the beginning of the list, or quoting
> values unnecessarily.  This patch provides the following changes:
> * write id=, if the option has an id
> * do not print separator before the first element
> * do not quote string arguments
> * properly escape commas (,) for QEMU
> 
> Reviewed-by: Markus Armbruster <address@hidden>
> Reviewed-by: Stefan Hajnoczi <address@hidden>
> Reviewed-by: Marc-André Lureau <address@hidden>
> Signed-off-by: Kővágó, Zoltán <address@hidden>
> ---

> +++ b/util/qemu-option.c
> @@ -730,14 +730,35 @@ void qemu_opts_del(QemuOpts *opts)
>      g_free(opts);
>  }
>  
> -void qemu_opts_print(QemuOpts *opts, const char *sep)
> +/* print value, escaping any commas in value */
> +static void escaped_print(const char *value)
> +{
> +    const char *ptr;
> +
> +    for (ptr = value; *ptr; ++ptr) {
> +        if (*ptr == ',') {
> +            putchar(',');
> +        }
> +        putchar(*ptr);
> +    }

I guess this not in a hot path.  (If it were, I might suggest using
strchr() to skip to the next command, and fwrite() to output blocks of
data between commas, rather than putchar() at a time; but unless it
shows up in a benchmark that might be premature optimization)

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]