Skip to contentSkip to conversation

replace QEMUOptionParameter with QemuOpts

PATCH Applied Chunyan Liu 6 participants 44 messages Jun 5, 2014 – Jun 26, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

v28 cover replace QEMUOptionParameter with QemuOpts

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

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

 block.c                    |  99 ++++----
 block/cow.c                |  52 ++--
 block/gluster.c            |  73 +++---
 block/iscsi.c              |  32 ++-
 block/nfs.c                |  10 +-
 block/qcow.c               |  72 +++---
 block/qcow2.c              | 259 ++++++++++----------
 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           | 105 ++++----
 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              |  14 +-
 include/block/block.h      |   7 +-
 include/block/block_int.h  |   9 +-
 include/qemu/option.h      |  53 +---
 include/qemu/option_int.h  |   4 +-
 qapi-schema.json           |   5 +-
 qapi/opts-visitor.c        |  10 +-
 qemu-img.c                 |  91 ++++---
 qmp-commands.hx            |   2 +
 tests/qemu-iotests/049.out |   2 +-
 tests/qemu-iotests/061.out |   2 +-
 util/qemu-config.c         |   4 +
 util/qemu-option.c         | 590 ++++++++++++++++++++-------------------------
 33 files changed, 1037 insertions(+), 1132 deletions(-)
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v28 1/33 QemuOpts: move find_desc_by_name ahead for later calling

---
 util/qemu-option.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
util/qemu-option.c +14 -14
index 324e4c5..c188c5c 100644
@@ -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);
Signature · 1 line
1.7.12.4
#2 lore raw

PATCH v28 2/33 QemuOpts: repurpose qemu_opts_print to replace print_option_parameters

In reply to Chunyan Liu

Currently this function is not used anywhere. In later patches, it will replace print_option_parameters. To avoid print info changes, change qemu_opts_print from fprintf stderr to printf, and remove last printf.

---
 include/qemu/option.h |  2 +-
 util/qemu-option.c    | 10 ++++------
 2 files changed, 5 insertions(+), 7 deletions(-)
include/qemu/option.h +1 -1
index 8c0ac34..1077b69 100644
@@ -156,7 +156,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);
 
util/qemu-option.c +4 -6
index c188c5c..2c46791 100644
@@ -895,17 +895,15 @@ 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;
 
-    fprintf(stderr, "%s: %s:", opts->list->name,
-            opts->id ? opts->id : "<noid>");
+    printf("%s: %s:", opts->list->name,
+           opts->id ? opts->id : "<noid>");
     QTAILQ_FOREACH(opt, &opts->head, next) {
-        fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
+        printf(" %s=\"%s\"", opt->name, opt->str);
     }
-    fprintf(stderr, "\n");
-    return 0;
 }
 
 static int opts_do_parse(QemuOpts *opts, const char *params,
Signature · 1 line
1.7.12.4
#3 lore raw

PATCH v28 3/33 QemuOpts: add def_value_str to QemuOptDesc

In reply to Chunyan Liu

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, print it.

---
 include/qemu/option.h |  1 +
 util/qemu-option.c    | 56 ++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 50 insertions(+), 7 deletions(-)
include/qemu/option.h +1 -0
index 1077b69..c3b0a91 100644
@@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
     const char *name;
     enum QemuOptType type;
     const char *help;
+    const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
util/qemu-option.c +49 -7

90 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#4 lore raw

PATCH v28 4/33 qapi: output def_value_str when query command line options

In reply to Chunyan Liu

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

---
 qapi-schema.json   | 5 ++++-
 qmp-commands.hx    | 2 ++
 util/qemu-config.c | 4 ++++
 3 files changed, 10 insertions(+), 1 deletion(-)
qapi-schema.json +4 -1
index 7bc33ea..ee4d8f4 100644
@@ -4096,12 +4096,15 @@
 #
 # @help: #optional human readable text string, not suitable for parsing.
 #
+# @default: #optional default value string (since 2.1)
+#
 # Since 1.5
 ##
 { 'type': 'CommandLineParameterInfo',
   'data': { 'name': 'str',
             'type': 'CommandLineParameterType',
-            '*help': 'str' } }
+            '*help': 'str',
+            '*default': 'str' } }
 
 ##
 # @CommandLineOptionInfo:
qmp-commands.hx +2 -0
index d8aa4ed..d6bb0f4 100644
@@ -2898,6 +2898,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:
 
util/qemu-config.c +4 -0
index f4e4f38..ba375c0 100644
@@ -82,6 +82,10 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
             info->has_help = true;
             info->help = g_strdup(desc[i].help);
         }
+        if (desc[i].def_value_str) {
+            info->has_q_default = true;
+            info->q_default = g_strdup(desc[i].def_value_str);
+        }
 
         entry = g_malloc0(sizeof(*entry));
         entry->value = info;
Signature · 1 line
1.7.12.4
#5 lore raw

PATCH v28 5/33 QemuOpts: change opt->name|str from (const char *) to (char *)

In reply to Chunyan Liu

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.

---
 include/qemu/option_int.h |  4 ++--
 qapi/opts-visitor.c       | 10 +++++++---
 util/qemu-option.c        |  4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)
include/qemu/option_int.h +2 -2
index 8212fa4..6432c1a 100644
@@ -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 {
qapi/opts-visitor.c +7 -3
index 16382e7..f2ad6d7 100644
@@ -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;
 }
 
util/qemu-option.c +2 -2
index 5af39a2..d4fd7b5 100644
@@ -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);
 }
 
Signature · 1 line
1.7.12.4
#6 lore raw

PATCH v28 6/33 QemuOpts: move qemu_opt_del ahead for later calling

In reply to Chunyan Liu

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.

---
 util/qemu-option.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
util/qemu-option.c +8 -8
index d4fd7b5..7124483 100644
@@ -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;
Signature · 1 line
1.7.12.4
#7 lore raw

PATCH v28 7/33 QemuOpts: add qemu_opt_get_*_del functions for replace work

In reply to Chunyan Liu

Add qemu_opt_get_del, qemu_opt_get_bool_del, qemu_opt_get_number_del and qemu_opt_get_size_del to replace the same handling of QEMUOptionParameter (get and delete).

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

Share common helper function:

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

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

---
 include/qemu/option.h |   6 +++
 util/qemu-option.c    | 117 ++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 110 insertions(+), 13 deletions(-)
include/qemu/option.h +6 -0
index c3b0a91..6653e43 100644
@@ -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,
util/qemu-option.c +104 -13

166 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#8 lore raw

PATCH v28 8/33 QemuOpts: add qemu_opts_print_help to replace print_option_help

In reply to Chunyan Liu

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

---
 include/qemu/option.h |  1 +
 util/qemu-option.c    | 13 +++++++++++++
 2 files changed, 14 insertions(+)
include/qemu/option.h +1 -0
index 6653e43..fbf5dc2 100644
@@ -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
util/qemu-option.c +13 -0
index a7330c6..cd03eb4 100644
@@ -553,6 +553,19 @@ void print_option_help(QEMUOptionParameter *list)
     }
 }
 
+void qemu_opts_print_help(QemuOptsList *list)
+{
+    QemuOptDesc *desc;
+
+    assert(list);
+    desc = list->desc;
+    printf("Supported options:\n");
+    while (desc && desc->name) {
+        printf("%-16s %s\n", desc->name,
+               desc->help ? desc->help : "No description available");
+        desc++;
+    }
+}
 /* ------------------------------------------------------------------ */
 
 static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
Signature · 1 line
1.7.12.4
#9 lore raw

PATCH v28 9/33 QemuOpts: add conversion between QEMUOptionParameter to QemuOpts

In reply to Chunyan Liu

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

---
 include/qemu/option.h |   9 +++
 util/qemu-option.c    | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+)
include/qemu/option.h +9 -0
index fbf5dc2..e98e8ef 100644
@@ -103,6 +103,12 @@ typedef struct QemuOptDesc {
 } QemuOptDesc;
 
 struct QemuOptsList {
+    /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
+     * indicate the need to free memory. Will remove after all drivers
+     * switch to QemuOpts.
+     */
+    bool allocated;
+
     const char *name;
     const char *implied_opt_name;
     bool merge_lists;  /* Merge multiple uses of option into a single list? */
@@ -167,5 +173,8 @@ void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
                       int abort_on_failure);
 void qemu_opts_print_help(QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+QEMUOptionParameter *opts_to_params(QemuOpts *opts);
+QemuOptsList *params_to_opts(QEMUOptionParameter *list);
 
 #endif
util/qemu-option.c +153 -0

156 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#10 lore raw

PATCH v28 10/33 QemuOpts: add qemu_opts_append to replace append_option_parameters

In reply to Chunyan Liu

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

---
 include/qemu/option.h |  5 ++++
 util/qemu-option.c    | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
include/qemu/option.h +5 -0
index e98e8ef..44d9961 100644
@@ -176,5 +176,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
util/qemu-option.c +67 -0

70 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#11 lore raw

PATCH v28 11/33 QemuOpts: check NULL input for qemu_opts_del

In reply to Chunyan Liu

To simplify later using of qemu_opts_del, accept NULL input.

---
 util/qemu-option.c | 4 ++++
 1 file changed, 4 insertions(+)
util/qemu-option.c +4 -0
index 6acfb0e..40e1ff3 100644
@@ -1011,6 +1011,10 @@ void qemu_opts_del(QemuOpts *opts)
 {
     QemuOpt *opt;
 
+    if (opts == NULL) {
+        return;
+    }
+
     for (;;) {
         opt = QTAILQ_FIRST(&opts->head);
         if (opt == NULL)
Signature · 1 line
1.7.12.4
#12 lore raw

PATCH v28 12/33 change block layer to support both QemuOpts and QEMUOptionParamter

In reply to Chunyan Liu

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.

---
 block.c                    | 160 +++++++++++++++++++++++++++++++--------------
 block/cow.c                |   2 +-
 block/qcow.c               |   2 +-
 block/qcow2.c              |   2 +-
 block/qed.c                |   2 +-
 block/raw_bsd.c            |   2 +-
 block/vhdx.c               |   2 +-
 block/vmdk.c               |   4 +-
 block/vvfat.c              |   2 +-
 include/block/block.h      |   7 +-
 include/block/block_int.h  |  13 +++-
 qemu-img.c                 |  96 +++++++++++++--------------
 tests/qemu-iotests/049.out |   2 +-
 tests/qemu-iotests/061.out |   2 +-
 14 files changed, 184 insertions(+), 114 deletions(-)
block.c +111 -49
index 310ea89..ebb76cf 100644
@@ -328,6 +328,13 @@ void bdrv_register(BlockDriver *bdrv)
         }
     }
 
+    if (bdrv->bdrv_create) {
+        assert(!bdrv->bdrv_create2 && !bdrv->create_opts);
+        assert(!bdrv->bdrv_amend_options2);
+    } else if (bdrv->bdrv_create2) {
+        assert(!bdrv->bdrv_create && !bdrv->create_options);
+        assert(!bdrv->bdrv_amend_options);
+    }
     QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
 }
 
@@ -423,6 +430,7 @@ typedef struct CreateCo {
     BlockDriver *drv;
     char *filename;
     QEMUOptionParameter *options;
+    QemuOpts *opts;
     int ret;
     Error *err;
 } CreateCo;
@@ -434,8 +442,28 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 
     CreateCo *cco = opaque;
     assert(cco->drv);
+    assert(!(cco->options && cco->opts));
 
-    ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+    if (cco->drv->bdrv_create2) {
+        QemuOptsList *opts_list = NULL;
+        if (cco->options) {
+            opts_list = params_to_opts(cco->options);
+            cco->opts = qemu_opts_create(opts_list, NULL, 0, &error_abort);
+        }
+        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+        if (cco->options) {
+            qemu_opts_del(cco->opts);
+            qemu_opts_free(opts_list);
+        }
+    } else {
+        if (cco->opts) {
+            cco->options = opts_to_params(cco->opts);
+        }
+        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+        if (cco->opts) {
+            free_option_parameters(cco->options);
+        }
+    }
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -443,7 +471,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;
 
@@ -452,11 +481,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;
@@ -488,7 +518,7 @@ out:
 }
 
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp)
+                     QemuOpts *opts, Error **errp)
 {
     BlockDriver *drv;
     Error *local_err = NULL;
@@ -500,7 +530,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);
     }
@@ -1245,7 +1275,8 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     char *tmp_filename = g_malloc0(PATH_MAX + 1);
     int64_t total_size;
     BlockDriver *bdrv_qcow2;
-    QEMUOptionParameter *create_options;
+    QemuOptsList *create_opts = NULL;
+    QemuOpts *opts = NULL;
     QDict *snapshot_options;
     BlockDriverState *bs_snapshot;
     Error *local_err;
@@ -1270,13 +1301,20 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     }
 
     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,
@@ -5489,8 +5527,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;
@@ -5509,28 +5549,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) {
-            error_setg(errp, "Invalid options for file format '%s'.", fmt);
+        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;
@@ -5538,37 +5575,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];
@@ -5579,11 +5616,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;
@@ -5593,7 +5630,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 {
@@ -5604,16 +5641,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'"
@@ -5623,9 +5662,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);
     }
@@ -5643,12 +5681,36 @@ 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 *opts_list = NULL;
+        if (options) {
+            opts_list = params_to_opts(options);
+            opts = qemu_opts_create(opts_list, NULL, 0, &error_abort);
+        }
+        ret = bs->drv->bdrv_amend_options2(bs, opts);
+        if (options) {
+            qemu_opts_del(opts);
+            qemu_opts_free(opts_list);
+        }
+    } else {
+        if (opts) {
+            options = opts_to_params(opts);
+        }
+        ret = bs->drv->bdrv_amend_options(bs, options);
+        if (opts) {
+            free_option_parameters(options);
+        }
+    }
+    return ret;
 }
 
 /* This function will be called by the bdrv_recurse_is_first_non_filter method
block/cow.c +1 -1
index 164759f..7e61024 100644
@@ -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;
block/qcow.c +1 -1
index 7fd57d7..32651eb 100644
@@ -718,7 +718,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;
block/qcow2.c +1 -1
index a54d2ba..6b95a7f 100644
@@ -1626,7 +1626,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;
block/qed.c +1 -1
index c130e42..2982640 100644
@@ -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;
block/raw_bsd.c +1 -1
index 01ea692..9ae5fc2 100644
@@ -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);
     }
block/vhdx.c +1 -1
index 353c74d..ca7d533 100644
@@ -1803,7 +1803,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;
block/vmdk.c +2 -2
index 2b38f61..79d55b0 100644
@@ -1539,7 +1539,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;
@@ -1879,7 +1879,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_propagate(errp, local_err);
             goto exit;
block/vvfat.c +1 -1
index 3cda19f..d895582 100644
@@ -2930,7 +2930,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
     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, errp);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, errp);
     free_option_parameters(options);
     if (ret < 0) {
         goto err;
include/block/block.h +4 -3
index faee3aa..02468fe 100644
@@ -204,9 +204,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, Error **errp);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -312,7 +312,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,
include/block/block_int.h +12 -1
index f2e753f..6219e59 100644
@@ -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,12 @@ 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.
+     * create_options should only be set with bdrv_create, and create_opts
+     * should only be set with bdrv_create2.
+     */
+    QemuOptsList *create_opts;
 
     /*
      * Returns 0 for completed check, -errno for internal errors.
@@ -228,6 +235,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);
 
qemu-img.c +46 -50

204 lines not on this page · raw message

tests/qemu-iotests/049.out +1 -1
index ceb2328..71ca44d 100644
@@ -120,7 +120,7 @@ qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
 
 qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2
 qemu-img: Parameter 'size' expects a size
-qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'.
+qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'
 
 == Check correct interpretation of suffixes for cluster size ==
 
tests/qemu-iotests/061.out +1 -1
index 4027e00..e372470 100644
@@ -281,7 +281,7 @@ Lazy refcounts only supported with compatibility level 1.1 and above (use compat
 qemu-img: Error while amending options: Invalid argument
 Unknown compatibility level 0.42.
 qemu-img: Error while amending options: Invalid argument
-Unknown option 'foo'
+qemu-img: Invalid parameter 'foo'
 qemu-img: Invalid options for file format 'qcow2'
 Changing the cluster size is not supported.
 qemu-img: Error while amending options: Operation not supported
Signature · 1 line
1.7.12.4
#13 lore raw

PATCH v28 13/33 vvfat.c: handle cross_driver's create_options and create_opts

In reply to Chunyan Liu

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

---
 block/vvfat.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
block/vvfat.c +17 -7
index d895582..b1ab195 100644
@@ -2910,8 +2910,9 @@ static BlockDriver vvfat_write_target = {
 
 static int enable_write_target(BDRVVVFATState *s, Error **errp)
 {
-    BlockDriver *bdrv_qcow;
-    QEMUOptionParameter *options;
+    BlockDriver *bdrv_qcow = NULL;
+    QemuOptsList *create_opts = NULL;
+    QemuOpts *opts = NULL;
     int ret;
     int size = sector2cluster(s, s->sector_count);
     s->used_clusters = calloc(size, 1);
@@ -2926,12 +2927,21 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
     }
 
     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, errp);
-    free_option_parameters(options);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, errp);
+    qemu_opts_del(opts);
+    if (bdrv_qcow->create_options) {
+        qemu_opts_free(create_opts);
+    }
     if (ret < 0) {
         goto err;
     }
Signature · 1 line
1.7.12.4
#14 lore raw

PATCH v28 14/33 cow.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 28 deletions(-)
block/cow.c +26 -28
index 7e61024..af85753 100644
@@ -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)
Signature · 1 line
1.7.12.4
#15 lore raw

PATCH v28 15/33 gluster.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/gluster.c | 81 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 39 deletions(-)
block/gluster.c +42 -39
index d0726ec..98dd886 100644
@@ -476,13 +476,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);
@@ -491,24 +492,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,
@@ -530,6 +528,7 @@ static int qemu_gluster_create(const char *filename,
         }
     }
 out:
+    g_free(tmp);
     qemu_gluster_gconf_free(gconf);
     if (glfs) {
         glfs_fini(glfs);
@@ -693,18 +692,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 = QEMU_OPT_STRING,
+            .help = "Preallocation mode (allowed values: off, full)"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_gluster = {
@@ -717,7 +720,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,
@@ -731,7 +734,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 = {
@@ -744,7 +747,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,
@@ -758,7 +761,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 = {
@@ -771,7 +774,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,
@@ -785,7 +788,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 = {
@@ -798,7 +801,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,
@@ -812,7 +815,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)
Signature · 1 line
1.7.12.4
#16 lore raw

PATCH v28 16/33 iscsi.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/iscsi.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)
block/iscsi.c +16 -18
index 3892cc5..76d4623 100644
@@ -1500,8 +1500,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
     return 0;
 }
 
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     int ret = 0;
     int64_t total_size = 0;
@@ -1512,13 +1511,8 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
     bs = bdrv_new("", &error_abort);
 
     /* 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;
 
@@ -1563,13 +1557,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 = {
@@ -1580,8 +1578,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,
Signature · 1 line
1.7.12.4
#17 lore raw

PATCH v28 17/33 nfs.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/nfs.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
block/nfs.c +3 -9
index 539bd95..20a90e2 100644
@@ -361,20 +361,14 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
     return 0;
 }
 
-static int nfs_file_create(const char *url, QEMUOptionParameter *options,
-                           Error **errp)
+static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp)
 {
     int ret = 0;
     int64_t total_size = 0;
     NFSClient *client = g_malloc0(sizeof(NFSClient));
 
     /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
-            total_size = options->value.n;
-        }
-        options++;
-    }
+    total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
 
     ret = nfs_client_open(client, url, O_CREAT, errp);
     if (ret < 0) {
@@ -431,7 +425,7 @@ static BlockDriver bdrv_nfs = {
 
     .bdrv_file_open  = nfs_file_open,
     .bdrv_close      = nfs_file_close,
-    .bdrv_create     = nfs_file_create,
+    .bdrv_create2    = nfs_file_create,
 
     .bdrv_co_readv         = nfs_co_readv,
     .bdrv_co_writev        = nfs_co_writev,
Signature · 1 line
1.7.12.4
#18 lore raw

PATCH v28 18/33 qcow.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/qcow.c | 72 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)
block/qcow.c +36 -36
index 32651eb..bcacfb8 100644
@@ -693,35 +693,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;
@@ -729,7 +723,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);
@@ -800,6 +794,8 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
     ret = 0;
 exit:
     bdrv_unref(qcow_bs);
+cleanup:
+    g_free(backing_file);
     return ret;
 }
 
@@ -912,24 +908,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 = {
@@ -938,8 +938,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,
@@ -951,7 +951,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)
Signature · 1 line
1.7.12.4
#19 lore raw

PATCH v28 19/33 QemuOpts: export qemu_opt_find

In reply to Chunyan Liu

Export qemu_opt_find for qcow2 driver using it.
After replacing QEMUOptionParameter with QemuOpts, qcow2 driver will use qemu_opt_find to judge if an option is explicitly set, to replace the usage of .assigned in QEMUOptionParameter.

---
Changes:
* same as v27.
* changes to v26:
Following Eric's comment, split v26 qcow2.c patch into two:
export qemu_opt_find first and then qcow2.c patch

 include/qemu/option.h | 1 +
 util/qemu-option.c    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
include/qemu/option.h +1 -0
index 44d9961..3455267 100644
@@ -130,6 +130,7 @@ char *qemu_opt_get_del(QemuOpts *opts, const char *name);
  * Returns: true if @opts includes 'help' or equivalent.
  */
 bool qemu_opt_has_help_opt(QemuOpts *opts);
+QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name);
 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);
util/qemu-option.c +1 -1
index 40e1ff3..0d9d3ec 100644
@@ -568,7 +568,7 @@ void qemu_opts_print_help(QemuOptsList *list)
 }
 /* ------------------------------------------------------------------ */
 
-static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
+QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
 {
     QemuOpt *opt;
 
Signature · 1 line
1.7.12.4
#20 lore raw

PATCH v28 20/33 qcow2.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu

---
Changes:
* same as v27
* changes to v26:
split v26 qcow2.c patch into two, move qemu_opt_find to a separate patch.

 block/qcow2.c | 261 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 139 insertions(+), 122 deletions(-)
block/qcow2.c +139 -122
index 6b95a7f..7150df6 100644
@@ -31,6 +31,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qbool.h"
 #include "trace.h"
+#include "qemu/option_int.h"
 
 /*
   Differences with QCOW:
@@ -1594,7 +1595,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 */
@@ -1626,7 +1627,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;
@@ -1762,11 +1763,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;
@@ -1776,64 +1777,66 @@ 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) {
+        /* keep the default */
+    } else if (!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;
 }
 
@@ -2198,64 +2201,72 @@ 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;
     bool lazy_refcounts = s->use_lazy_refcounts;
+    const char *compat = NULL;
+    uint64_t cluster_size = s->cluster_size;
+    bool encrypt;
     int ret;
-    int i;
+    QemuOptDesc *desc = opts->list->desc;
 
-    for (i = 0; options[i].name; i++)
-    {
-        if (!options[i].assigned) {
+    while (desc && desc->name) {
+        if (!qemu_opt_find(opts, desc->name)) {
             /* only change explicitly defined options */
+            desc++;
             continue;
         }
 
-        if (!strcmp(options[i].name, "compat")) {
-            if (!options[i].value.s) {
+        if (!strcmp(desc->name, "compat")) {
+            compat = qemu_opt_get(opts, "compat");
+            if (!compat) {
                 /* preserve default */
-            } else if (!strcmp(options[i].value.s, "0.10")) {
+            } else if (!strcmp(compat, "0.10")) {
                 new_version = 2;
-            } else if (!strcmp(options[i].value.s, "1.1")) {
+            } else if (!strcmp(compat, "1.1")) {
                 new_version = 3;
             } else {
-                fprintf(stderr, "Unknown compatibility level %s.\n",
-                        options[i].value.s);
+                fprintf(stderr, "Unknown compatibility level %s.\n", compat);
                 return -EINVAL;
             }
-        } else if (!strcmp(options[i].name, "preallocation")) {
+        } else if (!strcmp(desc->name, "preallocation")) {
             fprintf(stderr, "Cannot change preallocation mode.\n");
             return -ENOTSUP;
-        } else if (!strcmp(options[i].name, "size")) {
-            new_size = options[i].value.n;
-        } else if (!strcmp(options[i].name, "backing_file")) {
-            backing_file = options[i].value.s;
-        } else if (!strcmp(options[i].name, "backing_fmt")) {
-            backing_format = options[i].value.s;
-        } else if (!strcmp(options[i].name, "encryption")) {
-            if ((options[i].value.n != !!s->crypt_method)) {
+        } else if (!strcmp(desc->name, "size")) {
+            new_size = qemu_opt_get_size(opts, "size", 0);
+        } else if (!strcmp(desc->name, "backing_file")) {
+            backing_file = qemu_opt_get(opts, "backing_file");
+        } else if (!strcmp(desc->name, "backing_fmt")) {
+            backing_format = qemu_opt_get(opts, "backing_fmt");
+        } else if (!strcmp(desc->name, "encryption")) {
+            encrypt = qemu_opt_get_bool(opts, "encryption", s->crypt_method);
+            if (encrypt != !!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) {
+        } else if (!strcmp(desc->name, "cluster_size")) {
+            cluster_size = qemu_opt_get_size(opts, "cluster_size",
+                                             cluster_size);
+            if (cluster_size != 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 (!strcmp(desc->name, "lazy_refcounts")) {
+            lazy_refcounts = qemu_opt_get_bool(opts, "lazy_refcounts",
+                                               lazy_refcounts);
         } else {
             /* if this assertion fails, this probably means a new option was
              * added without having it covered here */
             assert(false);
         }
+
+        desc++;
     }
 
     if (new_version != old_version) {
@@ -2324,49 +2335,55 @@ static int qcow2_amend_options(BlockDriverState *bs,
     return 0;
 }
 
-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 = {
@@ -2376,7 +2393,7 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
-    .bdrv_create        = qcow2_create,
+    .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,
@@ -2394,8 +2411,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,
@@ -2406,9 +2423,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)
Signature · 1 line
1.7.12.4
#21 lore raw

PATCH v28 21/33 qed.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu

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.

---
 block/qed.c | 114 ++++++++++++++++++++++++++++++++----------------------------
 block/qed.h |   3 +-
 2 files changed, 61 insertions(+), 56 deletions(-)
block/qed.c +60 -54
index 2982640..9376996 100644
@@ -621,55 +621,53 @@ 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)) {
         error_setg(errp, "QED cluster size must be within range [%u, %u] "
                          "and power of 2",
                    QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
     if (!qed_is_table_size_valid(table_size)) {
         error_setg(errp, "QED table size must be within range [%u, %u] "
                          "and power of 2",
                    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)) {
         error_setg(errp, "QED image size must be a non-zero multiple of "
                          "cluster size and less than %" PRIu64 " bytes",
                    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 {
@@ -1595,43 +1593,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,
block/qed.h +1 -2
index 5d65bea..b024751 100644
@@ -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
Signature · 1 line
1.7.12.4
#22 lore raw

PATCH v28 22/33 raw-posix.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/raw-posix.c | 59 +++++++++++++++++++++++++------------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)
block/raw-posix.c +27 -32
index b7f0f26..e0a75db 100644
@@ -1240,8 +1240,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;
@@ -1250,12 +1249,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);
@@ -1440,13 +1435,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 = {
@@ -1461,7 +1460,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,
@@ -1478,7 +1477,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,
 };
 
 /***********************************************/
@@ -1799,7 +1798,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;
@@ -1820,12 +1819,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) {
@@ -1862,8 +1857,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,
@@ -2006,8 +2001,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,
@@ -2131,8 +2126,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,
@@ -2262,8 +2257,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,
Signature · 1 line
1.7.12.4
#23 lore raw

PATCH v28 23/33 raw-win32.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/raw-win32.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
block/raw-win32.c +19 -19
index 064ea31..e5ac297 100644
@@ -478,8 +478,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;
@@ -487,12 +486,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);
@@ -506,13 +501,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 = {
@@ -521,9 +521,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,
@@ -535,7 +535,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,
 };
 
 /***********************************************/
Signature · 1 line
1.7.12.4
#24 lore raw

PATCH v28 24/33 raw_bsd.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/raw_bsd.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
block/raw_bsd.c +15 -12
index 9ae5fc2..ee797fd 100644
@@ -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
 };
 
Signature · 1 line
1.7.12.4
#25 lore raw

PATCH v28 25/33 rbd.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/rbd.c | 63 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 30 insertions(+), 33 deletions(-)
block/rbd.c +30 -33
index 09af484..d7f22af 100644
@@ -289,8 +289,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf, Error **errp)
     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)
 {
     Error *local_err = NULL;
     int64_t bytes = 0;
@@ -315,24 +314,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_setg(errp, "obj size needs to be power of 2");
-                    return -EINVAL;
-                }
-                if (objsize < 4096) {
-                    error_setg(errp, "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_setg(errp, "obj size needs to be power of 2");
+            return -EINVAL;
+        }
+        if (objsize < 4096) {
+            error_setg(errp, "obj size too small");
+            return -EINVAL;
         }
-        options++;
+        obj_order = ffs(objsize) - 1;
     }
 
     clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
@@ -907,18 +900,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 = {
@@ -927,10 +924,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",
Signature · 1 line
1.7.12.4
#26 lore raw

PATCH v28 26/33 sheepdog.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/sheepdog.c | 111 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 56 insertions(+), 55 deletions(-)
block/sheepdog.c +56 -55
index 4ecbf5f..c971117 100644
@@ -1636,12 +1636,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;
@@ -1660,33 +1661,27 @@ 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_setg(errp, "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) {
-                    error_setg(errp, "Invalid redundancy mode: '%s'",
-                               options->value.s);
-                    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_setg(errp, "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) {
+            error_setg(errp, "Invalid redundancy mode: '%s'", buf);
+            goto out;
         }
-        options++;
     }
 
     if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -1736,6 +1731,8 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
         ret = sd_prealloc(filename, errp);
     }
 out:
+    g_free(backing_file);
+    g_free(buf);
     g_free(s);
     return ret;
 }
@@ -2529,28 +2526,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 = {
@@ -2560,7 +2561,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,
@@ -2580,7 +2581,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 = {
@@ -2590,7 +2591,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,
@@ -2610,7 +2611,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 = {
@@ -2620,7 +2621,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,
@@ -2640,7 +2641,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)
Signature · 1 line
1.7.12.4
#27 lore raw

PATCH v28 27/33 ssh.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/ssh.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
block/ssh.c +15 -17
index b212971..b6d55bc 100644
@@ -675,17 +675,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;
     int64_t total_size = 0;
@@ -697,12 +700,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();
@@ -1075,14 +1073,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)
Signature · 1 line
1.7.12.4
#28 lore raw

PATCH v28 28/33 vdi.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vdi.c | 73 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 35 insertions(+), 38 deletions(-)
block/vdi.c +35 -38
index 27737af..fe5cad2 100644
@@ -673,8 +673,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;
@@ -689,25 +688,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
 
     if (bytes > VDI_DISK_SIZE_MAX) {
         result = -ENOTSUP;
@@ -802,29 +794,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 = {
@@ -834,7 +831,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,
@@ -846,7 +843,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,
 };
 
Signature · 1 line
1.7.12.4
#29 lore raw

PATCH v28 29/33 vhdx.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vhdx.c | 99 +++++++++++++++++++++++++++++-------------------------------
 block/vhdx.h |  1 +
 2 files changed, 48 insertions(+), 52 deletions(-)
block/vhdx.c +47 -52
index ca7d533..e36f897 100644
@@ -1723,8 +1723,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;
@@ -1737,24 +1736,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");
@@ -1763,7 +1753,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     }
 
     if (type == NULL) {
-        type = "dynamic";
+        type = g_strdup("dynamic");
     }
 
     if (!strcmp(type, "dynamic")) {
@@ -1803,7 +1793,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;
@@ -1863,6 +1853,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;
 }
@@ -1885,37 +1876,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 = {
@@ -1927,11 +1922,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)
block/vhdx.h +1 -0
index 8103d4c..5370010 100644
@@ -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,
Signature · 1 line
1.7.12.4
#30 lore raw

PATCH v28 30/33 vmdk.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vmdk.c | 123 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 63 insertions(+), 60 deletions(-)
block/vmdk.c +63 -60
index 79d55b0..78d7312 100644
@@ -1695,17 +1695,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 = NULL;
     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;
@@ -1745,24 +1744,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") &&
@@ -1778,7 +1772,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") &&
@@ -1879,7 +1873,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_propagate(errp, local_err);
             goto exit;
@@ -1909,6 +1903,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;
@@ -2096,41 +2093,47 @@ static int vmdk_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
 
-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 = {
@@ -2145,7 +2148,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_write_compressed        = vmdk_write_compressed,
     .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,
@@ -2154,7 +2157,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_refresh_limits          = vmdk_refresh_limits,
     .bdrv_get_info                = vmdk_get_info,
 
-    .create_options               = vmdk_create_options,
+    .create_opts                  = &vmdk_create_opts,
 };
 
 static void bdrv_vmdk_init(void)
Signature · 1 line
1.7.12.4
#31 lore raw

PATCH v28 31/33 vpc.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vpc.c | 62 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 28 deletions(-)
block/vpc.c +34 -28
index 2e25f57..8ebf424 100644
@@ -738,12 +738,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;
@@ -754,16 +753,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;
@@ -772,7 +771,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;
     }
 
     /*
@@ -837,8 +837,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;
 }
 
@@ -866,20 +868,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 = {
@@ -890,14 +896,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,
 };
 
Signature · 1 line
1.7.12.4
#32 lore raw

PATCH v28 32/33 cleanup QEMUOptionParameter

In reply to Chunyan Liu

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

---
 block.c                   |  93 ++--------
 block/cow.c               |   4 +-
 block/gluster.c           |   8 +-
 block/iscsi.c             |   2 +-
 block/nfs.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             |  14 +-
 include/block/block.h     |   8 +-
 include/block/block_int.h |  18 +-
 include/qemu/option.h     |  48 +-----
 qemu-img.c                |  19 +--
 util/qemu-option.c        | 427 +---------------------------------------------
 24 files changed, 67 insertions(+), 630 deletions(-)
block.c +13 -80
index ebb76cf..3fc4598 100644
@@ -328,13 +328,6 @@ void bdrv_register(BlockDriver *bdrv)
         }
     }
 
-    if (bdrv->bdrv_create) {
-        assert(!bdrv->bdrv_create2 && !bdrv->create_opts);
-        assert(!bdrv->bdrv_amend_options2);
-    } else if (bdrv->bdrv_create2) {
-        assert(!bdrv->bdrv_create && !bdrv->create_options);
-        assert(!bdrv->bdrv_amend_options);
-    }
     QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
 }
 
@@ -429,7 +422,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;
@@ -442,28 +434,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;
-        if (cco->options) {
-            opts_list = params_to_opts(cco->options);
-            cco->opts = qemu_opts_create(opts_list, NULL, 0, &error_abort);
-        }
-        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
-        if (cco->options) {
-            qemu_opts_del(cco->opts);
-            qemu_opts_free(opts_list);
-        }
-    } else {
-        if (cco->opts) {
-            cco->options = opts_to_params(cco->opts);
-        }
-        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
-        if (cco->opts) {
-            free_option_parameters(cco->options);
-        }
-    }
+    ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err);
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -471,7 +443,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;
@@ -480,13 +451,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;
@@ -517,8 +487,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;
@@ -530,7 +499,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);
     }
@@ -1275,7 +1244,6 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     char *tmp_filename = g_malloc0(PATH_MAX + 1);
     int64_t total_size;
     BlockDriver *bdrv_qcow2;
-    QemuOptsList *create_opts = NULL;
     QemuOpts *opts = NULL;
     QDict *snapshot_options;
     BlockDriverState *bs_snapshot;
@@ -1301,20 +1269,11 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     }
 
     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,
@@ -5549,10 +5508,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);
@@ -5645,7 +5602,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
@@ -5681,36 +5638,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 *opts_list = NULL;
-        if (options) {
-            opts_list = params_to_opts(options);
-            opts = qemu_opts_create(opts_list, NULL, 0, &error_abort);
-        }
-        ret = bs->drv->bdrv_amend_options2(bs, opts);
-        if (options) {
-            qemu_opts_del(opts);
-            qemu_opts_free(opts_list);
-        }
-    } else {
-        if (opts) {
-            options = opts_to_params(opts);
-        }
-        ret = bs->drv->bdrv_amend_options(bs, options);
-        if (opts) {
-            free_option_parameters(options);
-        }
-    }
-    return ret;
+    return bs->drv->bdrv_amend_options(bs, opts);
 }
 
 /* This function will be called by the bdrv_recurse_is_first_non_filter method
block/cow.c +2 -2
index af85753..a05a92c 100644
@@ -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,
block/gluster.c +4 -4
index 98dd886..7ba0626 100644
@@ -720,7 +720,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,
@@ -747,7 +747,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,
@@ -774,7 +774,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,
@@ -801,7 +801,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,
block/iscsi.c +1 -1
index 76d4623..3f19999 100644
@@ -1578,7 +1578,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,
 
block/nfs.c +1 -1
index 20a90e2..c1c7296 100644
@@ -425,7 +425,7 @@ static BlockDriver bdrv_nfs = {
 
     .bdrv_file_open  = nfs_file_open,
     .bdrv_close      = nfs_file_close,
-    .bdrv_create2    = nfs_file_create,
+    .bdrv_create     = nfs_file_create,
 
     .bdrv_co_readv         = nfs_co_readv,
     .bdrv_co_writev        = nfs_co_writev,
block/qcow.c +2 -2
index bcacfb8..1f2bac8 100644
@@ -712,7 +712,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;
@@ -939,7 +939,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,
block/qcow2.c +3 -3
index 7150df6..b9d2fa6 100644
@@ -1627,7 +1627,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;
@@ -2393,7 +2393,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,
@@ -2425,7 +2425,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)
block/qed.c +2 -2
index 9376996..ebbc7f2 100644
@@ -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;
@@ -1637,7 +1637,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,
block/raw-posix.c +5 -5
index e0a75db..c93b86f 100644
@@ -1460,7 +1460,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,
@@ -1857,7 +1857,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,
 
@@ -2001,7 +2001,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,
@@ -2126,7 +2126,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,
@@ -2257,7 +2257,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,
block/raw-win32.c +1 -1
index e5ac297..f214ca0 100644
@@ -523,7 +523,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,
block/raw_bsd.c +2 -2
index ee797fd..492f58d 100644
@@ -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,
block/rbd.c +1 -1
index d7f22af..d86b71b 100644
@@ -924,7 +924,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,
block/sheepdog.c +3 -3
index c971117..546dbb4 100644
@@ -2561,7 +2561,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,
@@ -2591,7 +2591,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,
@@ -2621,7 +2621,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,
block/ssh.c +1 -1
index b6d55bc..35a3d1a 100644
@@ -1073,7 +1073,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,
block/vdi.c +1 -1
index fe5cad2..0506aae 100644
@@ -831,7 +831,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,
block/vhdx.c +2 -2
index e36f897..fedcf9f 100644
@@ -1793,7 +1793,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;
@@ -1922,7 +1922,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,
 
block/vmdk.c +3 -3
index 78d7312..1b66c55 100644
@@ -1539,7 +1539,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;
@@ -1873,7 +1873,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_propagate(errp, local_err);
             goto exit;
@@ -2148,7 +2148,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_write_compressed        = vmdk_write_compressed,
     .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,
block/vpc.c +1 -1
index 8ebf424..798d854 100644
@@ -896,7 +896,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,
block/vvfat.c +2 -12
index b1ab195..70176b1 100644
@@ -2911,7 +2911,6 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s, Error **errp)
 {
     BlockDriver *bdrv_qcow = NULL;
-    QemuOptsList *create_opts = NULL;
     QemuOpts *opts = NULL;
     int ret;
     int size = sector2cluster(s, s->sector_count);
@@ -2927,21 +2926,12 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
     }
 
     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, errp);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp);
     qemu_opts_del(opts);
-    if (bdrv_qcow->create_options) {
-        qemu_opts_free(create_opts);
-    }
     if (ret < 0) {
         goto err;
     }
include/block/block.h +3 -5
index 02468fe..379d441 100644
@@ -204,9 +204,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, Error **errp);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -312,8 +311,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,
include/block/block_int.h +2 -16
index 6219e59..77cd9d6 100644
@@ -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,12 +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.
-     * create_options should only be set with bdrv_create, and create_opts
-     * should only be set with bdrv_create2.
-     */
     QemuOptsList *create_opts;
 
     /*
@@ -233,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);
 
include/qemu/option.h +1 -47

70 lines not on this page · raw message

qemu-img.c +7 -12
index 566b25d..74a08b9 100644
@@ -280,8 +280,7 @@ 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) {
@@ -289,8 +288,7 @@ static int print_block_option_help(const char *filename, const char *fmt)
             qemu_opts_free(create_opts);
             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);
@@ -1380,10 +1378,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)) {
@@ -1436,7 +1432,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));
@@ -2765,8 +2761,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);
@@ -2774,7 +2769,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;
util/qemu-option.c +4 -423

472 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#33 lore raw

PATCH v28 33/33 QemuOpts: cleanup tmp 'allocated' member from QemuOptsList

In reply to Chunyan Liu

Now only qemu_opts_append uses 'allocated' 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 'allocated' member from QemuOptsList definition to keep code clean.

---
 include/qemu/option.h |  6 ------
 util/qemu-option.c    | 27 +++------------------------
 2 files changed, 3 insertions(+), 30 deletions(-)
include/qemu/option.h +0 -6
index 921eccd..59bea75 100644
@@ -63,12 +63,6 @@ typedef struct QemuOptDesc {
 } QemuOptDesc;
 
 struct QemuOptsList {
-    /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
-     * indicate the need to free memory. Will remove after all drivers
-     * switch to QemuOpts.
-     */
-    bool allocated;
-
     const char *name;
     const char *implied_opt_name;
     bool merge_lists;  /* Merge multiple uses of option into a single list? */
util/qemu-option.c +3 -24
index 8ac8111..836055a 100644
@@ -1077,26 +1077,13 @@ static size_t count_opts_list(QemuOptsList *list)
 
 void qemu_opts_free(QemuOptsList *list)
 {
-    /* List members point to new malloced space and need to be freed.
-     * FIXME:
-     * Introduced for QEMUOptionParamter->QemuOpts conversion.
-     * Will remove after all drivers switch to QemuOpts.
-     */
-    if (list && list->allocated) {
-        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.
+ * The lifetime of dst must be shorter than the input list because the
+ * QemuOptDesc->name, ->help, and ->def_value_str strings are shared.
  */
 QemuOptsList *qemu_opts_append(QemuOptsList *dst,
                                QemuOptsList *list)
@@ -1125,24 +1112,16 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
         dst->name = NULL;
         dst->implied_opt_name = NULL;
         QTAILQ_INIT(&dst->head);
-        dst->allocated = true;
         dst->merge_lists = false;
     }
     dst->desc[num_dst_opts].name = NULL;
 
-    /* (const char *) members of result dst are malloced, need free. */
-    assert(dst->allocated);
     /* 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++;
Signature · 1 line
1.7.12.4
#34 lore raw
In reply to Chunyan Liu
Quoted 7 lines · Chunyan Liu

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

This series causes two qemu-iotests failures. For info on qemu-iotests:
http://qemu-project.org/Documentation/QemuIoTests

Luckily they look easy to fix, they are just differences in error messages. Please preserve error messages where possible, and otherwise just update the test .out file.

When resolving these test failures, please make sure to keep bisectability by squashing the fix where the failure was introduced instead of adding new patches to the end of the series.

049 6s ... - output mismatch (see 049.out.bad)

049.out.bad renamed from 049.out +1 -1
@@ -120,7 +120,7 @@
 
 qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2
 qemu-img: Parameter 'size' expects a size
-qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'
+qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'.
 
 == Check correct interpretation of suffixes for cluster size ==
 

061 7s ... - output mismatch (see 061.out.bad)

061.out.bad renamed from 061.out +1 -1
@@ -281,7 +281,7 @@
 qemu-img: Error while amending options: Invalid argument
 Unknown compatibility level 0.42.
 qemu-img: Error while amending options: Invalid argument
-qemu-img: Invalid parameter 'foo'
+Unknown option 'foo'
 qemu-img: Invalid options for file format 'qcow2'
 Changing the cluster size is not supported.
 qemu-img: Error while amending options: Operation not supported
#35 lore raw
Quoted 24 lines · Stefan Hajnoczi
Quoted 7 lines · Chunyan Liu

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

This series causes two qemu-iotests failures. For info on qemu-iotests:
http://qemu-project.org/Documentation/QemuIoTests

Luckily they look easy to fix, they are just differences in error messages. Please preserve error messages where possible, and otherwise just update the test .out file.

When resolving these test failures, please make sure to keep bisectability by squashing the fix where the failure was introduced instead of adding new patches to the end of the series.

049 6s ... - output mismatch (see 049.out.bad)

049.out.bad line 123

Quoted 5 lines
049.out.bad renamed from 049.out +1 -1
@@ -120,7 +120,7 @@
 
 qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2
 qemu-img: Parameter 'size' expects a size
-qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'
+qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'.

Error messages should not end with a period.

061.out.bad line 284

Quoted 12 lines
049.out.bad renamed from 049.out +0 -0
 == Check correct interpretation of suffixes for cluster size ==
 
 061 7s ... - output mismatch (see 061.out.bad)
061.out.bad renamed from 061.out +1 -1
@@ -281,7 +281,7 @@
 qemu-img: Error while amending options: Invalid argument
 Unknown compatibility level 0.42.
 qemu-img: Error while amending options: Invalid argument
-qemu-img: Invalid parameter 'foo'
+Unknown option 'foo'

Losing the program name here would be regrettable.

061.out.bad line 287

Quoted 3 lines
061.out.bad renamed from 061.out +0 -0
 qemu-img: Invalid options for file format 'qcow2'
 Changing the cluster size is not supported.
 qemu-img: Error while amending options: Operation not supported

Never been closer!

#36 lore raw
In reply to Stefan Hajnoczi
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 6/5/2014 at 09:28 PM, in message

<[email protected]>, Stefan Hajnoczi

Quoted 38 lines · <[email protected]> wrote:
Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that

only

Quoted 6 lines

one Qemu Option structure is kept in QEMU code.

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

This series causes two qemu-iotests failures. For info on qemu-iotests:
http://qemu-project.org/Documentation/QemuIoTests

Luckily they look easy to fix, they are just differences in error messages. Please preserve error messages where possible, and otherwise just update the test .out file.

When resolving these test failures, please make sure to keep bisectability by squashing the fix where the failure was introduced instead of adding new patches to the end of the series.

049 6s ... - output mismatch (see 049.out.bad)

049.out.bad renamed from 049.out +1 -1
@@ -120,7 +120,7 @@ 
 
 qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2 
 qemu-img: Parameter 'size' expects a size 
-qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2' 
+qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'. 
 
 == Check correct interpretation of suffixes for cluster size == 
 

061 7s ... - output mismatch (see 061.out.bad)

061.out.bad line 287

Quoted 8 lines
061.out.bad renamed from 061.out +1 -1
@@ -281,7 +281,7 @@ 
 qemu-img: Error while amending options: Invalid argument 
 Unknown compatibility level 0.42. 
 qemu-img: Error while amending options: Invalid argument 
-qemu-img: Invalid parameter 'foo' 
+Unknown option 'foo' 
 qemu-img: Invalid options for file format 'qcow2' 
 Changing the cluster size is not supported. 
 qemu-img: Error while amending options: Operation not supported 

Hi, Stefan,
I'm confused about this mismatch. The mismatch error messages are just those are updated in 12/33, which should be correct I think and there are no failure in my testing 'make check-block'. How do you encounter those failure?

PS:
049.out: error message should not be ended with '.', I updated two places
in 12/33 and updated 049.out to match that.
061.out: old code uses QEMUOptionParameter, that prints "Unknown option 'foo'".
new code uses QemuOpts, which prints Invalid parameter 'foo'. So I correct that in 061.out.

Regards,
Chunyan

#37 lore raw
Quoted 55 lines · Chun Yan Liu
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/5/2014 at 09:28 PM, in message

<[email protected]>, Stefan Hajnoczi

Quoted 38 lines · <[email protected]> wrote:
Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that

only

Quoted 6 lines

one Qemu Option structure is kept in QEMU code.

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

This series causes two qemu-iotests failures. For info on qemu-iotests:
http://qemu-project.org/Documentation/QemuIoTests

Luckily they look easy to fix, they are just differences in error messages. Please preserve error messages where possible, and otherwise just update the test .out file.

When resolving these test failures, please make sure to keep bisectability by squashing the fix where the failure was introduced instead of adding new patches to the end of the series.

049 6s ... - output mismatch (see 049.out.bad)

049.out.bad renamed from 049.out +1 -1
@@ -120,7 +120,7 @@ 
 
 qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2 
 qemu-img: Parameter 'size' expects a size 
-qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2' 
+qemu-img: TEST_DIR/t.qcow2: Invalid options for file format 'qcow2'. 
 
 == Check correct interpretation of suffixes for cluster size == 
 

061 7s ... - output mismatch (see 061.out.bad)

061.out.bad line 287

Quoted 8 lines
061.out.bad renamed from 061.out +1 -1
@@ -281,7 +281,7 @@ 
 qemu-img: Error while amending options: Invalid argument 
 Unknown compatibility level 0.42. 
 qemu-img: Error while amending options: Invalid argument 
-qemu-img: Invalid parameter 'foo' 
+Unknown option 'foo' 
 qemu-img: Invalid options for file format 'qcow2' 
 Changing the cluster size is not supported. 
 qemu-img: Error while amending options: Operation not supported 

Hi, Stefan,
I'm confused about this mismatch. The mismatch error messages are just those are updated in 12/33, which should be correct I think and there are no failure in my testing 'make check-block'. How do you encounter those failure?

Quoted 6 lines

PS:
049.out: error message should not be ended with '.', I updated two places
in 12/33 and updated 049.out to match that.
061.out: old code uses QEMUOptionParameter, that prints "Unknown option 'foo'".
new code uses QemuOpts, which prints Invalid parameter 'foo'. So I correct that in 061.out.

You are right. I wonder if I ran qemu-iotests on v27 by mistake.

In any case, I reran git bisect -x 'make && cd tests/qemu-iotests && ./check -qcow2 049 061' to confirm that they pass with the v28 patch series.

Looks good.

Stefan

Reviewed-by on the v28 series
#38 lore raw
In reply to Chunyan Liu
Quoted 74 lines · Chunyan Liu

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

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

 block.c                    |  99 ++++----
 block/cow.c                |  52 ++--
 block/gluster.c            |  73 +++---
 block/iscsi.c              |  32 ++-
 block/nfs.c                |  10 +-
 block/qcow.c               |  72 +++---
 block/qcow2.c              | 259 ++++++++++----------
 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           | 105 ++++----
 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              |  14 +-
 include/block/block.h      |   7 +-
 include/block/block_int.h  |   9 +-
 include/qemu/option.h      |  53 +---
 include/qemu/option_int.h  |   4 +-
 qapi-schema.json           |   5 +-
Quoted 13 lines
 qapi/opts-visitor.c        |  10 +-
 qemu-img.c                 |  91 ++++---
 qmp-commands.hx            |   2 +
 tests/qemu-iotests/049.out |   2 +-
 tests/qemu-iotests/061.out |   2 +-
 util/qemu-config.c         |   4 +
 util/qemu-option.c         | 590 ++++++++++++++++++++-------------------------
 33 files changed, 1037 insertions(+), 1132 deletions(-)
Signature · 1 line
1.7.12.4
#39 lore raw
In reply to Chunyan Liu
Quoted 74 lines · Chunyan Liu

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

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

 block.c                    |  99 ++++----
 block/cow.c                |  52 ++--
 block/gluster.c            |  73 +++---
 block/iscsi.c              |  32 ++-
 block/nfs.c                |  10 +-
 block/qcow.c               |  72 +++---
 block/qcow2.c              | 259 ++++++++++----------
 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           | 105 ++++----
 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              |  14 +-
 include/block/block.h      |   7 +-
 include/block/block_int.h  |   9 +-
 include/qemu/option.h      |  53 +---
 include/qemu/option_int.h  |   4 +-
 qapi-schema.json           |   5 +-
Quoted 12 lines
 qapi/opts-visitor.c        |  10 +-
 qemu-img.c                 |  91 ++++---
 qmp-commands.hx            |   2 +
 tests/qemu-iotests/049.out |   2 +-
 tests/qemu-iotests/061.out |   2 +-
 util/qemu-config.c         |   4 +
 util/qemu-option.c         | 590 ++++++++++++++++++++-------------------------
 33 files changed, 1037 insertions(+), 1132 deletions(-)
Signature · 1 line
1.7.12.4

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

#40 lore raw
Quoted 11 lines · Stefan Hajnoczi
Quoted 10 lines · Chunyan Liu

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

[...]

Quoted 3 lines

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

A big, fat thank you all for persevering.

#41 lore raw
In reply to Chunyan Liu
Quoted 74 lines · Chunyan Liu

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

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27 sent so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

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

  block.c                    |  99 ++++----
  block/cow.c                |  52 ++--
  block/gluster.c            |  73 +++---
  block/iscsi.c              |  32 ++-
  block/nfs.c                |  10 +-
  block/qcow.c               |  72 +++---
  block/qcow2.c              | 259 ++++++++++----------
  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           | 105 ++++----
  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              |  14 +-
  include/block/block.h      |   7 +-
  include/block/block_int.h  |   9 +-
  include/qemu/option.h      |  53 +---
  include/qemu/option_int.h  |   4 +-
  qapi-schema.json           |   5 +-
Quoted 9 lines
  qapi/opts-visitor.c        |  10 +-
  qemu-img.c                 |  91 ++++---
  qmp-commands.hx            |   2 +
  tests/qemu-iotests/049.out |   2 +-
  tests/qemu-iotests/061.out |   2 +-
  util/qemu-config.c         |   4 +
  util/qemu-option.c         | 590 ++++++++++++++++++++-------------------------
  33 files changed, 1037 insertions(+), 1132 deletions(-)

It seems that for qemu-img this series introduces stack corruption. Any ideas?

lieven@lieven-pc:~/git/qemu$ valgrind --leak-check=full ./qemu-img convert -p nfs://172.21.200.61/vcore-dev-cdrom/pool3/VC_Ubuntu_LTS_12.04.2_64bit.qcow2 /tmp/x.raw
==23086== Memcheck, a memory error detector
==23086== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==23086== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==23086== Command: ./qemu-img convert -p nfs://172.21.200.61/vcore-dev-cdrom/pool3/VC_Ubuntu_LTS_12.04.2_64bit.qcow2 /tmp/x.raw
==23086==
==23086== Warning: client switching stacks?  SP change: 0x7650f08 --> 0x7feffe9f0
==23086==          to suppress, use: --max-stackframe=34218892008 or greater
==23086== Invalid write of size 8
==23086==    at 0x1C4980: qemu_opts_create (qemu-option.c:692)
==23086==    by 0x119918: img_convert (qemu-img.c:1385)
==23086==    by 0x11CEEC: main (qemu-img.c:2830)
==23086==  Address 0x7c65fe8 is 24 bytes inside a block of size 104 free'd
==23086==    at 0x4C2B7B2: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23086==    by 0x54C1AF6: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
==23086==    by 0x1C5C52: qemu_opts_append (qemu-option.c:1129)
==23086==    by 0x1198EE: img_convert (qemu-img.c:1383)
==23086==    by 0x11CEEC: main (qemu-img.c:2830)
==23086==

Peter

#42 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 6/23/2014 at 10:06 PM, in message <[email protected]>, Peter Lieven

Quoted 118 lines · <[email protected]> wrote:
Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that

only

Quoted 5 lines

one Qemu Option structure is kept in QEMU code.

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27

sent

Quoted 68 lines

so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

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

  block.c                    |  99 ++++---- 
  block/cow.c                |  52 ++-- 
  block/gluster.c            |  73 +++--- 
  block/iscsi.c              |  32 ++- 
  block/nfs.c                |  10 +- 
  block/qcow.c               |  72 +++--- 
  block/qcow2.c              | 259 ++++++++++---------- 
  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           | 105 ++++---- 
  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              |  14 +- 
  include/block/block.h      |   7 +- 
  include/block/block_int.h  |   9 +- 
  include/qemu/option.h      |  53 +--- 
  include/qemu/option_int.h  |   4 +- 
  qapi-schema.json           |   5 +- 
Quoted 9 lines
  qapi/opts-visitor.c        |  10 +- 
  qemu-img.c                 |  91 ++++--- 
  qmp-commands.hx            |   2 + 
  tests/qemu-iotests/049.out |   2 +- 
  tests/qemu-iotests/061.out |   2 +- 
  util/qemu-config.c         |   4 + 
  util/qemu-option.c         | 590 ++++++++++++++++++++------------------------- 
  33 files changed, 1037 insertions(+), 1132 deletions(-) 

It seems that for qemu-img this series introduces stack corruption. Any ideas?

lieven@lieven-pc:~/git/qemu$ valgrind --leak-check=full ./qemu-img convert -p  
nfs://172.21.200.61/vcore-dev-cdrom/pool3/VC_Ubuntu_LTS_12.04.2_64bit.qcow2  
/tmp/x.raw 
==23086== Memcheck, a memory error detector 
==23086== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. 
==23086== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info 
==23086== Command: ./qemu-img convert -p  
nfs://172.21.200.61/vcore-dev-cdrom/pool3/VC_Ubuntu_LTS_12.04.2_64bit.qcow2  
/tmp/x.raw 
==23086== 
==23086== Warning: client switching stacks?  SP change: 0x7650f08 -->  
0x7feffe9f0 
==23086==          to suppress, use: --max-stackframe=34218892008 or greater 
==23086== Invalid write of size 8 
==23086==    at 0x1C4980: qemu_opts_create (qemu-option.c:692) 
==23086==    by 0x119918: img_convert (qemu-img.c:1385) 
==23086==    by 0x11CEEC: main (qemu-img.c:2830) 
==23086==  Address 0x7c65fe8 is 24 bytes inside a block of size 104 free'd 
==23086==    at 0x4C2B7B2: realloc (in  
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 
==23086==    by 0x54C1AF6: g_realloc (in  
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4) 
==23086==    by 0x1C5C52: qemu_opts_append (qemu-option.c:1129) 
==23086==    by 0x1198EE: img_convert (qemu-img.c:1383) 
==23086==    by 0x11CEEC: main (qemu-img.c:2830) 
==23086== 
Quoted 2 lines

Peter

Thanks for reporting. I think it's the same issue and please refer to:
http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg06013.html

Quoted 1 line
#43 lore raw
Quoted 121 lines · Chun Yan Liu
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On 6/23/2014 at 10:06 PM, in message <[email protected]>, Peter Lieven

Quoted 118 lines · <[email protected]> wrote:
Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that

only

Quoted 5 lines

one Qemu Option structure is kept in QEMU code.

---
Changes to v27:
* rebase to git master (code has been updated in this part since v27

sent

Quoted 68 lines

so rebase to make the patch series work.)

All patches are also available from:
https://github.com/chunyanliu/qemu/commits/QemuOpts

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

   block.c                    |  99 ++++----
   block/cow.c                |  52 ++--
   block/gluster.c            |  73 +++---
   block/iscsi.c              |  32 ++-
   block/nfs.c                |  10 +-
   block/qcow.c               |  72 +++---
   block/qcow2.c              | 259 ++++++++++----------
   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           | 105 ++++----
   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              |  14 +-
   include/block/block.h      |   7 +-
   include/block/block_int.h  |   9 +-
   include/qemu/option.h      |  53 +---
   include/qemu/option_int.h  |   4 +-
   qapi-schema.json           |   5 +-
Quoted 9 lines
   qapi/opts-visitor.c        |  10 +-
   qemu-img.c                 |  91 ++++---
   qmp-commands.hx            |   2 +
   tests/qemu-iotests/049.out |   2 +-
   tests/qemu-iotests/061.out |   2 +-
   util/qemu-config.c         |   4 +
   util/qemu-option.c         | 590 ++++++++++++++++++++-------------------------
   33 files changed, 1037 insertions(+), 1132 deletions(-)

It seems that for qemu-img this series introduces stack corruption. Any ideas?

lieven@lieven-pc:~/git/qemu$ valgrind --leak-check=full ./qemu-img convert -p
nfs://172.21.200.61/vcore-dev-cdrom/pool3/VC_Ubuntu_LTS_12.04.2_64bit.qcow2
/tmp/x.raw
==23086== Memcheck, a memory error detector
==23086== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==23086== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==23086== Command: ./qemu-img convert -p
nfs://172.21.200.61/vcore-dev-cdrom/pool3/VC_Ubuntu_LTS_12.04.2_64bit.qcow2
/tmp/x.raw
==23086==
==23086== Warning: client switching stacks?  SP change: 0x7650f08 -->
0x7feffe9f0
==23086==          to suppress, use: --max-stackframe=34218892008 or greater
==23086== Invalid write of size 8
==23086==    at 0x1C4980: qemu_opts_create (qemu-option.c:692)
==23086==    by 0x119918: img_convert (qemu-img.c:1385)
==23086==    by 0x11CEEC: main (qemu-img.c:2830)
==23086==  Address 0x7c65fe8 is 24 bytes inside a block of size 104 free'd
==23086==    at 0x4C2B7B2: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23086==    by 0x54C1AF6: g_realloc (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
==23086==    by 0x1C5C52: qemu_opts_append (qemu-option.c:1129)
==23086==    by 0x1198EE: img_convert (qemu-img.c:1383)
==23086==    by 0x11CEEC: main (qemu-img.c:2830)
==23086==
Quoted 4 lines
Quoted 2 lines

Peter

Thanks for reporting. I think it's the same issue and please refer to:
http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg06013.html

Yes, thats it.

Thanks you,
Peter