qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH V4 09/10] Use QemuOpts support in block layer
Date: Fri, 26 Oct 2012 11:51:32 +0200	[thread overview]
Message-ID: <20121026095132.GF19272@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1351169848-28223-10-git-send-email-wdongxu@linux.vnet.ibm.com>

On Thu, Oct 25, 2012 at 08:57:27PM +0800, Dong Xu Wang wrote:
> @@ -177,9 +177,7 @@ struct BlockDriver {
>          unsigned long int req, void *buf,
>          BlockDriverCompletionFunc *cb, void *opaque);
>  
> -    /* List of options for creating images, terminated by name == NULL */
> -    QEMUOptionParameter *create_options;
> -
> +    QemuOptsList *(*bdrv_create_options)(void);

Why is .bdrv_create_options() a function?  It would be less code for
BlockDrivers to have a pointer: QemuOptsList *.

>      /* Check if compression is supported */
>      if (compress) {
> -        QEMUOptionParameter *encryption =
> -            get_option_parameter(param, BLOCK_OPT_ENCRYPT);
> -        QEMUOptionParameter *preallocation =
> -            get_option_parameter(param, BLOCK_OPT_PREALLOC);
> +        const char *encryption =
> +            qemu_opt_get(param, BLOCK_OPT_ENCRYPT);
> +        const char *preallocation =
> +            qemu_opt_get(param, BLOCK_OPT_PREALLOC);
>  
>          if (!drv->bdrv_write_compressed) {
>              error_report("Compression not supported for this file format");
> @@ -847,15 +842,15 @@ static int img_convert(int argc, char **argv)
>              goto out;
>          }
>  
> -        if (encryption && encryption->value.n) {
> +        if (encryption) {

encryption=off will print an error here.  We need to use
qemu_opt_get_bool().


> diff --git a/qemu-option.c b/qemu-option.c
> index ab270f0..c391f7d 100644
> --- a/qemu-option.c
> +++ b/qemu-option.c
> @@ -553,10 +553,15 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
>  
>  uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
>  {
> -    QemuOpt *opt = qemu_opt_find(opts, name);
> +    QemuOpt *opt;
> +    if (!opts) {
> +        return defval;
> +    }
> +    opt = qemu_opt_find(opts, name);
>  
> -    if (opt == NULL)
> +    if (opt == NULL) {
>          return defval;
> +    }
>      assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
>      return opt->value.uint;
>  }

This should be a separate patch, but there is a problem with the change
anyway: all qemu_opt_*() functions assume QemuOpts *opts is non-NULL.
This change makes qemu_opt_get_number() inconsistent.  This will lead to
bugs when people assume qemu_opt_get_bool() also handles opts == NULL,
for example.

Can the qemu-img/block callers make sure opts is never NULL or will that
add a lot of extra checks?

Stefan

  reply	other threads:[~2012-10-26  9:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-25 12:57 [Qemu-devel] [PATCH V4 00/10] replace QEMUOptionParameter with QemuOpts parser Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 01/10] qemu-option: opt_set(): split it up into more functions Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 02/10] qemu-option: qemu_opts_validate(): fix duplicated code Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 03/10] qemu-option: qemu_opt_set_bool(): fix code duplication Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 04/10] introduce qemu_opts_create_nofail function Dong Xu Wang
2012-10-25 13:06   ` Peter Maydell
2012-10-26  2:46     ` Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 05/10] use qemu_opts_create_nofail Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 06/10] create new function: qemu_opt_set_number Dong Xu Wang
2012-10-26  9:02   ` Stefan Hajnoczi
2012-10-29  8:03     ` Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 07/10] add def_value and use it in qemu_opts_print Dong Xu Wang
2012-10-26  9:32   ` Stefan Hajnoczi
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 08/10] Create four opts list related functions Dong Xu Wang
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 09/10] Use QemuOpts support in block layer Dong Xu Wang
2012-10-26  9:51   ` Stefan Hajnoczi [this message]
2012-10-25 12:57 ` [Qemu-devel] [PATCH V4 10/10] remove QEMUOptionParameter related functions and struct Dong Xu Wang

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=20121026095132.GF19272@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wdongxu@linux.vnet.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).