From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDTO3-0002V1-Nz for qemu-devel@nongnu.org; Wed, 12 Feb 2014 01:33:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDTNx-0000xw-O6 for qemu-devel@nongnu.org; Wed, 12 Feb 2014 01:33:35 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:58424) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDTNx-0000xf-Dw for qemu-devel@nongnu.org; Wed, 12 Feb 2014 01:33:29 -0500 From: Chunyan Liu Date: Wed, 12 Feb 2014 14:33:12 +0800 Message-Id: <1392186806-10418-13-git-send-email-cyliu@suse.com> In-Reply-To: <1392186806-10418-1-git-send-email-cyliu@suse.com> References: <1392186806-10418-1-git-send-email-cyliu@suse.com> Subject: [Qemu-devel] [PATCH v20 12/26] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Dong Xu Wang , Chunyan Liu , stefanha@redhat.com qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img amend' Signed-off-by: Dong Xu Wang Signed-off-by: Chunyan Liu --- block.c | 4 +- block/qcow2.c | 90 ++++++++++++++++++++------------------------ include/block/block.h | 2 +- include/block/block_int.h | 2 +- qemu-img.c | 17 ++++---- 5 files changed, 53 insertions(+), 62 deletions(-) diff --git a/block.c b/block.c index 69cec2f..d6ddbd0 100644 --- a/block.c +++ b/block.c @@ -5382,12 +5382,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); } /* Used to recurse on single child block filters. diff --git a/block/qcow2.c b/block/qcow2.c index cab7097..a3afacb 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2045,65 +2045,57 @@ 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) { + /* preserve default */ + } 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; + } - 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); - } + prealloc = qemu_opt_get_del(opts, "preallocation"); + if (prealloc) { + fprintf(stderr, "Cannot change preallocation mode.\n"); + return -ENOTSUP; } + 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) { /* Upgrade */ @@ -2228,7 +2220,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 0f8cc50..5430057 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -282,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 *opts); /* external snapshots */ diff --git a/include/block/block_int.h b/include/block/block_int.h index 2acce0b..3879d46 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -229,7 +229,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 18b4ab5..c2a941d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2639,7 +2639,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; @@ -2691,17 +2692,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; @@ -2711,8 +2710,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