All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
@ 2014-03-10  7:31 Chunyan Liu
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc Chunyan Liu
                   ` (34 more replies)
  0 siblings, 35 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
  * update verison info in patch 2/25
  * others are not changed except for rebase

Chunyan Liu (25):
  add def_value_str to QemuOptDesc
  qapi: output def_value_str when query command line options
  improve some functions in qemu-option.c
  improve assertion in qemu_opt_get functions
  add some QemuOpts functions for replace work
  add convert functions between QEMUOptionParameter to QemuOpts
  change block layer to support both QemuOpts and QEMUOptionParamter
  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
  vmdk.c: replace QEMUOptionParameter with QemuOpts
  vpc.c: replace QEMUOptionParameter with QemuOpts
  vhdx.c: replace QEMUOptionParameter with QemuOpts
  vvfat.c: replace QEMUOptionParameter with QemuOpts
  cleanup QEMUOptionParameter

 block.c                   |  96 ++++----
 block/cow.c               |  52 ++---
 block/gluster.c           |  73 +++---
 block/iscsi.c             |  29 ++-
 block/qcow.c              |  72 +++---
 block/qcow2.c             | 325 +++++++++++++-------------
 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               |  70 +++---
 block/vhdx.c              |  97 ++++----
 block/vhdx.h              |   1 +
 block/vmdk.c              | 121 +++++-----
 block/vpc.c               |  60 ++---
 block/vvfat.c             |  10 +-
 include/block/block.h     |   7 +-
 include/block/block_int.h |   9 +-
 include/qemu/option.h     |  56 +----
 include/qemu/option_int.h |   4 +-
 qapi-schema.json          |   6 +-
 qemu-img.c                |  89 ++++---
 qmp-commands.hx           |   2 +
 util/qemu-config.c        |   4 +
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------
 29 files changed, 1060 insertions(+), 1125 deletions(-)

-- 
1.7.12.4

^ permalink raw reply	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-10 19:52   ` Eric Blake
  2014-03-11 13:29   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options Chunyan Liu
                   ` (33 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

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 <address@hidden>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c    | 59 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 52 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 9d898af..65d1c22 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,9 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/option_int.h"
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+                                            const char *name);
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -556,6 +559,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 +585,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 +600,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 +616,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 +921,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 : "<noid>");
-    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");
-    return 0;
 }
 
 static int opts_do_parse(QemuOpts *opts, const char *params,
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-10 19:57   ` Eric Blake
  2014-03-11  6:14   ` Hu Tao
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c Chunyan Liu
                   ` (32 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

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

Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 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 6c381b7..f37834e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4059,12 +4059,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 d982cd6..94e8f9f 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2856,6 +2856,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

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc Chunyan Liu
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-10 20:29   ` Eric Blake
  2014-03-17 19:58   ` Leandro Dorileo
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions Chunyan Liu
                   ` (31 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

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 <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 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;
+    }
+
+    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 = opts;
     opt->value.boolean = !!val;
@@ -766,16 +807,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t 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.uint = val;
+        opt->str = g_strdup_printf("%" PRId64, val);
+        return 0;
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt->desc = desc;
     opt->name = g_strdup(name);
     opt->opts = opts;
     opt->value.uint = val;
@@ -910,6 +959,10 @@ void qemu_opts_del(QemuOpts *opts)
 {
     QemuOpt *opt;
 
+    if (opts == NULL) {
+        return;
+    }
+
     for (;;) {
         opt = QTAILQ_FIRST(&opts->head);
         if (opt == NULL)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (2 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-10 21:44   ` Eric Blake
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work Chunyan Liu
                   ` (30 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is true, it
won't report error, but can still alloc an opt for the option and save it.
However, after that, when doing qemu_opt_get, this option could be found in opts
but opt->desc is NULL. This is correct, should not be treated as error.

This patch would fix vvfat issue after changing to QemuOpts.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 util/qemu-option.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index c7639e8..df79235 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_BOOL);
+    }
     return opt->value.boolean;
 }
 
@@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_NUMBER);
+    }
     return opt->value.uint;
 }
 
@@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_SIZE);
+    }
     return opt->value.uint;
 }
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (3 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-10 23:28   ` Eric Blake
  2014-03-17 19:35   ` Leandro Dorileo
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
                   ` (29 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Add some qemu_opt functions to replace the same functionality of
QEMUOptionParameter handling.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 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);
 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 ? opt->str : NULL;
 }
 
+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 = g_strdup(opt->str);
+    qemu_opt_del(opt);
+    return str;
+}
+
 bool qemu_opt_has_help_opt(QemuOpts *opts)
 {
     QemuOpt *opt;
@@ -586,9 +678,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
     return false;
 }
 
-bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,
+                               bool defval, bool del)
 {
     QemuOpt *opt;
+    bool ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -599,19 +693,35 @@ 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);
+            parse_option_bool(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_BOOL);
     }
-    return opt->value.boolean;
+    ret = opt->value.boolean;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
 }
 
-uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, false);
+}
+
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, true);
+}
+
+static uint64_t _qemu_opt_get_number(QemuOpts *opts, const char *name,
+                                     uint64_t defval, bool del)
 {
     QemuOpt *opt;
+    uint64_t ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -622,20 +732,36 @@ 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);
+            parse_option_number(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_NUMBER);
     }
-    return opt->value.uint;
+    ret = opt->value.uint;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
 }
 
-uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
+uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
+{
+    return _qemu_opt_get_number(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval)
+{
+    return _qemu_opt_get_number(opts, name, defval, true);
+}
+
+static uint64_t _qemu_opt_get_size(QemuOpts *opts, const char *name,
+                                   uint64_t defval, bool del)
 {
     QemuOpt *opt;
+    uint64_t ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -645,14 +771,29 @@ 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);
+            parse_option_size(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_SIZE);
     }
-    return opt->value.uint;
+    ret = opt->value.uint;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
+}
+
+uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
+{
+    return _qemu_opt_get_size(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval)
+{
+    return _qemu_opt_get_size(opts, name, defval, true);
 }
 
 static void qemu_opt_parse(QemuOpt *opt, Error **errp)
@@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
     loc_pop(&loc);
     return rc;
 }
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+    if (!list) {
+        return;
+    }
+
+    g_free(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 : "");
+    }
+}
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (4 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11  4:46   ` Eric Blake
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
                   ` (28 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

Add two temp convert functions between QEMUOptionParameter to QemuOpts, so that
next patch can use it. It will simplify next patch for easier review.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |   2 +
 util/qemu-option.c    | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index de4912a..a6aca59 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -170,4 +170,6 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
 QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
 void qemu_opts_free(QemuOptsList *list);
 void qemu_opts_print_help(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 2c450e0..e05b126 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1464,3 +1464,108 @@ void qemu_opts_print_help(QemuOptsList *list)
                list->desc[i].help : "");
     }
 }
+
+/* convert QEMUOptionParameter 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);
+    opts->desc[i].name = NULL;
+
+    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 = 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++;
+        opts->desc[i].name = NULL;
+    }
+
+    return opts;
+}
+
+QEMUOptionParameter *opts_to_params(QemuOpts *opts)
+{
+    QEMUOptionParameter *dest = NULL;
+    QemuOptDesc *desc;
+    size_t num_opts, i = 0;
+    const char *tmp;
+
+    if (!opts || !opts->list || !opts->list->desc) {
+        return NULL;
+    }
+
+    num_opts = count_opts_list(opts->list);
+    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
+    dest[i].name = NULL;
+
+    desc = opts->list->desc;
+    while (desc && desc->name) {
+        dest[i].name = g_strdup(desc->name);
+        dest[i].help = g_strdup(desc->help);
+        switch (desc->type) {
+        case QEMU_OPT_STRING:
+            dest[i].type = OPT_STRING;
+            tmp = qemu_opt_get(opts, desc->name);
+            dest[i].value.s = g_strdup(tmp);
+            break;
+
+        case QEMU_OPT_BOOL:
+            dest[i].type = OPT_FLAG;
+            dest[i].value.n = qemu_opt_get_bool(opts, desc->name, 0) ? 1 : 0;
+            break;
+
+        case QEMU_OPT_NUMBER:
+            dest[i].type = OPT_NUMBER;
+            dest[i].value.n = qemu_opt_get_number(opts, desc->name, 0);
+            break;
+
+        case QEMU_OPT_SIZE:
+            dest[i].type = OPT_SIZE;
+            dest[i].value.n = qemu_opt_get_size(opts, desc->name, 0);
+            break;
+        }
+
+        i++;
+        desc++;
+        dest[i].name = NULL;
+    }
+
+    return dest;
+}
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (5 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11  4:34   ` Eric Blake
  2014-03-11 16:54   ` Eric Blake
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (27 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

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 <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block.c                   | 121 ++++++++++++++++++++++++++++++----------------
 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 |   8 ++-
 qemu-img.c                | 120 +++++++++++++++++++++++++++++----------------
 12 files changed, 177 insertions(+), 97 deletions(-)

diff --git a/block.c b/block.c
index f1ef4b0..d9b1da3 100644
--- a/block.c
+++ b/block.c
@@ -408,6 +408,7 @@ typedef struct CreateCo {
     BlockDriver *drv;
     char *filename;
     QEMUOptionParameter *options;
+    QemuOpts *opts;
     int ret;
     Error *err;
 } CreateCo;
@@ -420,7 +421,11 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
     CreateCo *cco = opaque;
     assert(cco->drv);
 
-    ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+    if (cco->drv->bdrv_create2) {
+        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+    } else {
+        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+    }
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -428,7 +433,7 @@ 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;
 
@@ -437,11 +442,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;
@@ -473,7 +479,7 @@ out:
 }
 
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp)
+                     QemuOpts *opts, Error **errp)
 {
     BlockDriver *drv;
     Error *local_err = NULL;
@@ -485,7 +491,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
         return -ENOENT;
     }
 
-    ret = bdrv_create(drv, filename, options, &local_err);
+    ret = bdrv_create(drv, filename, options, opts, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -1248,7 +1254,8 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QEMUOptionParameter *create_options;
+        QEMUOptionParameter *create_options = NULL;
+        QemuOpts *opts = NULL;
         QDict *snapshot_options;
 
         /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1281,21 @@ 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);
+        if (bdrv_qcow2->bdrv_create2) {
+            opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
+                                    &error_abort);
+            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
+        } else {
+            create_options =
+                parse_option_parameters("", bdrv_qcow2->create_options, NULL);
+            set_option_parameter_int(create_options, BLOCK_OPT_SIZE,
+                                     total_size);
+        }
 
-        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
+        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
+                          &local_err);
         free_option_parameters(create_options);
+        qemu_opts_del(opts);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create temporary overlay "
                              "'%s': %s", tmp_filename,
@@ -5229,7 +5244,10 @@ void bdrv_img_create(const char *filename, const char *fmt,
                      Error **errp, bool quiet)
 {
     QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *backing_fmt, *backing_file, *size;
+    QemuOptsList *create_opts = NULL;
+    QemuOpts *opts = NULL;
+    const char *backing_fmt, *backing_file;
+    int64_t size;
     BlockDriver *drv, *proto_drv;
     BlockDriver *backing_drv = NULL;
     Error *local_err = NULL;
@@ -5248,28 +5266,31 @@ 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);
+    if (drv->bdrv_create2) {
+        create_opts = qemu_opts_append(create_opts, drv->create_opts);
+        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+    } else {
+        create_options = append_option_parameters(create_options,
+                                                  drv->create_options);
+        create_options = append_option_parameters(create_options,
+                                                  proto_drv->create_options);
+        create_opts = params_to_opts(create_options);
+    }
 
     /* Create parameter list with default values */
-    param = parse_option_parameters("", create_options, param);
-
-    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);
 
     /* Parse -o options */
     if (options) {
-        param = parse_option_parameters(options, create_options, param);
-        if (param == NULL) {
+        if (qemu_opts_do_parse(opts, options, NULL) != 0) {
             error_setg(errp, "Invalid options for file format '%s'.", fmt);
             goto out;
         }
     }
 
     if (base_filename) {
-        if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
-                                 base_filename)) {
+        if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) {
             error_setg(errp, "Backing file not supported for file format '%s'",
                        fmt);
             goto out;
@@ -5277,37 +5298,37 @@ void bdrv_img_create(const char *filename, const char *fmt,
     }
 
     if (base_fmt) {
-        if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+        if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) {
             error_setg(errp, "Backing file format not supported for file "
                              "format '%s'", fmt);
             goto out;
         }
     }
 
-    backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
-    if (backing_file && backing_file->value.s) {
-        if (!strcmp(filename, backing_file->value.s)) {
+    backing_file = qemu_opt_get(opts, BLOCK_OPT_BACKING_FILE);
+    if (backing_file) {
+        if (!strcmp(filename, backing_file)) {
             error_setg(errp, "Error: Trying to create an image with the "
                              "same filename as the backing file");
             goto out;
         }
     }
 
-    backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
-    if (backing_fmt && backing_fmt->value.s) {
-        backing_drv = bdrv_find_format(backing_fmt->value.s);
+    backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT);
+    if (backing_fmt) {
+        backing_drv = bdrv_find_format(backing_fmt);
         if (!backing_drv) {
             error_setg(errp, "Unknown backing file format '%s'",
-                       backing_fmt->value.s);
+                       backing_fmt);
             goto out;
         }
     }
 
     // The size for the image must always be specified, with one exception:
     // If we are using a backing file, we can obtain the size from there
-    size = get_option_parameter(param, BLOCK_OPT_SIZE);
-    if (size && size->value.n == -1) {
-        if (backing_file && backing_file->value.s) {
+    size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0);
+    if (size == -1) {
+        if (backing_file) {
             BlockDriverState *bs;
             uint64_t size;
             char buf[32];
@@ -5318,11 +5339,11 @@ void bdrv_img_create(const char *filename, const char *fmt,
                 flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
 
             bs = NULL;
-            ret = bdrv_open(&bs, backing_file->value.s, NULL, NULL, back_flags,
+            ret = bdrv_open(&bs, backing_file, NULL, NULL, back_flags,
                             backing_drv, &local_err);
             if (ret < 0) {
                 error_setg_errno(errp, -ret, "Could not open '%s': %s",
-                                 backing_file->value.s,
+                                 backing_file,
                                  error_get_pretty(local_err));
                 error_free(local_err);
                 local_err = NULL;
@@ -5332,7 +5353,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
             size *= 512;
 
             snprintf(buf, sizeof(buf), "%" PRId64, size);
-            set_option_parameter(param, BLOCK_OPT_SIZE, buf);
+            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);
 
             bdrv_unref(bs);
         } else {
@@ -5343,16 +5364,23 @@ void bdrv_img_create(const char *filename, const char *fmt,
 
     if (!quiet) {
         printf("Formatting '%s', fmt=%s ", filename, fmt);
-        print_option_parameters(param);
+        qemu_opts_print(opts);
         puts("");
     }
-    ret = bdrv_create(drv, filename, param, &local_err);
+
+    if (drv->bdrv_create2) {
+        ret = bdrv_create(drv, filename, NULL, opts, &local_err);
+    } else {
+        param = opts_to_params(opts);
+        ret = bdrv_create(drv, filename, param, NULL, &local_err);
+    }
+
     if (ret == -EFBIG) {
         /* This is generally a better message than whatever the driver would
          * deliver (especially because of the cluster_size_hint), since that
          * is most probably not much different from "image too large". */
         const char *cluster_size_hint = "";
-        if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
+        if (qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZE, 0)) {
             cluster_size_hint = " (try using a larger cluster size)";
         }
         error_setg(errp, "The image size is too large for file format '%s'"
@@ -5365,6 +5393,8 @@ out:
     free_option_parameters(create_options);
     free_option_parameters(param);
 
+    qemu_opts_del(opts);
+    qemu_opts_free(create_opts);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -5382,12 +5412,17 @@ void bdrv_add_before_write_notifier(BlockDriverState *bs,
     notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
 }
 
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
+                       QemuOpts *opts)
 {
-    if (bs->drv->bdrv_amend_options == NULL) {
+    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
         return -ENOTSUP;
     }
-    return bs->drv->bdrv_amend_options(bs, options);
+    if (bs->drv->bdrv_amend_options2) {
+        return bs->drv->bdrv_amend_options2(bs, opts);
+    } else {
+        return bs->drv->bdrv_amend_options(bs, options);
+    }
 }
 
 /* Used to recurse on single child block filters.
diff --git a/block/cow.c b/block/cow.c
index 30deb88..26cf4a5 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -345,7 +345,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
         options++;
     }
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
diff --git a/block/qcow.c b/block/qcow.c
index 1e128be..153b9bd 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -687,7 +687,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
         options++;
     }
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
diff --git a/block/qcow2.c b/block/qcow2.c
index cfe80be..dcd43bc 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1487,7 +1487,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
diff --git a/block/qed.c b/block/qed.c
index 8802ad3..db27f36 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -566,7 +566,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
     int ret = 0;
     BlockDriverState *bs;
 
-    ret = bdrv_create_file(filename, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 01ea692..9ae5fc2 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -145,7 +145,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
diff --git a/block/vhdx.c b/block/vhdx.c
index 5390ba6..d8afb42 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1788,7 +1788,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
                                                     block_size;
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
diff --git a/block/vmdk.c b/block/vmdk.c
index b69988d..d87c8f6 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1525,7 +1525,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
     uint32_t *gd_buf = NULL;
     int gd_buf_size;
 
-    ret = bdrv_create_file(filename, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
@@ -1865,7 +1865,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     if (!split && !flat) {
         desc_offset = 0x200;
     } else {
-        ret = bdrv_create_file(filename, options, &local_err);
+        ret = bdrv_create_file(filename, options, NULL, &local_err);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create image file");
             goto exit;
diff --git a/block/vvfat.c b/block/vvfat.c
index f966ea5..ee32b3c 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2926,7 +2926,7 @@ static int enable_write_target(BDRVVVFATState *s)
     set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
     set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
 
-    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
diff --git a/include/block/block.h b/include/block/block.h
index 780f48b..c482204 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -177,9 +177,9 @@ BlockDriver *bdrv_find_format(const char *format_name);
 BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
                                           bool readonly);
 int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, Error **errp);
+    QEMUOptionParameter *options, QemuOpts *opts, Error **errp);
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp);
+                     QemuOpts *opts, Error **errp);
 BlockDriverState *bdrv_new(const char *device_name);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -283,7 +283,8 @@ typedef enum {
 
 int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
-int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
+int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options,
+                       QemuOpts *opts);
 
 /* external snapshots */
 
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 0bcf1c9..e4e832f 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -118,6 +118,8 @@ struct BlockDriver {
     void (*bdrv_rebind)(BlockDriverState *bs);
     int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
                        Error **errp);
+    /* FIXME: will remove the duplicate and rename back to bdrv_create later */
+    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error **errp);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -217,7 +219,7 @@ struct BlockDriver {
 
     /* List of options for creating images, terminated by name == NULL */
     QEMUOptionParameter *create_options;
-
+    QemuOptsList *create_opts;
 
     /*
      * Returns 0 for completed check, -errno for internal errors.
@@ -228,6 +230,10 @@ struct BlockDriver {
 
     int (*bdrv_amend_options)(BlockDriverState *bs,
         QEMUOptionParameter *options);
+    /* FIXME: will remove the duplicate and rename back to
+     * bdrv_amend_options later
+     */
+    int (*bdrv_amend_options2)(BlockDriverState *bs, QemuOpts *opts);
 
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
diff --git a/qemu-img.c b/qemu-img.c
index 2e40cc1..c548741 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -236,6 +236,7 @@ static int print_block_option_help(const char *filename, const char *fmt)
 {
     BlockDriver *drv, *proto_drv;
     QEMUOptionParameter *create_options = NULL;
+    QemuOptsList *create_opts = NULL;
 
     /* Find driver and parse its options */
     drv = bdrv_find_format(fmt);
@@ -244,21 +245,34 @@ 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 (drv->create_opts) {
+        create_opts = qemu_opts_append(create_opts, drv->create_opts);
+    } else {
+        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);
+        if (drv->create_opts) {
+            create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+        } else {
+            create_options =
+                append_option_parameters(create_options,
+                                         proto_drv->create_options);
+        }
     }
 
-    print_option_help(create_options);
+    if (drv->create_opts) {
+        qemu_opts_print_help(create_opts);
+    } else {
+        print_option_help(create_options);
+    }
     free_option_parameters(create_options);
+    qemu_opts_free(create_opts);
     return 0;
 }
 
@@ -311,19 +325,19 @@ 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)
 {
     if (base_filename) {
-        if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) {
+        if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) {
             error_report("Backing file not supported for file format '%s'",
                          fmt);
             return -1;
         }
     }
     if (base_fmt) {
-        if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+        if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) {
             error_report("Backing file format not supported for file "
                          "format '%s'", fmt);
             return -1;
@@ -1154,7 +1168,9 @@ static int img_convert(int argc, char **argv)
     const uint8_t *buf1;
     BlockDriverInfo bdi;
     QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *out_baseimg_param;
+    QemuOpts *opts = NULL;
+    QemuOptsList *create_opts = NULL;
+    const char *out_baseimg_param;
     char *options = NULL;
     const char *snapshot_name = NULL;
     int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
@@ -1340,40 +1356,42 @@ 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);
-
-    if (options) {
-        param = parse_option_parameters(options, create_options, param);
-        if (param == NULL) {
-            error_report("Invalid options for file format '%s'.", out_fmt);
-            ret = -1;
-            goto out;
-        }
+    if (drv->bdrv_create2) {
+        create_opts = qemu_opts_append(create_opts, drv->create_opts);
+        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
     } else {
-        param = parse_option_parameters("", create_options, param);
+        create_options = append_option_parameters(create_options,
+                                                  drv->create_options);
+        create_options = append_option_parameters(create_options,
+                                                  proto_drv->create_options);
+        create_opts = params_to_opts(create_options);
+    }
+
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    if (options && qemu_opts_do_parse(opts, options, NULL)) {
+        error_report("Invalid options for file format '%s'.", out_fmt);
+        ret = -1;
+        goto out;
     }
 
-    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");
@@ -1381,15 +1399,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");
@@ -1400,7 +1418,12 @@ static int img_convert(int argc, char **argv)
 
     if (!skip_create) {
         /* Create the new image */
-        ret = bdrv_create(drv, out_filename, param, &local_err);
+        if (drv->bdrv_create2) {
+            ret = bdrv_create(drv, out_filename, NULL, opts, &local_err);
+        } else {
+            param = opts_to_params(opts);
+            ret = bdrv_create(drv, out_filename, param, NULL, &local_err);
+        }
         if (ret < 0) {
             error_report("%s: error while converting %s: %s",
                          out_filename, out_fmt, error_get_pretty(local_err));
@@ -1666,6 +1689,8 @@ out:
     qemu_progress_end();
     free_option_parameters(create_options);
     free_option_parameters(param);
+    qemu_opts_free(create_opts);
+    qemu_opts_del(opts);
     qemu_vfree(buf);
     if (sn_opts) {
         qemu_opts_del(sn_opts);
@@ -2652,6 +2677,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;
@@ -2721,17 +2748,26 @@ 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) {
+    if (bs->drv->bdrv_amend_options2) {
+        create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
+    } else {
+        create_options = append_option_parameters(create_options,
+                                                  bs->drv->create_options);
+        create_opts = params_to_opts(create_options);
+    }
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    if (options && qemu_opts_do_parse(opts, options, NULL)) {
         error_report("Invalid options for file format '%s'", fmt);
         ret = -1;
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, options_param);
+    if (bs->drv->bdrv_amend_options2) {
+        ret = bdrv_amend_options(bs, NULL, opts);
+    } else {
+        options_param = opts_to_params(opts);
+        ret = bdrv_amend_options(bs, options_param, NULL);
+    }
     if (ret < 0) {
         error_report("Error while amending options: %s", strerror(-ret));
         goto out;
@@ -2743,6 +2779,8 @@ out:
     }
     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.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (6 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:12   ` Stefan Hajnoczi
  2014-03-11 15:28   ` Eric Blake
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 09/25] gluster.c: " Chunyan Liu
                   ` (26 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 26cf4a5..4085201 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -324,31 +324,24 @@ 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 *opts, Error **errp)
 {
     struct cow_header_v2 cow_header;
     struct stat st;
     int64_t image_sectors = 0;
-    const char *image_filename = NULL;
+    char *image_filename = NULL;
     Error *local_err = NULL;
     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_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+    image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
 
-    ret = bdrv_create_file(filename, options, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
-        return ret;
+        goto exit;
     }
 
     cow_bs = NULL;
@@ -356,7 +349,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
                     BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
-        return ret;
+        goto exit;
     }
 
     memset(&cow_header, 0, sizeof(cow_header));
@@ -389,22 +382,27 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
     }
 
 exit:
+    g_free(image_filename);
     bdrv_unref(cow_bs);
     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"
-    },
-    { NULL }
+static QemuOptsList cow_create_opts = {
+    .name = "cow-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.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"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_cow = {
@@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
     .bdrv_probe     = cow_probe,
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,
-    .bdrv_create    = cow_create,
+    .bdrv_create2   = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
     .bdrv_write             = cow_co_write,
     .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-    .create_options = cow_create_options,
+    .create_opts       = &cow_create_opts,
 };
 
 static void bdrv_cow_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 09/25] gluster.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (7 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:15   ` Stefan Hajnoczi
  2014-03-11 16:58   ` Eric Blake
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 10/25] iscsi.c: " Chunyan Liu
                   ` (25 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/gluster.c | 81 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 39 deletions(-)

diff --git a/block/gluster.c b/block/gluster.c
index a44d612..bd72d8d 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -471,13 +471,14 @@ 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)
+                               QemuOpts *opts, Error **errp)
 {
     struct glfs *glfs;
     struct glfs_fd *fd;
     int ret = 0;
     int prealloc = 0;
     int64_t total_size = 0;
+    char *tmp;
     GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
 
     glfs = qemu_gluster_init(gconf, filename, errp);
@@ -486,24 +487,21 @@ 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;
-            }
-        }
-        options++;
+    total_size =
+        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+
+    tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+    if (!tmp || !strcmp(tmp, "off")) {
+        prealloc = 0;
+    } else if (!strcmp(tmp, "full") &&
+               gluster_supports_zerofill()) {
+        prealloc = 1;
+    } else {
+        error_setg(errp, "Invalid preallocation mode: '%s'"
+            " or GlusterFS doesn't support zerofill API",
+            tmp);
+        ret = -EINVAL;
+        goto out;
     }
 
     fd = glfs_creat(glfs, gconf->image,
@@ -525,6 +523,7 @@ static int qemu_gluster_create(const char *filename,
         }
     }
 out:
+    g_free(tmp);
     qemu_gluster_gconf_free(gconf);
     if (glfs) {
         glfs_fini(glfs);
@@ -688,18 +687,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)"
-    },
-    { NULL }
+static QemuOptsList qemu_gluster_create_opts = {
+    .name = "qemu-gluster-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        {
+            .name = BLOCK_OPT_PREALLOC,
+            .type = OPT_STRING,
+            .help = "Preallocation mode (allowed values: off, full)"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_gluster = {
@@ -712,7 +715,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -726,7 +729,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_opts                  = &qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_tcp = {
@@ -739,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -753,7 +756,7 @@ static BlockDriver bdrv_gluster_tcp = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
     .bdrv_co_write_zeroes         = qemu_gluster_co_write_zeroes,
 #endif
-    .create_options               = qemu_gluster_create_options,
+    .create_opts                  = &qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_unix = {
@@ -766,7 +769,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -780,7 +783,7 @@ static BlockDriver bdrv_gluster_unix = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
     .bdrv_co_write_zeroes         = qemu_gluster_co_write_zeroes,
 #endif
-    .create_options               = qemu_gluster_create_options,
+    .create_opts                  = &qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_rdma = {
@@ -793,7 +796,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -807,7 +810,7 @@ static BlockDriver bdrv_gluster_rdma = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
     .bdrv_co_write_zeroes         = qemu_gluster_co_write_zeroes,
 #endif
-    .create_options               = qemu_gluster_create_options,
+    .create_opts                  = &qemu_gluster_create_opts,
 };
 
 static void bdrv_gluster_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 10/25] iscsi.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (8 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 09/25] gluster.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:17   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 11/25] qcow.c: " Chunyan Liu
                   ` (24 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/iscsi.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index b490e98..4379d14 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1394,13 +1394,8 @@ 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_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
     bs->opaque = g_malloc0(sizeof(struct IscsiLun));
     iscsilun = bs->opaque;
 
@@ -1451,13 +1446,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"
-    },
-    { NULL }
+static QemuOptsList iscsi_create_opts = {
+    .name = "iscsi-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1468,7 @@ static BlockDriver bdrv_iscsi = {
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
     .bdrv_create     = iscsi_create,
-    .create_options  = iscsi_create_options,
+    .create_opts     = &iscsi_create_opts,
     .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
     .bdrv_getlength  = iscsi_getlength,
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 11/25] qcow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (9 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 10/25] iscsi.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:18   ` Stefan Hajnoczi
  2014-03-11 17:05   ` Eric Blake
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 12/25] qcow2.c: " Chunyan Liu
                   ` (23 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/qcow.c | 72 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 153b9bd..374e6df 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -662,35 +662,29 @@ 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 *opts, 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;
+    char *backing_file = NULL;
     int 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_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+        flags |= BLOCK_FLAG_ENCRYPT;
     }
 
-    ret = bdrv_create_file(filename, options, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
-        return ret;
+        goto cleanup;
     }
 
     qcow_bs = NULL;
@@ -698,7 +692,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
                     BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
-        return ret;
+        goto cleanup;
     }
 
     ret = bdrv_truncate(qcow_bs, 0);
@@ -769,6 +763,8 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
     ret = 0;
 exit:
     bdrv_unref(qcow_bs);
+cleanup:
+    g_free(backing_file);
     return ret;
 }
 
@@ -881,24 +877,28 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
 
-
-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"
-    },
-    { NULL }
+static QemuOptsList qcow_create_opts = {
+    .name = "qcow-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.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_BOOL,
+            .help = "Encrypt the image",
+            .def_value_str = "off"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_qcow = {
@@ -907,8 +907,8 @@ static BlockDriver bdrv_qcow = {
     .bdrv_probe		= qcow_probe,
     .bdrv_open		= qcow_open,
     .bdrv_close		= qcow_close,
-    .bdrv_reopen_prepare = qcow_reopen_prepare,
-    .bdrv_create	= qcow_create,
+    .bdrv_reopen_prepare    = qcow_reopen_prepare,
+    .bdrv_create2           = qcow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_co_readv          = qcow_co_readv,
@@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_write_compressed  = qcow_write_compressed,
     .bdrv_get_info          = qcow_get_info,
 
-    .create_options = qcow_create_options,
+    .create_opts            = &qcow_create_opts,
 };
 
 static void bdrv_qcow_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 12/25] qcow2.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (10 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 11/25] qcow.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:21   ` Stefan Hajnoczi
  2014-03-11 14:22   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 13/25] qed.c: " Chunyan Liu
                   ` (22 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/qcow2.c | 325 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 167 insertions(+), 158 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index dcd43bc..e0f00bf 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1455,7 +1455,7 @@ static int preallocate(BlockDriverState *bs)
 static int qcow2_create2(const char *filename, int64_t total_size,
                          const char *backing_file, const char *backing_format,
                          int flags, size_t cluster_size, int prealloc,
-                         QEMUOptionParameter *options, int version,
+                         QemuOpts *opts, int version,
                          Error **errp)
 {
     /* Calculate cluster_bits */
@@ -1487,7 +1487,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, options, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
@@ -1622,11 +1622,11 @@ out:
     return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
 {
-    const char *backing_file = NULL;
-    const char *backing_fmt = NULL;
+    char *backing_file = NULL;
+    char *backing_fmt = NULL;
+    char *buf;
     uint64_t sectors = 0;
     int flags = 0;
     size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1636,64 +1636,64 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
     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;
-        }
-        options++;
+    sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+        flags |= BLOCK_FLAG_ENCRYPT;
+    }
+    cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
+                                         DEFAULT_CLUSTER_SIZE);
+    buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+    if (!buf || !strcmp(buf, "off")) {
+        prealloc = 0;
+    } else if (!strcmp(buf, "metadata")) {
+        prealloc = 1;
+    } else {
+        fprintf(stderr, "Invalid preallocation mode: '%s'\n", buf);
+        ret = -EINVAL;
+        goto finish;
+    }
+    g_free(buf);
+    buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL);
+    if (!buf || !strcmp(buf, "0.10")) {
+        version = 2;
+    } else if (!strcmp(buf, "1.1")) {
+        version = 3;
+    } else {
+        fprintf(stderr, "Invalid compatibility level: '%s'\n", buf);
+        ret = -EINVAL;
+        goto finish;
+    }
+
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+        flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
     }
 
     if (backing_file && prealloc) {
         error_setg(errp, "Backing file and preallocation cannot be used at "
                    "the same time");
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
 
     if (version < 3 && (flags & BLOCK_FLAG_LAZY_REFCOUNTS)) {
         error_setg(errp, "Lazy refcounts only supported with compatibility "
                    "level 1.1 and above (use compat=1.1 or greater)");
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
 
     ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, flags,
-                        cluster_size, prealloc, options, version, &local_err);
+                        cluster_size, prealloc, opts, version, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
+
+finish:
+    g_free(backing_file);
+    g_free(backing_fmt);
+    g_free(buf);
     return ret;
 }
 
@@ -2058,66 +2058,61 @@ static int qcow2_downgrade(BlockDriverState *bs, int target_version)
     return 0;
 }
 
-static int qcow2_amend_options(BlockDriverState *bs,
-                               QEMUOptionParameter *options)
+static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts)
 {
     BDRVQcowState *s = bs->opaque;
     int old_version = s->qcow_version, new_version = old_version;
     uint64_t new_size = 0;
-    const char *backing_file = NULL, *backing_format = NULL;
+    char *backing_file = NULL, *backing_format = NULL;
     bool lazy_refcounts = s->use_lazy_refcounts;
+    char *compat = NULL, *prealloc = NULL;
+    uint64_t cluster_size = s->cluster_size;
+    bool encrypt;
     int ret;
-    int i;
 
-    for (i = 0; options[i].name; i++)
-    {
-        if (!options[i].assigned) {
-            /* only change explicitly defined options */
-            continue;
-        }
+    compat = qemu_opt_get_del(opts, "compat");
+    if (!compat) {
+        /* preserve default */
+    } else if (!strcmp(compat, "0.10")) {
+        new_version = 2;
+    } else if (!strcmp(compat, "1.1")) {
+        new_version = 3;
+    } else {
+        fprintf(stderr, "Unknown compatibility level %s.\n", compat);
+        ret = -EINVAL;
+        goto finish;
+    }
 
-        if (!strcmp(options[i].name, "compat")) {
-            if (!options[i].value.s) {
-                /* preserve default */
-            } else if (!strcmp(options[i].value.s, "0.10")) {
-                new_version = 2;
-            } else if (!strcmp(options[i].value.s, "1.1")) {
-                new_version = 3;
-            } else {
-                fprintf(stderr, "Unknown compatibility level %s.\n",
-                        options[i].value.s);
-                return -EINVAL;
-            }
-        } else if (!strcmp(options[i].name, "preallocation")) {
-            fprintf(stderr, "Cannot change preallocation mode.\n");
-            return -ENOTSUP;
-        } else if (!strcmp(options[i].name, "size")) {
-            new_size = options[i].value.n;
-        } else if (!strcmp(options[i].name, "backing_file")) {
-            backing_file = options[i].value.s;
-        } else if (!strcmp(options[i].name, "backing_fmt")) {
-            backing_format = options[i].value.s;
-        } else if (!strcmp(options[i].name, "encryption")) {
-            if ((options[i].value.n != !!s->crypt_method)) {
-                fprintf(stderr, "Changing the encryption flag is not "
-                        "supported.\n");
-                return -ENOTSUP;
-            }
-        } else if (!strcmp(options[i].name, "cluster_size")) {
-            if (options[i].value.n != s->cluster_size) {
-                fprintf(stderr, "Changing the cluster size is not "
-                        "supported.\n");
-                return -ENOTSUP;
-            }
-        } else if (!strcmp(options[i].name, "lazy_refcounts")) {
-            lazy_refcounts = options[i].value.n;
-        } else {
-            /* if this assertion fails, this probably means a new option was
-             * added without having it covered here */
-            assert(false);
-        }
+    prealloc = qemu_opt_get_del(opts, "preallocation");
+    if (prealloc) {
+        fprintf(stderr, "Cannot change preallocation mode.\n");
+        ret = -ENOTSUP;
+        goto finish;
+    }
+
+    new_size = qemu_opt_get_size_del(opts, "size", 0);
+    backing_file = qemu_opt_get_del(opts, "backing_file");
+    backing_format = qemu_opt_get_del(opts, "backing_fmt");
+
+    encrypt = qemu_opt_get_bool_del(opts, "encryption", s->crypt_method);
+    if (encrypt != !!s->crypt_method) {
+        fprintf(stderr, "Changing the encryption flag is not "
+                "supported.\n");
+        ret = -ENOTSUP;
+        goto finish;
     }
 
+    cluster_size = qemu_opt_get_size_del(opts, "cluster_size", cluster_size);
+    if (cluster_size != s->cluster_size) {
+        fprintf(stderr, "Changing the cluster size is not "
+                "supported.\n");
+        ret = -ENOTSUP;
+        goto finish;
+    }
+
+    lazy_refcounts = qemu_opt_get_bool_del(opts, "lazy_refcounts",
+                                           lazy_refcounts);
+
     if (new_version != old_version) {
         if (new_version > old_version) {
             /* Upgrade */
@@ -2125,12 +2120,12 @@ static int qcow2_amend_options(BlockDriverState *bs,
             ret = qcow2_update_header(bs);
             if (ret < 0) {
                 s->qcow_version = old_version;
-                return ret;
+                goto finish;
             }
         } else {
             ret = qcow2_downgrade(bs, new_version);
             if (ret < 0) {
-                return ret;
+                goto finish;
             }
         }
     }
@@ -2139,7 +2134,7 @@ static int qcow2_amend_options(BlockDriverState *bs,
         ret = qcow2_change_backing_file(bs, backing_file ?: bs->backing_file,
                                         backing_format ?: bs->backing_format);
         if (ret < 0) {
-            return ret;
+            goto finish;
         }
     }
 
@@ -2148,27 +2143,28 @@ static int qcow2_amend_options(BlockDriverState *bs,
             if (s->qcow_version < 3) {
                 fprintf(stderr, "Lazy refcounts only supported with compatibility "
                         "level 1.1 and above (use compat=1.1 or greater)\n");
-                return -EINVAL;
+                ret = -EINVAL;
+                goto finish;
             }
             s->compatible_features |= QCOW2_COMPAT_LAZY_REFCOUNTS;
             ret = qcow2_update_header(bs);
             if (ret < 0) {
                 s->compatible_features &= ~QCOW2_COMPAT_LAZY_REFCOUNTS;
-                return ret;
+                goto finish;
             }
             s->use_lazy_refcounts = true;
         } else {
             /* make image clean first */
             ret = qcow2_mark_clean(bs);
             if (ret < 0) {
-                return ret;
+                goto finish;
             }
             /* now disallow lazy refcounts */
             s->compatible_features &= ~QCOW2_COMPAT_LAZY_REFCOUNTS;
             ret = qcow2_update_header(bs);
             if (ret < 0) {
                 s->compatible_features |= QCOW2_COMPAT_LAZY_REFCOUNTS;
-                return ret;
+                goto finish;
             }
             s->use_lazy_refcounts = false;
         }
@@ -2177,56 +2173,69 @@ static int qcow2_amend_options(BlockDriverState *bs,
     if (new_size) {
         ret = bdrv_truncate(bs, new_size);
         if (ret < 0) {
-            return ret;
+            goto finish;
         }
     }
 
-    return 0;
+    ret = 0;
+
+finish:
+    g_free(backing_file);
+    g_free(backing_format);
+    g_free(compat);
+    g_free(prealloc);
+    return ret;
 }
 
-static QEMUOptionParameter qcow2_create_options[] = {
-    {
-        .name = BLOCK_OPT_SIZE,
-        .type = OPT_SIZE,
-        .help = "Virtual disk size"
-    },
-    {
-        .name = BLOCK_OPT_COMPAT_LEVEL,
-        .type = OPT_STRING,
-        .help = "Compatibility level (0.10 or 1.1)"
-    },
-    {
-        .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_ENCRYPT,
-        .type = OPT_FLAG,
-        .help = "Encrypt the image"
-    },
-    {
-        .name = BLOCK_OPT_CLUSTER_SIZE,
-        .type = OPT_SIZE,
-        .help = "qcow2 cluster size",
-        .value = { .n = DEFAULT_CLUSTER_SIZE },
-    },
-    {
-        .name = BLOCK_OPT_PREALLOC,
-        .type = OPT_STRING,
-        .help = "Preallocation mode (allowed values: off, metadata)"
-    },
-    {
-        .name = BLOCK_OPT_LAZY_REFCOUNTS,
-        .type = OPT_FLAG,
-        .help = "Postpone refcount updates",
-    },
-    { NULL }
+static QemuOptsList qcow2_create_opts = {
+    .name = "qcow2-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        {
+            .name = BLOCK_OPT_COMPAT_LEVEL,
+            .type = QEMU_OPT_STRING,
+            .help = "Compatibility level (0.10 or 1.1)"
+        },
+        {
+            .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_ENCRYPT,
+            .type = QEMU_OPT_BOOL,
+            .help = "Encrypt the image",
+            .def_value_str = "off"
+        },
+        {
+            .name = BLOCK_OPT_CLUSTER_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "qcow2 cluster size",
+            .def_value_str = stringify(DEFAULT_CLUSTER_SIZE)
+        },
+        {
+            .name = BLOCK_OPT_PREALLOC,
+            .type = QEMU_OPT_STRING,
+            .help = "Preallocation mode (allowed values: off, metadata)"
+        },
+        {
+            .name = BLOCK_OPT_LAZY_REFCOUNTS,
+            .type = QEMU_OPT_BOOL,
+            .help = "Postpone refcount updates",
+            .def_value_str = "off"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_qcow2 = {
@@ -2236,10 +2245,10 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
-    .bdrv_create        = qcow2_create,
-    .bdrv_has_zero_init = bdrv_has_zero_init_1,
+    .bdrv_create2         = qcow2_create,
+    .bdrv_has_zero_init   = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = qcow2_co_get_block_status,
-    .bdrv_set_key       = qcow2_set_key,
+    .bdrv_set_key           = qcow2_set_key,
 
     .bdrv_co_readv          = qcow2_co_readv,
     .bdrv_co_writev         = qcow2_co_writev,
@@ -2254,8 +2263,8 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_snapshot_goto     = qcow2_snapshot_goto,
     .bdrv_snapshot_delete   = qcow2_snapshot_delete,
     .bdrv_snapshot_list     = qcow2_snapshot_list,
-    .bdrv_snapshot_load_tmp     = qcow2_snapshot_load_tmp,
-    .bdrv_get_info      = qcow2_get_info,
+    .bdrv_snapshot_load_tmp = qcow2_snapshot_load_tmp,
+    .bdrv_get_info          = qcow2_get_info,
     .bdrv_get_specific_info = qcow2_get_specific_info,
 
     .bdrv_save_vmstate    = qcow2_save_vmstate,
@@ -2266,9 +2275,9 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_refresh_limits        = qcow2_refresh_limits,
     .bdrv_invalidate_cache      = qcow2_invalidate_cache,
 
-    .create_options = qcow2_create_options,
-    .bdrv_check = qcow2_check,
-    .bdrv_amend_options = qcow2_amend_options,
+    .create_opts         = &qcow2_create_opts,
+    .bdrv_check          = qcow2_check,
+    .bdrv_amend_options2 = qcow2_amend_options,
 };
 
 static void bdrv_qcow2_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (11 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 12/25] qcow2.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:24   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 14/25] raw-posix.c: " Chunyan Liu
                   ` (21 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/qed.c | 114 ++++++++++++++++++++++++++++++++----------------------------
 block/qed.h |   3 +-
 2 files changed, 61 insertions(+), 56 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index db27f36..a22c2d9 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -621,53 +621,51 @@ out:
     return ret;
 }
 
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
-                           Error **errp)
+static int bdrv_qed_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     uint64_t image_size = 0;
     uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE;
     uint32_t table_size = QED_DEFAULT_TABLE_SIZE;
-    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++;
-    }
+    char *backing_file = NULL;
+    char *backing_fmt = NULL;
+    int ret;
+
+    image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+    cluster_size = qemu_opt_get_size_del(opts,
+                                         BLOCK_OPT_CLUSTER_SIZE,
+                                         QED_DEFAULT_CLUSTER_SIZE);
+    table_size = qemu_opt_get_size_del(opts, BLOCK_OPT_TABLE_SIZE,
+                                       QED_DEFAULT_TABLE_SIZE);
 
     if (!qed_is_cluster_size_valid(cluster_size)) {
         fprintf(stderr, "QED cluster size must be within range [%u, %u] and power of 2\n",
                 QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
     if (!qed_is_table_size_valid(table_size)) {
         fprintf(stderr, "QED table size must be within range [%u, %u] and power of 2\n",
                 QED_MIN_TABLE_SIZE, QED_MAX_TABLE_SIZE);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
     if (!qed_is_image_size_valid(image_size, cluster_size, table_size)) {
         fprintf(stderr, "QED image size must be a non-zero multiple of "
                         "cluster size and less than %" PRIu64 " bytes\n",
                 qed_max_image_size(cluster_size, table_size));
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
 
-    return qed_create(filename, cluster_size, image_size, table_size,
-                      backing_file, backing_fmt, errp);
+    ret = qed_create(filename, cluster_size, image_size, table_size,
+                     backing_file, backing_fmt, errp);
+
+finish:
+    g_free(backing_file);
+    g_free(backing_fmt);
+    return ret;
 }
 
 typedef struct {
@@ -1575,43 +1573,51 @@ 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_opts = {
+    .name = "qed-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qed_create_opts.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_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_value_str = stringify(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_opts              = &qed_create_opts,
 
     .bdrv_probe               = bdrv_qed_probe,
     .bdrv_rebind              = bdrv_qed_rebind,
     .bdrv_open                = bdrv_qed_open,
     .bdrv_close               = bdrv_qed_close,
     .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
-    .bdrv_create              = bdrv_qed_create,
+    .bdrv_create2             = bdrv_qed_create,
     .bdrv_has_zero_init       = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
     .bdrv_aio_readv           = bdrv_qed_aio_readv,
diff --git a/block/qed.h b/block/qed.h
index 5d65bea..b024751 100644
--- a/block/qed.h
+++ b/block/qed.h
@@ -43,7 +43,7 @@
  *
  * All fields are little-endian on disk.
  */
-
+#define  QED_DEFAULT_CLUSTER_SIZE  65536
 enum {
     QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24,
 
@@ -69,7 +69,6 @@ enum {
      */
     QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */
     QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024,
-    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024,
 
     /* Allocated clusters are tracked using a 2-level pagetable.  Table size is
      * a multiple of clusters so large maximum image sizes can be supported
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 14/25] raw-posix.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (12 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 13/25] qed.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:25   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 15/25] raw-win32.c: " Chunyan Liu
                   ` (20 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/raw-posix.c | 59 +++++++++++++++++++++++++------------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index e6b4c1f..7fc4a3a 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 *opts, Error **errp)
 {
     int fd;
     int result = 0;
@@ -1244,12 +1243,8 @@ 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_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
     fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
                    0644);
@@ -1410,13 +1405,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"
-    },
-    { NULL }
+static QemuOptsList raw_create_opts = {
+    .name = "raw-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_file = {
@@ -1431,7 +1430,7 @@ static BlockDriver bdrv_file = {
     .bdrv_reopen_commit = raw_reopen_commit,
     .bdrv_reopen_abort = raw_reopen_abort,
     .bdrv_close = raw_close,
-    .bdrv_create = raw_create,
+    .bdrv_create2 = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = raw_co_get_block_status,
     .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1448,7 +1447,7 @@ static BlockDriver bdrv_file = {
     .bdrv_get_allocated_file_size
                         = raw_get_allocated_file_size,
 
-    .create_options = raw_create_options,
+    .create_opts = &raw_create_opts,
 };
 
 /***********************************************/
@@ -1760,7 +1759,7 @@ static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
     return -ENOTSUP;
 }
 
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
+static int hdev_create(const char *filename, QemuOpts *opts,
                        Error **errp)
 {
     int fd;
@@ -1769,12 +1768,8 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
     int64_t total_size = 0;
 
     /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
-    }
+    total_size =
+        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
     fd = qemu_open(filename, O_WRONLY | O_BINARY);
     if (fd < 0) {
@@ -1810,8 +1805,8 @@ static BlockDriver bdrv_host_device = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts         = &raw_create_opts,
     .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
     .bdrv_aio_readv	= raw_aio_readv,
@@ -1944,8 +1939,8 @@ static BlockDriver bdrv_host_floppy = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
     .bdrv_aio_writev    = raw_aio_writev,
@@ -2055,8 +2050,8 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
     .bdrv_aio_writev    = raw_aio_writev,
@@ -2185,8 +2180,8 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts        = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
     .bdrv_aio_writev    = raw_aio_writev,
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 15/25] raw-win32.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (13 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 14/25] raw-posix.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:41   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: " Chunyan Liu
                   ` (19 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/raw-win32.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/block/raw-win32.c b/block/raw-win32.c
index 9954748..29f8e54 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -475,8 +475,7 @@ 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 *opts, Error **errp)
 {
     int fd;
     int64_t total_size = 0;
@@ -484,12 +483,8 @@ 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 / 512;
-        }
-        options++;
-    }
+    total_size =
+        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
 
     fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
                    0644);
@@ -503,13 +498,18 @@ 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"
-    },
-    { NULL }
+
+static QemuOptsList raw_create_opts = {
+    .name = "raw-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_file = {
@@ -518,9 +518,9 @@ static BlockDriver bdrv_file = {
     .instance_size	= sizeof(BDRVRawState),
     .bdrv_needs_filename = true,
     .bdrv_parse_filename = raw_parse_filename,
-    .bdrv_file_open	= raw_open,
-    .bdrv_close		= raw_close,
-    .bdrv_create	= raw_create,
+    .bdrv_file_open     = raw_open,
+    .bdrv_close         = raw_close,
+    .bdrv_create2       = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -532,7 +532,7 @@ static BlockDriver bdrv_file = {
     .bdrv_get_allocated_file_size
                         = raw_get_allocated_file_size,
 
-    .create_options = raw_create_options,
+    .create_opts        = &raw_create_opts,
 };
 
 /***********************************************/
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (14 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 15/25] raw-win32.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:44   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 17/25] rbd.c: " Chunyan Liu
                   ` (18 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/raw_bsd.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 9ae5fc2..ee797fd 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"
-    },
-    { 0 }
+static QemuOptsList raw_create_opts = {
+    .name = "raw-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
 };
 
 static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,13 +143,12 @@ 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 *opts, Error **errp)
 {
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, options, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, opts, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -177,7 +180,7 @@ static BlockDriver bdrv_raw = {
     .bdrv_reopen_prepare  = &raw_reopen_prepare,
     .bdrv_open            = &raw_open,
     .bdrv_close           = &raw_close,
-    .bdrv_create          = &raw_create,
+    .bdrv_create2         = &raw_create,
     .bdrv_co_readv        = &raw_co_readv,
     .bdrv_co_writev       = &raw_co_writev,
     .bdrv_co_write_zeroes = &raw_co_write_zeroes,
@@ -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_opts          = &raw_create_opts,
     .bdrv_has_zero_init   = &raw_has_zero_init
 };
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 17/25] rbd.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (15 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 14:46   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 18/25] sheepdog.c: " Chunyan Liu
                   ` (17 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/rbd.c | 63 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 30 insertions(+), 33 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index dbc79f4..f878877 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -282,8 +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,
-                           Error **errp)
+static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     int64_t bytes = 0;
     int64_t objsize;
@@ -306,24 +305,18 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
     }
 
     /* 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_del(opts, BLOCK_OPT_SIZE, 0);
+    objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
+    if (objsize) {
+        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 +893,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"
-    },
-    {NULL}
+static QemuOptsList qemu_rbd_create_opts = {
+    .name = "rbd-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.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"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_rbd = {
@@ -920,10 +917,10 @@ static BlockDriver bdrv_rbd = {
     .bdrv_needs_filename = true,
     .bdrv_file_open     = qemu_rbd_open,
     .bdrv_close         = qemu_rbd_close,
-    .bdrv_create        = qemu_rbd_create,
+    .bdrv_create2       = 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_opts        = &qemu_rbd_create_opts,
     .bdrv_getlength     = qemu_rbd_getlength,
     .bdrv_truncate      = qemu_rbd_truncate,
     .protocol_name      = "rbd",
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 18/25] sheepdog.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (16 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 17/25] rbd.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 16:01   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 19/25] ssh.c: " Chunyan Liu
                   ` (16 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/sheepdog.c | 108 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 55 insertions(+), 53 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f7bd024..027a34e 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1626,12 +1626,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const char *opt)
     return 0;
 }
 
-static int sd_create(const char *filename, QEMUOptionParameter *options,
+static int sd_create(const char *filename, QemuOpts *opts,
                      Error **errp)
 {
     int ret = 0;
     uint32_t vid = 0;
     char *backing_file = NULL;
+    char *buf = NULL;
     BDRVSheepdogState *s;
     char tag[SD_MAX_VDI_TAG_LEN];
     uint32_t snapid;
@@ -1650,31 +1651,26 @@ 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_del(opts, BLOCK_OPT_SIZE, 0);
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+    if (!buf || !strcmp(buf, "off")) {
+        prealloc = false;
+    } else if (!strcmp(buf, "full")) {
+        prealloc = true;
+    } else {
+        error_report("Invalid preallocation mode: '%s'", buf);
+        ret = -EINVAL;
+        goto out;
+    }
+
+    g_free(buf);
+    buf = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY);
+    if (buf) {
+        ret = parse_redundancy(s, buf);
+        if (ret < 0) {
+            goto out;
         }
-        options++;
     }
 
     if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -1724,6 +1720,8 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
 
     ret = sd_prealloc(filename);
 out:
+    g_free(backing_file);
+    g_free(buf);
     g_free(s);
     return ret;
 }
@@ -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"
-    },
-    { NULL }
+static QemuOptsList sd_create_opts = {
+    .name = "sheepdog-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(sd_create_opts.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"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_sheepdog = {
@@ -2521,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create    = sd_create,
+    .bdrv_create2   = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -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,
+    .create_opts    = &sd_create_opts,
 };
 
 static BlockDriver bdrv_sheepdog_tcp = {
@@ -2551,7 +2553,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create    = sd_create,
+    .bdrv_create2   = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2571,7 +2573,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_save_vmstate  = sd_save_vmstate,
     .bdrv_load_vmstate  = sd_load_vmstate,
 
-    .create_options = sd_create_options,
+    .create_opts    = &sd_create_opts,
 };
 
 static BlockDriver bdrv_sheepdog_unix = {
@@ -2581,7 +2583,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create    = sd_create,
+    .bdrv_create2   = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2601,7 +2603,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_save_vmstate  = sd_save_vmstate,
     .bdrv_load_vmstate  = sd_load_vmstate,
 
-    .create_options = sd_create_options,
+    .create_opts    = &sd_create_opts,
 };
 
 static void bdrv_sheepdog_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 19/25] ssh.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (17 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 18/25] sheepdog.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 16:01   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 20/25] vdi.c: " Chunyan Liu
                   ` (15 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/ssh.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..3a5eead 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"
-    },
-    { NULL }
+static QemuOptsList ssh_create_opts = {
+    .name = "ssh-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(ssh_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
 };
 
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
-                      Error **errp)
+static int ssh_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     int r, ret;
     Error *local_err = NULL;
@@ -665,12 +668,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_del(opts, BLOCK_OPT_SIZE, 0);
     DPRINTF("total_size=%" PRIi64, total_size);
 
     uri_options = qdict_new();
@@ -1044,14 +1042,14 @@ static BlockDriver bdrv_ssh = {
     .instance_size                = sizeof(BDRVSSHState),
     .bdrv_parse_filename          = ssh_parse_filename,
     .bdrv_file_open               = ssh_file_open,
-    .bdrv_create                  = ssh_create,
+    .bdrv_create2                 = ssh_create,
     .bdrv_close                   = ssh_close,
     .bdrv_has_zero_init           = ssh_has_zero_init,
     .bdrv_co_readv                = ssh_co_readv,
     .bdrv_co_writev               = ssh_co_writev,
     .bdrv_getlength               = ssh_getlength,
     .bdrv_co_flush_to_disk        = ssh_co_flush,
-    .create_options               = ssh_create_options,
+    .create_opts                  = &ssh_create_opts,
 };
 
 static void bdrv_ssh_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 20/25] vdi.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (18 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 19/25] ssh.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 17:50   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 21/25] vmdk.c: " Chunyan Liu
                   ` (14 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/vdi.c | 72 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index ae49cd8..0799467 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 *opts, Error **errp)
 {
     int fd;
     int result = 0;
@@ -669,25 +668,17 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
     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_del(opts, 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;
-            }
+    block_size = qemu_opt_get_size_del(opts,
+                                       BLOCK_OPT_CLUSTER_SIZE,
+                                       DEFAULT_CLUSTER_SIZE);
 #endif
 #if defined(CONFIG_VDI_STATIC_IMAGE)
-        } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
-            if (options->value.n) {
-                image_type = VDI_TYPE_STATIC;
-            }
-#endif
-        }
-        options++;
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) {
+        image_type = VDI_TYPE_STATIC;
     }
+#endif
 
     fd = qemu_open(filename,
                    O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
@@ -767,29 +758,34 @@ 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_opts = {
+    .name = "vdi-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vdi_create_opts.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_value_str = stringify(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",
+            .def_value_str = "off"
+        },
 #endif
-    /* TODO: An additional option to set UUID values might be useful. */
-    { NULL }
+        /* TODO: An additional option to set UUID values might be useful. */
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_vdi = {
@@ -799,7 +795,7 @@ static BlockDriver bdrv_vdi = {
     .bdrv_open = vdi_open,
     .bdrv_close = vdi_close,
     .bdrv_reopen_prepare = vdi_reopen_prepare,
-    .bdrv_create = vdi_create,
+    .bdrv_create2 = vdi_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = vdi_co_get_block_status,
     .bdrv_make_empty = vdi_make_empty,
@@ -811,7 +807,7 @@ static BlockDriver bdrv_vdi = {
 
     .bdrv_get_info = vdi_get_info,
 
-    .create_options = vdi_create_options,
+    .create_opts = &vdi_create_opts,
     .bdrv_check = vdi_check,
 };
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 21/25] vmdk.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (19 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 20/25] vdi.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 17:51   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 22/25] vpc.c: " Chunyan Liu
                   ` (13 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/vmdk.c | 123 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 63 insertions(+), 60 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index d87c8f6..f9b68a0 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1681,17 +1681,16 @@ 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 *opts, Error **errp)
 {
     int idx = 0;
     BlockDriverState *new_bs = NULL;
     Error *local_err;
     char *desc = NULL;
     int64_t total_size = 0, filesize;
-    const char *adapter_type = NULL;
-    const char *backing_file = NULL;
-    const char *fmt = NULL;
+    char *adapter_type = NULL;
+    char *backing_file = NULL;
+    char *fmt = NULL;
     int flags = 0;
     int ret = 0;
     bool flat, split, compress;
@@ -1731,24 +1730,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
         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_del(opts, BLOCK_OPT_SIZE, 0);
+    adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
+        flags |= BLOCK_FLAG_COMPAT6;
+    }
+    fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
+        zeroed_grain = true;
     }
+
     if (!adapter_type) {
-        adapter_type = "ide";
+        adapter_type = g_strdup("ide");
     } else if (strcmp(adapter_type, "ide") &&
                strcmp(adapter_type, "buslogic") &&
                strcmp(adapter_type, "lsilogic") &&
@@ -1764,7 +1758,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     }
     if (!fmt) {
         /* Default format to monolithicSparse */
-        fmt = "monolithicSparse";
+        fmt = g_strdup("monolithicSparse");
     } else if (strcmp(fmt, "monolithicFlat") &&
                strcmp(fmt, "monolithicSparse") &&
                strcmp(fmt, "twoGbMaxExtentSparse") &&
@@ -1865,7 +1859,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     if (!split && !flat) {
         desc_offset = 0x200;
     } else {
-        ret = bdrv_create_file(filename, options, NULL, &local_err);
+        ret = bdrv_create_file(filename, NULL, opts, &local_err);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create image file");
             goto exit;
@@ -1895,6 +1889,9 @@ exit:
     if (new_bs) {
         bdrv_unref(new_bs);
     }
+    g_free(adapter_type);
+    g_free(backing_file);
+    g_free(fmt);
     g_free(desc);
     g_string_free(ext_desc_lines, true);
     return ret;
@@ -2062,41 +2059,47 @@ 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 =
-            "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 }
+static QemuOptsList vmdk_create_opts = {
+    .name = "vmdk-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.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",
+            .def_value_str = "off"
+        },
+        {
+            .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 = QEMU_OPT_BOOL,
+            .help = "Enable efficient zero writes "
+                    "using the zeroed-grain GTE feature"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_vmdk = {
@@ -2110,7 +2113,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_write                   = vmdk_co_write,
     .bdrv_co_write_zeroes         = vmdk_co_write_zeroes,
     .bdrv_close                   = vmdk_close,
-    .bdrv_create                  = vmdk_create,
+    .bdrv_create2                 = vmdk_create,
     .bdrv_co_flush_to_disk        = vmdk_co_flush,
     .bdrv_co_get_block_status     = vmdk_co_get_block_status,
     .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
@@ -2118,7 +2121,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_get_specific_info       = vmdk_get_specific_info,
     .bdrv_refresh_limits          = vmdk_refresh_limits,
 
-    .create_options               = vmdk_create_options,
+    .create_opts                  = &vmdk_create_opts,
 };
 
 static void bdrv_vmdk_init(void)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 22/25] vpc.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (20 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 21/25] vmdk.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 17:55   ` Stefan Hajnoczi
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 23/25] vhdx.c: " Chunyan Liu
                   ` (12 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/vpc.c | 62 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 82bf248..ac85514 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 *opts, Error **errp)
 {
     uint8_t buf[1024];
     VHDFooter *footer = (VHDFooter *) buf;
-    QEMUOptionParameter *disk_type_param;
+    char *disk_type_param;
     int fd, i;
     uint16_t cyls = 0;
     uint8_t heads = 0;
@@ -730,16 +729,16 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
     int ret = -EIO;
 
     /* Read out options */
-    total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
-
-    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")) {
+    total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+    disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+    if (disk_type_param) {
+        if (!strcmp(disk_type_param, "dynamic")) {
             disk_type = VHD_DYNAMIC;
-        } else if (!strcmp(disk_type_param->value.s, "fixed")) {
+        } else if (!strcmp(disk_type_param, "fixed")) {
             disk_type = VHD_FIXED;
         } else {
-            return -EINVAL;
+            ret = -EINVAL;
+            goto out;
         }
     } else {
         disk_type = VHD_DYNAMIC;
@@ -748,7 +747,8 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
     /* Create the file */
     fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
     if (fd < 0) {
-        return -EIO;
+        ret = -EIO;
+        goto out;
     }
 
     /*
@@ -813,8 +813,10 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
         ret = create_fixed_disk(fd, buf, total_size);
     }
 
- fail:
+fail:
     qemu_close(fd);
+out:
+    g_free(disk_type_param);
     return ret;
 }
 
@@ -842,20 +844,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 =
-            "Type of virtual hard disk format. Supported formats are "
-            "{dynamic (default) | fixed} "
-    },
-    { NULL }
+static QemuOptsList vpc_create_opts = {
+    .name = "vpc-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.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} "
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_vpc = {
@@ -866,14 +872,14 @@ static BlockDriver bdrv_vpc = {
     .bdrv_open              = vpc_open,
     .bdrv_close             = vpc_close,
     .bdrv_reopen_prepare    = vpc_reopen_prepare,
-    .bdrv_create            = vpc_create,
+    .bdrv_create2           = vpc_create,
 
     .bdrv_read              = vpc_co_read,
     .bdrv_write             = vpc_co_write,
 
     .bdrv_get_info          = vpc_get_info,
 
-    .create_options         = vpc_create_options,
+    .create_opts            = &vpc_create_opts,
     .bdrv_has_zero_init     = vpc_has_zero_init,
 };
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 23/25] vhdx.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (21 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 22/25] vpc.c: " Chunyan Liu
@ 2014-03-10  7:31 ` Chunyan Liu
  2014-03-11 17:56   ` Stefan Hajnoczi
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 24/25] vvfat.c: " Chunyan Liu
                   ` (11 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/vhdx.c | 99 +++++++++++++++++++++++++++++-------------------------------
 block/vhdx.h |  1 +
 2 files changed, 48 insertions(+), 52 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index d8afb42..d90fe55 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 *opts, Error **errp)
 {
     int ret = 0;
     uint64_t image_size = (uint64_t) 2 * GiB;
@@ -1722,24 +1721,15 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     gunichar2 *creator = NULL;
     glong creator_items;
     BlockDriverState *bs;
-    const char *type = NULL;
+    char *type = NULL;
     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_del(opts, BLOCK_OPT_SIZE, 0);
+    log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+    block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+    type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+    use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, false);
 
     if (image_size > VHDX_MAX_IMAGE_SIZE) {
         error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1748,7 +1738,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     }
 
     if (type == NULL) {
-        type = "dynamic";
+        type = g_strdup("dynamic");
     }
 
     if (!strcmp(type, "dynamic")) {
@@ -1788,7 +1778,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
                                                     block_size;
 
-    ret = bdrv_create_file(filename, options, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
@@ -1848,6 +1838,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
 delete_and_exit:
     bdrv_unref(bs);
 exit:
+    g_free(type);
     g_free(creator);
     return ret;
 }
@@ -1870,37 +1861,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."
-    },
-    { NULL }
+static QemuOptsList vhdx_create_opts = {
+    .name = "vhdx-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.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_value_str = stringify(DEFAULT_LOG_SIZE),
+           .help = "Log size; min 1MB."
+       },
+       {
+           .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+           .type = QEMU_OPT_SIZE,
+           .def_value_str = stringify(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 }
+    }
 };
 
 static BlockDriver bdrv_vhdx = {
@@ -1912,11 +1907,11 @@ static BlockDriver bdrv_vhdx = {
     .bdrv_reopen_prepare    = vhdx_reopen_prepare,
     .bdrv_co_readv          = vhdx_co_readv,
     .bdrv_co_writev         = vhdx_co_writev,
-    .bdrv_create            = vhdx_create,
+    .bdrv_create2           = vhdx_create,
     .bdrv_get_info          = vhdx_get_info,
     .bdrv_check             = vhdx_check,
 
-    .create_options         = vhdx_create_options,
+    .create_opts            = &vhdx_create_opts,
 };
 
 static void bdrv_vhdx_init(void)
diff --git a/block/vhdx.h b/block/vhdx.h
index 2acd7c2..a5a36fc 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -23,6 +23,7 @@
 #define GiB            (MiB * 1024)
 #define TiB ((uint64_t) GiB * 1024)
 
+#define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */
 
 /* The header section has the following blocks,
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 24/25] vvfat.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (22 preceding siblings ...)
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 23/25] vhdx.c: " Chunyan Liu
@ 2014-03-10  7:32 ` Chunyan Liu
  2014-03-11 17:06   ` Eric Blake
  2014-03-11 18:01   ` Stefan Hajnoczi
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter Chunyan Liu
                   ` (10 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Dong Xu Wang, Chunyan Liu, stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/vvfat.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index ee32b3c..03be65d 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 *opts;
     Error *local_err = NULL;
     int ret;
     int size = sector2cluster(s, s->sector_count);
@@ -2922,11 +2922,11 @@ 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:");
+    opts = qemu_opts_create(bdrv_qcow->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);
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (23 preceding siblings ...)
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 24/25] vvfat.c: " Chunyan Liu
@ 2014-03-10  7:32 ` Chunyan Liu
  2014-03-11 14:06   ` Stefan Hajnoczi
  2014-03-17 19:29   ` Leandro Dorileo
  2014-03-10  7:36 ` [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chun Yan Liu
                   ` (9 subsequent siblings)
  34 siblings, 2 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-10  7:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Chunyan Liu, stefanha

Now all places using QEMUOptionParameter could use QemuOpts too, remove
QEMUOptionParameter related code.

Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 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(-)

diff --git a/block.c b/block.c
index d9b1da3..b6b86c5 100644
--- a/block.c
+++ b/block.c
@@ -407,7 +407,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
 typedef struct CreateCo {
     BlockDriver *drv;
     char *filename;
-    QEMUOptionParameter *options;
     QemuOpts *opts;
     int ret;
     Error *err;
@@ -421,11 +420,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
     CreateCo *cco = opaque;
     assert(cco->drv);
 
-    if (cco->drv->bdrv_create2) {
-        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
-    } else {
-        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
-    }
+    ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err);
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -433,7 +428,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
+                QemuOpts *opts, Error **errp)
 {
     int ret;
 
@@ -441,13 +436,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
     CreateCo cco = {
         .drv = drv,
         .filename = g_strdup(filename),
-        .options = options,
         .opts = opts,
         .ret = NOT_DONE,
         .err = NULL,
     };
 
-    if (!drv->bdrv_create && !drv->bdrv_create2) {
+    if (!drv->bdrv_create) {
         error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
         ret = -ENOTSUP;
         goto out;
@@ -478,8 +472,7 @@ out:
     return ret;
 }
 
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     QemuOpts *opts, Error **errp)
+int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
 {
     BlockDriver *drv;
     Error *local_err = NULL;
@@ -491,7 +484,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
         return -ENOENT;
     }
 
-    ret = bdrv_create(drv, filename, options, opts, &local_err);
+    ret = bdrv_create(drv, filename, opts, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -1254,7 +1247,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QEMUOptionParameter *create_options = NULL;
         QemuOpts *opts = NULL;
         QDict *snapshot_options;
 
@@ -1281,20 +1273,11 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         }
 
         bdrv_qcow2 = bdrv_find_format("qcow2");
-        if (bdrv_qcow2->bdrv_create2) {
-            opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
-                                    &error_abort);
-            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
-        } else {
-            create_options =
-                parse_option_parameters("", bdrv_qcow2->create_options, NULL);
-            set_option_parameter_int(create_options, BLOCK_OPT_SIZE,
-                                     total_size);
-        }
+        opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
+                                &error_abort);
+        qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
 
-        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
-                          &local_err);
-        free_option_parameters(create_options);
+        ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
         qemu_opts_del(opts);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create temporary overlay "
@@ -5243,7 +5226,6 @@ 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;
     QemuOptsList *create_opts = NULL;
     QemuOpts *opts = NULL;
     const char *backing_fmt, *backing_file;
@@ -5266,16 +5248,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
         return;
     }
 
-    if (drv->bdrv_create2) {
-        create_opts = qemu_opts_append(create_opts, drv->create_opts);
-        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
-    } else {
-        create_options = append_option_parameters(create_options,
-                                                  drv->create_options);
-        create_options = append_option_parameters(create_options,
-                                                  proto_drv->create_options);
-        create_opts = params_to_opts(create_options);
-    }
+    create_opts = qemu_opts_append(create_opts, drv->create_opts);
+    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
 
     /* Create parameter list with default values */
     opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
@@ -5368,12 +5342,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
         puts("");
     }
 
-    if (drv->bdrv_create2) {
-        ret = bdrv_create(drv, filename, NULL, opts, &local_err);
-    } else {
-        param = opts_to_params(opts);
-        ret = bdrv_create(drv, filename, param, NULL, &local_err);
-    }
+    ret = bdrv_create(drv, filename, opts, &local_err);
 
     if (ret == -EFBIG) {
         /* This is generally a better message than whatever the driver would
@@ -5390,9 +5359,6 @@ void bdrv_img_create(const char *filename, const char *fmt,
     }
 
 out:
-    free_option_parameters(create_options);
-    free_option_parameters(param);
-
     qemu_opts_del(opts);
     qemu_opts_free(create_opts);
     if (local_err) {
@@ -5412,17 +5378,12 @@ void bdrv_add_before_write_notifier(BlockDriverState *bs,
     notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
 }
 
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
-                       QemuOpts *opts)
+int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts)
 {
-    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
+    if (!bs->drv->bdrv_amend_options) {
         return -ENOTSUP;
     }
-    if (bs->drv->bdrv_amend_options2) {
-        return bs->drv->bdrv_amend_options2(bs, opts);
-    } else {
-        return bs->drv->bdrv_amend_options(bs, options);
-    }
+    return bs->drv->bdrv_amend_options(bs, opts);
 }
 
 /* Used to recurse on single child block filters.
diff --git a/block/cow.c b/block/cow.c
index 4085201..55b7631 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -338,7 +338,7 @@ static int cow_create(const char *filename, QemuOpts *opts, Error **errp)
     image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
     image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
 
-    ret = bdrv_create_file(filename, NULL, opts, &local_err);
+    ret = bdrv_create_file(filename, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
@@ -412,7 +412,7 @@ static BlockDriver bdrv_cow = {
     .bdrv_probe     = cow_probe,
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,
-    .bdrv_create2   = cow_create,
+    .bdrv_create    = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
diff --git a/block/gluster.c b/block/gluster.c
index bd72d8d..b3cfa01 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -715,7 +715,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -742,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -769,7 +769,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -796,7 +796,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
diff --git a/block/qcow.c b/block/qcow.c
index 374e6df..18ce338 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -681,7 +681,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
         flags |= BLOCK_FLAG_ENCRYPT;
     }
 
-    ret = bdrv_create_file(filename, NULL, opts, &local_err);
+    ret = bdrv_create_file(filename, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto cleanup;
@@ -908,7 +908,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_open		= qcow_open,
     .bdrv_close		= qcow_close,
     .bdrv_reopen_prepare    = qcow_reopen_prepare,
-    .bdrv_create2           = qcow_create,
+    .bdrv_create            = qcow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_co_readv          = qcow_co_readv,
diff --git a/block/qcow2.c b/block/qcow2.c
index e0f00bf..98d2e77 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1487,7 +1487,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, NULL, opts, &local_err);
+    ret = bdrv_create_file(filename, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
@@ -2245,7 +2245,7 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
-    .bdrv_create2         = qcow2_create,
+    .bdrv_create          = qcow2_create,
     .bdrv_has_zero_init   = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = qcow2_co_get_block_status,
     .bdrv_set_key           = qcow2_set_key,
@@ -2277,7 +2277,7 @@ static BlockDriver bdrv_qcow2 = {
 
     .create_opts         = &qcow2_create_opts,
     .bdrv_check          = qcow2_check,
-    .bdrv_amend_options2 = qcow2_amend_options,
+    .bdrv_amend_options  = qcow2_amend_options,
 };
 
 static void bdrv_qcow2_init(void)
diff --git a/block/qed.c b/block/qed.c
index a22c2d9..12d86bb 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -566,7 +566,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
     int ret = 0;
     BlockDriverState *bs;
 
-    ret = bdrv_create_file(filename, NULL, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
@@ -1617,7 +1617,7 @@ static BlockDriver bdrv_qed = {
     .bdrv_open                = bdrv_qed_open,
     .bdrv_close               = bdrv_qed_close,
     .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
-    .bdrv_create2             = bdrv_qed_create,
+    .bdrv_create              = bdrv_qed_create,
     .bdrv_has_zero_init       = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
     .bdrv_aio_readv           = bdrv_qed_aio_readv,
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 7fc4a3a..7dac3e1 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1430,7 +1430,7 @@ static BlockDriver bdrv_file = {
     .bdrv_reopen_commit = raw_reopen_commit,
     .bdrv_reopen_abort = raw_reopen_abort,
     .bdrv_close = raw_close,
-    .bdrv_create2 = raw_create,
+    .bdrv_create = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = raw_co_get_block_status,
     .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1805,7 +1805,7 @@ static BlockDriver bdrv_host_device = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create         = hdev_create,
     .create_opts         = &raw_create_opts,
     .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
@@ -1939,7 +1939,7 @@ static BlockDriver bdrv_host_floppy = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create         = hdev_create,
     .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -2050,7 +2050,7 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create         = hdev_create,
     .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -2180,7 +2180,7 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create        = hdev_create,
     .create_opts        = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 29f8e54..8cc8e61 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -520,7 +520,7 @@ static BlockDriver bdrv_file = {
     .bdrv_parse_filename = raw_parse_filename,
     .bdrv_file_open     = raw_open,
     .bdrv_close         = raw_close,
-    .bdrv_create2       = raw_create,
+    .bdrv_create        = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
     .bdrv_aio_readv     = raw_aio_readv,
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index ee797fd..492f58d 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -148,7 +148,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, NULL, opts, &local_err);
+    ret = bdrv_create_file(filename, opts, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -180,7 +180,7 @@ static BlockDriver bdrv_raw = {
     .bdrv_reopen_prepare  = &raw_reopen_prepare,
     .bdrv_open            = &raw_open,
     .bdrv_close           = &raw_close,
-    .bdrv_create2         = &raw_create,
+    .bdrv_create          = &raw_create,
     .bdrv_co_readv        = &raw_co_readv,
     .bdrv_co_writev       = &raw_co_writev,
     .bdrv_co_write_zeroes = &raw_co_write_zeroes,
diff --git a/block/rbd.c b/block/rbd.c
index f878877..f189900 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -917,7 +917,7 @@ static BlockDriver bdrv_rbd = {
     .bdrv_needs_filename = true,
     .bdrv_file_open     = qemu_rbd_open,
     .bdrv_close         = qemu_rbd_close,
-    .bdrv_create2       = qemu_rbd_create,
+    .bdrv_create        = qemu_rbd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_get_info      = qemu_rbd_getinfo,
     .create_opts        = &qemu_rbd_create_opts,
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 027a34e..c688b0f 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2523,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create2   = sd_create,
+    .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2553,7 +2553,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create2   = sd_create,
+    .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2583,7 +2583,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create2   = sd_create,
+    .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
diff --git a/block/ssh.c b/block/ssh.c
index 3a5eead..a4c7f06 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -1042,7 +1042,7 @@ static BlockDriver bdrv_ssh = {
     .instance_size                = sizeof(BDRVSSHState),
     .bdrv_parse_filename          = ssh_parse_filename,
     .bdrv_file_open               = ssh_file_open,
-    .bdrv_create2                 = ssh_create,
+    .bdrv_create                  = ssh_create,
     .bdrv_close                   = ssh_close,
     .bdrv_has_zero_init           = ssh_has_zero_init,
     .bdrv_co_readv                = ssh_co_readv,
diff --git a/block/vdi.c b/block/vdi.c
index 0799467..3680e1a 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -795,7 +795,7 @@ static BlockDriver bdrv_vdi = {
     .bdrv_open = vdi_open,
     .bdrv_close = vdi_close,
     .bdrv_reopen_prepare = vdi_reopen_prepare,
-    .bdrv_create2 = vdi_create,
+    .bdrv_create = vdi_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = vdi_co_get_block_status,
     .bdrv_make_empty = vdi_make_empty,
diff --git a/block/vhdx.c b/block/vhdx.c
index d90fe55..26ac780 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1778,7 +1778,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
     block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
                                                     block_size;
 
-    ret = bdrv_create_file(filename, NULL, opts, &local_err);
+    ret = bdrv_create_file(filename, opts, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
@@ -1907,7 +1907,7 @@ static BlockDriver bdrv_vhdx = {
     .bdrv_reopen_prepare    = vhdx_reopen_prepare,
     .bdrv_co_readv          = vhdx_co_readv,
     .bdrv_co_writev         = vhdx_co_writev,
-    .bdrv_create2           = vhdx_create,
+    .bdrv_create            = vhdx_create,
     .bdrv_get_info          = vhdx_get_info,
     .bdrv_check             = vhdx_check,
 
diff --git a/block/vmdk.c b/block/vmdk.c
index f9b68a0..97e0432 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1525,7 +1525,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
     uint32_t *gd_buf = NULL;
     int gd_buf_size;
 
-    ret = bdrv_create_file(filename, NULL, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
@@ -1859,7 +1859,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
     if (!split && !flat) {
         desc_offset = 0x200;
     } else {
-        ret = bdrv_create_file(filename, NULL, opts, &local_err);
+        ret = bdrv_create_file(filename, opts, &local_err);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create image file");
             goto exit;
@@ -2113,7 +2113,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_write                   = vmdk_co_write,
     .bdrv_co_write_zeroes         = vmdk_co_write_zeroes,
     .bdrv_close                   = vmdk_close,
-    .bdrv_create2                 = vmdk_create,
+    .bdrv_create                  = vmdk_create,
     .bdrv_co_flush_to_disk        = vmdk_co_flush,
     .bdrv_co_get_block_status     = vmdk_co_get_block_status,
     .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
diff --git a/block/vpc.c b/block/vpc.c
index ac85514..111c3c6 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -872,7 +872,7 @@ static BlockDriver bdrv_vpc = {
     .bdrv_open              = vpc_open,
     .bdrv_close             = vpc_close,
     .bdrv_reopen_prepare    = vpc_reopen_prepare,
-    .bdrv_create2           = vpc_create,
+    .bdrv_create            = vpc_create,
 
     .bdrv_read              = vpc_co_read,
     .bdrv_write             = vpc_co_write,
diff --git a/block/vvfat.c b/block/vvfat.c
index 03be65d..de00f69 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2926,7 +2926,7 @@ static int enable_write_target(BDRVVVFATState *s)
     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, NULL, opts, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
diff --git a/include/block/block.h b/include/block/block.h
index c482204..33a984e 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -177,9 +177,8 @@ BlockDriver *bdrv_find_format(const char *format_name);
 BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
                                           bool readonly);
 int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, QemuOpts *opts, Error **errp);
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     QemuOpts *opts, Error **errp);
+                QemuOpts *opts, Error **errp);
+int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
 BlockDriverState *bdrv_new(const char *device_name);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -283,8 +282,7 @@ typedef enum {
 
 int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
-int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options,
-                       QemuOpts *opts);
+int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts);
 
 /* external snapshots */
 
diff --git a/include/block/block_int.h b/include/block/block_int.h
index e4e832f..12684ef 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -116,10 +116,7 @@ struct BlockDriver {
                       const uint8_t *buf, int nb_sectors);
     void (*bdrv_close)(BlockDriverState *bs);
     void (*bdrv_rebind)(BlockDriverState *bs);
-    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
-                       Error **errp);
-    /* FIXME: will remove the duplicate and rename back to bdrv_create later */
-    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error **errp);
+    int (*bdrv_create)(const char *filename, QemuOpts *opts, Error **errp);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -218,7 +215,6 @@ struct BlockDriver {
         BlockDriverCompletionFunc *cb, void *opaque);
 
     /* List of options for creating images, terminated by name == NULL */
-    QEMUOptionParameter *create_options;
     QemuOptsList *create_opts;
 
     /*
@@ -228,12 +224,7 @@ struct BlockDriver {
     int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
         BdrvCheckMode fix);
 
-    int (*bdrv_amend_options)(BlockDriverState *bs,
-        QEMUOptionParameter *options);
-    /* FIXME: will remove the duplicate and rename back to
-     * bdrv_amend_options later
-     */
-    int (*bdrv_amend_options2)(BlockDriverState *bs, QemuOpts *opts);
+    int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts);
 
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
diff --git a/include/qemu/option.h b/include/qemu/option.h
index a6aca59..9574819 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -31,59 +31,15 @@
 #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);
 int get_next_param_value(char *buf, int buf_size,
                          const char *tag, const char **pstr);
 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;
@@ -170,6 +126,4 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
 QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
 void qemu_opts_free(QemuOptsList *list);
 void qemu_opts_print_help(QemuOptsList *list);
-QEMUOptionParameter *opts_to_params(QemuOpts *opts);
-QemuOptsList *params_to_opts(QEMUOptionParameter *list);
 #endif
diff --git a/qemu-img.c b/qemu-img.c
index c548741..9ca09dc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -235,7 +235,6 @@ 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 *create_opts = NULL;
 
     /* Find driver and parse its options */
@@ -245,33 +244,17 @@ static int print_block_option_help(const char *filename, const char *fmt)
         return 1;
     }
 
-    if (drv->create_opts) {
-        create_opts = qemu_opts_append(create_opts, drv->create_opts);
-    } else {
-        create_options = append_option_parameters(create_options,
-                                                  drv->create_options);
-    }
+    create_opts = qemu_opts_append(create_opts, drv->create_opts);
     if (filename) {
         proto_drv = bdrv_find_protocol(filename, true);
         if (!proto_drv) {
             error_report("Unknown protocol '%s'", filename);
             return 1;
         }
-        if (drv->create_opts) {
-            create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
-        } else {
-            create_options =
-                append_option_parameters(create_options,
-                                         proto_drv->create_options);
-        }
+        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
     }
 
-    if (drv->create_opts) {
-        qemu_opts_print_help(create_opts);
-    } else {
-        print_option_help(create_options);
-    }
-    free_option_parameters(create_options);
+    qemu_opts_print_help(create_opts);
     qemu_opts_free(create_opts);
     return 0;
 }
@@ -1167,7 +1150,6 @@ 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;
     QemuOpts *opts = NULL;
     QemuOptsList *create_opts = NULL;
     const char *out_baseimg_param;
@@ -1356,16 +1338,8 @@ static int img_convert(int argc, char **argv)
         goto out;
     }
 
-    if (drv->bdrv_create2) {
-        create_opts = qemu_opts_append(create_opts, drv->create_opts);
-        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
-    } else {
-        create_options = append_option_parameters(create_options,
-                                                  drv->create_options);
-        create_options = append_option_parameters(create_options,
-                                                  proto_drv->create_options);
-        create_opts = params_to_opts(create_options);
-    }
+    create_opts = qemu_opts_append(create_opts, drv->create_opts);
+    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
 
     opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
     if (options && qemu_opts_do_parse(opts, options, NULL)) {
@@ -1418,12 +1392,7 @@ static int img_convert(int argc, char **argv)
 
     if (!skip_create) {
         /* Create the new image */
-        if (drv->bdrv_create2) {
-            ret = bdrv_create(drv, out_filename, NULL, opts, &local_err);
-        } else {
-            param = opts_to_params(opts);
-            ret = bdrv_create(drv, out_filename, param, NULL, &local_err);
-        }
+        ret = bdrv_create(drv, out_filename, opts, &local_err);
         if (ret < 0) {
             error_report("%s: error while converting %s: %s",
                          out_filename, out_fmt, error_get_pretty(local_err));
@@ -1687,8 +1656,6 @@ out:
         qemu_progress_print(100, 0);
     }
     qemu_progress_end();
-    free_option_parameters(create_options);
-    free_option_parameters(param);
     qemu_opts_free(create_opts);
     qemu_opts_del(opts);
     qemu_vfree(buf);
@@ -2676,7 +2643,6 @@ 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;
@@ -2748,13 +2714,7 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    if (bs->drv->bdrv_amend_options2) {
-        create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
-    } else {
-        create_options = append_option_parameters(create_options,
-                                                  bs->drv->create_options);
-        create_opts = params_to_opts(create_options);
-    }
+    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
     opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
     if (options && qemu_opts_do_parse(opts, options, NULL)) {
         error_report("Invalid options for file format '%s'", fmt);
@@ -2762,12 +2722,7 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    if (bs->drv->bdrv_amend_options2) {
-        ret = bdrv_amend_options(bs, NULL, opts);
-    } else {
-        options_param = opts_to_params(opts);
-        ret = bdrv_amend_options(bs, options_param, NULL);
-    }
+    ret = bdrv_amend_options(bs, opts);
     if (ret < 0) {
         error_report("Error while amending options: %s", strerror(-ret));
         goto out;
@@ -2777,8 +2732,6 @@ 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);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index e05b126..d8d99d5 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -127,22 +127,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)
 {
@@ -216,170 +200,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_err) {
-        qerror_report_err(local_err);
-        error_free(local_err);
-        return -1;
-    }
-
-    list->assigned = true;
-
-    return 0;
-}
-
-/*
- * Sets the given parameter to an integer instead of a string.
- * This function cannot be used to set string options.
- *
- * Returns 0 on success, -1 in error cases
- */
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-    uint64_t value)
-{
-    // 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:
-    case OPT_NUMBER:
-    case OPT_SIZE:
-        list->value.n = value;
-        break;
-
-    default:
-        return -1;
-    }
-
-    list->assigned = true;
-
-    return 0;
-}
-
-/*
- * Frees a option list. If it contains strings, the strings are freed as well.
- */
-void free_option_parameters(QEMUOptionParameter *list)
-{
-    QEMUOptionParameter *cur = list;
-
-    while (cur && cur->name) {
-        if (cur->type == OPT_STRING) {
-            g_free(cur->value.s);
-        }
-        cur++;
-    }
-
-    g_free(list);
-}
-
-/*
- * Count valid options in list
- */
-static size_t count_option_parameters(QEMUOptionParameter *list)
-{
-    size_t num_options = 0;
-
-    while (list && list->name) {
-        num_options++;
-        list++;
-    }
-
-    return num_options;
-}
-
-/*
- * Append an option list (list) to an option list (dest).
- *
- * If dest is NULL, a new copy of list is created.
- *
- * Returns a pointer to the first element of dest (or the newly allocated copy)
- */
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
-    QEMUOptionParameter *list)
-{
-    size_t num_options, num_dest_options;
-
-    num_options = count_option_parameters(dest);
-    num_dest_options = num_options;
-
-    num_options += count_option_parameters(list);
-
-    dest = g_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter));
-    dest[num_dest_options].name = NULL;
-
-    while (list && list->name) {
-        if (get_option_parameter(dest, list->name) == NULL) {
-            dest[num_dest_options++] = *list;
-            dest[num_dest_options].name = NULL;
-        }
-        list++;
-    }
-
-    return dest;
-}
-
 static size_t count_opts_list(QemuOptsList *list)
 {
     QemuOptDesc *desc = NULL;
@@ -448,80 +268,6 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
     return tmp;
 }
 
-/*
- * Parses a parameter string (param) into an option list (dest).
- *
- * list is the template option list. If dest is NULL, a new copy of list is
- * created. If list is NULL, this function fails.
- *
- * A parameter string consists of one or more parameters, separated by commas.
- * Each parameter consists of its name and possibly of a value. In the latter
- * case, the 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;
@@ -571,48 +317,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++;
-    }
-}
-
-/* ------------------------------------------------------------------ */
-
 static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
 {
     QemuOpt *opt;
@@ -1464,108 +1168,3 @@ void qemu_opts_print_help(QemuOptsList *list)
                list->desc[i].help : "");
     }
 }
-
-/* convert QEMUOptionParameter 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);
-    opts->desc[i].name = NULL;
-
-    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 = 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++;
-        opts->desc[i].name = NULL;
-    }
-
-    return opts;
-}
-
-QEMUOptionParameter *opts_to_params(QemuOpts *opts)
-{
-    QEMUOptionParameter *dest = NULL;
-    QemuOptDesc *desc;
-    size_t num_opts, i = 0;
-    const char *tmp;
-
-    if (!opts || !opts->list || !opts->list->desc) {
-        return NULL;
-    }
-
-    num_opts = count_opts_list(opts->list);
-    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
-    dest[i].name = NULL;
-
-    desc = opts->list->desc;
-    while (desc && desc->name) {
-        dest[i].name = g_strdup(desc->name);
-        dest[i].help = g_strdup(desc->help);
-        switch (desc->type) {
-        case QEMU_OPT_STRING:
-            dest[i].type = OPT_STRING;
-            tmp = qemu_opt_get(opts, desc->name);
-            dest[i].value.s = g_strdup(tmp);
-            break;
-
-        case QEMU_OPT_BOOL:
-            dest[i].type = OPT_FLAG;
-            dest[i].value.n = qemu_opt_get_bool(opts, desc->name, 0) ? 1 : 0;
-            break;
-
-        case QEMU_OPT_NUMBER:
-            dest[i].type = OPT_NUMBER;
-            dest[i].value.n = qemu_opt_get_number(opts, desc->name, 0);
-            break;
-
-        case QEMU_OPT_SIZE:
-            dest[i].type = OPT_SIZE;
-            dest[i].value.n = qemu_opt_get_size(opts, desc->name, 0);
-            break;
-        }
-
-        i++;
-        desc++;
-        dest[i].name = NULL;
-    }
-
-    return dest;
-}
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (24 preceding siblings ...)
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter Chunyan Liu
@ 2014-03-10  7:36 ` Chun Yan Liu
  2014-03-10  7:37 ` Chun Yan Liu
                   ` (8 subsequent siblings)
  34 siblings, 0 replies; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-10  7:36 UTC (permalink / raw)
  To: qemu-devel, Chun Yan Liu; +Cc: kwolf, stefanha

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

>>> On 3/10/2014 at 03:31 PM, in message
<1394436721-21812-1-git-send-email-cyliu@suse.com>, Chunyan Liu
<cyliu@suse.com> 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: 
>   * update verison info in patch 2/25 
>   * others are not changed except for rebase 
>  
> Chunyan Liu (25): 
>   add def_value_str to QemuOptDesc 
>   qapi: output def_value_str when query command line options 
>   improve some functions in qemu-option.c 
>   improve assertion in qemu_opt_get functions 
>   add some QemuOpts functions for replace work 
>   add convert functions between QEMUOptionParameter to QemuOpts 
>   change block layer to support both QemuOpts and QEMUOptionParamter 
>   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 
>   vmdk.c: replace QEMUOptionParameter with QemuOpts 
>   vpc.c: replace QEMUOptionParameter with QemuOpts 
>   vhdx.c: replace QEMUOptionParameter with QemuOpts 
>   vvfat.c: replace QEMUOptionParameter with QemuOpts 
>   cleanup QEMUOptionParameter 
>  
>  block.c                   |  96 ++++---- 
>  block/cow.c               |  52 ++--- 
>  block/gluster.c           |  73 +++--- 
>  block/iscsi.c             |  29 ++- 
>  block/qcow.c              |  72 +++--- 
>  block/qcow2.c             | 325 +++++++++++++------------- 
>  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               |  70 +++--- 
>  block/vhdx.c              |  97 ++++---- 
>  block/vhdx.h              |   1 + 
>  block/vmdk.c              | 121 +++++----- 
>  block/vpc.c               |  60 ++--- 
>  block/vvfat.c             |  10 +- 
>  include/block/block.h     |   7 +- 
>  include/block/block_int.h |   9 +- 
>  include/qemu/option.h     |  56 +---- 
>  include/qemu/option_int.h |   4 +- 
>  qapi-schema.json          |   6 +- 
>  qemu-img.c                |  89 ++++--- 
>  qmp-commands.hx           |   2 + 
>  util/qemu-config.c        |   4 + 
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
>  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (25 preceding siblings ...)
  2014-03-10  7:36 ` [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chun Yan Liu
@ 2014-03-10  7:37 ` Chun Yan Liu
  2014-03-10  7:37 ` Chun Yan Liu
                   ` (7 subsequent siblings)
  34 siblings, 0 replies; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-10  7:37 UTC (permalink / raw)
  To: qemu-devel, Chun Yan Liu; +Cc: kwolf, stefanha

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

>>> On 3/10/2014 at 03:31 PM, in message
<1394436721-21812-1-git-send-email-cyliu@suse.com>, Chunyan Liu
<cyliu@suse.com> 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: 
>   * update verison info in patch 2/25 
>   * others are not changed except for rebase 
>  
> Chunyan Liu (25): 
>   add def_value_str to QemuOptDesc 
>   qapi: output def_value_str when query command line options 
>   improve some functions in qemu-option.c 
>   improve assertion in qemu_opt_get functions 
>   add some QemuOpts functions for replace work 
>   add convert functions between QEMUOptionParameter to QemuOpts 
>   change block layer to support both QemuOpts and QEMUOptionParamter 
>   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 
>   vmdk.c: replace QEMUOptionParameter with QemuOpts 
>   vpc.c: replace QEMUOptionParameter with QemuOpts 
>   vhdx.c: replace QEMUOptionParameter with QemuOpts 
>   vvfat.c: replace QEMUOptionParameter with QemuOpts 
>   cleanup QEMUOptionParameter 
>  
>  block.c                   |  96 ++++---- 
>  block/cow.c               |  52 ++--- 
>  block/gluster.c           |  73 +++--- 
>  block/iscsi.c             |  29 ++- 
>  block/qcow.c              |  72 +++--- 
>  block/qcow2.c             | 325 +++++++++++++------------- 
>  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               |  70 +++--- 
>  block/vhdx.c              |  97 ++++---- 
>  block/vhdx.h              |   1 + 
>  block/vmdk.c              | 121 +++++----- 
>  block/vpc.c               |  60 ++--- 
>  block/vvfat.c             |  10 +- 
>  include/block/block.h     |   7 +- 
>  include/block/block_int.h |   9 +- 
>  include/qemu/option.h     |  56 +---- 
>  include/qemu/option_int.h |   4 +- 
>  qapi-schema.json          |   6 +- 
>  qemu-img.c                |  89 ++++--- 
>  qmp-commands.hx           |   2 + 
>  util/qemu-config.c        |   4 + 
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
>  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (26 preceding siblings ...)
  2014-03-10  7:37 ` Chun Yan Liu
@ 2014-03-10  7:37 ` Chun Yan Liu
  2014-03-10  7:38 ` Chun Yan Liu
                   ` (6 subsequent siblings)
  34 siblings, 0 replies; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-10  7:37 UTC (permalink / raw)
  To: qemu-devel, Chun Yan Liu; +Cc: kwolf, stefanha

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

>>> On 3/10/2014 at 03:31 PM, in message
<1394436721-21812-1-git-send-email-cyliu@suse.com>, Chunyan Liu
<cyliu@suse.com> 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: 
>   * update verison info in patch 2/25 
>   * others are not changed except for rebase 
>  
> Chunyan Liu (25): 
>   add def_value_str to QemuOptDesc 
>   qapi: output def_value_str when query command line options 
>   improve some functions in qemu-option.c 
>   improve assertion in qemu_opt_get functions 
>   add some QemuOpts functions for replace work 
>   add convert functions between QEMUOptionParameter to QemuOpts 
>   change block layer to support both QemuOpts and QEMUOptionParamter 
>   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 
>   vmdk.c: replace QEMUOptionParameter with QemuOpts 
>   vpc.c: replace QEMUOptionParameter with QemuOpts 
>   vhdx.c: replace QEMUOptionParameter with QemuOpts 
>   vvfat.c: replace QEMUOptionParameter with QemuOpts 
>   cleanup QEMUOptionParameter 
>  
>  block.c                   |  96 ++++---- 
>  block/cow.c               |  52 ++--- 
>  block/gluster.c           |  73 +++--- 
>  block/iscsi.c             |  29 ++- 
>  block/qcow.c              |  72 +++--- 
>  block/qcow2.c             | 325 +++++++++++++------------- 
>  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               |  70 +++--- 
>  block/vhdx.c              |  97 ++++---- 
>  block/vhdx.h              |   1 + 
>  block/vmdk.c              | 121 +++++----- 
>  block/vpc.c               |  60 ++--- 
>  block/vvfat.c             |  10 +- 
>  include/block/block.h     |   7 +- 
>  include/block/block_int.h |   9 +- 
>  include/qemu/option.h     |  56 +---- 
>  include/qemu/option_int.h |   4 +- 
>  qapi-schema.json          |   6 +- 
>  qemu-img.c                |  89 ++++--- 
>  qmp-commands.hx           |   2 + 
>  util/qemu-config.c        |   4 + 
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
>  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (27 preceding siblings ...)
  2014-03-10  7:37 ` Chun Yan Liu
@ 2014-03-10  7:38 ` Chun Yan Liu
  2014-03-10  7:39 ` Chun Yan Liu
                   ` (5 subsequent siblings)
  34 siblings, 0 replies; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-10  7:38 UTC (permalink / raw)
  To: qemu-devel, Chun Yan Liu; +Cc: kwolf, stefanha

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

>>> On 3/10/2014 at 03:31 PM, in message
<1394436721-21812-1-git-send-email-cyliu@suse.com>, Chunyan Liu
<cyliu@suse.com> 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: 
>   * update verison info in patch 2/25 
>   * others are not changed except for rebase 
>  
> Chunyan Liu (25): 
>   add def_value_str to QemuOptDesc 
>   qapi: output def_value_str when query command line options 
>   improve some functions in qemu-option.c 
>   improve assertion in qemu_opt_get functions 
>   add some QemuOpts functions for replace work 
>   add convert functions between QEMUOptionParameter to QemuOpts 
>   change block layer to support both QemuOpts and QEMUOptionParamter 
>   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 
>   vmdk.c: replace QEMUOptionParameter with QemuOpts 
>   vpc.c: replace QEMUOptionParameter with QemuOpts 
>   vhdx.c: replace QEMUOptionParameter with QemuOpts 
>   vvfat.c: replace QEMUOptionParameter with QemuOpts 
>   cleanup QEMUOptionParameter 
>  
>  block.c                   |  96 ++++---- 
>  block/cow.c               |  52 ++--- 
>  block/gluster.c           |  73 +++--- 
>  block/iscsi.c             |  29 ++- 
>  block/qcow.c              |  72 +++--- 
>  block/qcow2.c             | 325 +++++++++++++------------- 
>  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               |  70 +++--- 
>  block/vhdx.c              |  97 ++++---- 
>  block/vhdx.h              |   1 + 
>  block/vmdk.c              | 121 +++++----- 
>  block/vpc.c               |  60 ++--- 
>  block/vvfat.c             |  10 +- 
>  include/block/block.h     |   7 +- 
>  include/block/block_int.h |   9 +- 
>  include/qemu/option.h     |  56 +---- 
>  include/qemu/option_int.h |   4 +- 
>  qapi-schema.json          |   6 +- 
>  qemu-img.c                |  89 ++++--- 
>  qmp-commands.hx           |   2 + 
>  util/qemu-config.c        |   4 + 
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
>  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (28 preceding siblings ...)
  2014-03-10  7:38 ` Chun Yan Liu
@ 2014-03-10  7:39 ` Chun Yan Liu
  2014-03-10  7:39 ` Chun Yan Liu
                   ` (4 subsequent siblings)
  34 siblings, 0 replies; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-10  7:39 UTC (permalink / raw)
  To: qemu-devel, Chun Yan Liu; +Cc: kwolf, stefanha

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

>>> On 3/10/2014 at 03:31 PM, in message
<1394436721-21812-1-git-send-email-cyliu@suse.com>, Chunyan Liu
<cyliu@suse.com> 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: 
>   * update verison info in patch 2/25 
>   * others are not changed except for rebase 
>  
> Chunyan Liu (25): 
>   add def_value_str to QemuOptDesc 
>   qapi: output def_value_str when query command line options 
>   improve some functions in qemu-option.c 
>   improve assertion in qemu_opt_get functions 
>   add some QemuOpts functions for replace work 
>   add convert functions between QEMUOptionParameter to QemuOpts 
>   change block layer to support both QemuOpts and QEMUOptionParamter 
>   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 
>   vmdk.c: replace QEMUOptionParameter with QemuOpts 
>   vpc.c: replace QEMUOptionParameter with QemuOpts 
>   vhdx.c: replace QEMUOptionParameter with QemuOpts 
>   vvfat.c: replace QEMUOptionParameter with QemuOpts 
>   cleanup QEMUOptionParameter 
>  
>  block.c                   |  96 ++++---- 
>  block/cow.c               |  52 ++--- 
>  block/gluster.c           |  73 +++--- 
>  block/iscsi.c             |  29 ++- 
>  block/qcow.c              |  72 +++--- 
>  block/qcow2.c             | 325 +++++++++++++------------- 
>  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               |  70 +++--- 
>  block/vhdx.c              |  97 ++++---- 
>  block/vhdx.h              |   1 + 
>  block/vmdk.c              | 121 +++++----- 
>  block/vpc.c               |  60 ++--- 
>  block/vvfat.c             |  10 +- 
>  include/block/block.h     |   7 +- 
>  include/block/block_int.h |   9 +- 
>  include/qemu/option.h     |  56 +---- 
>  include/qemu/option_int.h |   4 +- 
>  qapi-schema.json          |   6 +- 
>  qemu-img.c                |  89 ++++--- 
>  qmp-commands.hx           |   2 + 
>  util/qemu-config.c        |   4 + 
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
>  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (29 preceding siblings ...)
  2014-03-10  7:39 ` Chun Yan Liu
@ 2014-03-10  7:39 ` Chun Yan Liu
  2014-03-10 20:22 ` Stefan Hajnoczi
                   ` (3 subsequent siblings)
  34 siblings, 0 replies; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-10  7:39 UTC (permalink / raw)
  To: qemu-devel, Chun Yan Liu; +Cc: kwolf, stefanha

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

>>> On 3/10/2014 at 03:31 PM, in message
<1394436721-21812-1-git-send-email-cyliu@suse.com>, Chunyan Liu
<cyliu@suse.com> 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: 
>   * update verison info in patch 2/25 
>   * others are not changed except for rebase 
>  
> Chunyan Liu (25): 
>   add def_value_str to QemuOptDesc 
>   qapi: output def_value_str when query command line options 
>   improve some functions in qemu-option.c 
>   improve assertion in qemu_opt_get functions 
>   add some QemuOpts functions for replace work 
>   add convert functions between QEMUOptionParameter to QemuOpts 
>   change block layer to support both QemuOpts and QEMUOptionParamter 
>   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 
>   vmdk.c: replace QEMUOptionParameter with QemuOpts 
>   vpc.c: replace QEMUOptionParameter with QemuOpts 
>   vhdx.c: replace QEMUOptionParameter with QemuOpts 
>   vvfat.c: replace QEMUOptionParameter with QemuOpts 
>   cleanup QEMUOptionParameter 
>  
>  block.c                   |  96 ++++---- 
>  block/cow.c               |  52 ++--- 
>  block/gluster.c           |  73 +++--- 
>  block/iscsi.c             |  29 ++- 
>  block/qcow.c              |  72 +++--- 
>  block/qcow2.c             | 325 +++++++++++++------------- 
>  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               |  70 +++--- 
>  block/vhdx.c              |  97 ++++---- 
>  block/vhdx.h              |   1 + 
>  block/vmdk.c              | 121 +++++----- 
>  block/vpc.c               |  60 ++--- 
>  block/vvfat.c             |  10 +- 
>  include/block/block.h     |   7 +- 
>  include/block/block_int.h |   9 +- 
>  include/qemu/option.h     |  56 +---- 
>  include/qemu/option_int.h |   4 +- 
>  qapi-schema.json          |   6 +- 
>  qemu-img.c                |  89 ++++--- 
>  qmp-commands.hx           |   2 + 
>  util/qemu-config.c        |   4 + 
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
>  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc Chunyan Liu
@ 2014-03-10 19:52   ` Eric Blake
  2014-03-11 13:29   ` Stefan Hajnoczi
  1 sibling, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-10 19:52 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, stefanha

[-- Attachment #1: Type: text/plain, Size: 1451 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> 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 <address@hidden>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option.h |  3 ++-
>  util/qemu-option.c    | 59 +++++++++++++++++++++++++++++++++++++++++++--------
>  2 files changed, 52 insertions(+), 10 deletions(-)
> 

> +++ b/util/qemu-option.c
> @@ -33,6 +33,9 @@
>  #include "qapi/qmp/qerror.h"
>  #include "qemu/option_int.h"
>  
> +static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
> +                                            const char *name);

I tend to avoid forward-declaration of static functions, except when
true mutual recursion is required - when I read a file, it's nicer to
see the smaller building blocks up front instead of having to skip to
the bottom to see what they do.  Do you need a forward-declaration, or
can you split this into two patches, one that does just code motion to
hoist find_desc_by_name() earlier, and the second to make use of it in
correct topological order?

But what you have is correct, so if you don't have a reason to respin
for anything else,

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options Chunyan Liu
@ 2014-03-10 19:57   ` Eric Blake
  2014-03-11  6:14   ` Hu Tao
  1 sibling, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-10 19:57 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, stefanha

[-- Attachment #1: Type: text/plain, Size: 566 bytes --]

On 03/10/2014 01:31 AM, 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 <address@hidden>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  qapi-schema.json   | 6 +++++-
>  qmp-commands.hx    | 2 ++
>  util/qemu-config.c | 4 ++++
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (30 preceding siblings ...)
  2014-03-10  7:39 ` Chun Yan Liu
@ 2014-03-10 20:22 ` Stefan Hajnoczi
  2014-03-11  3:07   ` Chunyan Liu
  2014-03-10 22:45 ` Eric Blake
                   ` (2 subsequent siblings)
  34 siblings, 1 reply; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-10 20:22 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

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.
> 
> ---
> Changes to v21:
>   * update verison info in patch 2/25
>   * others are not changed except for rebase
> 
> Chunyan Liu (25):
>   add def_value_str to QemuOptDesc
>   qapi: output def_value_str when query command line options
>   improve some functions in qemu-option.c
>   improve assertion in qemu_opt_get functions
>   add some QemuOpts functions for replace work
>   add convert functions between QEMUOptionParameter to QemuOpts
>   change block layer to support both QemuOpts and QEMUOptionParamter
>   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
>   vmdk.c: replace QEMUOptionParameter with QemuOpts
>   vpc.c: replace QEMUOptionParameter with QemuOpts
>   vhdx.c: replace QEMUOptionParameter with QemuOpts
>   vvfat.c: replace QEMUOptionParameter with QemuOpts
>   cleanup QEMUOptionParameter
> 
>  block.c                   |  96 ++++----
>  block/cow.c               |  52 ++---
>  block/gluster.c           |  73 +++---
>  block/iscsi.c             |  29 ++-
>  block/qcow.c              |  72 +++---
>  block/qcow2.c             | 325 +++++++++++++-------------
>  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               |  70 +++---
>  block/vhdx.c              |  97 ++++----
>  block/vhdx.h              |   1 +
>  block/vmdk.c              | 121 +++++-----
>  block/vpc.c               |  60 ++---
>  block/vvfat.c             |  10 +-
>  include/block/block.h     |   7 +-
>  include/block/block_int.h |   9 +-
>  include/qemu/option.h     |  56 +----
>  include/qemu/option_int.h |   4 +-
>  qapi-schema.json          |   6 +-
>  qemu-img.c                |  89 ++++---
>  qmp-commands.hx           |   2 +
>  util/qemu-config.c        |   4 +
>  util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------
>  29 files changed, 1060 insertions(+), 1125 deletions(-)

Looks like this needs to be rebased onto qemu.git/master:

qapi/string-input-visitor.c: In function ‘parse_type_size’:
qapi/string-input-visitor.c:53:9: error: implicit declaration of function ‘parse_option_size’ [-Werror=implicit-function-declaration]
         parse_option_size(name, siv->string, &val, &err);
         ^
qapi/string-input-visitor.c:53:9: error: nested extern declaration of ‘parse_option_size’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [qapi/string-input-visitor.o] Error 1
make: *** Waiting for unfinished jobs....
qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]
         ov->fake_id_opt->name = "id";
                               ^

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c Chunyan Liu
@ 2014-03-10 20:29   ` Eric Blake
  2014-03-10 21:21     ` Eric Blake
  2014-03-17 19:58   ` Leandro Dorileo
  1 sibling, 1 reply; 105+ messages in thread
From: Eric Blake @ 2014-03-10 20:29 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 2790 bytes --]

On 03/10/2014 01:31 AM, 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 <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option_int.h |  4 +--
>  util/qemu-option.c        | 81 +++++++++++++++++++++++++++++++++++++++--------
>  2 files changed, 69 insertions(+), 16 deletions(-)
> 
> 
> +++ 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;

You are losing the 'const' here...


> @@ -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);

...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.  Is it
intentional?  If so, document it in the commit message.  Or am I missing
something, where we already reject duplicates, in which case, your new
code is currently unreachable, and your commit message could do with
more explanation of why you are adding something that later patches will
make use of.

Also, I'd feel a LOT better if we FIRST had a testsuite that covered
what QemuOpts is _supposed_ to do before we then patch it,so that we
aren't getting surprised by silent changes in behavior.  It's okay to
write a test that shows old behavior, then tweak the test in the patch
that updates the behavior along with the justification of why the new
behavior is nicer.

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

> +    opt = qemu_opt_find(opts, name);
> +    if (opt) {
> +        g_free((char *)opt->str);

Another pointless cast.


>  
> +    opt = qemu_opt_find(opts, name);
> +    if (opt) {
> +        g_free((char *)opt->str);

and another.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-10 20:29   ` Eric Blake
@ 2014-03-10 21:21     ` Eric Blake
  2014-03-11  7:26       ` Chunyan Liu
  2014-03-12  6:49       ` Chunyan Liu
  0 siblings, 2 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-10 21:21 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 2731 bytes --]

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?):

qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier
from pointer target type [-Werror]
         ov->fake_id_opt->name = "id";
                               ^

If I press on in spite of that warning, then I get the same behavior
where the last type= still wins on behavior.  So I'm not sure how it all
worked, but at least behavior wise, my one test didn't uncover a regression.

Still, I'd feel a LOT better with a testsuite of what QemuOpts is
supposed to be able to do.  tests/test-opts-visitor.c was the only file
in tests/ that even mentions QemuOpts.

>> @@ -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)
> 
>> +    opt = qemu_opt_find(opts, name);
>> +    if (opt) {
>> +        g_free((char *)opt->str);
> 
> Another pointless cast.

Maybe not pointless, if you end up not removing the const in the struct
declaration due to the compile error; but that brings me back to my
earlier question - since the compiler error proves that we have places
that are assigning compile-time string constants into the name field, we
must NOT call g_free on those copies - how does your code distinguish
between a QemuOpt that is built up by mallocs, vs. one that is described
by compile-time constants?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions Chunyan Liu
@ 2014-03-10 21:44   ` Eric Blake
  2014-03-12  6:34     ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Eric Blake @ 2014-03-10 21:44 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, stefanha

[-- Attachment #1: Type: text/plain, Size: 3139 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is true, it

s/doen't/doesn't/

I mentioned the same problem against v20.  It is very depressing when
review comments are not addressed.

> won't report error, but can still alloc an opt for the option and save it.
> However, after that, when doing qemu_opt_get, this option could be found in opts
> but opt->desc is NULL. This is correct, should not be treated as error.
> 
> This patch would fix vvfat issue after changing to QemuOpts.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  util/qemu-option.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index c7639e8..df79235 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
>          }
>          return defval;
>      }
> -    assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
> +    if (opt->desc) {
> +        assert(opt->desc->type == QEMU_OPT_BOOL);
> +    }
>      return opt->value.boolean;

I'm not sure I like this.  opt->value is a union, but opt_set() does NOT
populate the union when opts_accepts_any() fails.  Previously, we were
using opt->desc->type as the discriminator for which branch of the union
is valid.  But with your patch, if an option was set as a string, but
then queried as a boolean, we may be reading bogus contents from the
union.  Or even worse, if someone sets the uint member of the union to
0x100000000 via qemu_opt_set_number(), then later calls
qemu_opt_get_bool, the boolean member _might_ read as true on some
platforms and false on others, depending on things such as host endianness.

How is vvfat broken without this patch?  That is, what specific option
are you setting without specifying its type, that later triggers the
assertion when you try to get the option via a specific type?

I'm wondering if the fix should look more like:

if (opt->desc) {
    assert(opt->desc->type == QEMU_OPT_BOOL);
    return opt->value.boolean;
} else {
    code to parse opt->str
}

so that you are not dereferencing an undefined state of the union.

> @@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
>          }
>          return defval;
>      }
> -    assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
> +    if (opt->desc) {
> +        assert(opt->desc->type == QEMU_OPT_NUMBER);
> +    }
>      return opt->value.uint;
>  }
>  
> @@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
>          }
>          return defval;
>      }
> -    assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
> +    if (opt->desc) {
> +        assert(opt->desc->type == QEMU_OPT_SIZE);
> +    }
>      return opt->value.uint;

Same problem in these two spots.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (31 preceding siblings ...)
  2014-03-10 20:22 ` Stefan Hajnoczi
@ 2014-03-10 22:45 ` Eric Blake
  2014-03-11 18:03 ` Stefan Hajnoczi
  2014-03-21  0:07 ` Leandro Dorileo
  34 siblings, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-10 22:45 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, stefanha

[-- Attachment #1: Type: text/plain, Size: 1180 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
> one Qemu Option structure is kept in QEMU code.

Uggh.  The more I learn about QemuOpts while reviewing this patch, the
more I KNOW it has lurking bugs waiting to bite us.

Case in point:

$ touch oddname,id=1
$ qemu-system-x86_64 -drive id=a,file=oddname,,id=1    # starts
$ # now, swap the two arguments:
$ qemu-system-x86_64 -drive file=oddname,,id=1,id=a
qemu-system-x86_64: -drive file=oddname,,id=1,id=a: Parameter 'id'
expects an identifier
$

Gross.  opts_parse uses strncmp() for checking for a leading 'id=', but
strstr() for checking for an intermediate ',id='.  And strstr() can have
false positives, including in the middle of my filename that was
properly escaped.

This is a long-standing bug - as a bug, you can fix it after freeze, but
as it is long-standing, it's not the end of the world if it misses 2.0.
 But it underscores my plea that this series is not fully baked until
you add a testsuite.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work Chunyan Liu
@ 2014-03-10 23:28   ` Eric Blake
  2014-03-11  5:29     ` Chunyan Liu
  2014-03-17 19:35   ` Leandro Dorileo
  1 sibling, 1 reply; 105+ messages in thread
From: Eric Blake @ 2014-03-10 23:28 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 9438 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> Add some qemu_opt functions to replace the same functionality of
> QEMUOptionParameter handling.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option.h |   9 +++
>  util/qemu-option.c    | 188 ++++++++++++++++++++++++++++++++++++++++++++++----
>  2 files changed, 184 insertions(+), 13 deletions(-)
> 

> +++ 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);

Again, any reason you can't hoist the function so that it occurs in
topological order, rather than needing to add a forward declaration?

>  }
>  
> +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++;
> +    }

This returns 0 for option lists where opts_accepts_any() is true.  Is
that going to bite us?  Let's see...

> +/* 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,

Naming this 'dst' is confusing, as it is not the destination.  Rather,
you are creating a new list, and the new list is the destination of the
concatenation of first and second list arguments, where descriptions in
the first list have priority over any duplicates in the second list.

> +                               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));

...Already I can see problems if either 'dst' or 'list' passes
opts_accepts_any().  If exactly one has a desc array with no name, then
that QemuOptsList accepts any option spelling, but the resulting list in
'tmp' will only accept the options in the other input.  Probably worth
asserting that neither input passes opts_accepts_any().

> +    QTAILQ_INIT(&tmp->head);
> +    num_dst_opts = 0;

This name is confusing - it is actually tracking how many descriptions
you have copied into 'tmp', and NOT how many options are in 'dst'.

> +
> +    /* 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;

Redundant assignment; your g_malloc0() above already guaranteed this.

> +            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) {

So every call to qemu_opts_append() is O(n^2) behavior - I guess it's
okay: as long as we are always passing short lists, we don't need it to
scale very well.

> +                tmp->desc[num_dst_opts++] = *desc;
> +                tmp->desc[num_dst_opts].name = NULL;

Again, redundant assignment to NULL.

> +            }
> +            desc++;
> +        }
> +    }
> +
> +    return tmp;

Okay, at the end of the day, 'tmp' is a single block of malloc'd
storage, where descriptions are shared with pre-existing opt lists
(probably worth documenting that the lifetime of the returned value of
this function is no longer than the lifetime of the two lists you
concatenated, and that a simple g_free() of the list will suffice - or
point to qemu_opts_free() as the recommended cleanup method).

> +}
> +
>  /*
>   * 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 ? opt->str : NULL;
>  }
>  
> +char *qemu_opt_get_del(QemuOpts *opts, const char *name)

Please, add a comment what this function does.  Something like:

If 'opts' already has a value for the key 'name', remove that key from
the options list and return the value.  Otherwise, if 'opts' has a
default value for the key, return that default.  Otherwise, return NULL.

Also, I think qemu_opt_get_del and qemu_opts_append may be better as two
separate commits, particularly if you are also enhancing the testsuite
with each commit to prove the functionality works.

Why are your later callers using a common helper function, but
qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()?
Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common helper?


>  
> -bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> +static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,

Nothing else in the code base uses the '_qemu' namespace.  You need to
name this function something better. A comment for this method would be
helpful, something like:

Determine the boolean value for key 'name' from 'opts', defaulting to
'defval' if one has not already been added to the list and if the list
does not already provide a default.  Additionally, if 'del', remove the
value from the list.

> +                               bool defval, bool del)
>  {
>      QemuOpt *opt;
> +    bool ret = defval;
>  
>      if (opts == NULL) {
>          return defval;
> @@ -599,19 +693,35 @@ 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);
> +            parse_option_bool(name, desc->def_value_str, &ret, &error_abort);
>          }
> -        return defval;
> +        return ret;

This favors the QemuOptDesc default over the defval that the user passed
in.  I think that's an important detail to document that use of the
def_value_str means the defval argument is never used.

>      }
>      if (opt->desc) {
>          assert(opt->desc->type == QEMU_OPT_BOOL);
>      }
> -    return opt->value.boolean;
> +    ret = opt->value.boolean;

Same problem as in 4/25 - I don't think you can rely on
opt->value.boolean being valid if you don't track the union
discriminator, and right now, the union discriminator is tracked only
via opt->desc.

> +    if (del) {
> +        qemu_opt_del(opt);
> +    }
> +    return ret;

Couldn't this whole function be shortened to:

char *tmp;
if (del) {
    tmp = qemu_opt_get_del(opts, name);
} else {
    tmp = qemu_opt_get(opts, name);
}
if (!tmp) {
    return defval;
}
parse_option_bool(name, tmp, &defval, &error_abort);
g_free(tmp);
return defval;

or even shorter, if you combine qemu_opt_get{,_del} into calling a
common helper function?

>  }
>  
> -uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
> +bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> +{
> +    return _qemu_opt_get_bool(opts, name, defval, false);
> +}
> +
> +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
> +{
> +    return _qemu_opt_get_bool(opts, name, defval, true);
> +}

Other than the _qemu namespace, this is a good example of how a common
helper function makes it easier to implement two variants.

The _number and _size variants will need similar treatment as the _bool.


> @@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
>      loc_pop(&loc);
>      return rc;
>  }
> +
> +/* free a QemuOptsList, can accept NULL as arguments */
> +void qemu_opts_free(QemuOptsList *list)
> +{
> +    if (!list) {
> +        return;
> +    }
> +
> +    g_free(list);
> +}

g_free() is safe to call on NULL.  Which means qemu_opts_free(foo) is a
fancy way to spell g_free(foo).  Do we need this function?

> +
> +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 : "");

This prints trailing spaces for any description that lacks help text.
Not the end of the world, but I try to be cleaner than that.

> +    }
> +}

Unrelated to either of the other two categories of functions - maybe
this patch should be split into three parts.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10 20:22 ` Stefan Hajnoczi
@ 2014-03-11  3:07   ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-11  3:07 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 5293 bytes --]

2014-03-11 4:22 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:

> 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.
> >
> > ---
> > Changes to v21:
> >   * update verison info in patch 2/25
> >   * others are not changed except for rebase
> >
> > Chunyan Liu (25):
> >   add def_value_str to QemuOptDesc
> >   qapi: output def_value_str when query command line options
> >   improve some functions in qemu-option.c
> >   improve assertion in qemu_opt_get functions
> >   add some QemuOpts functions for replace work
> >   add convert functions between QEMUOptionParameter to QemuOpts
> >   change block layer to support both QemuOpts and QEMUOptionParamter
> >   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
> >   vmdk.c: replace QEMUOptionParameter with QemuOpts
> >   vpc.c: replace QEMUOptionParameter with QemuOpts
> >   vhdx.c: replace QEMUOptionParameter with QemuOpts
> >   vvfat.c: replace QEMUOptionParameter with QemuOpts
> >   cleanup QEMUOptionParameter
> >
> >  block.c                   |  96 ++++----
> >  block/cow.c               |  52 ++---
> >  block/gluster.c           |  73 +++---
> >  block/iscsi.c             |  29 ++-
> >  block/qcow.c              |  72 +++---
> >  block/qcow2.c             | 325 +++++++++++++-------------
> >  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               |  70 +++---
> >  block/vhdx.c              |  97 ++++----
> >  block/vhdx.h              |   1 +
> >  block/vmdk.c              | 121 +++++-----
> >  block/vpc.c               |  60 ++---
> >  block/vvfat.c             |  10 +-
> >  include/block/block.h     |   7 +-
> >  include/block/block_int.h |   9 +-
> >  include/qemu/option.h     |  56 +----
> >  include/qemu/option_int.h |   4 +-
> >  qapi-schema.json          |   6 +-
> >  qemu-img.c                |  89 ++++---
> >  qmp-commands.hx           |   2 +
> >  util/qemu-config.c        |   4 +
> >  util/qemu-option.c        | 576
> ++++++++++++++++++++++------------------------
> >  29 files changed, 1060 insertions(+), 1125 deletions(-)
>
> Looks like this needs to be rebased onto qemu.git/master:
>
> qapi/string-input-visitor.c: In function ‘parse_type_size’:
> qapi/string-input-visitor.c:53:9: error: implicit declaration of function
> ‘parse_option_size’ [-Werror=implicit-function-declaration]
>          parse_option_size(name, siv->string, &val, &err);
>          ^
>

I've updated the patch series in github:
https://github.com/chunyanliu/qemu/commits/QemuOpts

updated 25/25.


> qapi/string-input-visitor.c:53:9: error: nested extern declaration of
> ‘parse_option_size’ [-Werror=nested-externs]
> cc1: all warnings being treated as errors
> make: *** [qapi/string-input-visitor.o] Error 1
> make: *** Waiting for unfinished jobs....
> qapi/opts-visitor.c: In function ‘opts_start_struct’:
> qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier
> from pointer target type [-Werror]
>          ov->fake_id_opt->name = "id";
>                                ^
>

following patch squashed to 03/25:
---
 qapi/opts-visitor.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 5d830a2..e6a295a 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,6 +177,8 @@ opts_end_struct(Visitor *v, Error **errp)
     }
     g_hash_table_destroy(ov->unprocessed_opts);
     ov->unprocessed_opts = NULL;
+    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;
 }
-- 
1.7.12.4

[-- Attachment #2: Type: text/html, Size: 6827 bytes --]

^ permalink raw reply related	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
@ 2014-03-11  4:34   ` Eric Blake
  2014-03-11 16:54   ` Eric Blake
  1 sibling, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-11  4:34 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 2130 bytes --]

On 03/10/2014 01:31 AM, 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 <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---

> @@ -420,7 +421,11 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
>      CreateCo *cco = opaque;
>      assert(cco->drv);
>  
> -    ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
> +    if (cco->drv->bdrv_create2) {
> +        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);

Is it worth assert(!cco->options) here,

> +    } else {
> +        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);

and assert(!cco->opts) here, to ensure that we aren't ignoring options
from the other style of create?  Then again, it gets cleaned up in later
patches.

> @@ -5248,28 +5266,31 @@ 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);
> +    if (drv->bdrv_create2) {
> +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> +        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);

Memory leak.  As implemented earlier in the series, qemu_opts_append()
creates a new object, but as you are overwriting create_opts with the
second result without hanging onto the pointer returned by the first
call, you have just leaked the first instance.

I ran out of time to review further today, but this series still needs
more work, and I am starting to doubt that it will make 2.0.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
@ 2014-03-11  4:46   ` Eric Blake
  0 siblings, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-11  4:46 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, stefanha

[-- Attachment #1: Type: text/plain, Size: 4252 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> Add two temp convert functions between QEMUOptionParameter to QemuOpts, so that
> next patch can use it. It will simplify next patch for easier review.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option.h |   2 +
>  util/qemu-option.c    | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 107 insertions(+)
> 

> +
> +/* convert QEMUOptionParameter 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);
> +    opts->desc[i].name = NULL;

Dead assignment to NULL, thanks to the g_malloc0 above.

> +
> +    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 = list->value.n ? "on" : "off";

Ouch.  The pointer used here points to constant memory...

> +            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);

...while the pointer used here points to heap memory.  Yet I see nothing
in the struct that you use to track whether to free the string or not,
which means this is more likely a memory leak, but also a potential for
a crash during an errant call to g_free().  You absolutely must manage
the memory correctly, if you are going to conditionally heap-allocate
def_value_str.

For the sake of conversions between the two types, may I suggest an idea:
in 'struct QemuOpt', add a char[24] buffer (that's large enough to hold
the maximum stringized uint value).  Then, instead of malloc'ing memory
with g_strdup_printf, you instead format integers in place.  You've
already malloc'd the size for the QemuOpt, and now the string
representation also fits within that space without needing a secondary
malloc.

Whether or not you end up keeping the stringizing buffer permanently
part of QemuOpt, or delete it after you delete QEMUOptionParameter,
remains to be seen at the end of the series.

> +        case OPT_STRING:
> +            opts->desc[i].type = QEMU_OPT_STRING;
> +            opts->desc[i].def_value_str = g_strdup(list->value.s);

Here, just declare that your temporary QemuOptsList result from the
function has a shorter lifetime than the input QemuOptionParameter, and
set the def_value_str pointer to the original list->value.s instead of
duplicating it.  Then, you are back to the situation where freeing the
temporary QemuOptsList doesn't leak and doesn't risk double frees.


> +QEMUOptionParameter *opts_to_params(QemuOpts *opts)
> +{
> +    QEMUOptionParameter *dest = NULL;
> +    QemuOptDesc *desc;
> +    size_t num_opts, i = 0;
> +    const char *tmp;
> +
> +    if (!opts || !opts->list || !opts->list->desc) {
> +        return NULL;
> +    }
> +
> +    num_opts = count_opts_list(opts->list);
> +    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
> +    dest[i].name = NULL;
> +
> +    desc = opts->list->desc;
> +    while (desc && desc->name) {
> +        dest[i].name = g_strdup(desc->name);
> +        dest[i].help = g_strdup(desc->help);

I didn't research QEMUOptionParameter close enough to know if you will
be causing any memory leaks on the reverse conversion - but since the
end goal of the series is to delete QEMUOptionParameter, this method
will eventually disappear, so I guess I could live with leaks here
(although it would be nice to document it in the commit message, if you
do indeed leak).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-10 23:28   ` Eric Blake
@ 2014-03-11  5:29     ` Chunyan Liu
  2014-03-11 11:59       ` Eric Blake
  0 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-11  5:29 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 10299 bytes --]

2014-03-11 7:28 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> > Add some qemu_opt functions to replace the same functionality of
> > QEMUOptionParameter handling.
> >
> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  include/qemu/option.h |   9 +++
> >  util/qemu-option.c    | 188
> ++++++++++++++++++++++++++++++++++++++++++++++----
> >  2 files changed, 184 insertions(+), 13 deletions(-)
> >
>
> > +++ 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);
>
> Again, any reason you can't hoist the function so that it occurs in
> topological order, rather than needing to add a forward declaration?
>
> >  }
> >
> > +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++;
> > +    }
>
> This returns 0 for option lists where opts_accepts_any() is true.  Is
> that going to bite us?  Let's see...
>
> > +/* 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,
>
> Naming this 'dst' is confusing, as it is not the destination.  Rather,
> you are creating a new list, and the new list is the destination of the
> concatenation of first and second list arguments, where descriptions in
> the first list have priority over any duplicates in the second list.
>
> > +                               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));
>
> ...Already I can see problems if either 'dst' or 'list' passes
> opts_accepts_any().  If exactly one has a desc array with no name, then
> that QemuOptsList accepts any option spelling, but the resulting list in
> 'tmp' will only accept the options in the other input.  Probably worth
> asserting that neither input passes opts_accepts_any().
>
> > +    QTAILQ_INIT(&tmp->head);
> > +    num_dst_opts = 0;
>
> This name is confusing - it is actually tracking how many descriptions
> you have copied into 'tmp', and NOT how many options are in 'dst'.
>
> > +
> > +    /* 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;
>
> Redundant assignment; your g_malloc0() above already guaranteed this.
>
> > +            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) {
>
> So every call to qemu_opts_append() is O(n^2) behavior - I guess it's
> okay: as long as we are always passing short lists, we don't need it to
> scale very well.
>
> > +                tmp->desc[num_dst_opts++] = *desc;
> > +                tmp->desc[num_dst_opts].name = NULL;
>
> Again, redundant assignment to NULL.
>
> > +            }
> > +            desc++;
> > +        }
> > +    }
> > +
> > +    return tmp;
>
> Okay, at the end of the day, 'tmp' is a single block of malloc'd
> storage, where descriptions are shared with pre-existing opt lists
> (probably worth documenting that the lifetime of the returned value of
> this function is no longer than the lifetime of the two lists you
> concatenated, and that a simple g_free() of the list will suffice - or
> point to qemu_opts_free() as the recommended cleanup method).
>
> > +}
> > +
> >  /*
> >   * 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 ? opt->str : NULL;
> >  }
> >
> > +char *qemu_opt_get_del(QemuOpts *opts, const char *name)
>
> Please, add a comment what this function does.  Something like:
>
> If 'opts' already has a value for the key 'name', remove that key from
> the options list and return the value.  Otherwise, if 'opts' has a
> default value for the key, return that default.  Otherwise, return NULL.
>
> Also, I think qemu_opt_get_del and qemu_opts_append may be better as two
> separate commits, particularly if you are also enhancing the testsuite
> with each commit to prove the functionality works.
>
> Why are your later callers using a common helper function, but
> qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()?
> Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common helper?
>
> qemu_opt_get_del must return (char *), but the existing qemu_opt_get
returns
(const char *). Could also change qemu_opt_get return value to (char *)
type,
then these two functions could use a common helper function. But there are
too
many places using qemu_opt_get already, if the return value type changes,
it will
affect a lot.


> >
> > -bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> > +static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,
>
> Nothing else in the code base uses the '_qemu' namespace.  You need to
> name this function something better. A comment for this method would be
> helpful, something like:
>
> Determine the boolean value for key 'name' from 'opts', defaulting to
> 'defval' if one has not already been added to the list and if the list
> does not already provide a default.  Additionally, if 'del', remove the
> value from the list.
>
> > +                               bool defval, bool del)
> >  {
> >      QemuOpt *opt;
> > +    bool ret = defval;
> >
> >      if (opts == NULL) {
> >          return defval;
> > @@ -599,19 +693,35 @@ 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);
> > +            parse_option_bool(name, desc->def_value_str, &ret,
> &error_abort);
> >          }
> > -        return defval;
> > +        return ret;
>
> This favors the QemuOptDesc default over the defval that the user passed
> in.  I think that's an important detail to document that use of the
> def_value_str means the defval argument is never used.
>
> >      }
> >      if (opt->desc) {
> >          assert(opt->desc->type == QEMU_OPT_BOOL);
> >      }
> > -    return opt->value.boolean;
> > +    ret = opt->value.boolean;
>
> Same problem as in 4/25 - I don't think you can rely on
> opt->value.boolean being valid if you don't track the union
> discriminator, and right now, the union discriminator is tracked only
> via opt->desc.


Couldn't find a reliable way if the option is passed through
opts_accept_any,
just no way to check the option type.


>
> > +    if (del) {
> > +        qemu_opt_del(opt);
> > +    }
> > +    return ret;
>
> Couldn't this whole function be shortened to:
>
> char *tmp;
> if (del) {
>     tmp = qemu_opt_get_del(opts, name);
> } else {
>     tmp = qemu_opt_get(opts, name);
> }
> if (!tmp) {
>     return defval;
> }
> parse_option_bool(name, tmp, &defval, &error_abort);
> g_free(tmp);
> return defval;
>
> or even shorter, if you combine qemu_opt_get{,_del} into calling a
> common helper function?
>
>
Could be if changing qemu_opt_get return value type, but just as said
before,
that will affect many codes.


> >  }
> >
> > -uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t
> defval)
> > +bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> > +{
> > +    return _qemu_opt_get_bool(opts, name, defval, false);
> > +}
> > +
> > +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool
> defval)
> > +{
> > +    return _qemu_opt_get_bool(opts, name, defval, true);
> > +}
>
> Other than the _qemu namespace, this is a good example of how a common
> helper function makes it easier to implement two variants.
>
> The _number and _size variants will need similar treatment as the _bool.
>
>
> > @@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list,
> qemu_opts_loopfunc func, void *opaque,
> >      loc_pop(&loc);
> >      return rc;
> >  }
> > +
> > +/* free a QemuOptsList, can accept NULL as arguments */
> > +void qemu_opts_free(QemuOptsList *list)
> > +{
> > +    if (!list) {
> > +        return;
> > +    }
> > +
> > +    g_free(list);
> > +}
>
> g_free() is safe to call on NULL.  Which means qemu_opts_free(foo) is a
> fancy way to spell g_free(foo).  Do we need this function?
>
> > +
> > +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 : "");
>
> This prints trailing spaces for any description that lacks help text.
> Not the end of the world, but I try to be cleaner than that.
>
> > +    }
> > +}
>
> Unrelated to either of the other two categories of functions - maybe
> this patch should be split into three parts.
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 13880 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options Chunyan Liu
  2014-03-10 19:57   ` Eric Blake
@ 2014-03-11  6:14   ` Hu Tao
  1 sibling, 0 replies; 105+ messages in thread
From: Hu Tao @ 2014-03-11  6:14 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:38PM +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 <address@hidden>

Not a valid email address.

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-10 21:21     ` Eric Blake
@ 2014-03-11  7:26       ` Chunyan Liu
  2014-03-11 21:00         ` Leandro Dorileo
  2014-03-12  6:49       ` Chunyan Liu
  1 sibling, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-11  7:26 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 3405 bytes --]

2014-03-11 5:21 GMT+08:00 Eric Blake <eblake@redhat.com>:

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


> qapi/opts-visitor.c: In function ‘opts_start_struct’:
> qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier
> from pointer target type [-Werror]
>          ov->fake_id_opt->name = "id";
>                                ^
>

This is a place needed to be changed but missing, since name and str
changed to be (char *), here should be g_strdup("id"). Due to my
configuration,
it appears as a warning instead of error which is missed. Updated 3/25.


> If I press on in spite of that warning, then I get the same behavior
> where the last type= still wins on behavior.  So I'm not sure how it all
> worked, but at least behavior wise, my one test didn't uncover a
> regression.
>
> Still, I'd feel a LOT better with a testsuite of what QemuOpts is
> supposed to be able to do.  tests/test-opts-visitor.c was the only file
> in tests/ that even mentions QemuOpts.
>
>

>
>> @@ -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)
> >
> >> +    opt = qemu_opt_find(opts, name);
> >> +    if (opt) {
> >> +        g_free((char *)opt->str);
> >
> > Another pointless cast.
>
> Maybe not pointless, if you end up not removing the const in the struct
> declaration due to the compile error; but that brings me back to my
> earlier question - since the compiler error proves that we have places
> that are assigning compile-time string constants into the name field, we
> must NOT call g_free on those copies - how does your code distinguish
> between a QemuOpt that is built up by mallocs, vs. one that is described
> by compile-time constants?
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 4859 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-11  5:29     ` Chunyan Liu
@ 2014-03-11 11:59       ` Eric Blake
  2014-03-12  3:10         ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Eric Blake @ 2014-03-11 11:59 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 2160 bytes --]

On 03/10/2014 11:29 PM, Chunyan Liu wrote:
>>
>> Why are your later callers using a common helper function, but
>> qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()?
>> Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common helper?
>>
>> qemu_opt_get_del must return (char *), but the existing qemu_opt_get
> returns
> (const char *). Could also change qemu_opt_get return value to (char *)
> type,
> then these two functions could use a common helper function. But there are
> too
> many places using qemu_opt_get already, if the return value type changes,
> it will
> affect a lot.

Going from 'char *' to 'const char *' is automatic.  Have your helper
return 'char *', and qemu_opt_get can call it just fine and give its
callers their desired const char *.

>>
>> Same problem as in 4/25 - I don't think you can rely on
>> opt->value.boolean being valid if you don't track the union
>> discriminator, and right now, the union discriminator is tracked only
>> via opt->desc.
> 
> 
> Couldn't find a reliable way if the option is passed through
> opts_accept_any,
> just no way to check the option type.
> 

Like I said in 4/25, if the option is passed through opts_accept_any,
treat it as string only; and make the opt_get_bool function either
reject it outright, or to always do the string-to-bool conversion at the
time of the lookup:

if (opt->desc) {
    assert(opt->desc->type == QEMU_OPT_BOOL);
    return opt->value.boolean;
} else {
    code to parse opt->str
}


>>
> Could be if changing qemu_opt_get return value type, but just as said
> before,
> that will affect many codes.

Also, changing an existing function that returns 'const char *' into now
returning 'char *' will NOT break any callers if the semantics remain
unchanged (what WILL break is if the semantics change where the callers
must now free the result).  But in general, it should still be just fine
to have qemu_opt_get return 'const char *' even if the common helper
returns 'char *'.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc Chunyan Liu
  2014-03-10 19:52   ` Eric Blake
@ 2014-03-11 13:29   ` Stefan Hajnoczi
  2014-03-12  2:45     ` Chunyan Liu
  1 sibling, 1 reply; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 13:29 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> 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 <address@hidden>

The address should be <wdongxu@linux.vnet.ibm.com>.

Stefan

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter Chunyan Liu
@ 2014-03-11 14:06   ` Stefan Hajnoczi
  2014-03-17 19:29   ` Leandro Dorileo
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:06 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

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 <address@hidden>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  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(-)

Please change the commit message to "qemu-option: remove
QEMUOptionParameter".  Commit messages should have a prefix that
indicates which part of the codebase is affected.  And "remove" is more
specific than "cleanup".

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-03-11 14:12   ` Stefan Hajnoczi
  2014-03-11 15:28   ` Eric Blake
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:12 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:44PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
>  1 file changed, 26 insertions(+), 28 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 09/25] gluster.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 09/25] gluster.c: " Chunyan Liu
@ 2014-03-11 14:15   ` Stefan Hajnoczi
  2014-03-11 16:58   ` Eric Blake
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:15 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:45PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/gluster.c | 81 ++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 42 insertions(+), 39 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 10/25] iscsi.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 10/25] iscsi.c: " Chunyan Liu
@ 2014-03-11 14:17   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:17 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:46PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/iscsi.c | 29 ++++++++++++++---------------
>  1 file changed, 14 insertions(+), 15 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 11/25] qcow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 11/25] qcow.c: " Chunyan Liu
@ 2014-03-11 14:18   ` Stefan Hajnoczi
  2014-03-11 17:05   ` Eric Blake
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:18 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:47PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/qcow.c | 72 ++++++++++++++++++++++++++++++------------------------------
>  1 file changed, 36 insertions(+), 36 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 12/25] qcow2.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 12/25] qcow2.c: " Chunyan Liu
@ 2014-03-11 14:21   ` Stefan Hajnoczi
  2014-03-11 14:22   ` Stefan Hajnoczi
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:21 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:48PM +0800, Chunyan Liu wrote:
> @@ -1636,64 +1636,64 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
>      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;
> -        }
> -        options++;
> +    sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
> +    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
> +    backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
> +    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
> +        flags |= BLOCK_FLAG_ENCRYPT;
> +    }
> +    cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
> +                                         DEFAULT_CLUSTER_SIZE);
> +    buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
> +    if (!buf || !strcmp(buf, "off")) {
> +        prealloc = 0;
> +    } else if (!strcmp(buf, "metadata")) {
> +        prealloc = 1;
> +    } else {
> +        fprintf(stderr, "Invalid preallocation mode: '%s'\n", buf);

This should be error_setg(errp, "Invalid preallocation mode: '%s'",
options->value.s).

Please check the other patches too to ensure the error_setg() hasn't
been turned into fprintf().

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 12/25] qcow2.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 12/25] qcow2.c: " Chunyan Liu
  2014-03-11 14:21   ` Stefan Hajnoczi
@ 2014-03-11 14:22   ` Stefan Hajnoczi
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:22 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:48PM +0800, Chunyan Liu wrote:
> @@ -1622,11 +1622,11 @@ out:
>      return ret;
>  }
>  
> -static int qcow2_create(const char *filename, QEMUOptionParameter *options,
> -                        Error **errp)
> +static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
>  {
> -    const char *backing_file = NULL;
> -    const char *backing_fmt = NULL;
> +    char *backing_file = NULL;
> +    char *backing_fmt = NULL;
> +    char *buf;

It wouldn't hurt to initialize buf to NULL.  That way there is no chance
of introducing a bug by jumping to the error path before buf has been
initialized.

Stefan

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 13/25] qed.c: " Chunyan Liu
@ 2014-03-11 14:24   ` Stefan Hajnoczi
  2014-03-20  9:08     ` Chun Yan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:24 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:49PM +0800, Chunyan Liu wrote:
> diff --git a/block/qed.h b/block/qed.h
> index 5d65bea..b024751 100644
> --- a/block/qed.h
> +++ b/block/qed.h
> @@ -43,7 +43,7 @@
>   *
>   * All fields are little-endian on disk.
>   */
> -
> +#define  QED_DEFAULT_CLUSTER_SIZE  65536
>  enum {
>      QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24,
>  
> @@ -69,7 +69,6 @@ enum {
>       */
>      QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */
>      QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024,
> -    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024,

Why is this change made for cluster size but not table size?

Stefan

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 14/25] raw-posix.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 14/25] raw-posix.c: " Chunyan Liu
@ 2014-03-11 14:25   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:25 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:50PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/raw-posix.c | 59 +++++++++++++++++++++++++------------------------------
>  1 file changed, 27 insertions(+), 32 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 15/25] raw-win32.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 15/25] raw-win32.c: " Chunyan Liu
@ 2014-03-11 14:41   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:41 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:51PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/raw-win32.c | 38 +++++++++++++++++++-------------------
>  1 file changed, 19 insertions(+), 19 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: " Chunyan Liu
@ 2014-03-11 14:44   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:44 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:52PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/raw_bsd.c | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)
> 
> diff --git a/block/raw_bsd.c b/block/raw_bsd.c
> index 9ae5fc2..ee797fd 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"
> -    },
> -    { 0 }
> +static QemuOptsList raw_create_opts = {
> +    .name = "raw-create-opts",
> +    .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
> +    .desc = {
> +        {
> +            .name = BLOCK_OPT_SIZE,
> +            .type = QEMU_OPT_SIZE,
> +            .help = "Virtual disk size"
> +        },
> +        { /* end of list */ }
> +    }
>  };

Hmm...I'm not sure how this works.  The option isn't consumed so maybe
we don't need to declare it at all.  However, it's not your problem
because it was like this before already.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 17/25] rbd.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 17/25] rbd.c: " Chunyan Liu
@ 2014-03-11 14:46   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 14:46 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:53PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/rbd.c | 63 +++++++++++++++++++++++++++++--------------------------------
>  1 file changed, 30 insertions(+), 33 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
  2014-03-11 14:12   ` Stefan Hajnoczi
@ 2014-03-11 15:28   ` Eric Blake
  2014-03-20  6:56     ` Chunyan Liu
  1 sibling, 1 reply; 105+ messages in thread
From: Eric Blake @ 2014-03-11 15:28 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
>  1 file changed, 26 insertions(+), 28 deletions(-)
> 

> @@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
>      .bdrv_probe     = cow_probe,
>      .bdrv_open      = cow_open,
>      .bdrv_close     = cow_close,
> -    .bdrv_create    = cow_create,
> +    .bdrv_create2   = cow_create,
>      .bdrv_has_zero_init     = bdrv_has_zero_init_1,
>  
>      .bdrv_read              = cow_co_read,
>      .bdrv_write             = cow_co_write,
>      .bdrv_co_get_block_status   = cow_co_get_block_status,
>  
> -    .create_options = cow_create_options,
> +    .create_opts       = &cow_create_opts,

Inconsistent alignment of =, and inconsistent use of & (it is not needed
here, '.create_opts = cow_create_opts' is just fine).

But those are both minor;

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 18/25] sheepdog.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 18/25] sheepdog.c: " Chunyan Liu
@ 2014-03-11 16:01   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 16:01 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:54PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/sheepdog.c | 108 ++++++++++++++++++++++++++++---------------------------
>  1 file changed, 55 insertions(+), 53 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 19/25] ssh.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 19/25] ssh.c: " Chunyan Liu
@ 2014-03-11 16:01   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 16:01 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:55PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/ssh.c | 32 +++++++++++++++-----------------
>  1 file changed, 15 insertions(+), 17 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
  2014-03-11  4:34   ` Eric Blake
@ 2014-03-11 16:54   ` Eric Blake
  2014-03-12  6:26     ` Chunyan Liu
  1 sibling, 1 reply; 105+ messages in thread
From: Eric Blake @ 2014-03-11 16:54 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 11919 bytes --]

On 03/10/2014 01:31 AM, 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 <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---

>  int bdrv_create(BlockDriver *drv, const char* filename,
> -    QEMUOptionParameter *options, Error **errp)
> +    QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
>  {
>      int ret;

In addition to my remarks last night:

I wonder if you should add:

assert(!(options && opts))

to prove that all callers are passing at most one of the two supported
option lists, while doing the conversion.

> @@ -5248,28 +5266,31 @@ 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);
> +    if (drv->bdrv_create2) {
> +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> +        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);

In addition to the memory leak I pointed out earlier, I see another
potential problem: What if drv has been converted to QemuOpts, but
proto_drv is still on QEMUOptionParameter?

> +    } else {
> +        create_options = append_option_parameters(create_options,
> +                                                  drv->create_options);
> +        create_options = append_option_parameters(create_options,
> +                                                  proto_drv->create_options);

Or the converse, if drv is still on QEMUOptionParameter, but proto_drv
has been converted to QEMUOpts?

Either way, you will be appending NULL for the proto_drv case, when what
you really wanted to be doing was merging both the QemuOpts and
QEMUOptionParameters into a single list.

> +        create_opts = params_to_opts(create_options);
> +    }

I think a better path to conversion would be doing everything possible
in QemuOpts, and only switching to QEMUOptionParameters at the last
possible moment, rather than having two separate append code paths.

My suggestion: until the conversion is complete, add a new function,
something like:

void qemu_opts_append_pair(QemuOpts *dst, QemuOpts *opts,
                           QEMUOptionParameter *options) {
    assert(!(opts && options));
    ... modify dst in-place to have it cover the entries from opts or
options
}

then in this code, you do:
    create_options = /* generate empty QemuOpts */;
    qemu_opts_append_pair(options, drv->create_opts,
                          drv->create_options);
    qemu_opts_append_pair(options, proto_drv->create_options,
                          proto_drv->create_options);

>  
>      /* Create parameter list with default values */
> -    param = parse_option_parameters("", create_options, param);
> -
> -    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
> +    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> +    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);

This part worked nicely - once you convert both incoming styles to
QemuOpts, it really is easier to have this part of the code just use
QemuOpts functions for setting the size....

> ...
> @@ -5343,16 +5364,23 @@ void bdrv_img_create(const char *filename, const char *fmt,
>  
>      if (!quiet) {
>          printf("Formatting '%s', fmt=%s ", filename, fmt);
> -        print_option_parameters(param);
> +        qemu_opts_print(opts);
>          puts("");
>      }
> -    ret = bdrv_create(drv, filename, param, &local_err);
> +
> +    if (drv->bdrv_create2) {
> +        ret = bdrv_create(drv, filename, NULL, opts, &local_err);
> +    } else {
> +        param = opts_to_params(opts);
> +        ret = bdrv_create(drv, filename, param, NULL, &local_err);
> +    }

...and finally convert back to QEMUOptionParameters at the last moment.
 But wait a minute - why are you checking for drv->bdrv_create2 here?
Isn't the last possible moment really inside bdrv_create() (that is, the
actual function that decides whether to call drv->bdrv_create vs.
drv->bdrv_create2)?  For the code to be as clean as possible, you want
to use QemuOpts everywhere until the actual point where you are calling
the unconverted callback.


> -int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
> +int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
> +                       QemuOpts *opts)
>  {
> -    if (bs->drv->bdrv_amend_options == NULL) {
> +    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
>          return -ENOTSUP;
>      }
> -    return bs->drv->bdrv_amend_options(bs, options);
> +    if (bs->drv->bdrv_amend_options2) {
> +        return bs->drv->bdrv_amend_options2(bs, opts);
> +    } else {
> +        return bs->drv->bdrv_amend_options(bs, options);

Similar to the create/create2 situation, _this_ function is the last
possible place to make the conversions.  You have a problem in that if
the user passes you options but the callback expects opts, you are
passing NULL to the callback.  I think this should look more like:

int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
                       QemuOpts *opts)
{
    int ret;
    assert(!(opts && options));
    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
        return -ENOTSUP;
    }
    if (bs->drv->bdrv_amend_options2) {
        if (options) {
            opts = params_to_opts(options);
        }
        ret = bs->drv->bdrv_amend_options2(bs, opts);
        if (options) {
            g_free(opts); // or whatever correct spelling to avoid leak
        }
    } else {
        if (opts) {
            options = opts_to_params(opts);
        }
        ret = bs->drv->bdrv_amend_options(bs, options);
        if (opts) {
            g_free(options); // again, with correct spelling
        }
    }
    return ret;

> +++ b/include/block/block_int.h
> @@ -118,6 +118,8 @@ struct BlockDriver {
>      void (*bdrv_rebind)(BlockDriverState *bs);
>      int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
>                         Error **errp);
> +    /* FIXME: will remove the duplicate and rename back to bdrv_create later */
> +    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error **errp);

I like the FIXME here; maybe also mention that bdrv_create and
bdrv_create2 are mutually exclusive (at most one can be non-NULL).

>      int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
>      int (*bdrv_make_empty)(BlockDriverState *bs);
>      /* aio */
> @@ -217,7 +219,7 @@ struct BlockDriver {
>  
>      /* List of options for creating images, terminated by name == NULL */
>      QEMUOptionParameter *create_options;
> -
> +    QemuOptsList *create_opts;

A similar FIXME comment here might be nice, likewise mentioning that at
most one of these two fields should be non-NULL.

> @@ -244,21 +245,34 @@ 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 (drv->create_opts) {
> +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> +    } else {
> +        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);
> +        if (drv->create_opts) {
> +            create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);

Memory leak.

> +        } else {
> +            create_options =
> +                append_option_parameters(create_options,
> +                                         proto_drv->create_options);
> +        }
>      }
>  
> -    print_option_help(create_options);
> +    if (drv->create_opts) {
> +        qemu_opts_print_help(create_opts);
> +    } else {
> +        print_option_help(create_options);
> +    }

Another case where if you add a new helper function that absorbs either
style of options into a QemuOpts, then all you have to do here is print
the QemuOpts, instead of trying to switch between print methods here.


> @@ -1340,40 +1356,42 @@ static int img_convert(int argc, char **argv)
>          goto out;
>      }

> -        }
> +    if (drv->bdrv_create2) {
> +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> +        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);

More memory leaks.


> @@ -1400,7 +1418,12 @@ static int img_convert(int argc, char **argv)
>  
>      if (!skip_create) {
>          /* Create the new image */
> -        ret = bdrv_create(drv, out_filename, param, &local_err);
> +        if (drv->bdrv_create2) {
> +            ret = bdrv_create(drv, out_filename, NULL, opts, &local_err);
> +        } else {
> +            param = opts_to_params(opts);
> +            ret = bdrv_create(drv, out_filename, param, NULL, &local_err);
> +        }

Another case where you should just always pass opts to bdrv_create(),
and let bdrv_create() do the last minute conversion to
QEMUOptionParameters based on what callbacks drv supports, rather than
trying to make decisions here based on contents of drv.


> @@ -2721,17 +2748,26 @@ 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) {
> +    if (bs->drv->bdrv_amend_options2) {

And again, you should not be making decisions on the contents of
bs->drv, but just blindly setting up QemuOpts here...

> +        create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
> +    } else {
> +        create_options = append_option_parameters(create_options,
> +                                                  bs->drv->create_options);
> +        create_opts = params_to_opts(create_options);
> +    }
> +    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> +    if (options && qemu_opts_do_parse(opts, options, NULL)) {
>          error_report("Invalid options for file format '%s'", fmt);
>          ret = -1;
>          goto out;
>      }
>  
> -    ret = bdrv_amend_options(bs, options_param);
> +    if (bs->drv->bdrv_amend_options2) {
> +        ret = bdrv_amend_options(bs, NULL, opts);
> +    } else {
> +        options_param = opts_to_params(opts);
> +        ret = bdrv_amend_options(bs, options_param, NULL);

...and blindly letting bdrv_amend_options() be the place that converts
to QEMUOptionParameters as needed.

Here's hoping v23 is nicer; I'm looking forward to ditching
QEMUOptionParameters.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 09/25] gluster.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 09/25] gluster.c: " Chunyan Liu
  2014-03-11 14:15   ` Stefan Hajnoczi
@ 2014-03-11 16:58   ` Eric Blake
  1 sibling, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-11 16:58 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 783 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/gluster.c | 81 ++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 42 insertions(+), 39 deletions(-)
> 

> @@ -726,7 +729,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_opts                  = &qemu_gluster_create_opts,

Unnecessary &.  Probably true in most of your patches.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 11/25] qcow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 11/25] qcow.c: " Chunyan Liu
  2014-03-11 14:18   ` Stefan Hajnoczi
@ 2014-03-11 17:05   ` Eric Blake
  1 sibling, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-11 17:05 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/qcow.c | 72 ++++++++++++++++++++++++++++++------------------------------
>  1 file changed, 36 insertions(+), 36 deletions(-)

See my comments on patch 24 - this commit temporarily breaks the vvfat
driver, which is trying to reuse the qcow create_options member.

> @@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = {
>      .bdrv_write_compressed  = qcow_write_compressed,
>      .bdrv_get_info          = qcow_get_info,
>  
> -    .create_options = qcow_create_options,
> +    .create_opts            = &qcow_create_opts,
>  };
>  
>  static void bdrv_qcow_init(void)
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 24/25] vvfat.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 24/25] vvfat.c: " Chunyan Liu
@ 2014-03-11 17:06   ` Eric Blake
  2014-03-11 18:01   ` Stefan Hajnoczi
  1 sibling, 0 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-11 17:06 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: kwolf, Dong Xu Wang, stefanha

[-- Attachment #1: Type: text/plain, Size: 1512 bytes --]

On 03/10/2014 01:32 AM, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/vvfat.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

>      bdrv_qcow = bdrv_find_format("qcow");
> -    options = parse_option_parameters("", bdrv_qcow->create_options, NULL);

Problem.  This code is broken from the time that patch 11/25 is applied
until now.  That's because commit 11 changed bdrv_qcow from having
create_options over to having create_opts.  Do any of the other drivers
do cross-driver option sharing?  It would be nice to fix that to quit
happening, preferably earlier in the series than where you start doing
per-driver conversions.

> -    set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
> -    set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
> +    opts = qemu_opts_create(bdrv_qcow->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);
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 20/25] vdi.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 20/25] vdi.c: " Chunyan Liu
@ 2014-03-11 17:50   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 17:50 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:56PM +0800, Chunyan Liu wrote:
> @@ -669,25 +668,17 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
>      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_del(opts, 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;
> -            }
> +    block_size = qemu_opt_get_size_del(opts,
> +                                       BLOCK_OPT_CLUSTER_SIZE,
> +                                       DEFAULT_CLUSTER_SIZE);

Please keep the TODO.

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 21/25] vmdk.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 21/25] vmdk.c: " Chunyan Liu
@ 2014-03-11 17:51   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 17:51 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:57PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/vmdk.c | 123 ++++++++++++++++++++++++++++++-----------------------------
>  1 file changed, 63 insertions(+), 60 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 22/25] vpc.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 22/25] vpc.c: " Chunyan Liu
@ 2014-03-11 17:55   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 17:55 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:58PM +0800, Chunyan Liu wrote:
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/vpc.c | 62 +++++++++++++++++++++++++++++++++----------------------------
>  1 file changed, 34 insertions(+), 28 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 23/25] vhdx.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 23/25] vhdx.c: " Chunyan Liu
@ 2014-03-11 17:56   ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 17:56 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:31:59PM +0800, Chunyan Liu wrote:
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/vhdx.c | 99 +++++++++++++++++++++++++++++-------------------------------
>  block/vhdx.h |  1 +
>  2 files changed, 48 insertions(+), 52 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 24/25] vvfat.c: replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 24/25] vvfat.c: " Chunyan Liu
  2014-03-11 17:06   ` Eric Blake
@ 2014-03-11 18:01   ` Stefan Hajnoczi
  1 sibling, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 18:01 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

On Mon, Mar 10, 2014 at 03:32:00PM +0800, Chunyan Liu wrote:
> -    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);

Who frees opts?

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (32 preceding siblings ...)
  2014-03-10 22:45 ` Eric Blake
@ 2014-03-11 18:03 ` Stefan Hajnoczi
  2014-03-21  0:07 ` Leandro Dorileo
  34 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 18:03 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

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.

Hi Chunyan,
Please add my Reviewed-by: tags to the commits so future revisions will
already have them.  If you change the code in a patch then please remove
the Reviewed-by: again.

This will help reviewers narrow down the scope of patches to review and
hopefully we'll soon be able to merge this series.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-11  7:26       ` Chunyan Liu
@ 2014-03-11 21:00         ` Leandro Dorileo
  2014-03-16 21:19           ` Leandro Dorileo
  0 siblings, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-11 21:00 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

Hi,

On Tue, Mar 11, 2014 at 03:26:51PM +0800, Chunyan Liu wrote:
> 2014-03-11 5:21 GMT+08:00 Eric Blake <eblake@redhat.com>:
> 
> > 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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-11 13:29   ` Stefan Hajnoczi
@ 2014-03-12  2:45     ` Chunyan Liu
  2014-03-12  8:27       ` Stefan Hajnoczi
  0 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-12  2:45 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 546 bytes --]

2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:

> On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > 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 <address@hidden>
>
> The address should be <wdongxu@linux.vnet.ibm.com>.
>

Seems this address is not valid now, so when sending patches with git
send-email, it's
changed to be <address@hidden> automatically.


> Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 1219 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-11 11:59       ` Eric Blake
@ 2014-03-12  3:10         ` Chunyan Liu
  2014-03-12 12:40           ` Eric Blake
  0 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-12  3:10 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 2474 bytes --]

2014-03-11 19:59 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/10/2014 11:29 PM, Chunyan Liu wrote:
> >>
> >> Why are your later callers using a common helper function, but
> >> qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()?
> >> Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common
> helper?
> >>
> >> qemu_opt_get_del must return (char *), but the existing qemu_opt_get
> > returns
> > (const char *). Could also change qemu_opt_get return value to (char *)
> > type,
> > then these two functions could use a common helper function. But there
> are
> > too
> > many places using qemu_opt_get already, if the return value type changes,
> > it will
> > affect a lot.
>
> Going from 'char *' to 'const char *' is automatic.  Have your helper
> return 'char *', and qemu_opt_get can call it just fine and give its
> callers their desired const char *.
>
> >>
> >> Same problem as in 4/25 - I don't think you can rely on
> >> opt->value.boolean being valid if you don't track the union
> >> discriminator, and right now, the union discriminator is tracked only
> >> via opt->desc.
> >
> >
> > Couldn't find a reliable way if the option is passed through
> > opts_accept_any,
> > just no way to check the option type.
> >
>
> Like I said in 4/25, if the option is passed through opts_accept_any,
> treat it as string only; and make the opt_get_bool function either
> reject it outright, or to always do the string-to-bool conversion at the
> time of the lookup:
>
> if (opt->desc) {
>     assert(opt->desc->type == QEMU_OPT_BOOL);
>     return opt->value.boolean;
> } else {
>     code to parse opt->str
> }
>
>
> >>
> > Could be if changing qemu_opt_get return value type, but just as said
> > before,
> > that will affect many codes.
>
> Also, changing an existing function that returns 'const char *' into now
> returning 'char *' will NOT break any callers if the semantics remain
> unchanged (what WILL break is if the semantics change where the callers
> must now free the result)


Yes, that's the only change, we need to free the result. There are more
than 200
places using qemu_opt_get in existing code, we need to checkout the related
files
and free the result one by one.


>  But in general, it should still be just fine
> to have qemu_opt_get return 'const char *' even if the common helper
> returns 'char *'.
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 3633 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter
  2014-03-11 16:54   ` Eric Blake
@ 2014-03-12  6:26     ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-12  6:26 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 12498 bytes --]

2014-03-12 0:54 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/10/2014 01:31 AM, 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 <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
>
> >  int bdrv_create(BlockDriver *drv, const char* filename,
> > -    QEMUOptionParameter *options, Error **errp)
> > +    QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
> >  {
> >      int ret;
>
> In addition to my remarks last night:
>
> I wonder if you should add:
>
> assert(!(options && opts))
>
> to prove that all callers are passing at most one of the two supported
> option lists, while doing the conversion.
>
> > @@ -5248,28 +5266,31 @@ 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);
> > +    if (drv->bdrv_create2) {
> > +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> > +        create_opts = qemu_opts_append(create_opts,
> proto_drv->create_opts);
>
> In addition to the memory leak I pointed out earlier,


Should use g_realloc in qemu_opts_append, realloc create_opts
to the desired space and append 2nd list to it. Saving the effort to free
memory while append many times.

I see another
> potential problem: What if drv has been converted to QemuOpts, but
> proto_drv is still on QEMUOptionParameter?
>

> > +    } else {
> > +        create_options = append_option_parameters(create_options,
> > +                                                  drv->create_options);
> > +        create_options = append_option_parameters(create_options,
> > +
>  proto_drv->create_options);
>
> Or the converse, if drv is still on QEMUOptionParameter, but proto_drv
> has been converted to QEMUOpts?
>
> Either way, you will be appending NULL for the proto_drv case, when what
> you really wanted to be doing was merging both the QemuOpts and
> QEMUOptionParameters into a single list.
>
> > +        create_opts = params_to_opts(create_options);
> > +    }
>
> I think a better path to conversion would be doing everything possible
> in QemuOpts, and only switching to QEMUOptionParameters at the last
> possible moment, rather than having two separate append code paths.
>
> My suggestion: until the conversion is complete, add a new function,
> something like:
>
> void qemu_opts_append_pair(QemuOpts *dst, QemuOpts *opts,
>                            QEMUOptionParameter *options) {
>     assert(!(opts && options));
>     ... modify dst in-place to have it cover the entries from opts or
> options
> }
>
> then in this code, you do:
>     create_options = /* generate empty QemuOpts */;
>     qemu_opts_append_pair(options, drv->create_opts,
>                           drv->create_options);
>     qemu_opts_append_pair(options, proto_drv->create_options,
>                           proto_drv->create_options);
>
>
Good. Together with always using QemuOpts and only converting to
QEMUOptionParameter until it calls .bdrv_create in specific driver,
the drv/proto_drv inconsistent problem could be solved.
Will update.

Thanks very much for all your suggestions!

Chunyan

>
> >      /* Create parameter list with default values */
> > -    param = parse_option_parameters("", create_options, param);
> > -
> > -    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
> > +    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> > +    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);
>
> This part worked nicely - once you convert both incoming styles to
> QemuOpts, it really is easier to have this part of the code just use
> QemuOpts functions for setting the size....
>
> > ...
> > @@ -5343,16 +5364,23 @@ void bdrv_img_create(const char *filename, const
> char *fmt,
> >
> >      if (!quiet) {
> >          printf("Formatting '%s', fmt=%s ", filename, fmt);
> > -        print_option_parameters(param);
> > +        qemu_opts_print(opts);
> >          puts("");
> >      }
> > -    ret = bdrv_create(drv, filename, param, &local_err);
> > +
> > +    if (drv->bdrv_create2) {
> > +        ret = bdrv_create(drv, filename, NULL, opts, &local_err);
> > +    } else {
> > +        param = opts_to_params(opts);
> > +        ret = bdrv_create(drv, filename, param, NULL, &local_err);
> > +    }
>
> ...and finally convert back to QEMUOptionParameters at the last moment.
>  But wait a minute - why are you checking for drv->bdrv_create2 here?
> Isn't the last possible moment really inside bdrv_create() (that is, the
> actual function that decides whether to call drv->bdrv_create vs.
> drv->bdrv_create2)?  For the code to be as clean as possible, you want
> to use QemuOpts everywhere until the actual point where you are calling
> the unconverted callback.
>
>
> > -int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter
> *options)
> > +int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter
> *options,
> > +                       QemuOpts *opts)
> >  {
> > -    if (bs->drv->bdrv_amend_options == NULL) {
> > +    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
> >          return -ENOTSUP;
> >      }
> > -    return bs->drv->bdrv_amend_options(bs, options);
> > +    if (bs->drv->bdrv_amend_options2) {
> > +        return bs->drv->bdrv_amend_options2(bs, opts);
> > +    } else {
> > +        return bs->drv->bdrv_amend_options(bs, options);
>
> Similar to the create/create2 situation, _this_ function is the last
> possible place to make the conversions.  You have a problem in that if
> the user passes you options but the callback expects opts, you are
> passing NULL to the callback.  I think this should look more like:
>
> int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
>                        QemuOpts *opts)
> {
>     int ret;
>     assert(!(opts && options));
>     if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
>         return -ENOTSUP;
>     }
>     if (bs->drv->bdrv_amend_options2) {
>         if (options) {
>             opts = params_to_opts(options);
>         }
>         ret = bs->drv->bdrv_amend_options2(bs, opts);
>         if (options) {
>             g_free(opts); // or whatever correct spelling to avoid leak
>         }
>     } else {
>         if (opts) {
>             options = opts_to_params(opts);
>         }
>         ret = bs->drv->bdrv_amend_options(bs, options);
>         if (opts) {
>             g_free(options); // again, with correct spelling
>         }
>     }
>     return ret;
>
> > +++ b/include/block/block_int.h
> > @@ -118,6 +118,8 @@ struct BlockDriver {
> >      void (*bdrv_rebind)(BlockDriverState *bs);
> >      int (*bdrv_create)(const char *filename, QEMUOptionParameter
> *options,
> >                         Error **errp);
> > +    /* FIXME: will remove the duplicate and rename back to bdrv_create
> later */
> > +    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error
> **errp);
>
> I like the FIXME here; maybe also mention that bdrv_create and
> bdrv_create2 are mutually exclusive (at most one can be non-NULL).
>
> >      int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
> >      int (*bdrv_make_empty)(BlockDriverState *bs);
> >      /* aio */
> > @@ -217,7 +219,7 @@ struct BlockDriver {
> >
> >      /* List of options for creating images, terminated by name == NULL
> */
> >      QEMUOptionParameter *create_options;
> > -
> > +    QemuOptsList *create_opts;
>
> A similar FIXME comment here might be nice, likewise mentioning that at
> most one of these two fields should be non-NULL.
>
> > @@ -244,21 +245,34 @@ 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 (drv->create_opts) {
> > +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> > +    } else {
> > +        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);
> > +        if (drv->create_opts) {
> > +            create_opts = qemu_opts_append(create_opts,
> proto_drv->create_opts);
>
> Memory leak.
>
> > +        } else {
> > +            create_options =
> > +                append_option_parameters(create_options,
> > +                                         proto_drv->create_options);
> > +        }
> >      }
> >
> > -    print_option_help(create_options);
> > +    if (drv->create_opts) {
> > +        qemu_opts_print_help(create_opts);
> > +    } else {
> > +        print_option_help(create_options);
> > +    }
>
> Another case where if you add a new helper function that absorbs either
> style of options into a QemuOpts, then all you have to do here is print
> the QemuOpts, instead of trying to switch between print methods here.
>
>
> > @@ -1340,40 +1356,42 @@ static int img_convert(int argc, char **argv)
> >          goto out;
> >      }
>
> > -        }
> > +    if (drv->bdrv_create2) {
> > +        create_opts = qemu_opts_append(create_opts, drv->create_opts);
> > +        create_opts = qemu_opts_append(create_opts,
> proto_drv->create_opts);
>
> More memory leaks.
>
>
> > @@ -1400,7 +1418,12 @@ static int img_convert(int argc, char **argv)
> >
> >      if (!skip_create) {
> >          /* Create the new image */
> > -        ret = bdrv_create(drv, out_filename, param, &local_err);
> > +        if (drv->bdrv_create2) {
> > +            ret = bdrv_create(drv, out_filename, NULL, opts,
> &local_err);
> > +        } else {
> > +            param = opts_to_params(opts);
> > +            ret = bdrv_create(drv, out_filename, param, NULL,
> &local_err);
> > +        }
>
> Another case where you should just always pass opts to bdrv_create(),
> and let bdrv_create() do the last minute conversion to
> QEMUOptionParameters based on what callbacks drv supports, rather than
> trying to make decisions here based on contents of drv.
>
>
> > @@ -2721,17 +2748,26 @@ 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) {
> > +    if (bs->drv->bdrv_amend_options2) {
>
> And again, you should not be making decisions on the contents of
> bs->drv, but just blindly setting up QemuOpts here...
>
> > +        create_opts = qemu_opts_append(create_opts,
> bs->drv->create_opts);
> > +    } else {
> > +        create_options = append_option_parameters(create_options,
> > +
>  bs->drv->create_options);
> > +        create_opts = params_to_opts(create_options);
> > +    }
> > +    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> > +    if (options && qemu_opts_do_parse(opts, options, NULL)) {
> >          error_report("Invalid options for file format '%s'", fmt);
> >          ret = -1;
> >          goto out;
> >      }
> >
> > -    ret = bdrv_amend_options(bs, options_param);
> > +    if (bs->drv->bdrv_amend_options2) {
> > +        ret = bdrv_amend_options(bs, NULL, opts);
> > +    } else {
> > +        options_param = opts_to_params(opts);
> > +        ret = bdrv_amend_options(bs, options_param, NULL);
>
> ...and blindly letting bdrv_amend_options() be the place that converts
> to QEMUOptionParameters as needed.
>
> Here's hoping v23 is nicer; I'm looking forward to ditching
> QEMUOptionParameters.
>

> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 16909 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions
  2014-03-10 21:44   ` Eric Blake
@ 2014-03-12  6:34     ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-12  6:34 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 3814 bytes --]

2014-03-11 5:44 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> > In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is
> true, it
>
> s/doen't/doesn't/
>
> I mentioned the same problem against v20.  It is very depressing when
> review comments are not addressed.
>
> > won't report error, but can still alloc an opt for the option and save
> it.
> > However, after that, when doing qemu_opt_get, this option could be found
> in opts
> > but opt->desc is NULL. This is correct, should not be treated as error.
> >
> > This patch would fix vvfat issue after changing to QemuOpts.
> >
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  util/qemu-option.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/util/qemu-option.c b/util/qemu-option.c
> > index c7639e8..df79235 100644
> > --- a/util/qemu-option.c
> > +++ b/util/qemu-option.c
> > @@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char
> *name, bool defval)
> >          }
> >          return defval;
> >      }
> > -    assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
> > +    if (opt->desc) {
> > +        assert(opt->desc->type == QEMU_OPT_BOOL);
> > +    }
> >      return opt->value.boolean;
>
> I'm not sure I like this.  opt->value is a union, but opt_set() does NOT
> populate the union when opts_accepts_any() fails.  Previously, we were
> using opt->desc->type as the discriminator for which branch of the union
> is valid.  But with your patch, if an option was set as a string, but
> then queried as a boolean, we may be reading bogus contents from the
> union.  Or even worse, if someone sets the uint member of the union to
> 0x100000000 via qemu_opt_set_number(), then later calls
> qemu_opt_get_bool, the boolean member _might_ read as true on some
> platforms and false on others, depending on things such as host endianness.
>
> How is vvfat broken without this patch?  That is, what specific option
> are you setting without specifying its type, that later triggers the
> assertion when you try to get the option via a specific type?
>

Well, now I think it caused by drv (vvfat.c) and proto_drv (raw-posix.c) not
consistent, one is using QemuOpts, the other is using QEMUOptionParameter.
That will cause create_opts became NULL, then when passing a size option,
qemu_opt_set_size is OK, but later qemu_opt_get_size will segment fault.
After solving the drv/proto_drv consistent issue, this problem won't happen.
So, in this patch series, this place could not be changed.

( But with opts_accept_any, I still think this place may bring problem some
time
 in future.)


>
> I'm wondering if the fix should look more like:
>
> if (opt->desc) {
>     assert(opt->desc->type == QEMU_OPT_BOOL);
>     return opt->value.boolean;
> } else {
>     code to parse opt->str
> }
>
> so that you are not dereferencing an undefined state of the union.
>
> > @@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const
> char *name, uint64_t defval)
> >          }
> >          return defval;
> >      }
> > -    assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
> > +    if (opt->desc) {
> > +        assert(opt->desc->type == QEMU_OPT_NUMBER);
> > +    }
> >      return opt->value.uint;
> >  }
> >
> > @@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const
> char *name, uint64_t defval)
> >          }
> >          return defval;
> >      }
> > -    assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
> > +    if (opt->desc) {
> > +        assert(opt->desc->type == QEMU_OPT_SIZE);
> > +    }
> >      return opt->value.uint;
>
> Same problem in these two spots.
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 5228 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-10 21:21     ` Eric Blake
  2014-03-11  7:26       ` Chunyan Liu
@ 2014-03-12  6:49       ` Chunyan Liu
  1 sibling, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-12  6:49 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 3060 bytes --]

2014-03-11 5:21 GMT+08:00 Eric Blake <eblake@redhat.com>:

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

 In qemu_opt_find(), it uses:
 QTAILQ_FOREACH_REVERSE(),
 so that means find the last setting, the same result with replacement.


> Post-patch, I get a compilation error (so how did you test your patch?):
>
> qapi/opts-visitor.c: In function ‘opts_start_struct’:
> qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier
> from pointer target type [-Werror]
>          ov->fake_id_opt->name = "id";
>                                ^
>
> If I press on in spite of that warning, then I get the same behavior
> where the last type= still wins on behavior.  So I'm not sure how it all
> worked, but at least behavior wise, my one test didn't uncover a
> regression.
>
> Still, I'd feel a LOT better with a testsuite of what QemuOpts is
> supposed to be able to do.  tests/test-opts-visitor.c was the only file
> in tests/ that even mentions QemuOpts.
>



>
> >> @@ -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)
> >
> >> +    opt = qemu_opt_find(opts, name);
> >> +    if (opt) {
> >> +        g_free((char *)opt->str);
> >
> > Another pointless cast.
>
> Maybe not pointless, if you end up not removing the const in the struct
> declaration due to the compile error; but that brings me back to my
> earlier question - since the compiler error proves that we have places
> that are assigning compile-time string constants into the name field, we
> must NOT call g_free on those copies - how does your code distinguish
> between a QemuOpt that is built up by mallocs, vs. one that is described
> by compile-time constants?
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 4233 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-12  2:45     ` Chunyan Liu
@ 2014-03-12  8:27       ` Stefan Hajnoczi
  2014-03-13  2:46         ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-12  8:27 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel

On Wed, Mar 12, 2014 at 10:45:57AM +0800, Chunyan Liu wrote:
> 2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:
> 
> > On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > > 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 <address@hidden>
> >
> > The address should be <wdongxu@linux.vnet.ibm.com>.
> >
> 
> Seems this address is not valid now, so when sending patches with git
> send-email, it's
> changed to be <address@hidden> automatically.

That sounds weird.  Are you sure it's not because you grabbed the
patches from a web mailing list archive that hides email address to
avoid spammers?

See git-send-email(1) --suppress-cc to avoid sending the patch to his
old address.  Since we don't have a new address, please keep
wdongxu@linux.vnet.ibm.com.

Stefan

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-12  3:10         ` Chunyan Liu
@ 2014-03-12 12:40           ` Eric Blake
  2014-03-13  5:16             ` Chunyan Liu
  2014-03-18  5:34             ` Chunyan Liu
  0 siblings, 2 replies; 105+ messages in thread
From: Eric Blake @ 2014-03-12 12:40 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]

On 03/11/2014 09:10 PM, Chunyan Liu wrote:

>>>>
>>> Could be if changing qemu_opt_get return value type, but just as said
>>> before,
>>> that will affect many codes.
>>
>> Also, changing an existing function that returns 'const char *' into now
>> returning 'char *' will NOT break any callers if the semantics remain
>> unchanged (what WILL break is if the semantics change where the callers
>> must now free the result)
> 
> 
> Yes, that's the only change, we need to free the result. There are more
> than 200
> places using qemu_opt_get in existing code, we need to checkout the related
> files
> and free the result one by one.

You can still write your helper function so that if 'del' is true, you
strdup, if 'del' is false, you return the in-place memory.  You'll have
to cast away const in the helper, but qemu_opt_get can then restore the
const and you don't have to adjust any existing callers, while still
sharing the underlying implementation rather than duplicating code.  But
I guess I'll wait for v23 to see what you actually do in response to my
suggestions.  If nothing else, please document design decisions in your
commit message (for example, if you choose to duplicate code rather than
share code in a common helper, explain that the duplication is because
one function returns malloc'd memory while the other returns in-place
memory).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-12  8:27       ` Stefan Hajnoczi
@ 2014-03-13  2:46         ` Chunyan Liu
  2014-03-13 12:13           ` Stefan Hajnoczi
  0 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-13  2:46 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

2014-03-12 16:27 GMT+08:00 Stefan Hajnoczi <stefanha@redhat.com>:

> On Wed, Mar 12, 2014 at 10:45:57AM +0800, Chunyan Liu wrote:
> > 2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:
> >
> > > On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > > > 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 <address@hidden>
> > >
> > > The address should be <wdongxu@linux.vnet.ibm.com>.
> > >
> >
> > Seems this address is not valid now, so when sending patches with git
> > send-email, it's
> > changed to be <address@hidden> automatically.
>
> That sounds weird.  Are you sure it's not because you grabbed the
> patches from a web mailing list archive that hides email address to
> avoid spammers?
>

Absolutely no. In previous version, no such problem. Only in this version,
while
doing "git send-email", got the message about "email delivery failed", and
the
address changed. I'll still keep this address in new version patch series:
 wdongxu@linux.vnet.ibm.com


>
> See git-send-email(1) --suppress-cc to avoid sending the patch to his
> old address.  Since we don't have a new address, please keep
> wdongxu@linux.vnet.ibm.com.
>

OK.


>
> Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 2529 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-12 12:40           ` Eric Blake
@ 2014-03-13  5:16             ` Chunyan Liu
  2014-03-18  5:34             ` Chunyan Liu
  1 sibling, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-13  5:16 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 1613 bytes --]

2014-03-12 20:40 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/11/2014 09:10 PM, Chunyan Liu wrote:
>
> >>>>
> >>> Could be if changing qemu_opt_get return value type, but just as said
> >>> before,
> >>> that will affect many codes.
> >>
> >> Also, changing an existing function that returns 'const char *' into now
> >> returning 'char *' will NOT break any callers if the semantics remain
> >> unchanged (what WILL break is if the semantics change where the callers
> >> must now free the result)
> >
> >
> > Yes, that's the only change, we need to free the result. There are more
> > than 200
> > places using qemu_opt_get in existing code, we need to checkout the
> related
> > files
> > and free the result one by one.
>
> You can still write your helper function so that if 'del' is true, you
> strdup, if 'del' is false, you return the in-place memory.  You'll have
> to cast away const in the helper, but qemu_opt_get can then restore the
> const and you don't have to adjust any existing callers, while still
> sharing the underlying implementation rather than duplicating code.  But
> I guess I'll wait for v23 to see what you actually do in response to my
> suggestions.  If nothing else, please document design decisions in your
> commit message (for example, if you choose to duplicate code rather than
> share code in a common helper, explain that the duplication is because
> one function returns malloc'd memory while the other returns in-place
> memory).
>
> Got it. Thanks.


> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 2532 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc
  2014-03-13  2:46         ` Chunyan Liu
@ 2014-03-13 12:13           ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-13 12:13 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel

On Thu, Mar 13, 2014 at 10:46:45AM +0800, Chunyan Liu wrote:
> 2014-03-12 16:27 GMT+08:00 Stefan Hajnoczi <stefanha@redhat.com>:
> 
> > On Wed, Mar 12, 2014 at 10:45:57AM +0800, Chunyan Liu wrote:
> > > 2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:
> > >
> > > > On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > > > > 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 <address@hidden>
> > > >
> > > > The address should be <wdongxu@linux.vnet.ibm.com>.
> > > >
> > >
> > > Seems this address is not valid now, so when sending patches with git
> > > send-email, it's
> > > changed to be <address@hidden> automatically.
> >
> > That sounds weird.  Are you sure it's not because you grabbed the
> > patches from a web mailing list archive that hides email address to
> > avoid spammers?
> >
> 
> Absolutely no. In previous version, no such problem. Only in this version,
> while
> doing "git send-email", got the message about "email delivery failed", and
> the
> address changed. I'll still keep this address in new version patch series:
>  wdongxu@linux.vnet.ibm.com

I don't think the change comes from git:
$ git clone https://github.com/git/git.git
$ cd git && git grep 'address@hidden'

(Even grepping for 'hidden' doesn't show any relevant hits.)

I'm on CC list for these patches, so the emails are sent directly to my
SMTP server.  Since they go directly and not via the mailing list, we
can eliminate the mailing list software.

The mailing list archive also shows <address@hidden> so that eliminates
my SMTP server:
http://article.gmane.org/gmane.comp.emulators.qemu/260626

Do you see <address@hidden> in git-log(1)?

If yes, then maybe it's possible to track it down via git-reflog(1).  If
no, then it's happening while the mail is being sent.

Stefan

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-11 21:00         ` Leandro Dorileo
@ 2014-03-16 21:19           ` Leandro Dorileo
  2014-03-18  7:41             ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-16 21:19 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, stefanha

Hi Chunyan,

On Tue, Mar 11, 2014 at 09:00:04PM +0000, 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 <eblake@redhat.com>:
> > 
> > > 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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter
  2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter Chunyan Liu
  2014-03-11 14:06   ` Stefan Hajnoczi
@ 2014-03-17 19:29   ` Leandro Dorileo
  2014-03-17 19:43     ` Leandro Dorileo
  1 sibling, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-17 19:29 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

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 <address@hidden>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work Chunyan Liu
  2014-03-10 23:28   ` Eric Blake
@ 2014-03-17 19:35   ` Leandro Dorileo
  2014-03-18  3:03     ` Chunyan Liu
  1 sibling, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-17 19:35 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

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 <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  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 ? opt->str : NULL;
>  }
>  
> +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 = g_strdup(opt->str);
> +    qemu_opt_del(opt);
> +    return str;
> +}
> +
>  bool qemu_opt_has_help_opt(QemuOpts *opts)
>  {
>      QemuOpt *opt;
> @@ -586,9 +678,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
>      return false;
>  }
>  
> -bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> +static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,
> +                               bool defval, bool del)
>  {
>      QemuOpt *opt;
> +    bool ret = defval;
>  
>      if (opts == NULL) {
>          return defval;
> @@ -599,19 +693,35 @@ 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);
> +            parse_option_bool(name, desc->def_value_str, &ret, &error_abort);
>          }
> -        return defval;
> +        return ret;
>      }
>      if (opt->desc) {
>          assert(opt->desc->type == QEMU_OPT_BOOL);
>      }
> -    return opt->value.boolean;
> +    ret = opt->value.boolean;
> +    if (del) {
> +        qemu_opt_del(opt);
> +    }
> +    return ret;
>  }
>  
> -uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
> +bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> +{
> +    return _qemu_opt_get_bool(opts, name, defval, false);
> +}
> +
> +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
> +{
> +    return _qemu_opt_get_bool(opts, name, defval, true);
> +}
> +
> +static uint64_t _qemu_opt_get_number(QemuOpts *opts, const char *name,
> +                                     uint64_t defval, bool del)
>  {
>      QemuOpt *opt;
> +    uint64_t ret = defval;
>  
>      if (opts == NULL) {
>          return defval;
> @@ -622,20 +732,36 @@ 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);
> +            parse_option_number(name, desc->def_value_str, &ret, &error_abort);
>          }
> -        return defval;
> +        return ret;
>      }
>      if (opt->desc) {
>          assert(opt->desc->type == QEMU_OPT_NUMBER);
>      }
> -    return opt->value.uint;
> +    ret = opt->value.uint;
> +    if (del) {
> +        qemu_opt_del(opt);
> +    }
> +    return ret;
>  }
>  
> -uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
> +uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
> +{
> +    return _qemu_opt_get_number(opts, name, defval, false);
> +}
> +
> +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
> +                                 uint64_t defval)
> +{
> +    return _qemu_opt_get_number(opts, name, defval, true);
> +}
> +
> +static uint64_t _qemu_opt_get_size(QemuOpts *opts, const char *name,
> +                                   uint64_t defval, bool del)
>  {
>      QemuOpt *opt;
> +    uint64_t ret = defval;
>  
>      if (opts == NULL) {
>          return defval;
> @@ -645,14 +771,29 @@ 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);
> +            parse_option_size(name, desc->def_value_str, &ret, &error_abort);
>          }
> -        return defval;
> +        return ret;
>      }
>      if (opt->desc) {
>          assert(opt->desc->type == QEMU_OPT_SIZE);
>      }
> -    return opt->value.uint;
> +    ret = opt->value.uint;
> +    if (del) {
> +        qemu_opt_del(opt);
> +    }
> +    return ret;
> +}
> +
> +uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
> +{
> +    return _qemu_opt_get_size(opts, name, defval, false);
> +}
> +
> +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
> +                               uint64_t defval)
> +{
> +    return _qemu_opt_get_size(opts, name, defval, true);
>  }
>  
>  static void qemu_opt_parse(QemuOpt *opt, Error **errp)
> @@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
>      loc_pop(&loc);
>      return rc;
>  }
> +
> +/* free a QemuOptsList, can accept NULL as arguments */
> +void qemu_opts_free(QemuOptsList *list)
> +{
> +    if (!list) {
> +        return;
> +    }
> +
> +    g_free(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 : "");
> +    }
> +}
> -- 
> 1.7.12.4
> 
> 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter
  2014-03-17 19:29   ` Leandro Dorileo
@ 2014-03-17 19:43     ` Leandro Dorileo
  0 siblings, 0 replies; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-17 19:43 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

Hi,

On Mon, Mar 17, 2014 at 07:29:29PM +0000, 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 <address@hidden>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c Chunyan Liu
  2014-03-10 20:29   ` Eric Blake
@ 2014-03-17 19:58   ` Leandro Dorileo
  2014-03-18  7:49     ` Chunyan Liu
  1 sibling, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-17 19:58 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha

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 <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  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 = opts;
>      opt->value.boolean = !!val;
> @@ -766,16 +807,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
>  int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t 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.uint = val;
> +        opt->str = g_strdup_printf("%" PRId64, val);
> +        return 0;
> +    }
> +
> +    opt = g_malloc0(sizeof(*opt));
> +    opt->desc = desc;
>      opt->name = g_strdup(name);
>      opt->opts = opts;
>      opt->value.uint = val;
> @@ -910,6 +959,10 @@ void qemu_opts_del(QemuOpts *opts)
>  {
>      QemuOpt *opt;
>  
> +    if (opts == NULL) {
> +        return;
> +    }
> +
>      for (;;) {
>          opt = QTAILQ_FIRST(&opts->head);
>          if (opt == NULL)
> -- 
> 1.7.12.4
> 
> 

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-17 19:35   ` Leandro Dorileo
@ 2014-03-18  3:03     ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-18  3:03 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 11725 bytes --]

2014-03-18 3:35 GMT+08:00 Leandro Dorileo <l@dorileo.org>:

> 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 <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  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 {*0*
> >  };
> >
> >  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?
>

No, it won't be removed. It replaces the existing handling of
QEMUOptionParameter.
For each driver, it handles the options they are expected to handle, then
remove those
options from the list; for the left options, they will be passed to
proto_drv for 2nd phase
handling.


>
> 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 ? opt->str : NULL;
> >  }
> >
> > +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 = g_strdup(opt->str);
> > +    qemu_opt_del(opt);
> > +    return str;
> > +}
> > +
> >  bool qemu_opt_has_help_opt(QemuOpts *opts)
> >  {
> >      QemuOpt *opt;
> > @@ -586,9 +678,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
> >      return false;
> >  }
> >
> > -bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> > +static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,
> > +                               bool defval, bool del)
> >  {
> >      QemuOpt *opt;
> > +    bool ret = defval;
> >
> >      if (opts == NULL) {
> >          return defval;
> > @@ -599,19 +693,35 @@ 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);
> > +            parse_option_bool(name, desc->def_value_str, &ret,
> &error_abort);
> >          }
> > -        return defval;
> > +        return ret;
> >      }
> >      if (opt->desc) {
> >          assert(opt->desc->type == QEMU_OPT_BOOL);
> >      }
> > -    return opt->value.boolean;
> > +    ret = opt->value.boolean;
> > +    if (del) {
> > +        qemu_opt_del(opt);
> > +    }
> > +    return ret;
> >  }
> >
> > -uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t
> defval)
> > +bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> > +{
> > +    return _qemu_opt_get_bool(opts, name, defval, false);
> > +}
> > +
> > +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool
> defval)
> > +{
> > +    return _qemu_opt_get_bool(opts, name, defval, true);
> > +}
> > +
> > +static uint64_t _qemu_opt_get_number(QemuOpts *opts, const char *name,
> > +                                     uint64_t defval, bool del)
> >  {
> >      QemuOpt *opt;
> > +    uint64_t ret = defval;
> >
> >      if (opts == NULL) {
> >          return defval;
> > @@ -622,20 +732,36 @@ 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);
> > +            parse_option_number(name, desc->def_value_str, &ret,
> &error_abort);
> >          }
> > -        return defval;
> > +        return ret;
> >      }
> >      if (opt->desc) {
> >          assert(opt->desc->type == QEMU_OPT_NUMBER);
> >      }
> > -    return opt->value.uint;
> > +    ret = opt->value.uint;
> > +    if (del) {
> > +        qemu_opt_del(opt);
> > +    }
> > +    return ret;
> >  }
> >
> > -uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t
> defval)
> > +uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t
> defval)
> > +{
> > +    return _qemu_opt_get_number(opts, name, defval, false);
> > +}
> > +
> > +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
> > +                                 uint64_t defval)
> > +{
> > +    return _qemu_opt_get_number(opts, name, defval, true);
> > +}
> > +
> > +static uint64_t _qemu_opt_get_size(QemuOpts *opts, const char *name,
> > +                                   uint64_t defval, bool del)
> >  {
> >      QemuOpt *opt;
> > +    uint64_t ret = defval;
> >
> >      if (opts == NULL) {
> >          return defval;
> > @@ -645,14 +771,29 @@ 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);
> > +            parse_option_size(name, desc->def_value_str, &ret,
> &error_abort);
> >          }
> > -        return defval;
> > +        return ret;
> >      }
> >      if (opt->desc) {
> >          assert(opt->desc->type == QEMU_OPT_SIZE);
> >      }
> > -    return opt->value.uint;
> > +    ret = opt->value.uint;
> > +    if (del) {
> > +        qemu_opt_del(opt);
> > +    }
> > +    return ret;
> > +}
> > +
> > +uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t
> defval)
> > +{
> > +    return _qemu_opt_get_size(opts, name, defval, false);
> > +}
> > +
> > +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
> > +                               uint64_t defval)
> > +{
> > +    return _qemu_opt_get_size(opts, name, defval, true);
> >  }
> >
> >  static void qemu_opt_parse(QemuOpt *opt, Error **errp)
> > @@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list,
> qemu_opts_loopfunc func, void *opaque,
> >      loc_pop(&loc);
> >      return rc;
> >  }
> > +
> > +/* free a QemuOptsList, can accept NULL as arguments */
> > +void qemu_opts_free(QemuOptsList *list)
> > +{
> > +    if (!list) {
> > +        return;
> > +    }
> > +
> > +    g_free(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 : "");
> > +    }
> > +}
> > --
> > 1.7.12.4
> >
> >
>
>

[-- Attachment #2: Type: text/html, Size: 15406 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work
  2014-03-12 12:40           ` Eric Blake
  2014-03-13  5:16             ` Chunyan Liu
@ 2014-03-18  5:34             ` Chunyan Liu
  1 sibling, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-18  5:34 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 2271 bytes --]

2014-03-12 20:40 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/11/2014 09:10 PM, Chunyan Liu wrote:
>
> >>>>
> >>> Could be if changing qemu_opt_get return value type, but just as said
> >>> before,
> >>> that will affect many codes.
> >>
> >> Also, changing an existing function that returns 'const char *' into now
> >> returning 'char *' will NOT break any callers if the semantics remain
> >> unchanged (what WILL break is if the semantics change where the callers
> >> must now free the result)
> >
> >
> > Yes, that's the only change, we need to free the result. There are more
> > than 200
> > places using qemu_opt_get in existing code, we need to checkout the
> related
> > files
> > and free the result one by one.
>
> You can still write your helper function so that if 'del' is true, you
> strdup, if 'del' is false, you return the in-place memory.  You'll have
> to cast away const in the helper, but qemu_opt_get can then restore the
> const and you don't have to adjust any existing callers, while still
> sharing the underlying implementation rather than duplicating code.


After trying, still has blocking here. qemu_opt_get returns either opt->str
(this
is char *) or desc->def_value_str (this is const char *). If not g_strdup
the result,
return (const char *) is OK, but return (char *) will has build error when
casting
(const char *) to (char *).

And since assert(opt->desc && opt->desc->type == xx) doesn't need change
for this patch series now, qemu_opt_get_bool could still return
opt->value.boolean, doesn't need to call qemu_opt_get to get opt->str and
parse that to bool. Same to qemu_opt_get_size/number. So, it's not so urgent
that qemu_opt_get/qemu_opt_get_del share common helper function. I'm
inclined
to keep duplicating code.


> But
> I guess I'll wait for v23 to see what you actually do in response to my
> suggestions.  If nothing else, please document design decisions in your
> commit message (for example, if you choose to duplicate code rather than
> share code in a common helper, explain that the duplication is because
> one function returns malloc'd memory while the other returns in-place
> memory).
>

> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 3463 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-16 21:19           ` Leandro Dorileo
@ 2014-03-18  7:41             ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-18  7:41 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 2253 bytes --]

2014-03-17 5:19 GMT+08:00 Leandro Dorileo <l@dorileo.org>:

> Hi Chunyan,
>
> On Tue, Mar 11, 2014 at 09:00:04PM +0000, 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 <eblake@redhat.com>:
> > >
> > > > 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.
>

Thanks a lot, I've seen that.


>
> Regards...
>
> --
> Leandro Dorileo
>
>

[-- Attachment #2: Type: text/html, Size: 3461 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c
  2014-03-17 19:58   ` Leandro Dorileo
@ 2014-03-18  7:49     ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-18  7:49 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 7281 bytes --]

2014-03-18 3:58 GMT+08:00 Leandro Dorileo <l@dorileo.org>:

> 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 <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  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?
>

It should be broken in generating patches (so I thought we should add input
check), although
might not be broken at the end :) Maybe I could look at and try to exclude
some changes
that's not mandatory to just make this patch series work. Like: don't need
to change assertion
as in patch 4/25, don't need to replace existing setting in qemu_opt_set_*
functions as in
patch 3/25.


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

Could do. Either change qemu_opt_find or qemu_opt_get.
I can update to change qemu_opt_find :)


>
> --
> 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 = opts;
> >      opt->value.boolean = !!val;
> > @@ -766,16 +807,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char
> *name, bool val)
> >  int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t 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.uint = val;
> > +        opt->str = g_strdup_printf("%" PRId64, val);
> > +        return 0;
> > +    }
> > +
> > +    opt = g_malloc0(sizeof(*opt));
> > +    opt->desc = desc;
> >      opt->name = g_strdup(name);
> >      opt->opts = opts;
> >      opt->value.uint = val;
> > @@ -910,6 +959,10 @@ void qemu_opts_del(QemuOpts *opts)
> >  {
> >      QemuOpt *opt;
> >
> > +    if (opts == NULL) {
> > +        return;
> > +    }
> > +
> >      for (;;) {
> >          opt = QTAILQ_FIRST(&opts->head);
> >          if (opt == NULL)
> > --
> > 1.7.12.4
> >
> >
>
>

[-- Attachment #2: Type: text/html, Size: 9906 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-11 15:28   ` Eric Blake
@ 2014-03-20  6:56     ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-03-20  6:56 UTC (permalink / raw)
  To: Eric Blake; +Cc: Kevin Wolf, Dong Xu Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]

2014-03-11 23:28 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
> >  1 file changed, 26 insertions(+), 28 deletions(-)
> >
>
> > @@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
> >      .bdrv_probe     = cow_probe,
> >      .bdrv_open      = cow_open,
> >      .bdrv_close     = cow_close,
> > -    .bdrv_create    = cow_create,
> > +    .bdrv_create2   = cow_create,
> >      .bdrv_has_zero_init     = bdrv_has_zero_init_1,
> >
> >      .bdrv_read              = cow_co_read,
> >      .bdrv_write             = cow_co_write,
> >      .bdrv_co_get_block_status   = cow_co_get_block_status,
> >
> > -    .create_options = cow_create_options,
> > +    .create_opts       = &cow_create_opts,
>
> Inconsistent alignment of =, and inconsistent use of & (it is not needed
> here, '.create_opts = cow_create_opts' is just fine).
>

& is needed, since cow_create_opts is a struct, but .create_opts is struct
*;
It's different from cow_create_options, which is a struct array,
.create_options
is struct *, so it can simply let the pointer = array name.


>
> But those are both minor;
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

[-- Attachment #2: Type: text/html, Size: 2563 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts
  2014-03-11 14:24   ` Stefan Hajnoczi
@ 2014-03-20  9:08     ` Chun Yan Liu
  2014-03-20 14:14       ` Stefan Hajnoczi
  0 siblings, 1 reply; 105+ messages in thread
From: Chun Yan Liu @ 2014-03-20  9:08 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: kwolf, Dong Xu Wang, qemu-devel, stefanha



>>> On 3/11/2014 at 10:24 PM, in message
<20140311142451.GM7761@stefanha-thinkpad.redhat.com>, Stefan Hajnoczi
<stefanha@gmail.com> wrote: 
> On Mon, Mar 10, 2014 at 03:31:49PM +0800, Chunyan Liu wrote: 
> > diff --git a/block/qed.h b/block/qed.h 
> > index 5d65bea..b024751 100644 
> > --- a/block/qed.h 
> > +++ b/block/qed.h 
> > @@ -43,7 +43,7 @@ 
> >   * 
> >   * All fields are little-endian on disk. 
> >   */ 
> > - 
> > +#define  QED_DEFAULT_CLUSTER_SIZE  65536 
> >  enum { 
> >      QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24, 
> >   
> > @@ -69,7 +69,6 @@ enum { 
> >       */ 
> >      QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */ 
> >      QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024, 
> > -    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024, 
>  
> Why is this change made for cluster size but not table size? 

According to existing create_options, "cluster size" has default value = 
QED_DEFAULT_CLUSTER_SIZE, after switching to create_opts, this has to be 
stringized and set to .def_value_str. That is, 
 .def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE), 
so the QED_DEFAULT_CLUSTER_SIZE could not be a expression, here changes. 
"table size" has no default value in create_options, not need such changes

>  
> Stefan 
>  
>  

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts
  2014-03-20  9:08     ` Chun Yan Liu
@ 2014-03-20 14:14       ` Stefan Hajnoczi
  0 siblings, 0 replies; 105+ messages in thread
From: Stefan Hajnoczi @ 2014-03-20 14:14 UTC (permalink / raw)
  To: Chun Yan Liu; +Cc: kwolf, Stefan Hajnoczi, Dong Xu Wang, qemu-devel

On Thu, Mar 20, 2014 at 03:08:07AM -0600, Chun Yan Liu wrote:
> 
> 
> >>> On 3/11/2014 at 10:24 PM, in message
> <20140311142451.GM7761@stefanha-thinkpad.redhat.com>, Stefan Hajnoczi
> <stefanha@gmail.com> wrote: 
> > On Mon, Mar 10, 2014 at 03:31:49PM +0800, Chunyan Liu wrote: 
> > > diff --git a/block/qed.h b/block/qed.h 
> > > index 5d65bea..b024751 100644 
> > > --- a/block/qed.h 
> > > +++ b/block/qed.h 
> > > @@ -43,7 +43,7 @@ 
> > >   * 
> > >   * All fields are little-endian on disk. 
> > >   */ 
> > > - 
> > > +#define  QED_DEFAULT_CLUSTER_SIZE  65536 
> > >  enum { 
> > >      QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24, 
> > >   
> > > @@ -69,7 +69,6 @@ enum { 
> > >       */ 
> > >      QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */ 
> > >      QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024, 
> > > -    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024, 
> >  
> > Why is this change made for cluster size but not table size? 
> 
> According to existing create_options, "cluster size" has default value = 
> QED_DEFAULT_CLUSTER_SIZE, after switching to create_opts, this has to be 
> stringized and set to .def_value_str. That is, 
>  .def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE), 
> so the QED_DEFAULT_CLUSTER_SIZE could not be a expression, here changes. 
> "table size" has no default value in create_options, not need such changes

Okay, thanks!

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (33 preceding siblings ...)
  2014-03-11 18:03 ` Stefan Hajnoczi
@ 2014-03-21  0:07 ` Leandro Dorileo
  2014-03-21 10:09   ` Chunyan Liu
  2014-03-21 10:34   ` Kevin Wolf
  34 siblings, 2 replies; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-21  0:07 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: kwolf, qemu-devel, stefanha

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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-21  0:07 ` Leandro Dorileo
@ 2014-03-21 10:09   ` Chunyan Liu
  2014-03-21 12:31     ` Leandro Dorileo
  2014-03-21 10:34   ` Kevin Wolf
  1 sibling, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:09 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 3522 bytes --]

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <l@dorileo.org>:

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


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

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.


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

[-- Attachment #2: Type: text/html, Size: 4607 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-21  0:07 ` Leandro Dorileo
  2014-03-21 10:09   ` Chunyan Liu
@ 2014-03-21 10:34   ` Kevin Wolf
  2014-03-21 12:21     ` Leandro Dorileo
  1 sibling, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2014-03-21 10:34 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Chunyan Liu, stefanha, qemu-devel

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.

Kevin

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:34   ` Kevin Wolf
@ 2014-03-21 12:21     ` Leandro Dorileo
  0 siblings, 0 replies; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-21 12:21 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Chunyan Liu, stefanha, qemu-devel

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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:09   ` Chunyan Liu
@ 2014-03-21 12:31     ` Leandro Dorileo
  2014-03-24  3:02       ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-21 12:31 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi

On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
> 2014-03-21 8:07 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
> 
> > 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
> >
> >

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-21 12:31     ` Leandro Dorileo
@ 2014-03-24  3:02       ` Chunyan Liu
  2014-03-24 15:00         ` Leandro Dorileo
  0 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-24  3:02 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 5095 bytes --]

2014-03-21 20:31 GMT+08:00 Leandro Dorileo <l@dorileo.org>:

> On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
> > 2014-03-21 8:07 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
> >
> > > 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.
>
>
The reason qemu_opt_get_*_del functions should be used in  backend drivers,
is to
keep same behavior as how previous QEMUOptionParameter handles. At least,
in one
case: create a qcow2 img. "size" option is handled by qcow2 driver, then
delete; in 2nd raw
driver, there is no "size" option any more, it will create a 0 size file.
If qemu_opt_get but
not delete, then all options will be passed to 2nd raw driver, it will
create a full sized file.
That is not expected.


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

[-- Attachment #2: Type: text/html, Size: 6916 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-24  3:02       ` Chunyan Liu
@ 2014-03-24 15:00         ` Leandro Dorileo
  2014-03-25  7:15           ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Leandro Dorileo @ 2014-03-24 15:00 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi

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 <l@dorileo.org>:
> 
> > On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
> > > 2014-03-21 8:07 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
> > >
> > > > 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.
> >
> >
> The reason qemu_opt_get_*_del functions should be used in  backend drivers,
> is to
> keep same behavior as how previous QEMUOptionParameter handles. At least,
> in one
> case: create a qcow2 img. "size" option is handled by qcow2 driver, then
> delete; in 2nd raw
> driver, there is no "size" option any more, it will create a 0 size file.
> If qemu_opt_get but
> not delete, then all options will be passed to 2nd raw driver, it will
> create a full sized file.
> That is not expected.


I couldn't find the described use case - I still think you don't need to
unset it, but if that's the case what about using for example:

uint64_t sectos = qemu_opt_get_size(options, BLOCK_OPT_SIZE) / 512;
ret = qemu_opt_unset(options, BLOCK_OPT_SIZE);

You don't need to introduce a new API for this.

Regards..

-- 
Leandro Dorileo


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

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-24 15:00         ` Leandro Dorileo
@ 2014-03-25  7:15           ` Chunyan Liu
  2014-04-03  9:46             ` Chunyan Liu
  0 siblings, 1 reply; 105+ messages in thread
From: Chunyan Liu @ 2014-03-25  7:15 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 7292 bytes --]

2014-03-24 23:00 GMT+08:00 Leandro Dorileo <l@dorileo.org>:

> 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 <l@dorileo.org>:
> >
> > > On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
> > > > 2014-03-21 8:07 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
> > > >
> > > > > 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.
> > >
> > >
> > The reason qemu_opt_get_*_del functions should be used in  backend
> drivers,
> > is to
> > keep same behavior as how previous QEMUOptionParameter handles. At least,
> > in one
> > case: create a qcow2 img. "size" option is handled by qcow2 driver, then
> > delete; in 2nd raw
> > driver, there is no "size" option any more, it will create a 0 size file.
> > If qemu_opt_get but
> > not delete, then all options will be passed to 2nd raw driver, it will
> > create a full sized file.
> > That is not expected.
>
>
> I couldn't find the described use case -


In block drivers that calls bdrv_create_file in its bdrv_create (like:
qcow.c qcow2.c vhdx.c vpc.c, etc), current code, will see, it get options
from QEMUOptionParameter one by one with options++, after that passes
'options' to bdrv_create_file (at this time, 'options' actually points to
left options
that's not be handled yet).


> I still think you don't need to
> unset it, but if that's the case what about using for example:
>
> uint64_t sectos = qemu_opt_get_size(options, BLOCK_OPT_SIZE) / 512;
> ret = qemu_opt_unset(options, BLOCK_OPT_SIZE);
>
> You don't need to introduce a new API for this.
>

OK. I checked and it seems only those call bdrv_create_file or
bdrv_create() in
their .bdrv_create functions should take care. Currently, only need to take
care of
options that's parsed in raw-posix.c: raw_create(). That is, currently, only
BLOCK_OPT_SIZE should be taken care. Base on this, we can unset after
parsing
BLOCK_OPT_SIZE as you point in related drivers.

I'll adjust the patches for this, after feedback of other patches and after
there is a
consensus about in which way doing patches:
a. keep changes simple in 'natural way' (allowing break between patch)
or
b. keep current way (make each patch build and work successfully)

Regards,
Chunyan


> Regards..
>
> --
> Leandro Dorileo
>
>
> >
> >
> > >
> > > >
> > > > 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
> > > > >
> > > > >
> > >
> > >
>
>

[-- Attachment #2: Type: text/html, Size: 10476 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

* Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts
  2014-03-25  7:15           ` Chunyan Liu
@ 2014-04-03  9:46             ` Chunyan Liu
  0 siblings, 0 replies; 105+ messages in thread
From: Chunyan Liu @ 2014-04-03  9:46 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 8132 bytes --]

2014-03-25 15:15 GMT+08:00 Chunyan Liu <cyliu@suse.com>:

>
>
>
> 2014-03-24 23:00 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
>
> 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 <l@dorileo.org>:
>> >
>> > > On Fri, Mar 21, 2014 at 06:09:22PM +0800, Chunyan Liu wrote:
>> > > > 2014-03-21 8:07 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
>> > > >
>> > > > > 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.
>> > >
>> > >
>> > The reason qemu_opt_get_*_del functions should be used in  backend
>> drivers,
>> > is to
>> > keep same behavior as how previous QEMUOptionParameter handles. At
>> least,
>> > in one
>> > case: create a qcow2 img. "size" option is handled by qcow2 driver, then
>> > delete; in 2nd raw
>> > driver, there is no "size" option any more, it will create a 0 size
>> file.
>> > If qemu_opt_get but
>> > not delete, then all options will be passed to 2nd raw driver, it will
>> > create a full sized file.
>> > That is not expected.
>>
>>
>> I couldn't find the described use case -
>
>
> In block drivers that calls bdrv_create_file in its bdrv_create (like:
> qcow.c qcow2.c vhdx.c vpc.c, etc), current code, will see, it get options
> from QEMUOptionParameter one by one with options++, after that passes
> 'options' to bdrv_create_file (at this time, 'options' actually points to
> left options
> that's not be handled yet).
>
>

Hi, Leandro,

I found some comment very long before:
http://lists.gnu.org/archive/html/qemu-devel/2013-01/msg02446.html
I think maybe keep qemu_opt_get_del is better than optionally doing
qemu_opt_unset.
Using qemu_opt_get_del will keep same logic with previous options++, we
don't need
to take care which option should be unset, which need effort to know who
will use it later
and easy to cause problem.

So I'll still keep qemu_opt_get_del in next version. Will post soon.

Regards,
Chunyan


> I still think you don't need to
>> unset it, but if that's the case what about using for example:
>>
>> uint64_t sectos = qemu_opt_get_size(options, BLOCK_OPT_SIZE) / 512;
>> ret = qemu_opt_unset(options, BLOCK_OPT_SIZE);
>>
>> You don't need to introduce a new API for this.
>>
>
> OK. I checked and it seems only those call bdrv_create_file or
> bdrv_create() in
> their .bdrv_create functions should take care. Currently, only need to
> take care of
> options that's parsed in raw-posix.c: raw_create(). That is, currently,
> only
> BLOCK_OPT_SIZE should be taken care. Base on this, we can unset after
> parsing
> BLOCK_OPT_SIZE as you point in related drivers.
>
> I'll adjust the patches for this, after feedback of other patches and
> after there is a
> consensus about in which way doing patches:
> a. keep changes simple in 'natural way' (allowing break between patch)
> or
> b. keep current way (make each patch build and work successfully)
>
> Regards,
> Chunyan
>
>
>> Regards..
>>
>> --
>> Leandro Dorileo
>>
>>
>> >
>> >
>> > >
>> > > >
>> > > > 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
>> > > > >
>> > > > >
>> > >
>> > >
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 11917 bytes --]

^ permalink raw reply	[flat|nested] 105+ messages in thread

end of thread, other threads:[~2014-04-03  9:46 UTC | newest]

Thread overview: 105+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-10  7:31 [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc Chunyan Liu
2014-03-10 19:52   ` Eric Blake
2014-03-11 13:29   ` Stefan Hajnoczi
2014-03-12  2:45     ` Chunyan Liu
2014-03-12  8:27       ` Stefan Hajnoczi
2014-03-13  2:46         ` Chunyan Liu
2014-03-13 12:13           ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options Chunyan Liu
2014-03-10 19:57   ` Eric Blake
2014-03-11  6:14   ` Hu Tao
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c Chunyan Liu
2014-03-10 20:29   ` Eric Blake
2014-03-10 21:21     ` Eric Blake
2014-03-11  7:26       ` Chunyan Liu
2014-03-11 21:00         ` Leandro Dorileo
2014-03-16 21:19           ` Leandro Dorileo
2014-03-18  7:41             ` Chunyan Liu
2014-03-12  6:49       ` Chunyan Liu
2014-03-17 19:58   ` Leandro Dorileo
2014-03-18  7:49     ` Chunyan Liu
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions Chunyan Liu
2014-03-10 21:44   ` Eric Blake
2014-03-12  6:34     ` Chunyan Liu
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work Chunyan Liu
2014-03-10 23:28   ` Eric Blake
2014-03-11  5:29     ` Chunyan Liu
2014-03-11 11:59       ` Eric Blake
2014-03-12  3:10         ` Chunyan Liu
2014-03-12 12:40           ` Eric Blake
2014-03-13  5:16             ` Chunyan Liu
2014-03-18  5:34             ` Chunyan Liu
2014-03-17 19:35   ` Leandro Dorileo
2014-03-18  3:03     ` Chunyan Liu
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
2014-03-11  4:46   ` Eric Blake
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
2014-03-11  4:34   ` Eric Blake
2014-03-11 16:54   ` Eric Blake
2014-03-12  6:26     ` Chunyan Liu
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-03-11 14:12   ` Stefan Hajnoczi
2014-03-11 15:28   ` Eric Blake
2014-03-20  6:56     ` Chunyan Liu
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 09/25] gluster.c: " Chunyan Liu
2014-03-11 14:15   ` Stefan Hajnoczi
2014-03-11 16:58   ` Eric Blake
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 10/25] iscsi.c: " Chunyan Liu
2014-03-11 14:17   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 11/25] qcow.c: " Chunyan Liu
2014-03-11 14:18   ` Stefan Hajnoczi
2014-03-11 17:05   ` Eric Blake
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 12/25] qcow2.c: " Chunyan Liu
2014-03-11 14:21   ` Stefan Hajnoczi
2014-03-11 14:22   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 13/25] qed.c: " Chunyan Liu
2014-03-11 14:24   ` Stefan Hajnoczi
2014-03-20  9:08     ` Chun Yan Liu
2014-03-20 14:14       ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 14/25] raw-posix.c: " Chunyan Liu
2014-03-11 14:25   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 15/25] raw-win32.c: " Chunyan Liu
2014-03-11 14:41   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: " Chunyan Liu
2014-03-11 14:44   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 17/25] rbd.c: " Chunyan Liu
2014-03-11 14:46   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 18/25] sheepdog.c: " Chunyan Liu
2014-03-11 16:01   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 19/25] ssh.c: " Chunyan Liu
2014-03-11 16:01   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 20/25] vdi.c: " Chunyan Liu
2014-03-11 17:50   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 21/25] vmdk.c: " Chunyan Liu
2014-03-11 17:51   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 22/25] vpc.c: " Chunyan Liu
2014-03-11 17:55   ` Stefan Hajnoczi
2014-03-10  7:31 ` [Qemu-devel] [PATCH v22 23/25] vhdx.c: " Chunyan Liu
2014-03-11 17:56   ` Stefan Hajnoczi
2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 24/25] vvfat.c: " Chunyan Liu
2014-03-11 17:06   ` Eric Blake
2014-03-11 18:01   ` Stefan Hajnoczi
2014-03-10  7:32 ` [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter Chunyan Liu
2014-03-11 14:06   ` Stefan Hajnoczi
2014-03-17 19:29   ` Leandro Dorileo
2014-03-17 19:43     ` Leandro Dorileo
2014-03-10  7:36 ` [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts Chun Yan Liu
2014-03-10  7:37 ` Chun Yan Liu
2014-03-10  7:37 ` Chun Yan Liu
2014-03-10  7:38 ` Chun Yan Liu
2014-03-10  7:39 ` Chun Yan Liu
2014-03-10  7:39 ` Chun Yan Liu
2014-03-10 20:22 ` Stefan Hajnoczi
2014-03-11  3:07   ` Chunyan Liu
2014-03-10 22:45 ` Eric Blake
2014-03-11 18:03 ` Stefan Hajnoczi
2014-03-21  0:07 ` Leandro Dorileo
2014-03-21 10:09   ` Chunyan Liu
2014-03-21 12:31     ` Leandro Dorileo
2014-03-24  3:02       ` Chunyan Liu
2014-03-24 15:00         ` Leandro Dorileo
2014-03-25  7:15           ` Chunyan Liu
2014-04-03  9:46             ` Chunyan Liu
2014-03-21 10:34   ` Kevin Wolf
2014-03-21 12:21     ` Leandro Dorileo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.