[Qemu-devel] [PATCH v4] QemuOpt: add unit tests

2014-05-19 Thread Leandro Dorileo
Cover basic aspects and API usage for QemuOpt. The current implementation
covers the API's planned to be changed by Chunyan Liu in his QEMUOptionParameter
replacement/cleanup job.

Other APIs should be covered in future improvements.

Signed-off-by: Leandro Dorileo 
---

Notes:
V4:
  + call register_opts() only once (pointed by Stefan);

V3:
  + fix a typo (s/dinamically/dynamically/);

V2:
  + fixed comments;
  + make use of g_assert_cmpstr();
  + use error_abort instead of a local_err for qemu_opts_absorb_qdict();
  + asserts on QemuOptsList (empty and list name);
  + added test_qemu_opt_unset();
  + asserts on qemu_opt_*_set() return;
  + added test_qemu_opts_reset();
  + added test_qemu_opts_set();

 tests/Makefile |   3 +
 tests/test-qemu-opts.c | 438 +
 2 files changed, 441 insertions(+)
 create mode 100644 tests/test-qemu-opts.c

diff --git a/tests/Makefile b/tests/Makefile
index 9f7ca61..8f71e0d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF)
+check-unit-y += tests/test-qemu-opts$(EXESUF)
+gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -319,6 +321,7 @@ tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o
 tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o
 tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
libqemustub.a
 
 # QTest rules
 
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
new file mode 100644
index 000..c186040
--- /dev/null
+++ b/tests/test-qemu-opts.c
@@ -0,0 +1,438 @@
+/*
+ * QemuOpts unit-tests.
+ *
+ * Copyright (C) 2014 Leandro Dorileo 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qapi/error.h"
+#include "qapi/qmp/qstring.h"
+#include "qemu/config-file.h"
+
+#include 
+#include 
+
+static QemuOptsList opts_list_01 = {
+.name = "opts_list_01",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str3",
+.type = QEMU_OPT_STRING,
+},{
+.name = "number1",
+.type = QEMU_OPT_NUMBER,
+},
+{ /* end of list */ }
+},
+};
+
+static QemuOptsList opts_list_02 = {
+.name = "opts_list_02",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "bool1",
+.type = QEMU_OPT_BOOL,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "size1",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
+QemuOptsList opts_list_03 = {
+.name = "opts_list_03",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
+static void register_opts(void)
+{
+qemu_add_opts(&opts_list_01);
+qemu_add_opts(&opts_list_02);
+qemu_add_opts(&opts_list_03);
+}
+
+static void test_find_unknown_opts(void)
+{
+QemuOptsList *list;
+
+/* should not return anything, we don't have an "unknown" option */
+list = qemu_find_opts("unknown");
+g_assert(list == NULL);
+}
+
+static void test_qemu_find_opts(void)
+{
+QemuOptsList *list;
+
+/* we have an "opts_list_01" option, should return it */
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+}
+
+static void test_qemu_opts_create(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert(QTAILQ_EMPTY(&list->head));
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/* create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+g_assert(opts != NULL);
+ 

Re: [Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-05-19 Thread Leandro Dorileo
On Fri, May 02, 2014 at 10:40:33AM +0200, Stefan Hajnoczi wrote:
> On Tue, Mar 25, 2014 at 10:27:19AM -0300, Leandro Dorileo wrote:
> > Cover basic aspects and API usage for QemuOpt. The current implementation
> > covers the API's planned to be changed by Chunyan Liu in his 
> > QEMUOptionParameter
> > replacement/cleanup job.
> > 
> > Other APIs should be covered in future improvements.
> > 
> > Signed-off-by: Leandro Dorileo 
> > Reviewed-by: Eric Blake 
> > ---
> >  tests/Makefile |   3 +
> >  tests/test-qemu-opts.c | 455 
> > +
> >  2 files changed, 458 insertions(+)
> >  create mode 100644 tests/test-qemu-opts.c
> 
> Looks useful.  I skipped this patch original because you and Chunyan
> were working on different versions of the QemuOpts conversion series and
> I wanted to wait until the dust settled on that.

Ok, no problem.

> 
> > +static void register_opts(void)
> > +{
> > +qemu_add_opts(&opts_list_01);
> > +qemu_add_opts(&opts_list_02);
> > +qemu_add_opts(&opts_list_03);
> > +}
> > +
> > +static void test_find_unknown_opts(void)
> > +{
> > +QemuOptsList *list;
> > +
> > +register_opts();
> 
> Should this function be called once in main() instead?  I think you keep
> adding the same opts lists again and again as the test cases execute.

Yep, definitively. I'm sending v4 soon.

Thanks...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-05-19 Thread Leandro Dorileo
On Wed, Apr 30, 2014 at 10:28:26AM +0200, Markus Armbruster wrote:
> Leandro Dorileo  writes:
> 
> > Hi Andreas,
> >
> > On Mon, Apr 28, 2014 at 09:02:12PM +0200, Andreas Färber wrote:
> >> Am 28.04.2014 20:55, schrieb Leandro Dorileo:
> >> > ping?
> >> > 
> >> > 
> >> > On Tue, Mar 25, 2014 at 10:27:19AM -0300, Leandro Dorileo wrote:
> >> >> Cover basic aspects and API usage for QemuOpt. The current 
> >> >> implementation
> >> >> covers the API's planned to be changed by Chunyan Liu in his
> >> >> QEMUOptionParameter
> >> >> replacement/cleanup job.
> >> >>
> >> >> Other APIs should be covered in future improvements.
> >> >>
> >> >> Signed-off-by: Leandro Dorileo 
> >> >> Reviewed-by: Eric Blake 
> >> >> ---
> >> >>  tests/Makefile |   3 +
> >> >>  tests/test-qemu-opts.c | 455
> >> >> +
> >> >>  2 files changed, 458 insertions(+)
> >> >>  create mode 100644 tests/test-qemu-opts.c
> >> 
> >> I don't spot any test API or style issues; not familiar enough with
> >> QemuOpts to judge the tests though.
> >
> > What maintainer would best suite to route this patch?
> 
> MAINTAINERS doesn't cover it.  In the past year, patches went in via
> Anthony, Kevin, Luiz, or Stefan Hajnoczi.  I'm cc'ing the ones from this
> list you missed.

Ok.

> 
> I read your patch.  There's some redundant testing, some comments feel
> superfluous, and there's a spelling mistake or two.  Coverage is far
> from perfect (QemuOpts has become ridiculously complex), but infinitely
> better than before :)
> 

Redundant testing don't seem to be a problem in this case, the comments are
intentionally verbose. My spell checker doesn't spot any spelling error -
besides "defval" :)

> Let's take it as is.

I'm respining the patch changing what Stefan suggested.

Thanks...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 00/32] replace QEMUOptionParameter with QemuOpts

2014-05-19 Thread Leandro Dorileo
On Sun, May 18, 2014 at 09:02:45PM -0600, Chun Yan Liu wrote:
> 
> 
> >>> On 5/6/2014 at 09:26 PM, in message
> <20140506132615.gv15...@stefanha-thinkpad.redhat.com>, Stefan Hajnoczi
>  wrote: 
> > On Tue, Apr 29, 2014 at 05:10:24PM +0800, Chunyan Liu wrote: 
> > > This patch series is to replace QEMUOptionParameter with QemuOpts, so 
> > > that  
> > only 
> > > one Qemu Option structure is kept in QEMU code. 
> > >  
> > > --- 
> > > Changes to v25: 
> > >   * split v25 2/31 (add def_value_str to QemuOptDesc) into two patches: 
> > > 1st patch adds def_value_str, 2nd patch repurpose qemu_opts_print. 
> > >   * update 4/32 qapi command line description. 
> > >   * update 12/32 (change block layer to support both) according to 
> > > Eric's comments. 
> > >   * small update to gluster.c 
> > >   * rebase to latest code 
> > >  
> > > All patches are also available from: 
> > > https://github.com/chunyanliu/qemu/commits/QemuOpts 
> >  
> > I looked through the comments from Leandro and Eric.  A respin is 
> > necessary to address the test failures that Leandro found.  Please also 
> > address the comments Eric made. 
> >  
> > We're almost there now! 
> >  
> >  
> 
> Hi, Stefan, Leandro & Eric,
> 
> Could you help to have a look at the new update? I've sent it about 10
> days ago.  It addressed all Eric's comments in last version and two
> memory free fix to address iotest issue. Hope it's the final work and
> won't take you more time :-)
> 
> The thread has been cut into two, since the git-send-email died in the
> middle at the 1st time sending. Please refer to:


I'll take a look at it, thanks.

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 12/32] change block layer to support both QemuOpts and QEMUOptionParamter

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:10:36PM +0800, Chunyan Liu wrote:
> Change block layer to support both QemuOpts and QEMUOptionParameter.
> After this patch, it will change backend drivers one by one. At the end,
> QEMUOptionParameter will be removed and only QemuOpts is kept.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 


Did you send the patch series twice? I commented in the first v26 emails...


-- 
Leandro Dorileo

> ---
> Changes to V25:
>   * fix Eric's comments:
>   * update bdrv_create_co_entry and bdrv_amend_options code, to let it
> more readable.
>   * add assertion in bdrv_register.
>   * improve comments to create_opts in header file.
> 
>  block.c   | 158 
> --
>  block/cow.c   |   2 +-
>  block/qcow.c  |   2 +-
>  block/qcow2.c |   2 +-
>  block/qed.c   |   2 +-
>  block/raw_bsd.c   |   2 +-
>  block/vhdx.c  |   2 +-
>  block/vmdk.c  |   4 +-
>  block/vvfat.c |   2 +-
>  include/block/block.h |   7 +-
>  include/block/block_int.h |  13 +++-
>  qemu-img.c|  94 +--
>  12 files changed, 180 insertions(+), 110 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 4745712..124f045 100644
> --- a/block.c
> +++ b/block.c
> @@ -328,6 +328,13 @@ void bdrv_register(BlockDriver *bdrv)
>  }
>  }
>  
> +if (bdrv->bdrv_create) {
> +assert(!bdrv->bdrv_create2 && !bdrv->create_opts);
> +assert(!bdrv->bdrv_amend_options2);
> +} else if (bdrv->bdrv_create2) {
> +assert(!bdrv->bdrv_create && !bdrv->create_options);
> +assert(!bdrv->bdrv_amend_options);
> +}
>  QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
>  }
>  
> @@ -419,6 +426,7 @@ typedef struct CreateCo {
>  BlockDriver *drv;
>  char *filename;
>  QEMUOptionParameter *options;
> +QemuOpts *opts;
>  int ret;
>  Error *err;
>  } CreateCo;
> @@ -430,8 +438,28 @@ static void coroutine_fn bdrv_create_co_entry(void 
> *opaque)
>  
>  CreateCo *cco = opaque;
>  assert(cco->drv);
> +assert(!(cco->options && cco->opts));
>  
> -ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
> +if (cco->drv->bdrv_create2) {
> +QemuOptsList *opts_list = NULL;
> +if (cco->options) {
> +opts_list = params_to_opts(cco->options);
> +cco->opts = qemu_opts_create(opts_list, NULL, 0, &error_abort);
> +}
> +ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
> +if (cco->options) {
> +qemu_opts_del(cco->opts);
> +qemu_opts_free(opts_list);
> +}
> +} else {
> +if (cco->opts) {
> +cco->options = opts_to_params(cco->opts);
> +}
> +ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
> +if (cco->opts) {
> +free_option_parameters(cco->options);
> +}
> +}
>  if (local_err) {
>  error_propagate(&cco->err, local_err);
>  }
> @@ -439,7 +467,8 @@ static void coroutine_fn bdrv_create_co_entry(void 
> *opaque)
>  }
>  
>  int bdrv_create(BlockDriver *drv, const char* filename,
> -QEMUOptionParameter *options, Error **errp)
> +QEMUOptionParameter *options,
> +QemuOpts *opts, Error **errp)
>  {
>  int ret;
>  
> @@ -448,11 +477,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
>  .drv = drv,
>  .filename = g_strdup(filename),
>  .options = options,
> +.opts = opts,
>  .ret = NOT_DONE,
>  .err = NULL,
>  };
>  
> -if (!drv->bdrv_create) {
> +if (!drv->bdrv_create && !drv->bdrv_create2) {
>  error_setg(errp, "Driver '%s' does not support image creation", 
> drv->format_name);
>  ret = -ENOTSUP;
>  goto out;
> @@ -484,7 +514,7 @@ out:
>  }
>  
>  int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
> - Error **errp)
> + QemuOpts *opts, Error **errp)
>  {
>  BlockDriver *drv;
>  Error *local_err = NULL;
> @@ -496,7 +526,7 @@ int bdrv_create_file(const char* filename, 
> QEMUOptionParameter *options,
>  return -ENOENT;
>  }
>  
> -ret = bdrv_create(drv, filename, 

Re: [Qemu-devel] [PATCH V26 12/32] change block layer to support both QemuOpts and QEMUOptionParamter

2014-05-01 Thread Leandro Dorileo
; -set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
> -ret = add_old_style_options(out_fmt, param, out_baseimg, NULL);
> +qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512);
> +ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
>  if (ret < 0) {
>  goto out;
>  }
>  
>  /* Get backing file name if -o backing_file was used */
> -out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
> +out_baseimg_param = qemu_opt_get(opts, BLOCK_OPT_BACKING_FILE);
>  if (out_baseimg_param) {
> -out_baseimg = out_baseimg_param->value.s;
> +out_baseimg = out_baseimg_param;
>  }
>  
>  /* 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);
> +bool encryption =
> +qemu_opt_get_bool(opts, BLOCK_OPT_ENCRYPT, false);
> +const char *preallocation =
> +qemu_opt_get(opts, BLOCK_OPT_PREALLOC);
>  
>  if (!drv->bdrv_write_compressed) {
>  error_report("Compression not supported for this file format");
> @@ -1400,15 +1396,15 @@ static int img_convert(int argc, char **argv)
>  goto out;
>  }
>  
> -if (encryption && encryption->value.n) {
> +if (encryption) {
>  error_report("Compression and encryption not supported at "
>   "the same time");
>  ret = -1;
>  goto out;
>  }
>  
> -if (preallocation && preallocation->value.s
> -&& strcmp(preallocation->value.s, "off"))
> +if (preallocation
> +&& strcmp(preallocation, "off"))
>  {
>  error_report("Compression and preallocation not supported at "
>   "the same time");
> @@ -1419,7 +1415,7 @@ static int img_convert(int argc, char **argv)
>  
>  if (!skip_create) {
>  /* Create the new image */
> -ret = bdrv_create(drv, out_filename, param, &local_err);
> +ret = bdrv_create(drv, out_filename, NULL, opts, &local_err);
>  if (ret < 0) {
>  error_report("%s: error while converting %s: %s",
>   out_filename, out_fmt, error_get_pretty(local_err));
> @@ -1683,8 +1679,8 @@ out:
>  qemu_progress_print(100, 0);
>  }
>  qemu_progress_end();
> -free_option_parameters(create_options);
> -free_option_parameters(param);
> +qemu_opts_del(opts);
> +qemu_opts_free(create_opts);
>  qemu_vfree(buf);
>  if (sn_opts) {
>  qemu_opts_del(sn_opts);
> @@ -2675,7 +2671,8 @@ static int img_amend(int argc, char **argv)
>  {
>  int c, ret = 0;
>  char *options = NULL;
> -QEMUOptionParameter *create_options = NULL, *options_param = NULL;
> +QemuOptsList *create_opts = NULL;
> +QemuOpts *opts = NULL;
>  const char *fmt = NULL, *filename;
>  bool quiet = false;
>  BlockDriverState *bs = NULL;
> @@ -2746,17 +2743,16 @@ static int img_amend(int argc, char **argv)
>  goto out;
>  }
>  
> -create_options = append_option_parameters(create_options,
> -bs->drv->create_options);
> -options_param = parse_option_parameters(options, create_options,
> -options_param);
> -if (options_param == NULL) {
> +create_opts = qemu_opts_append(create_opts, bs->drv->create_opts,
> +   bs->drv->create_options);
> +opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> +if (options && qemu_opts_do_parse(opts, options, NULL)) {


Since now we're calling qemu_opts_do_parse() instead of 
parse_option_parameters()
you should update the 061 test output, otherwise the test will fail due to wrong
output, the following should be enough:

--- a/tests/qemu-iotests/061.out
+++ b/tests/qemu-iotests/061.out
@@ -281,7 +281,7 @@ Lazy refcounts only supported with compatibility level 1.1 
and above (use compat
 qemu-img: Error while amending options: Invalid argument
 Unknown compatibility level 0.42.
 qemu-img: Error while amending options: Invalid argument
-Unknown option 'foo'
+qemu-img: Invalid parameter 'foo'
 qemu-img: Invalid options for file format 'qcow2'
 Changing the cluster size is not supported.
 qemu-img: Error while amending options: Operation not supported

Regards...

-- 
Leandro Dorileo


>  error_report("Invalid options for file format '%s'", fmt);
>  ret = -1;
>  goto out;
>  }
>  
> -ret = bdrv_amend_options(bs, options_param);
> +ret = bdrv_amend_options(bs, NULL, opts);
>  if (ret < 0) {
>  error_report("Error while amending options: %s", strerror(-ret));
>  goto out;
> @@ -2766,8 +2762,8 @@ out:
>  if (bs) {
>  bdrv_unref(bs);
>  }
> -free_option_parameters(create_options);
> -free_option_parameters(options_param);
> +qemu_opts_del(opts);
> +qemu_opts_free(create_opts);
>  g_free(options);
>  
>  if (ret) {
> -- 
> 1.8.4.5
> 
> 



Re: [Qemu-devel] [PATCH V26 11/32] QemuOpts: check NULL input for qemu_opts_del

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:20PM +0800, Chunyan Liu wrote:
> To simplify later using of qemu_opts_del, accept NULL input.
> 
> Reviewed-by: Stefan Hajnoczi 
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 

Reviewed-by: Leandro Dorileo 

> ---
>  util/qemu-option.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 4de99b3..2667e16 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -1010,6 +1010,10 @@ void qemu_opts_del(QemuOpts *opts)
>  {
>  QemuOpt *opt;
>  
> +if (opts == NULL) {
> +return;
> +}
> +
>  for (;;) {
>  opt = QTAILQ_FIRST(&opts->head);
>  if (opt == NULL)
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 09/32] QemuOpts: add conversion between QEMUOptionParameter to QemuOpts

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:18PM +0800, Chunyan Liu wrote:
> Add two temp conversion functions between QEMUOptionParameter to QemuOpts,
> so that next patch can use it. It will simplify later patch for easier
> review. And will be finally removed after all backend drivers switch to
> QemuOpts.
> 
> Reviewed-by: Stefan Hajnoczi 
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
>  include/qemu/option.h |   9 +++
>  util/qemu-option.c| 153 
> ++
>  2 files changed, 162 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index fbf5dc2..e98e8ef 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -103,6 +103,12 @@ typedef struct QemuOptDesc {
>  } QemuOptDesc;
>  
>  struct QemuOptsList {
> +/* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
> + * indicate the need to free memory. Will remove after all drivers
> + * switch to QemuOpts.
> + */
> +bool allocated;
> +
>  const char *name;
>  const char *implied_opt_name;
>  bool merge_lists;  /* Merge multiple uses of option into a single list? 
> */
> @@ -167,5 +173,8 @@ void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
> *opaque,
>int abort_on_failure);
>  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);
>  
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index adb7c3c..93ffcd5 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -1345,3 +1345,156 @@ int qemu_opts_foreach(QemuOptsList *list, 
> qemu_opts_loopfunc func, void *opaque,
>  loc_pop(&loc);
>  return rc;
>  }
> +
> +static size_t count_opts_list(QemuOptsList *list)
> +{
> +QemuOptDesc *desc = NULL;
> +size_t num_opts = 0;
> +
> +if (!list) {
> +return 0;
> +}
> +
> +desc = list->desc;
> +while (desc && desc->name) {
> +num_opts++;
> +desc++;
> +}
> +
> +return num_opts;
> +}
> +
> +/* Convert QEMUOptionParameter to QemuOpts
> + * FIXME: this function will be removed after all drivers
> + * switch to QemuOpts
> + */
> +QemuOptsList *params_to_opts(QEMUOptionParameter *list)
> +{
> +QemuOptsList *opts = NULL;
> +size_t num_opts, i = 0;
> +
> +if (!list) {
> +return NULL;
> +}
> +
> +num_opts = count_option_parameters(list);
> +opts = g_malloc0(sizeof(QemuOptsList) +
> + (num_opts + 1) * sizeof(QemuOptDesc));
> +QTAILQ_INIT(&opts->head);
> +/* (const char *) members will point to malloced space and need to free 
> */
> +opts->allocated = true;
> +
> +while (list && list->name) {
> +opts->desc[i].name = g_strdup(list->name);
> +opts->desc[i].help = g_strdup(list->help);
> +switch (list->type) {
> +case OPT_FLAG:
> +opts->desc[i].type = QEMU_OPT_BOOL;
> +opts->desc[i].def_value_str =
> +g_strdup(list->value.n ? "on" : "off");
> +break;
> +
> +case OPT_NUMBER:
> +opts->desc[i].type = QEMU_OPT_NUMBER;
> +if (list->value.n) {
> +opts->desc[i].def_value_str =
> +g_strdup_printf("%" PRIu64, list->value.n);
> +}
> +break;
> +
> +case OPT_SIZE:
> +opts->desc[i].type = QEMU_OPT_SIZE;
> +if (list->value.n) {
> +opts->desc[i].def_value_str =
> +g_strdup_printf("%" PRIu64, list->value.n);
> +}
> +break;
> +
> +case OPT_STRING:
> +opts->desc[i].type = QEMU_OPT_STRING;
> +opts->desc[i].def_value_str = g_strdup(list->value.s);
> +break;
> +}
> +
> +i++;
> +list++;
> +}
> +
> +return opts;
> +}
> +
> +/* convert QemuOpts to QEMUOptionParameter
> + * Note: result QEMUOptionParameter has shorter lifetime than
> + * input QemuOpts.
> + * FIXME: this function will be removed after all drivers
> + * switch to QemuOpts
> + */
> +QEMUOptionParameter *opts_to_params(QemuOpts *opts)
> +{
> +QEMUOptionParameter *dest = NULL;
> +QemuOptDesc *

Re: [Qemu-devel] [PATCH V26 08/32] QemuOpts: add qemu_opts_print_help to replace print_option_help

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:17PM +0800, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Reviewed-by: Eric Blake 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 

Reviewed-by: Leandro Dorileo 

> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c| 13 +
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 6653e43..fbf5dc2 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -166,5 +166,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void 
> *opaque);
>  void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
> *opaque,
>int abort_on_failure);
> +void qemu_opts_print_help(QemuOptsList *list);
>  
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 32e1d50..adb7c3c 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -553,6 +553,19 @@ void print_option_help(QEMUOptionParameter *list)
>  }
>  }
>  
> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> +QemuOptDesc *desc;
> +
> +assert(list);
> +desc = list->desc;
> +printf("Supported options:\n");
> +while (desc && desc->name) {
> +printf("%-16s %s\n", desc->name,
> +   desc->help ? desc->help : "No description available");
> +desc++;
> +}
> +}
>  /* -- */
>  
>  static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 07/32] QemuOpts: add qemu_opt_get_*_del functions for replace work

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:16PM +0800, Chunyan Liu wrote:
> Add qemu_opt_get_del, qemu_opt_get_bool_del, qemu_opt_get_number_del and
> qemu_opt_get_size_del to replace the same handling of QEMUOptionParameter
> (get and delete).
> 
> Several drivers are coded to parse a known subset of options, then
> remove them from the list before handing all remaining options to a
> second driver for further option processing.  get_*_del makes it easier
> to retrieve a known option (or its default) and remove it from the list
> all in one action.
> 
> Share common helper function:
> 
> For qemu_opt_get_bool/size/number, they and their get_*_del counterpart
> could share most of the code except whether or not deleting the opt from
> option list, so generate common helper functions.
> 
> For qemu_opt_get and qemu_opt_get_del, keep code duplication, since
> 1. qemu_opt_get_del returns malloc'd memory while qemu_opt_get returns
> in-place memory
> 2. qemu_opt_get_del returns (char *), qemu_opt_get returns (const char *),
> and could not change to (char *), since in one case, it will return
> desc->def_value_str, which is (const char *).
> 
> Reviewed-by: Eric Blake 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 

Reviewed-by: Leandro Dorileo 

> ---
>  include/qemu/option.h |   6 +++
>  util/qemu-option.c| 116 
> --
>  2 files changed, 109 insertions(+), 13 deletions(-)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index c3b0a91..6653e43 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -111,6 +111,7 @@ struct QemuOptsList {
>  };
>  
>  const char *qemu_opt_get(QemuOpts *opts, const char *name);
> +char *qemu_opt_get_del(QemuOpts *opts, const char *name);
>  /**
>   * qemu_opt_has_help_opt:
>   * @opts: options to search for a help request
> @@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
>  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);
>  uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t 
> defval);
> +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
> +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
> + uint64_t defval);
> +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
> +   uint64_t defval);
>  int qemu_opt_unset(QemuOpts *opts, const char *name);
>  int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
>  void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 4d2d4d1..32e1d50 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -575,6 +575,19 @@ static void qemu_opt_del(QemuOpt *opt)
>  g_free(opt);
>  }
>  
> +/* qemu_opt_set allows many settings for the same option.
> + * This function deletes all settings for an option.
> + */
> +static void qemu_opt_del_all(QemuOpts *opts, const char *name)
> +{
> +QemuOpt *opt, *next_opt;
> +
> +QTAILQ_FOREACH_SAFE(opt, &opts->head, next, next_opt) {
> +if (!strcmp(opt->name, name))
> +qemu_opt_del(opt);
> +}
> +}
> +
>  const char *qemu_opt_get(QemuOpts *opts, const char *name)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
> @@ -588,6 +601,34 @@ const char *qemu_opt_get(QemuOpts *opts, const char 
> *name)
>  return opt ? opt->str : NULL;
>  }
>  
> +/* Get a known option (or its default) and remove it from the list
> + * all in one action. Return a malloced string of the option value.
> + * Result must be freed by caller with g_free().
> + */
> +char *qemu_opt_get_del(QemuOpts *opts, const char *name)
> +{
> +QemuOpt *opt;
> +const QemuOptDesc *desc;
> +char *str = NULL;
> +
> +if (opts == NULL) {
> +return NULL;
> +}
> +
> +opt = qemu_opt_find(opts, name);
> +if (!opt) {
> +desc = find_desc_by_name(opts->list->desc, name);
> +if (desc && desc->def_value_str) {
> +str = g_strdup(desc->def_value_str);
> +}
> +return str;
> +}
> +str = opt->str;
> +opt->str = NULL;
> +qemu_opt_del_all(opts, name);
> +return str;
> +}
> +
>  bool qemu_opt_has_help_opt(QemuOpts *opts)
>  {
>  QemuOpt *opt;
> @@ -600,50 +641,99 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
>  return false;
>  }
>  
> -bool qemu_opt_get_bool(

Re: [Qemu-devel] [PATCH V26 06/32] QemuOpts: move qemu_opt_del ahead for later calling

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:15PM +0800, Chunyan Liu wrote:
> In later patch, qemu_opt_get_del functions will be added, they will
> first get the option value, then call qemu_opt_del to remove the option
> from opt list. To prepare for that purpose, move qemu_opt_del ahead first.
> 
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 

Reviewed-by: Leandro Dorileo 

> ---
>  util/qemu-option.c | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 69cdf3f..4d2d4d1 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -567,6 +567,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
> *name)
>  return NULL;
>  }
>  
> +static void qemu_opt_del(QemuOpt *opt)
> +{
> +QTAILQ_REMOVE(&opt->opts->head, opt, next);
> +g_free(opt->name);
> +g_free(opt->str);
> +g_free(opt);
> +}
> +
>  const char *qemu_opt_get(QemuOpts *opts, const char *name)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
> @@ -661,14 +669,6 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>  }
>  }
>  
> -static void qemu_opt_del(QemuOpt *opt)
> -{
> -QTAILQ_REMOVE(&opt->opts->head, opt, next);
> -g_free(opt->name);
> -g_free(opt->str);
> -g_free(opt);
> -}
> -
>  static bool opts_accepts_any(const QemuOpts *opts)
>  {
>  return opts->list->desc[0].name == NULL;
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt->name|str from (const char *) to (char *)

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:14PM +0800, Chunyan Liu wrote:
> qemu_opt_del() already assumes that all QemuOpt instances contain
> malloc'd name and value; but it had to cast away const because
> opts_start_struct() was doing its own thing and using static storage
> instead.  By using the correct type and malloced strings everywhere, the
> usage of this struct becomes clearer.
> 
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 

Reviewed-by: Leandro Dorileo 


> ---
>  include/qemu/option_int.h |  4 ++--
>  qapi/opts-visitor.c   | 10 +++---
>  util/qemu-option.c|  4 ++--
>  3 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
> index 8212fa4..6432c1a 100644
> --- a/include/qemu/option_int.h
> +++ b/include/qemu/option_int.h
> @@ -30,8 +30,8 @@
>  #include "qemu/error-report.h"
>  
>  struct QemuOpt {
> -const char   *name;
> -const char   *str;
> +char *name;
> +char *str;
>  
>  const QemuOptDesc *desc;
>  union {
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 5d830a2..7a64f4e 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char 
> *kind,
>  if (ov->opts_root->id != NULL) {
>  ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt);
>  
> -ov->fake_id_opt->name = "id";
> -ov->fake_id_opt->str = ov->opts_root->id;
> +ov->fake_id_opt->name = g_strdup("id");
> +ov->fake_id_opt->str = g_strdup(ov->opts_root->id);
>  opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt);
>  }
>  }
> @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp)
>  }
>  g_hash_table_destroy(ov->unprocessed_opts);
>  ov->unprocessed_opts = NULL;
> -g_free(ov->fake_id_opt);
> +if (ov->fake_id_opt) {
> +g_free(ov->fake_id_opt->name);
> +g_free(ov->fake_id_opt->str);
> +g_free(ov->fake_id_opt);
> +}
>  ov->fake_id_opt = NULL;
>  }
>  
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 2be6995..69cdf3f 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>  static void qemu_opt_del(QemuOpt *opt)
>  {
>  QTAILQ_REMOVE(&opt->opts->head, opt, next);
> -g_free((/* !const */ char*)opt->name);
> -g_free((/* !const */ char*)opt->str);
> +g_free(opt->name);
> +g_free(opt->str);
>  g_free(opt);
>  }
>  
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 04/32] qapi: output def_value_str when query command line options

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:13PM +0800, Chunyan Liu wrote:
> Change qapi interfaces to output the newly added def_value_str when querying
> command line options.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
> Changes to V25:
>   * update @default description in .json file
> 
>  qapi-schema.json   | 5 -
>  qmp-commands.hx| 2 ++
>  util/qemu-config.c | 4 
>  3 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 0b00427..880829d 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4088,12 +4088,15 @@
>  #
>  # @help: #optional human readable text string, not suitable for parsing.
>  #
> +# @default: #optional default value string (since 2.1)
> +#
>  # Since 1.5
>  ##
>  { 'type': 'CommandLineParameterInfo',
>'data': { 'name': 'str',
>  'type': 'CommandLineParameterType',
> -'*help': 'str' } }
> +'*help': 'str',
> +'*default': 'str' } }
>  
>  ##
>  # @CommandLineOptionInfo:
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index ed3ab92..1271332 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -2895,6 +2895,8 @@ Each array entry contains the following:
>or 'size')
>  - "help": human readable description of the parameter
>(json-string, optional)
> +- "default": default value string for the parameter
> + (json-string, optional)
>  
>  Example:
>  
> diff --git a/util/qemu-config.c b/util/qemu-config.c
> index f4e4f38..ba375c0 100644
> --- a/util/qemu-config.c
> +++ b/util/qemu-config.c
> @@ -82,6 +82,10 @@ static CommandLineParameterInfoList 
> *query_option_descs(const QemuOptDesc *desc)
>  info->has_help = true;
>      info->help = g_strdup(desc[i].help);
>  }
> +if (desc[i].def_value_str) {
> +info->has_q_default = true;
> +info->q_default = g_strdup(desc[i].def_value_str);
> +}
>  
>  entry = g_malloc0(sizeof(*entry));
>  entry->value = info;
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 03/32] QemuOpts: repurpose qemu_opts_print to replace print_option_parameters

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:12PM +0800, Chunyan Liu wrote:
> Currently this function is not used anywhere. In later patches, it will
> replace print_option_parameters. To avoid print info changes, change
> qemu_opts_print from fprintf stderr to printf to keep consistent with
> print_option_parameters, remove last printf and print size/number with
> opt->value.uint instead of opt->str.
> 
> Signed-off-by: Chunyan Liu 

Reviewed-by: Leandro Dorileo 

> ---
>  util/qemu-option.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 5346c90..2be6995 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -925,7 +925,7 @@ void qemu_opts_print(QemuOpts *opts)
>  
>  if (desc[0].name == NULL) {
>  QTAILQ_FOREACH(opt, &opts->head, next) {
> -fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str);
> +printf("%s=\"%s\" ", opt->name, opt->str);
>  }
>  return;
>  }
> @@ -938,12 +938,14 @@ void qemu_opts_print(QemuOpts *opts)
>  continue;
>  }
>  if (desc->type == QEMU_OPT_STRING) {
> -fprintf(stderr, "%s='%s' ", desc->name, value);
> +printf("%s='%s' ", desc->name, value);
> +} else if ((desc->type == QEMU_OPT_SIZE ||
> +desc->type == QEMU_OPT_NUMBER) && opt) {
> +printf("%s=%" PRId64 " ", desc->name, opt->value.uint);
>  } else {
> -        fprintf(stderr, "%s=%s ", desc->name, value);
> +printf("%s=%s ", desc->name, value);
>  }
>  }
> -fprintf(stderr, "\n");
>  }
>  
>  static int opts_do_parse(QemuOpts *opts, const char *params,
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 02/32] QemuOpts: add def_value_str to QemuOptDesc

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:11PM +0800, Chunyan Liu wrote:
> Add def_value_str (default value) to QemuOptDesc, to replace function of the
> default value in QEMUOptionParameter.
> 
> Improve qemu_opts_get_* functions: if find opt, return opt->str; otherwise,
> if desc->def_value_str is set, return desc->def_value_str; otherwise, return
> input defval.
> 
> Improve qemu_opts_print: if option is set, print opt->str; otherwise, if
> desc->def_value_str is set, also print it. It will replace
> print_option_parameters.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
> Changes to V25:
>   * split v25 patch into two: this one and next one.
>   * this patch is the same as v22 which is reviewed-by Eric.
> 
>  include/qemu/option.h |  3 ++-
>  util/qemu-option.c| 56 
> ++-
>  2 files changed, 49 insertions(+), 10 deletions(-)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 8c0ac34..c3b0a91 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
>  const char *name;
>  enum QemuOptType type;
>  const char *help;
> +const char *def_value_str;
>  } QemuOptDesc;
>  
>  struct QemuOptsList {
> @@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
>  void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
>  
>  typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
> -int qemu_opts_print(QemuOpts *opts, void *dummy);
> +void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
> *opaque,
>int abort_on_failure);
>  
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 808aef4..5346c90 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
> *name)
>  const char *qemu_opt_get(QemuOpts *opts, const char *name)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
> +
> +if (!opt) {
> +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
> +if (desc && desc->def_value_str) {
> +return desc->def_value_str;
> +}
> +}
>  return opt ? opt->str : NULL;
>  }
>  
> @@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
> bool defval)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
>  
> -if (opt == NULL)
> +if (opt == NULL) {
> +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
> +if (desc && desc->def_value_str) {
> +parse_option_bool(name, desc->def_value_str, &defval, 
> &error_abort);
> +}
>  return defval;
> +}
>  assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
>  return opt->value.boolean;
>  }
> @@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
> *name, uint64_t defval)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
>  
> -if (opt == NULL)
> +if (opt == NULL) {
> +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
> +if (desc && desc->def_value_str) {
> +parse_option_number(name, desc->def_value_str, &defval,
> +&error_abort);
> +}
>  return defval;
> +}
>  assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
>  return opt->value.uint;
>  }
> @@ -609,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
> *name, uint64_t defval)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
>  
> -if (opt == NULL)
> +if (opt == NULL) {
> +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
> +if (desc && desc->def_value_str) {
> +parse_option_size(name, desc->def_value_str, &defval, 
> &error_abort);
> +}
>  return defval;
> +}
>  assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
>  return opt->value.uint;
>  }
> @@ -895,17 +918,32 @@ void qemu_opts_del(QemuOpts *opts)
>  g_free(opts);
>  }
>  
> -int qemu_opts_print(QemuOpts *opts, void *dummy)
> +void qemu_opts_print(QemuOpts *opts)
>  {
>  QemuOpt *opt;
> +QemuOptDesc *desc = opts->list->desc;
>  
> -fprintf(stderr, "%s: %s:", opts-

Re: [Qemu-devel] [PATCH V26 01/32] QemuOpts: move find_desc_by_name ahead for later calling

2014-05-01 Thread Leandro Dorileo
On Tue, Apr 29, 2014 at 05:08:10PM +0800, Chunyan Liu wrote:
> Reviewed-by: Stefan Hajnoczi 
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
>  util/qemu-option.c | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 8bbc3ad..808aef4 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -173,6 +173,20 @@ static void parse_option_number(const char *name, const 
> char *value,
>  }
>  }
>  
> +static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
> +const char *name)
> +{
> +int i;
> +
> +for (i = 0; desc[i].name != NULL; i++) {
> +if (strcmp(desc[i].name, name) == 0) {
> +return &desc[i];
> +}
> +}
> +
> +return NULL;
> +}
> +
>  void parse_option_size(const char *name, const char *value,
> uint64_t *ret, Error **errp)
>  {
> @@ -637,20 +651,6 @@ static bool opts_accepts_any(const QemuOpts *opts)
>  return opts->list->desc[0].name == NULL;
>  }
>  
> -static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
> -const char *name)
> -{
> -int i;
> -
> -for (i = 0; desc[i].name != NULL; i++) {
> -if (strcmp(desc[i].name, name) == 0) {
> -return &desc[i];
> -}
> -}
> -
> -    return NULL;
> -}
> -
>  int qemu_opt_unset(QemuOpts *opts, const char *name)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
> -- 
> 1.8.4.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH V26 00/32] replace QEMUOptionParameter with QemuOpts

2014-04-29 Thread Leandro Dorileo
Hi Chunyan,

I haven't found enough time the last versions you've sent for review. I've buit 
your
patch series and the final result builds nicely, but it fails the test 061, I 
haven't
had the time to investigate it yet.

I'm leaving on vacation next Friday so I'll try to review all you patches 
before that.

Regards...

--
Dorileo


On Tue, Apr 29, 2014 at 05:10:24PM +0800, Chunyan Liu wrote:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that 
> only
> one Qemu Option structure is kept in QEMU code.
> 
> ---
> Changes to v25:
>   * split v25 2/31 (add def_value_str to QemuOptDesc) into two patches:
> 1st patch adds def_value_str, 2nd patch repurpose qemu_opts_print.
>   * update 4/32 qapi command line description.
>   * update 12/32 (change block layer to support both) according to
> Eric's comments.
>   * small update to gluster.c
>   * rebase to latest code
> 
> All patches are also available from:
> https://github.com/chunyanliu/qemu/commits/QemuOpts
> 
> 
> Chunyan Liu (31):
>   QemuOpts: move find_desc_by_name ahead for later calling
>   QemuOpts: add def_value_str to QemuOptDesc
>   QemuOpts: repurpose qemu_opts_print to replace print_option_parameters
>   qapi: output def_value_str when query command line options
>   QemuOpts: change opt->name|str from (const char *) to (char *)
>   QemuOpts: move qemu_opt_del ahead for later calling
>   QemuOpts: add qemu_opt_get_*_del functions for replace work
>   QemuOpts: add qemu_opts_print_help to replace print_option_help
>   QemuOpts: add conversion between QEMUOptionParameter to QemuOpts
>   QemuOpts: add qemu_opts_append to replace append_option_parameters
>   QemuOpts: check NULL input for qemu_opts_del
>   change block layer to support both QemuOpts and QEMUOptionParamter
>   vvfat.c: handle cross_driver's create_options and create_opts
>   cow.c: replace QEMUOptionParameter with QemuOpts
>   gluster.c: replace QEMUOptionParameter with QemuOpts
>   iscsi.c: replace QEMUOptionParameter with QemuOpts
>   nfs.c: replace QEMUOptionParameter with QemuOpts
>   qcow.c: replace QEMUOptionParameter with QemuOpts
>   qcow2.c: replace QEMUOptionParameter with QemuOpts
>   qed.c: replace QEMUOptionParameter with QemuOpts
>   raw-posix.c: replace QEMUOptionParameter with QemuOpts
>   raw-win32.c: replace QEMUOptionParameter with QemuOpts
>   raw_bsd.c: replace QEMUOptionParameter with QemuOpts
>   rbd.c: replace QEMUOptionParameter with QemuOpts
>   sheepdog.c: replace QEMUOptionParameter with QemuOpts
>   ssh.c: replace QEMUOptionParameter with QemuOpts
>   vdi.c: replace QEMUOptionParameter with QemuOpts
>   vhdx.c: replace QEMUOptionParameter with QemuOpts
>   vmdk.c: replace QEMUOptionParameter with QemuOpts
>   vpc.c: replace QEMUOptionParameter with QemuOpts
>   cleanup QEMUOptionParameter
> 
> Michael Buesch (1):
>   slirp/smb: Move ncalrpc directory to tmp
> 
> 



Re: [Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-04-28 Thread Leandro Dorileo
Hi Andreas,

On Mon, Apr 28, 2014 at 09:02:12PM +0200, Andreas Färber wrote:
> Am 28.04.2014 20:55, schrieb Leandro Dorileo:
> > ping?
> > 
> > 
> > On Tue, Mar 25, 2014 at 10:27:19AM -0300, Leandro Dorileo wrote:
> >> Cover basic aspects and API usage for QemuOpt. The current implementation
> >> covers the API's planned to be changed by Chunyan Liu in his 
> >> QEMUOptionParameter
> >> replacement/cleanup job.
> >>
> >> Other APIs should be covered in future improvements.
> >>
> >> Signed-off-by: Leandro Dorileo 
> >> Reviewed-by: Eric Blake 
> >> ---
> >>  tests/Makefile |   3 +
> >>  tests/test-qemu-opts.c | 455 
> >> +
> >>  2 files changed, 458 insertions(+)
> >>  create mode 100644 tests/test-qemu-opts.c
> 
> I don't spot any test API or style issues; not familiar enough with
> QemuOpts to judge the tests though.

What maintainer would best suite to route this patch?

Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-04-28 Thread Leandro Dorileo
ping?


On Tue, Mar 25, 2014 at 10:27:19AM -0300, Leandro Dorileo wrote:
> Cover basic aspects and API usage for QemuOpt. The current implementation
> covers the API's planned to be changed by Chunyan Liu in his 
> QEMUOptionParameter
> replacement/cleanup job.
> 
> Other APIs should be covered in future improvements.
> 
> Signed-off-by: Leandro Dorileo 
> Reviewed-by: Eric Blake 
> ---
>  tests/Makefile |   3 +
>  tests/test-qemu-opts.c | 455 
> +
>  2 files changed, 458 insertions(+)
>  create mode 100644 tests/test-qemu-opts.c
> 
> diff --git a/tests/Makefile b/tests/Makefile
> index 471b4c8..4814283 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
>  check-unit-y += tests/check-qom-interface$(EXESUF)
>  gcov-files-check-qom-interface-y = qom/object.c
>  check-unit-y += tests/test-vmstate$(EXESUF)
> +check-unit-y += tests/test-qemu-opts$(EXESUF)
> +gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
>  
>  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>  
> @@ -272,6 +274,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
>  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
>  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o 
> $(libqos-pc-obj-y)
>  tests/qemu-iotests/socket_scm_helper$(EXESUF): 
> tests/qemu-iotests/socket_scm_helper.o
> +tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
> libqemustub.a
>  
>  # QTest rules
>  
> diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
> new file mode 100644
> index 000..abd2fb8
> --- /dev/null
> +++ b/tests/test-qemu-opts.c
> @@ -0,0 +1,455 @@
> +/*
> + * QemuOpts unit-tests.
> + *
> + * Copyright (C) 2014 Leandro Dorileo 
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.
> + */
> +
> +#include "qapi/error.h"
> +#include "qapi/qmp/qstring.h"
> +#include "qemu/config-file.h"
> +
> +#include 
> +#include 
> +
> +static QemuOptsList opts_list_01 = {
> +.name = "opts_list_01",
> +.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
> +.desc = {
> +{
> +.name = "str1",
> +.type = QEMU_OPT_STRING,
> +},{
> +.name = "str2",
> +.type = QEMU_OPT_STRING,
> +},{
> +.name = "str3",
> +.type = QEMU_OPT_STRING,
> +},{
> +.name = "number1",
> +.type = QEMU_OPT_NUMBER,
> +},
> +{ /* end of list */ }
> +},
> +};
> +
> +static QemuOptsList opts_list_02 = {
> +.name = "opts_list_02",
> +.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
> +.desc = {
> +{
> +.name = "str1",
> +.type = QEMU_OPT_STRING,
> +},{
> +.name = "bool1",
> +.type = QEMU_OPT_BOOL,
> +},{
> +.name = "str2",
> +.type = QEMU_OPT_STRING,
> +},{
> +.name = "size1",
> +.type = QEMU_OPT_SIZE,
> +},
> +{ /* end of list */ }
> +},
> +};
> +
> +QemuOptsList opts_list_03 = {
> +.name = "opts_list_03",
> +.head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
> +.desc = {
> +/* no elements => accept any params */
> +{ /* end of list */ }
> +},
> +};
> +
> +static void register_opts(void)
> +{
> +qemu_add_opts(&opts_list_01);
> +qemu_add_opts(&opts_list_02);
> +qemu_add_opts(&opts_list_03);
> +}
> +
> +static void test_find_unknown_opts(void)
> +{
> +QemuOptsList *list;
> +
> +register_opts();
> +
> +/* should not return anything, we don't have an "unknown" option */
> +list = qemu_find_opts("unknown");
> +g_assert(list == NULL);
> +}
> +
> +static void test_qemu_find_opts(void)
> +{
> +QemuOptsList *list;
> +
> +register_opts();
> +
> +/* we have an "opts_list_01" option, should return it */
> +list = qemu_find_opts("opts_list_01");
> +g_assert(list != NULL);
> +g_assert_cmpstr(list->name, ==, "opts_list_01");
> +}
> +
> +static void test_qemu_opts_create(void)
> +{
> +QemuOptsList *list;
> +QemuOpts *opts;
> +
> +register_opts();
> +
> +  

Re: [Qemu-devel] [PATCH v24 00/31] replace QEMUOptionParameter with QemuOpts

2014-04-16 Thread Leandro Dorileo
On Thu, Apr 10, 2014 at 11:20:46AM +0800, Chunyan Liu wrote:
> 2014-04-08 9:12 GMT+08:00 Leandro Dorileo :
> 
> > On Thu, Apr 03, 2014 at 05:54:18PM +0800, Chunyan Liu wrote:
> > > This patch series is to replace QEMUOptionParameter with QemuOpts, so
> > that only
> > > one Qemu Option structure is kept in QEMU code.
> > >
> > > ---
> > > Changes to v23:
> > >   * Improve conversion functions, make .assigned info not lost.
> > >   * Update qcow2.c amend_option, keep checking 'assigned'.
> > >   * Improve qemu_opt_get_*_del, after get option, delete all settings
> > > to this option (since in qemu_opt_set, if set option many times,
> > > there will be many opts in the list for the same option).
> > >   * Some other fixes for qemu-iotests
> > >   * Other fixes to v23 comments
> > >
> > > Chunyan Liu (31):
> > >   QemuOpts: move find_desc_by_name ahead for later calling
> > >   QemuOpts: add def_value_str to QemuOptDesc
> > >   qapi: output def_value_str when query command line options
> > >   QemuOpts: change opt->name|str from (const char *) to (char *)
> > >   QemuOpts: move qemu_opt_del ahead for later calling
> > >   QemuOpts: add qemu_opt_get_*_del functions for replace work
> > >   QemuOpts: add qemu_opts_print_help to replace print_option_help
> > >   QemuOpts: add conversion between QEMUOptionParameter to QemuOpts
> > >   QemuOpts: add qemu_opts_append to replace append_option_parameters
> > >   QemuOpts: check NULL input for qemu_opts_del
> > >   qemu_opts_print: change fprintf stderr to printf
> > >   change block layer to support both QemuOpts and QEMUOptionParamter
> > >   vvfat.c: handle cross_driver's create_options and create_opts
> > >   cow.c: replace QEMUOptionParameter with QemuOpts
> > >   gluster.c: replace QEMUOptionParameter with QemuOpts
> > >   iscsi.c: replace QEMUOptionParameter with QemuOpts
> > >   qcow.c: replace QEMUOptionParameter with QemuOpts
> > >   qcow2.c: replace QEMUOptionParameter with QemuOpts
> > >   qed.c: replace QEMUOptionParameter with QemuOpts
> > >   raw-posix.c: replace QEMUOptionParameter with QemuOpts
> > >   raw-win32.c: replace QEMUOptionParameter with QemuOpts
> > >   raw_bsd.c: replace QEMUOptionParameter with QemuOpts
> > >   rbd.c: replace QEMUOptionParameter with QemuOpts
> > >   sheepdog.c: replace QEMUOptionParameter with QemuOpts
> > >   ssh.c: replace QEMUOptionParameter with QemuOpts
> > >   vdi.c: replace QEMUOptionParameter with QemuOpts
> > >   vhdx.c: replace QEMUOptionParameter with QemuOpts
> > >   vmdk.c: replace QEMUOptionParameter with QemuOpts
> > >   vpc.c: replace QEMUOptionParameter with QemuOpts
> > >   cleanup QEMUOptionParameter
> > >   QemuOpts: cleanup tmp 'allocated' member from QemuOptsList
> >
> >
> > block/nfs.c is missing conversion. Have you tested your own patches?
> > A simple git am && config && make is enough to break the build.
> >
> 
> Another case that's caused because "libnfs supportno" and nfs.c is not
> compiled. I'll update and check if there is other files missing. But is
> there
> any configure option that could enable all drivers?


Not that I'm aware of.


> For those changed backend drivers above, of course have been tested
> "make && tests/qemu-iotests/check".

Good...

--
Dorileo

> 
> Chunyan
> 
> 
> > ---
> > Leandro Dorileo
> >
> >
> > >
> > >  block.c   |  96 
> > >  block/cow.c   |  52 ++--
> > >  block/gluster.c   |  73 +++---
> > >  block/iscsi.c |  32 ++-
> > >  block/qcow.c  |  72 +++---
> > >  block/qcow2.c | 264 +++--
> > >  block/qed.c   | 112 -
> > >  block/qed.h   |   3 +-
> > >  block/raw-posix.c |  55 ++---
> > >  block/raw-win32.c |  38 +--
> > >  block/raw_bsd.c   |  25 +-
> > >  block/rbd.c   |  61 +++--
> > >  block/sheepdog.c  | 102 
> > >  block/ssh.c   |  30 ++-
> > >  block/vdi.c   |  71 +++---
> > >  block/vhdx.c  |  97 
> > >  block/vhdx.h  |   1 +
> > >  block/vmdk.c  | 121 +-
> > >  block/vpc.c   |  60 ++---
> > >  block/vvfat.c |  11 +-
> > >  include/block/block.h |   7 +-
> > >  include/block/block_int.h |   9 +-
> > >  include/qemu/option.h |  53 +
> > >  include/qemu/option_int.h |   4 +-
> > >  qapi-schema.json  |   6 +-
> > >  qapi/opts-visitor.c   |  10 +-
> > >  qemu-img.c|  89 ---
> > >  qmp-commands.hx   |   2 +
> > >  util/qemu-config.c|   4 +
> > >  util/qemu-option.c| 587
> > --
> > >  30 files changed, 1029 insertions(+), 1118 deletions(-)
> > >
> > > --
> > > 1.7.12.4
> > >
> >
> >



Re: [Qemu-devel] [PATCH v24 02/31] QemuOpts: add def_value_str to QemuOptDesc

2014-04-16 Thread Leandro Dorileo
On Thu, Apr 10, 2014 at 11:36:05AM +0800, Chunyan Liu wrote:
> 2014-04-08 9:31 GMT+08:00 Leandro Dorileo :
> 
> > On Thu, Apr 03, 2014 at 05:54:20PM +0800, Chunyan Liu wrote:
> > > Add def_value_str (default value) to QemuOptDesc, to replace function of
> > the
> > > default value in QEMUOptionParameter.
> > >
> > > Improve qemu_opts_get_* functions: if find opt, return opt->str;
> > otherwise,
> > > if desc->def_value_str is set, return desc->def_value_str; otherwise,
> > return
> > > input defval.
> > >
> > > Improve qemu_opts_print: if option is set, print opt->str; otherwise, if
> > > desc->def_value_str is set, also print it.
> > >
> > > Reviewed-by: Eric Blake 
> > > Signed-off-by: Dong Xu Wang 
> > > Signed-off-by: Chunyan Liu 
> > > ---
> > >  include/qemu/option.h |  3 ++-
> > >  util/qemu-option.c| 56
> > ++-
> > >  2 files changed, 49 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/include/qemu/option.h b/include/qemu/option.h
> > > index 8c0ac34..c3b0a91 100644
> > > --- a/include/qemu/option.h
> > > +++ b/include/qemu/option.h
> > > @@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
> > >  const char *name;
> > >  enum QemuOptType type;
> > >  const char *help;
> > > +const char *def_value_str;
> > >  } QemuOptDesc;
> >
> >
> > I still think you don't need to define the default value as a string to
> > later
> > parse it, see what I mean
> > https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg04273.html
> >
> > But I think we can live with it. See bellow, if you fix the issue you can
> > add my Reviewed-by.
> >
> >
> > >
> > >  struct QemuOptsList {
> > > @@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict
> > *qdict);
> > >  void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
> > >
> > >  typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
> > > -int qemu_opts_print(QemuOpts *opts, void *dummy);
> > > +void qemu_opts_print(QemuOpts *opts);
> > >  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void
> > *opaque,
> > >int abort_on_failure);
> > >
> > > diff --git a/util/qemu-option.c b/util/qemu-option.c
> > > index e6d10bc..d5e80da 100644
> > > --- a/util/qemu-option.c
> > > +++ b/util/qemu-option.c
> > > @@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const
> > char *name)
> > >  const char *qemu_opt_get(QemuOpts *opts, const char *name)
> > >  {
> > >  QemuOpt *opt = qemu_opt_find(opts, name);
> > > +
> > > +if (!opt) {
> > > +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,
> > name);
> > > +if (desc && desc->def_value_str) {
> > > +return desc->def_value_str;
> > > +}
> > > +}
> > >  return opt ? opt->str : NULL;
> > >  }
> > >
> > > @@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char
> > *name, bool defval)
> > >  {
> > >  QemuOpt *opt = qemu_opt_find(opts, name);
> > >
> > > -if (opt == NULL)
> > > +if (opt == NULL) {
> > > +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,
> > name);
> > > +if (desc && desc->def_value_str) {
> > > +parse_option_bool(name, desc->def_value_str, &defval,
> > &error_abort);
> > > +}
> > >  return defval;
> > > +}
> > >  assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
> > >  return opt->value.boolean;
> > >  }
> > > @@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const
> > char *name, uint64_t defval)
> > >  {
> > >  QemuOpt *opt = qemu_opt_find(opts, name);
> > >
> > > -if (opt == NULL)
> > > +if (opt == NULL) {
> > > +const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,
> > name);
> > > +if (desc && desc->def_value_str) {
> > > +parse_option_number(name, desc->def_value_str, &defval,
> > > +&error_abo

Re: [Qemu-devel] [PATCH v24 05/31] QemuOpts: move qemu_opt_del ahead for later calling

2014-04-07 Thread Leandro Dorileo
On Thu, Apr 03, 2014 at 05:54:23PM +0800, Chunyan Liu wrote:
> In later patch, qemu_opt_get_del functions will be added, they will
> first get the option value, then call qemu_opt_del to remove the option
> from opt list. To prepare for that purpose, move qemu_opt_del ahead first.
> 
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
>  util/qemu-option.c | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index eab5102..25abd65 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -567,6 +567,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
> *name)
>  return NULL;
>  }
>  
> +static void qemu_opt_del(QemuOpt *opt)
> +{
> +QTAILQ_REMOVE(&opt->opts->head, opt, next);
> +g_free(opt->name);
> +g_free(opt->str);
> +g_free(opt);
> +}
> +
>  const char *qemu_opt_get(QemuOpts *opts, const char *name)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
> @@ -661,14 +669,6 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>  }
>  }
>  
> -static void qemu_opt_del(QemuOpt *opt)
> -{
> -QTAILQ_REMOVE(&opt->opts->head, opt, next);
> -g_free(opt->name);
> -g_free(opt->str);
> -g_free(opt);
> -}
> -
>  static bool opts_accepts_any(const QemuOpts *opts)
>  {
>  return opts->list->desc[0].name == NULL;
> -- 
> 1.7.12.4
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v24 04/31] QemuOpts: change opt->name|str from (const char *) to (char *)

2014-04-07 Thread Leandro Dorileo
On Thu, Apr 03, 2014 at 05:54:22PM +0800, Chunyan Liu wrote:
> qemu_opt_del() already assumes that all QemuOpt instances contain
> malloc'd name and value; but it had to cast away const because
> opts_start_struct() was doing its own thing and using static storage
> instead.  By using the correct type and malloced strings everywhere, the
> usage of this struct becomes clearer.
> 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
> Changes:
>   * Add explaination to this change.
>   * Remove extra space before char *name, char *str;
> 
>  include/qemu/option_int.h |  4 ++--
>  qapi/opts-visitor.c   | 10 +++---
>  util/qemu-option.c|  4 ++--
>  3 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
> index 8212fa4..6432c1a 100644
> --- a/include/qemu/option_int.h
> +++ b/include/qemu/option_int.h
> @@ -30,8 +30,8 @@
>  #include "qemu/error-report.h"
>  
>  struct QemuOpt {
> -const char   *name;
> -const char   *str;
> +char *name;
> +char *str;
>  
>  const QemuOptDesc *desc;
>  union {
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 5d830a2..7a64f4e 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char 
> *kind,
>  if (ov->opts_root->id != NULL) {
>  ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt);
>  
> -ov->fake_id_opt->name = "id";
> -ov->fake_id_opt->str = ov->opts_root->id;
> +ov->fake_id_opt->name = g_strdup("id");
> +ov->fake_id_opt->str = g_strdup(ov->opts_root->id);
>  opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt);
>  }
>  }
> @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp)
>  }
>  g_hash_table_destroy(ov->unprocessed_opts);
>  ov->unprocessed_opts = NULL;
> -g_free(ov->fake_id_opt);
> +if (ov->fake_id_opt) {
> +g_free(ov->fake_id_opt->name);
> +g_free(ov->fake_id_opt->str);
> +g_free(ov->fake_id_opt);
> +}
>  ov->fake_id_opt = NULL;
>  }
>  
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index d5e80da..eab5102 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>  static void qemu_opt_del(QemuOpt *opt)
>  {
>  QTAILQ_REMOVE(&opt->opts->head, opt, next);
> -g_free((/* !const */ char*)opt->name);
> -g_free((/* !const */ char*)opt->str);
> +g_free(opt->name);
> +g_free(opt->str);
>  g_free(opt);
>  }
>  
> -- 
> 1.7.12.4
> 



Re: [Qemu-devel] [PATCH v24 03/31] qapi: output def_value_str when query command line options

2014-04-07 Thread Leandro Dorileo
On Thu, Apr 03, 2014 at 05:54:21PM +0800, Chunyan Liu wrote:
> Change qapi interfaces to output the newly added def_value_str when querying
> command line options.
> 
> Reviewed-by: Eric Blake 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 
> ---
>  qapi-schema.json   | 6 +-
>  qmp-commands.hx| 2 ++
>  util/qemu-config.c | 4 
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 391356f..f04ea18 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4088,12 +4088,16 @@
>  #
>  # @help: #optional human readable text string, not suitable for parsing.
>  #
> +# @default: #optional string representation of the default used
> +#   if the option is omitted. (since 2.1)
> +#


what about #optional option's default value  - set if option not informed
 (since 2.1).

But if you feel comfortable with the current text you can add:

Reviewed-by: Leandro Dorileo 

--
Leandro Dorileo

>  # Since 1.5
>  ##
>  { 'type': 'CommandLineParameterInfo',
>'data': { 'name': 'str',
>  'type': 'CommandLineParameterType',
> -'*help': 'str' } }
> +'*help': 'str',
> +'*default': 'str' } }
>  
>  ##
>  # @CommandLineOptionInfo:
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index ed3ab92..1271332 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -2895,6 +2895,8 @@ Each array entry contains the following:
>or 'size')
>  - "help": human readable description of the parameter
>(json-string, optional)
> +- "default": default value string for the parameter
> + (json-string, optional)
>  
>  Example:
>  
> diff --git a/util/qemu-config.c b/util/qemu-config.c
> index f610101..d608b2f 100644
> --- a/util/qemu-config.c
> +++ b/util/qemu-config.c
> @@ -68,6 +68,10 @@ static CommandLineParameterInfoList 
> *query_option_descs(const QemuOptDesc *desc)
>  info->has_help = true;
>  info->help = g_strdup(desc[i].help);
>  }
> +if (desc[i].def_value_str) {
> +info->has_q_default = true;
> +info->q_default = g_strdup(desc[i].def_value_str);
> +}
>  
>  entry = g_malloc0(sizeof(*entry));
>  entry->value = info;
> -- 
> 1.7.12.4
> 



Re: [Qemu-devel] [PATCH v24 07/31] QemuOpts: add qemu_opts_print_help to replace print_option_help

2014-04-07 Thread Leandro Dorileo
On Thu, Apr 03, 2014 at 05:54:25PM +0800, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
> Changes:
>   * check non-empty list
> 
>  include/qemu/option.h |  1 +
>  util/qemu-option.c| 13 +
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 6653e43..fbf5dc2 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -166,5 +166,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void 
> *opaque);
>  void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
> *opaque,
>int abort_on_failure);
> +void qemu_opts_print_help(QemuOptsList *list);
>  
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 786c687..26710d6 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -553,6 +553,19 @@ void print_option_help(QEMUOptionParameter *list)
>  }
>  }
>  
> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> +QemuOptDesc *desc;
> +
> +assert(list);
> +desc = list->desc;
> +printf("Supported options:\n");
> +while (desc && desc->name) {
> +printf("%-16s %s\n", desc->name,
> +   desc->help ? desc->help : "No description available");
> +desc++;
> +}
> +}
>  /* -- */
>  
>  static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
> -- 
> 1.7.12.4
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v24 02/31] QemuOpts: add def_value_str to QemuOptDesc

2014-04-07 Thread Leandro Dorileo
>list->desc;
>  
> -fprintf(stderr, "%s: %s:", opts->list->name,
> -opts->id ? opts->id : "");
> -QTAILQ_FOREACH(opt, &opts->head, next) {
> -fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
> +if (desc[0].name == NULL) {
> +QTAILQ_FOREACH(opt, &opts->head, next) {
> +fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str);
> +}
> +return;
> +}
> +for (; desc && desc->name; desc++) {
> +const char *value;
> +QemuOpt *opt = qemu_opt_find(opts, desc->name);
> +
> +value = opt ? opt->str : desc->def_value_str;
> +if (!value) {
> +continue;
> +}
> +if (desc->type == QEMU_OPT_STRING) {
> +fprintf(stderr, "%s='%s' ", desc->name, value);
> +} else {
> +fprintf(stderr, "%s=%s ", desc->name, value);
> +}
>  }
>  fprintf(stderr, "\n");



I see you removed this fprintf() in the commit 
afe65f5c92694d551aaebc128233b623e8665d5e
Please do this change in this commit and avoid breaking the block tests in
further commits.

-- 
Leandro Dorileo

> -return 0;
>  }
>  
>  static int opts_do_parse(QemuOpts *opts, const char *params,
> -- 
> 1.7.12.4
> 



Re: [Qemu-devel] [PATCH v24 01/31] QemuOpts: move find_desc_by_name ahead for later calling

2014-04-07 Thread Leandro Dorileo
On Thu, Apr 03, 2014 at 05:54:19PM +0800, Chunyan Liu wrote:
> Reviewed-by: Eric Blake 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
>  util/qemu-option.c | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 9d898af..e6d10bc 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -173,6 +173,20 @@ static void parse_option_number(const char *name, const 
> char *value,
>  }
>  }
>  
> +static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
> +const char *name)
> +{
> +int i;
> +
> +for (i = 0; desc[i].name != NULL; i++) {
> +if (strcmp(desc[i].name, name) == 0) {
> +return &desc[i];
> +}
> +}
> +
> +return NULL;
> +}
> +
>  void parse_option_size(const char *name, const char *value,
> uint64_t *ret, Error **errp)
>  {
> @@ -637,20 +651,6 @@ static bool opts_accepts_any(const QemuOpts *opts)
>  return opts->list->desc[0].name == NULL;
>  }
>  
> -static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
> -const char *name)
> -{
> -int i;
> -
> -for (i = 0; desc[i].name != NULL; i++) {
> -if (strcmp(desc[i].name, name) == 0) {
> -return &desc[i];
> -}
> -}
> -
> -    return NULL;
> -}
> -
>  int qemu_opt_unset(QemuOpts *opts, const char *name)
>  {
>  QemuOpt *opt = qemu_opt_find(opts, name);
> -- 
> 1.7.12.4
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v24 00/31] replace QEMUOptionParameter with QemuOpts

2014-04-07 Thread Leandro Dorileo
On Thu, Apr 03, 2014 at 05:54:18PM +0800, Chunyan Liu wrote:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that 
> only
> one Qemu Option structure is kept in QEMU code.
> 
> ---
> Changes to v23:
>   * Improve conversion functions, make .assigned info not lost.
>   * Update qcow2.c amend_option, keep checking 'assigned'.
>   * Improve qemu_opt_get_*_del, after get option, delete all settings
> to this option (since in qemu_opt_set, if set option many times,
> there will be many opts in the list for the same option).
>   * Some other fixes for qemu-iotests
>   * Other fixes to v23 comments
> 
> Chunyan Liu (31):
>   QemuOpts: move find_desc_by_name ahead for later calling
>   QemuOpts: add def_value_str to QemuOptDesc
>   qapi: output def_value_str when query command line options
>   QemuOpts: change opt->name|str from (const char *) to (char *)
>   QemuOpts: move qemu_opt_del ahead for later calling
>   QemuOpts: add qemu_opt_get_*_del functions for replace work
>   QemuOpts: add qemu_opts_print_help to replace print_option_help
>   QemuOpts: add conversion between QEMUOptionParameter to QemuOpts
>   QemuOpts: add qemu_opts_append to replace append_option_parameters
>   QemuOpts: check NULL input for qemu_opts_del
>   qemu_opts_print: change fprintf stderr to printf
>   change block layer to support both QemuOpts and QEMUOptionParamter
>   vvfat.c: handle cross_driver's create_options and create_opts
>   cow.c: replace QEMUOptionParameter with QemuOpts
>   gluster.c: replace QEMUOptionParameter with QemuOpts
>   iscsi.c: replace QEMUOptionParameter with QemuOpts
>   qcow.c: replace QEMUOptionParameter with QemuOpts
>   qcow2.c: replace QEMUOptionParameter with QemuOpts
>   qed.c: replace QEMUOptionParameter with QemuOpts
>   raw-posix.c: replace QEMUOptionParameter with QemuOpts
>   raw-win32.c: replace QEMUOptionParameter with QemuOpts
>   raw_bsd.c: replace QEMUOptionParameter with QemuOpts
>   rbd.c: replace QEMUOptionParameter with QemuOpts
>   sheepdog.c: replace QEMUOptionParameter with QemuOpts
>   ssh.c: replace QEMUOptionParameter with QemuOpts
>   vdi.c: replace QEMUOptionParameter with QemuOpts
>   vhdx.c: replace QEMUOptionParameter with QemuOpts
>   vmdk.c: replace QEMUOptionParameter with QemuOpts
>   vpc.c: replace QEMUOptionParameter with QemuOpts
>   cleanup QEMUOptionParameter
>   QemuOpts: cleanup tmp 'allocated' member from QemuOptsList


block/nfs.c is missing conversion. Have you tested your own patches?
A simple git am && config && make is enough to break the build.

--
Leandro Dorileo


> 
>  block.c   |  96 
>  block/cow.c   |  52 ++--
>  block/gluster.c   |  73 +++---
>  block/iscsi.c |  32 ++-
>  block/qcow.c  |  72 +++---
>  block/qcow2.c | 264 +++--
>  block/qed.c   | 112 -
>  block/qed.h   |   3 +-
>  block/raw-posix.c |  55 ++---
>  block/raw-win32.c |  38 +--
>  block/raw_bsd.c   |  25 +-
>  block/rbd.c   |  61 +++--
>  block/sheepdog.c  | 102 
>  block/ssh.c   |  30 ++-
>  block/vdi.c   |  71 +++---
>  block/vhdx.c  |  97 
>  block/vhdx.h  |   1 +
>  block/vmdk.c  | 121 +-
>  block/vpc.c   |  60 ++---
>  block/vvfat.c |  11 +-
>  include/block/block.h |   7 +-
>  include/block/block_int.h |   9 +-
>  include/qemu/option.h |  53 +
>  include/qemu/option_int.h |   4 +-
>  qapi-schema.json  |   6 +-
>  qapi/opts-visitor.c   |  10 +-
>  qemu-img.c|  89 ---
>  qmp-commands.hx   |   2 +
>  util/qemu-config.c|   4 +
>  util/qemu-option.c| 587 
> --
>  30 files changed, 1029 insertions(+), 1118 deletions(-)
> 
> -- 
> 1.7.12.4
> 



Re: [Qemu-devel] [PATCH v5 for 2.0 3/3] abort QEMU if group name in option table doesn't match with defined option name

2014-03-28 Thread Leandro Dorileo
Hi Amos,

On Thu, Mar 27, 2014 at 09:04:31PM +0800, Amos Kong wrote:
> All the options are defined in qemu-options.hx. If we can't find a
> matched option definition by group name of option table, then the
> group name doesn't match with defined option name, it's not allowed
> from 2.0
> 
> Signed-off-by: Amos Kong 
> ---
>  qemu-options.h | 12 
>  util/qemu-config.c | 28 
>  vl.c   | 19 ++-
>  3 files changed, 42 insertions(+), 17 deletions(-)
> 
> diff --git a/qemu-options.h b/qemu-options.h
> index 89a009e..4024487 100644
> --- a/qemu-options.h
> +++ b/qemu-options.h
> @@ -28,9 +28,21 @@
>  #ifndef _QEMU_OPTIONS_H_
>  #define _QEMU_OPTIONS_H_
>  
> +#include "sysemu/arch_init.h"
> +
>  enum {
>  #define QEMU_OPTIONS_GENERATE_ENUM
>  #include "qemu-options-wrapper.h"
>  };
>  
> +#define HAS_ARG 0x0001
> +
> +typedef struct QEMUOption {
> +const char *name;
> +int flags;
> +int index;
> +uint32_t arch_mask;
> +} QEMUOption;
> +
> +extern const QEMUOption qemu_options[];
>  #endif
> diff --git a/util/qemu-config.c b/util/qemu-config.c
> index f610101..eba5428 100644
> --- a/util/qemu-config.c
> +++ b/util/qemu-config.c
> @@ -6,6 +6,14 @@
>  #include "hw/qdev.h"
>  #include "qapi/error.h"
>  #include "qmp-commands.h"
> +#include "qemu-options.h"
> +
> +const QEMUOption qemu_options[] = {
> +{ "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
> +#define QEMU_OPTIONS_GENERATE_OPTIONS
> +#include "qemu-options-wrapper.h"
> +{ NULL },
> +};
>  
>  static QemuOptsList *vm_config_groups[32];
>  static QemuOptsList *drive_config_groups[4];
> @@ -184,6 +192,20 @@ void qemu_add_drive_opts(QemuOptsList *list)
>  abort();
>  }
>  
> +/* check if the option is defined in qemu-options.hx */
> +static bool opt_is_defined(const char *name)
> +{
> +int i;
> +
> +for (i = 0; qemu_options[i].name; i++) {
> +if (!strcmp(qemu_options[i].name, name)) {
> +return true;
> +}
> +}
> +
> +return false;
> +}
> +
>  void qemu_add_opts(QemuOptsList *list)
>  {
>  int entries, i;
> @@ -193,6 +215,12 @@ void qemu_add_opts(QemuOptsList *list)
>  for (i = 0; i < entries; i++) {
>  if (vm_config_groups[i] == NULL) {
>  vm_config_groups[i] = list;
> +if (!opt_is_defined(list->name)) {
> +error_report("Didn't find a matched option definition, "
> + "group name (%s) of option table must match 
> with "
> + "defined option name (Since 2.0)", list->name);


I'm not a native English speaker but I don't fell comfortable with this
message output, what about "option table's group name (%s) must match with
predefined option name (Since 2.0)"?

The patch looks good, I tested it and it works properly, so

Reviewed-by: Leandro Dorileo 



> +abort();
> +}
>  return;
>  }
>  }
> diff --git a/vl.c b/vl.c
> index 0464494..bd44c52 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -111,7 +111,6 @@ int main(int argc, char **argv)
>  #include "trace/control.h"
>  #include "qemu/queue.h"
>  #include "sysemu/cpus.h"
> -#include "sysemu/arch_init.h"
>  #include "qemu/osdep.h"
>  
>  #include "ui/qemu-spice.h"
> @@ -2082,22 +2081,6 @@ static void help(int exitcode)
>  exit(exitcode);
>  }
>  
> -#define HAS_ARG 0x0001
> -
> -typedef struct QEMUOption {
> -const char *name;
> -int flags;
> -int index;
> -uint32_t arch_mask;
> -} QEMUOption;
> -
> -static const QEMUOption qemu_options[] = {
> -{ "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
> -#define QEMU_OPTIONS_GENERATE_OPTIONS
> -#include "qemu-options-wrapper.h"
> -{ NULL },
> -};
> -
>  static bool vga_available(void)
>  {
>  return object_class_by_name("VGA") || object_class_by_name("isa-vga");
> @@ -2842,6 +2825,8 @@ static const QEMUOption *lookup_opt(int argc, char 
> **argv,
>  return popt;
>  }
>  
> +#undef HAS_ARG
> +
>  static gpointer malloc_and_trace(gsize n_bytes)
>  {
>  void *ptr = malloc(n_bytes);
> -- 
> 1.8.5.3
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [RFC PATCH 2/4] qemu-log: support simple pid substitution in logfile

2014-03-28 Thread Leandro Dorileo
On Thu, Mar 27, 2014 at 09:59:21AM +, Alex Bennée wrote:
> 
> Leandro Dorileo  writes:
> 
> > On Wed, Mar 26, 2014 at 02:37:12PM +, alex.ben...@linaro.org wrote:
> >> From: Alex Bennée 
> >> 
> >> When debugging stuff that occurs over several forks it would be useful
> >> not to keep overwriting the one logfile you've set-up. This allows a
> >> simple %d to be included once in the logfile parameter which is
> >> substituted with getpid().
> 
> >
> > Looks good to me.
> 
> Is that a Reviewed-by? If you include a Reviewed-by tag it makes it
> easier to copy and paste into the commit for the next iteration.

Sure, you can add

Reviewed-by: Leandro Dorileo 

-- 
Leandro Dorileo



Re: [Qemu-devel] [RFC PATCH 2/4] qemu-log: support simple pid substitution in logfile

2014-03-26 Thread Leandro Dorileo
On Wed, Mar 26, 2014 at 02:37:12PM +, alex.ben...@linaro.org wrote:
> From: Alex Bennée 
> 
> When debugging stuff that occurs over several forks it would be useful
> not to keep overwriting the one logfile you've set-up. This allows a
> simple %d to be included once in the logfile parameter which is
> substituted with getpid().
> 
> Signed-off-by: Alex Bennée 
> 
> diff --git a/qemu-log.c b/qemu-log.c
> index 35bbb56..2897596 100644
> --- a/qemu-log.c
> +++ b/qemu-log.c
> @@ -81,11 +81,24 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
>  qemu_log_close();
>  }
>  }
> -
> +/*
> + * Allow the user to include %d in their logfile which will be
> + * substituted with the current PID. This is useful for debugging many
> + * nested linux-user tasks but will result in lots of logs.
> + */
>  void qemu_set_log_filename(const char *filename)
>  {
>  g_free(logfilename);
> -logfilename = g_strdup(filename);
> +if (g_strrstr(filename, "%d")) {
> +/* if we are going to format this we'd better validate first */
> +if (g_regex_match_simple("^[^%]+%d[^%]+$", filename, 0, 0)) {
> +logfilename = g_strdup_printf(filename, getpid());
> +} else {
> +g_error("Bad logfile format: %s", filename);
> +}
> +} else {
> +    logfilename = g_strdup(filename);
> +}
>  qemu_log_close();
>  qemu_set_log(qemu_loglevel);
>  }

Looks good to me.

-- 
Leandro Dorileo



Re: [Qemu-devel] [RFC PATCH 1/4] qemu-log: correct help text for -d cpu

2014-03-26 Thread Leandro Dorileo
On Wed, Mar 26, 2014 at 02:37:11PM +, alex.ben...@linaro.org wrote:
> From: Alex Bennée 
> 
> This doesn't just dump CPU state on translation but on every block
> entrance.
> 
> Signed-off-by: Alex Bennée 
> 
> diff --git a/qemu-log.c b/qemu-log.c
> index 797f2af..35bbb56 100644
> --- a/qemu-log.c
> +++ b/qemu-log.c
> @@ -105,7 +105,7 @@ const QEMULogItem qemu_log_items[] = {
>  { CPU_LOG_EXEC, "exec",
>"show trace before each executed TB (lots of logs)" },
>  { CPU_LOG_TB_CPU, "cpu",
> -  "show CPU state before block translation" },
> +  "show CPU registers before each executed TB (lots of logs)" },

what about s/lots of logs/hight volume log/ or maybe s/lots of logs/hight 
volume/ ?

Regards

--
Leandro Dorileo

>  { CPU_LOG_PCALL, "pcall",
>"x86 only: show protected mode far calls/returns/exceptions" },
>  { CPU_LOG_RESET, "cpu_reset",
> -- 
> 1.9.1
> 
> 



Re: [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts

2014-03-25 Thread Leandro Dorileo
On Tue, Mar 25, 2014 at 06:09:40PM +, Leandro Dorileo wrote:
> On Fri, Mar 21, 2014 at 06:12:11PM +0800, Chunyan Liu wrote:
> > This patch series is to replace QEMUOptionParameter with QemuOpts, so that 
> > only
> > one Qemu Option structure is kept in QEMU code.
> > 
> > ---
> > Changes to v21:
> >   * Move find_desc_by_name and qemu_opt_del functions ahead in separate
> > patches before later calling, so to avoid static declaration.
> >   * Remove some changes that not quite necessary for this patch series:
> > improve qemu_opt_set, improve assert() in qemu_opt_get,
> > NULL check in qemu_opt_get and qemu_opt_find.
> >   * improve convert functions and qemu_opts_append() functions
> >   * improve block layer changes to support both struct
> >   * other fixes according to Eric and Stefan's comments.
> > 
> > Not added:
> >   * QemuOpts test suite what Eric suggests, not included in this version, 
> > since:
> > Currently, things that changes QemuOpts original syntax only include:
> > qemu_opts_del: NULL input check.
> > opt->name, opt->str: from const char * to char *
> > Generally, no big change to its original usage.
> > 
> > Things that are newly added to QemuOpts are:
> > qemu_opt_append function
> > qemu_opt_get_*_del functions
> > I think we could add tests for these functions later based on
> > Leandro Dorileo's test suite patches:
> > https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg03282.html
> > 
> > 
> > Chunyan Liu (32):
> >   move find_desc_by_name ahead for later calling
> >   add def_value_str to QemuOptDesc
> >   qapi: output def_value_str when query command line options
> >   change opt->name and opt->str from (const char *) to (char *)
> >   move qemu_opt_del ahead for later calling
> >   add qemu_opt_get_*_del functions for replace work
> >   add qemu_opts_print_help to replace print_option_help
> >   add convert functions between QEMUOptionParameter to QemuOpts
> >   add qemu_opts_append to repalce append_option_parameters
> >   check NULL input for qemu_opts_del
> >   qemu_opts_print: change fprintf stderr to printf
> >   qcow2.c: remove 'assigned' check in amend
> >   change block layer to support both QemuOpts and QEMUOptionParamter
> >   vvfat.c: handle cross_driver's create_options and create_opts
> >   cow.c: replace QEMUOptionParameter with QemuOpts
> >   gluster.c: replace QEMUOptionParameter with QemuOpts
> >   iscsi.c: replace QEMUOptionParameter with QemuOpts
> >   qcow.c: replace QEMUOptionParameter with QemuOpts
> >   qcow2.c: replace QEMUOptionParameter with QemuOpts
> >   qed.c: replace QEMUOptionParameter with QemuOpts
> >   raw-posix.c: replace QEMUOptionParameter with QemuOpts
> >   raw-win32.c: replace QEMUOptionParameter with QemuOpts
> >   raw_bsd.c: replace QEMUOptionParameter with QemuOpts
> >   rbd.c: replace QEMUOptionParameter with QemuOpts
> >   sheepdog.c: replace QEMUOptionParameter with QemuOpts
> >   ssh.c: replace QEMUOptionParameter with QemuOpts
> >   vdi.c: replace QEMUOptionParameter with QemuOpts
> >   vhdx.c: replace QEMUOptionParameter with QemuOpts
> >   vmdk.c: replace QEMUOptionParameter with QemuOpts
> >   vpc.c: replace QEMUOptionParameter with QemuOpts
> >   cleanup QEMUOptionParameter
> >   cleanup tmp 'mallocd' member from QemuOptsList
> 
> 
> The series is still breaking the build and the io tests.
> 
> I picked some patches in the series to see if it was
> supposed to work, I could not build without fixing some
> stuffs (like I commented on [31/32]).
> 
> After fixing the build stuffs I could not successfuly run
> the io tests.
> 
> Testing with all your patches applied I could also not run
> the io tests, they all failed.
> 


I commented on your [11/32] patch about a new line in the end of
qemu_opts_print() being the source of most of io tests breakeage.

Fixing that we still have 073 and 082 breaking. Where 082 shows me
the following:

082[17:07:48]*** Error in `qemu-img': corrupted double-linked 
list: 0x7f69209d2340 ***

Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf

2014-03-25 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:12:22PM +0800, Chunyan Liu wrote:
> Currently this function is not used anywhere. In later patches, it will
> replace print_option_parameters. print_option_parameters uses printf,
> to avoid print info changes after switching to QemuOpts, change
> qemu_opts_print from fprintf stderr to printf to keep consistent.
> 
> Signed-off-by: Chunyan Liu 
> ---
>  util/qemu-option.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index e9802f3..a9c53cd 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -1012,7 +1012,7 @@ void qemu_opts_print(QemuOpts *opts)
>  
>  if (desc[0].name == NULL) {
>  QTAILQ_FOREACH(opt, &opts->head, next) {
> -fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str);
> +printf("%s=\"%s\" ", opt->name, opt->str);
>  }
>  return;
>  }
> @@ -1025,12 +1025,12 @@ void qemu_opts_print(QemuOpts *opts)
>  continue;
>  }
>  if (desc->type == QEMU_OPT_STRING) {
> -fprintf(stderr, "%s='%s' ", desc->name, value);
> +printf("%s='%s' ", desc->name, value);
>  } else {
> -fprintf(stderr, "%s=%s ", desc->name, value);
> +printf("%s=%s ", desc->name, value);
>  }
>  }
> -fprintf(stderr, "\n");
> +printf("\n");


This new line is breaking most of the io tests since it changes
the expected output.

Regards...

--
Leandro Dorileo

>  }
>  
>  static int opts_do_parse(QemuOpts *opts, const char *params,
> -- 
> 1.7.12.4
> 
> 



Re: [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend

2014-03-25 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:12:23PM +0800, Chunyan Liu wrote:
> In QEMUOptionParameter and QemuOptsList conversion, 'assigned' info
> is lost. In current code, only qcow2 amend uses 'assigned' for a check.
> It will be broken after next patch. So, remove 'assigned' check. If it's
> really a must that amend is valid only to explicitly defined options,
> we could add it TODO later.
> 
> And for 'prealloc', it's not support amend, since nowhere to compare it
> is changed or not, simply ignore it.
> 
> Signed-off-by: Chunyan Liu 
> ---
>  block/qcow2.c | 8 +---
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index b9dc960..92d3327 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2088,11 +2088,6 @@ static int qcow2_amend_options(BlockDriverState *bs,
>  
>  for (i = 0; options[i].name; i++)
>  {
> -if (!options[i].assigned) {
> -/* only change explicitly defined options */
> -continue;
> -}
> -
>  if (!strcmp(options[i].name, "compat")) {
>  if (!options[i].value.s) {
>  /* preserve default */
> @@ -2106,8 +2101,7 @@ static int qcow2_amend_options(BlockDriverState *bs,
>  return -EINVAL;
>  }
>  } else if (!strcmp(options[i].name, "preallocation")) {
> -fprintf(stderr, "Cannot change preallocation mode.\n");
> -return -ENOTSUP;
> +/* Cannot change preallocation mode. Ignore it. */


You're ignoring/silencing an informed option, I think it's fear enough to 
notify the caller
about it - even if we're never using it for amend.

Regards...

--
Leandro Dorileo


>      } else if (!strcmp(options[i].name, "size")) {
>  new_size = options[i].value.n;
>  } else if (!strcmp(options[i].name, "backing_file")) {
> -- 
> 1.7.12.4
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts

2014-03-25 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:12:25PM +0800, Chunyan Liu wrote:
> vvfat shares create options of qcow driver. To avoid vvfat broken when
> qcow driver changes from QEMUOptionParameter to QemuOpts, let it able
> to handle both cases.
> 
> Signed-off-by: Chunyan Liu 
> ---
>  block/vvfat.c | 19 ++-
>  1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/block/vvfat.c b/block/vvfat.c
> index ee32b3c..82b1521 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -2907,7 +2907,8 @@ static BlockDriver vvfat_write_target = {
>  static int enable_write_target(BDRVVVFATState *s)
>  {
>  BlockDriver *bdrv_qcow;
> -QEMUOptionParameter *options;
> +QemuOptsList *create_opts;
> +QemuOpts *opts;


opts is used uninitialized.


>  Error *local_err = NULL;
>  int ret;
>  int size = sector2cluster(s, s->sector_count);
> @@ -2922,11 +2923,17 @@ static int enable_write_target(BDRVVVFATState *s)
>  }
>  
>  bdrv_qcow = bdrv_find_format("qcow");
> -options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
> -set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
> -set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
> +assert(!(bdrv_qcow->create_opts && bdrv_qcow->create_options));
> +if (bdrv_qcow->create_options) {
> +create_opts = params_to_opts(bdrv_qcow->create_options);
> +} else {
> +create_opts = bdrv_qcow->create_opts;
> +}
> +opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> +qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
> +qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
>  
> -ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, 
> &local_err);
> +ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
>  if (ret < 0) {
>  qerror_report_err(local_err);
>  error_free(local_err);
> @@ -2955,6 +2962,8 @@ static int enable_write_target(BDRVVVFATState *s)
>  return 0;
>  
>  err:
> +qemu_opts_del(opts);
> +qemu_opts_free(create_opts);
>  g_free(s->qcow_filename);
>  s->qcow_filename = NULL;
>  return ret;
> -- 
> 1.7.12.4
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters

2014-03-25 Thread Leandro Dorileo
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 

Reviewed-by: Leandro Dorileo 


> ---
> 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



Re: [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help

2014-03-25 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:12:18PM +0800, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 


Reviewed-by: Leandro Dorileo 


> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c| 11 +++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 6653e43..fbf5dc2 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -166,5 +166,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void 
> *opaque);
>  void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
> *opaque,
>int abort_on_failure);
> +void qemu_opts_print_help(QemuOptsList *list);
>  
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 02a7602..315a7bb 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -553,6 +553,17 @@ void print_option_help(QEMUOptionParameter *list)
>  }
>  }
>  
> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> +int i;
> +
> +printf("Supported options:\n");
> +for (i = 0; list && list->desc[i].name; i++) {
> +printf("%-16s %s\n", list->desc[i].name,
> +   list->desc[i].help ?
> +   list->desc[i].help : "No description available");
> +}
> +}
>  /* -- */
>  
>  static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
> -- 
> 1.7.12.4
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *)

2014-03-25 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:12:15PM +0800, Chunyan Liu wrote:
> Signed-off-by: Chunyan Liu 
> ---
>  include/qemu/option_int.h |  4 ++--
>  qapi/opts-visitor.c   | 10 +++---
>  util/qemu-option.c|  4 ++--
>  3 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
> index 8212fa4..db9ed91 100644
> --- a/include/qemu/option_int.h
> +++ b/include/qemu/option_int.h
> @@ -30,8 +30,8 @@
>  #include "qemu/error-report.h"
>  
>  struct QemuOpt {
> -const char   *name;
> -const char   *str;
> +char   *name;
> +char   *str;


I still don't see why you need this change. I understand you're strdup'ing name
and str, what I can't get is why you need this, and since the lack of 
description
in the patch itself I don't know what you're fixing here.

I saw the opts-visitor.c users and they're mostly controlling their QemuOpts 
instances,
their instances come after a qemu_opts_from_qdict() or qemu_opts_parse().

I haven't seen the users with too much inversion but I guess they follow the 
same
pattern.

I may be missing something completely obvious here but if you really need this 
change
could you introduce a test in the test-opts-visitor.c test suite so we can 
understand
the problem you're fixing here?

Regards...

-- 
Leandro Dorileo

>  
>  const QemuOptDesc *desc;
>  union {
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 5d830a2..7a64f4e 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char 
> *kind,
>  if (ov->opts_root->id != NULL) {
>  ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt);
>  
> -ov->fake_id_opt->name = "id";
> -ov->fake_id_opt->str = ov->opts_root->id;
> +ov->fake_id_opt->name = g_strdup("id");
> +ov->fake_id_opt->str = g_strdup(ov->opts_root->id);
>  opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt);
>  }
>  }
> @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp)
>  }
>  g_hash_table_destroy(ov->unprocessed_opts);
>  ov->unprocessed_opts = NULL;
> -g_free(ov->fake_id_opt);
> +if (ov->fake_id_opt) {
> +g_free(ov->fake_id_opt->name);
> +g_free(ov->fake_id_opt->str);
> +g_free(ov->fake_id_opt);
> +}
>  ov->fake_id_opt = NULL;
>  }
>  
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index d5e80da..eab5102 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>  static void qemu_opt_del(QemuOpt *opt)
>  {
>  QTAILQ_REMOVE(&opt->opts->head, opt, next);
> -g_free((/* !const */ char*)opt->name);
> -g_free((/* !const */ char*)opt->str);
> +g_free(opt->name);
> +g_free(opt->str);
>  g_free(opt);
>  }
>  
> -- 
> 1.7.12.4
> 
> 



Re: [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter

2014-03-25 Thread Leandro Dorileo
he value is delimited by an = character. To specify a value which
> - * contains commas, double each comma so it won't be recognized as the end of
> - * the parameter.
> - *
> - * For more details of the parsing see above.
> - *
> - * Returns a pointer to the first element of dest (or the newly allocated 
> copy)
> - * or NULL in error cases
> - */
> -QEMUOptionParameter *parse_option_parameters(const char *param,
> -QEMUOptionParameter *list, QEMUOptionParameter *dest)
> -{
> -QEMUOptionParameter *allocated = NULL;
> -char name[256];
> -char value[256];
> -char *param_delim, *value_delim;
> -char next_delim;
> -int i;
> -
> -if (list == NULL) {
> -return NULL;
> -}
> -
> -if (dest == NULL) {
> -dest = allocated = append_option_parameters(NULL, list);
> -}
> -
> -for (i = 0; dest[i].name; i++) {
> -dest[i].assigned = false;
> -}
> -
> -while (*param) {
> -
> -// Find parameter name and value in the string
> -param_delim = strchr(param, ',');
> -value_delim = strchr(param, '=');
> -
> -if (value_delim && (value_delim < param_delim || !param_delim)) {
> -next_delim = '=';
> -} else {
> -next_delim = ',';
> -value_delim = NULL;
> -}
> -
> -param = get_opt_name(name, sizeof(name), param, next_delim);
> -if (value_delim) {
> -param = get_opt_value(value, sizeof(value), param + 1);
> -}
> -if (*param != '\0') {
> -param++;
> -}
> -
> -// Set the parameter
> -if (set_option_parameter(dest, name, value_delim ? value : NULL)) {
> -goto fail;
> -}
> -}
> -
> -return dest;
> -
> -fail:
> -// Only free the list if it was newly allocated
> -free_option_parameters(allocated);
> -return NULL;
> -}
> -
>  bool has_help_option(const char *param)
>  {
>  size_t buflen = strlen(param) + 1;
> @@ -513,46 +259,6 @@ out:
>  return result;
>  }
>  
> -/*
> - * Prints all options of a list that have a value to stdout
> - */
> -void print_option_parameters(QEMUOptionParameter *list)
> -{
> -while (list && list->name) {
> -switch (list->type) {
> -case OPT_STRING:
> - if (list->value.s != NULL) {
> - printf("%s='%s' ", list->name, list->value.s);
> - }
> -break;
> -case OPT_FLAG:
> -printf("%s=%s ", list->name, list->value.n ? "on" : "off");
> -break;
> -case OPT_SIZE:
> -case OPT_NUMBER:
> -printf("%s=%" PRId64 " ", list->name, list->value.n);
> -break;
> -default:
> -printf("%s=(unknown type) ", list->name);
> -break;
> -}
> -list++;
> -}
> -}
> -
> -/*
> - * Prints an overview of all available options
> - */
> -void print_option_help(QEMUOptionParameter *list)
> -{
> -printf("Supported options:\n");
> -while (list && list->name) {
> -printf("%-16s %s\n", list->name,
> -list->help ? list->help : "No description available");
> -list++;
> -}
> -}
> -
>  void qemu_opts_print_help(QemuOptsList *list)
>  {
>  int i;
> @@ -1346,122 +1052,6 @@ static size_t count_opts_list(QemuOptsList *list)
>  return num_opts;
>  }
>  
> -/* Convert QEMUOptionParameter to QemuOpts
> - * FIXME: this function will be removed after all drivers
> - * switch to QemuOpts
> - */
> -QemuOptsList *params_to_opts(QEMUOptionParameter *list)
> -{
> -QemuOptsList *opts = NULL;
> -size_t num_opts, i = 0;
> -
> -if (!list

Re: [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts

2014-03-25 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:12:11PM +0800, Chunyan Liu wrote:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that 
> only
> one Qemu Option structure is kept in QEMU code.
> 
> ---
> Changes to v21:
>   * Move find_desc_by_name and qemu_opt_del functions ahead in separate
> patches before later calling, so to avoid static declaration.
>   * Remove some changes that not quite necessary for this patch series:
> improve qemu_opt_set, improve assert() in qemu_opt_get,
> NULL check in qemu_opt_get and qemu_opt_find.
>   * improve convert functions and qemu_opts_append() functions
>   * improve block layer changes to support both struct
>   * other fixes according to Eric and Stefan's comments.
> 
> Not added:
>   * QemuOpts test suite what Eric suggests, not included in this version, 
> since:
> Currently, things that changes QemuOpts original syntax only include:
> qemu_opts_del: NULL input check.
> opt->name, opt->str: from const char * to char *
> Generally, no big change to its original usage.
> 
> Things that are newly added to QemuOpts are:
> qemu_opt_append function
> qemu_opt_get_*_del functions
> I think we could add tests for these functions later based on
> Leandro Dorileo's test suite patches:
> https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg03282.html
> 
> 
> Chunyan Liu (32):
>   move find_desc_by_name ahead for later calling
>   add def_value_str to QemuOptDesc
>   qapi: output def_value_str when query command line options
>   change opt->name and opt->str from (const char *) to (char *)
>   move qemu_opt_del ahead for later calling
>   add qemu_opt_get_*_del functions for replace work
>   add qemu_opts_print_help to replace print_option_help
>   add convert functions between QEMUOptionParameter to QemuOpts
>   add qemu_opts_append to repalce append_option_parameters
>   check NULL input for qemu_opts_del
>   qemu_opts_print: change fprintf stderr to printf
>   qcow2.c: remove 'assigned' check in amend
>   change block layer to support both QemuOpts and QEMUOptionParamter
>   vvfat.c: handle cross_driver's create_options and create_opts
>   cow.c: replace QEMUOptionParameter with QemuOpts
>   gluster.c: replace QEMUOptionParameter with QemuOpts
>   iscsi.c: replace QEMUOptionParameter with QemuOpts
>   qcow.c: replace QEMUOptionParameter with QemuOpts
>   qcow2.c: replace QEMUOptionParameter with QemuOpts
>   qed.c: replace QEMUOptionParameter with QemuOpts
>   raw-posix.c: replace QEMUOptionParameter with QemuOpts
>   raw-win32.c: replace QEMUOptionParameter with QemuOpts
>   raw_bsd.c: replace QEMUOptionParameter with QemuOpts
>   rbd.c: replace QEMUOptionParameter with QemuOpts
>   sheepdog.c: replace QEMUOptionParameter with QemuOpts
>   ssh.c: replace QEMUOptionParameter with QemuOpts
>   vdi.c: replace QEMUOptionParameter with QemuOpts
>   vhdx.c: replace QEMUOptionParameter with QemuOpts
>   vmdk.c: replace QEMUOptionParameter with QemuOpts
>   vpc.c: replace QEMUOptionParameter with QemuOpts
>   cleanup QEMUOptionParameter
>   cleanup tmp 'mallocd' member from QemuOptsList


The series is still breaking the build and the io tests.

I picked some patches in the series to see if it was
supposed to work, I could not build without fixing some
stuffs (like I commented on [31/32]).

After fixing the build stuffs I could not successfuly run
the io tests.

Testing with all your patches applied I could also not run
the io tests, they all failed.

Regards...

-- 
Leandro Dorileo



[Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-03-25 Thread Leandro Dorileo
Cover basic aspects and API usage for QemuOpt. The current implementation
covers the API's planned to be changed by Chunyan Liu in his QEMUOptionParameter
replacement/cleanup job.

Other APIs should be covered in future improvements.

Signed-off-by: Leandro Dorileo 
Reviewed-by: Eric Blake 
---

Notes:
v3:
  + fix a typo (s/dinamically/dynamically/);

v2:
  + fixed comments;
  + make use of g_assert_cmpstr();
  + use error_abort instead of a local_err for qemu_opts_absorb_qdict();
  + asserts on QemuOptsList (empty and list name);
  + added test_qemu_opt_unset();
  + asserts on qemu_opt_*_set() return;
  + added test_qemu_opts_reset();
  + added test_qemu_opts_set();

 tests/Makefile |   3 +
 tests/test-qemu-opts.c | 455 +
 2 files changed, 458 insertions(+)
 create mode 100644 tests/test-qemu-opts.c

diff --git a/tests/Makefile b/tests/Makefile
index 471b4c8..4814283 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-y += tests/test-vmstate$(EXESUF)
+check-unit-y += tests/test-qemu-opts$(EXESUF)
+gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -272,6 +274,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
libqemustub.a
 
 # QTest rules
 
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
new file mode 100644
index 000..38917d4
--- /dev/null
+++ b/tests/test-qemu-opts.c
@@ -0,0 +1,455 @@
+/*
+ * QemuOpts unit-tests.
+ *
+ * Copyright (C) 2014 Leandro Dorileo 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qapi/error.h"
+#include "qapi/qmp/qstring.h"
+#include "qemu/config-file.h"
+
+#include 
+#include 
+
+static QemuOptsList opts_list_01 = {
+.name = "opts_list_01",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str3",
+.type = QEMU_OPT_STRING,
+},{
+.name = "number1",
+.type = QEMU_OPT_NUMBER,
+},
+{ /* end of list */ }
+},
+};
+
+static QemuOptsList opts_list_02 = {
+.name = "opts_list_02",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "bool1",
+.type = QEMU_OPT_BOOL,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "size1",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
+QemuOptsList opts_list_03 = {
+.name = "opts_list_03",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
+static void register_opts(void)
+{
+qemu_add_opts(&opts_list_01);
+qemu_add_opts(&opts_list_02);
+qemu_add_opts(&opts_list_03);
+}
+
+static void test_find_unknown_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* should not return anything, we don't have an "unknown" option */
+list = qemu_find_opts("unknown");
+g_assert(list == NULL);
+}
+
+static void test_qemu_find_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* we have an "opts_list_01" option, should return it */
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+}
+
+static void test_qemu_opts_create(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+
+register_opts();
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert(QTAILQ_EMPTY(&list->head));
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/* create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abo

[Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-03-25 Thread Leandro Dorileo
Cover basic aspects and API usage for QemuOpt. The current implementation
covers the API's planned to be changed by Chunyan Liu in his QEMUOptionParameter
replacement/cleanup job.

Other APIs should be covered in future improvements.

Signed-off-by: Leandro Dorileo 
Reviewed-by: Eric Blake 
---
 tests/Makefile |   3 +
 tests/test-qemu-opts.c | 455 +
 2 files changed, 458 insertions(+)
 create mode 100644 tests/test-qemu-opts.c

diff --git a/tests/Makefile b/tests/Makefile
index 471b4c8..4814283 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-y += tests/test-vmstate$(EXESUF)
+check-unit-y += tests/test-qemu-opts$(EXESUF)
+gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -272,6 +274,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
libqemustub.a
 
 # QTest rules
 
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
new file mode 100644
index 000..abd2fb8
--- /dev/null
+++ b/tests/test-qemu-opts.c
@@ -0,0 +1,455 @@
+/*
+ * QemuOpts unit-tests.
+ *
+ * Copyright (C) 2014 Leandro Dorileo 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qapi/error.h"
+#include "qapi/qmp/qstring.h"
+#include "qemu/config-file.h"
+
+#include 
+#include 
+
+static QemuOptsList opts_list_01 = {
+.name = "opts_list_01",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str3",
+.type = QEMU_OPT_STRING,
+},{
+.name = "number1",
+.type = QEMU_OPT_NUMBER,
+},
+{ /* end of list */ }
+},
+};
+
+static QemuOptsList opts_list_02 = {
+.name = "opts_list_02",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "bool1",
+.type = QEMU_OPT_BOOL,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "size1",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
+QemuOptsList opts_list_03 = {
+.name = "opts_list_03",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
+static void register_opts(void)
+{
+qemu_add_opts(&opts_list_01);
+qemu_add_opts(&opts_list_02);
+qemu_add_opts(&opts_list_03);
+}
+
+static void test_find_unknown_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* should not return anything, we don't have an "unknown" option */
+list = qemu_find_opts("unknown");
+g_assert(list == NULL);
+}
+
+static void test_qemu_find_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* we have an "opts_list_01" option, should return it */
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+}
+
+static void test_qemu_opts_create(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+
+register_opts();
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert(QTAILQ_EMPTY(&list->head));
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/* create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+g_assert(opts != NULL);
+g_assert(!QTAILQ_EMPTY(&list->head));
+
+/* now we've create the opts, must find it */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts != NULL);
+
+qemu_opts_del(opts);
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+}
+
+static void test_qemu_opt_get(void)
+{
+QemuOptsList *list;
+Q

[Qemu-devel] [PATCH v3] QemuOpt: add unit tests

2014-03-25 Thread Leandro Dorileo
Cover basic aspects and API usage for QemuOpt. The current implementation
covers the API's planned to be changed by Chunyan Liu in his QEMUOptionParameter
replacement/cleanup job.

Other APIs should be covered in future improvements.

Signed-off-by: Leandro Dorileo 
Reviewed-by: Eric Blake 
---
 tests/Makefile |   3 +
 tests/test-qemu-opts.c | 455 +
 2 files changed, 458 insertions(+)
 create mode 100644 tests/test-qemu-opts.c

diff --git a/tests/Makefile b/tests/Makefile
index 471b4c8..4814283 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-y += tests/test-vmstate$(EXESUF)
+check-unit-y += tests/test-qemu-opts$(EXESUF)
+gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -272,6 +274,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
libqemustub.a
 
 # QTest rules
 
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
new file mode 100644
index 000..abd2fb8
--- /dev/null
+++ b/tests/test-qemu-opts.c
@@ -0,0 +1,455 @@
+/*
+ * QemuOpts unit-tests.
+ *
+ * Copyright (C) 2014 Leandro Dorileo 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qapi/error.h"
+#include "qapi/qmp/qstring.h"
+#include "qemu/config-file.h"
+
+#include 
+#include 
+
+static QemuOptsList opts_list_01 = {
+.name = "opts_list_01",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str3",
+.type = QEMU_OPT_STRING,
+},{
+.name = "number1",
+.type = QEMU_OPT_NUMBER,
+},
+{ /* end of list */ }
+},
+};
+
+static QemuOptsList opts_list_02 = {
+.name = "opts_list_02",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "bool1",
+.type = QEMU_OPT_BOOL,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "size1",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
+QemuOptsList opts_list_03 = {
+.name = "opts_list_03",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
+static void register_opts(void)
+{
+qemu_add_opts(&opts_list_01);
+qemu_add_opts(&opts_list_02);
+qemu_add_opts(&opts_list_03);
+}
+
+static void test_find_unknown_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* should not return anything, we don't have an "unknown" option */
+list = qemu_find_opts("unknown");
+g_assert(list == NULL);
+}
+
+static void test_qemu_find_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* we have an "opts_list_01" option, should return it */
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+}
+
+static void test_qemu_opts_create(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+
+register_opts();
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert(QTAILQ_EMPTY(&list->head));
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/* create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+g_assert(opts != NULL);
+g_assert(!QTAILQ_EMPTY(&list->head));
+
+/* now we've create the opts, must find it */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts != NULL);
+
+qemu_opts_del(opts);
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+}
+
+static void test_qemu_opt_get(void)
+{
+QemuOptsList *list;
+Q

Re: [Qemu-devel] [PATCH] qemu-img: mandate argument to 'qemu-img check --repair'

2014-03-24 Thread Leandro Dorileo
On Tue, Mar 25, 2014 at 12:08:54AM +0530, Prasad Joshi wrote:
> qemu-img check --repair option accepts an argument. The argument to
> --repair switch can either be 'all' or 'leak'. Fix the long option to
> mandate argument with --repair switch.
> 
> The patch fixes following segmentation fault
> 
> Core was generated by `qemu-img check -f qcow2 --repair all t.qcow2'.
> Program terminated with signal 11, Segmentation fault.
> 0  in img_check (argc=6, argv=0x7fffab9b8a10) at qemu-img.c:588
> 588   if (!strcmp(optarg, "leaks")) {
> (gdb) bt
>   0  img_check (argc=6, argv=0x7fffab9b8a10) at qemu-img.c:588
>   1  __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
>   2  _start ()
> (gdb)
> 
> Signed-off-by: Prasad Joshi 


Patch looks good to me.

Reviewed-by: Leandro Dorileo 


> ---
>  qemu-img.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 2e40cc1..77d946b 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -565,7 +565,7 @@ static int img_check(int argc, char **argv)
>  static const struct option long_options[] = {
>  {"help", no_argument, 0, 'h'},
>  {"format", required_argument, 0, 'f'},
> -{"repair", no_argument, 0, 'r'},
> +        {"repair", required_argument, 0, 'r'},
>  {"output", required_argument, 0, OPTION_OUTPUT},
>  {0, 0, 0, 0}
>  };
> -- 
> 1.8.1.2
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH] qcow2: Remove FIXME comment, already fixed

2014-03-24 Thread Leandro Dorileo
On Mon, Mar 24, 2014 at 02:06:15PM +0800, Deepak Kathayat wrote:
> 
> Signed-off-by: Deepak Kathayat 

Reviewed-by: Leandro Dorileo 

> ---
>  block/qcow2.h |1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/block/qcow2.h b/block/qcow2.h
> index 0b0eac8..25663d4 100644
> --- a/block/qcow2.h
> +++ b/block/qcow2.h
> @@ -413,7 +413,6 @@ static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
>  + (m->cow_end.nb_sectors << BDRV_SECTOR_BITS);
>  }
>  
> -// FIXME Need qcow2_ prefix to global functions
>  
>  /* qcow2.c functions */
>  int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
> -- 
> 1.7.9.5
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts

2014-03-24 Thread Leandro Dorileo
Hi Chunyan,

On Mon, Mar 24, 2014 at 11:02:14AM +0800, Chunyan Liu wrote:
> 2014-03-21 20:31 GMT+08:00 Leandro Dorileo :
> 
> > On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
> > > 2014-03-21 8:07 GMT+08:00 Leandro Dorileo :
> > >
> > > > Hi Chunyan,
> > > >
> > > > On Mon, Mar 10, 2014 at 03:31:36PM +0800, Chunyan Liu wrote:
> > > > > This patch series is to replace QEMUOptionParameter with QemuOpts, so
> > > > that only
> > > > > one Qemu Option structure is kept in QEMU code.
> > > > >
> > > >
> > > >
> > > > Last night I took some time do take a deeper look at you series and the
> > > > required
> > > > effort to do the QemuOptionParameter -> QemuOpts migration.
> > > >
> > > > I think you've over complicated the things, I understand you tried to
> > keep
> > > > your
> > > > serie's bisectability (?), but the final result was something really
> > hard
> > > > to
> > > > review and to integrate as well. The overall approach wasn't even
> > > > resolving the
> > > > bisectability problem since it breaks the tree until the last commit.
> > > > Moreover,
> > > > in the path of getting things ready you created new problems and their
> > > > respective
> > > > fixes, what we really don't need to.
> > > >
> > > > In this regards you could have kept things as simple as possible and
> > > > submitted
> > > > the patches in a "natural way", even if they were breaking the build
> > > > between each
> > > > patch, you could get all the required maintainer's Reviewed-by +
> > Tested-by
> > > > +
> > > > Signed-off-by and so on for each individual patch and when it was time
> > to
> > > > integrate get squashed the needed patches.
> > > >
> > >
> > > Well, if breaking the build could be allowed between each patch, then it
> > > could be
> > > much cleaner. Indeed there are lots of code just for build and function
> > > unbroken
> > > between each patch. I'm inclined to listen to more voice. If all agree to
> > > this method,
> > > it's OK to me.
> >
> >
> > The thing is the balance between complexity and the change size. Do we
> > really
> > want to avoid a small patch - doing all the change - and increase the whole
> > thing complexity? I don't see a great benefit on that :)
> >
> >
> > >
> > >
> > > >
> > > > I mean, add N patches introducing new required QemuOpts API's, 1 patch
> > > > migrating
> > > > the block upper layer (block.c, block.h, etc), one patch for each block
> > > > driver
> > > > (i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and
> > finally a
> > > > last
> > > > patch removing the QEMUOptionParamer itself. When time comes to
> > integrate
> > > > your
> > > > series the patches changing the block layer + patches changing the
> > block
> > > > drivers +
> > > > patches changing qemu-img.c could be squashed adding all the collected
> > > > Reviewed-by
> > > > to this single squashed patch.
> > > >
> > > > As I said, last night I took a deeper look at the problem and,
> > understood
> > > > most
> > > > of changes weren't required to do the job. We don't need an adaptation
> > > > layer between
> > > > QemuOptionParameter and QemuOpts, we don't need to add new opts
> > accessors
> > > > (like
> > > > those qemu_opt_*_del() functions), all we need is 1) that
> > > > qemu_opts_append() function
> > > > so we can merge the protocol and drivers options in a single
> > QemuOptList
> > > > and
> > > > 2) the default value support. All we need is already present in the
> > > > QemuOpts APIs.
> > > >
> > > > qemu_opt_*_del functions are needed. Each driver handles options they
> > > expected then
> > > delete, left options passed to 2nd driver and let it handle. Like qcow2
> > > create, first, qcow2
> > > driver handle, then raw driver handle.
> >
> >
> > Not true, the only place you need to allocate QemuOpts or QemuOptsList is
> > on qemu-img.c and block.c, if t

Re: [Qemu-devel] [PATCH v2] QemuOpt: add unit tests

2014-03-21 Thread Leandro Dorileo
Hi Laszlo,

On Fri, Mar 21, 2014 at 04:30:32PM +0100, Laszlo Ersek wrote:
> On 03/21/14 15:56, Leandro Dorileo wrote:
> > Hi Eric,
> > 
> > On Fri, Mar 21, 2014 at 08:37:40AM -0600, Eric Blake wrote:
> >> On 03/17/2014 05:10 PM, Leandro Dorileo wrote:
> >>> Cover basic aspects and API usage for QemuOpt. The current implementation
> >>> covers the API's planned to be changed by Chunyan Liu in his 
> >>> QEMUOptionParameter
> >>> replacement/cleanup job.
> >>>
> >>> Other APIs should be covered in future improvements.
> >>>
> >>> Signed-off-by: Leandro Dorileo 
> >>
> >> Right here is where you should stick a --- marker.
> >>
> >>>
> >>> Changes:
> >>>   v2:
> >>>  + fixed comments;
> >>>  + make use of g_assert_cmpstr();
> >>>  + use error_abort instead of a local_err for 
> >>> qemu_opts_absorb_qdict();
> >>>  + asserts on QemuOptsList (empty and list name);
> >>>  + added test_qemu_opt_unset();
> >>>  + asserts on qemu_opt_*_set() return;
> >>>  + added test_qemu_opts_reset();
> >>>  + added test_qemu_opts_set();
> >>> ---
> >>
> >> It's okay to have a duplicate one; but the main point is that the v2
> >> changelog is useful to reviewers but not to the git log; and anything
> >> after the --- marker gets omitted by 'git am' when a maintainer accepts
> >> your patch into their pull request.
> > 
> > I would say that I even know about the --- marker, but have misplaced it... 
> > :(
> 
> Off-topic: I suggest to include a reference to git-notes(1) in our patch
> submission guidelines.
> - git-notes(1) lets you manage such v(n)->v(n+1) changelogs inside git,
> - the notes are pushable,
> - they are carried across rebases,
> - they are *not* part of the commit messages (consequently, they are not
> part of the commit hashes either),
> - they are (can be) correctly displayed by git-log, git-show, gitk, and
> git-format-patch (notably, in the last case, under the --- separator)
> 
> When you start using git-notes, you don't understand how you could exist
> without it.

Definitely, I wasn't aware of git-notes. Thanks...

> 
> Git-notes(1) takes some minimal configuration before use; the web offers
> easily searchable, good advice.
> 
> Thanks,
> Laszlo

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v2] QemuOpt: add unit tests

2014-03-21 Thread Leandro Dorileo
Hi Eric,

On Fri, Mar 21, 2014 at 08:37:40AM -0600, Eric Blake wrote:
> On 03/17/2014 05:10 PM, Leandro Dorileo wrote:
> > Cover basic aspects and API usage for QemuOpt. The current implementation
> > covers the API's planned to be changed by Chunyan Liu in his 
> > QEMUOptionParameter
> > replacement/cleanup job.
> > 
> > Other APIs should be covered in future improvements.
> > 
> > Signed-off-by: Leandro Dorileo 
> 
> Right here is where you should stick a --- marker.
> 
> > 
> > Changes:
> >   v2:
> >  + fixed comments;
> >  + make use of g_assert_cmpstr();
> >  + use error_abort instead of a local_err for qemu_opts_absorb_qdict();
> >  + asserts on QemuOptsList (empty and list name);
> >  + added test_qemu_opt_unset();
> >  + asserts on qemu_opt_*_set() return;
> >  + added test_qemu_opts_reset();
> >  + added test_qemu_opts_set();
> > ---
> 
> It's okay to have a duplicate one; but the main point is that the v2
> changelog is useful to reviewers but not to the git log; and anything
> after the --- marker gets omitted by 'git am' when a maintainer accepts
> your patch into their pull request.

I would say that I even know about the --- marker, but have misplaced it... :(

> 
> >  tests/Makefile |   3 +
> >  tests/test-qemu-opts.c | 455 
> > +
> >  2 files changed, 458 insertions(+)
> >  create mode 100644 tests/test-qemu-opts.c
> > 
> > +static void test_qemu_find_opts(void)
> > +{
> > +QemuOptsList *list;
> > +
> > +register_opts();
> > +
> > +/* we have an "opts_list_01" option, should return it */
> > +list = qemu_find_opts("opts_list_01");
> > +g_assert(list != NULL);
> > +g_assert_cmpstr(list->name, ==, "opts_list_01");
> > +}
> > +
> > +static void test_qemu_opts_create(void)
> > +{
> > +QemuOptsList *list;
> > +QemuOpts *opts;
> > +
> > +register_opts();
> > +
> > +list = qemu_find_opts("opts_list_01");
> > +g_assert(list != NULL);
> > +g_assert(QTAILQ_EMPTY(&list->head));
> > +g_assert_cmpstr(list->name, ==, "opts_list_01");
> 
> This test starts as a duplicate of test_qemu_find_opts; I guess that's
> okay (having both tests means a bit more insight into what broke if one
> fails but the other passes).
> 
> > +
> > +static void test_qemu_opt_unset(void)
> > +{
> > +QemuOpts *opts;
> > +const char *value;
> > +int ret;
> > +
> > +/* dinamically initialized (parsed) opts */
> 
> s/dinamically/dynamically/
> 
> That's trivially fixable, so feel free to add:

Ok...

> 
> Reviewed-by: Eric Blake 


Thanks for reviewing...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage

2014-03-21 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 02:42:35PM +0100, Peter Lieven wrote:
> On 21.03.2014 14:31, Leandro Dorileo wrote:
> >On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
> >>On 21.03.2014 01:13, Leandro Dorileo wrote:
> >>>Do the directly migration from QemuOptionParameter to QemuOpts on
> >>>iscsi block driver.
> >>>
> >>>Signed-off-by: Leandro Dorileo 
> >>>---
> >>>  block/iscsi.c | 32 
> >>>  1 file changed, 16 insertions(+), 16 deletions(-)
> >>>
> >>>diff --git a/block/iscsi.c b/block/iscsi.c
> >>>index b490e98..85252e7 100644
> >>>--- a/block/iscsi.c
> >>>+++ b/block/iscsi.c
> >>>@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
> >>>*options, int flags,
> >>>  QemuOpts *opts;
> >>>  Error *local_err = NULL;
> >>>  const char *filename;
> >>>-int i, ret;
> >>>+int i, ret = 0;
> >>why? is there a chance that ret remains uninitialized?
> >Yep, my compiler tells me so:
> >
> >block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this 
> >function [-Werror=maybe-uninitialized]
> >
> >
> >>>  if ((BDRV_SECTOR_SIZE % 512) != 0) {
> >>>  error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> >>>@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, 
> >>>int64_t offset)
> >>>  return 0;
> >>>  }
> >>>-static int iscsi_create(const char *filename, QEMUOptionParameter 
> >>>*options,
> >>>-Error **errp)
> >>>+static int iscsi_create(const char *filename, QemuOpts *options, Error 
> >>>**errp)
> >>>  {
> >>>  int ret = 0;
> >>>  int64_t total_size = 0;
> >>>@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, 
> >>>QEMUOptionParameter *options,
> >>>  bs = bdrv_new("");
> >>>-/* Read out options */
> >>>-while (options && options->name) {
> >>>-if (!strcmp(options->name, "size")) {
> >>>-total_size = options->value.n / BDRV_SECTOR_SIZE;
> >>>-}
> >>>-options++;
> >>>+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
> >>>+if (total_size) {
> >>>+total_size = total_size / BDRV_SECTOR_SIZE;
> >>>  }
> >>you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
> >>
> >I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we 
> >have no guarantee on the
> >value passed to bdrv_img_create(), we don't check img_size value there, 
> >having said that can't
> >we run on division by zero here? The previous code wasn't checking it but I 
> >wonder if the problem
> >wasn't there already.
> 
> division by zero is x / 0 not 0 / x.
> 
> 0 / x = 0
> x / 0 = undef
> 

Yep, true.

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage

2014-03-21 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 01:31:42PM +, Leandro Dorileo wrote:
> On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
> > On 21.03.2014 01:13, Leandro Dorileo wrote:
> > >Do the directly migration from QemuOptionParameter to QemuOpts on
> > >iscsi block driver.
> > >
> > >Signed-off-by: Leandro Dorileo 
> > >---
> > >  block/iscsi.c | 32 
> > >  1 file changed, 16 insertions(+), 16 deletions(-)
> > >
> > >diff --git a/block/iscsi.c b/block/iscsi.c
> > >index b490e98..85252e7 100644
> > >--- a/block/iscsi.c
> > >+++ b/block/iscsi.c
> > >@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
> > >*options, int flags,
> > >  QemuOpts *opts;
> > >  Error *local_err = NULL;
> > >  const char *filename;
> > >-int i, ret;
> > >+int i, ret = 0;
> > 
> > why? is there a chance that ret remains uninitialized?
> 
> Yep, my compiler tells me so:
> 
> block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this 
> function [-Werror=maybe-uninitialized]
> 
> 
> > 
> > >  if ((BDRV_SECTOR_SIZE % 512) != 0) {
> > >  error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> > >@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, 
> > >int64_t offset)
> > >  return 0;
> > >  }
> > >-static int iscsi_create(const char *filename, QEMUOptionParameter 
> > >*options,
> > >-Error **errp)
> > >+static int iscsi_create(const char *filename, QemuOpts *options, Error 
> > >**errp)
> > >  {
> > >  int ret = 0;
> > >  int64_t total_size = 0;
> > >@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, 
> > >QEMUOptionParameter *options,
> > >  bs = bdrv_new("");
> > >-/* Read out options */
> > >-while (options && options->name) {
> > >-if (!strcmp(options->name, "size")) {
> > >-total_size = options->value.n / BDRV_SECTOR_SIZE;
> > >-}
> > >-options++;
> > >+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
> > >+if (total_size) {
> > >+total_size = total_size / BDRV_SECTOR_SIZE;
> > >  }
> > you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
> > 
> 
> I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we 
> have no guarantee on the
> value passed to bdrv_img_create(), we don't check img_size value there, 
> having said that can't
> we run on division by zero here? The previous code wasn't checking it but I 
> wonder if the problem
> wasn't there already.

Ok, qemu-img does guarantee the img_size value...

> 
> 
> > Peter
> > >  bs->opaque = g_malloc0(sizeof(struct IscsiLun));
> > >@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, 
> > >BlockDriverInfo *bdi)
> > >  return 0;
> > >  }
> > >-static QEMUOptionParameter iscsi_create_options[] = {
> > >-{
> > >-.name = BLOCK_OPT_SIZE,
> > >-.type = OPT_SIZE,
> > >-.help = "Virtual disk size"
> > >+static QemuOptsList iscsi_create_options = {
> > >+.name = "iscsi_create_options",
> > >+.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
> > >+.desc = {
> > >+{
> > >+.name = BLOCK_OPT_SIZE,
> > >+.type = QEMU_OPT_SIZE,
> > >+.help = "Virtual disk size"
> > >+},
> > >+{ NULL }
> > >  },
> > >-{ NULL }
> > >  };
> > >  static BlockDriver bdrv_iscsi = {
> > >@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
> > >  .bdrv_file_open  = iscsi_open,
> > >      .bdrv_close  = iscsi_close,
> > >  .bdrv_create = iscsi_create,
> > >-.create_options  = iscsi_create_options,
> > >+.create_options  = &iscsi_create_options,
> > >  .bdrv_reopen_prepare  = iscsi_reopen_prepare,
> > >  .bdrv_getlength  = iscsi_getlength,
> > 
> > 
> > -- 
> > 
> > Mit freundlichen Grüßen
> > 
> > Peter Lieven
> > 
> > ...
> > 
> >   KAMP Netzwerkdienste GmbH
> >   Vestische Str. 89-91 | 46117 Oberhausen
> >   Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
> >   p...@kamp.de | http://www.kamp.de
> > 
> >   Geschäftsführer: Heiner Lante | Michael Lante
> >   Amtsgericht Duisburg | HRB Nr. 12154
> >   USt-Id-Nr.: DE 120607556
> > 
> > ...
> > 
> > 
> 
> -- 
> Leandro Dorileo

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage

2014-03-21 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
> On 21.03.2014 01:13, Leandro Dorileo wrote:
> >Do the directly migration from QemuOptionParameter to QemuOpts on
> >iscsi block driver.
> >
> >Signed-off-by: Leandro Dorileo 
> >---
> >  block/iscsi.c | 32 
> >  1 file changed, 16 insertions(+), 16 deletions(-)
> >
> >diff --git a/block/iscsi.c b/block/iscsi.c
> >index b490e98..85252e7 100644
> >--- a/block/iscsi.c
> >+++ b/block/iscsi.c
> >@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
> >*options, int flags,
> >  QemuOpts *opts;
> >  Error *local_err = NULL;
> >  const char *filename;
> >-int i, ret;
> >+int i, ret = 0;
> 
> why? is there a chance that ret remains uninitialized?

Yep, my compiler tells me so:

block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this function 
[-Werror=maybe-uninitialized]


> 
> >  if ((BDRV_SECTOR_SIZE % 512) != 0) {
> >  error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> >@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, 
> >int64_t offset)
> >  return 0;
> >  }
> >-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
> >-Error **errp)
> >+static int iscsi_create(const char *filename, QemuOpts *options, Error 
> >**errp)
> >  {
> >  int ret = 0;
> >  int64_t total_size = 0;
> >@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, 
> >QEMUOptionParameter *options,
> >  bs = bdrv_new("");
> >-/* Read out options */
> >-while (options && options->name) {
> >-if (!strcmp(options->name, "size")) {
> >-total_size = options->value.n / BDRV_SECTOR_SIZE;
> >-}
> >-options++;
> >+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
> >+if (total_size) {
> >+total_size = total_size / BDRV_SECTOR_SIZE;
> >  }
> you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
> 

I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we have 
no guarantee on the
value passed to bdrv_img_create(), we don't check img_size value there, having 
said that can't
we run on division by zero here? The previous code wasn't checking it but I 
wonder if the problem
wasn't there already.


> Peter
> >  bs->opaque = g_malloc0(sizeof(struct IscsiLun));
> >@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, 
> >BlockDriverInfo *bdi)
> >  return 0;
> >  }
> >-static QEMUOptionParameter iscsi_create_options[] = {
> >-{
> >-.name = BLOCK_OPT_SIZE,
> >-.type = OPT_SIZE,
> >-.help = "Virtual disk size"
> >+static QemuOptsList iscsi_create_options = {
> >+.name = "iscsi_create_options",
> >+.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
> >+.desc = {
> >+{
> >+.name = BLOCK_OPT_SIZE,
> >+.type = QEMU_OPT_SIZE,
> >+.help = "Virtual disk size"
> >+},
> >+{ NULL }
> >  },
> >-{ NULL }
> >  };
> >  static BlockDriver bdrv_iscsi = {
> >@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
> >  .bdrv_file_open  = iscsi_open,
> >  .bdrv_close  = iscsi_close,
> >  .bdrv_create = iscsi_create,
> >-.create_options  = iscsi_create_options,
> >+.create_options  = &iscsi_create_options,
> >  .bdrv_reopen_prepare  = iscsi_reopen_prepare,
> >  .bdrv_getlength  = iscsi_getlength,
> 
> 
> -- 
> 
> Mit freundlichen Grüßen
> 
> Peter Lieven
> 
> ...
> 
>   KAMP Netzwerkdienste GmbH
>   Vestische Str. 89-91 | 46117 Oberhausen
>   Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
>   p...@kamp.de | http://www.kamp.de
> 
>   Geschäftsführer: Heiner Lante | Michael Lante
>   Amtsgericht Duisburg | HRB Nr. 12154
>   USt-Id-Nr.: DE 120607556
> 
> ...
> 
> 

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts

2014-03-21 Thread Leandro Dorileo
On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
> 2014-03-21 8:07 GMT+08:00 Leandro Dorileo :
> 
> > Hi Chunyan,
> >
> > On Mon, Mar 10, 2014 at 03:31:36PM +0800, Chunyan Liu wrote:
> > > This patch series is to replace QEMUOptionParameter with QemuOpts, so
> > that only
> > > one Qemu Option structure is kept in QEMU code.
> > >
> >
> >
> > Last night I took some time do take a deeper look at you series and the
> > required
> > effort to do the QemuOptionParameter -> QemuOpts migration.
> >
> > I think you've over complicated the things, I understand you tried to keep
> > your
> > serie's bisectability (?), but the final result was something really hard
> > to
> > review and to integrate as well. The overall approach wasn't even
> > resolving the
> > bisectability problem since it breaks the tree until the last commit.
> > Moreover,
> > in the path of getting things ready you created new problems and their
> > respective
> > fixes, what we really don't need to.
> >
> > In this regards you could have kept things as simple as possible and
> > submitted
> > the patches in a "natural way", even if they were breaking the build
> > between each
> > patch, you could get all the required maintainer's Reviewed-by + Tested-by
> > +
> > Signed-off-by and so on for each individual patch and when it was time to
> > integrate get squashed the needed patches.
> >
> 
> Well, if breaking the build could be allowed between each patch, then it
> could be
> much cleaner. Indeed there are lots of code just for build and function
> unbroken
> between each patch. I'm inclined to listen to more voice. If all agree to
> this method,
> it's OK to me.


The thing is the balance between complexity and the change size. Do we really
want to avoid a small patch - doing all the change - and increase the whole
thing complexity? I don't see a great benefit on that :)


> 
> 
> >
> > I mean, add N patches introducing new required QemuOpts API's, 1 patch
> > migrating
> > the block upper layer (block.c, block.h, etc), one patch for each block
> > driver
> > (i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and finally a
> > last
> > patch removing the QEMUOptionParamer itself. When time comes to integrate
> > your
> > series the patches changing the block layer + patches changing the block
> > drivers +
> > patches changing qemu-img.c could be squashed adding all the collected
> > Reviewed-by
> > to this single squashed patch.
> >
> > As I said, last night I took a deeper look at the problem and, understood
> > most
> > of changes weren't required to do the job. We don't need an adaptation
> > layer between
> > QemuOptionParameter and QemuOpts, we don't need to add new opts accessors
> > (like
> > those qemu_opt_*_del() functions), all we need is 1) that
> > qemu_opts_append() function
> > so we can merge the protocol and drivers options in a single QemuOptList
> > and
> > 2) the default value support. All we need is already present in the
> > QemuOpts APIs.
> >
> > qemu_opt_*_del functions are needed. Each driver handles options they
> expected then
> delete, left options passed to 2nd driver and let it handle. Like qcow2
> create, first, qcow2
> driver handle, then raw driver handle.


Not true, the only place you need to allocate QemuOpts or QemuOptsList is
on qemu-img.c and block.c, if they're doing so they should free it, not
the lower lavels. The block drivers should just use it, unless they do
allocate anything themselves.


> 
> But as you point, some changes are not required for this job, I've omitted
> in my new patch
> series, like: qemu_opt_set, NULL check in qemu_opt_get and qemu_opt_find,
> assert()
> update in qemu_opt_get.
> 

Ok.

-- 
Leandro Dorileo

> 
> > With that simpler approach in mind I ended up putting my hands in the
> > source code
> > trying to see how feasible it is, and turns out I came up with a full
> > solution. I'm
> > sending the job's resulting series to the mailing list so I can show you
> > what
> > I mean and have some more room for discussion. It doesn't mean I want to
> > overlap
> > you work, I just needed to have a little more input on that.
> >
> 
> No matter. I'm OK to follow a more acceptable way :)
> 
> 
> >
> > Regards
> >
> > --
> > Leandro Dorileo
> >
> >



Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts

2014-03-21 Thread Leandro Dorileo
Hi Kevin,

On Fri, Mar 21, 2014 at 11:34:53AM +0100, Kevin Wolf wrote:
> Am 21.03.2014 um 01:07 hat Leandro Dorileo geschrieben:
> > Hi Chunyan,
> > 
> > On Mon, Mar 10, 2014 at 03:31:36PM +0800, Chunyan Liu wrote:
> > > This patch series is to replace QEMUOptionParameter with QemuOpts, so 
> > > that only
> > > one Qemu Option structure is kept in QEMU code.
> > > 
> > 
> > 
> > Last night I took some time do take a deeper look at you series and the 
> > required
> > effort to do the QemuOptionParameter -> QemuOpts migration.
> > 
> > I think you've over complicated the things, I understand you tried to keep 
> > your
> > serie's bisectability (?), but the final result was something really hard to
> > review and to integrate as well. The overall approach wasn't even resolving 
> > the
> > bisectability problem since it breaks the tree until the last commit. 
> > Moreover,
> > in the path of getting things ready you created new problems and their 
> > respective
> > fixes, what we really don't need to.
> > 
> > In this regards you could have kept things as simple as possible and 
> > submitted
> > the patches in a "natural way", even if they were breaking the build 
> > between each
> > patch, you could get all the required maintainer's Reviewed-by + Tested-by +
> > Signed-off-by and so on for each individual patch and when it was time to
> > integrate get squashed the needed patches.
> 
> No, please not. If you have bisectability on the surface, but the bisect
> ends in a monster patch with several thousand lines of code, nothing is
> won.

I don't think that is the case (several thousand lines), with the experiment I 
did the
"squashable" patches are 769 insertions(+), 1076 deletions(-), of course, the 
patch
series is bigger than that - not that bigger, but bigger - but I'm mentioning 
only
the patches I think need to be squashed.

These patches represent the changes across the block layer. I see no gain on 
increasing
the patches complexity just to avoid a patch with that statistic. More over, 
the changes
are very simple and easily reviewable.

Regards...

-- 
Leandro Dorileo



[Qemu-devel] [PATCH 17/26] rbd: migrate rbd driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
rbd block driver.

Signed-off-by: Leandro Dorileo 
---
 block/rbd.c | 60 +---
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index dbc79f4..ae8c471 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -282,7 +282,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char 
*conf)
 return ret;
 }
 
-static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
+static int qemu_rbd_create(const char *filename, QemuOpts *options,
Error **errp)
 {
 int64_t bytes = 0;
@@ -305,25 +305,19 @@ static int qemu_rbd_create(const char *filename, 
QEMUOptionParameter *options,
 return -EINVAL;
 }
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-bytes = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options->value.n) {
-objsize = options->value.n;
-if ((objsize - 1) & objsize) {/* not a power of 2? */
-error_report("obj size needs to be power of 2");
-return -EINVAL;
-}
-if (objsize < 4096) {
-error_report("obj size too small");
-return -EINVAL;
-}
-obj_order = ffs(objsize) - 1;
-}
+bytes = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+objsize = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+if (objsize != 0) {
+if ((objsize - 1) & objsize) {  /* not a power of 2? */
+error_report("obj size needs to be power of 2");
+return -EINVAL;
+}
+if (objsize < 4096) {
+error_report("obj size too small");
+return -EINVAL;
 }
-options++;
+obj_order = ffs(objsize) - 1;
 }
 
 clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
@@ -900,18 +894,22 @@ static BlockDriverAIOCB* 
qemu_rbd_aio_discard(BlockDriverState *bs,
 }
 #endif
 
-static QEMUOptionParameter qemu_rbd_create_options[] = {
-{
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
-},
-{
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "RBD object size"
+static QemuOptsList qemu_rbd_create_options = {
+.name = "qemu_rbd_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "RBD object size"
+},
+{NULL}
 },
-{NULL}
 };
 
 static BlockDriver bdrv_rbd = {
@@ -923,7 +921,7 @@ static BlockDriver bdrv_rbd = {
 .bdrv_create= qemu_rbd_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_get_info  = qemu_rbd_getinfo,
-.create_options = qemu_rbd_create_options,
+.create_options = &qemu_rbd_create_options,
 .bdrv_getlength = qemu_rbd_getlength,
 .bdrv_truncate  = qemu_rbd_truncate,
 .protocol_name  = "rbd",
-- 
1.9.0




[Qemu-devel] [PATCH 06/26] block: migrate block later QemuOptionParameter

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
block layer.

Signed-off-by: Leandro Dorileo 
---
 block.c   | 133 --
 include/block/block.h |   7 ++-
 include/block/block_int.h |   8 ++-
 3 files changed, 86 insertions(+), 62 deletions(-)

diff --git a/block.c b/block.c
index acb70fd..e70f360 100644
--- a/block.c
+++ b/block.c
@@ -407,7 +407,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char 
*format_name,
 typedef struct CreateCo {
 BlockDriver *drv;
 char *filename;
-QEMUOptionParameter *options;
+QemuOpts *options;
 int ret;
 Error *err;
 } CreateCo;
@@ -427,8 +427,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 cco->ret = ret;
 }
 
-int bdrv_create(BlockDriver *drv, const char* filename,
-QEMUOptionParameter *options, Error **errp)
+int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *options,
+Error **errp)
 {
 int ret;
 
@@ -472,8 +472,7 @@ out:
 return ret;
 }
 
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp)
+int bdrv_create_file(const char *filename, QemuOpts *options, Error **errp)
 {
 BlockDriver *drv;
 Error *local_err = NULL;
@@ -1248,7 +1247,7 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 BlockDriverState *bs1;
 int64_t total_size;
 BlockDriver *bdrv_qcow2;
-QEMUOptionParameter *create_options;
+QemuOpts *create_options;
 QDict *snapshot_options;
 
 /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1273,27 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 }
 
 bdrv_qcow2 = bdrv_find_format("qcow2");
-create_options = parse_option_parameters("", 
bdrv_qcow2->create_options,
- NULL);
 
-set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
+create_options = qemu_opts_create(bdrv_qcow2->create_options, NULL, 0,
+  &local_err);
+
+if (create_options == NULL) {
+error_setg(errp, "Could not create internal option %s",
+   error_get_pretty(local_err));
+error_free(local_err);
+local_err = NULL;
+goto fail;
+}
+
+ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, total_size);
+if (ret < 0) {
+qemu_opts_del(create_options);
+goto fail;
+}
 
 ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, 
&local_err);
-free_option_parameters(create_options);
+qemu_opts_del(create_options);
+
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not create temporary overlay "
  "'%s': %s", tmp_filename,
@@ -5259,12 +5272,14 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
  char *options, uint64_t img_size, int flags,
  Error **errp, bool quiet)
 {
-QEMUOptionParameter *param = NULL, *create_options = NULL;
-QEMUOptionParameter *backing_fmt, *backing_file, *size;
+QemuOptsList *list;
+QemuOpts *create_options;
+const char *backing_file, *backing_fmt;
 BlockDriver *drv, *proto_drv;
 BlockDriver *backing_drv = NULL;
 Error *local_err = NULL;
 int ret = 0;
+uint64_t size;
 
 /* Find driver and parse its options */
 drv = bdrv_find_format(fmt);
@@ -5279,28 +5294,39 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 return;
 }
 
-create_options = append_option_parameters(create_options,
-  drv->create_options);
-create_options = append_option_parameters(create_options,
-  proto_drv->create_options);
+list = qemu_opts_append(drv->create_options, proto_drv->create_options);
+if (!list) {
+error_setg(errp, "Could not allocate option list");
+return;
+}
 
-/* Create parameter list with default values */
-param = parse_option_parameters("", create_options, param);
+create_options = qemu_opts_create(list, NULL, 0, &local_err);
+if (create_options == NULL) {
+error_setg(errp, "Could not create internal option %s",
+   error_get_pretty(local_err));
+error_free(local_err);
+g_free(list);
+local_err = NULL;
+return;
+}
 
-set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, img_size);
+if (ret < 0) {
+goto out;
+}
 
 /* Parse -o options */
 if (options) {
-p

[Qemu-devel] [PATCH 19/26] ssh: migrate ssh driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
ssh block driver.

Signed-off-by: Leandro Dorileo 
---
 block/ssh.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..b55c518 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -642,17 +642,20 @@ static int ssh_file_open(BlockDriverState *bs, QDict 
*options, int bdrv_flags,
 return ret;
 }
 
-static QEMUOptionParameter ssh_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
+static QemuOptsList ssh_create_options = {
+.name = "ssh_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(ssh_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int ssh_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int r, ret;
 Error *local_err = NULL;
@@ -664,13 +667,7 @@ static int ssh_create(const char *filename, 
QEMUOptionParameter *options,
 
 ssh_state_init(&s);
 
-/* Get desired file size. */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n;
-}
-options++;
-}
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
 DPRINTF("total_size=%" PRIi64, total_size);
 
 uri_options = qdict_new();
@@ -1051,7 +1048,7 @@ static BlockDriver bdrv_ssh = {
 .bdrv_co_writev   = ssh_co_writev,
 .bdrv_getlength   = ssh_getlength,
 .bdrv_co_flush_to_disk= ssh_co_flush,
-.create_options   = ssh_create_options,
+.create_options   = &ssh_create_options,
 };
 
 static void bdrv_ssh_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 20/26] vdi: migrate vdi driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vdi block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vdi.c | 73 -
 1 file changed, 34 insertions(+), 39 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index ae49cd8..4f8a143 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -653,8 +653,7 @@ static int vdi_co_write(BlockDriverState *bs,
 return ret;
 }
 
-static int vdi_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int vdi_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int result = 0;
@@ -662,31 +661,23 @@ static int vdi_create(const char *filename, 
QEMUOptionParameter *options,
 uint32_t blocks;
 size_t block_size = DEFAULT_CLUSTER_SIZE;
 uint32_t image_type = VDI_TYPE_DYNAMIC;
+bool stat;
 VdiHeader header;
 size_t i;
 size_t bmap_size;
 
 logout("\n");
 
-/* Read out options. */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-bytes = options->value.n;
+bytes = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+
 #if defined(CONFIG_VDI_BLOCK_SIZE)
-} else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options->value.n) {
-/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
-block_size = options->value.n;
-}
-#endif
-#if defined(CONFIG_VDI_STATIC_IMAGE)
-} else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
-if (options->value.n) {
-image_type = VDI_TYPE_STATIC;
-}
+/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
+block_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
 #endif
-}
-options++;
+
+stat = qemu_opt_get_bool(options, BLOCK_OPT_STATIC, false);
+if (stat) {
+image_type = VDI_TYPE_STATIC;
 }
 
 fd = qemu_open(filename,
@@ -767,29 +758,33 @@ static void vdi_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static QEMUOptionParameter vdi_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
+static QemuOptsList vdi_create_options = {
+.name = "vdi_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vdi_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
 #if defined(CONFIG_VDI_BLOCK_SIZE)
-{
-.name = BLOCK_OPT_CLUSTER_SIZE,
-.type = OPT_SIZE,
-.help = "VDI cluster (block) size",
-.value = { .n = DEFAULT_CLUSTER_SIZE },
-},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "VDI cluster (block) size",
+.def_val = QEMU_OPT_VAL_SIZE(DEFAULT_CLUSTER_SIZE),
+},
 #endif
 #if defined(CONFIG_VDI_STATIC_IMAGE)
-{
-.name = BLOCK_OPT_STATIC,
-.type = OPT_FLAG,
-.help = "VDI static (pre-allocated) image"
-},
+{
+.name = BLOCK_OPT_STATIC,
+.type = QEMU_OPT_BOOL,
+.help = "VDI static (pre-allocated) image"
+},
 #endif
-/* TODO: An additional option to set UUID values might be useful. */
-{ NULL }
+/* TODO: An additional option to set UUID values might be useful. */
+{ NULL }
+},
 };
 
 static BlockDriver bdrv_vdi = {
@@ -811,7 +806,7 @@ static BlockDriver bdrv_vdi = {
 
 .bdrv_get_info = vdi_get_info,
 
-.create_options = vdi_create_options,
+.create_options = &vdi_create_options,
 .bdrv_check = vdi_check,
 };
 
-- 
1.9.0




[Qemu-devel] [PATCH 11/26] qcow: migrate qcow driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qcow block driver.

Signed-off-by: Leandro Dorileo 
---
 block/qcow.c | 59 +--
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 1e128be..65c7486 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -662,31 +662,26 @@ static void qcow_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static int qcow_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int qcow_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int header_size, backing_filename_len, l1_size, shift, i;
 QCowHeader header;
 uint8_t *tmp;
 int64_t total_size = 0;
 const char *backing_file = NULL;
-int flags = 0;
+uint64_t flags = 0;
 Error *local_err = NULL;
 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++;
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / 512;
 }
 
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+flags |= qemu_opt_get_number(options, BLOCK_OPT_ENCRYPT, 0);
+
 ret = bdrv_create_file(filename, options, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
@@ -882,23 +877,27 @@ static int qcow_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 }
 
 
-static QEMUOptionParameter qcow_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{
-.name = BLOCK_OPT_ENCRYPT,
-.type = OPT_FLAG,
-.help = "Encrypt the image"
+static QemuOptsList qcow_create_options = {
+.name = "qcow_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qcow_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_ENCRYPT,
+.type = QEMU_OPT_NUMBER,
+.help = "Encrypt the image"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_qcow = {
@@ -920,7 +919,7 @@ static BlockDriver bdrv_qcow = {
 .bdrv_write_compressed  = qcow_write_compressed,
 .bdrv_get_info  = qcow_get_info,
 
-.create_options = qcow_create_options,
+.create_options = &qcow_create_options,
 };
 
 static void bdrv_qcow_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 01/26] qapi: output def_value_str when query command line options

2014-03-20 Thread Leandro Dorileo
From: Chunyan Liu 

Change qapi interfaces to output the newly added def_value_str when querying
command line options.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 qapi-schema.json   | 6 +-
 qmp-commands.hx| 2 ++
 util/qemu-config.c | 4 
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index b68cd44..cf9174e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4088,12 +4088,16 @@
 #
 # @help: #optional human readable text string, not suitable for parsing.
 #
+# @default: #optional string representation of the default used
+#   if the option is omitted. (since 2.0)
+#
 # Since 1.5
 ##
 { 'type': 'CommandLineParameterInfo',
   'data': { 'name': 'str',
 'type': 'CommandLineParameterType',
-'*help': 'str' } }
+'*help': 'str',
+'*default': 'str' } }
 
 ##
 # @CommandLineOptionInfo:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a22621f..178aadd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2895,6 +2895,8 @@ Each array entry contains the following:
   or 'size')
 - "help": human readable description of the parameter
   (json-string, optional)
+- "default": default value string for the parameter
+ (json-string, optional)
 
 Example:
 
diff --git a/util/qemu-config.c b/util/qemu-config.c
index f610101..d608b2f 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -68,6 +68,10 @@ static CommandLineParameterInfoList 
*query_option_descs(const QemuOptDesc *desc)
 info->has_help = true;
 info->help = g_strdup(desc[i].help);
 }
+if (desc[i].def_value_str) {
+info->has_q_default = true;
+info->q_default = g_strdup(desc[i].def_value_str);
+}
 
 entry = g_malloc0(sizeof(*entry));
 entry->value = info;
-- 
1.9.0




[Qemu-devel] [PATCH 18/26] sheepdog: migrate sheepdog driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
sheepdog block driver.

Signed-off-by: Leandro Dorileo 
---
 block/sheepdog.c | 104 ---
 1 file changed, 53 insertions(+), 51 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f7bd024..4f4945f 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1626,17 +1626,18 @@ static int parse_redundancy(BDRVSheepdogState *s, const 
char *opt)
 return 0;
 }
 
-static int sd_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int sd_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 uint32_t vid = 0;
-char *backing_file = NULL;
+const char *backing_file = NULL;
 BDRVSheepdogState *s;
 char tag[SD_MAX_VDI_TAG_LEN];
 uint32_t snapid;
 bool prealloc = false;
 Error *local_err = NULL;
+const char *prealloc_opt;
+char *redundancy_opt;
 
 s = g_malloc0(sizeof(BDRVSheepdogState));
 
@@ -1650,31 +1651,28 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options,
 goto out;
 }
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-s->inode.vdi_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
-if (!options->value.s || !strcmp(options->value.s, "off")) {
-prealloc = false;
-} else if (!strcmp(options->value.s, "full")) {
-prealloc = true;
-} else {
-error_report("Invalid preallocation mode: '%s'",
- options->value.s);
-ret = -EINVAL;
-goto out;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_REDUNDANCY)) {
-if (options->value.s) {
-ret = parse_redundancy(s, options->value.s);
-if (ret < 0) {
-goto out;
-}
-}
+s->inode.vdi_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
+prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+if (prealloc_opt) {
+if (!strcmp(prealloc_opt, "off")) {
+prealloc = false;
+} else if (!strcmp(prealloc_opt, "full")) {
+prealloc = true;
+} else {
+error_report("Invalid preallocation mode: '%s'", prealloc_opt);
+ret = -EINVAL;
+goto out;
+}
+}
+
+redundancy_opt = (char *)qemu_opt_get(options, BLOCK_OPT_REDUNDANCY);
+if (redundancy_opt) {
+ret = parse_redundancy(s, redundancy_opt);
+if (ret < 0) {
+goto out;
 }
-options++;
 }
 
 if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -2490,28 +2488,32 @@ static int64_t 
sd_get_allocated_file_size(BlockDriverState *bs)
 return size;
 }
 
-static QEMUOptionParameter sd_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{
-.name = BLOCK_OPT_PREALLOC,
-.type = OPT_STRING,
-.help = "Preallocation mode (allowed values: off, full)"
-},
-{
-.name = BLOCK_OPT_REDUNDANCY,
-.type = OPT_STRING,
-.help = "Redundancy of the image"
+static QemuOptsList sd_create_options = {
+.name = "sd_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(sd_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = QEMU_OPT_STRING,
+.help = "Preallocation mode (allowed values: off, full)"
+},
+{
+.name = BLOCK_OPT_REDUNDANCY,
+.type = QEMU_OPT_STRING,
+.help = "Redundancy of the image"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_sheepdog = {
@@ -2541,7 +2543,7 @@ static BlockDriver bdrv_sheepdog = {
 .bdrv_save_vmstate  = sd_save_vmstate,
 .bdrv_load_vmstate  = sd_load_vmstate,
 
-.create_options = sd_create_options,
+

[Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration

2014-03-20 Thread Leandro Dorileo
This patch series does the QemuOptionParameter -> QemuOpts migration. The idea
is to collect all the required Reviewed-by and squash the patches changing the
block layer + block drivers (patches [06..25]) in a single patch so we don't
break anything and keep the tree's bisectability (just in case we realize this 
patch
series must be integrated).

In response to Chunyan's patchset, this patch series was first intended to 
describe
my thoughts on how this migration should be performed.

The patches 2 and 3 can be squashed later on, I just kept them split to keep
Chunyan's authorship.

--
Dorileo

Chunyan Liu (3):
  qapi: output def_value_str when query command line options
  add def_value_str to QemuOptDesc
  QemuOpt: introduce qemu_opts_append()

Leandro Dorileo (23):
  QemuOpt: improve default value
  QemuOpt: add qemu_opt_print_help()
  block: migrate block later QemuOptionParameter
  cow: migrate cow driver QemuOptionParameter usage
  gluster: migrate gluster driver QemuOptionParameter usage
  iscsi: migrate iscsi driver QemuOptionParameter usage
  nfs: migrate nfs driver QemuOptionParameter usage
  qcow: migrate qcow driver QemuOptionParameter usage
  qcow2: migrate qcow2 driver QemuOptionParameter usage
  qed: migrate qed driver QemuOptionParameter usage
  raw-posix: migrate raw-posix driver QemuOptionParameter usage
  raw-win32: migrate cow driver QemuOptionParameter usage
  raw_bsd: migrate raw_bsd driver QemuOptionParameter usage
  rbd: migrate rbd driver QemuOptionParameter usage
  sheepdog: migrate sheepdog driver QemuOptionParameter usage
  ssh: migrate ssh driver QemuOptionParameter usage
  vdi: migrate vdi driver QemuOptionParameter usage
  vhdx: migrate vhdx driver QemuOptionParameter usage
  vmdk: migrate vmdk driver QemuOptionParameter usage
  vpc: migrate vpc driver QemuOptionParameter usage
  vvfat: migrate vvfat driver QemuOptionParameter usage
  QemuOpt: get rid of QEMUOptionParameter
  qemu-img: migrate QemuOptionParameter usage

 block.c   | 133 +--
 block/cow.c   |  44 
 block/gluster.c   |  68 ++--
 block/iscsi.c |  32 +++---
 block/nfs.c   |  11 +-
 block/qcow.c  |  59 +--
 block/qcow2.c | 263 ++
 block/qed.c   |  79 ++
 block/raw-posix.c |  50 -
 block/raw-win32.c |  29 +++--
 block/raw_bsd.c   |  21 ++--
 block/rbd.c   |  60 +--
 block/sheepdog.c  | 104 +-
 block/ssh.c   |  29 +++--
 block/vdi.c   |  73 ++---
 block/vhdx.c  |  88 
 block/vmdk.c  | 105 +-
 block/vpc.c   |  54 +-
 block/vvfat.c |  26 -
 include/block/block.h |   7 +-
 include/block/block_int.h |   8 +-
 include/qemu/option.h |  23 +++-
 qapi-schema.json  |   6 +-
 qemu-img.c| 166 -
 qmp-commands.hx   |   2 +
 util/qemu-config.c|   4 +
 util/qemu-option.c| 174 +-
 27 files changed, 952 insertions(+), 766 deletions(-)

-- 
1.9.0




[Qemu-devel] [PATCH 24/26] vvfat: migrate vvfat driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vvfat block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vvfat.c | 26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index f966ea5..7aefba3 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2907,7 +2907,7 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s)
 {
 BlockDriver *bdrv_qcow;
-QEMUOptionParameter *options;
+QemuOpts *options;
 Error *local_err = NULL;
 int ret;
 int size = sector2cluster(s, s->sector_count);
@@ -2918,13 +2918,26 @@ static int enable_write_target(BDRVVVFATState *s)
 s->qcow_filename = g_malloc(1024);
 ret = get_tmp_filename(s->qcow_filename, 1024);
 if (ret < 0) {
-goto err;
+goto err_opt;
 }
 
 bdrv_qcow = bdrv_find_format("qcow");
-options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
-set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
-set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
+
+options = qemu_opts_create(bdrv_qcow->create_options, NULL, 0,
+   &error_abort);
+if (!options) {
+goto err_opt;
+}
+
+ret = qemu_opt_set_number(options, BLOCK_OPT_SIZE, s->sector_count * 512);
+if (ret < 0) {
+goto err;
+}
+
+ret = qemu_opt_set(options, BLOCK_OPT_BACKING_FILE, "fat:");
+if (ret < 0) {
+goto err;
+}
 
 ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, &local_err);
 if (ret < 0) {
@@ -2951,10 +2964,13 @@ static int enable_write_target(BDRVVVFATState *s)
 s->bs->backing_hd->drv = &vvfat_write_target;
 s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
 *(void**)s->bs->backing_hd->opaque = s;
+qemu_opts_del(options);
 
 return 0;
 
 err:
+qemu_opts_del(options);
+err_opt:
 g_free(s->qcow_filename);
 s->qcow_filename = NULL;
 return ret;
-- 
1.9.0




[Qemu-devel] [PATCH 22/26] vmdk: migrate vmdk driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vmdk block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vmdk.c | 105 ++-
 1 file changed, 53 insertions(+), 52 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index b69988d..1974c30 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1681,8 +1681,7 @@ static int filename_decompose(const char *filename, char 
*path, char *prefix,
 return VMDK_OK;
 }
 
-static int vmdk_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int vmdk_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int idx = 0;
 BlockDriverState *new_bs = NULL;
@@ -1704,6 +1703,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 uint32_t number_heads = 16;
 bool zeroed_grain = false;
 uint32_t desc_offset = 0, desc_len;
+bool compat6;
 const char desc_template[] =
 "# Disk DescriptorFile\n"
 "version=1\n"
@@ -1730,23 +1730,19 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 ret = -EINVAL;
 goto exit;
 }
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_ADAPTER_TYPE)) {
-adapter_type = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_COMPAT6)) {
-flags |= options->value.n ? BLOCK_FLAG_COMPAT6 : 0;
-} else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
-fmt = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_ZEROED_GRAIN)) {
-zeroed_grain |= options->value.n;
-}
-options++;
+
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+adapter_type = qemu_opt_get(options, BLOCK_OPT_ADAPTER_TYPE);
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
+compat6 = qemu_opt_get_bool(options, BLOCK_OPT_COMPAT6, false);
+if (compat6) {
+flags |= BLOCK_FLAG_COMPAT6;
 }
+
+fmt = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
+zeroed_grain = qemu_opt_get_bool(options, BLOCK_OPT_ZEROED_GRAIN, false);
+
 if (!adapter_type) {
 adapter_type = "ide";
 } else if (strcmp(adapter_type, "ide") &&
@@ -2062,41 +2058,46 @@ static ImageInfoSpecific 
*vmdk_get_specific_info(BlockDriverState *bs)
 return spec_info;
 }
 
-static QEMUOptionParameter vmdk_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_ADAPTER_TYPE,
-.type = OPT_STRING,
-.help = "Virtual adapter type, can be one of "
-"ide (default), lsilogic, buslogic or legacyESX"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{
-.name = BLOCK_OPT_COMPAT6,
-.type = OPT_FLAG,
-.help = "VMDK version 6 image"
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help =
+static QemuOptsList vmdk_create_options = {
+.name = "vmdk_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vmdk_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_ADAPTER_TYPE,
+.type = QEMU_OPT_STRING,
+.help = "Virtual adapter type, can be one of "
+"ide (default), lsilogic, buslogic or legacyESX"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_COMPAT6,
+.type = QEMU_OPT_BOOL,
+.help = "VMDK version 6 image"
+},
+{
+.name = BLOCK_OPT_SUBFMT,
+.type = QEMU_OPT_STRING,
+.help =
 "VMDK flat extent format, can be one of "
 "{monolithicSparse (default) | monolithicFlat | 
twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} "
-},
-{
-.name = BLOCK_OPT_ZEROED_GRAIN,
-.type = OPT_FLAG,
-.help = "Enable efficient zero writes using the zeroed-grain GTE 
feature"
-},
-{ NULL }
+},
+{
+.name = BLOCK_OPT_ZEROED_GRAIN,

[Qemu-devel] [PATCH 16/26] raw_bsd: migrate raw_bsd driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
raw_bsd block driver.

Signed-off-by: Leandro Dorileo 
---
 block/raw_bsd.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 01ea692..5090b4e 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -29,13 +29,17 @@
 #include "block/block_int.h"
 #include "qemu/option.h"
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
+static QemuOptsList raw_create_options = {
+.name = "raw_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ 0 }
 },
-{ 0 }
 };
 
 static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,8 +143,7 @@ static int raw_has_zero_init(BlockDriverState *bs)
 return bdrv_has_zero_init(bs->file);
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
 Error *local_err = NULL;
 int ret;
@@ -194,7 +197,7 @@ static BlockDriver bdrv_raw = {
 .bdrv_lock_medium = &raw_lock_medium,
 .bdrv_ioctl   = &raw_ioctl,
 .bdrv_aio_ioctl   = &raw_aio_ioctl,
-.create_options   = &raw_create_options[0],
+.create_options   = &raw_create_options,
 .bdrv_has_zero_init   = &raw_has_zero_init
 };
 
-- 
1.9.0




[Qemu-devel] [PATCH 15/26] raw-win32: migrate cow driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
raw-win32 block driver.

Signed-off-by: Leandro Dorileo 
---
 block/raw-win32.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/block/raw-win32.c b/block/raw-win32.c
index 48cb2c2..4cca514 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -475,21 +475,14 @@ static int64_t 
raw_get_allocated_file_size(BlockDriverState *bs)
 return st.st_size;
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int64_t total_size = 0;
 
 strstart(filename, "file:", &filename);
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n / 512;
-}
-options++;
-}
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -503,13 +496,17 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options,
 return 0;
 }
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
+static QemuOptsList raw_create_options = {
+.name = "raw_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_file = {
@@ -532,7 +529,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 };
 
 /***/
-- 
1.9.0




[Qemu-devel] [PATCH 26/26] qemu-img: migrate QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qemu-img.

Signed-off-by: Leandro Dorileo 
---
 qemu-img.c | 166 +++--
 1 file changed, 95 insertions(+), 71 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 2e40cc1..1a8ce3c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -235,7 +235,9 @@ static int read_password(char *buf, int buf_size)
 static int print_block_option_help(const char *filename, const char *fmt)
 {
 BlockDriver *drv, *proto_drv;
-QEMUOptionParameter *create_options = NULL;
+QemuOptsList *proto_opts = NULL;
+QemuOpts *opts;
+QemuOptsList *list;
 
 /* Find driver and parse its options */
 drv = bdrv_find_format(fmt);
@@ -244,21 +246,32 @@ static int print_block_option_help(const char *filename, 
const char *fmt)
 return 1;
 }
 
-create_options = append_option_parameters(create_options,
-  drv->create_options);
-
 if (filename) {
 proto_drv = bdrv_find_protocol(filename, true);
 if (!proto_drv) {
 error_report("Unknown protocol '%s'", filename);
 return 1;
 }
-create_options = append_option_parameters(create_options,
-  proto_drv->create_options);
+proto_opts = proto_drv->create_options;
+}
+
+list = qemu_opts_append(drv->create_options, proto_opts);
+if (!list) {
+error_report("Could not allocate option descriptors structure");
+return 1;
+}
+
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+if (!list) {
+error_report("Could not allocate options structure");
+g_free(list);
+return 1;
 }
 
-print_option_help(create_options);
-free_option_parameters(create_options);
+qemu_opts_print_help(opts);
+
+qemu_opts_del(opts);
+g_free(list);
 return 0;
 }
 
@@ -311,22 +324,26 @@ fail:
 return NULL;
 }
 
-static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
+static int add_old_style_options(const char *fmt, QemuOpts *opts,
  const char *base_filename,
  const char *base_fmt)
 {
+int ret;
+
 if (base_filename) {
-if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) 
{
+ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename);
+if (ret < 0) {
 error_report("Backing file not supported for file format '%s'",
  fmt);
-return -1;
+return ret;
 }
 }
 if (base_fmt) {
-if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt);
+if (ret < 0) {
 error_report("Backing file format not supported for file "
  "format '%s'", fmt);
-return -1;
+return ret;
 }
 }
 return 0;
@@ -1153,8 +1170,8 @@ static int img_convert(int argc, char **argv)
 size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
 const uint8_t *buf1;
 BlockDriverInfo bdi;
-QEMUOptionParameter *param = NULL, *create_options = NULL;
-QEMUOptionParameter *out_baseimg_param;
+QemuOpts *create_options;
+QemuOptsList *opts_list = NULL;
 char *options = NULL;
 const char *snapshot_name = NULL;
 int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
@@ -1340,72 +1357,73 @@ static int img_convert(int argc, char **argv)
 goto out;
 }
 
-create_options = append_option_parameters(create_options,
-  drv->create_options);
-create_options = append_option_parameters(create_options,
-  proto_drv->create_options);
+opts_list = qemu_opts_append(drv->create_options,
+ proto_drv->create_options);
+if (!opts_list) {
+error_report("Could not allocate option descriptors structure");
+ret = -1;
+goto out;
+}
+
+create_options = qemu_opts_create(opts_list, NULL, 0, &error_abort);
+if (!create_options) {
+error_report("Could not allocate options structure");
+ret = -1;
+goto err_opts;
+}
 
 if (options) {
-param = parse_option_parameters(options, create_options, param);
-if (param == NULL) {
+ret = qemu_opts_do_parse(create_options, options, NULL);
+if (ret < 0) {
 error_report("Invalid options for file format '%s'.", out_fmt);
-ret = -1;
-goto out;
+goto err;
 }
-} else {
-param = parse

[Qemu-devel] [PATCH 12/26] qcow2: migrate qcow2 driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qcow2 block driver.

Signed-off-by: Leandro Dorileo 
---
 block/qcow2.c | 263 --
 1 file changed, 128 insertions(+), 135 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index b9dc960..a69438f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1472,7 +1472,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 *options, int version,
  Error **errp)
 {
 /* Calculate cluster_bits */
@@ -1639,9 +1639,10 @@ out:
 return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *options, Error **errp)
 {
+const char *compat_level_opt = NULL;
+const char *prealloc_opt = NULL;
 const char *backing_file = NULL;
 const char *backing_fmt = NULL;
 uint64_t sectors = 0;
@@ -1652,46 +1653,47 @@ static int qcow2_create(const char *filename, 
QEMUOptionParameter *options,
 Error *local_err = NULL;
 int ret;
 
-/* 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 {
-error_setg(errp, "Invalid preallocation mode: '%s'",
-   options->value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
-if (!options->value.s) {
-/* keep the default */
-} else if (!strcmp(options->value.s, "0.10")) {
-version = 2;
-} else if (!strcmp(options->value.s, "1.1")) {
-version = 3;
-} else {
-error_setg(errp, "Invalid compatibility level: '%s'",
-   options->value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
-flags |= options->value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
+sectors = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (sectors) {
+sectors = sectors / 512;
+}
+
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+
+if (qemu_opt_get_bool(options, BLOCK_OPT_ENCRYPT, false)) {
+flags |= BLOCK_FLAG_ENCRYPT;
+}
+
+cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+if (prealloc_opt) {
+if (!strcmp(prealloc_opt, "off")) {
+prealloc = 0;
+} else if (!strcmp(prealloc_opt, "metadata")) {
+prealloc = 1;
+} else {
+error_setg(errp, "Invalid preallocation mode: '%s'", prealloc_opt);
+return -EINVAL;
+}
+}
+
+compat_level_opt = qemu_opt_get(options, BLOCK_OPT_COMPAT_LEVEL);
+if (compat_level_opt) {
+if (!strcmp(compat_level_opt, "0.10")) {
+version = 2;
+} else if (!strcmp(compat_level_opt, "1.1")) {
+version = 3;
+} else {
+error_setg(errp, "Invalid compatibility level: '%s'",
+   compat_level_opt);
+return -EINVAL;
 }
-options++;
+}
+
+if (qemu_opt_get_bool(options, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
 }
 
 if (backing_file && prealloc) {
@@ -2075,66 +2077,53 @@ static int

[Qemu-devel] [PATCH 21/26] vhdx: migrate vhdx driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vhdx block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vhdx.c | 88 
 1 file changed, 41 insertions(+), 47 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index 5390ba6..106ea7a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1708,8 +1708,7 @@ exit:
  *. ~ --- ~  ~  ~ ---.
  *   1MB
  */
-static int vhdx_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int vhdx_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 uint64_t image_size = (uint64_t) 2 * GiB;
@@ -1726,20 +1725,11 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 VHDXImageType image_type;
 Error *local_err = NULL;
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-image_size = options->value.n;
-} else if (!strcmp(options->name, VHDX_BLOCK_OPT_LOG_SIZE)) {
-log_size = options->value.n;
-} else if (!strcmp(options->name, VHDX_BLOCK_OPT_BLOCK_SIZE)) {
-block_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
-type = options->value.s;
-} else if (!strcmp(options->name, VHDX_BLOCK_OPT_ZERO)) {
-use_zero_blocks = options->value.n != 0;
-}
-options++;
-}
+image_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+log_size = qemu_opt_get_size(options, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+block_size = qemu_opt_get_size(options, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+type = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
+use_zero_blocks = qemu_opt_get_bool(options, VHDX_BLOCK_OPT_ZERO, false);
 
 if (image_size > VHDX_MAX_IMAGE_SIZE) {
 error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1870,37 +1860,41 @@ static int vhdx_check(BlockDriverState *bs, 
BdrvCheckResult *result,
 return 0;
 }
 
-static QEMUOptionParameter vhdx_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size; max of 64TB."
-},
-{
-.name = VHDX_BLOCK_OPT_LOG_SIZE,
-.type = OPT_SIZE,
-.value.n = 1 * MiB,
-.help = "Log size; min 1MB."
-},
-{
-.name = VHDX_BLOCK_OPT_BLOCK_SIZE,
-.type = OPT_SIZE,
-.value.n = 0,
-.help = "Block Size; min 1MB, max 256MB. " \
-"0 means auto-calculate based on image size."
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
-"Default is 'dynamic'."
-},
-{
-.name = VHDX_BLOCK_OPT_ZERO,
-.type = OPT_FLAG,
-.help = "Force use of payload blocks of type 'ZERO'.  Non-standard."
+static QemuOptsList vhdx_create_options = {
+.name = "vhdx_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vhdx_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size; max of 64TB."
+},
+{
+.name = VHDX_BLOCK_OPT_LOG_SIZE,
+.type = QEMU_OPT_SIZE,
+.def_val = QEMU_OPT_VAL_SIZE(1 * MiB),
+.help = "Log size; min 1MB."
+},
+{
+.name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+.type = QEMU_OPT_SIZE,
+.def_val = QEMU_OPT_VAL_SIZE(0),
+.help = "Block Size; min 1MB, max 256MB. " \
+"0 means auto-calculate based on image size."
+},
+{
+.name = BLOCK_OPT_SUBFMT,
+.type = QEMU_OPT_STRING,
+.help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
+"Default is 'dynamic'."
+},
+{
+.name = VHDX_BLOCK_OPT_ZERO,
+.type = QEMU_OPT_BOOL,
+.help = "Force use of payload blocks of type 'ZERO'.  
Non-standard."
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_vhdx = {
@@ -1916,7 +1910,7 @@ static BlockDriver bdrv_vhdx = {
 .bdrv_get_info  = vhdx_get_info,
 .bdrv_check = vhdx_check,
 
-.create_options = vhdx_create_options,
+.create_options = &vhdx_create_options,
 };
 
 static void bdrv_vhdx_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 10/26] nfs: migrate nfs driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
nfs block driver.

Signed-off-by: Leandro Dorileo 
---
 block/nfs.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/block/nfs.c b/block/nfs.c
index 98aa363..c01f109 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -357,20 +357,13 @@ static int nfs_file_open(BlockDriverState *bs, QDict 
*options, int flags,
 return 0;
 }
 
-static int nfs_file_create(const char *url, QEMUOptionParameter *options,
-   Error **errp)
+static int nfs_file_create(const char *url, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 int64_t total_size = 0;
 NFSClient *client = g_malloc0(sizeof(NFSClient));
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, "size")) {
-total_size = options->value.n;
-}
-options++;
-}
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
 
 ret = nfs_client_open(client, url, O_CREAT, errp);
 if (ret < 0) {
-- 
1.9.0




[Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
iscsi block driver.

Signed-off-by: Leandro Dorileo 
---
 block/iscsi.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index b490e98..85252e7 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
*options, int flags,
 QemuOpts *opts;
 Error *local_err = NULL;
 const char *filename;
-int i, ret;
+int i, ret = 0;
 
 if ((BDRV_SECTOR_SIZE % 512) != 0) {
 error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t 
offset)
 return 0;
 }
 
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, 
QEMUOptionParameter *options,
 
 bs = bdrv_new("");
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, "size")) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-}
-options++;
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
 }
 
 bs->opaque = g_malloc0(sizeof(struct IscsiLun));
@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-static QEMUOptionParameter iscsi_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
+static QemuOptsList iscsi_create_options = {
+.name = "iscsi_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
 .bdrv_file_open  = iscsi_open,
 .bdrv_close  = iscsi_close,
 .bdrv_create = iscsi_create,
-.create_options  = iscsi_create_options,
+.create_options  = &iscsi_create_options,
 .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
 .bdrv_getlength  = iscsi_getlength,
-- 
1.9.0




[Qemu-devel] [PATCH 14/26] raw-posix: migrate raw-posix driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
raw-posix block driver.

Signed-off-by: Leandro Dorileo 
---
 block/raw-posix.c | 50 +++---
 1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 1688e16..ddeafa7 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1234,8 +1234,7 @@ 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,
-  Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int result = 0;
@@ -1243,12 +1242,9 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options,
 
 strstart(filename, "file:", &filename);
 
-/* 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 = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
 }
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
@@ -1410,13 +1406,17 @@ static int raw_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
+static QemuOptsList raw_create_options = {
+.name = "raw_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_file = {
@@ -1448,7 +1448,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 };
 
 /***/
@@ -1769,8 +1769,7 @@ static coroutine_fn int 
hdev_co_write_zeroes(BlockDriverState *bs,
 return -ENOTSUP;
 }
 
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int hdev_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int ret = 0;
@@ -1789,12 +1788,9 @@ static int hdev_create(const char *filename, 
QEMUOptionParameter *options,
 
 (void)has_prefix;
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, "size")) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-}
-options++;
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
 }
 
 fd = qemu_open(filename, O_WRONLY | O_BINARY);
@@ -1833,7 +1829,7 @@ static BlockDriver bdrv_host_device = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
 .bdrv_aio_readv= raw_aio_readv,
@@ -1977,7 +1973,7 @@ static BlockDriver bdrv_host_floppy = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2102,7 +2098,7 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2233,7 +2229,7 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
-- 
1.9.0




[Qemu-devel] [PATCH 13/26] qed: migrate qed driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qed block driver.

Signed-off-by: Leandro Dorileo 
---
 block/qed.c | 79 +++--
 1 file changed, 35 insertions(+), 44 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index 3bd9db9..c082ba3 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -621,7 +621,7 @@ out:
 return ret;
 }
 
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
+static int bdrv_qed_create(const char *filename, QemuOpts *options,
Error **errp)
 {
 uint64_t image_size = 0;
@@ -630,24 +630,11 @@ static int bdrv_qed_create(const char *filename, 
QEMUOptionParameter *options,
 const char *backing_file = NULL;
 const char *backing_fmt = NULL;
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-image_size = options->value.n;
-} 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_CLUSTER_SIZE)) {
-if (options->value.n) {
-cluster_size = options->value.n;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_TABLE_SIZE)) {
-if (options->value.n) {
-table_size = options->value.n;
-}
-}
-options++;
-}
+image_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+table_size = qemu_opt_get_size(options, BLOCK_OPT_TABLE_SIZE, 0);
 
 if (!qed_is_cluster_size_valid(cluster_size)) {
 fprintf(stderr, "QED cluster size must be within range [%u, %u] and 
power of 2\n",
@@ -1593,36 +1580,40 @@ static int bdrv_qed_check(BlockDriverState *bs, 
BdrvCheckResult *result,
 return qed_check(s, result, !!fix);
 }
 
-static QEMUOptionParameter qed_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size (in bytes)"
-}, {
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-}, {
-.name = BLOCK_OPT_BACKING_FMT,
-.type = OPT_STRING,
-.help = "Image format of the base image"
-}, {
-.name = BLOCK_OPT_CLUSTER_SIZE,
-.type = OPT_SIZE,
-.help = "Cluster size (in bytes)",
-.value = { .n = QED_DEFAULT_CLUSTER_SIZE },
-}, {
-.name = BLOCK_OPT_TABLE_SIZE,
-.type = OPT_SIZE,
-.help = "L1/L2 table size (in clusters)"
-},
-{ /* end of list */ }
+static QemuOptsList qed_create_options = {
+.name = "qed_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qed_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size (in bytes)"
+}, {
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+}, {
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Image format of the base image"
+}, {
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Cluster size (in bytes)",
+.def_val = QEMU_OPT_VAL_SIZE(QED_DEFAULT_CLUSTER_SIZE),
+}, {
+.name = BLOCK_OPT_TABLE_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "L1/L2 table size (in clusters)"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_qed = {
 .format_name  = "qed",
 .instance_size= sizeof(BDRVQEDState),
-.create_options   = qed_create_options,
+.create_options   = &qed_create_options,
 
 .bdrv_probe   = bdrv_qed_probe,
 .bdrv_rebind  = bdrv_qed_rebind,
-- 
1.9.0




[Qemu-devel] [PATCH 07/26] cow: migrate cow driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
cow block driver.

Signed-off-by: Leandro Dorileo 
---
 block/cow.c | 44 ++--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 30deb88..811f7f7 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -324,8 +324,7 @@ static void cow_close(BlockDriverState *bs)
 {
 }
 
-static int cow_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int cow_create(const char *filename, QemuOpts *options, Error **errp)
 {
 struct cow_header_v2 cow_header;
 struct stat st;
@@ -335,16 +334,13 @@ static int cow_create(const char *filename, 
QEMUOptionParameter *options,
 int ret;
 BlockDriverState *cow_bs;
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-image_sectors = options->value.n / 512;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-image_filename = options->value.s;
-}
-options++;
+image_sectors = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (image_sectors) {
+image_sectors = image_sectors / 512;
 }
 
+image_filename = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
 ret = bdrv_create_file(filename, options, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
@@ -393,18 +389,22 @@ exit:
 return ret;
 }
 
-static QEMUOptionParameter cow_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
+static QemuOptsList cow_create_options = {
+.name = "cow_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(cow_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_cow = {
@@ -421,7 +421,7 @@ static BlockDriver bdrv_cow = {
 .bdrv_write = cow_co_write,
 .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-.create_options = cow_create_options,
+.create_options = &cow_create_options,
 };
 
 static void bdrv_cow_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 08/26] gluster: migrate gluster driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
gluster block driver.

Signed-off-by: Leandro Dorileo 
---
 block/gluster.c | 68 +++--
 1 file changed, 37 insertions(+), 31 deletions(-)

diff --git a/block/gluster.c b/block/gluster.c
index a44d612..e8d966e 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -470,14 +470,15 @@ static inline int qemu_gluster_zerofill(struct glfs_fd 
*fd, int64_t offset,
 }
 #endif
 
-static int qemu_gluster_create(const char *filename,
-QEMUOptionParameter *options, Error **errp)
+static int qemu_gluster_create(const char *filename, QemuOpts *options,
+   Error **errp)
 {
 struct glfs *glfs;
 struct glfs_fd *fd;
 int ret = 0;
 int prealloc = 0;
 int64_t total_size = 0;
+const char *prealloc_opt;
 GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
 
 glfs = qemu_gluster_init(gconf, filename, errp);
@@ -486,24 +487,25 @@ static int qemu_gluster_create(const char *filename,
 goto out;
 }
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-} 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, "full") &&
-gluster_supports_zerofill()) {
-prealloc = 1;
-} else {
-error_setg(errp, "Invalid preallocation mode: '%s'"
-" or GlusterFS doesn't support zerofill API",
-   options->value.s);
-ret = -EINVAL;
-goto out;
-}
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
+}
+
+prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+if (prealloc_opt) {
+if (!strcmp(prealloc_opt, "off")) {
+prealloc = 0;
+} else if (!strcmp(prealloc_opt, "full") &&
+   gluster_supports_zerofill()) {
+prealloc = 1;
+} else {
+error_setg(errp, "Invalid preallocation mode: '%s'"
+   " or GlusterFS doesn't support zerofill API",
+   prealloc_opt);
+ret = -EINVAL;
+goto out;
 }
-options++;
 }
 
 fd = glfs_creat(glfs, gconf->image,
@@ -688,18 +690,22 @@ static int qemu_gluster_has_zero_init(BlockDriverState 
*bs)
 return 0;
 }
 
-static QEMUOptionParameter qemu_gluster_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_PREALLOC,
-.type = OPT_STRING,
-.help = "Preallocation mode (allowed values: off, full)"
+static QemuOptsList qemu_gluster_create_options = {
+.name = "qemu_gluster_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = QEMU_OPT_STRING,
+.help = "Preallocation mode (allowed values: off, full)"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_gluster = {
@@ -726,7 +732,7 @@ static BlockDriver bdrv_gluster = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
 .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes,
 #endif
-.create_options   = qemu_gluster_create_options,
+.create_options   = &qemu_gluster_create_options,
 };
 
 static BlockDriver bdrv_gluster_tcp = {
-- 
1.9.0




[Qemu-devel] [PATCH 05/26] QemuOpt: add qemu_opt_print_help()

2014-03-20 Thread Leandro Dorileo
Analogous to print_option_help(QEMUOptionParameter *list) this function
displays the available key and help for each described QemuOptDesc in
QemuOptList.

Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h |  1 +
 util/qemu-option.c| 12 
 2 files changed, 13 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3f4976d..62eacf3 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -177,6 +177,7 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, 
Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
 void qemu_opts_print(QemuOpts *opts);
+void qemu_opts_print_help(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 026d2ff..6fac370 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1022,6 +1022,18 @@ void qemu_opts_print(QemuOpts *opts)
 }
 }
 
+void qemu_opts_print_help(QemuOpts *opts)
+{
+QemuOptDesc *desc = opts->list->desc;
+
+printf("Supported options:\n");
+
+for (; desc && desc->name; desc++) {
+printf("%-16s %s\n", desc->name, desc->help ?
+   desc->help : "No description available");
+}
+}
+
 static int opts_do_parse(QemuOpts *opts, const char *params,
  const char *firstname, bool prepend)
 {
-- 
1.9.0




[Qemu-devel] [PATCH 25/26] QemuOpt: get rid of QEMUOptionParameter

2014-03-20 Thread Leandro Dorileo
Finally remove all the remaining QEMUOptionParameter bits.

Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h |  40 ---
 util/qemu-option.c| 296 --
 2 files changed, 336 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 62eacf3..4a7c148 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -31,24 +31,6 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
-enum QEMUOptionParType {
-OPT_FLAG,
-OPT_NUMBER,
-OPT_SIZE,
-OPT_STRING,
-};
-
-typedef struct QEMUOptionParameter {
-const char *name;
-enum QEMUOptionParType type;
-union {
-uint64_t n;
-char* s;
-} value;
-const char *help;
-bool assigned;
-} QEMUOptionParameter;
-
 
 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
 const char *get_opt_value(char *buf, int buf_size, const char *p);
@@ -57,33 +39,11 @@ int get_next_param_value(char *buf, int buf_size,
 int get_param_value(char *buf, int buf_size,
 const char *tag, const char *str);
 
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry->name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
-QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
-QEMUOptionParameter *list, QEMUOptionParameter *dest);
 void parse_option_size(const char *name, const char *value,
uint64_t *ret, Error **errp);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
 bool has_help_option(const char *param);
 bool is_valid_option_list(const char *param);
 
-/* -- */
-
 typedef struct QemuOpt QemuOpt;
 typedef struct QemuOpts QemuOpts;
 typedef struct QemuOptsList QemuOptsList;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6fac370..e08ed74 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -137,22 +137,6 @@ int get_param_value(char *buf, int buf_size,
 return get_next_param_value(buf, buf_size, tag, &str);
 }
 
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name)
-{
-while (list && list->name) {
-if (!strcmp(list->name, name)) {
-return list;
-}
-list++;
-}
-
-return NULL;
-}
-
 static void parse_option_bool(const char *name, const char *value, bool *ret,
   Error **errp)
 {
@@ -226,244 +210,6 @@ void parse_option_size(const char *name, const char 
*value,
 }
 }
 
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- *  If no value is given, the flag is set to 1.
- *  Otherwise the value must be "on" (set to 1) or "off" (set to 0)
- *
- * OPT_STRING (uses value.s):
- *  value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- *  The value is converted to an integer. Suffixes for kilobytes etc. are
- *  allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value)
-{
-bool flag;
-Error *local_err = NULL;
-
-// Find a matching parameter
-list = get_option_parameter(list, name);
-if (list == NULL) {
-fprintf(stderr, "Unknown option '%s'\n", name);
-return -1;
-}
-
-// Process parameter
-switch (list->type) {
-case OPT_FLAG:
-parse_option_bool(name, value, &flag, &local_err);
-if (!local_err) {
-list->value.n = flag;
-}
-break;
-
-case OPT_STRING:
-if (value != NULL) {
-list->value.s = g_strdup(value);
-} else {
-fprintf(stderr, "Option '%s' needs a parameter\n", name);
-return -1;
-}
-break;
-
-case OPT_SIZE:
-parse_option_size(name, value, &list->value.n, &local_err);
-break;
-
-default:
-fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
-return -1;
-}
-
-if (local_e

[Qemu-devel] [PATCH 23/26] vpc: migrate vpc driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vpc block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vpc.c | 54 +++---
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 82bf248..421b820 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -714,12 +714,11 @@ static int create_fixed_disk(int fd, uint8_t *buf, 
int64_t total_size)
 return ret;
 }
 
-static int vpc_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int vpc_create(const char *filename, QemuOpts *options, Error **errp)
 {
 uint8_t buf[1024];
 VHDFooter *footer = (VHDFooter *) buf;
-QEMUOptionParameter *disk_type_param;
+const char *disk_type_param;
 int fd, i;
 uint16_t cyls = 0;
 uint8_t heads = 0;
@@ -729,20 +728,17 @@ static int vpc_create(const char *filename, 
QEMUOptionParameter *options,
 int disk_type;
 int ret = -EIO;
 
-/* Read out options */
-total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+disk_type_param = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
 
-disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT);
-if (disk_type_param && disk_type_param->value.s) {
-if (!strcmp(disk_type_param->value.s, "dynamic")) {
-disk_type = VHD_DYNAMIC;
-} else if (!strcmp(disk_type_param->value.s, "fixed")) {
-disk_type = VHD_FIXED;
-} else {
-return -EINVAL;
-}
-} else {
+if (!disk_type_param) {
 disk_type = VHD_DYNAMIC;
+} else if (!strcmp(disk_type_param, "dynamic")) {
+disk_type = VHD_DYNAMIC;
+} else if (!strcmp(disk_type_param, "fixed")) {
+disk_type = VHD_FIXED;
+} else {
+return -EINVAL;
 }
 
 /* Create the file */
@@ -842,20 +838,24 @@ static void vpc_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static QEMUOptionParameter vpc_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help =
+static QemuOptsList vpc_create_options = {
+.name = "vpc_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vpc_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_SUBFMT,
+.type = QEMU_OPT_STRING,
+.help =
 "Type of virtual hard disk format. Supported formats are "
 "{dynamic (default) | fixed} "
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_vpc = {
@@ -873,7 +873,7 @@ static BlockDriver bdrv_vpc = {
 
 .bdrv_get_info  = vpc_get_info,
 
-.create_options = vpc_create_options,
+.create_options = &vpc_create_options,
 .bdrv_has_zero_init = vpc_has_zero_init,
 };
 
-- 
1.9.0




[Qemu-devel] [PATCH 03/26] QemuOpt: improve default value

2014-03-20 Thread Leandro Dorileo
Use a pointer to a structure holding the primitive types and avoid
parsing the default value representation.

Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h | 20 +++-
 util/qemu-config.c|  4 ++--
 util/qemu-option.c| 45 ++---
 3 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index c3b0a91..f0d4798 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -95,11 +95,29 @@ enum QemuOptType {
 QEMU_OPT_SIZE,/* size, accepts (K)ilo, (M)ega, (G)iga, (T)era 
postfix */
 };
 
+#define QEMU_OPT_VAL_STR(_val)  \
+&(QemuOptValue) {.s = _val} \
+
+#define QEMU_OPT_VAL_NUMBER(_val)   \
+&(QemuOptValue) {.n = _val} \
+
+#define QEMU_OPT_VAL_SIZE(_val) \
+&(QemuOptValue) {.n = _val} \
+
+#define QEMU_OPT_VAL_BOOL(_val) \
+&(QemuOptValue) {.b = _val} \
+
+typedef struct QemuOptValue {
+bool b;
+uint64_t n;
+const char *s;
+} QemuOptValue;
+
 typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
-const char *def_value_str;
+QemuOptValue *def_val;
 } QemuOptDesc;
 
 struct QemuOptsList {
diff --git a/util/qemu-config.c b/util/qemu-config.c
index d608b2f..a40711b 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -68,9 +68,9 @@ static CommandLineParameterInfoList *query_option_descs(const 
QemuOptDesc *desc)
 info->has_help = true;
 info->help = g_strdup(desc[i].help);
 }
-if (desc[i].def_value_str) {
+if (desc[i].def_val) {
 info->has_q_default = true;
-info->q_default = g_strdup(desc[i].def_value_str);
+info->q_default = g_strdup(desc[i].def_val->s);
 }
 
 entry = g_malloc0(sizeof(*entry));
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8c0756d..612a966 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -573,8 +573,8 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
 
 if (!opt) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-return desc->def_value_str;
+if (desc && desc->def_val) {
+return desc->def_val->s;
 }
 }
 return opt ? opt->str : NULL;
@@ -598,11 +598,12 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-parse_option_bool(name, desc->def_value_str, &defval, 
&error_abort);
+if (desc && desc->def_val) {
+return desc->def_val->b;
 }
 return defval;
 }
+
 assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
 return opt->value.boolean;
 }
@@ -613,9 +614,8 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-parse_option_number(name, desc->def_value_str, &defval,
-&error_abort);
+if (desc && desc->def_val) {
+return desc->def_val->n;
 }
 return defval;
 }
@@ -629,8 +629,8 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
*name, uint64_t defval)
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-parse_option_size(name, desc->def_value_str, &defval, 
&error_abort);
+if (desc && desc->def_val) {
+return desc->def_val->n;
 }
 return defval;
 }
@@ -929,21 +929,28 @@ void qemu_opts_print(QemuOpts *opts)
 }
 return;
 }
+
 for (; desc && desc->name; desc++) {
-const char *value;
-QemuOpt *opt = qemu_opt_find(opts, desc->name);
+const char *str;
+uint64_t number;
+bool bol;
 
-value = opt ? opt->str : desc->def_value_str;
-if (!value) {
-continue;
-}
 if (desc->type == QEMU_OPT_STRING) {
-fprintf(stderr, "%s='%s' ", desc->name, value);
-} else {
-fprintf(stderr, "%s=%s ", desc->name, value);
+s

[Qemu-devel] [PATCH 04/26] QemuOpt: introduce qemu_opts_append()

2014-03-20 Thread Leandro Dorileo
From: Chunyan Liu 

The qemu_opts_append() function is intended to merge to different
QemuOptsList's. The resulting list must be freed by its user.

Signed-off-by: Chunyan Liu 
Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h |  1 +
 util/qemu-option.c| 69 +++
 2 files changed, 70 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index f0d4798..3f4976d 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -157,6 +157,7 @@ int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc 
func, void *opaque,
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
int fail_if_exists, Error **errp);
+QemuOptsList *qemu_opts_append(QemuOptsList *head, QemuOptsList *tail);
 void qemu_opts_reset(QemuOptsList *list);
 void qemu_opts_loc_restore(QemuOpts *opts);
 int qemu_opts_set(QemuOptsList *list, const char *id,
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 612a966..026d2ff 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -863,6 +863,75 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char 
*id,
 return opts;
 }
 
+static size_t count_opts_list(QemuOptsList *list)
+{
+QemuOptDesc *desc = NULL;
+size_t num_opts = 0;
+
+if (!list) {
+return 0;
+}
+
+desc = list->desc;
+while (desc && desc->name) {
+num_opts++;
+desc++;
+}
+
+return num_opts;
+}
+
+/**
+ * Merge two QEMUOptsList. First argument's QemuOptDesc members take precedence
+ * over second's.
+ *
+ * @note The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both lists can be NULL.
+ *
+ * The resulting QemuOptsList should be freed by this functions caller.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list)
+{
+size_t num_opts, num_dst_opts;
+QemuOptsList *tmp;
+QemuOptDesc *desc;
+
+if (!dst && !list) {
+return NULL;
+}
+
+num_opts = count_opts_list(dst);
+num_opts += count_opts_list(list);
+tmp = g_malloc0(sizeof(QemuOptsList) +
+(num_opts + 1) * sizeof(QemuOptDesc));
+QTAILQ_INIT(&tmp->head);
+num_dst_opts = 0;
+
+/* copy dst->desc to new list */
+if (dst) {
+desc = dst->desc;
+while (desc && desc->name) {
+tmp->desc[num_dst_opts++] = *desc;
+tmp->desc[num_dst_opts].name = NULL;
+desc++;
+}
+}
+
+/* add list->desc to new list */
+if (list) {
+desc = list->desc;
+while (desc && desc->name) {
+if (find_desc_by_name(tmp->desc, desc->name) == NULL) {
+tmp->desc[num_dst_opts++] = *desc;
+tmp->desc[num_dst_opts].name = NULL;
+}
+desc++;
+}
+}
+
+return tmp;
+}
+
 void qemu_opts_reset(QemuOptsList *list)
 {
 QemuOpts *opts, *next_opts;
-- 
1.9.0




[Qemu-devel] [PATCH 02/26] add def_value_str to QemuOptDesc

2014-03-20 Thread Leandro Dorileo
From: Chunyan Liu 

Add def_value_str (default value) to QemuOptDesc, to replace function of the
default value in QEMUOptionParameter. And improved related functions.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 include/qemu/option.h |  3 +-
 util/qemu-option.c| 84 +--
 2 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..c3b0a91 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
+const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
@@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
-int qemu_opts_print(QemuOpts *opts, void *dummy);
+void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9d898af..8c0756d 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,20 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/option_int.h"
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+const char *name)
+{
+int i;
+
+for (i = 0; desc[i].name != NULL; i++) {
+if (strcmp(desc[i].name, name) == 0) {
+return &desc[i];
+}
+}
+
+return NULL;
+}
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -556,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
*name)
 const char *qemu_opt_get(QemuOpts *opts, const char *name)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+
+if (!opt) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+return desc->def_value_str;
+}
+}
 return opt ? opt->str : NULL;
 }
 
@@ -575,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
-if (opt == NULL)
+if (opt == NULL) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_bool(name, desc->def_value_str, &defval, 
&error_abort);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
 return opt->value.boolean;
 }
@@ -585,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
-if (opt == NULL)
+if (opt == NULL) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_number(name, desc->def_value_str, &defval,
+&error_abort);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
 return opt->value.uint;
 }
@@ -595,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
*name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
-if (opt == NULL)
+if (opt == NULL) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_size(name, desc->def_value_str, &defval, 
&error_abort);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
 return opt->value.uint;
 }
@@ -637,20 +674,6 @@ static bool opts_accepts_any(const QemuOpts *opts)
 return opts->list->desc[0].name == NULL;
 }
 
-static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
-const char *name)
-{
-int i;
-
-for (i = 0; desc[i].name != NULL; i++) {
-if (strcmp(desc[i].name, name) == 0) {
-return &desc[i];
-}
-}
-
-return NULL;
-}
-
 int qemu_opt_unset(QemuOpts *opts, const char *name)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
@@ -895,17 +918,32 @@ void qemu_opts_del(QemuOpts *opts)
 g_free(opts);
 }
 
-int qemu_opts_print(QemuOpts *opts, void *dummy)
+void qemu_opts_print(QemuOpts *opts)
 {
 QemuOpt *opt;
+QemuOptDesc *desc = opts->list->desc;
 
-fprintf(stderr, "%s: %s:", opts->list->name,
-opts->id ? opts->id : "");
-QTAILQ_FOREACH(opt, &opts->head, next) {
-fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
+if (desc[0].name == NULL) {
+QTAILQ_FOREACH(opt, &opts->head, next) {
+fprintf(stderr, "%s=\"%s\"

Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts

2014-03-20 Thread Leandro Dorileo
Hi Chunyan,

On Mon, Mar 10, 2014 at 03:31:36PM +0800, Chunyan Liu wrote:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that 
> only
> one Qemu Option structure is kept in QEMU code.
> 


Last night I took some time do take a deeper look at you series and the required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your
serie's bisectability (?), but the final result was something really hard to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last commit. Moreover,
in the path of getting things ready you created new problems and their 
respective
fixes, what we really don't need to.

In this regards you could have kept things as simple as possible and submitted
the patches in a "natural way", even if they were breaking the build between 
each
patch, you could get all the required maintainer's Reviewed-by + Tested-by +
Signed-off-by and so on for each individual patch and when it was time to
integrate get squashed the needed patches.

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating
the block upper layer (block.c, block.h, etc), one patch for each block driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and finally a last
patch removing the QEMUOptionParamer itself. When time comes to integrate your
series the patches changing the block layer + patches changing the block 
drivers +
patches changing qemu-img.c could be squashed adding all the collected 
Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and, understood most
of changes weren't required to do the job. We don't need an adaptation layer 
between
QemuOptionParameter and QemuOpts, we don't need to add new opts accessors (like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() 
function
so we can merge the protocol and drivers options in a single QemuOptList and
2) the default value support. All we need is already present in the QemuOpts 
APIs.

With that simpler approach in mind I ended up putting my hands in the source 
code
trying to see how feasible it is, and turns out I came up with a full solution. 
I'm
sending the job's resulting series to the mailing list so I can show you what
I mean and have some more room for discussion. It doesn't mean I want to overlap
you work, I just needed to have a little more input on that.

Regards

-- 
Leandro Dorileo



Re: [Qemu-devel] How to understand the coroutine context?

2014-03-18 Thread Leandro Dorileo
Hi,

On Tue, Mar 18, 2014 at 07:56:16AM +0800, Le Tan wrote:
> Hi, I am diving into the source code of qemu. I see the word
> "coroutine" appears in so many places. I can't figure out what it
> means. So, please, can anyone help me, telling me the mechanism or
> semantic of "coroutine"? Thanks!

If you want to understand the coroutine technique itself take a look
at this page[1], the're two references that may be helpfull.

A friend of mine has described[2] his view on implementing coroutine,
this may be helpfull as well.

[1] - http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
[2] - 
http://tia.mat.br/blog/html/2012/09/29/asynchronous_i_o_in_c_with_coroutines.html

Regards...

-- 
Leandro Dorileo



[Qemu-devel] [PATCH v2] QemuOpt: add unit tests

2014-03-17 Thread Leandro Dorileo
Cover basic aspects and API usage for QemuOpt. The current implementation
covers the API's planned to be changed by Chunyan Liu in his QEMUOptionParameter
replacement/cleanup job.

Other APIs should be covered in future improvements.

Signed-off-by: Leandro Dorileo 

Changes:
  v2:
 + fixed comments;
 + make use of g_assert_cmpstr();
 + use error_abort instead of a local_err for qemu_opts_absorb_qdict();
 + asserts on QemuOptsList (empty and list name);
 + added test_qemu_opt_unset();
 + asserts on qemu_opt_*_set() return;
 + added test_qemu_opts_reset();
 + added test_qemu_opts_set();
---
 tests/Makefile |   3 +
 tests/test-qemu-opts.c | 455 +
 2 files changed, 458 insertions(+)
 create mode 100644 tests/test-qemu-opts.c

diff --git a/tests/Makefile b/tests/Makefile
index 471b4c8..4814283 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-y += tests/test-vmstate$(EXESUF)
+check-unit-y += tests/test-qemu-opts$(EXESUF)
+gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -272,6 +274,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
libqemustub.a
 
 # QTest rules
 
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
new file mode 100644
index 000..abd2fb8
--- /dev/null
+++ b/tests/test-qemu-opts.c
@@ -0,0 +1,455 @@
+/*
+ * QemuOpts unit-tests.
+ *
+ * Copyright (C) 2014 Leandro Dorileo 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qapi/error.h"
+#include "qapi/qmp/qstring.h"
+#include "qemu/config-file.h"
+
+#include 
+#include 
+
+static QemuOptsList opts_list_01 = {
+.name = "opts_list_01",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str3",
+.type = QEMU_OPT_STRING,
+},{
+.name = "number1",
+.type = QEMU_OPT_NUMBER,
+},
+{ /* end of list */ }
+},
+};
+
+static QemuOptsList opts_list_02 = {
+.name = "opts_list_02",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "bool1",
+.type = QEMU_OPT_BOOL,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "size1",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
+QemuOptsList opts_list_03 = {
+.name = "opts_list_03",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
+static void register_opts(void)
+{
+qemu_add_opts(&opts_list_01);
+qemu_add_opts(&opts_list_02);
+qemu_add_opts(&opts_list_03);
+}
+
+static void test_find_unknown_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* should not return anything, we don't have an "unknown" option */
+list = qemu_find_opts("unknown");
+g_assert(list == NULL);
+}
+
+static void test_qemu_find_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/* we have an "opts_list_01" option, should return it */
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+}
+
+static void test_qemu_opts_create(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+
+register_opts();
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+g_assert(QTAILQ_EMPTY(&list->head));
+g_assert_cmpstr(list->name, ==, "opts_list_01");
+
+/* should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/* create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+g_assert(opts != NULL);
+g_assert(!QTAILQ_EMPTY(&list->head));
+
+/*

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

2014-03-17 Thread Leandro Dorileo
Hi,

On Mon, Mar 10, 2014 at 03:31:39PM +0800, Chunyan Liu wrote:
> Improve opt_get and opt_set group of functions. For opt_get, check and handle
> NULL input; for opt_set, when set to an existing option, rewrite the option
> with new value.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 
> ---
>  include/qemu/option_int.h |  4 +--
>  util/qemu-option.c| 81 
> +++
>  2 files changed, 69 insertions(+), 16 deletions(-)
> 
> diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
> index 8212fa4..db9ed91 100644
> --- a/include/qemu/option_int.h
> +++ b/include/qemu/option_int.h
> @@ -30,8 +30,8 @@
>  #include "qemu/error-report.h"
>  
>  struct QemuOpt {
> -const char   *name;
> -const char   *str;
> +char   *name;
> +char   *str;
>  
>  const QemuOptDesc *desc;
>  union {
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 65d1c22..c7639e8 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -558,8 +558,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
> *name)
>  
>  const char *qemu_opt_get(QemuOpts *opts, const char *name)
>  {
> -QemuOpt *opt = qemu_opt_find(opts, name);
> +QemuOpt *opt;
>  
> +if (opts == NULL) {
> +return NULL;
> +}



I understand you want to prevent a segfault in qemu_opt_find(), and I'm fine 
with that,
but these checks make me wonder why you decided to change it, aren't you hiding 
some
broken caller?

Btw, you could change qemu_opt_find() and check if opts != NULL there and not 
introduce
all these opts == NULL qemu_opt_find() pairs.

--
Dorileo

> +
> +opt = qemu_opt_find(opts, name);
>  if (!opt) {
>  const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
>  if (desc && desc->def_value_str) {
> @@ -583,7 +588,13 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
>  
>  bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
>  {
> -QemuOpt *opt = qemu_opt_find(opts, name);
> +QemuOpt *opt;
> +
> +if (opts == NULL) {
> +return defval;
> +}
> +
> +opt = qemu_opt_find(opts, name);
>  
>  if (opt == NULL) {
>  const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
> @@ -598,7 +609,13 @@ 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 == NULL) {
> +return defval;
> +}
> +
> +opt = qemu_opt_find(opts, name);
>  
>  if (opt == NULL) {
>  const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
> @@ -614,8 +631,13 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
> *name, uint64_t defval)
>  
>  uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
>  {
> -QemuOpt *opt = qemu_opt_find(opts, name);
> +QemuOpt *opt;
>  
> +if (opts == NULL) {
> +return defval;
> +}
> +
> +opt = qemu_opt_find(opts, name);
>  if (opt == NULL) {
>  const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
>  if (desc && desc->def_value_str) {
> @@ -652,6 +674,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>  
>  static void qemu_opt_del(QemuOpt *opt)
>  {
> +if (opt == NULL) {
> +return;
> +}
> +
>  QTAILQ_REMOVE(&opt->opts->head, opt, next);
>  g_free((/* !const */ char*)opt->name);
>  g_free((/* !const */ char*)opt->str);
> @@ -704,6 +730,13 @@ static void opt_set(QemuOpts *opts, const char *name, 
> const char *value,
>  return;
>  }
>  
> +opt = qemu_opt_find(opts, name);
> +if (opt) {
> +g_free((char *)opt->str);
> +opt->str = g_strdup(value);
> +return;
> +}
> +
>  opt = g_malloc0(sizeof(*opt));
>  opt->name = g_strdup(name);
>  opt->opts = opts;
> @@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, 
> const char *value,
>  int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
>  {
>  QemuOpt *opt;
> -const QemuOptDesc *desc = opts->list->desc;
> +const QemuOptDesc *desc;
>  
> -opt = g_malloc0(sizeof(*opt));
> -opt->desc = find_desc_by_name(desc, name);
> -if (!opt->desc && !opts_accepts_any(opts)) {
> +desc = find_desc_by_name(opts->list->desc, name);
> +if (!desc && !opts_accepts_any(opts)) {
>  qerror_report(QERR_INVALID_PARAMETER, name);
> -g_free(opt);
>  return -1;
>  }
>  
> +opt = qemu_opt_find(opts, name);
> +if (opt) {
> +g_free((char *)opt->str);
> +opt->value.boolean = val;
> +opt->str = g_strdup(val ? "on" : "off");
> +return 0;
> +}
> +
> +opt = g_malloc0(sizeof(*opt));
> +opt->desc = desc;
>  opt->name = g_strdup(name);
>  opt->opts =

Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter

2014-03-17 Thread Leandro Dorileo
Hi,

On Mon, Mar 17, 2014 at 07:29:29PM +, Leandro Dorileo wrote:
> Hi,
> 
> On Mon, Mar 10, 2014 at 03:32:01PM +0800, Chunyan Liu wrote:
> > Now all places using QEMUOptionParameter could use QemuOpts too, remove
> > QEMUOptionParameter related code.
> > 
> > Signed-off-by: Dong Xu Wang 
> > Signed-off-by: Chunyan Liu 
> > ---
> >  block.c   |  69 ++--
> >  block/cow.c   |   4 +-
> >  block/gluster.c   |   8 +-
> >  block/qcow.c  |   4 +-
> >  block/qcow2.c |   6 +-
> >  block/qed.c   |   4 +-
> >  block/raw-posix.c |  10 +-
> >  block/raw-win32.c |   2 +-
> >  block/raw_bsd.c   |   4 +-
> >  block/rbd.c   |   2 +-
> >  block/sheepdog.c  |   6 +-
> >  block/ssh.c   |   2 +-
> >  block/vdi.c   |   2 +-
> >  block/vhdx.c  |   4 +-
> >  block/vmdk.c  |   6 +-
> >  block/vpc.c   |   2 +-
> >  block/vvfat.c |   2 +-
> >  include/block/block.h |   8 +-
> >  include/block/block_int.h |  13 +-
> >  include/qemu/option.h |  46 --
> >  qemu-img.c|  63 +---
> >  util/qemu-option.c| 401 
> > --
> >  22 files changed, 62 insertions(+), 606 deletions(-)
> 
> It seems you've missed block/iscsi.c in the final cleanup.
> 
> I got the following:
> 
> block/iscsi.c:1385:47: error: unknown type name ‘QEMUOptionParameter’
>  static int iscsi_create(const char *filename, QEMUOptionParameter *options,
>^
> block/iscsi.c:1470:24: error: ‘iscsi_create’ undeclared here (not in a 
> function)
>  .bdrv_create = iscsi_create,
> 
> 
> I did a s/QemuOptionParameter/QemuOption/ and got the following:
> 
> block/iscsi.c: In function ‘iscsi_create’:
> block/iscsi.c:1398:31: error: ‘opts’ undeclared (first use in this function)
>  qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
>^
> block/iscsi.c:1398:31: note: each undeclared identifier is reported only once 
> for each function it appears in
> /home/dorileo/work/sources/foss/qemu/rules.mak:33: recipe for target 
> 'block/iscsi.o' failed
> 
> iscsi_create() is expecting an argument opts not options, then a 
> s/options/opts/ here
> fixed the issue.
> 
> I ran my QemuOpts testsuite on top of your patches and got a few problems 
> (initially 2 wrong assertions).
> I'll dig it a little deeper - when I find some time to - and comment in the 
> proper patches.


It's also broken test-opts-visitor.c

ERROR:tests/test-opts-visitor.c:119:test_value: assertion failed: (magic == 
0xDEADBEEF)

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

2014-03-17 Thread Leandro Dorileo
Hi,

On Mon, Mar 10, 2014 at 03:31:41PM +0800, Chunyan Liu wrote:
> Add some qemu_opt functions to replace the same functionality of
> QEMUOptionParameter handling.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 
> ---
>  include/qemu/option.h |   9 +++
>  util/qemu-option.c| 188 
> ++
>  2 files changed, 184 insertions(+), 13 deletions(-)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index c3b0a91..de4912a 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -111,6 +111,7 @@ struct QemuOptsList {
>  };
>  
>  const char *qemu_opt_get(QemuOpts *opts, const char *name);
> +char *qemu_opt_get_del(QemuOpts *opts, const char *name);
>  /**
>   * qemu_opt_has_help_opt:
>   * @opts: options to search for a help request
> @@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
>  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);
>  uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t 
> defval);
> +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
> +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
> + uint64_t defval);
> +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
> +   uint64_t defval);


I have initially understood you would remove these _del() suffixed functions in 
your
final cleanup, but it seems you haven't. Am I missing something?

Neither the functions nor the callers have been cleanup, why?

Regards..

--
Dorileo

>  int qemu_opt_unset(QemuOpts *opts, const char *name);
>  int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
>  void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
> @@ -161,4 +167,7 @@ void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
> *opaque,
>int abort_on_failure);
>  
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
> +void qemu_opts_free(QemuOptsList *list);
> +void qemu_opts_print_help(QemuOptsList *list);
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index df79235..2c450e0 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -35,6 +35,7 @@
>  
>  static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
>  const char *name);
> +static void qemu_opt_del(QemuOpt *opt);
>  
>  /*
>   * Extracts the name of an option from the parameter string (p points at the
> @@ -379,6 +380,74 @@ QEMUOptionParameter 
> *append_option_parameters(QEMUOptionParameter *dest,
>  return dest;
>  }
>  
> +static size_t count_opts_list(QemuOptsList *list)
> +{
> +QemuOptDesc *desc = NULL;
> +size_t num_opts = 0;
> +
> +if (!list) {
> +return 0;
> +}
> +
> +desc = list->desc;
> +while (desc && desc->name) {
> +num_opts++;
> +desc++;
> +}
> +
> +return num_opts;
> +}
> +
> +/* Create a new QemuOptsList with a desc of the merge of the first
> + * and second. It will allocate space for one new QemuOptsList plus
> + * enough space for QemuOptDesc in first and second QemuOptsList.
> + * First argument's QemuOptDesc members take precedence over second's.
> + * The result's name and implied_opt_name are not copied from them.
> + * Both merge_lists should not be set. Both lists can be NULL.
> + */
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> +   QemuOptsList *list)
> +{
> +size_t num_opts, num_dst_opts;
> +QemuOptsList *tmp;
> +QemuOptDesc *desc;
> +
> +if (!dst && !list) {
> +return NULL;
> +}
> +
> +num_opts = count_opts_list(dst);
> +num_opts += count_opts_list(list);
> +tmp = g_malloc0(sizeof(QemuOptsList) +
> +(num_opts + 1) * sizeof(QemuOptDesc));
> +QTAILQ_INIT(&tmp->head);
> +num_dst_opts = 0;
> +
> +/* copy dst->desc to new list */
> +if (dst) {
> +desc = dst->desc;
> +while (desc && desc->name) {
> +tmp->desc[num_dst_opts++] = *desc;
> +tmp->desc[num_dst_opts].name = NULL;
> +desc++;
> +}
> +}
> +
> +/* add list->desc to new list */
> +if (list) {
> +desc = list->desc;
> +while (desc && desc->name) {
> +if (find_desc_by_name(tmp->desc, desc->name) == NULL) {
> +tmp->desc[num_dst_opts++] = *desc;
> +tmp->desc[num_dst_opts].name = NULL;
> +}
> +desc++;
> +}
> +}
> +
> +return tmp;
> +}
> +
>  /*
>   * Parses a parameter string (param) into an option list (dest).
>   *
> @@ -574,6 +643,29 @@ const char *qemu_opt_get(QemuOpts *opts, const char 
> *name)
>  return opt ? 

Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter

2014-03-17 Thread Leandro Dorileo
Hi,

On Mon, Mar 10, 2014 at 03:32:01PM +0800, Chunyan Liu wrote:
> Now all places using QEMUOptionParameter could use QemuOpts too, remove
> QEMUOptionParameter related code.
> 
> Signed-off-by: Dong Xu Wang 
> Signed-off-by: Chunyan Liu 
> ---
>  block.c   |  69 ++--
>  block/cow.c   |   4 +-
>  block/gluster.c   |   8 +-
>  block/qcow.c  |   4 +-
>  block/qcow2.c |   6 +-
>  block/qed.c   |   4 +-
>  block/raw-posix.c |  10 +-
>  block/raw-win32.c |   2 +-
>  block/raw_bsd.c   |   4 +-
>  block/rbd.c   |   2 +-
>  block/sheepdog.c  |   6 +-
>  block/ssh.c   |   2 +-
>  block/vdi.c   |   2 +-
>  block/vhdx.c  |   4 +-
>  block/vmdk.c  |   6 +-
>  block/vpc.c   |   2 +-
>  block/vvfat.c |   2 +-
>  include/block/block.h |   8 +-
>  include/block/block_int.h |  13 +-
>  include/qemu/option.h |  46 --
>  qemu-img.c|  63 +---
>  util/qemu-option.c| 401 
> --
>  22 files changed, 62 insertions(+), 606 deletions(-)

It seems you've missed block/iscsi.c in the final cleanup.

I got the following:

block/iscsi.c:1385:47: error: unknown type name ‘QEMUOptionParameter’
 static int iscsi_create(const char *filename, QEMUOptionParameter *options,
   ^
block/iscsi.c:1470:24: error: ‘iscsi_create’ undeclared here (not in a function)
 .bdrv_create = iscsi_create,


I did a s/QemuOptionParameter/QemuOption/ and got the following:

block/iscsi.c: In function ‘iscsi_create’:
block/iscsi.c:1398:31: error: ‘opts’ undeclared (first use in this function)
 qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
   ^
block/iscsi.c:1398:31: note: each undeclared identifier is reported only once 
for each function it appears in
/home/dorileo/work/sources/foss/qemu/rules.mak:33: recipe for target 
'block/iscsi.o' failed

iscsi_create() is expecting an argument opts not options, then a 
s/options/opts/ here
fixed the issue.

I ran my QemuOpts testsuite on top of your patches and got a few problems 
(initially 2 wrong assertions).
I'll dig it a little deeper - when I find some time to - and comment in the 
proper patches.

Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH] QemuOpt: add unit tests

2014-03-17 Thread Leandro Dorileo
On Mon, Mar 17, 2014 at 10:16:12AM -0600, Eric Blake wrote:
> On 03/16/2014 03:18 PM, Leandro Dorileo wrote:
> > Cover basic aspects and API usage for QemuOpt. The current implementation
> > covers the API's planed to be changed by Chunyan Liu in his 
> > QEMUOptionParameter
> 
> s/planed/planned/
> 
> > replacement/cleanup job.
> > 
> > Other APIs should be covered in future improvements.
> > 
> > Signed-off-by: Leandro Dorileo 
> > ---
> >  tests/Makefile |   3 +
> >  tests/test-qemu-opts.c | 309 
> > +
> >  2 files changed, 312 insertions(+)
> >  create mode 100644 tests/test-qemu-opts.c
> > 
> 
> > +
> > +static void test_find_unknown_opts(void)
> > +{
> > +QemuOptsList *list;
> > +
> > +register_opts();
> > +
> > +/** should not return anything, we don't known "unknown" option */
> 
> s/known/have an/

ok.

> 
> Here, and throughout the file: /** */ comments are special to doc
> markup, and should only be needed prior to declaring a function.  Within
> a function body, use the simpler /* */ comment.
> 
> > +static void test_qemu_find_opts(void)
> > +{
> > +QemuOptsList *list;
> > +
> > +register_opts();
> > +
> > +/** we have an rtc option, should return it */
> > +list = qemu_find_opts("opts_list_01");
> > +g_assert(list != NULL);
> 
> Should you do any further testing on the contents of the returned list?

ok. I'll see the API.

> 
> > +static void test_qemu_opt_get(void)
> > +{
> 
> > +/** now we have set str2, should know about it */
> > +opt = qemu_opt_get(opts, "str2");
> > +g_assert(opt != NULL && !strcmp(opt, "value"));
> 
> Isn't g_assert_cmpstr nicer for this, as in:
> 
> g_assert_cmpstr(opt, ==, "value");


Yep, sure, I wasn't awere of g_assert_cmpstr, thanks.

> 
> > +static void test_qemu_opt_get_size(void)
> > +{
> > +QemuOptsList *list;
> 
> > +
> > +qemu_opts_absorb_qdict(opts, dict, &local_err);
> > +g_assert(local_err == NULL);
> 
> shorter as:
> 
> qemu_opts_absorb_qdict(opts, dict, &error_abort);

I see.

> 
> Overall, I like where this is headed; looking forward to v2.
> 

Thanks for reviewing...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH RFC 0/2] qemu-arg: general purpose argument parser

2014-03-16 Thread Leandro Dorileo
Hi Erick,

On Tue, Mar 11, 2014 at 09:22:54AM -0600, Eric Blake wrote:
> On 03/11/2014 08:09 AM, Leandro Dorileo wrote:
> > Hi Kevin,
> > 
> > On Tue, Mar 11, 2014 at 12:06:16PM +0100, Kevin Wolf wrote:
> >> Am 08.03.2014 um 19:47 hat Leandro Dorileo geschrieben:
> >>> The following patchset introduces a general purpose argument parser and 
> >>> migrates
> >>> qemu-img to make use of it. qemu-img is just the first user of it, if we 
> >>> see a
> >>> good feedback here I move forward and migrate all the other possible 
> >>> users.
> >>
> >> I was planning to reply to this in more detail, but it doesn't look like
> >> I can find the time to do so, so let me just summarise my thoughts
> >> briefly.
> > 
> > Ok.
> > 
> >>
> >> I do like the idea of simplifying qemu-img's argument parsing, but we
> >> shouldn't make the mistake of introducing another option parsing
> >> infrastructure and end up with three different coexisting models. If we
> >> were to introduce a new framework, we must make sure that all code is
> >> converted to it and QemuOpts can be dropped.
> > 
> > Agreed.
> 
> For that matter, if you want to help the current conversion efforts
> going on, we are trying to get rid of QEMUOptionParameters to _just_ use
> QemuOpts:
> https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg01728.html

Yep sure, I have followed the current patches and reviews, I have just
posted a patch with an initial testsuite for QemuOpt in the sense to help to 
have it
integrated.

> 
> 
> >>
> >> We would probably need to add a new parser to QemuOpts that parses
> >> command line options into a QemuOpts, and extend the definition of them
> >> with a couple of new features that are required there (sub-QemuOpts for
> >> -o, perhaps enumerations for things like --output=human/json, positional
> >> parameters).
> > 
> > Ok.
> 
> We also need to think how to expose those improvements via the QMP
> command query-command-line-arguments; lots of details in this thread:
> https://lists.gnu.org/archive/html/qemu-devel/2014-03/threads.html#00934

Will take a look at it.

Thanks...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

2014-03-16 Thread Leandro Dorileo
Hi Chunyan,

On Tue, Mar 11, 2014 at 09:00:04PM +, Leandro Dorileo wrote:
> Hi,
> 
> On Tue, Mar 11, 2014 at 03:26:51PM +0800, Chunyan Liu wrote:
> > 2014-03-11 5:21 GMT+08:00 Eric Blake :
> > 
> > > On 03/10/2014 02:29 PM, Eric Blake wrote:
> > >
> > > >> +opt = qemu_opt_find(opts, name);
> > > >> +if (opt) {
> > > >> +g_free((char *)opt->str);
> > > >
> > > > ...which means the cast is pointless here.
> > > >
> > > > Hmm.  This means that you are giving opt_set() the behavior of 'last
> > > > version wins', by silently overwriting earlier versions.  If I'm
> > > > understanding the existing code correctly, the previous behavior was
> > > > that calling opt_set twice in a row on the same name would inject BOTH
> > > > names into 'opts', but then subsequent lookups on opts would find the
> > > > FIRST hit.  Doesn't that mean this is a semantic change:
> > > >
> > > > qemu -opt key=value1,key=value2
> > > >
> > > > would previously set key to value1, but now sets key to value2.
> > >
> > > I've played with this a bit more, and now am more confused.  QemuOpts is
> > > a LOT to comprehend.
> > >
> > > Pre-patch, 'qemu-system-x86_64 -nodefaults -machine
> > > type=none,type-noone' displayed a help message about unknown machine
> > > type "noone", while swapping type=noone,type=none proceeded with the
> > > 'none' type.  So the last version silently won, which was not the
> > > behavior I had predicted.
> > >
> > > Post-patch, I get a compilation error (so how did you test your patch?):
> > >
> > 
> > Mostly tested ./qemu-img commands where QEMUOptionParameter is used.
> > I really didn't think of test QemuOpts fully, and about the test suite, I
> > have no full
> > knowledge about how many things need to be tested, how many things need to
> > be
> > covered?
> 
> The testsuite should test the QemuOpts implementation, not the current users.

I have just posted a patch introducing a basic QemuOpt testsuite, we can use it
as a start.

Regards...

-- 
Leandro Dorileo



[Qemu-devel] [PATCH] QemuOpt: add unit tests

2014-03-16 Thread Leandro Dorileo
Cover basic aspects and API usage for QemuOpt. The current implementation
covers the API's planed to be changed by Chunyan Liu in his QEMUOptionParameter
replacement/cleanup job.

Other APIs should be covered in future improvements.

Signed-off-by: Leandro Dorileo 
---
 tests/Makefile |   3 +
 tests/test-qemu-opts.c | 309 +
 2 files changed, 312 insertions(+)
 create mode 100644 tests/test-qemu-opts.c

diff --git a/tests/Makefile b/tests/Makefile
index 471b4c8..4814283 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-y += tests/test-vmstate$(EXESUF)
+check-unit-y += tests/test-qemu-opts$(EXESUF)
+gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -272,6 +274,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a 
libqemustub.a
 
 # QTest rules
 
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
new file mode 100644
index 000..61fc6076
--- /dev/null
+++ b/tests/test-qemu-opts.c
@@ -0,0 +1,309 @@
+/*
+ * QemuOpts unit-tests.
+ *
+ * Copyright (C) 2014 Leandro Dorileo 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qapi/error.h"
+#include "qapi/qmp/qstring.h"
+#include "qemu/config-file.h"
+
+#include 
+#include 
+
+static QemuOptsList opts_list_01 = {
+.name = "opts_list_01",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_01.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "str3",
+.type = QEMU_OPT_STRING,
+},{
+.name = "number1",
+.type = QEMU_OPT_NUMBER,
+},
+{ /* end of list */ }
+},
+};
+
+static QemuOptsList opts_list_02 = {
+.name = "opts_list_02",
+.head = QTAILQ_HEAD_INITIALIZER(opts_list_02.head),
+.desc = {
+{
+.name = "str1",
+.type = QEMU_OPT_STRING,
+},{
+.name = "bool1",
+.type = QEMU_OPT_BOOL,
+},{
+.name = "str2",
+.type = QEMU_OPT_STRING,
+},{
+.name = "size1",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
+static void register_opts(void)
+{
+qemu_add_opts(&opts_list_01);
+qemu_add_opts(&opts_list_02);
+}
+
+static void test_find_unknown_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/** should not return anything, we don't known "unknown" option */
+list = qemu_find_opts("unknown");
+g_assert(list == NULL);
+}
+
+static void test_qemu_find_opts(void)
+{
+QemuOptsList *list;
+
+register_opts();
+
+/** we have an rtc option, should return it */
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+}
+
+static void test_qemu_opts_create(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+
+register_opts();
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+
+/** should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/** create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+g_assert(opts != NULL);
+
+/** now we've create the opts, must find it */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts != NULL);
+
+qemu_opts_del(opts);
+
+/** should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+}
+
+static void test_qemu_opt_get(void)
+{
+QemuOptsList *list;
+QemuOpts *opts;
+const char *opt = NULL;
+
+register_opts();
+
+list = qemu_find_opts("opts_list_01");
+g_assert(list != NULL);
+
+/** should not find anything at this point */
+opts = qemu_opts_find(list, NULL);
+g_assert(opts == NULL);
+
+/** create the opts */
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+g_assert(opts != NULL);
+
+/** haven't set anything to str2 yet */
+opt = qemu_opt_get(opts, "str2");
+g_assert(opt == NULL);
+
+q

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

2014-03-11 Thread Leandro Dorileo
Hi,

On Tue, Mar 11, 2014 at 03:26:51PM +0800, Chunyan Liu wrote:
> 2014-03-11 5:21 GMT+08:00 Eric Blake :
> 
> > On 03/10/2014 02:29 PM, Eric Blake wrote:
> >
> > >> +opt = qemu_opt_find(opts, name);
> > >> +if (opt) {
> > >> +g_free((char *)opt->str);
> > >
> > > ...which means the cast is pointless here.
> > >
> > > Hmm.  This means that you are giving opt_set() the behavior of 'last
> > > version wins', by silently overwriting earlier versions.  If I'm
> > > understanding the existing code correctly, the previous behavior was
> > > that calling opt_set twice in a row on the same name would inject BOTH
> > > names into 'opts', but then subsequent lookups on opts would find the
> > > FIRST hit.  Doesn't that mean this is a semantic change:
> > >
> > > qemu -opt key=value1,key=value2
> > >
> > > would previously set key to value1, but now sets key to value2.
> >
> > I've played with this a bit more, and now am more confused.  QemuOpts is
> > a LOT to comprehend.
> >
> > Pre-patch, 'qemu-system-x86_64 -nodefaults -machine
> > type=none,type-noone' displayed a help message about unknown machine
> > type "noone", while swapping type=noone,type=none proceeded with the
> > 'none' type.  So the last version silently won, which was not the
> > behavior I had predicted.
> >
> > Post-patch, I get a compilation error (so how did you test your patch?):
> >
> 
> Mostly tested ./qemu-img commands where QEMUOptionParameter is used.
> I really didn't think of test QemuOpts fully, and about the test suite, I
> have no full
> knowledge about how many things need to be tested, how many things need to
> be
> covered?

The testsuite should test the QemuOpts implementation, not the current users.

Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH RFC 0/2] qemu-arg: general purpose argument parser

2014-03-11 Thread Leandro Dorileo
Hi Kevin,

On Tue, Mar 11, 2014 at 12:06:16PM +0100, Kevin Wolf wrote:
> Am 08.03.2014 um 19:47 hat Leandro Dorileo geschrieben:
> > The following patchset introduces a general purpose argument parser and 
> > migrates
> > qemu-img to make use of it. qemu-img is just the first user of it, if we 
> > see a
> > good feedback here I move forward and migrate all the other possible users.
> 
> I was planning to reply to this in more detail, but it doesn't look like
> I can find the time to do so, so let me just summarise my thoughts
> briefly.

Ok.

> 
> I do like the idea of simplifying qemu-img's argument parsing, but we
> shouldn't make the mistake of introducing another option parsing
> infrastructure and end up with three different coexisting models. If we
> were to introduce a new framework, we must make sure that all code is
> converted to it and QemuOpts can be dropped.

Agreed.

> 
> Now replacing QemuOpts and all of its users is not something that seems
> to be very productive - it works quite well in those places. So I think
> we should rather extend QemuOpts to work for qemu-img as well.

Indeed, I took some time yesterday to take a deeper look at QemuOpt users,
I saw that converting it all to an entirely new framework would be a massive
task and maybe not worth it. Extending QemuOpts to new needs seems to be a more
reasonable thing.

> 
> We would probably need to add a new parser to QemuOpts that parses
> command line options into a QemuOpts, and extend the definition of them
> with a couple of new features that are required there (sub-QemuOpts for
> -o, perhaps enumerations for things like --output=human/json, positional
> parameters).

Ok.

> 
> I see that you also fill the values in (global) variables. The existing
> code that converts QemuOpts into C variables are the QAPI visitors. So I
> could imagine that we define all qemu-img options in a JSON schema like
> qapi-schema.json and generate the struct definitions from it. We would
> then end up with something like this, where the code to create a
> QemuImgCreateOptions struct from the QemuOpts would be QAPI generated:
> 
> void img_create(QemuImgCreateOptions *options, Error **errp);

Using json descriptors was something I considered after sending the patches
and the feedbacks I already got. That's something that would be useful on
cases of generating different outputs from it, like manpages or even
fragments of it, it would be more flexible as far as I can see.

But yeah, I need to take a look at qapi and see how things work.

> 
> Not sure if we really want to go that far, but perhaps it's some food
> for thought.

Yeah, sure.

Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH RFC 0/2] qemu-arg: general purpose argument parser

2014-03-09 Thread Leandro Dorileo
Hi Andreas,


On Sun, Mar 09, 2014 at 05:32:17PM +0100, Andreas Färber wrote:
> Am 08.03.2014 19:47, schrieb Leandro Dorileo:
> > The following patchset introduces a general purpose argument parser and 
> > migrates
> > qemu-img to make use of it. qemu-img is just the first user of it, if we 
> > see a
> > good feedback here I move forward and migrate all the other possible users.
> 
> Why? :) You forgot to describe what's wrong with the current
> infrastructure, how your approach is different and what the benefit is.
>

Indead, I failed miserably on that (describing the problem intended to be 
solved).
The general sense is to unify the argument parsing strategies with some benefits
like help generation. If you see, every qemu binary has its own strategy - where
some (most?) use getopt and the QEMU main binary uses QemuOpt, they lack a 
runtine
help message generation, the sync between the help message and 
expected/implemented
arguments are done manually.

But I'm not sure if we really want/need it, that's the why I sent an early RFC. 
For
me it was just few weekend hours putting all together. :)

I see a good benefit on that - having a simple, clean, consistent and common API
throughout the source code. But again, do we want it? is it worth it?

Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH RFC 2/2] qemu-img: migrate to use qemu-arg

2014-03-09 Thread Leandro Dorileo
On Sun, Mar 09, 2014 at 01:03:12PM +, Peter Maydell wrote:
> On 9 March 2014 12:37, Leandro Dorileo  wrote:
> > Hi Paolo,
> >
> > On Sun, Mar 09, 2014 at 08:30:28AM +0100, Paolo Bonzini wrote:
> >> Il 08/03/2014 19:47, Leandro Dorileo ha scritto:
> >> >Remove the arg parsing implementations using getopt and use qemu-arg.
> >> >Also remove the qemu-img-cmds.hx since it's now generated on building 
> >> >time,
> >> >adapted the build system to generate the .hx file using the qemu-img 
> >> >itself
> >> >using the qemu-arg internal command generate-hx.
> >> >
> >> >Signed-off-by: Leandro Dorileo 
> >>
> >> This makes it much harder to cross-compile QEMU.
> >
> > What's non-portable in this case? what would limit the QEMU cross-compile?
> 
> qemu-img is a binary for the target system; it can't run at all
> on the host system, so you can't run it during compilation.
> You need to keep "things we do during build" completely
> separate from the runtime binaries.

Yep, true.

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH RFC 2/2] qemu-img: migrate to use qemu-arg

2014-03-09 Thread Leandro Dorileo
Hi Paolo,

On Sun, Mar 09, 2014 at 08:30:28AM +0100, Paolo Bonzini wrote:
> Il 08/03/2014 19:47, Leandro Dorileo ha scritto:
> >Remove the arg parsing implementations using getopt and use qemu-arg.
> >Also remove the qemu-img-cmds.hx since it's now generated on building time,
> >adapted the build system to generate the .hx file using the qemu-img itself
> >using the qemu-arg internal command generate-hx.
> >
> >Signed-off-by: Leandro Dorileo 
> 
> This makes it much harder to cross-compile QEMU.

What's non-portable in this case? what would limit the QEMU cross-compile?

>  Also, I wonder how hard it
> would be to apply the same approach to the main QEMU binary which already
> uses QemuOpts for its more complex arguments;

Yeah, you're right, QEMU binary is much more complex, In that case I think we
should put QemuOpts and QemuArg together or so, I still need to better 
understand
the current vl.c + QemuOpt source code to come up with a good solution.

> for sure you risk that
> accumulating multiple layers of abstractions makes the code even harder to
> read than it is now.

The idea is to keep things simple not the other way round. I think it's possible
to accommodate both cases without imposing more complexity.


Regards...

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH RFC 0/2] qemu-arg: general purpose argument parser

2014-03-08 Thread Leandro Dorileo
Hi Peter,

On Sat, Mar 08, 2014 at 06:55:50PM +, Peter Maydell wrote:
> On 8 March 2014 18:47, Leandro Dorileo  wrote:
> > The following patchset introduces a general purpose argument parser and 
> > migrates
> > qemu-img to make use of it. qemu-img is just the first user of it, if we 
> > see a
> > good feedback here I move forward and migrate all the other possible users.
> 
> Can you describe what the QEMU-specific features are that
> mean we must roll our own argument-parsing infrastructure
> rather than using (say) the glib option parsing routines?


I don't think GOption will do the output I want and think to be the ideal for
qemu or specially to qemu-img.

GOption knows nothing about command, since qemu-img was my first target I
wanted something to handle its command schema. GOption will not show the users
the list of available commands neither show commands specific options, I wanted
the user to run qemu-img create -h and show the create command arguments 
(similar
to git output). GOption will not do that by default, of course we can wrap that
and have something similar.

GOption will not be able to list commands and their arguments so we can generate
the .hx file (see patch 02 in my series) or maybe the texi output and keep the
sync between the implemented commands, arguments and the textinfo stuffs.
GOption also doesn't know about the "cumulative" stuff - well I agree this last
one is not somethig to justify qemu-arg per se.

The command callbacks flow is also something GOption will not give us for free,
we would still need to know ourself about the available commands and their
callees.

As I said, my first target was qemu-img, but I ended up writing something more
generic to be used elsewhere.

Of course I could wrap GOption or getopt and handle all the corner cases but
parsing the arguments myself gave me more flexibility.

Regards...

-- 
Leandro Dorileo



[Qemu-devel] [PATCH RFC 1/2] qemu-arg: introduce a general purpose argument parser

2014-03-08 Thread Leandro Dorileo
qemu-arg defines a standardized API for argument parsing, help displaying and
texi generation/sync.

The implementation supports command + arguments form (i.e qemu-img requirements)
and a more general simple arguments parsing. So we can parse:

$ prog  --arg1 --arg2
$ prog --arg1 --arg2

We support the following:
   + basic arguments validation (i.e required arguments and required values);
   + basic arguments transformations (integer, bool values)
   + repeated/"cumullated" arguments (i.e -o opt1=val -o opt2=val2 will result 
the
 string "opt1=val,opt2=val2")
   + positional arguments;
 + identified positional for fixed/defined numbers of expected positional 
args;
 + listed positional for N expected positional args;
   + help messages generation;
   + texi generation;
   + default value setting;
   + mutually exclusive arguments;
   + display and parsing decorated arguments ("--argument value" and 
"--argument=value"
  are valid)

Signed-off-by: Leandro Dorileo 
---
 include/qemu/qemu-arg.h | 287 
 util/Makefile.objs  |   1 +
 util/qemu-arg.c | 887 
 3 files changed, 1175 insertions(+)
 create mode 100644 include/qemu/qemu-arg.h
 create mode 100644 util/qemu-arg.c

diff --git a/include/qemu/qemu-arg.h b/include/qemu/qemu-arg.h
new file mode 100644
index 000..c8d8fb4
--- /dev/null
+++ b/include/qemu/qemu-arg.h
@@ -0,0 +1,287 @@
+/*
+ * QEMU argument helper
+ *
+ * Copyright (c) 2014 Leandro Dorileo 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_ARG_H_
+#define _QEMU_ARG_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef struct _QemuArgContext QemuArgContext;
+typedef struct _QemuArgCommand QemuArgCommand;
+
+typedef enum _QemuArgOptType {
+QEMU_ARG_OPT_TYPE_INT,
+QEMU_ARG_OPT_TYPE_BOOL,
+QEMU_ARG_OPT_TYPE_STR,
+QEMU_ARG_OPT_TYPE_POSITIONAL,
+QEMU_ARG_OPT_TYPE_POSITIONAL_LIST,
+QEMU_ARG_OPT_TYPE_DEPRECATED,
+QEMU_ARG_OPT_TYPE_GROUP,
+QEMU_ARG_OPT_TYPE_SENTINEL,
+} QemuArgOptType;
+
+typedef struct _QemuArgIntValue {
+/** default value */
+int def_val;
+
+/** user value pointer */
+int *value;
+} QemuArgIntValue;
+
+typedef struct _QemuArgBoolValue {
+/** default value */
+bool def_val;
+
+/** user value pointer */
+bool *value;
+} QemuArgBoolValue;
+
+typedef struct _QemuArgStrValue {
+/** default value */
+char *def_val;
+
+/** user value pointer */
+char **value;
+} QemuArgStrValue;
+
+typedef struct _QemuArgStrListValue {
+/** default value */
+char **def_val;
+
+/** user value pointer */
+char ***value;
+
+/** list elements counter */
+int list_cnt;
+} QemuArgStrListValue;
+
+typedef enum _QemuArgOptFlag {
+ARG_FLAG_NONE   = 0,
+
+/** provide many arguments instances, their value are concatenated in a
+comman separated string */
+ARG_FLAG_CUMULATE   = 1 << 0,
+
+/** the argument is required */
+ARG_FLAG_REQUIRED   = 1 << 1,
+
+/** the argument requires a value like --foo bar where --foo requires bar 
*/
+ARG_FLAG_REQ_VALUE  = 1 << 2,
+} QemuArgOptFlag;
+
+typedef struct _QemuArgOpt {
+/** argument type, bool, int, str, etc @see QemuArgOptType */
+QemuArgOptType type;
+
+/** the argument's short name i.e -c */
+const char short_name;
+
+/** argument's long name i.e --cache */
+const char *long_name;
+
+/** argument's description, used to display a hint about the argument's
+value i.e -f fmt where fmt is the arg's desc */
+const char *desc;
+
+/** help message, describes the argument */
+const char *help;
+
+/** some behavior flags @see QemuArgOptFlag for possible modifiers */
+int flags;
+
+/** indicates the argument was set, for bo

[Qemu-devel] [PATCH RFC 0/2] qemu-arg: general purpose argument parser

2014-03-08 Thread Leandro Dorileo
The following patchset introduces a general purpose argument parser and migrates
qemu-img to make use of it. qemu-img is just the first user of it, if we see a
good feedback here I move forward and migrate all the other possible users.

Leandro Dorileo (2):
  qemu-arg: introduce a general purpose argument parser
  qemu-img: migrate to use qemu-arg

 .gitignore  |1 +
 Makefile|   12 +-
 include/qemu/qemu-arg.h |  287 
 qemu-img-cmds.hx|   77 ---
 qemu-img-descs.h|  128 +
 qemu-img.c  | 1184 ---
 util/Makefile.objs  |1 +
 util/qemu-arg.c |  887 +++
 8 files changed, 1706 insertions(+), 871 deletions(-)
 create mode 100644 include/qemu/qemu-arg.h
 delete mode 100644 qemu-img-cmds.hx
 create mode 100644 qemu-img-descs.h
 create mode 100644 util/qemu-arg.c

-- 
1.9.0




  1   2   >