Skip to contentSkip to conversation

QemuOptionParameter -> QemuOpts migration

PATCH In review Leandro Dorileo 4 participants 34 messages Mar 21, 2014 – Mar 22, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

cover QemuOptionParameter -> QemuOpts migration

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

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

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

--
Dorileo

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

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

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

PATCH 1/26 qapi: output def_value_str when query command line options

From: Chunyan Liu <[email protected]>

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

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

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

Quoted 18 lines · Leandro Dorileo

From: Chunyan Liu <[email protected]>

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

---
 qapi-schema.json   | 6 +++++-
 qmp-commands.hx    | 2 ++
 util/qemu-config.c | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)
qapi-schema.json +0 -0
index b68cd44..cf9174e 100644

qapi-schema.json line 4092

Quoted 5 lines
qapi-schema.json +2 -0
@@ -4088,12 +4088,16 @@
 #
 # @help: #optional human readable text string, not suitable for parsing.
 #
+# @default: #optional string representation of the default used
+#           if the option is omitted. (since 2.0)

We've missed 2.0; this needs to mention 2.1.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

PATCH 2/26 add def_value_str to QemuOptDesc

In reply to Leandro Dorileo

From: Chunyan Liu <[email protected]>

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

---
 include/qemu/option.h |  3 +-
 util/qemu-option.c    | 84 +++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 63 insertions(+), 24 deletions(-)
include/qemu/option.h +2 -1
index 8c0ac34..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 {
@@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
-int qemu_opts_print(QemuOpts *opts, void *dummy);
+void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
                       int abort_on_failure);
 
util/qemu-option.c +61 -23

134 lines not on this page · raw message

Signature · 1 line
1.9.0
#4 lore raw

PATCH 3/26 QemuOpt: improve default value

In reply to Leandro Dorileo

Use a pointer to a structure holding the primitive types and avoid parsing the default value representation.

---
 include/qemu/option.h | 20 +++++++++++++++++++-
 util/qemu-config.c    |  4 ++--
 util/qemu-option.c    | 45 ++++++++++++++++++++++++++-------------------
 3 files changed, 47 insertions(+), 22 deletions(-)
include/qemu/option.h +19 -1
index c3b0a91..f0d4798 100644
@@ -95,11 +95,29 @@ enum QemuOptType {
     QEMU_OPT_SIZE,        /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */
 };
 
+#define QEMU_OPT_VAL_STR(_val)                                  \
+    &(QemuOptValue) {.s = _val}                                 \
+
+#define QEMU_OPT_VAL_NUMBER(_val)                               \
+    &(QemuOptValue) {.n = _val}                                 \
+
+#define QEMU_OPT_VAL_SIZE(_val)                                 \
+    &(QemuOptValue) {.n = _val}                                 \
+
+#define QEMU_OPT_VAL_BOOL(_val)                                 \
+    &(QemuOptValue) {.b = _val}                                 \
+
+typedef struct QemuOptValue {
+    bool b;
+    uint64_t n;
+    const char *s;
+} QemuOptValue;
+
 typedef struct QemuOptDesc {
     const char *name;
     enum QemuOptType type;
     const char *help;
-    const char *def_value_str;
+    QemuOptValue *def_val;
 } QemuOptDesc;
 
 struct QemuOptsList {
util/qemu-config.c +2 -2
index d608b2f..a40711b 100644
@@ -68,9 +68,9 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
             info->has_help = true;
             info->help = g_strdup(desc[i].help);
         }
-        if (desc[i].def_value_str) {
+        if (desc[i].def_val) {
             info->has_q_default = true;
-            info->q_default = g_strdup(desc[i].def_value_str);
+            info->q_default = g_strdup(desc[i].def_val->s);
         }
 
         entry = g_malloc0(sizeof(*entry));
util/qemu-option.c +26 -19

83 lines not on this page · raw message

Signature · 1 line
1.9.0
#5 lore raw

PATCH 4/26 QemuOpt: introduce qemu_opts_append()

In reply to Leandro Dorileo

From: Chunyan Liu <[email protected]>

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

---
 include/qemu/option.h |  1 +
 util/qemu-option.c    | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
include/qemu/option.h +1 -0
index f0d4798..3f4976d 100644
@@ -157,6 +157,7 @@ int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
                            int fail_if_exists, Error **errp);
+QemuOptsList *qemu_opts_append(QemuOptsList *head, QemuOptsList *tail);
 void qemu_opts_reset(QemuOptsList *list);
 void qemu_opts_loc_restore(QemuOpts *opts);
 int qemu_opts_set(QemuOptsList *list, const char *id,
util/qemu-option.c +69 -0

75 lines not on this page · raw message

Signature · 1 line
1.9.0
#6 lore raw

PATCH 5/26 QemuOpt: add qemu_opt_print_help()

In reply to Leandro Dorileo

Analogous to print_option_help(QEMUOptionParameter *list) this function displays the available key and help for each described QemuOptDesc in QemuOptList.

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

PATCH 6/26 block: migrate block later QemuOptionParameter

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on block layer.

---
 block.c                   | 133 ++++++++++++++++++++++++++++------------------
 include/block/block.h     |   7 ++-
 include/block/block_int.h |   8 ++-
 3 files changed, 86 insertions(+), 62 deletions(-)
block.c +80 -53
index acb70fd..e70f360 100644
@@ -407,7 +407,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
 typedef struct CreateCo {
     BlockDriver *drv;
     char *filename;
-    QEMUOptionParameter *options;
+    QemuOpts *options;
     int ret;
     Error *err;
 } CreateCo;
@@ -427,8 +427,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
     cco->ret = ret;
 }
 
-int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, Error **errp)
+int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *options,
+                Error **errp)
 {
     int ret;
 
@@ -472,8 +472,7 @@ out:
     return ret;
 }
 
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp)
+int bdrv_create_file(const char *filename, QemuOpts *options, Error **errp)
 {
     BlockDriver *drv;
     Error *local_err = NULL;
@@ -1248,7 +1247,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QEMUOptionParameter *create_options;
+        QemuOpts *create_options;
         QDict *snapshot_options;
 
         /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1273,27 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         }
 
         bdrv_qcow2 = bdrv_find_format("qcow2");
-        create_options = parse_option_parameters("", bdrv_qcow2->create_options,
-                                                 NULL);
 
-        set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
+        create_options = qemu_opts_create(bdrv_qcow2->create_options, NULL, 0,
+                                          &local_err);
+
+        if (create_options == NULL) {
+            error_setg(errp, "Could not create internal option %s",
+                       error_get_pretty(local_err));
+            error_free(local_err);
+            local_err = NULL;
+            goto fail;
+        }
+
+        ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, total_size);
+        if (ret < 0) {
+            qemu_opts_del(create_options);
+            goto fail;
+        }
 
         ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
-        free_option_parameters(create_options);
+        qemu_opts_del(create_options);
+
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create temporary overlay "
                              "'%s': %s", tmp_filename,
@@ -5259,12 +5272,14 @@ void bdrv_img_create(const char *filename, const char *fmt,
                      char *options, uint64_t img_size, int flags,
                      Error **errp, bool quiet)
 {
-    QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *backing_fmt, *backing_file, *size;
+    QemuOptsList *list;
+    QemuOpts *create_options;
+    const char *backing_file, *backing_fmt;
     BlockDriver *drv, *proto_drv;
     BlockDriver *backing_drv = NULL;
     Error *local_err = NULL;
     int ret = 0;
+    uint64_t size;
 
     /* Find driver and parse its options */
     drv = bdrv_find_format(fmt);
@@ -5279,28 +5294,39 @@ void bdrv_img_create(const char *filename, const char *fmt,
         return;
     }
 
-    create_options = append_option_parameters(create_options,
-                                              drv->create_options);
-    create_options = append_option_parameters(create_options,
-                                              proto_drv->create_options);
+    list = qemu_opts_append(drv->create_options, proto_drv->create_options);
+    if (!list) {
+        error_setg(errp, "Could not allocate option list");
+        return;
+    }
 
-    /* Create parameter list with default values */
-    param = parse_option_parameters("", create_options, param);
+    create_options = qemu_opts_create(list, NULL, 0, &local_err);
+    if (create_options == NULL) {
+        error_setg(errp, "Could not create internal option %s",
+                   error_get_pretty(local_err));
+        error_free(local_err);
+        g_free(list);
+        local_err = NULL;
+        return;
+    }
 
-    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+    ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, img_size);
+    if (ret < 0) {
+        goto out;
+    }
 
     /* Parse -o options */
     if (options) {
-        param = parse_option_parameters(options, create_options, param);
-        if (param == NULL) {
-            error_setg(errp, "Invalid options for file format '%s'.", fmt);
+        ret = qemu_opts_do_parse(create_options, options, NULL);
+        if (ret < 0) {
             goto out;
         }
     }
 
     if (base_filename) {
-        if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
-                                 base_filename)) {
+        ret  = qemu_opt_set(create_options, BLOCK_OPT_BACKING_FILE,
+                            base_filename);
+        if (ret < 0) {
             error_setg(errp, "Backing file not supported for file format '%s'",
                        fmt);
             goto out;
@@ -5308,40 +5334,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)) {
+        ret = qemu_opt_set(create_options, BLOCK_OPT_BACKING_FMT, base_fmt);
+        if (ret < 0) {
             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)) {
-            error_setg(errp, "Error: Trying to create an image with the "
-                             "same filename as the backing file");
-            goto out;
-        }
+    backing_file = qemu_opt_get(create_options, BLOCK_OPT_BACKING_FILE);
+    if (backing_file && !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(create_options, 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);
+            error_setg(errp, "Unknown backing file format '%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(create_options, BLOCK_OPT_SIZE, 0);
+    if (size == -1) {
+        if (backing_file) {
             BlockDriverState *bs;
             uint64_t size;
-            char buf[32];
             int back_flags;
 
             /* backing files always opened read-only */
@@ -5349,12 +5372,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,
-                                 error_get_pretty(local_err));
+                                 backing_file, error_get_pretty(local_err));
                 error_free(local_err);
                 local_err = NULL;
                 goto out;
@@ -5362,8 +5384,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
             bdrv_get_geometry(bs, &size);
             size *= 512;
 
-            snprintf(buf, sizeof(buf), "%" PRId64, size);
-            set_option_parameter(param, BLOCK_OPT_SIZE, buf);
+            qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, size);
 
             bdrv_unref(bs);
         } else {
@@ -5373,19 +5394,25 @@ void bdrv_img_create(const char *filename, const char *fmt,
     }
 
     if (!quiet) {
-        printf("Formatting '%s', fmt=%s ", filename, fmt);
-        print_option_parameters(param);
+        fprintf(stderr, "Formatting '%s', fmt=%s ", filename, fmt);
+        qemu_opts_print(create_options);
         puts("");
     }
-    ret = bdrv_create(drv, filename, param, &local_err);
+    ret = bdrv_create(drv, filename, create_options, &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)) {
+        uint32_t cluster_size;
+
+        cluster_size = qemu_opt_get_size(create_options,
+                                         BLOCK_OPT_CLUSTER_SIZE, 0);
+
+        if (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'"
                    "%s", fmt, cluster_size_hint);
         error_free(local_err);
@@ -5393,8 +5420,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
     }
 
 out:
-    free_option_parameters(create_options);
-    free_option_parameters(param);
+    qemu_opts_del(create_options);
+    g_free(list);
 
     if (local_err) {
         error_propagate(errp, local_err);
@@ -5413,7 +5440,7 @@ 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, QemuOpts *options)
 {
     if (bs->drv->bdrv_amend_options == NULL) {
         return -ENOTSUP;
include/block/block.h +3 -4
index 1ed55d8..ec3fc34 100644
@@ -177,9 +177,8 @@ BlockDriver *bdrv_find_format(const char *format_name);
 BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
                                           bool readonly);
 int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, Error **errp);
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp);
+                QemuOpts *options, Error **errp);
+int bdrv_create_file(const char *filename, QemuOpts *options, Error **errp);
 BlockDriverState *bdrv_new(const char *device_name);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -283,7 +282,7 @@ 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, QemuOpts *options);
 
 /* external snapshots */
 bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
include/block/block_int.h +3 -5
index cd5bc73..365686f 100644
@@ -116,8 +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);
+    int (*bdrv_create)(const char *filename, QemuOpts *options, Error **errp);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -216,7 +215,7 @@ struct BlockDriver {
         BlockDriverCompletionFunc *cb, void *opaque);
 
     /* List of options for creating images, terminated by name == NULL */
-    QEMUOptionParameter *create_options;
+    QemuOptsList *create_options;
 
 
     /*
@@ -226,8 +225,7 @@ struct BlockDriver {
     int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
         BdrvCheckMode fix);
 
-    int (*bdrv_amend_options)(BlockDriverState *bs,
-        QEMUOptionParameter *options);
+    int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *options);
 
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
Signature · 1 line
1.9.0
#8 lore raw

PATCH 7/26 cow: migrate cow driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on cow block driver.

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

PATCH 8/26 gluster: migrate gluster driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on gluster block driver.

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

PATCH 9/26 iscsi: migrate iscsi driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on iscsi block driver.

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

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

Quoted 13 lines · Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on iscsi block driver.

---
  block/iscsi.c | 32 ++++++++++++++++----------------
  1 file changed, 16 insertions(+), 16 deletions(-)
block/iscsi.c +0 -0
index b490e98..85252e7 100644

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1128

Quoted 5 lines
block/iscsi.c +1 -1
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
      QemuOpts *opts;
      Error *local_err = NULL;
      const char *filename;
-    int i, ret;
+    int i, ret = 0;

why? is there a chance that ret remains uninitialized?

Quoted 17 lines
block/iscsi.c +1 -2
      if ((BDRV_SECTOR_SIZE % 512) != 0) {
          error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
      return 0;
  }
 
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
  {
      int ret = 0;
      int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
 
      bs = bdrv_new("");
 

block/iscsi.c static int iscsi_create(const char *filename, QEMUOptionParameter *options, · line 1398

Quoted 10 lines
block/iscsi.c +3 -6
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (total_size) {
+        total_size = total_size / BDRV_SECTOR_SIZE;
      }

you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.

Peter

Quoted 35 lines
block/iscsi.c +11 -7
      bs->opaque = g_malloc0(sizeof(struct IscsiLun));
@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
      return 0;
  }
 
-static QEMUOptionParameter iscsi_create_options[] = {
-    {
-        .name = BLOCK_OPT_SIZE,
-        .type = OPT_SIZE,
-        .help = "Virtual disk size"
+static QemuOptsList iscsi_create_options = {
+    .name = "iscsi_create_options",
+    .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { NULL }
      },
-    { NULL }
  };
 
  static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
      .bdrv_file_open  = iscsi_open,
      .bdrv_close      = iscsi_close,
      .bdrv_create     = iscsi_create,
-    .create_options  = iscsi_create_options,
+    .create_options  = &iscsi_create_options,
      .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
      .bdrv_getlength  = iscsi_getlength,
Signature · 16 lines
Mit freundlichen Grüßen

Peter Lieven

...........................................................

  KAMP Netzwerkdienste GmbH
  Vestische Str. 89-91 | 46117 Oberhausen
  Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
  [email protected] | http://www.kamp.de

  Geschäftsführer: Heiner Lante | Michael Lante
  Amtsgericht Duisburg | HRB Nr. 12154
  USt-Id-Nr.: DE 120607556

...........................................................
#12 lore raw

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

Quoted 9 lines · Peter Lieven
Quoted 8 lines · Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on iscsi block driver.

---
 block/iscsi.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
Quoted 12 lines

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1128

Quoted 10 lines
block/iscsi.c +1 -1
index b490e98..85252e7 100644
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     QemuOpts *opts;
     Error *local_err = NULL;
     const char *filename;
-    int i, ret;
+    int i, ret = 0;

why? is there a chance that ret remains uninitialized?

Yep, my compiler tells me so:

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

Quoted 17 lines
Quoted 17 lines
block/iscsi.c +1 -5
     if ((BDRV_SECTOR_SIZE % 512) != 0) {
         error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
     return 0;
 }
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
 {
     int ret = 0;
     int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
     bs = bdrv_new("");
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
Quoted 9 lines

block/iscsi.c static int iscsi_create(const char *filename, QEMUOptionParameter *options, · line 1398

Quoted 7 lines
block/iscsi.c +3 -3
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (total_size) {
+        total_size = total_size / BDRV_SECTOR_SIZE;
     }

you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.

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

Quoted 54 lines

Peter

Quoted 31 lines
block/iscsi.c +11 -7
     bs->opaque = g_malloc0(sizeof(struct IscsiLun));
@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
-static QEMUOptionParameter iscsi_create_options[] = {
-    {
-        .name = BLOCK_OPT_SIZE,
-        .type = OPT_SIZE,
-        .help = "Virtual disk size"
+static QemuOptsList iscsi_create_options = {
+    .name = "iscsi_create_options",
+    .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { NULL }
     },
-    { NULL }
 };
 static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
     .bdrv_create     = iscsi_create,
-    .create_options  = iscsi_create_options,
+    .create_options  = &iscsi_create_options,
     .bdrv_reopen_prepare  = iscsi_reopen_prepare,
     .bdrv_getlength  = iscsi_getlength,
Signature · 16 lines
Mit freundlichen Grüßen

Peter Lieven

...........................................................

  KAMP Netzwerkdienste GmbH
  Vestische Str. 89-91 | 46117 Oberhausen
  Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
  [email protected] | http://www.kamp.de

  Geschäftsführer: Heiner Lante | Michael Lante
  Amtsgericht Duisburg | HRB Nr. 12154
  USt-Id-Nr.: DE 120607556

...........................................................
Signature · 1 line
Leandro Dorileo
#13 lore raw

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

Quoted 55 lines · Leandro Dorileo
Quoted 9 lines · Peter Lieven
Quoted 8 lines · Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on iscsi block driver.

---
 block/iscsi.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
Quoted 12 lines

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1128

Quoted 10 lines
block/iscsi.c +1 -1
index b490e98..85252e7 100644
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     QemuOpts *opts;
     Error *local_err = NULL;
     const char *filename;
-    int i, ret;
+    int i, ret = 0;

why? is there a chance that ret remains uninitialized?

Yep, my compiler tells me so:

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

Quoted 17 lines
Quoted 17 lines
block/iscsi.c +1 -5
     if ((BDRV_SECTOR_SIZE % 512) != 0) {
         error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
     return 0;
 }
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
 {
     int ret = 0;
     int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
     bs = bdrv_new("");
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
Quoted 9 lines

block/iscsi.c static int iscsi_create(const char *filename, QEMUOptionParameter *options, · line 1398

Quoted 7 lines
block/iscsi.c +3 -3
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (total_size) {
+        total_size = total_size / BDRV_SECTOR_SIZE;
     }

you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.

Quoted 4 lines

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

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

Quoted 59 lines
Quoted 56 lines

Peter

Quoted 31 lines
block/iscsi.c +11 -7
     bs->opaque = g_malloc0(sizeof(struct IscsiLun));
@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
-static QEMUOptionParameter iscsi_create_options[] = {
-    {
-        .name = BLOCK_OPT_SIZE,
-        .type = OPT_SIZE,
-        .help = "Virtual disk size"
+static QemuOptsList iscsi_create_options = {
+    .name = "iscsi_create_options",
+    .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { NULL }
     },
-    { NULL }
 };
 static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
     .bdrv_create     = iscsi_create,
-    .create_options  = iscsi_create_options,
+    .create_options  = &iscsi_create_options,
     .bdrv_reopen_prepare  = iscsi_reopen_prepare,
     .bdrv_getlength  = iscsi_getlength,
Signature · 16 lines
Mit freundlichen Grüßen

Peter Lieven

...........................................................

  KAMP Netzwerkdienste GmbH
  Vestische Str. 89-91 | 46117 Oberhausen
  Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
  [email protected] | http://www.kamp.de

  Geschäftsführer: Heiner Lante | Michael Lante
  Amtsgericht Duisburg | HRB Nr. 12154
  USt-Id-Nr.: DE 120607556

...........................................................
Signature · 1 line
Leandro Dorileo
Signature · 1 line
Leandro Dorileo
#14 lore raw

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

In reply to Leandro Dorileo
Quoted 51 lines · Leandro Dorileo
Quoted 9 lines · Peter Lieven
Quoted 8 lines · Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on iscsi block driver.

---
  block/iscsi.c | 32 ++++++++++++++++----------------
  1 file changed, 16 insertions(+), 16 deletions(-)
Quoted 11 lines

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1128

Quoted 10 lines
block/iscsi.c +1 -1
index b490e98..85252e7 100644
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
      QemuOpts *opts;
      Error *local_err = NULL;
      const char *filename;
-    int i, ret;
+    int i, ret = 0;

why? is there a chance that ret remains uninitialized?

Yep, my compiler tells me so:

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

Quoted 16 lines
Quoted 16 lines
block/iscsi.c +1 -5
      if ((BDRV_SECTOR_SIZE % 512) != 0) {
          error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
      return 0;
  }
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
  {
      int ret = 0;
      int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
      bs = bdrv_new("");
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
Quoted 9 lines

block/iscsi.c static int iscsi_create(const char *filename, QEMUOptionParameter *options, · line 1398

Quoted 7 lines
block/iscsi.c +3 -3
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (total_size) {
+        total_size = total_size / BDRV_SECTOR_SIZE;
      }

you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.

Quoted 4 lines

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

division by zero is x / 0 not 0 / x.

0 / x = 0
x / 0 = undef

Peter

#15 lore raw

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

Quoted 57 lines · Peter Lieven
Quoted 51 lines · Leandro Dorileo
Quoted 9 lines · Peter Lieven
Quoted 8 lines · Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on iscsi block driver.

---
 block/iscsi.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
Quoted 11 lines

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1128

Quoted 10 lines
block/iscsi.c +1 -1
index b490e98..85252e7 100644
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     QemuOpts *opts;
     Error *local_err = NULL;
     const char *filename;
-    int i, ret;
+    int i, ret = 0;

why? is there a chance that ret remains uninitialized?

Yep, my compiler tells me so:

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

Quoted 16 lines
Quoted 16 lines
block/iscsi.c +1 -5
     if ((BDRV_SECTOR_SIZE % 512) != 0) {
         error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
     return 0;
 }
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
 {
     int ret = 0;
     int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
     bs = bdrv_new("");
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
Quoted 9 lines

block/iscsi.c static int iscsi_create(const char *filename, QEMUOptionParameter *options, · line 1398

Quoted 7 lines
block/iscsi.c +3 -3
-            total_size = options->value.n / BDRV_SECTOR_SIZE;
-        }
-        options++;
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (total_size) {
+        total_size = total_size / BDRV_SECTOR_SIZE;
     }

you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.

Quoted 4 lines

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

Quoted 5 lines

division by zero is x / 0 not 0 / x.

0 / x = 0
x / 0 = undef

Yep, true.

Signature · 1 line
Leandro Dorileo
#16 lore raw

PATCH 10/26 nfs: migrate nfs driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on nfs block driver.

---
 block/nfs.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
block/nfs.c +2 -9
index 98aa363..c01f109 100644
@@ -357,20 +357,13 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
     return 0;
 }
 
-static int nfs_file_create(const char *url, QEMUOptionParameter *options,
-                           Error **errp)
+static int nfs_file_create(const char *url, QemuOpts *options, Error **errp)
 {
     int ret = 0;
     int64_t total_size = 0;
     NFSClient *client = g_malloc0(sizeof(NFSClient));
 
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, "size")) {
-            total_size = options->value.n;
-        }
-        options++;
-    }
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
 
     ret = nfs_client_open(client, url, O_CREAT, errp);
     if (ret < 0) {
Signature · 1 line
1.9.0
#17 lore raw

PATCH 11/26 qcow: migrate qcow driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on qcow block driver.

---
 block/qcow.c | 59 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 29 insertions(+), 30 deletions(-)
block/qcow.c +29 -30
index 1e128be..65c7486 100644
@@ -662,31 +662,26 @@ static void qcow_close(BlockDriverState *bs)
     error_free(s->migration_blocker);
 }
 
-static int qcow_create(const char *filename, QEMUOptionParameter *options,
-                       Error **errp)
+static int qcow_create(const char *filename, QemuOpts *options, Error **errp)
 {
     int header_size, backing_filename_len, l1_size, shift, i;
     QCowHeader header;
     uint8_t *tmp;
     int64_t total_size = 0;
     const char *backing_file = NULL;
-    int flags = 0;
+    uint64_t flags = 0;
     Error *local_err = NULL;
     int ret;
     BlockDriverState *qcow_bs;
 
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-            total_size = options->value.n / 512;
-        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-            backing_file = options->value.s;
-        } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
-            flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
-        }
-        options++;
+    total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (total_size) {
+        total_size = total_size / 512;
     }
 
+    backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+    flags |= qemu_opt_get_number(options, BLOCK_OPT_ENCRYPT, 0);
+
     ret = bdrv_create_file(filename, options, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
@@ -882,23 +877,27 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
 }
 
 
-static QEMUOptionParameter qcow_create_options[] = {
-    {
-        .name = BLOCK_OPT_SIZE,
-        .type = OPT_SIZE,
-        .help = "Virtual disk size"
-    },
-    {
-        .name = BLOCK_OPT_BACKING_FILE,
-        .type = OPT_STRING,
-        .help = "File name of a base image"
-    },
-    {
-        .name = BLOCK_OPT_ENCRYPT,
-        .type = OPT_FLAG,
-        .help = "Encrypt the image"
+static QemuOptsList qcow_create_options = {
+    .name = "qcow_create_options",
+    .head = QTAILQ_HEAD_INITIALIZER(qcow_create_options.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        {
+            .name = BLOCK_OPT_BACKING_FILE,
+            .type = QEMU_OPT_STRING,
+            .help = "File name of a base image"
+        },
+        {
+            .name = BLOCK_OPT_ENCRYPT,
+            .type = QEMU_OPT_NUMBER,
+            .help = "Encrypt the image"
+        },
+        { NULL }
     },
-    { NULL }
 };
 
 static BlockDriver bdrv_qcow = {
@@ -920,7 +919,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_write_compressed  = qcow_write_compressed,
     .bdrv_get_info          = qcow_get_info,
 
-    .create_options = qcow_create_options,
+    .create_options = &qcow_create_options,
 };
 
 static void bdrv_qcow_init(void)
Signature · 1 line
1.9.0
#18 lore raw

PATCH 12/26 qcow2: migrate qcow2 driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on qcow2 block driver.

---
 block/qcow2.c | 263 ++++++++++++++++++++++++++++------------------------------
 1 file changed, 128 insertions(+), 135 deletions(-)
block/qcow2.c +128 -135
index b9dc960..a69438f 100644
@@ -1472,7 +1472,7 @@ static int preallocate(BlockDriverState *bs)
 static int qcow2_create2(const char *filename, int64_t total_size,
                          const char *backing_file, const char *backing_format,
                          int flags, size_t cluster_size, int prealloc,
-                         QEMUOptionParameter *options, int version,
+                         QemuOpts *options, int version,
                          Error **errp)
 {
     /* Calculate cluster_bits */
@@ -1639,9 +1639,10 @@ out:
     return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *options, Error **errp)
 {
+    const char *compat_level_opt = NULL;
+    const char *prealloc_opt = NULL;
     const char *backing_file = NULL;
     const char *backing_fmt = NULL;
     uint64_t sectors = 0;
@@ -1652,46 +1653,47 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
     Error *local_err = NULL;
     int ret;
 
-    /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-            sectors = options->value.n / 512;
-        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-            backing_file = options->value.s;
-        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
-            backing_fmt = options->value.s;
-        } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
-            flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
-        } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-            if (options->value.n) {
-                cluster_size = options->value.n;
-            }
-        } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
-            if (!options->value.s || !strcmp(options->value.s, "off")) {
-                prealloc = 0;
-            } else if (!strcmp(options->value.s, "metadata")) {
-                prealloc = 1;
-            } else {
-                error_setg(errp, "Invalid preallocation mode: '%s'",
-                           options->value.s);
-                return -EINVAL;
-            }
-        } else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
-            if (!options->value.s) {
-                /* keep the default */
-            } else if (!strcmp(options->value.s, "0.10")) {
-                version = 2;
-            } else if (!strcmp(options->value.s, "1.1")) {
-                version = 3;
-            } else {
-                error_setg(errp, "Invalid compatibility level: '%s'",
-                           options->value.s);
-                return -EINVAL;
-            }
-        } else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
-            flags |= options->value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
+    sectors = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    if (sectors) {
+        sectors = sectors / 512;
+    }
+
+    backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+    backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+
+    if (qemu_opt_get_bool(options, BLOCK_OPT_ENCRYPT, false)) {
+        flags |= BLOCK_FLAG_ENCRYPT;
+    }
+
+    cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+    prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+    if (prealloc_opt) {
+        if (!strcmp(prealloc_opt, "off")) {
+            prealloc = 0;
+        } else if (!strcmp(prealloc_opt, "metadata")) {
+            prealloc = 1;
+        } else {
+            error_setg(errp, "Invalid preallocation mode: '%s'", prealloc_opt);
+            return -EINVAL;
+        }
+    }
+
+    compat_level_opt = qemu_opt_get(options, BLOCK_OPT_COMPAT_LEVEL);
+    if (compat_level_opt) {
+        if (!strcmp(compat_level_opt, "0.10")) {
+            version = 2;
+        } else if (!strcmp(compat_level_opt, "1.1")) {
+            version = 3;
+        } else {
+            error_setg(errp, "Invalid compatibility level: '%s'",
+                       compat_level_opt);
+            return -EINVAL;
         }
-        options++;
+    }
+
+    if (qemu_opt_get_bool(options, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+        flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
     }
 
     if (backing_file && prealloc) {
@@ -2075,66 +2077,53 @@ static int 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 *options)
 {
     BDRVQcowState *s = bs->opaque;
     int old_version = s->qcow_version, new_version = old_version;
-    uint64_t new_size = 0;
+    uint64_t cluster_size, new_size = 0;
     const char *backing_file = NULL, *backing_format = NULL;
-    bool lazy_refcounts = s->use_lazy_refcounts;
+    const char *compat_level_opt = NULL;
+    bool crypt_opt, lazy_refcounts;
     int ret;
-    int i;
 
-    for (i = 0; options[i].name; i++)
-    {
-        if (!options[i].assigned) {
-            /* only change explicitly defined options */
-            continue;
-        }
-
-        if (!strcmp(options[i].name, "compat")) {
-            if (!options[i].value.s) {
-                /* preserve default */
-            } else if (!strcmp(options[i].value.s, "0.10")) {
-                new_version = 2;
-            } else if (!strcmp(options[i].value.s, "1.1")) {
-                new_version = 3;
-            } else {
-                fprintf(stderr, "Unknown compatibility level %s.\n",
-                        options[i].value.s);
-                return -EINVAL;
-            }
-        } else if (!strcmp(options[i].name, "preallocation")) {
-            fprintf(stderr, "Cannot change preallocation mode.\n");
-            return -ENOTSUP;
-        } else if (!strcmp(options[i].name, "size")) {
-            new_size = options[i].value.n;
-        } else if (!strcmp(options[i].name, "backing_file")) {
-            backing_file = options[i].value.s;
-        } else if (!strcmp(options[i].name, "backing_fmt")) {
-            backing_format = options[i].value.s;
-        } else if (!strcmp(options[i].name, "encryption")) {
-            if ((options[i].value.n != !!s->crypt_method)) {
-                fprintf(stderr, "Changing the encryption flag is not "
-                        "supported.\n");
-                return -ENOTSUP;
-            }
-        } else if (!strcmp(options[i].name, "cluster_size")) {
-            if (options[i].value.n != s->cluster_size) {
-                fprintf(stderr, "Changing the cluster size is not "
-                        "supported.\n");
-                return -ENOTSUP;
-            }
-        } else if (!strcmp(options[i].name, "lazy_refcounts")) {
-            lazy_refcounts = options[i].value.n;
+    compat_level_opt = qemu_opt_get(options, BLOCK_OPT_COMPAT_LEVEL);
+    if (compat_level_opt) {
+        if (!strcmp(compat_level_opt, "0.10")) {
+            new_version = 2;
+        } else if (!strcmp(compat_level_opt, "1.1")) {
+            new_version = 3;
         } else {
-            /* if this assertion fails, this probably means a new option was
-             * added without having it covered here */
-            assert(false);
+            fprintf(stderr, "Invalid compatibility level: '%s'",
+                    compat_level_opt);
+            return -EINVAL;
         }
     }
 
+    if (qemu_opt_get_bool(options, BLOCK_OPT_PREALLOC, false)) {
+        fprintf(stderr, "Cannot change preallocation mode.\n");
+        return -ENOTSUP;
+    }
+
+    new_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+    backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+    backing_format = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+
+    crypt_opt = qemu_opt_get_bool(options, BLOCK_OPT_ENCRYPT, false);
+    if (crypt_opt != !!s->crypt_method) {
+        fprintf(stderr, "Changing the encryption flag is not supported.\n");
+        return -ENOTSUP;
+    }
+
+    cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+    if (cluster_size != s->cluster_size) {
+        fprintf(stderr, "Changing the cluster size is not supported.\n");
+        return -ENOTSUP;
+    }
+
+    lazy_refcounts = qemu_opt_get_bool(options, BLOCK_OPT_LAZY_REFCOUNTS,
+                                       s->use_lazy_refcounts);
+
     if (new_version != old_version) {
         if (new_version > old_version) {
             /* Upgrade */
@@ -2201,49 +2190,53 @@ 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",
+static QemuOptsList qcow2_create_options = {
+    .name = "qcow2_create_options",
+    .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_options.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"
+        },
+        {
+            .name = BLOCK_OPT_CLUSTER_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "qcow2 cluster size",
+            .def_val = QEMU_OPT_VAL_SIZE(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",
+        },
+        { NULL }
     },
-    { NULL }
 };
 
 static BlockDriver bdrv_qcow2 = {
@@ -2283,7 +2276,7 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_refresh_limits        = qcow2_refresh_limits,
     .bdrv_invalidate_cache      = qcow2_invalidate_cache,
 
-    .create_options = qcow2_create_options,
+    .create_options = &qcow2_create_options,
     .bdrv_check = qcow2_check,
     .bdrv_amend_options = qcow2_amend_options,
 };
Signature · 1 line
1.9.0
#19 lore raw

PATCH 13/26 qed: migrate qed driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on qed block driver.

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

PATCH 14/26 raw-posix: migrate raw-posix driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on raw-posix block driver.

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

PATCH 15/26 raw-win32: migrate cow driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on raw-win32 block driver.

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

PATCH 16/26 raw_bsd: migrate raw_bsd driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on raw_bsd block driver.

---
 block/raw_bsd.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
block/raw_bsd.c +12 -9
index 01ea692..5090b4e 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"
+static QemuOptsList raw_create_options = {
+    .name = "raw_create_options",
+    .head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { 0 }
     },
-    { 0 }
 };
 
 static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,8 +143,7 @@ static int raw_has_zero_init(BlockDriverState *bs)
     return bdrv_has_zero_init(bs->file);
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
-                      Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
     Error *local_err = NULL;
     int ret;
@@ -194,7 +197,7 @@ static BlockDriver bdrv_raw = {
     .bdrv_lock_medium     = &raw_lock_medium,
     .bdrv_ioctl           = &raw_ioctl,
     .bdrv_aio_ioctl       = &raw_aio_ioctl,
-    .create_options       = &raw_create_options[0],
+    .create_options       = &raw_create_options,
     .bdrv_has_zero_init   = &raw_has_zero_init
 };
 
Signature · 1 line
1.9.0
#23 lore raw

PATCH 17/26 rbd: migrate rbd driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on rbd block driver.

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

PATCH 18/26 sheepdog: migrate sheepdog driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on sheepdog block driver.

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

PATCH 19/26 ssh: migrate ssh driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on ssh block driver.

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

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

Quoted 67 lines · Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on ssh block driver.

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

Looks good to me, ACK.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
#27 lore raw

PATCH 20/26 vdi: migrate vdi driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on vdi block driver.

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

PATCH 21/26 vhdx: migrate vhdx driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on vhdx block driver.

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

PATCH 22/26 vmdk: migrate vmdk driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on vmdk block driver.

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

PATCH 23/26 vpc: migrate vpc driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on vpc block driver.

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

PATCH 24/26 vvfat: migrate vvfat driver QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on vvfat block driver.

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

PATCH 25/26 QemuOpt: get rid of QEMUOptionParameter

In reply to Leandro Dorileo

Finally remove all the remaining QEMUOptionParameter bits.

---
 include/qemu/option.h |  40 -------
 util/qemu-option.c    | 296 --------------------------------------------------
 2 files changed, 336 deletions(-)
include/qemu/option.h +0 -40
index 62eacf3..4a7c148 100644
@@ -31,24 +31,6 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
-enum QEMUOptionParType {
-    OPT_FLAG,
-    OPT_NUMBER,
-    OPT_SIZE,
-    OPT_STRING,
-};
-
-typedef struct QEMUOptionParameter {
-    const char *name;
-    enum QEMUOptionParType type;
-    union {
-        uint64_t n;
-        char* s;
-    } value;
-    const char *help;
-    bool assigned;
-} QEMUOptionParameter;
-
 
 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
 const char *get_opt_value(char *buf, int buf_size, const char *p);
@@ -57,33 +39,11 @@ int get_next_param_value(char *buf, int buf_size,
 int get_param_value(char *buf, int buf_size,
                     const char *tag, const char *str);
 
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry->name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-    const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-    const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-    uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
-    QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
-    QEMUOptionParameter *list, QEMUOptionParameter *dest);
 void parse_option_size(const char *name, const char *value,
                        uint64_t *ret, Error **errp);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
 bool has_help_option(const char *param);
 bool is_valid_option_list(const char *param);
 
-/* ------------------------------------------------------------------ */
-
 typedef struct QemuOpt QemuOpt;
 typedef struct QemuOpts QemuOpts;
 typedef struct QemuOptsList QemuOptsList;
util/qemu-option.c +0 -296

314 lines not on this page · raw message

Signature · 1 line
1.9.0
#33 lore raw

PATCH 26/26 qemu-img: migrate QemuOptionParameter usage

In reply to Leandro Dorileo

Do the directly migration from QemuOptionParameter to QemuOpts on qemu-img.

---
 qemu-img.c | 166 +++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 95 insertions(+), 71 deletions(-)
qemu-img.c +95 -71
index 2e40cc1..1a8ce3c 100644
@@ -235,7 +235,9 @@ static int read_password(char *buf, int buf_size)
 static int print_block_option_help(const char *filename, const char *fmt)
 {
     BlockDriver *drv, *proto_drv;
-    QEMUOptionParameter *create_options = NULL;
+    QemuOptsList *proto_opts = NULL;
+    QemuOpts *opts;
+    QemuOptsList *list;
 
     /* Find driver and parse its options */
     drv = bdrv_find_format(fmt);
@@ -244,21 +246,32 @@ static int print_block_option_help(const char *filename, const char *fmt)
         return 1;
     }
 
-    create_options = append_option_parameters(create_options,
-                                              drv->create_options);
-
     if (filename) {
         proto_drv = bdrv_find_protocol(filename, true);
         if (!proto_drv) {
             error_report("Unknown protocol '%s'", filename);
             return 1;
         }
-        create_options = append_option_parameters(create_options,
-                                                  proto_drv->create_options);
+        proto_opts = proto_drv->create_options;
+    }
+
+    list = qemu_opts_append(drv->create_options, proto_opts);
+    if (!list) {
+        error_report("Could not allocate option descriptors structure");
+        return 1;
+    }
+
+    opts = qemu_opts_create(list, NULL, 0, &error_abort);
+    if (!list) {
+        error_report("Could not allocate options structure");
+        g_free(list);
+        return 1;
     }
 
-    print_option_help(create_options);
-    free_option_parameters(create_options);
+    qemu_opts_print_help(opts);
+
+    qemu_opts_del(opts);
+    g_free(list);
     return 0;
 }
 
@@ -311,22 +324,26 @@ fail:
     return NULL;
 }
 
-static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
+static int add_old_style_options(const char *fmt, QemuOpts *opts,
                                  const char *base_filename,
                                  const char *base_fmt)
 {
+    int ret;
+
     if (base_filename) {
-        if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) {
+        ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename);
+        if (ret < 0) {
             error_report("Backing file not supported for file format '%s'",
                          fmt);
-            return -1;
+            return ret;
         }
     }
     if (base_fmt) {
-        if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+        ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt);
+        if (ret < 0) {
             error_report("Backing file format not supported for file "
                          "format '%s'", fmt);
-            return -1;
+            return ret;
         }
     }
     return 0;
@@ -1153,8 +1170,8 @@ static int img_convert(int argc, char **argv)
     size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
     const uint8_t *buf1;
     BlockDriverInfo bdi;
-    QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *out_baseimg_param;
+    QemuOpts *create_options;
+    QemuOptsList *opts_list = NULL;
     char *options = NULL;
     const char *snapshot_name = NULL;
     int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
@@ -1340,72 +1357,73 @@ static int img_convert(int argc, char **argv)
         goto out;
     }
 
-    create_options = append_option_parameters(create_options,
-                                              drv->create_options);
-    create_options = append_option_parameters(create_options,
-                                              proto_drv->create_options);
+    opts_list = qemu_opts_append(drv->create_options,
+                                 proto_drv->create_options);
+    if (!opts_list) {
+        error_report("Could not allocate option descriptors structure");
+        ret = -1;
+        goto out;
+    }
+
+    create_options = qemu_opts_create(opts_list, NULL, 0, &error_abort);
+    if (!create_options) {
+        error_report("Could not allocate options structure");
+        ret = -1;
+        goto err_opts;
+    }
 
     if (options) {
-        param = parse_option_parameters(options, create_options, param);
-        if (param == NULL) {
+        ret = qemu_opts_do_parse(create_options, options, NULL);
+        if (ret < 0) {
             error_report("Invalid options for file format '%s'.", out_fmt);
-            ret = -1;
-            goto out;
+            goto err;
         }
-    } else {
-        param = parse_option_parameters("", create_options, param);
     }
 
-    set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
-    ret = add_old_style_options(out_fmt, param, out_baseimg, NULL);
+    ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE,
+                              total_sectors * 512);
     if (ret < 0) {
-        goto out;
+        goto err;
     }
 
-    /* Get backing file name if -o backing_file was used */
-    out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
-    if (out_baseimg_param) {
-        out_baseimg = out_baseimg_param->value.s;
+    ret = add_old_style_options(out_fmt, create_options, out_baseimg, NULL);
+    if (ret < 0) {
+        goto err;
     }
 
+    /* Get backing file name if -o backing_file was used */
+    out_baseimg = qemu_opt_get(create_options, BLOCK_OPT_BACKING_FILE);
+
     /* Check if compression is supported */
     if (compress) {
-        QEMUOptionParameter *encryption =
-            get_option_parameter(param, BLOCK_OPT_ENCRYPT);
-        QEMUOptionParameter *preallocation =
-            get_option_parameter(param, BLOCK_OPT_PREALLOC);
+        const char *encryption, *preallocation;
+
+        encryption = qemu_opt_get(create_options, BLOCK_OPT_ENCRYPT);
+        preallocation = qemu_opt_get(create_options, BLOCK_OPT_PREALLOC);
 
         if (!drv->bdrv_write_compressed) {
             error_report("Compression not supported for this file format");
             ret = -1;
-            goto out;
-        }
-
-        if (encryption && encryption->value.n) {
-            error_report("Compression and encryption not supported at "
-                         "the same time");
-            ret = -1;
-            goto out;
+            goto err;
         }
 
-        if (preallocation && preallocation->value.s
-            && strcmp(preallocation->value.s, "off"))
+        if (encryption && preallocation && strcmp(preallocation, "off"))
         {
             error_report("Compression and preallocation not supported at "
                          "the same time");
             ret = -1;
-            goto out;
+            goto err;
         }
     }
 
     if (!skip_create) {
         /* Create the new image */
-        ret = bdrv_create(drv, out_filename, param, &local_err);
+        ret = bdrv_create(drv, out_filename, create_options, &local_err);
         if (ret < 0) {
             error_report("%s: error while converting %s: %s",
                          out_filename, out_fmt, error_get_pretty(local_err));
             error_free(local_err);
-            goto out;
+            goto err;
         }
     }
 
@@ -1419,7 +1437,7 @@ static int img_convert(int argc, char **argv)
     out_bs = bdrv_new_open(out_filename, out_fmt, flags, true, quiet);
     if (!out_bs) {
         ret = -1;
-        goto out;
+        goto err;
     }
 
     bs_i = 0;
@@ -1442,11 +1460,11 @@ static int img_convert(int argc, char **argv)
             error_report("unable to get output image length: %s\n",
                          strerror(-output_length));
             ret = -1;
-            goto out;
+            goto err;
         } else if (output_length < total_sectors << BDRV_SECTOR_BITS) {
             error_report("output file is smaller than input file");
             ret = -1;
-            goto out;
+            goto err;
         }
     }
 
@@ -1455,7 +1473,7 @@ static int img_convert(int argc, char **argv)
     if (ret < 0) {
         if (compress) {
             error_report("could not get block driver info");
-            goto out;
+            goto err;
         }
     } else {
         cluster_sectors = bdi.cluster_size / BDRV_SECTOR_SIZE;
@@ -1465,7 +1483,7 @@ static int img_convert(int argc, char **argv)
         if (cluster_sectors <= 0 || cluster_sectors > bufsectors) {
             error_report("invalid cluster size");
             ret = -1;
-            goto out;
+            goto err;
         }
         sector_num = 0;
 
@@ -1508,7 +1526,7 @@ static int img_convert(int argc, char **argv)
                 if (ret < 0) {
                     error_report("error while reading sector %" PRId64 ": %s",
                                  bs_num, strerror(-ret));
-                    goto out;
+                    goto err;
                 }
 
                 buf2 += nlow * 512;
@@ -1523,7 +1541,7 @@ static int img_convert(int argc, char **argv)
                 if (ret != 0) {
                     error_report("error while compressing sector %" PRId64
                                  ": %s", sector_num, strerror(-ret));
-                    goto out;
+                    goto err;
                 }
             }
             sector_num += n;
@@ -1539,7 +1557,7 @@ static int img_convert(int argc, char **argv)
         if (!has_zero_init && bdrv_can_write_zeroes_with_unmap(out_bs)) {
             ret = bdrv_make_zero(out_bs, BDRV_REQ_MAY_UNMAP);
             if (ret < 0) {
-                goto out;
+                goto err;
             }
             has_zero_init = 1;
         }
@@ -1582,7 +1600,7 @@ restart:
                     error_report("error while reading block status of sector %"
                                  PRId64 ": %s", sector_num - bs_offset,
                                  strerror(-ret));
-                    goto out;
+                    goto err;
                 }
                 /* If the output image is zero initialized, we are not working
                  * on a shared base and the input is zero we can skip the next
@@ -1636,7 +1654,7 @@ restart:
             if (ret < 0) {
                 error_report("error while reading sector %" PRId64 ": %s",
                              sector_num - bs_offset, strerror(-ret));
-                goto out;
+                goto err;
             }
             /* NOTE: at the same time we convert, we do not write zero
                sectors to have a chance to compress the image. Ideally, we
@@ -1649,7 +1667,7 @@ restart:
                     if (ret < 0) {
                         error_report("error while writing sector %" PRId64
                                      ": %s", sector_num, strerror(-ret));
-                        goto out;
+                        goto err;
                     }
                 }
                 sector_num += n1;
@@ -1659,13 +1677,16 @@ restart:
             qemu_progress_print(100.0 * sectors_read / sectors_to_read, 0);
         }
     }
+
+err:
+    qemu_opts_del(create_options);
+err_opts:
+    g_free(opts_list);
 out:
     if (!ret) {
         qemu_progress_print(100, 0);
     }
     qemu_progress_end();
-    free_option_parameters(create_options);
-    free_option_parameters(param);
     qemu_vfree(buf);
     if (sn_opts) {
         qemu_opts_del(sn_opts);
@@ -2651,7 +2672,7 @@ static int img_amend(int argc, char **argv)
 {
     int c, ret = 0;
     char *options = NULL;
-    QEMUOptionParameter *create_options = NULL, *options_param = NULL;
+    QemuOpts *opts = NULL;
     const char *fmt = NULL, *filename;
     bool quiet = false;
     BlockDriverState *bs = NULL;
@@ -2721,17 +2742,21 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    create_options = append_option_parameters(create_options,
-            bs->drv->create_options);
-    options_param = parse_option_parameters(options, create_options,
-            options_param);
-    if (options_param == NULL) {
+    opts = qemu_opts_create(bs->drv->create_options, NULL, 0, &error_abort);
+    if (!opts) {
+        error_report("Could not create the options structure");
+        ret = -1;
+        goto out;
+    }
+
+    ret = qemu_opts_do_parse(opts, options, NULL);
+    if (ret < 0) {
         error_report("Invalid options for file format '%s'", fmt);
         ret = -1;
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, options_param);
+    ret = bdrv_amend_options(bs, opts);
     if (ret < 0) {
         error_report("Error while amending options: %s", strerror(-ret));
         goto out;
@@ -2741,8 +2766,7 @@ out:
     if (bs) {
         bdrv_unref(bs);
     }
-    free_option_parameters(create_options);
-    free_option_parameters(options_param);
+    qemu_opts_del(opts);
     g_free(options);
 
     if (ret) {
Signature · 1 line
1.9.0