qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuO


From: Chunyan Liu
Subject: [Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options
Date: Mon, 20 Jan 2014 22:19:54 +0800

qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img amend'

Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Chunyan Liu <address@hidden>
---
 block.c                   |    4 +-
 block/qcow2.c             |   88 ++++++++++++++++++++-------------------------
 include/block/block.h     |    2 +-
 include/block/block_int.h |    2 +-
 qemu-img.c                |   17 ++++-----
 5 files changed, 51 insertions(+), 62 deletions(-)

diff --git a/block.c b/block.c
index 0dc0b09..8c490c6 100644
--- a/block.c
+++ b/block.c
@@ -5000,12 +5000,12 @@ void bdrv_add_before_write_notifier(BlockDriverState 
*bs,
     notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
 }
 
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts)
 {
     if (bs->drv->bdrv_amend_options == NULL) {
         return -ENOTSUP;
     }
-    return bs->drv->bdrv_amend_options(bs, options);
+    return bs->drv->bdrv_amend_options(bs, opts);
 }
 
 ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs)
diff --git a/block/qcow2.c b/block/qcow2.c
index b7a2e3f..580bc93 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2057,64 +2057,54 @@ static int qcow2_downgrade(BlockDriverState *bs, int 
target_version)
 }
 
 static int qcow2_amend_options(BlockDriverState *bs,
-                               QEMUOptionParameter *options)
+                               QemuOpts *opts)
 {
     BDRVQcowState *s = bs->opaque;
     int old_version = s->qcow_version, new_version = old_version;
     uint64_t new_size = 0;
     const char *backing_file = NULL, *backing_format = NULL;
     bool lazy_refcounts = s->use_lazy_refcounts;
+    const char *compat, *prealloc;
+    uint64_t cluster_size = s->cluster_size;
+    bool encrypt;
     int ret;
-    int i;
 
-    for (i = 0; options[i].name; i++)
-    {
-        if (!options[i].assigned) {
-            /* only change explicitly defined options */
-            continue;
-        }
+    compat = qemu_opt_get_del(opts, "compat");
+    if (!compat) {
+    } else if (!strcmp(compat, "0.10")) {
+        new_version = 2;
+    } else if (!strcmp(compat, "1.1")) {
+        new_version = 3;
+    } else {
+        fprintf(stderr, "Unknown compatibility level %s.\n", compat);
+        return -EINVAL;
+    }
+    
+    prealloc = qemu_opt_get_del(opts, "preallocation");
+    if (prealloc) {
+        fprintf(stderr, "Cannot change preallocation mode.\n");
+        return -ENOTSUP;
+    }
 
-        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;
-        } else {
-            /* if this assertion fails, this probably means a new option was
-             * added without having it covered here */
-            assert(false);
-        }
+    new_size = qemu_opt_get_size_del(opts, "size", 0);
+    backing_file = qemu_opt_get_del(opts, "backing_file");
+    backing_format = qemu_opt_get_del(opts, "backing_fmt");
+
+    encrypt = qemu_opt_get_bool_del(opts, "encryption", s->crypt_method);
+    if (encrypt != !!s->crypt_method) {
+        fprintf(stderr, "Changing the encryption flag is not "
+                "supported.\n");
+        return -ENOTSUP;
+    }
+
+    cluster_size = qemu_opt_get_size_del(opts, "cluster_size", cluster_size);
+    if (cluster_size != s->cluster_size) {
+        fprintf(stderr, "Changing the cluster size is not "
+                "supported.\n");
+        return -ENOTSUP;
     }
+    
+    lazy_refcounts = qemu_opt_get_bool_del(opts, "lazy_refcounts", 
lazy_refcounts);
 
     if (new_version != old_version) {
         if (new_version > old_version) {
@@ -2240,7 +2230,7 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
-    .bdrv_create2       = qcow2_create,
+    .bdrv_create2        = qcow2_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = qcow2_co_get_block_status,
     .bdrv_set_key       = qcow2_set_key,
diff --git a/include/block/block.h b/include/block/block.h
index 687d423..e23a7da 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -278,7 +278,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 *opts);
 
 /* external snapshots */
 
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f0043f8..f5bdd08 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -216,7 +216,7 @@ struct BlockDriver {
         BdrvCheckMode fix);
 
     int (*bdrv_amend_options)(BlockDriverState *bs,
-        QEMUOptionParameter *options);
+        QemuOpts *opts);
 
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
diff --git a/qemu-img.c b/qemu-img.c
index 05052d9..863bd03 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2692,7 +2692,8 @@ static int img_amend(int argc, char **argv)
 {
     int c, ret = 0;
     char *options = NULL;
-    QEMUOptionParameter *create_options = NULL, *options_param = NULL;
+    QemuOptsList *create_opts = NULL;
+    QemuOpts *opts = NULL;
     const char *fmt = NULL, *filename;
     bool quiet = false;
     BlockDriverState *bs = NULL;
@@ -2744,17 +2745,15 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    create_options = append_option_parameters(create_options,
-            bs->drv->create_options);
-    options_param = parse_option_parameters(options, create_options,
-            options_param);
-    if (options_param == NULL) {
+    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    if (options && qemu_opts_do_parse(opts, options, NULL)) {
         error_report("Invalid options for file format '%s'", fmt);
         ret = -1;
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, options_param);
+    ret = bdrv_amend_options(bs, opts);
     if (ret < 0) {
         error_report("Error while amending options: %s", strerror(-ret));
         goto out;
@@ -2764,8 +2763,8 @@ out:
     if (bs) {
         bdrv_unref(bs);
     }
-    free_option_parameters(create_options);
-    free_option_parameters(options_param);
+    qemu_opts_del(opts);
+    qemu_opts_free(create_opts);
     if (ret) {
         return 1;
     }
-- 
1.6.0.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]