All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leandro Dorileo <l@dorileo.org>
To: Chunyan Liu <cyliu@suse.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters
Date: Tue, 25 Mar 2014 19:13:14 +0000	[thread overview]
Message-ID: <20140325191314.GE29429@dorilex> (raw)
In-Reply-To: <1395396763-26081-10-git-send-email-cyliu@suse.com>

On Fri, Mar 21, 2014 at 06:12:20PM +0800, Chunyan Liu wrote:
> For later merge .create_opts of drv and proto_drv in qemu-img commands.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>

Reviewed-by: Leandro Dorileo <l@dorileo.org>


> ---
> Changes:
>   * Following Eric's suggestion, qemu_opts_append() will accept a pair of
>     parameters (QEMUOptionParameter and QemuOpts), to handle the inconsistency
>     that some driver uses QemuOpts while some driver uses QEMUOptionParameter.
>   * using g_realloc of first parameter 'dst' and return it, instead of malloc
>     a new list and copy data from all parameters to the new list, and return
>     the new malloced list. Solving memory free effort for multiple append(s),
>     and no naming problem as in previous version.
> 
>  include/qemu/option.h |  5 ++++
>  util/qemu-option.c    | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 70 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index fd6f075..120c998 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -175,5 +175,10 @@ void qemu_opts_print_help(QemuOptsList *list);
>  void qemu_opts_free(QemuOptsList *list);
>  QEMUOptionParameter *opts_to_params(QemuOpts *opts);
>  QemuOptsList *params_to_opts(QEMUOptionParameter *list);
> +/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
> + */
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> +                               QemuOptsList *list,
> +                               QEMUOptionParameter *param);
>  
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 4bdcfbf..6c304b2 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -1477,3 +1477,68 @@ void qemu_opts_free(QemuOptsList *list)
>  
>      g_free(list);
>  }
> +
> +/* Realloc dst option list and append options either from an option list (list)
> + * or an QEMUOptionParameter (param) to it. dst could be NULL or a malloced list.
> + * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
> + */
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> +                               QemuOptsList *list,
> +                               QEMUOptionParameter *param)
> +{
> +    size_t num_opts, num_dst_opts;
> +    QemuOptsList *tmp_list = NULL;
> +    QemuOptDesc *desc;
> +    bool need_init = false;
> +
> +    assert(!(list && param));
> +    if (!param &&!list) {
> +        return dst;
> +    }
> +
> +    if (param) {
> +        list = tmp_list = params_to_opts(param);
> +    }
> +
> +    /* If dst is NULL, after realloc, some area of dst should be initialized
> +     * before adding options to it.
> +     */
> +    if (!dst) {
> +        need_init = true;
> +    }
> +
> +    num_opts = count_opts_list(dst);
> +    num_dst_opts = num_opts;
> +    num_opts += count_opts_list(list);
> +    dst = g_realloc(dst, sizeof(QemuOptsList) +
> +                    (num_opts + 1) * sizeof(QemuOptDesc));
> +    if (need_init) {
> +        dst->name = NULL;
> +        dst->implied_opt_name = NULL;
> +        QTAILQ_INIT(&dst->head);
> +        dst->mallocd = true;
> +    }
> +    dst->desc[num_dst_opts].name = NULL;
> +
> +    /* (const char *) members of result dst are malloced, need free. */
> +    assert(dst->mallocd);
> +    /* append list->desc to dst->desc */
> +    if (list) {
> +        desc = list->desc;
> +        while (desc && desc->name) {
> +            if (find_desc_by_name(dst->desc, desc->name) == NULL) {
> +                dst->desc[num_dst_opts].name = g_strdup(desc->name);
> +                dst->desc[num_dst_opts].type = desc->type;
> +                dst->desc[num_dst_opts].help = g_strdup(desc->help);
> +                dst->desc[num_dst_opts].def_value_str =
> +                                         g_strdup(desc->def_value_str);
> +                num_dst_opts++;
> +                dst->desc[num_dst_opts].name = NULL;
> +            }
> +            desc++;
> +        }
> +    }
> +
> +    g_free(tmp_list);
> +    return dst;
> +}
> -- 
> 1.7.12.4
> 
> 

-- 
Leandro Dorileo

  reply	other threads:[~2014-03-25 19:14 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling Chunyan Liu
2014-03-21 23:16   ` Eric Blake
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 02/32] add def_value_str to QemuOptDesc Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options Chunyan Liu
2014-03-21 23:27   ` Eric Blake
2014-03-24  3:18     ` Chun Yan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *) Chunyan Liu
2014-03-25 19:00   ` Leandro Dorileo
2014-03-25 19:23   ` Eric Blake
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 05/32] move qemu_opt_del ahead for later calling Chunyan Liu
2014-03-25 19:29   ` Eric Blake
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 06/32] add qemu_opt_get_*_del functions for replace work Chunyan Liu
2014-03-25 20:33   ` Eric Blake
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help Chunyan Liu
2014-03-25 19:07   ` Leandro Dorileo
2014-03-25 20:43   ` Eric Blake
2014-03-26  2:58     ` Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
2014-03-25 21:35   ` Eric Blake
2014-03-26  3:26     ` Chunyan Liu
2014-03-26  6:30     ` Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters Chunyan Liu
2014-03-25 19:13   ` Leandro Dorileo [this message]
2014-03-25 21:40   ` Eric Blake
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 10/32] check NULL input for qemu_opts_del Chunyan Liu
2014-03-25 21:41   ` Eric Blake
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf Chunyan Liu
2014-03-25 20:10   ` Leandro Dorileo
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend Chunyan Liu
2014-03-25 19:25   ` Leandro Dorileo
2014-03-26  7:37     ` Chunyan Liu
2014-03-27  7:27       ` Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 13/32] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts Chunyan Liu
2014-03-25 19:17   ` Leandro Dorileo
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 15/32] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 16/32] gluster.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 17/32] iscsi.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 18/32] qcow.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 19/32] qcow2.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 20/32] qed.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 21/32] raw-posix.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 22/32] raw-win32.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 23/32] raw_bsd.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 24/32] rbd.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 25/32] sheepdog.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 26/32] ssh.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 27/32] vdi.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 28/32] vhdx.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 29/32] vmdk.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 30/32] vpc.c: " Chunyan Liu
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter Chunyan Liu
2014-03-25 18:02   ` Leandro Dorileo
2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 32/32] cleanup tmp 'mallocd' member from QemuOptsList Chunyan Liu
2014-03-25 18:09 ` [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Leandro Dorileo
2014-03-25 20:22   ` Leandro Dorileo
2014-03-26 15:18   ` Stefan Hajnoczi
2014-03-27  7:20     ` Chunyan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140325191314.GE29429@dorilex \
    --to=l@dorileo.org \
    --cc=cyliu@suse.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.