[libvirt] [PATCH v3 3/8] Handle arbitrary qemu command-lines in qemuParseCommandLine.

Daniel P. Berrange berrange at redhat.com
Wed Jul 7 11:41:18 UTC 2010


On Fri, Jul 02, 2010 at 11:18:20AM -0400, Chris Lalancette wrote:
> Now that we have the ability to specify arbitrary qemu
> command-line parameters in the XML, use it to handle unknown
> command-line parameters when doing a native-to-xml conversion.
> 
> Changes since v1:
>  - Rename num_extra to num_args
>  - Fix up a memory leak on an error path
> 
> Changes since v2:
>  - Add a VIR_WARN when adding the argument via qemu:arg
> 
> Signed-off-by: Chris Lalancette <clalance at redhat.com>
> ---
>  src/qemu/qemu_conf.c |   30 ++++++++++++++++++++++++------
>  1 files changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 151fa68..c7ee278 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -5853,6 +5853,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
>      const char **nics = NULL;
>      int video = VIR_DOMAIN_VIDEO_TYPE_CIRRUS;
>      int nvirtiodisk = 0;
> +    qemuDomainCmdlineDefPtr cmd;
>  
>      if (!progargv[0]) {
>          qemuReportError(VIR_ERR_INTERNAL_ERROR,
> @@ -5863,6 +5864,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
>      if (VIR_ALLOC(def) < 0)
>          goto no_memory;
>  
> +    /* allocate the cmdlinedef up-front; if it's unused, we'll free it later */
> +    if (VIR_ALLOC(cmd) < 0)
> +        goto no_memory;
> +
>      virUUIDGenerate(def->uuid);
>  
>      def->id = -1;
> @@ -6287,12 +6292,17 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
>          } else if (STREQ(arg, "-S")) {
>              /* ignore, always added by libvirt */
>          } else {
> -            VIR_WARN("unknown QEMU argument '%s' during conversion", arg);
> -#if 0
> -            qemuReportError(VIR_ERR_INTERNAL_ERROR,
> -                            _("unknown argument '%s'"), arg);
> -            goto error;
> -#endif
> +            /* something we can't yet parse.  Add it to the qemu namespace
> +             * cmdline/environment advanced options and hope for the best
> +             */
> +            VIR_WARN("unknown QEMU argument '%s', adding to the qemu namespace",
> +                     arg);

Lets just make this a VIR_INFO now - no need to log this at the
default level, it'll just annoy people using this new feature.

> +            if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0)
> +                goto no_memory;
> +            cmd->args[cmd->num_args] = strdup(arg);
> +            if (cmd->args[cmd->num_args] == NULL)
> +                goto no_memory;
> +            cmd->num_args++;
>          }
>      }
>  
> @@ -6352,11 +6362,19 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
>      if (virDomainDefAddImplicitControllers(def) < 0)
>          goto error;
>  
> +    if (cmd->num_args || cmd->num_env) {
> +        def->ns = caps->ns;
> +        def->namespaceData = cmd;
> +    }
> +    else
> +        VIR_FREE(cmd);
> +
>      return def;
>  
>  no_memory:
>      virReportOOMError();
>  error:
> +    VIR_FREE(cmd);
>      virDomainDefFree(def);
>      VIR_FREE(nics);
>      return NULL;

ACK, with the logging level change

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list