All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts
@ 2014-03-21 10:12 Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling Chunyan Liu
                   ` (32 more replies)
  0 siblings, 33 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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:
  * Move find_desc_by_name and qemu_opt_del functions ahead in separate
    patches before later calling, so to avoid static declaration.
  * Remove some changes that not quite necessary for this patch series:
    improve qemu_opt_set, improve assert() in qemu_opt_get,
    NULL check in qemu_opt_get and qemu_opt_find.
  * improve convert functions and qemu_opts_append() functions
  * improve block layer changes to support both struct
  * other fixes according to Eric and Stefan's comments.

Not added:
  * QemuOpts test suite what Eric suggests, not included in this version, since:
    Currently, things that changes QemuOpts original syntax only include:
    qemu_opts_del: NULL input check.
    opt->name, opt->str: from const char * to char *
    Generally, no big change to its original usage.

    Things that are newly added to QemuOpts are:
    qemu_opt_append function
    qemu_opt_get_*_del functions
    I think we could add tests for these functions later based on
    Leandro Dorileo's test suite patches:
    https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg03282.html


Chunyan Liu (32):
  move find_desc_by_name ahead for later calling
  add def_value_str to QemuOptDesc
  qapi: output def_value_str when query command line options
  change opt->name and opt->str from (const char *) to (char *)
  move qemu_opt_del ahead for later calling
  add qemu_opt_get_*_del functions for replace work
  add qemu_opts_print_help to replace print_option_help
  add convert functions between QEMUOptionParameter to QemuOpts
  add qemu_opts_append to repalce append_option_parameters
  check NULL input for qemu_opts_del
  qemu_opts_print: change fprintf stderr to printf
  qcow2.c: remove 'assigned' check in amend
  change block layer to support both QemuOpts and QEMUOptionParamter
  vvfat.c: handle cross_driver's create_options and create_opts
  cow.c: replace QEMUOptionParameter with QemuOpts
  gluster.c: replace QEMUOptionParameter with QemuOpts
  iscsi.c: replace QEMUOptionParameter with QemuOpts
  qcow.c: replace QEMUOptionParameter with QemuOpts
  qcow2.c: replace QEMUOptionParameter with QemuOpts
  qed.c: replace QEMUOptionParameter with QemuOpts
  raw-posix.c: replace QEMUOptionParameter with QemuOpts
  raw-win32.c: replace QEMUOptionParameter with QemuOpts
  raw_bsd.c: replace QEMUOptionParameter with QemuOpts
  rbd.c: replace QEMUOptionParameter with QemuOpts
  sheepdog.c: replace QEMUOptionParameter with QemuOpts
  ssh.c: replace QEMUOptionParameter with QemuOpts
  vdi.c: replace QEMUOptionParameter with QemuOpts
  vhdx.c: replace QEMUOptionParameter with QemuOpts
  vmdk.c: replace QEMUOptionParameter with QemuOpts
  vpc.c: replace QEMUOptionParameter with QemuOpts
  cleanup QEMUOptionParameter
  cleanup tmp 'mallocd' member from QemuOptsList

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

-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 23:16   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 02/32] add def_value_str to QemuOptDesc Chunyan Liu
                   ` (31 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

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

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

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

* [Qemu-devel] [PATCH v23 02/32] add def_value_str to QemuOptDesc
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options Chunyan Liu
                   ` (30 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

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

Improve qemu_opts_get_* functions: if find opt, return opt->str; otherwise,
if desc->def_value_str is set, return desc->def_value_str; otherwise, return
input defval.

Improve qemu_opts_print: if option is set, print opt->str; otherwise, if
desc->def_value_str is set, also print it.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c    | 56 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..c3b0a91 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
     const char *name;
     enum QemuOptType type;
     const char *help;
+    const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
@@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
-int qemu_opts_print(QemuOpts *opts, void *dummy);
+void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
                       int abort_on_failure);
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index e6d10bc..d5e80da 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
 const char *qemu_opt_get(QemuOpts *opts, const char *name)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
+
+    if (!opt) {
+        const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            return desc->def_value_str;
+        }
+    }
     return opt ? opt->str : NULL;
 }
 
@@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
-    if (opt == NULL)
+    if (opt == NULL) {
+        const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            parse_option_bool(name, desc->def_value_str, &defval, &error_abort);
+        }
         return defval;
+    }
     assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
     return opt->value.boolean;
 }
@@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
-    if (opt == NULL)
+    if (opt == NULL) {
+        const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            parse_option_number(name, desc->def_value_str, &defval,
+                                &error_abort);
+        }
         return defval;
+    }
     assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
     return opt->value.uint;
 }
@@ -609,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
-    if (opt == NULL)
+    if (opt == NULL) {
+        const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            parse_option_size(name, desc->def_value_str, &defval, &error_abort);
+        }
         return defval;
+    }
     assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
     return opt->value.uint;
 }
@@ -895,17 +918,32 @@ void qemu_opts_del(QemuOpts *opts)
     g_free(opts);
 }
 
-int qemu_opts_print(QemuOpts *opts, void *dummy)
+void qemu_opts_print(QemuOpts *opts)
 {
     QemuOpt *opt;
+    QemuOptDesc *desc = opts->list->desc;
 
-    fprintf(stderr, "%s: %s:", opts->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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 02/32] add def_value_str to QemuOptDesc Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 23:27   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *) Chunyan Liu
                   ` (29 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

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

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

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

* [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *)
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (2 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 19:00   ` Leandro Dorileo
  2014-03-25 19:23   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 05/32] move qemu_opt_del ahead for later calling Chunyan Liu
                   ` (28 subsequent siblings)
  32 siblings, 2 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option_int.h |  4 ++--
 qapi/opts-visitor.c       | 10 +++++++---
 util/qemu-option.c        |  4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)

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

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

* [Qemu-devel] [PATCH v23 05/32] move qemu_opt_del ahead for later calling
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (3 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *) Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 19:29   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 06/32] add qemu_opt_get_*_del functions for replace work Chunyan Liu
                   ` (27 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

In later patch, qemu_opt_get_del functions will be added, they will
first get the option value, then call qemu_opt_del to remove the option
from opt list. To prepare for that purpose, move qemu_opt_del ahead first.

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

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

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

* [Qemu-devel] [PATCH v23 06/32] add qemu_opt_get_*_del functions for replace work
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (4 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 05/32] move qemu_opt_del ahead for later calling Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 20:33   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help Chunyan Liu
                   ` (26 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Add qemu_opt_get_del, qemu_opt_get_bool_del and qemu_opt_get_number_gel
to replace the same handling of QEMUOptionParamter (get and delete).

get_*_del purpose:

In specific driver (like "qcow2"), it only handles expected options, then
delete them from option list. Leave the left options to be passed down
to 2nd driver (like "raw") to do 2nd handling.

Share common helper function:

For qemu_opt_get_bool/size/number, they and their get_*_del counterpart
could share most of the code except whether or not deleting the opt from
option list, so generate common helper functions.

For qemu_opt_get and qemu_opt_get_del, keep code duplication, since
1. qemu_opt_get_del returns malloc'd memory while qemu_opt_get returns
in-place memory
2. qemu_opt_get_del returns (char *), qemu_opt_get returns (const char *),
and could not change to (char *), since in one case, it will return
desc->def_value_str, which is (const char *).

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |  6 ++++
 util/qemu-option.c    | 98 ++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 91 insertions(+), 13 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index c3b0a91..6653e43 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -111,6 +111,7 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request
@@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval);
 int qemu_opt_unset(QemuOpts *opts, const char *name);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 25abd65..02a7602 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -588,6 +588,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;
@@ -600,50 +623,99 @@ 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_helper(QemuOpts *opts, const char *name,
+                                     bool defval, bool del)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
+    bool ret = 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;
     }
     assert(opt->desc && 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_helper(opts, name, defval, false);
+}
+
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+    return qemu_opt_get_bool_helper(opts, name, defval, true);
+}
+
+static uint64_t qemu_opt_get_number_helper(QemuOpts *opts, const char *name,
+                                           uint64_t defval, bool del)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
+    uint64_t ret = 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;
     }
     assert(opt->desc && 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_helper(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval)
+{
+    return qemu_opt_get_number_helper(opts, name, defval, true);
+}
+
+static uint64_t qemu_opt_get_size_helper(QemuOpts *opts, const char *name,
+                                         uint64_t defval, bool del)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
+    uint64_t ret = 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;
     }
     assert(opt->desc && 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_helper(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval)
+{
+    return qemu_opt_get_size_helper(opts, name, defval, true);
 }
 
 static void qemu_opt_parse(QemuOpt *opt, Error **errp)
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (5 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 06/32] add qemu_opt_get_*_del functions for replace work Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 19:07   ` Leandro Dorileo
  2014-03-25 20:43   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
                   ` (25 subsequent siblings)
  32 siblings, 2 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

print_option_help takes QEMUOptionParameter as parameter, add
qemu_opts_print_help to take QemuOptsList as parameter for later
replace work.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |  1 +
 util/qemu-option.c    | 11 +++++++++++
 2 files changed, 12 insertions(+)

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

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

* [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (6 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 21:35   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters Chunyan Liu
                   ` (24 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Add two temp convert functions between QEMUOptionParameter to QemuOpts,
so that next patch can use it. It will simplify later patch for easier
review. And will be finally removed after all backend drivers switch to
QemuOpts.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
Finally not following Eric's suggestion of adding char tmp[] to QemuOptList
to store stringized uint value, but choosing g_strdup and add flag 'mallocd'
to QemuOptList to indicate free the mallocd space, since:
1. there could be many unit options need to store, so, adding char tmp[] in
QemuOptList couldn't solve problem, but should add char tmp[] in QemuOptDesc.
Then, for those not unit type, the char tmp[] space is wasted.
2. in later qemu_opts_append() function, since it accept both QemuOptsList and
QEMUOptionParameter as input, for QEMUOptionParamter, it will temp converted
to QemuOpts, then append to result list; after that, the converted QemuOpts
should be freed. It's risky that some memory that the result list members
point to might be freed.
So, simply g_strdup is safer, the only thing is to free in this case.

 include/qemu/option.h |   8 +++
 util/qemu-option.c    | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+)

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

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

* [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (7 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 19:13   ` Leandro Dorileo
  2014-03-25 21:40   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 10/32] check NULL input for qemu_opts_del Chunyan Liu
                   ` (23 subsequent siblings)
  32 siblings, 2 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

For later merge .create_opts of drv and proto_drv in qemu-img commands.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
Changes:
  * Following Eric's suggestion, qemu_opts_append() will accept a pair of
    parameters (QEMUOptionParameter and QemuOpts), to handle the inconsistency
    that some driver uses QemuOpts while some driver uses QEMUOptionParameter.
  * using g_realloc of first parameter 'dst' and return it, instead of malloc
    a new list and copy data from all parameters to the new list, and return
    the new malloced list. Solving memory free effort for multiple append(s),
    and no naming problem as in previous version.

 include/qemu/option.h |  5 ++++
 util/qemu-option.c    | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index fd6f075..120c998 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -175,5 +175,10 @@ void qemu_opts_print_help(QemuOptsList *list);
 void qemu_opts_free(QemuOptsList *list);
 QEMUOptionParameter *opts_to_params(QemuOpts *opts);
 QemuOptsList *params_to_opts(QEMUOptionParameter *list);
+/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+                               QemuOptsList *list,
+                               QEMUOptionParameter *param);
 
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 4bdcfbf..6c304b2 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1477,3 +1477,68 @@ void qemu_opts_free(QemuOptsList *list)
 
     g_free(list);
 }
+
+/* Realloc dst option list and append options either from an option list (list)
+ * or an QEMUOptionParameter (param) to it. dst could be NULL or a malloced list.
+ * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+                               QemuOptsList *list,
+                               QEMUOptionParameter *param)
+{
+    size_t num_opts, num_dst_opts;
+    QemuOptsList *tmp_list = NULL;
+    QemuOptDesc *desc;
+    bool need_init = false;
+
+    assert(!(list && param));
+    if (!param &&!list) {
+        return dst;
+    }
+
+    if (param) {
+        list = tmp_list = params_to_opts(param);
+    }
+
+    /* If dst is NULL, after realloc, some area of dst should be initialized
+     * before adding options to it.
+     */
+    if (!dst) {
+        need_init = true;
+    }
+
+    num_opts = count_opts_list(dst);
+    num_dst_opts = num_opts;
+    num_opts += count_opts_list(list);
+    dst = g_realloc(dst, sizeof(QemuOptsList) +
+                    (num_opts + 1) * sizeof(QemuOptDesc));
+    if (need_init) {
+        dst->name = NULL;
+        dst->implied_opt_name = NULL;
+        QTAILQ_INIT(&dst->head);
+        dst->mallocd = true;
+    }
+    dst->desc[num_dst_opts].name = NULL;
+
+    /* (const char *) members of result dst are malloced, need free. */
+    assert(dst->mallocd);
+    /* append list->desc to dst->desc */
+    if (list) {
+        desc = list->desc;
+        while (desc && desc->name) {
+            if (find_desc_by_name(dst->desc, desc->name) == NULL) {
+                dst->desc[num_dst_opts].name = g_strdup(desc->name);
+                dst->desc[num_dst_opts].type = desc->type;
+                dst->desc[num_dst_opts].help = g_strdup(desc->help);
+                dst->desc[num_dst_opts].def_value_str =
+                                         g_strdup(desc->def_value_str);
+                num_dst_opts++;
+                dst->desc[num_dst_opts].name = NULL;
+            }
+            desc++;
+        }
+    }
+
+    g_free(tmp_list);
+    return dst;
+}
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 10/32] check NULL input for qemu_opts_del
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (8 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 21:41   ` Eric Blake
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf Chunyan Liu
                   ` (22 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

To simplify later using of qemu_opts_del, accept NULL input.

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

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6c304b2..e9802f3 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -990,6 +990,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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (9 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 10/32] check NULL input for qemu_opts_del Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 20:10   ` Leandro Dorileo
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend Chunyan Liu
                   ` (21 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Currently this function is not used anywhere. In later patches, it will
replace print_option_parameters. print_option_parameters uses printf,
to avoid print info changes after switching to QemuOpts, change
qemu_opts_print from fprintf stderr to printf to keep consistent.

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

diff --git a/util/qemu-option.c b/util/qemu-option.c
index e9802f3..a9c53cd 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1012,7 +1012,7 @@ void qemu_opts_print(QemuOpts *opts)
 
     if (desc[0].name == NULL) {
         QTAILQ_FOREACH(opt, &opts->head, next) {
-            fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str);
+            printf("%s=\"%s\" ", opt->name, opt->str);
         }
         return;
     }
@@ -1025,12 +1025,12 @@ void qemu_opts_print(QemuOpts *opts)
             continue;
         }
         if (desc->type == QEMU_OPT_STRING) {
-            fprintf(stderr, "%s='%s' ", desc->name, value);
+            printf("%s='%s' ", desc->name, value);
         } else {
-            fprintf(stderr, "%s=%s ", desc->name, value);
+            printf("%s=%s ", desc->name, value);
         }
     }
-    fprintf(stderr, "\n");
+    printf("\n");
 }
 
 static int opts_do_parse(QemuOpts *opts, const char *params,
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (10 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 19:25   ` Leandro Dorileo
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 13/32] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
                   ` (20 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

In QEMUOptionParameter and QemuOptsList conversion, 'assigned' info
is lost. In current code, only qcow2 amend uses 'assigned' for a check.
It will be broken after next patch. So, remove 'assigned' check. If it's
really a must that amend is valid only to explicitly defined options,
we could add it TODO later.

And for 'prealloc', it's not support amend, since nowhere to compare it
is changed or not, simply ignore it.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/qcow2.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index b9dc960..92d3327 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2088,11 +2088,6 @@ static int qcow2_amend_options(BlockDriverState *bs,
 
     for (i = 0; options[i].name; i++)
     {
-        if (!options[i].assigned) {
-            /* only change explicitly defined options */
-            continue;
-        }
-
         if (!strcmp(options[i].name, "compat")) {
             if (!options[i].value.s) {
                 /* preserve default */
@@ -2106,8 +2101,7 @@ static int qcow2_amend_options(BlockDriverState *bs,
                 return -EINVAL;
             }
         } else if (!strcmp(options[i].name, "preallocation")) {
-            fprintf(stderr, "Cannot change preallocation mode.\n");
-            return -ENOTSUP;
+            /* Cannot change preallocation mode. Ignore it. */
         } else if (!strcmp(options[i].name, "size")) {
             new_size = options[i].value.n;
         } else if (!strcmp(options[i].name, "backing_file")) {
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 13/32] change block layer to support both QemuOpts and QEMUOptionParamter
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (11 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts Chunyan Liu
                   ` (19 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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>
---
Changes:
  * use new qemu_opts_append(), solving memory leak.
  * unify hanling with QemuOpts, only decide using QEMUOptionParameter or
    QemuOpts till last moment, that is, when calling specific backend
    driver's callback.

 block.c                   | 151 +++++++++++++++++++++++++++++++---------------
 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 |  11 +++-
 qemu-img.c                |  94 ++++++++++++++---------------
 12 files changed, 170 insertions(+), 111 deletions(-)

diff --git a/block.c b/block.c
index acb70fd..125279c 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;
@@ -419,8 +420,27 @@ 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);
+    assert(!(cco->options && cco->opts));
+
+    if (cco->drv->bdrv_create2) {
+        QemuOptsList *opts_list = NULL;
+        QemuOpts *opts = NULL;
+        if (!cco->opts) {
+            opts_list = params_to_opts(cco->options);
+            cco->opts = opts =
+                qemu_opts_create(opts_list, NULL, 0, &error_abort);
+        }
+        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+        qemu_opts_del(opts);
+        qemu_opts_free(opts_list);
+    } else {
+        QEMUOptionParameter *options = NULL;
+        if (!cco->options) {
+            cco->options = options = opts_to_params(cco->opts);
+        }
+        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+        free_option_parameters(options);
+    }
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -428,7 +448,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, Error **errp)
+                QEMUOptionParameter *options,
+                QemuOpts *opts, Error **errp)
 {
     int ret;
 
@@ -437,11 +458,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 +495,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 +507,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 +1270,8 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QEMUOptionParameter *create_options;
+        QemuOptsList *create_opts = NULL;
+        QemuOpts *opts = NULL;
         QDict *snapshot_options;
 
         /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1297,20 @@ 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);
-
-        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
-        free_option_parameters(create_options);
+        assert(!(bdrv_qcow2->create_options && bdrv_qcow2->create_opts));
+        if (bdrv_qcow2->create_options) {
+            create_opts = params_to_opts(bdrv_qcow2->create_options);
+        } else {
+            create_opts = bdrv_qcow2->create_opts;
+        }
+        opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+        qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
+        ret = bdrv_create(bdrv_qcow2, tmp_filename, NULL, opts, &local_err);
+        qemu_opts_del(opts);
+        if (bdrv_qcow2->create_options) {
+            qemu_opts_free(create_opts);
+        }
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create temporary overlay "
                              "'%s': %s", tmp_filename,
@@ -5259,8 +5289,10 @@ void bdrv_img_create(const char *filename, const char *fmt,
                      char *options, uint64_t img_size, int flags,
                      Error **errp, bool quiet)
 {
-    QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *backing_fmt, *backing_file, *size;
+    QemuOptsList *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;
@@ -5279,28 +5311,25 @@ 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);
+    create_opts = qemu_opts_append(create_opts, drv->create_opts,
+                                   drv->create_options);
+    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
+                                   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);
 
     /* 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;
@@ -5308,37 +5337,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];
@@ -5349,11 +5378,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;
@@ -5363,7 +5392,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 {
@@ -5374,16 +5403,18 @@ 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);
+
+    ret = bdrv_create(drv, filename, NULL, opts, &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'"
@@ -5393,9 +5424,8 @@ 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) {
         error_propagate(errp, local_err);
     }
@@ -5413,12 +5443,35 @@ 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) {
+    int ret;
+    assert(!(options && opts));
+
+    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) {
+        QemuOptsList *tmp_opts_list = NULL;
+        QemuOpts *tmp_opts = NULL;
+        if (options) {
+            tmp_opts_list = params_to_opts(options);
+            opts = tmp_opts =
+                qemu_opts_create(tmp_opts_list, NULL, 0, &error_abort);
+        }
+        ret = bs->drv->bdrv_amend_options2(bs, opts);
+        qemu_opts_del(tmp_opts);
+        qemu_opts_free(tmp_opts_list);
+    } else {
+        QEMUOptionParameter *param = NULL;
+        if (opts) {
+            options = param = opts_to_params(opts);
+        }
+        ret = bs->drv->bdrv_amend_options(bs, options);
+        free_option_parameters(param);
+    }
+    return ret;
 }
 
 /* This function will be called by the bdrv_recurse_is_first_non_filter method
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 92d3327..65afbac 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1504,7 +1504,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 3bd9db9..ef5c56c 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 1ed55d8..6fc9777 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 */
 bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index cd5bc73..f9d87da 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,10 @@ struct BlockDriver {
 
     /* List of options for creating images, terminated by name == NULL */
     QEMUOptionParameter *create_options;
-
+    /* FIXME: will replace create_options.
+     * These two fields are mutually exclusive. At most one is non-NULL.
+     */
+    QemuOptsList *create_opts;
 
     /*
      * Returns 0 for completed check, -errno for internal errors.
@@ -228,6 +233,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..e78e933 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -235,7 +235,7 @@ 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 */
     drv = bdrv_find_format(fmt);
@@ -244,21 +244,20 @@ static int print_block_option_help(const char *filename, const char *fmt)
         return 1;
     }
 
-    create_options = append_option_parameters(create_options,
-                                              drv->create_options);
-
+    create_opts = qemu_opts_append(create_opts, drv->create_opts,
+                                   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);
+        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
+                                       proto_drv->create_options);
     }
 
-    print_option_help(create_options);
-    free_option_parameters(create_options);
+    qemu_opts_print_help(create_opts);
+    qemu_opts_free(create_opts);
     return 0;
 }
 
@@ -311,19 +310,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;
@@ -1153,8 +1152,9 @@ static int img_convert(int argc, char **argv)
     size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
     const uint8_t *buf1;
     BlockDriverInfo bdi;
-    QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *out_baseimg_param;
+    QemuOpts *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 +1340,36 @@ 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);
+    create_opts = qemu_opts_append(create_opts, drv->create_opts,
+                                   drv->create_options);
+    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
+                                   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;
-        }
-    } else {
-        param = parse_option_parameters("", create_options, param);
+    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 +1377,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 +1396,7 @@ static int img_convert(int argc, char **argv)
 
     if (!skip_create) {
         /* Create the new image */
-        ret = bdrv_create(drv, out_filename, param, &local_err);
+        ret = bdrv_create(drv, out_filename, NULL, opts, &local_err);
         if (ret < 0) {
             error_report("%s: error while converting %s: %s",
                          out_filename, out_fmt, error_get_pretty(local_err));
@@ -1664,8 +1660,8 @@ out:
         qemu_progress_print(100, 0);
     }
     qemu_progress_end();
-    free_option_parameters(create_options);
-    free_option_parameters(param);
+    qemu_opts_del(opts);
+    qemu_opts_free(create_opts);
     qemu_vfree(buf);
     if (sn_opts) {
         qemu_opts_del(sn_opts);
@@ -2651,7 +2647,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 +2718,16 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    create_options = append_option_parameters(create_options,
-            bs->drv->create_options);
-    options_param = parse_option_parameters(options, create_options,
-            options_param);
-    if (options_param == NULL) {
+    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts,
+                                   bs->drv->create_options);
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    if (options && qemu_opts_do_parse(opts, options, NULL)) {
         error_report("Invalid options for file format '%s'", fmt);
         ret = -1;
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, options_param);
+    ret = bdrv_amend_options(bs, NULL, opts);
     if (ret < 0) {
         error_report("Error while amending options: %s", strerror(-ret));
         goto out;
@@ -2741,8 +2737,8 @@ out:
     if (bs) {
         bdrv_unref(bs);
     }
-    free_option_parameters(create_options);
-    free_option_parameters(options_param);
+    qemu_opts_del(opts);
+    qemu_opts_free(create_opts);
     g_free(options);
 
     if (ret) {
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (12 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 13/32] change block layer to support both QemuOpts and QEMUOptionParamter Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 19:17   ` Leandro Dorileo
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 15/32] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (18 subsequent siblings)
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

vvfat shares create options of qcow driver. To avoid vvfat broken when
qcow driver changes from QEMUOptionParameter to QemuOpts, let it able
to handle both cases.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block/vvfat.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index ee32b3c..82b1521 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2907,7 +2907,8 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s)
 {
     BlockDriver *bdrv_qcow;
-    QEMUOptionParameter *options;
+    QemuOptsList *create_opts;
+    QemuOpts *opts;
     Error *local_err = NULL;
     int ret;
     int size = sector2cluster(s, s->sector_count);
@@ -2922,11 +2923,17 @@ static int enable_write_target(BDRVVVFATState *s)
     }
 
     bdrv_qcow = bdrv_find_format("qcow");
-    options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
-    set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
-    set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
+    assert(!(bdrv_qcow->create_opts && bdrv_qcow->create_options));
+    if (bdrv_qcow->create_options) {
+        create_opts = params_to_opts(bdrv_qcow->create_options);
+    } else {
+        create_opts = bdrv_qcow->create_opts;
+    }
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
+    qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
 
-    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
@@ -2955,6 +2962,8 @@ static int enable_write_target(BDRVVVFATState *s)
     return 0;
 
 err:
+    qemu_opts_del(opts);
+    qemu_opts_free(create_opts);
     g_free(s->qcow_filename);
     s->qcow_filename = NULL;
     return ret;
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 15/32] cow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (13 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 16/32] gluster.c: " Chunyan Liu
                   ` (17 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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..fb2cd68 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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 16/32] gluster.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (14 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 15/32] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 17/32] iscsi.c: " Chunyan Liu
                   ` (16 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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..c5a519e 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 = NULL;
     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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 17/32] iscsi.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (15 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 16/32] gluster.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 18/32] qcow.c: " Chunyan Liu
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

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

diff --git a/block/iscsi.c b/block/iscsi.c
index b490e98..316e1b9 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 = {
@@ -1468,8 +1467,8 @@ static BlockDriver bdrv_iscsi = {
     .bdrv_needs_filename = true,
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
-    .bdrv_create     = iscsi_create,
-    .create_options  = iscsi_create_options,
+    .bdrv_create2    = iscsi_create,
+    .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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 18/32] qcow.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (16 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 17/32] iscsi.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 19/32] qcow2.c: " Chunyan Liu
                   ` (14 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 19/32] qcow2.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (17 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 18/32] qcow.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 20/32] qed.c: " Chunyan Liu
                   ` (13 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
Changes:
  * Initialze char *buf = NULL
  * qcow2_amend_options, ignore prealloc, instead of always return NOTSUPPORT.
    Since we don't know it's changed or not.

 block/qcow2.c | 316 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 163 insertions(+), 153 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 65afbac..d8e72a5 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1472,7 +1472,7 @@ static int preallocate(BlockDriverState *bs)
 static int qcow2_create2(const char *filename, int64_t total_size,
                          const char *backing_file, const char *backing_format,
                          int flags, size_t cluster_size, int prealloc,
-                         QEMUOptionParameter *options, int version,
+                         QemuOpts *opts, int version,
                          Error **errp)
 {
     /* Calculate cluster_bits */
@@ -1504,7 +1504,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;
@@ -1639,11 +1639,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 = NULL;
     uint64_t sectors = 0;
     int flags = 0;
     size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1653,64 +1653,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 {
+        error_setg(errp, "Invalid preallocation mode: '%s'", 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 {
+        error_setg(errp, "Invalid compatibility level: '%s'", 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;
 }
 
@@ -2075,60 +2075,56 @@ 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 (!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")) {
-            /* Cannot change preallocation mode. Ignore it. */
-        } 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);
-        }
+    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;
+    }
+
+    /* Cannot change preallocation mode. Ignore it. */
+
+    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 */
@@ -2136,12 +2132,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;
             }
         }
     }
@@ -2150,7 +2146,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;
         }
     }
 
@@ -2159,27 +2155,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;
         }
@@ -2188,56 +2185,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 = {
@@ -2247,10 +2257,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,
@@ -2265,8 +2275,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,
@@ -2277,9 +2287,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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 20/32] qed.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (18 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 19/32] qcow2.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 21/32] raw-posix.c: " Chunyan Liu
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

One extra change is to define QED_DEFAULT_CLUSTER_SIZE = 65536 instead
of 64 * 1024; because:
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.

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 ef5c56c..ae7b98f 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 {
@@ -1593,43 +1591,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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 21/32] raw-posix.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (19 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 20/32] qed.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 22/32] raw-win32.c: " Chunyan Liu
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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 1688e16..e72f449 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,
 };
 
 /***********************************************/
@@ -1769,7 +1768,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;
@@ -1790,12 +1789,8 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
     (void)has_prefix;
 
     /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
-    }
+    total_size =
+        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
     fd = qemu_open(filename, O_WRONLY | O_BINARY);
     if (fd < 0) {
@@ -1832,8 +1827,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,
@@ -1976,8 +1971,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,
@@ -2101,8 +2096,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,
@@ -2232,8 +2227,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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 22/32] raw-win32.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (20 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 21/32] raw-posix.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 23/32] raw_bsd.c: " Chunyan Liu
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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 48cb2c2..b00d7fc 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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 23/32] raw_bsd.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (21 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 22/32] raw-win32.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 24/32] rbd.c: " Chunyan Liu
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 24/32] rbd.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (22 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 23/32] raw_bsd.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 25/32] sheepdog.c: " Chunyan Liu
                   ` (8 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 25/32] sheepdog.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (23 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 24/32] rbd.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 26/32] ssh.c: " Chunyan Liu
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 26/32] ssh.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (24 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 25/32] sheepdog.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 27/32] vdi.c: " Chunyan Liu
                   ` (6 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 27/32] vdi.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (25 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 26/32] ssh.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 28/32] vhdx.c: " Chunyan Liu
                   ` (5 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
Changes:
  * keep TODO line

 block/vdi.c | 73 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index ae49cd8..fc0d5a4 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,18 @@ 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;
-            }
+    /* TODO: Additional checks (SECTOR_SIZE * 2^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 +759,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 +796,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 +808,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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 28/32] vhdx.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (26 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 27/32] vdi.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 29/32] vmdk.c: " Chunyan Liu
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
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 8103d4c..5370010 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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 29/32] vmdk.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (27 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 28/32] vhdx.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 30/32] vpc.c: " Chunyan Liu
                   ` (3 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 30/32] vpc.c: replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (28 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 29/32] vmdk.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter Chunyan Liu
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 59+ messages in thread

* [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (29 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 30/32] vpc.c: " Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 18:02   ` Leandro Dorileo
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 32/32] cleanup tmp 'mallocd' member from QemuOptsList Chunyan Liu
  2014-03-25 18:09 ` [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Leandro Dorileo
  32 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Now that all backend drivers are using QemuOpts, remove all
QEMUOptionParameter related codes.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 block.c                   |  85 ++-------
 block/cow.c               |   4 +-
 block/gluster.c           |   8 +-
 block/iscsi.c             |   2 +-
 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             |  12 +-
 include/block/block.h     |   8 +-
 include/block/block_int.h |  16 +-
 include/qemu/option.h     |  48 +-----
 qemu-img.c                |  19 +--
 util/qemu-option.c        | 427 +---------------------------------------------
 23 files changed, 67 insertions(+), 616 deletions(-)

diff --git a/block.c b/block.c
index 125279c..1f11007 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;
@@ -420,27 +419,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 
     CreateCo *cco = opaque;
     assert(cco->drv);
-    assert(!(cco->options && cco->opts));
 
-    if (cco->drv->bdrv_create2) {
-        QemuOptsList *opts_list = NULL;
-        QemuOpts *opts = NULL;
-        if (!cco->opts) {
-            opts_list = params_to_opts(cco->options);
-            cco->opts = opts =
-                qemu_opts_create(opts_list, NULL, 0, &error_abort);
-        }
-        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
-        qemu_opts_del(opts);
-        qemu_opts_free(opts_list);
-    } else {
-        QEMUOptionParameter *options = NULL;
-        if (!cco->options) {
-            cco->options = options = opts_to_params(cco->opts);
-        }
-        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
-        free_option_parameters(options);
-    }
+    ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err);
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -448,7 +428,6 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-                QEMUOptionParameter *options,
                 QemuOpts *opts, Error **errp)
 {
     int ret;
@@ -457,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;
@@ -494,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;
@@ -507,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);
     }
@@ -1270,7 +1247,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QemuOptsList *create_opts = NULL;
         QemuOpts *opts = NULL;
         QDict *snapshot_options;
 
@@ -1297,20 +1273,12 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         }
 
         bdrv_qcow2 = bdrv_find_format("qcow2");
-
-        assert(!(bdrv_qcow2->create_options && bdrv_qcow2->create_opts));
-        if (bdrv_qcow2->create_options) {
-            create_opts = params_to_opts(bdrv_qcow2->create_options);
-        } else {
-            create_opts = bdrv_qcow2->create_opts;
-        }
-        opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+        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, NULL, opts, &local_err);
+
+        ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
         qemu_opts_del(opts);
-        if (bdrv_qcow2->create_options) {
-            qemu_opts_free(create_opts);
-        }
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create temporary overlay "
                              "'%s': %s", tmp_filename,
@@ -5311,10 +5279,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
         return;
     }
 
-    create_opts = qemu_opts_append(create_opts, drv->create_opts,
-                                   drv->create_options);
-    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
-                                   proto_drv->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);
@@ -5407,7 +5373,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
         puts("");
     }
 
-    ret = bdrv_create(drv, filename, NULL, opts, &local_err);
+    ret = bdrv_create(drv, filename, opts, &local_err);
 
     if (ret == -EFBIG) {
         /* This is generally a better message than whatever the driver would
@@ -5443,35 +5409,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)
 {
-    int ret;
-    assert(!(options && 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) {
-        QemuOptsList *tmp_opts_list = NULL;
-        QemuOpts *tmp_opts = NULL;
-        if (options) {
-            tmp_opts_list = params_to_opts(options);
-            opts = tmp_opts =
-                qemu_opts_create(tmp_opts_list, NULL, 0, &error_abort);
-        }
-        ret = bs->drv->bdrv_amend_options2(bs, opts);
-        qemu_opts_del(tmp_opts);
-        qemu_opts_free(tmp_opts_list);
-    } else {
-        QEMUOptionParameter *param = NULL;
-        if (opts) {
-            options = param = opts_to_params(opts);
-        }
-        ret = bs->drv->bdrv_amend_options(bs, options);
-        free_option_parameters(param);
-    }
-    return ret;
+    return bs->drv->bdrv_amend_options(bs, opts);
 }
 
 /* This function will be called by the bdrv_recurse_is_first_non_filter method
diff --git a/block/cow.c b/block/cow.c
index fb2cd68..d49ed17 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 c5a519e..b1633e2 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/iscsi.c b/block/iscsi.c
index 316e1b9..4379d14 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1467,7 +1467,7 @@ static BlockDriver bdrv_iscsi = {
     .bdrv_needs_filename = true,
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
-    .bdrv_create2    = iscsi_create,
+    .bdrv_create     = iscsi_create,
     .create_opts     = &iscsi_create_opts,
     .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
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 d8e72a5..28184cc 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1504,7 +1504,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;
@@ -2257,7 +2257,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,
@@ -2289,7 +2289,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 ae7b98f..2dbbcfe 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;
@@ -1635,7 +1635,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 e72f449..f51f31d 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,
@@ -1827,7 +1827,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,
 
@@ -1971,7 +1971,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,
@@ -2096,7 +2096,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,
@@ -2227,7 +2227,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 b00d7fc..7bc04bd 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 fc0d5a4..677a88e 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -796,7 +796,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 82b1521..1ccab39 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2907,7 +2907,6 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s)
 {
     BlockDriver *bdrv_qcow;
-    QemuOptsList *create_opts;
     QemuOpts *opts;
     Error *local_err = NULL;
     int ret;
@@ -2923,17 +2922,11 @@ static int enable_write_target(BDRVVVFATState *s)
     }
 
     bdrv_qcow = bdrv_find_format("qcow");
-    assert(!(bdrv_qcow->create_opts && bdrv_qcow->create_options));
-    if (bdrv_qcow->create_options) {
-        create_opts = params_to_opts(bdrv_qcow->create_options);
-    } else {
-        create_opts = bdrv_qcow->create_opts;
-    }
-    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    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, 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);
@@ -2963,7 +2956,6 @@ static int enable_write_target(BDRVVVFATState *s)
 
 err:
     qemu_opts_del(opts);
-    qemu_opts_free(create_opts);
     g_free(s->qcow_filename);
     s->qcow_filename = NULL;
     return ret;
diff --git a/include/block/block.h b/include/block/block.h
index 6fc9777..6c0ead2 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 */
 bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f9d87da..bf5b4ed 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,10 +215,6 @@ struct BlockDriver {
         BlockDriverCompletionFunc *cb, void *opaque);
 
     /* List of options for creating images, terminated by name == NULL */
-    QEMUOptionParameter *create_options;
-    /* FIXME: will replace create_options.
-     * These two fields are mutually exclusive. At most one is non-NULL.
-     */
     QemuOptsList *create_opts;
 
     /*
@@ -231,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 120c998..30533d2 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -31,25 +31,6 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
-enum QEMUOptionParType {
-    OPT_FLAG,
-    OPT_NUMBER,
-    OPT_SIZE,
-    OPT_STRING,
-};
-
-typedef struct QEMUOptionParameter {
-    const char *name;
-    enum QEMUOptionParType type;
-    union {
-        uint64_t n;
-        char* s;
-    } value;
-    const char *help;
-    bool assigned;
-} QEMUOptionParameter;
-
-
 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
 const char *get_opt_value(char *buf, int buf_size, const char *p);
 int get_next_param_value(char *buf, int buf_size,
@@ -58,32 +39,11 @@ 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;
@@ -173,12 +133,6 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
                       int abort_on_failure);
 void qemu_opts_print_help(QemuOptsList *list);
 void qemu_opts_free(QemuOptsList *list);
-QEMUOptionParameter *opts_to_params(QemuOpts *opts);
-QemuOptsList *params_to_opts(QEMUOptionParameter *list);
-/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
- */
-QemuOptsList *qemu_opts_append(QemuOptsList *dst,
-                               QemuOptsList *list,
-                               QEMUOptionParameter *param);
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
 
 #endif
diff --git a/qemu-img.c b/qemu-img.c
index e78e933..771843f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -244,16 +244,14 @@ static int print_block_option_help(const char *filename, const char *fmt)
         return 1;
     }
 
-    create_opts = qemu_opts_append(create_opts, drv->create_opts,
-                                   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;
         }
-        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
-                                       proto_drv->create_options);
+        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
     }
 
     qemu_opts_print_help(create_opts);
@@ -1340,10 +1338,8 @@ static int img_convert(int argc, char **argv)
         goto out;
     }
 
-    create_opts = qemu_opts_append(create_opts, drv->create_opts,
-                                   drv->create_options);
-    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
-                                   proto_drv->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)) {
@@ -1396,7 +1392,7 @@ static int img_convert(int argc, char **argv)
 
     if (!skip_create) {
         /* Create the new image */
-        ret = bdrv_create(drv, out_filename, NULL, opts, &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));
@@ -2718,8 +2714,7 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts,
-                                   bs->drv->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);
@@ -2727,7 +2722,7 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, NULL, opts);
+    ret = bdrv_amend_options(bs, opts);
     if (ret < 0) {
         error_report("Error while amending options: %s", strerror(-ret));
         goto out;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index a9c53cd..c98f729 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -123,22 +123,6 @@ int get_param_value(char *buf, int buf_size,
     return get_next_param_value(buf, buf_size, tag, &str);
 }
 
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-    const char *name)
-{
-    while (list && list->name) {
-        if (!strcmp(list->name, name)) {
-            return list;
-        }
-        list++;
-    }
-
-    return NULL;
-}
-
 static void parse_option_bool(const char *name, const char *value, bool *ret,
                               Error **errp)
 {
@@ -226,244 +210,6 @@ void parse_option_size(const char *name, const char *value,
     }
 }
 
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- *      If no value is given, the flag is set to 1.
- *      Otherwise the value must be "on" (set to 1) or "off" (set to 0)
- *
- * OPT_STRING (uses value.s):
- *      value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- *      The value is converted to an integer. Suffixes for kilobytes etc. are
- *      allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-    const char *value)
-{
-    bool flag;
-    Error *local_err = NULL;
-
-    // Find a matching parameter
-    list = get_option_parameter(list, name);
-    if (list == NULL) {
-        fprintf(stderr, "Unknown option '%s'\n", name);
-        return -1;
-    }
-
-    // Process parameter
-    switch (list->type) {
-    case OPT_FLAG:
-        parse_option_bool(name, value, &flag, &local_err);
-        if (!local_err) {
-            list->value.n = flag;
-        }
-        break;
-
-    case OPT_STRING:
-        if (value != NULL) {
-            list->value.s = g_strdup(value);
-        } else {
-            fprintf(stderr, "Option '%s' needs a parameter\n", name);
-            return -1;
-        }
-        break;
-
-    case OPT_SIZE:
-        parse_option_size(name, value, &list->value.n, &local_err);
-        break;
-
-    default:
-        fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
-        return -1;
-    }
-
-    if (local_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;
-}
-
-/*
- * 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;
@@ -513,46 +259,6 @@ out:
     return result;
 }
 
-/*
- * Prints all options of a list that have a value to stdout
- */
-void print_option_parameters(QEMUOptionParameter *list)
-{
-    while (list && list->name) {
-        switch (list->type) {
-            case OPT_STRING:
-                 if (list->value.s != NULL) {
-                     printf("%s='%s' ", list->name, list->value.s);
-                 }
-                break;
-            case OPT_FLAG:
-                printf("%s=%s ", list->name, list->value.n ? "on" : "off");
-                break;
-            case OPT_SIZE:
-            case OPT_NUMBER:
-                printf("%s=%" PRId64 " ", list->name, list->value.n);
-                break;
-            default:
-                printf("%s=(unknown type) ", list->name);
-                break;
-        }
-        list++;
-    }
-}
-
-/*
- * Prints an overview of all available options
- */
-void print_option_help(QEMUOptionParameter *list)
-{
-    printf("Supported options:\n");
-    while (list && list->name) {
-        printf("%-16s %s\n", list->name,
-            list->help ? list->help : "No description available");
-        list++;
-    }
-}
-
 void qemu_opts_print_help(QemuOptsList *list)
 {
     int i;
@@ -1346,122 +1052,6 @@ static size_t count_opts_list(QemuOptsList *list)
     return num_opts;
 }
 
-/* Convert QEMUOptionParameter to QemuOpts
- * FIXME: this function will be removed after all drivers
- * switch to QemuOpts
- */
-QemuOptsList *params_to_opts(QEMUOptionParameter *list)
-{
-    QemuOptsList *opts = NULL;
-    size_t num_opts, i = 0;
-
-    if (!list) {
-        return NULL;
-    }
-
-    num_opts = count_option_parameters(list);
-    opts = g_malloc0(sizeof(QemuOptsList) +
-                     (num_opts + 1) * sizeof(QemuOptDesc));
-    QTAILQ_INIT(&opts->head);
-    /* (const char *) members will point to malloced space and need to free */
-    opts->mallocd = true;
-
-    while (list && list->name) {
-        opts->desc[i].name = g_strdup(list->name);
-        opts->desc[i].help = g_strdup(list->help);
-        switch (list->type) {
-        case OPT_FLAG:
-            opts->desc[i].type = QEMU_OPT_BOOL;
-            opts->desc[i].def_value_str =
-                g_strdup(list->value.n ? "on" : "off");
-            break;
-
-        case OPT_NUMBER:
-            opts->desc[i].type = QEMU_OPT_NUMBER;
-            if (list->value.n) {
-                opts->desc[i].def_value_str =
-                    g_strdup_printf("%" PRIu64, list->value.n);
-            }
-            break;
-
-        case OPT_SIZE:
-            opts->desc[i].type = QEMU_OPT_SIZE;
-            if (list->value.n) {
-                opts->desc[i].def_value_str =
-                    g_strdup_printf("%" PRIu64, list->value.n);
-            }
-            break;
-
-        case OPT_STRING:
-            opts->desc[i].type = QEMU_OPT_STRING;
-            opts->desc[i].def_value_str = g_strdup(list->value.s);
-            break;
-        }
-
-        i++;
-        list++;
-        opts->desc[i].name = NULL;
-    }
-
-    return opts;
-}
-
-/* convert QemuOpts to QEMUOptionParamter
- * Note: result QEMUOptionParameter has shorter lifetime than
- * input QemuOpts.
- * FIXME: this function will be removed after all drivers
- * switch to QemuOpts
- */
-QEMUOptionParameter *opts_to_params(QemuOpts *opts)
-{
-    QEMUOptionParameter *dest = NULL;
-    QemuOptDesc *desc;
-    size_t num_opts, i = 0;
-    const char *tmp;
-
-    if (!opts || !opts->list || !opts->list->desc) {
-        return NULL;
-    }
-    assert(!opts_accepts_any(opts));
-
-    num_opts = count_opts_list(opts->list);
-    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
-
-    desc = opts->list->desc;
-    while (desc && desc->name) {
-        dest[i].name = desc->name;
-        dest[i].help = 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;
-}
-
 void qemu_opts_free(QemuOptsList *list)
 {
     /* List members point to new malloced space and need to free.
@@ -1482,28 +1072,20 @@ void qemu_opts_free(QemuOptsList *list)
     g_free(list);
 }
 
-/* Realloc dst option list and append options either from an option list (list)
- * or an QEMUOptionParameter (param) to it. dst could be NULL or a malloced list.
- * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
+/* Realloc dst option list and append options from an option list (list)
+ * to it. dst could be NULL or a malloced list.
  */
 QemuOptsList *qemu_opts_append(QemuOptsList *dst,
-                               QemuOptsList *list,
-                               QEMUOptionParameter *param)
+                               QemuOptsList *list)
 {
     size_t num_opts, num_dst_opts;
-    QemuOptsList *tmp_list = NULL;
     QemuOptDesc *desc;
     bool need_init = false;
 
-    assert(!(list && param));
-    if (!param &&!list) {
+    if (!list) {
         return dst;
     }
 
-    if (param) {
-        list = tmp_list = params_to_opts(param);
-    }
-
     /* If dst is NULL, after realloc, some area of dst should be initialized
      * before adding options to it.
      */
@@ -1543,6 +1125,5 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
         }
     }
 
-    g_free(tmp_list);
     return dst;
 }
-- 
1.7.12.4

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

* [Qemu-devel] [PATCH v23 32/32] cleanup tmp 'mallocd' member from QemuOptsList
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (30 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter Chunyan Liu
@ 2014-03-21 10:12 ` Chunyan Liu
  2014-03-25 18:09 ` [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Leandro Dorileo
  32 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-21 10:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Now only qemu_opts_append uses mallocd to indicate free memory. For
this function only, we can also let result list's (const char *)
members point to input list's members, only if the input list has
longer lifetime than result list. In current code, that is true.
So, we can remove the 'mallocd' member from QemuOptsList definition
to keep code clean.

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

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 30533d2..a57e1af 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -63,11 +63,6 @@ typedef struct QemuOptDesc {
 } QemuOptDesc;
 
 struct QemuOptsList {
-    /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
-     * indicate free memory. Will remove after all drivers switch to QemuOpts.
-     */
-    bool mallocd;
-
     const char *name;
     const char *implied_opt_name;
     bool merge_lists;  /* Merge multiple uses of option into a single list? */
diff --git a/util/qemu-option.c b/util/qemu-option.c
index c98f729..752f220 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1054,26 +1054,12 @@ static size_t count_opts_list(QemuOptsList *list)
 
 void qemu_opts_free(QemuOptsList *list)
 {
-    /* List members point to new malloced space and need to free.
-     * FIXME:
-     * Introduced for QEMUOptionParamter->QemuOpts conversion.
-     * Will remove after all drivers switch to QemuOpts.
-     */
-    if (list && list->mallocd) {
-        QemuOptDesc *desc = list->desc;
-        while (desc && desc->name) {
-            g_free((char *)desc->name);
-            g_free((char *)desc->help);
-            g_free((char *)desc->def_value_str);
-            desc++;
-        }
-    }
-
     g_free(list);
 }
 
 /* Realloc dst option list and append options from an option list (list)
  * to it. dst could be NULL or a malloced list.
+ * Result dst has shorter lifetime then input list.
  */
 QemuOptsList *qemu_opts_append(QemuOptsList *dst,
                                QemuOptsList *list)
@@ -1102,23 +1088,15 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
         dst->name = NULL;
         dst->implied_opt_name = NULL;
         QTAILQ_INIT(&dst->head);
-        dst->mallocd = true;
     }
     dst->desc[num_dst_opts].name = NULL;
 
-    /* (const char *) members of result dst are malloced, need free. */
-    assert(dst->mallocd);
     /* append list->desc to dst->desc */
     if (list) {
         desc = list->desc;
         while (desc && desc->name) {
             if (find_desc_by_name(dst->desc, desc->name) == NULL) {
-                dst->desc[num_dst_opts].name = g_strdup(desc->name);
-                dst->desc[num_dst_opts].type = desc->type;
-                dst->desc[num_dst_opts].help = g_strdup(desc->help);
-                dst->desc[num_dst_opts].def_value_str =
-                                         g_strdup(desc->def_value_str);
-                num_dst_opts++;
+                dst->desc[num_dst_opts++] = *desc;
                 dst->desc[num_dst_opts].name = NULL;
             }
             desc++;
-- 
1.7.12.4

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

* Re: [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 01/32] move find_desc_by_name ahead for later calling Chunyan Liu
@ 2014-03-21 23:16   ` Eric Blake
  0 siblings, 0 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-21 23:16 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  util/qemu-option.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)

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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options Chunyan Liu
@ 2014-03-21 23:27   ` Eric Blake
  2014-03-24  3:18     ` Chun Yan Liu
  0 siblings, 1 reply; 59+ messages in thread
From: Eric Blake @ 2014-03-21 23:27 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> Change qapi interfaces to output the newly added def_value_str when querying
> command line options.
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> 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 b68cd44..cf9174e 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4088,12 +4088,16 @@
>  #
>  # @help: #optional human readable text string, not suitable for parsing.
>  #
> +# @default: #optional string representation of the default used
> +#           if the option is omitted. (since 2.0)

We've missed 2.0; this needs to be 2.1 now.

However, I'm okay if you keep my Reviewed-by with just that change.

-- 
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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 03/32] qapi: output def_value_str when query command line options
  2014-03-21 23:27   ` Eric Blake
@ 2014-03-24  3:18     ` Chun Yan Liu
  0 siblings, 0 replies; 59+ messages in thread
From: Chun Yan Liu @ 2014-03-24  3:18 UTC (permalink / raw)
  To: qemu-devel, Eric Blake; +Cc: stefanha

I'll update.
All patch series could also be available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

>>> On 3/22/2014 at 07:27 AM, in message <532CCADC.40607@redhat.com>, Eric Blake
<eblake@redhat.com> wrote: 
> On 03/21/2014 04:12 AM, Chunyan Liu wrote: 
> > Change qapi interfaces to output the newly added def_value_str when  
> querying 
> > command line options. 
> >  
> > Reviewed-by: Eric Blake <eblake@redhat.com> 
> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> 
> > 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 b68cd44..cf9174e 100644 
> > --- a/qapi-schema.json 
> > +++ b/qapi-schema.json 
> > @@ -4088,12 +4088,16 @@ 
> >  # 
> >  # @help: #optional human readable text string, not suitable for parsing. 
> >  # 
> > +# @default: #optional string representation of the default used 
> > +#           if the option is omitted. (since 2.0) 
>  
> We've missed 2.0; this needs to be 2.1 now. 
>  
> However, I'm okay if you keep my Reviewed-by with just that change. 
>  
> --  
> Eric Blake   eblake redhat com    +1-919-301-3266 
> Libvirt virtualization library http://libvirt.org 
>  
>  

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

* Re: [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 31/32] cleanup QEMUOptionParameter Chunyan Liu
@ 2014-03-25 18:02   ` Leandro Dorileo
  0 siblings, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 18:02 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

On Fri, Mar 21, 2014 at 06:12:42PM +0800, Chunyan Liu wrote:
> Now that all backend drivers are using QemuOpts, remove all
> QEMUOptionParameter related codes.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block.c                   |  85 ++-------
>  block/cow.c               |   4 +-
>  block/gluster.c           |   8 +-
>  block/iscsi.c             |   2 +-
>  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             |  12 +-
>  include/block/block.h     |   8 +-
>  include/block/block_int.h |  16 +-
>  include/qemu/option.h     |  48 +-----
>  qemu-img.c                |  19 +--
>  util/qemu-option.c        | 427 +---------------------------------------------
>  23 files changed, 67 insertions(+), 616 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 125279c..1f11007 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;
> @@ -420,27 +419,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
>  
>      CreateCo *cco = opaque;
>      assert(cco->drv);
> -    assert(!(cco->options && cco->opts));
>  
> -    if (cco->drv->bdrv_create2) {
> -        QemuOptsList *opts_list = NULL;
> -        QemuOpts *opts = NULL;
> -        if (!cco->opts) {
> -            opts_list = params_to_opts(cco->options);
> -            cco->opts = opts =
> -                qemu_opts_create(opts_list, NULL, 0, &error_abort);
> -        }
> -        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
> -        qemu_opts_del(opts);
> -        qemu_opts_free(opts_list);
> -    } else {
> -        QEMUOptionParameter *options = NULL;
> -        if (!cco->options) {
> -            cco->options = options = opts_to_params(cco->opts);
> -        }
> -        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
> -        free_option_parameters(options);
> -    }
> +    ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err);
>      if (local_err) {
>          error_propagate(&cco->err, local_err);
>      }
> @@ -448,7 +428,6 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
>  }
>  
>  int bdrv_create(BlockDriver *drv, const char* filename,
> -                QEMUOptionParameter *options,
>                  QemuOpts *opts, Error **errp)
>  {
>      int ret;
> @@ -457,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;
> @@ -494,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;
> @@ -507,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);
>      }
> @@ -1270,7 +1247,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
>          BlockDriverState *bs1;
>          int64_t total_size;
>          BlockDriver *bdrv_qcow2;
> -        QemuOptsList *create_opts = NULL;
>          QemuOpts *opts = NULL;
>          QDict *snapshot_options;
>  
> @@ -1297,20 +1273,12 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
>          }
>  
>          bdrv_qcow2 = bdrv_find_format("qcow2");
> -
> -        assert(!(bdrv_qcow2->create_options && bdrv_qcow2->create_opts));
> -        if (bdrv_qcow2->create_options) {
> -            create_opts = params_to_opts(bdrv_qcow2->create_options);
> -        } else {
> -            create_opts = bdrv_qcow2->create_opts;
> -        }
> -        opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> +        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, NULL, opts, &local_err);
> +
> +        ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
>          qemu_opts_del(opts);
> -        if (bdrv_qcow2->create_options) {
> -            qemu_opts_free(create_opts);
> -        }
>          if (ret < 0) {
>              error_setg_errno(errp, -ret, "Could not create temporary overlay "
>                               "'%s': %s", tmp_filename,
> @@ -5311,10 +5279,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
>          return;
>      }
>  
> -    create_opts = qemu_opts_append(create_opts, drv->create_opts,
> -                                   drv->create_options);
> -    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
> -                                   proto_drv->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);
> @@ -5407,7 +5373,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
>          puts("");
>      }
>  
> -    ret = bdrv_create(drv, filename, NULL, opts, &local_err);
> +    ret = bdrv_create(drv, filename, opts, &local_err);
>  
>      if (ret == -EFBIG) {
>          /* This is generally a better message than whatever the driver would
> @@ -5443,35 +5409,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)
>  {
> -    int ret;
> -    assert(!(options && 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) {
> -        QemuOptsList *tmp_opts_list = NULL;
> -        QemuOpts *tmp_opts = NULL;
> -        if (options) {
> -            tmp_opts_list = params_to_opts(options);
> -            opts = tmp_opts =
> -                qemu_opts_create(tmp_opts_list, NULL, 0, &error_abort);
> -        }
> -        ret = bs->drv->bdrv_amend_options2(bs, opts);
> -        qemu_opts_del(tmp_opts);
> -        qemu_opts_free(tmp_opts_list);
> -    } else {
> -        QEMUOptionParameter *param = NULL;
> -        if (opts) {
> -            options = param = opts_to_params(opts);
> -        }
> -        ret = bs->drv->bdrv_amend_options(bs, options);
> -        free_option_parameters(param);
> -    }
> -    return ret;
> +    return bs->drv->bdrv_amend_options(bs, opts);
>  }
>  
>  /* This function will be called by the bdrv_recurse_is_first_non_filter method
> diff --git a/block/cow.c b/block/cow.c
> index fb2cd68..d49ed17 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 c5a519e..b1633e2 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/iscsi.c b/block/iscsi.c
> index 316e1b9..4379d14 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -1467,7 +1467,7 @@ static BlockDriver bdrv_iscsi = {
>      .bdrv_needs_filename = true,
>      .bdrv_file_open  = iscsi_open,
>      .bdrv_close      = iscsi_close,
> -    .bdrv_create2    = iscsi_create,
> +    .bdrv_create     = iscsi_create,


The iscsi_create function is still expecting QEMUOptionParameter
instead of QemuOpts, and the function implementation is still
expecting an argument named opts instead of options.


>      .create_opts     = &iscsi_create_opts,
>      .bdrv_reopen_prepare  = iscsi_reopen_prepare,
>  
> 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 d8e72a5..28184cc 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -1504,7 +1504,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;
> @@ -2257,7 +2257,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,
> @@ -2289,7 +2289,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 ae7b98f..2dbbcfe 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;
> @@ -1635,7 +1635,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 e72f449..f51f31d 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,
> @@ -1827,7 +1827,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,
>  
> @@ -1971,7 +1971,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,
> @@ -2096,7 +2096,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,
> @@ -2227,7 +2227,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 b00d7fc..7bc04bd 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 fc0d5a4..677a88e 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -796,7 +796,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 82b1521..1ccab39 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -2907,7 +2907,6 @@ static BlockDriver vvfat_write_target = {
>  static int enable_write_target(BDRVVVFATState *s)
>  {
>      BlockDriver *bdrv_qcow;
> -    QemuOptsList *create_opts;
>      QemuOpts *opts;
>      Error *local_err = NULL;
>      int ret;
> @@ -2923,17 +2922,11 @@ static int enable_write_target(BDRVVVFATState *s)
>      }
>  
>      bdrv_qcow = bdrv_find_format("qcow");
> -    assert(!(bdrv_qcow->create_opts && bdrv_qcow->create_options));
> -    if (bdrv_qcow->create_options) {
> -        create_opts = params_to_opts(bdrv_qcow->create_options);
> -    } else {
> -        create_opts = bdrv_qcow->create_opts;
> -    }
> -    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
> +    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, 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);
> @@ -2963,7 +2956,6 @@ static int enable_write_target(BDRVVVFATState *s)
>  
>  err:
>      qemu_opts_del(opts);
> -    qemu_opts_free(create_opts);
>      g_free(s->qcow_filename);
>      s->qcow_filename = NULL;
>      return ret;
> diff --git a/include/block/block.h b/include/block/block.h
> index 6fc9777..6c0ead2 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 */
>  bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
> diff --git a/include/block/block_int.h b/include/block/block_int.h
> index f9d87da..bf5b4ed 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,10 +215,6 @@ struct BlockDriver {
>          BlockDriverCompletionFunc *cb, void *opaque);
>  
>      /* List of options for creating images, terminated by name == NULL */
> -    QEMUOptionParameter *create_options;
> -    /* FIXME: will replace create_options.
> -     * These two fields are mutually exclusive. At most one is non-NULL.
> -     */
>      QemuOptsList *create_opts;
>  
>      /*
> @@ -231,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 120c998..30533d2 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -31,25 +31,6 @@
>  #include "qapi/error.h"
>  #include "qapi/qmp/qdict.h"
>  
> -enum QEMUOptionParType {
> -    OPT_FLAG,
> -    OPT_NUMBER,
> -    OPT_SIZE,
> -    OPT_STRING,
> -};
> -
> -typedef struct QEMUOptionParameter {
> -    const char *name;
> -    enum QEMUOptionParType type;
> -    union {
> -        uint64_t n;
> -        char* s;
> -    } value;
> -    const char *help;
> -    bool assigned;
> -} QEMUOptionParameter;
> -
> -
>  const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
>  const char *get_opt_value(char *buf, int buf_size, const char *p);
>  int get_next_param_value(char *buf, int buf_size,
> @@ -58,32 +39,11 @@ 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;
> @@ -173,12 +133,6 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
>                        int abort_on_failure);
>  void qemu_opts_print_help(QemuOptsList *list);
>  void qemu_opts_free(QemuOptsList *list);
> -QEMUOptionParameter *opts_to_params(QemuOpts *opts);
> -QemuOptsList *params_to_opts(QEMUOptionParameter *list);
> -/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
> - */
> -QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> -                               QemuOptsList *list,
> -                               QEMUOptionParameter *param);
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
>  
>  #endif
> diff --git a/qemu-img.c b/qemu-img.c
> index e78e933..771843f 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -244,16 +244,14 @@ static int print_block_option_help(const char *filename, const char *fmt)
>          return 1;
>      }
>  
> -    create_opts = qemu_opts_append(create_opts, drv->create_opts,
> -                                   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;
>          }
> -        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
> -                                       proto_drv->create_options);
> +        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
>      }
>  
>      qemu_opts_print_help(create_opts);
> @@ -1340,10 +1338,8 @@ static int img_convert(int argc, char **argv)
>          goto out;
>      }
>  
> -    create_opts = qemu_opts_append(create_opts, drv->create_opts,
> -                                   drv->create_options);
> -    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts,
> -                                   proto_drv->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)) {
> @@ -1396,7 +1392,7 @@ static int img_convert(int argc, char **argv)
>  
>      if (!skip_create) {
>          /* Create the new image */
> -        ret = bdrv_create(drv, out_filename, NULL, opts, &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));
> @@ -2718,8 +2714,7 @@ static int img_amend(int argc, char **argv)
>          goto out;
>      }
>  
> -    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts,
> -                                   bs->drv->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);
> @@ -2727,7 +2722,7 @@ static int img_amend(int argc, char **argv)
>          goto out;
>      }
>  
> -    ret = bdrv_amend_options(bs, NULL, opts);
> +    ret = bdrv_amend_options(bs, opts);
>      if (ret < 0) {
>          error_report("Error while amending options: %s", strerror(-ret));
>          goto out;
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index a9c53cd..c98f729 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -123,22 +123,6 @@ int get_param_value(char *buf, int buf_size,
>      return get_next_param_value(buf, buf_size, tag, &str);
>  }
>  
> -/*
> - * Searches an option list for an option with the given name
> - */
> -QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
> -    const char *name)
> -{
> -    while (list && list->name) {
> -        if (!strcmp(list->name, name)) {
> -            return list;
> -        }
> -        list++;
> -    }
> -
> -    return NULL;
> -}
> -
>  static void parse_option_bool(const char *name, const char *value, bool *ret,
>                                Error **errp)
>  {
> @@ -226,244 +210,6 @@ void parse_option_size(const char *name, const char *value,
>      }
>  }
>  
> -/*
> - * Sets the value of a parameter in a given option list. The parsing of the
> - * value depends on the type of option:
> - *
> - * OPT_FLAG (uses value.n):
> - *      If no value is given, the flag is set to 1.
> - *      Otherwise the value must be "on" (set to 1) or "off" (set to 0)
> - *
> - * OPT_STRING (uses value.s):
> - *      value is strdup()ed and assigned as option value
> - *
> - * OPT_SIZE (uses value.n):
> - *      The value is converted to an integer. Suffixes for kilobytes etc. are
> - *      allowed (powers of 1024).
> - *
> - * Returns 0 on succes, -1 in error cases
> - */
> -int set_option_parameter(QEMUOptionParameter *list, const char *name,
> -    const char *value)
> -{
> -    bool flag;
> -    Error *local_err = NULL;
> -
> -    // Find a matching parameter
> -    list = get_option_parameter(list, name);
> -    if (list == NULL) {
> -        fprintf(stderr, "Unknown option '%s'\n", name);
> -        return -1;
> -    }
> -
> -    // Process parameter
> -    switch (list->type) {
> -    case OPT_FLAG:
> -        parse_option_bool(name, value, &flag, &local_err);
> -        if (!local_err) {
> -            list->value.n = flag;
> -        }
> -        break;
> -
> -    case OPT_STRING:
> -        if (value != NULL) {
> -            list->value.s = g_strdup(value);
> -        } else {
> -            fprintf(stderr, "Option '%s' needs a parameter\n", name);
> -            return -1;
> -        }
> -        break;
> -
> -    case OPT_SIZE:
> -        parse_option_size(name, value, &list->value.n, &local_err);
> -        break;
> -
> -    default:
> -        fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
> -        return -1;
> -    }
> -
> -    if (local_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;
> -}
> -
> -/*
> - * 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;
> @@ -513,46 +259,6 @@ out:
>      return result;
>  }
>  
> -/*
> - * Prints all options of a list that have a value to stdout
> - */
> -void print_option_parameters(QEMUOptionParameter *list)
> -{
> -    while (list && list->name) {
> -        switch (list->type) {
> -            case OPT_STRING:
> -                 if (list->value.s != NULL) {
> -                     printf("%s='%s' ", list->name, list->value.s);
> -                 }
> -                break;
> -            case OPT_FLAG:
> -                printf("%s=%s ", list->name, list->value.n ? "on" : "off");
> -                break;
> -            case OPT_SIZE:
> -            case OPT_NUMBER:
> -                printf("%s=%" PRId64 " ", list->name, list->value.n);
> -                break;
> -            default:
> -                printf("%s=(unknown type) ", list->name);
> -                break;
> -        }
> -        list++;
> -    }
> -}
> -
> -/*
> - * Prints an overview of all available options
> - */
> -void print_option_help(QEMUOptionParameter *list)
> -{
> -    printf("Supported options:\n");
> -    while (list && list->name) {
> -        printf("%-16s %s\n", list->name,
> -            list->help ? list->help : "No description available");
> -        list++;
> -    }
> -}
> -
>  void qemu_opts_print_help(QemuOptsList *list)
>  {
>      int i;
> @@ -1346,122 +1052,6 @@ static size_t count_opts_list(QemuOptsList *list)
>      return num_opts;
>  }
>  
> -/* Convert QEMUOptionParameter to QemuOpts
> - * FIXME: this function will be removed after all drivers
> - * switch to QemuOpts
> - */
> -QemuOptsList *params_to_opts(QEMUOptionParameter *list)
> -{
> -    QemuOptsList *opts = NULL;
> -    size_t num_opts, i = 0;
> -
> -    if (!list) {
> -        return NULL;
> -    }
> -
> -    num_opts = count_option_parameters(list);
> -    opts = g_malloc0(sizeof(QemuOptsList) +
> -                     (num_opts + 1) * sizeof(QemuOptDesc));
> -    QTAILQ_INIT(&opts->head);
> -    /* (const char *) members will point to malloced space and need to free */
> -    opts->mallocd = true;
> -
> -    while (list && list->name) {
> -        opts->desc[i].name = g_strdup(list->name);
> -        opts->desc[i].help = g_strdup(list->help);
> -        switch (list->type) {
> -        case OPT_FLAG:
> -            opts->desc[i].type = QEMU_OPT_BOOL;
> -            opts->desc[i].def_value_str =
> -                g_strdup(list->value.n ? "on" : "off");
> -            break;
> -
> -        case OPT_NUMBER:
> -            opts->desc[i].type = QEMU_OPT_NUMBER;
> -            if (list->value.n) {
> -                opts->desc[i].def_value_str =
> -                    g_strdup_printf("%" PRIu64, list->value.n);
> -            }
> -            break;
> -
> -        case OPT_SIZE:
> -            opts->desc[i].type = QEMU_OPT_SIZE;
> -            if (list->value.n) {
> -                opts->desc[i].def_value_str =
> -                    g_strdup_printf("%" PRIu64, list->value.n);
> -            }
> -            break;
> -
> -        case OPT_STRING:
> -            opts->desc[i].type = QEMU_OPT_STRING;
> -            opts->desc[i].def_value_str = g_strdup(list->value.s);
> -            break;
> -        }
> -
> -        i++;
> -        list++;
> -        opts->desc[i].name = NULL;
> -    }
> -
> -    return opts;
> -}
> -
> -/* convert QemuOpts to QEMUOptionParamter
> - * Note: result QEMUOptionParameter has shorter lifetime than
> - * input QemuOpts.
> - * FIXME: this function will be removed after all drivers
> - * switch to QemuOpts
> - */
> -QEMUOptionParameter *opts_to_params(QemuOpts *opts)
> -{
> -    QEMUOptionParameter *dest = NULL;
> -    QemuOptDesc *desc;
> -    size_t num_opts, i = 0;
> -    const char *tmp;
> -
> -    if (!opts || !opts->list || !opts->list->desc) {
> -        return NULL;
> -    }
> -    assert(!opts_accepts_any(opts));
> -
> -    num_opts = count_opts_list(opts->list);
> -    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
> -
> -    desc = opts->list->desc;
> -    while (desc && desc->name) {
> -        dest[i].name = desc->name;
> -        dest[i].help = 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;
> -}
> -
>  void qemu_opts_free(QemuOptsList *list)
>  {
>      /* List members point to new malloced space and need to free.
> @@ -1482,28 +1072,20 @@ void qemu_opts_free(QemuOptsList *list)
>      g_free(list);
>  }
>  
> -/* Realloc dst option list and append options either from an option list (list)
> - * or an QEMUOptionParameter (param) to it. dst could be NULL or a malloced list.
> - * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
> +/* Realloc dst option list and append options from an option list (list)
> + * to it. dst could be NULL or a malloced list.
>   */
>  QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> -                               QemuOptsList *list,
> -                               QEMUOptionParameter *param)
> +                               QemuOptsList *list)
>  {
>      size_t num_opts, num_dst_opts;
> -    QemuOptsList *tmp_list = NULL;
>      QemuOptDesc *desc;
>      bool need_init = false;
>  
> -    assert(!(list && param));
> -    if (!param &&!list) {
> +    if (!list) {
>          return dst;
>      }
>  
> -    if (param) {
> -        list = tmp_list = params_to_opts(param);
> -    }
> -
>      /* If dst is NULL, after realloc, some area of dst should be initialized
>       * before adding options to it.
>       */
> @@ -1543,6 +1125,5 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
>          }
>      }
>  
> -    g_free(tmp_list);
>      return dst;
>  }
> -- 
> 1.7.12.4
> 
> 

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts
  2014-03-21 10:12 [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Chunyan Liu
                   ` (31 preceding siblings ...)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 32/32] cleanup tmp 'mallocd' member from QemuOptsList Chunyan Liu
@ 2014-03-25 18:09 ` Leandro Dorileo
  2014-03-25 20:22   ` Leandro Dorileo
  2014-03-26 15:18   ` Stefan Hajnoczi
  32 siblings, 2 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 18:09 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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


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

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

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

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

Regards...

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *) Chunyan Liu
@ 2014-03-25 19:00   ` Leandro Dorileo
  2014-03-25 19:23   ` Eric Blake
  1 sibling, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 19:00 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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


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

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

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

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

Regards...

-- 
Leandro Dorileo

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

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

* Re: [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help Chunyan Liu
@ 2014-03-25 19:07   ` Leandro Dorileo
  2014-03-25 20:43   ` Eric Blake
  1 sibling, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 19:07 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

On Fri, Mar 21, 2014 at 06:12:18PM +0800, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>


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


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

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters Chunyan Liu
@ 2014-03-25 19:13   ` Leandro Dorileo
  2014-03-25 21:40   ` Eric Blake
  1 sibling, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 19:13 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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

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


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

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 14/32] vvfat.c: handle cross_driver's create_options and create_opts Chunyan Liu
@ 2014-03-25 19:17   ` Leandro Dorileo
  0 siblings, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 19:17 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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


opts is used uninitialized.


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

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *)
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 04/32] change opt->name and opt->str from (const char *) to (char *) Chunyan Liu
  2014-03-25 19:00   ` Leandro Dorileo
@ 2014-03-25 19:23   ` Eric Blake
  1 sibling, 0 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-25 19:23 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:

Your subject says "what", but your commit message lacks a "why".
Without a good reason, it's hard to see what this patch is good for.
May I suggest:

qemu_opt_del() already assumes that all QemuOpt instances contain
malloc'd name and value; but it had to cast away const because
opts_start_struct() was doing its own thing and using static storage
instead.  By using the correct type and malloced strings everywhere, the
usage of this struct becomes clearer.

> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option_int.h |  4 ++--
>  qapi/opts-visitor.c       | 10 +++++++---
>  util/qemu-option.c        |  4 ++--
>  3 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
> index 8212fa4..db9ed91 100644
> --- a/include/qemu/option_int.h
> +++ b/include/qemu/option_int.h
> @@ -30,8 +30,8 @@
>  #include "qemu/error-report.h"
>  
>  struct QemuOpt {
> -    const char   *name;
> -    const char   *str;
> +    char   *name;
> +    char   *str;

While touching this, is it worth trimming the extra spacing before '*'?
 It's not like you are preserving alignment or anything.  But as that's
cosmetic, and as the code itself is correct, I'm fine if you add this
when you expand your commit message:

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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend Chunyan Liu
@ 2014-03-25 19:25   ` Leandro Dorileo
  2014-03-26  7:37     ` Chunyan Liu
  0 siblings, 1 reply; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 19:25 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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


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

Regards...

--
Leandro Dorileo


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

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 05/32] move qemu_opt_del ahead for later calling
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 05/32] move qemu_opt_del ahead for later calling Chunyan Liu
@ 2014-03-25 19:29   ` Eric Blake
  0 siblings, 0 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-25 19:29 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> In later patch, qemu_opt_get_del functions will be added, they will
> first get the option value, then call qemu_opt_del to remove the option
> from opt list. To prepare for that purpose, move qemu_opt_del ahead first.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  util/qemu-option.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)

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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 11/32] qemu_opts_print: change fprintf stderr to printf Chunyan Liu
@ 2014-03-25 20:10   ` Leandro Dorileo
  0 siblings, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 20:10 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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


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

Regards...

--
Leandro Dorileo

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

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

* Re: [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts
  2014-03-25 18:09 ` [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Leandro Dorileo
@ 2014-03-25 20:22   ` Leandro Dorileo
  2014-03-26 15:18   ` Stefan Hajnoczi
  1 sibling, 0 replies; 59+ messages in thread
From: Leandro Dorileo @ 2014-03-25 20:22 UTC (permalink / raw)
  To: Chunyan Liu; +Cc: qemu-devel, stefanha

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


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

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

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

Regards...

-- 
Leandro Dorileo

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

* Re: [Qemu-devel] [PATCH v23 06/32] add qemu_opt_get_*_del functions for replace work
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 06/32] add qemu_opt_get_*_del functions for replace work Chunyan Liu
@ 2014-03-25 20:33   ` Eric Blake
  0 siblings, 0 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-25 20:33 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> Add qemu_opt_get_del, qemu_opt_get_bool_del and qemu_opt_get_number_gel

s/gel/del/

Any reason you don't mention qemu_opt_get_size_del here?

> to replace the same handling of QEMUOptionParamter (get and delete).

s/Paramter/Parameter/

> 
> get_*_del purpose:
> 
> In specific driver (like "qcow2"), it only handles expected options, then
> delete them from option list. Leave the left options to be passed down
> to 2nd driver (like "raw") to do 2nd handling.

Awkward wording.  I suggest replacing these two paragraphs with:

Several drivers are coded to parse a known subset of options, then
remove them for the list before handing all remaining options to a
second driver for further option processing.  get_*_del makes it easier
to retrieve a known option (or its default) and remove it from the list
all in one action.

> +++ b/util/qemu-option.c
> @@ -588,6 +588,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)

It would help to add documentation to this function; particularly that
the caller must use g_free() on the result (in contrast to qemu_opt_get
where they must NOT use g_free).

> +    str = g_strdup(opt->str);

We could play a game with transfer semantics for fewer mallocs, by
writing this as:

str = opt->str;
opt->str = NULL;

but not the end of the world if you keep it as-is.

-- 
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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help Chunyan Liu
  2014-03-25 19:07   ` Leandro Dorileo
@ 2014-03-25 20:43   ` Eric Blake
  2014-03-26  2:58     ` Chunyan Liu
  1 sibling, 1 reply; 59+ messages in thread
From: Eric Blake @ 2014-03-25 20:43 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c    | 11 +++++++++++
>  2 files changed, 12 insertions(+)
> 

> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> +    int i;
> +
> +    printf("Supported options:\n");
> +    for (i = 0; list && list->desc[i].name; i++) {

Similar to print_option_help(), this prints "Supported options:\n" on a
line by itself if list is NULL.  But do any of the drivers/protocols
actually lack options?  Is it worth guaranteeing that this is only used
on non-empty lists?  What would happen if you wrote this as:

assert(list);
for (i = 0; list->desc[i].name; i++) { ...

or even

QemuOptDesc *desc;
assert(list);
desc = list->desc;
while (desc->name) {
    ...
    desc++;
}

-- 
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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts Chunyan Liu
@ 2014-03-25 21:35   ` Eric Blake
  2014-03-26  3:26     ` Chunyan Liu
  2014-03-26  6:30     ` Chunyan Liu
  0 siblings, 2 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-25 21:35 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> Add two temp convert functions between QEMUOptionParameter to QemuOpts,

s/convert/conversion/ here and in subject

> so that next patch can use it. It will simplify later patch for easier
> review. And will be finally removed after all backend drivers switch to
> QemuOpts.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---

> +++ b/include/qemu/option.h
> @@ -103,6 +103,11 @@ typedef struct QemuOptDesc {
>  } QemuOptDesc;
>  
>  struct QemuOptsList {
> +    /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
> +     * indicate free memory. Will remove after all drivers switch to QemuOpts.
> +     */
> +    bool mallocd;

Spelling looks odd; I might have used 'allocated'.  But as it gets
deleted later, I don't care.

> +    num_opts = count_option_parameters(list);
> +    opts = g_malloc0(sizeof(QemuOptsList) +
> +                     (num_opts + 1) * sizeof(QemuOptDesc));

[1]...

> +    while (list && list->name) {
> +        opts->desc[i].name = g_strdup(list->name);
> +        opts->desc[i].help = g_strdup(list->help);
> +        switch (list->type) {
> +        case OPT_FLAG:
> +            opts->desc[i].type = QEMU_OPT_BOOL;
> +            opts->desc[i].def_value_str =
> +                g_strdup(list->value.n ? "on" : "off");

This always sets def_value_str...

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

...whereas this only sets def_value_str for non-zero values.  But can't
0 be a valid setting?  Is this mismatch in what gets converted going to
bite us?  Should you be paying attention to list->assigned instead or in
addition to just checking for non-zero values?

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

Same question for 0 values.

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

...[1] This assignment is dead code, because you used malloc0 which
guarantees that desc[i].name is already NULL.

> +/* convert QemuOpts to QEMUOptionParamter

s/Paramter/Parameter/

> + * Note: result QEMUOptionParameter has shorter lifetime than
> + * input QemuOpts.
> + * FIXME: this function will be removed after all drivers
> + * switch to QemuOpts
> + */
> +QEMUOptionParameter *opts_to_params(QemuOpts *opts)
> +{

> +    num_opts = count_opts_list(opts->list);
> +    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
> +

> +        i++;
> +        desc++;
> +        dest[i].name = NULL;

Another dead assignment.

> +    }
> +
> +    return dest;
> +}
> +
> +void qemu_opts_free(QemuOptsList *list)
> +{
> +    /* List members point to new malloced space and need to free.
> +     * FIXME:
> +     * Introduced for QEMUOptionParamter->QemuOpts conversion.
> +     * Will remove after all drivers switch to QemuOpts.
> +     */
> +    if (list && list->mallocd) {
> +        QemuOptDesc *desc = list->desc;
> +        while (desc && desc->name) {
> +            g_free((char *)desc->name);
> +            g_free((char *)desc->help);

Are these casts still necessary, given patch 4?

> +            g_free((char *)desc->def_value_str);

However, it looks like you are correct that this one is casting away const.

-- 
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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 09/32] add qemu_opts_append to repalce append_option_parameters Chunyan Liu
  2014-03-25 19:13   ` Leandro Dorileo
@ 2014-03-25 21:40   ` Eric Blake
  1 sibling, 0 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-25 21:40 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:

s/repalce/replace/ in subject

Also, your overall series could probably use subject lines with a prefix
that makes it obvious they are related to a common category; maybe "opts: ".

> For later merge .create_opts of drv and proto_drv in qemu-img commands.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---

> +
> +/* Realloc dst option list and append options either from an option list (list)
> + * or an QEMUOptionParameter (param) to it. dst could be NULL or a malloced list.

s/an QEMU/a QEMU/

> + * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
> + */
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> +                               QemuOptsList *list,
> +                               QEMUOptionParameter *param)
> +{
> +    size_t num_opts, num_dst_opts;
> +    QemuOptsList *tmp_list = NULL;
> +    QemuOptDesc *desc;
> +    bool need_init = false;
> +
> +    assert(!(list && param));
> +    if (!param &&!list) {

Space after &&

-- 
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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 10/32] check NULL input for qemu_opts_del
  2014-03-21 10:12 ` [Qemu-devel] [PATCH v23 10/32] check NULL input for qemu_opts_del Chunyan Liu
@ 2014-03-25 21:41   ` Eric Blake
  0 siblings, 0 replies; 59+ messages in thread
From: Eric Blake @ 2014-03-25 21:41 UTC (permalink / raw)
  To: Chunyan Liu, qemu-devel; +Cc: stefanha

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

On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> To simplify later using of qemu_opts_del, accept NULL input.
> 
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  util/qemu-option.c | 4 ++++
>  1 file changed, 4 insertions(+)

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

> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 6c304b2..e9802f3 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -990,6 +990,10 @@ void qemu_opts_del(QemuOpts *opts)
>  {
>      QemuOpt *opt;
>  
> +    if (opts == NULL) {
> +        return;
> +    }
> +
>      for (;;) {
>          opt = QTAILQ_FIRST(&opts->head);
>          if (opt == NULL)
> 

-- 
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] 59+ messages in thread

* Re: [Qemu-devel] [PATCH v23 07/32] add qemu_opts_print_help to replace print_option_help
  2014-03-25 20:43   ` Eric Blake
@ 2014-03-26  2:58     ` Chunyan Liu
  0 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-26  2:58 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, Stefan Hajnoczi

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

2014-03-26 4:43 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> > print_option_help takes QEMUOptionParameter as parameter, add
> > qemu_opts_print_help to take QemuOptsList as parameter for later
> > replace work.
> >
> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  include/qemu/option.h |  1 +
> >  util/qemu-option.c    | 11 +++++++++++
> >  2 files changed, 12 insertions(+)
> >
>
> > +void qemu_opts_print_help(QemuOptsList *list)
> > +{
> > +    int i;
> > +
> > +    printf("Supported options:\n");
> > +    for (i = 0; list && list->desc[i].name; i++) {
>
> Similar to print_option_help(), this prints "Supported options:\n" on a
> line by itself if list is NULL.  But do any of the drivers/protocols
> actually lack options?


Yes, vvfat has no .create_options. Will update.


>  Is it worth guaranteeing that this is only used
> on non-empty lists?  What would happen if you wrote this as:
>
> assert(list);
> for (i = 0; list->desc[i].name; i++) { ...
>
> or even
>
> QemuOptDesc *desc;
> assert(list);
> desc = list->desc;
> while (desc->name) {
>     ...
>     desc++;
> }
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

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

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

* Re: [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts
  2014-03-25 21:35   ` Eric Blake
@ 2014-03-26  3:26     ` Chunyan Liu
  2014-03-26  6:30     ` Chunyan Liu
  1 sibling, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-26  3:26 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, Stefan Hajnoczi

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

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

> On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> > Add two temp convert functions between QEMUOptionParameter to QemuOpts,
>
> s/convert/conversion/ here and in subject
>
> > so that next patch can use it. It will simplify later patch for easier
> > review. And will be finally removed after all backend drivers switch to
> > QemuOpts.
> >
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
>
> > +++ b/include/qemu/option.h
> > @@ -103,6 +103,11 @@ typedef struct QemuOptDesc {
> >  } QemuOptDesc;
> >
> >  struct QemuOptsList {
> > +    /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
> > +     * indicate free memory. Will remove after all drivers switch to
> QemuOpts.
> > +     */
> > +    bool mallocd;
>
> Spelling looks odd; I might have used 'allocated'.  But as it gets
> deleted later, I don't care.
>
> > +    num_opts = count_option_parameters(list);
> > +    opts = g_malloc0(sizeof(QemuOptsList) +
> > +                     (num_opts + 1) * sizeof(QemuOptDesc));
>
> [1]...
>
> > +    while (list && list->name) {
> > +        opts->desc[i].name = g_strdup(list->name);
> > +        opts->desc[i].help = g_strdup(list->help);
> > +        switch (list->type) {
> > +        case OPT_FLAG:
> > +            opts->desc[i].type = QEMU_OPT_BOOL;
> > +            opts->desc[i].def_value_str =
> > +                g_strdup(list->value.n ? "on" : "off");
>
> This always sets def_value_str...
>
> > +            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);
> > +            }
>
> ...whereas this only sets def_value_str for non-zero values.  But can't
> 0 be a valid setting?  Is this mismatch in what gets converted going to
> bite us?  Should you be paying attention to list->assigned instead or in
> addition to just checking for non-zero values?


To QemuOptionParameter, 0 value to SIZE/NUMBEr is meaningless, same
effect as not setting the option at all. But yes, we can use list->assigned
to
differentiate option set with 0 value or non-set option.


>
> > +            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);
> > +            }
>
> Same question for 0 values.
>
> > +            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;
>
> ...[1] This assignment is dead code, because you used malloc0 which
> guarantees that desc[i].name is already NULL.
>
> > +/* convert QemuOpts to QEMUOptionParamter
>
> s/Paramter/Parameter/
>
> > + * Note: result QEMUOptionParameter has shorter lifetime than
> > + * input QemuOpts.
> > + * FIXME: this function will be removed after all drivers
> > + * switch to QemuOpts
> > + */
> > +QEMUOptionParameter *opts_to_params(QemuOpts *opts)
> > +{
>
> > +    num_opts = count_opts_list(opts->list);
> > +    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
> > +
>
> > +        i++;
> > +        desc++;
> > +        dest[i].name = NULL;
>
> Another dead assignment.
>
> > +    }
> > +
> > +    return dest;
> > +}
> > +
> > +void qemu_opts_free(QemuOptsList *list)
> > +{
> > +    /* List members point to new malloced space and need to free.
> > +     * FIXME:
> > +     * Introduced for QEMUOptionParamter->QemuOptsList conversion.
> > +     * Will remove after all drivers switch to QemuOptsList.
> > +     */
> > +    if (list && list->mallocd) {
> > +        QemuOptDesc *desc = list->desc;
> > +        while (desc && desc->name) {
> > +            g_free((char *)desc->name);
> > +            g_free((char *)desc->help);
>
> Are these casts still necessary, given patch 4?


Different places, patch 4 changes QemuOpts .name and .str to (char *). Here
is
QemuOptsDesc, in which .name, .help, .def_value_str are (const char *).


> > +            g_free((char *)desc->def_value_str);
>
> However, it looks like you are correct that this one is casting away const.
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

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

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

* Re: [Qemu-devel] [PATCH v23 08/32] add convert functions between QEMUOptionParameter to QemuOpts
  2014-03-25 21:35   ` Eric Blake
  2014-03-26  3:26     ` Chunyan Liu
@ 2014-03-26  6:30     ` Chunyan Liu
  1 sibling, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-26  6:30 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, Stefan Hajnoczi

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

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

> On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> > Add two temp convert functions between QEMUOptionParameter to QemuOpts,
>
> s/convert/conversion/ here and in subject
>
> > so that next patch can use it. It will simplify later patch for easier
> > review. And will be finally removed after all backend drivers switch to
> > QemuOpts.
> >
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
>
> > +++ b/include/qemu/option.h
> > @@ -103,6 +103,11 @@ typedef struct QemuOptDesc {
> >  } QemuOptDesc;
> >
> >  struct QemuOptsList {
> > +    /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
> > +     * indicate free memory. Will remove after all drivers switch to
> QemuOpts.
> > +     */
> > +    bool mallocd;
>
> Spelling looks odd; I might have used 'allocated'.  But as it gets
> deleted later, I don't care.
>
> > +    num_opts = count_option_parameters(list);
> > +    opts = g_malloc0(sizeof(QemuOptsList) +
> > +                     (num_opts + 1) * sizeof(QemuOptDesc));
>
> [1]...
>
> > +    while (list && list->name) {
> > +        opts->desc[i].name = g_strdup(list->name);
> > +        opts->desc[i].help = g_strdup(list->help);
> > +        switch (list->type) {
> > +        case OPT_FLAG:
> > +            opts->desc[i].type = QEMU_OPT_BOOL;
> > +            opts->desc[i].def_value_str =
> > +                g_strdup(list->value.n ? "on" : "off");
>
> This always sets def_value_str...
>

Here, to a boolean type, 0 equals to false.


>
> > +            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);
> > +            }
>
> ...whereas this only sets def_value_str for non-zero values.  But can't
> 0 be a valid setting?  Is this mismatch in what gets converted going to
> bite us?  Should you be paying attention to list->assigned instead or in
> addition to just checking for non-zero values?
>

All places calling params_to_opts() are to convert .create_options to
.create_opts,
and unify later processing. For all OPT_SIZE or OPT_NUMBER option in
.create_options,
if value is set, it won't be 0. 0 equals to "not set". And for the calling
cases, list->assigned
is always false.


>
> > +            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);
> > +            }
>
> Same question for 0 values.
>
> > +            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;
>
> ...[1] This assignment is dead code, because you used malloc0 which
> guarantees that desc[i].name is already NULL.
>
> > +/* convert QemuOpts to QEMUOptionParamter
>
> s/Paramter/Parameter/
>
> > + * Note: result QEMUOptionParameter has shorter lifetime than
> > + * input QemuOpts.
> > + * FIXME: this function will be removed after all drivers
> > + * switch to QemuOpts
> > + */
> > +QEMUOptionParameter *opts_to_params(QemuOpts *opts)
> > +{
>
> > +    num_opts = count_opts_list(opts->list);
> > +    dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
> > +
>
> > +        i++;
> > +        desc++;
> > +        dest[i].name = NULL;
>
> Another dead assignment.
>
> > +    }
> > +
> > +    return dest;
> > +}
> > +
> > +void qemu_opts_free(QemuOptsList *list)
> > +{
> > +    /* List members point to new malloced space and need to free.
> > +     * FIXME:
> > +     * Introduced for QEMUOptionParamter->QemuOpts conversion.
> > +     * Will remove after all drivers switch to QemuOpts.
> > +     */
> > +    if (list && list->mallocd) {
> > +        QemuOptDesc *desc = list->desc;
> > +        while (desc && desc->name) {
> > +            g_free((char *)desc->name);
> > +            g_free((char *)desc->help);
>
> Are these casts still necessary, given patch 4?
>
> > +            g_free((char *)desc->def_value_str);
>
> However, it looks like you are correct that this one is casting away const.
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>

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

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

* Re: [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend
  2014-03-25 19:25   ` Leandro Dorileo
@ 2014-03-26  7:37     ` Chunyan Liu
  2014-03-27  7:27       ` Chunyan Liu
  0 siblings, 1 reply; 59+ messages in thread
From: Chunyan Liu @ 2014-03-26  7:37 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: qemu-devel, Stefan Hajnoczi

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

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

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

To ignore it because options is an array which contains all options
described in
.create_options, not matter it is set or not. Before, it's filtered by
"assigned" info, this
switch may not enter.

But since changing block layer to support both QemuOpts and
QEMUOptionParameter,
QEMUOptionParameter will be converted to QemuOpts for unified processing
and back
for here processing, after two conversions, the assigned info is lost,
without filtering by
"assigned" info, this switch can always enter, and just make the amend work
impossible.

PS:
Add .assigned to QemuOptsDesc might be an easier way for the work.


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

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

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

* Re: [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts
  2014-03-25 18:09 ` [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts Leandro Dorileo
  2014-03-25 20:22   ` Leandro Dorileo
@ 2014-03-26 15:18   ` Stefan Hajnoczi
  2014-03-27  7:20     ` Chunyan Liu
  1 sibling, 1 reply; 59+ messages in thread
From: Stefan Hajnoczi @ 2014-03-26 15:18 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: Chunyan Liu, stefanha, qemu-devel

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

Thanks for pointing this out Leandro.

Chunyan, git tip for running the build and tests for every commit in the
series:

  git rebase -x 'make && make check && cd tests/qemu-iotests && ./check' -i master

It is important that the series is bisectable and builds at every point.

Stefan

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

* Re: [Qemu-devel] [PATCH v23 00/32] replace QEMUOptionParameter with QemuOpts
  2014-03-26 15:18   ` Stefan Hajnoczi
@ 2014-03-27  7:20     ` Chunyan Liu
  0 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-27  7:20 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Leandro Dorileo, Stefan Hajnoczi, qemu-devel

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

2014-03-26 23:18 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:

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

- Chunyan

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

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

* Re: [Qemu-devel] [PATCH v23 12/32] qcow2.c: remove 'assigned' check in amend
  2014-03-26  7:37     ` Chunyan Liu
@ 2014-03-27  7:27       ` Chunyan Liu
  0 siblings, 0 replies; 59+ messages in thread
From: Chunyan Liu @ 2014-03-27  7:27 UTC (permalink / raw)
  To: Leandro Dorileo; +Cc: qemu-devel, Stefan Hajnoczi

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

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

>
>
>
> 2014-03-26 3:25 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
>
> On Fri, Mar 21, 2014 at 06:12:23PM +0800, Chunyan Liu wrote:
>> > In QEMUOptionParameter and QemuOptsList conversion, 'assigned' info
>> > is lost. In current code, only qcow2 amend uses 'assigned' for a check.
>> > It will be broken after next patch. So, remove 'assigned' check. If it's
>> > really a must that amend is valid only to explicitly defined options,
>> > we could add it TODO later.
>> >
>> > And for 'prealloc', it's not support amend, since nowhere to compare it
>> > is changed or not, simply ignore it.
>> >
>> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
>> > ---
>> >  block/qcow2.c | 8 +-------
>> >  1 file changed, 1 insertion(+), 7 deletions(-)
>> >
>> > diff --git a/block/qcow2.c b/block/qcow2.c
>> > index b9dc960..92d3327 100644
>> > --- a/block/qcow2.c
>> > +++ b/block/qcow2.c
>> > @@ -2088,11 +2088,6 @@ static int qcow2_amend_options(BlockDriverState
>> *bs,
>> >
>> >      for (i = 0; options[i].name; i++)
>> >      {
>> > -        if (!options[i].assigned) {
>> > -            /* only change explicitly defined options */
>> > -            continue;
>> > -        }
>> > -
>> >          if (!strcmp(options[i].name, "compat")) {
>> >              if (!options[i].value.s) {
>> >                  /* preserve default */
>> > @@ -2106,8 +2101,7 @@ static int qcow2_amend_options(BlockDriverState
>> *bs,
>> >                  return -EINVAL;
>> >              }
>> >          } else if (!strcmp(options[i].name, "preallocation")) {
>> > -            fprintf(stderr, "Cannot change preallocation mode.\n");
>> > -            return -ENOTSUP;
>> > +            /* Cannot change preallocation mode. Ignore it. */
>>
>>
>> You're ignoring/silencing an informed option, I think it's fear enough to
>> notify the caller
>> about it - even if we're never using it for amend.
>>
>
> To ignore it because options is an array which contains all options
> described in
> .create_options, not matter it is set or not. Before, it's filtered by
> "assigned" info, this
> switch may not enter.
>
> But since changing block layer to support both QemuOpts and
> QEMUOptionParameter,
> QEMUOptionParameter will be converted to QemuOpts for unified processing
> and back
> for here processing, after two conversions, the assigned info is lost,
> without filtering by
> "assigned" info, this switch can always enter, and just make the amend
> work impossible.
>
> PS:
> Add .assigned to QemuOptsDesc might be an easier way for the work.
>

Well, I may finally try to keep .assigned info after conversion. When
qemu_opt_find can
find the opt, that means the opt is set, then convert to
QEMUOptionParamter, the
.assigned=true. With this process, this patch is not needed.

Similarly, when switching to QemuOpts in qcow2.c, previous filtering by
.assigned could be
replaced with filtering by qemu_opt_find.


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

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

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

end of thread, other threads:[~2014-03-27  7:27 UTC | newest]

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

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.