diff mbox

[v20,17/26] rbd.c: replace QEMUOptionParameter with QemuOpts

Message ID 1392186806-10418-18-git-send-email-cyliu@suse.com
State New
Headers show

Commit Message

Chunyan Liu Feb. 12, 2014, 6:33 a.m. UTC
rbd.c: replace QEMUOptionParameter with QemuOpts

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

Comments

Eric Blake Feb. 17, 2014, 6:57 p.m. UTC | #1
On 02/11/2014 11:33 PM, Chunyan Liu wrote:
> rbd.c: replace QEMUOptionParameter with QemuOpts
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  block/rbd.c |   63 +++++++++++++++++++++++++++++------------------------------
>  1 files changed, 31 insertions(+), 32 deletions(-)
> 

> +    objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
> +    if (objsize) {
> +        if ((objsize - 1) & objsize) {    /* not a power of 2? */
> +            error_report("obj size needs to be power of 2");
> +            return -EINVAL;
> +        }
> +        if (objsize < 4096) {
> +            error_report("obj size too small");
> +            return -EINVAL;
>          }

> +        {
> +            .name = BLOCK_OPT_CLUSTER_SIZE,
> +            .type = QEMU_OPT_SIZE,
> +            .help = "RBD object size",
> +            .def_value_str = stringify(0),

Do we really want to list a default of 0, given that the code behaves
the same as if 0 had been specified or if the argument had been omitted?
 Passing 0 doesn't really mean using a cluster size of 0, which makes
listing it as an explicit default would look odd.

> -    .create_options     = qemu_rbd_create_options,
> +    .create_opts        = qemu_rbd_create_opts,

Hmm, I've noticed that your series is inconsistent on whether it uses '=
foo_opts' or '= &foo_opts' in these initializers (for example, 15/26
used & even though nothing else did, 16/26 uses & but all other
initializers were also using &, and in this 17/26 nothing is using &).
Not that it matters to the compiler, but there's a lot to be said for
consistency.
Chunyan Liu Feb. 18, 2014, 5:56 a.m. UTC | #2
2014-02-18 2:57 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 02/11/2014 11:33 PM, Chunyan Liu wrote:
> > rbd.c: replace QEMUOptionParameter with QemuOpts
> >
> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  block/rbd.c |   63
> +++++++++++++++++++++++++++++------------------------------
> >  1 files changed, 31 insertions(+), 32 deletions(-)
> >
>
> > +    objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
> > +    if (objsize) {
> > +        if ((objsize - 1) & objsize) {    /* not a power of 2? */
> > +            error_report("obj size needs to be power of 2");
> > +            return -EINVAL;
> > +        }
> > +        if (objsize < 4096) {
> > +            error_report("obj size too small");
> > +            return -EINVAL;
> >          }
>
> > +        {
> > +            .name = BLOCK_OPT_CLUSTER_SIZE,
> > +            .type = QEMU_OPT_SIZE,
> > +            .help = "RBD object size",
> > +            .def_value_str = stringify(0),
>
> Do we really want to list a default of 0, given that the code behaves
> the same as if 0 had been specified or if the argument had been omitted?
>  Passing 0 doesn't really mean using a cluster size of 0, which makes
> listing it as an explicit default would look odd.
>
> Inherited from old patches. Not necessary in fact. Will remove that.


> > -    .create_options     = qemu_rbd_create_options,
> > +    .create_opts        = qemu_rbd_create_opts,
>
> Hmm, I've noticed that your series is inconsistent on whether it uses '=
> foo_opts' or '= &foo_opts' in these initializers (for example, 15/26
> used & even though nothing else did, 16/26 uses & but all other
> initializers were also using &, and in this 17/26 nothing is using &).
> Not that it matters to the compiler, but there's a lot to be said for
> consistency.
>
>
Sorry, will correct that.


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

Patch

diff --git a/block/rbd.c b/block/rbd.c
index 121fae2..b23fe7b 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -282,7 +282,7 @@  static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
     return ret;
 }
 
-static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
+static int qemu_rbd_create(const char *filename, QemuOpts *opts,
                            Error **errp)
 {
     int64_t bytes = 0;
@@ -306,24 +306,18 @@  static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
     }
 
     /* Read out options */
-    while (options && options->name) {
-        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-            bytes = options->value.n;
-        } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-            if (options->value.n) {
-                objsize = options->value.n;
-                if ((objsize - 1) & objsize) {    /* not a power of 2? */
-                    error_report("obj size needs to be power of 2");
-                    return -EINVAL;
-                }
-                if (objsize < 4096) {
-                    error_report("obj size too small");
-                    return -EINVAL;
-                }
-                obj_order = ffs(objsize) - 1;
-            }
+    bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+    objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
+    if (objsize) {
+        if ((objsize - 1) & objsize) {    /* not a power of 2? */
+            error_report("obj size needs to be power of 2");
+            return -EINVAL;
+        }
+        if (objsize < 4096) {
+            error_report("obj size too small");
+            return -EINVAL;
         }
-        options++;
+        obj_order = ffs(objsize) - 1;
     }
 
     clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
@@ -900,18 +894,23 @@  static BlockDriverAIOCB* qemu_rbd_aio_discard(BlockDriverState *bs,
 }
 #endif
 
-static QEMUOptionParameter qemu_rbd_create_options[] = {
-    {
-     .name = BLOCK_OPT_SIZE,
-     .type = OPT_SIZE,
-     .help = "Virtual disk size"
-    },
-    {
-     .name = BLOCK_OPT_CLUSTER_SIZE,
-     .type = OPT_SIZE,
-     .help = "RBD object size"
-    },
-    {NULL}
+static QemuOptsList qemu_rbd_create_opts = {
+    .name = "rbd-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        {
+            .name = BLOCK_OPT_CLUSTER_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "RBD object size",
+            .def_value_str = stringify(0),
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_rbd = {
@@ -920,10 +919,10 @@  static BlockDriver bdrv_rbd = {
     .bdrv_needs_filename = true,
     .bdrv_file_open     = qemu_rbd_open,
     .bdrv_close         = qemu_rbd_close,
-    .bdrv_create        = qemu_rbd_create,
+    .bdrv_create2       = qemu_rbd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_get_info      = qemu_rbd_getinfo,
-    .create_options     = qemu_rbd_create_options,
+    .create_opts        = qemu_rbd_create_opts,
     .bdrv_getlength     = qemu_rbd_getlength,
     .bdrv_truncate      = qemu_rbd_truncate,
     .protocol_name      = "rbd",