diff mbox

[08/26] gluster: migrate gluster driver QemuOptionParameter usage

Message ID 1395360813-2833-9-git-send-email-l@dorileo.org
State New
Headers show

Commit Message

Leandro Dorileo March 21, 2014, 12:13 a.m. UTC
Do the directly migration from QemuOptionParameter to QemuOpts on
gluster block driver.

Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
 block/gluster.c | 68 +++++++++++++++++++++++++++++++--------------------------
 1 file changed, 37 insertions(+), 31 deletions(-)
diff mbox

Patch

diff --git a/block/gluster.c b/block/gluster.c
index a44d612..e8d966e 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -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 = {