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 V5 09/10] Use QemuOpts support in block layer
Date: Mon, 19 Nov 2012 18:14:30 +0100	[thread overview]
Message-ID: <20121119171430.GA19114@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1351761150-20705-10-git-send-email-wdongxu@linux.vnet.ibm.com>

On Thu, Nov 01, 2012 at 05:12:29PM +0800, Dong Xu Wang wrote:
> diff --git a/block/qcow.c b/block/qcow.c
> index b239c82..9bb736a 100644
> --- a/block/qcow.c
> +++ b/block/qcow.c
> @@ -651,7 +651,7 @@ static void qcow_close(BlockDriverState *bs)
>      error_free(s->migration_blocker);
>  }
>  
> -static int qcow_create(const char *filename, QEMUOptionParameter *options)
> +static int qcow_create(const char *filename, QemuOpts *opts)
>  {
>      int header_size, backing_filename_len, l1_size, shift, i;
>      QCowHeader header;
> @@ -662,19 +662,14 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
>      int ret;
>      BlockDriverState *qcow_bs;
>  
> -    /* Read out options */
> -    while (options && options->name) {
> -        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> -            total_size = options->value.n / 512;
> -        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
> -            backing_file = options->value.s;
> -        } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
> -            flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
> -        }
> -        options++;
> +    /* Read out opts */
> +    total_size = qemu_opt_get_number(opts, BLOCK_OPT_SIZE, 0) / 512;
> +    backing_file = qemu_opt_get(opts, BLOCK_OPT_BACKING_FILE);
> +    if (qemu_opt_get_bool(opts, BLOCK_OPT_ENCRYPT, 0)) {
> +        flags |= BLOCK_FLAG_ENCRYPT;
>      }
>  
> -    ret = bdrv_create_file(filename, options);
> +    ret = bdrv_create_file(filename, opts);

Previously options would be an empty QEMUOptionParameter (because the
while loop iterated until options->name).  Now you are passing the same
opts for creating this image file, this seems wrong.  Should this be
bdrv_create_file(filename, NULL)?

> diff --git a/block/qcow2.c b/block/qcow2.c
> index c1ff31f..9cea051 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -1180,7 +1180,7 @@ static int preallocate(BlockDriverState *bs)
>  static int qcow2_create2(const char *filename, int64_t total_size,
>                           const char *backing_file, const char *backing_format,
>                           int flags, size_t cluster_size, int prealloc,
> -                         QEMUOptionParameter *options, int version)
> +                         QemuOpts *opts, int version)

The opts argument can be dropped since it is not used.

> @@ -1314,7 +1314,7 @@ out:
>      return ret;
>  }
>  
> -static int qcow2_create(const char *filename, QEMUOptionParameter *options)
> +static int qcow2_create(const char *filename, QemuOpts *opts)
>  {
>      const char *backing_file = NULL;
>      const char *backing_fmt = NULL;
> @@ -1323,45 +1323,41 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options)
>      size_t cluster_size = DEFAULT_CLUSTER_SIZE;
>      int prealloc = 0;
>      int version = 2;
> +    const char *buf;
>  
>      /* Read out options */
> -    while (options && options->name) {
> -        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> -            sectors = options->value.n / 512;
> -        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
> -            backing_file = options->value.s;
> -        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
> -            backing_fmt = options->value.s;
> -        } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
> -            flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
> -        } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
> -            if (options->value.n) {
> -                cluster_size = options->value.n;
> -            }
> -        } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
> -            if (!options->value.s || !strcmp(options->value.s, "off")) {
> -                prealloc = 0;
> -            } else if (!strcmp(options->value.s, "metadata")) {
> -                prealloc = 1;
> -            } else {
> -                fprintf(stderr, "Invalid preallocation mode: '%s'\n",
> -                    options->value.s);
> -                return -EINVAL;
> -            }
> -        } else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
> -            if (!options->value.s || !strcmp(options->value.s, "0.10")) {
> -                version = 2;
> -            } else if (!strcmp(options->value.s, "1.1")) {
> -                version = 3;
> -            } else {
> -                fprintf(stderr, "Invalid compatibility level: '%s'\n",
> -                    options->value.s);
> -                return -EINVAL;
> -            }
> -        } else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
> -            flags |= options->value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
> -        }
> -        options++;

The old code worked when options == NULL.  I think the new code should
also work when opts == NULL:

if (opts) {
    ....
}

This should be done for all block drivers or the way that
bdrv_create(..., NULL) works should be changed so that block drivers
don't have to check for opts == NULL.

> @@ -674,19 +687,14 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
>      return (int64_t)st.st_blocks * 512;
>  }
>  
> -static int raw_create(const char *filename, QEMUOptionParameter *options)
> +static int raw_create(const char *filename, QemuOpts *opts)
>  {
>      int fd;
>      int result = 0;
>      int64_t total_size = 0;
>  
> -    /* Read out options */
> -    while (options && options->name) {
> -        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> -            total_size = options->value.n / BDRV_SECTOR_SIZE;
> -        }
> -        options++;
> -    }
> +    total_size = opts ?
> +        qemu_opt_get_number(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE : 0;

total_size is initialized to 0 above, so this line can be made more
readable like this:

if (opts) {
    total_size = qemu_opt_get_number(opts, BLOCK_OPT_SIZE, 0);
}

> @@ -1081,20 +1079,15 @@ static int fd_open(BlockDriverState *bs)
>  
>  #endif /* !linux && !FreeBSD */
>  
> -static int hdev_create(const char *filename, QEMUOptionParameter *options)
> +static int hdev_create(const char *filename, QemuOpts *opts)
>  {
>      int fd;
>      int ret = 0;
>      struct stat stat_buf;
>      int64_t total_size = 0;
>  
> -    /* Read out options */
> -    while (options && options->name) {
> -        if (!strcmp(options->name, "size")) {
> -            total_size = options->value.n / BDRV_SECTOR_SIZE;
> -        }
> -        options++;
> -    }
> +    total_size = opts ?
> +        qemu_opt_get_number(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE : 0;

Same here.

  reply	other threads:[~2012-11-19 17:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-01  9:12 [Qemu-devel] [PATCH V5 00/10] replace QEMUOptionParameter with QemuOpts parser Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 01/10] qemu-option: opt_set(): split it up into more functions Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 02/10] qemu-option: qemu_opts_validate(): fix duplicated code Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 03/10] qemu-option: qemu_opt_set_bool(): fix code duplication Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 04/10] introduce qemu_opts_create_nofail function Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 05/10] use qemu_opts_create_nofail Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 06/10] create new function: qemu_opt_set_number Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 07/10] add def_print_str and use it in qemu_opts_print Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 08/10] Create four opts list related functions Dong Xu Wang
2012-11-19 17:16   ` Stefan Hajnoczi
2012-11-21  2:48     ` Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 09/10] Use QemuOpts support in block layer Dong Xu Wang
2012-11-19 17:14   ` Stefan Hajnoczi [this message]
2012-11-21  2:51     ` Dong Xu Wang
2012-11-01  9:12 ` [Qemu-devel] [PATCH V5 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=20121119171430.GA19114@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).