From patchwork Fri Feb 21 10:35:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 322550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D37492C00B0 for ; Fri, 21 Feb 2014 22:26:35 +1100 (EST) Received: from localhost ([::1]:43631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGnbp-0001gN-PY for incoming@patchwork.ozlabs.org; Fri, 21 Feb 2014 05:45:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGnTZ-00070v-Gy for qemu-devel@nongnu.org; Fri, 21 Feb 2014 05:37:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGnTR-0001hi-7R for qemu-devel@nongnu.org; Fri, 21 Feb 2014 05:37:01 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:44977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGnTQ-0001gI-SV for qemu-devel@nongnu.org; Fri, 21 Feb 2014 05:36:53 -0500 Received: from localhost.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (TLS encrypted); Fri, 21 Feb 2014 03:36:40 -0700 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Fri, 21 Feb 2014 18:35:44 +0800 Message-Id: <1392978948-27416-22-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1392978948-27416-1-git-send-email-cyliu@suse.com> References: <1392978948-27416-1-git-send-email-cyliu@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 137.65.250.26 Cc: kwolf@redhat.com, Dong Xu Wang , Chunyan Liu , stefanha@redhat.com Subject: [Qemu-devel] [PATCH v21 21/25] vmdk.c: replace QEMUOptionParameter with QemuOpts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org vmdk.c: replace QEMUOptionParameter with QemuOpts Signed-off-by: Dong Xu Wang Signed-off-by: Chunyan Liu --- block/vmdk.c | 123 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 63 insertions(+), 60 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 9b6660d..95d52c3 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1641,17 +1641,16 @@ 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 *opts, Error **errp) { int idx = 0; BlockDriverState *new_bs = NULL; Error *local_err; char *desc = NULL; int64_t total_size = 0, filesize; - const char *adapter_type = NULL; - const char *backing_file = NULL; - const char *fmt = NULL; + char *adapter_type = NULL; + char *backing_file = NULL; + char *fmt = NULL; int flags = 0; int ret = 0; bool flat, split, compress; @@ -1691,24 +1690,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, 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_del(opts, BLOCK_OPT_SIZE, 0); + adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE); + backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); + if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) { + flags |= BLOCK_FLAG_COMPAT6; + } + fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); + if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) { + zeroed_grain = true; } + if (!adapter_type) { - adapter_type = "ide"; + adapter_type = g_strdup("ide"); } else if (strcmp(adapter_type, "ide") && strcmp(adapter_type, "buslogic") && strcmp(adapter_type, "lsilogic") && @@ -1724,7 +1718,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, } if (!fmt) { /* Default format to monolithicSparse */ - fmt = "monolithicSparse"; + fmt = g_strdup("monolithicSparse"); } else if (strcmp(fmt, "monolithicFlat") && strcmp(fmt, "monolithicSparse") && strcmp(fmt, "twoGbMaxExtentSparse") && @@ -1825,7 +1819,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, if (!split && !flat) { desc_offset = 0x200; } else { - ret = bdrv_create_file(filename, options, NULL, &local_err); + ret = bdrv_create_file(filename, NULL, opts, &local_err); if (ret < 0) { error_setg_errno(errp, -ret, "Could not create image file"); goto exit; @@ -1853,6 +1847,9 @@ exit: if (new_bs) { bdrv_unref(new_bs); } + g_free(adapter_type); + g_free(backing_file); + g_free(fmt); g_free(desc); g_string_free(ext_desc_lines, true); return ret; @@ -2020,41 +2017,47 @@ 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 = - "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 } +static QemuOptsList vmdk_create_opts = { + .name = "vmdk-create-opts", + .head = QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.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", + .def_value_str = "off" + }, + { + .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 = QEMU_OPT_BOOL, + .help = "Enable efficient zero writes " + "using the zeroed-grain GTE feature" + }, + { /* end of list */ } + } }; static BlockDriver bdrv_vmdk = { @@ -2068,7 +2071,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_write = vmdk_co_write, .bdrv_co_write_zeroes = vmdk_co_write_zeroes, .bdrv_close = vmdk_close, - .bdrv_create = vmdk_create, + .bdrv_create2 = vmdk_create, .bdrv_co_flush_to_disk = vmdk_co_flush, .bdrv_co_get_block_status = vmdk_co_get_block_status, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, @@ -2076,7 +2079,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_opts = &vmdk_create_opts, }; static void bdrv_vmdk_init(void)