From patchwork Fri Feb 21 10:35:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 322537 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AD0482C0319 for ; Fri, 21 Feb 2014 21:47:06 +1100 (EST) Received: from localhost ([::1]:43647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGndI-0003UR-LK for incoming@patchwork.ozlabs.org; Fri, 21 Feb 2014 05:47:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGnTZ-00071G-NV 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-0001ht-Bq for qemu-devel@nongnu.org; Fri, 21 Feb 2014 05:37:01 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:53529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGnTR-0001gN-3E 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:44 -0700 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Fri, 21 Feb 2014 18:35:45 +0800 Message-Id: <1392978948-27416-23-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 22/25] vpc.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 vpc.c: replace QEMUOptionParameter with QemuOpts Signed-off-by: Dong Xu Wang Signed-off-by: Chunyan Liu --- block/vpc.c | 62 ++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 34 insertions(+), 28 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 1d326cb..4570827 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -713,12 +713,11 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size) return ret; } -static int vpc_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) { uint8_t buf[1024]; VHDFooter *footer = (VHDFooter *) buf; - QEMUOptionParameter *disk_type_param; + char *disk_type_param; int fd, i; uint16_t cyls = 0; uint8_t heads = 0; @@ -729,16 +728,16 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, int ret = -EIO; /* Read out options */ - total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n; - - disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT); - if (disk_type_param && disk_type_param->value.s) { - if (!strcmp(disk_type_param->value.s, "dynamic")) { + total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); + if (disk_type_param) { + if (!strcmp(disk_type_param, "dynamic")) { disk_type = VHD_DYNAMIC; - } else if (!strcmp(disk_type_param->value.s, "fixed")) { + } else if (!strcmp(disk_type_param, "fixed")) { disk_type = VHD_FIXED; } else { - return -EINVAL; + ret = -EINVAL; + goto out; } } else { disk_type = VHD_DYNAMIC; @@ -747,7 +746,8 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, /* Create the file */ fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd < 0) { - return -EIO; + ret = -EIO; + goto out; } /* @@ -812,8 +812,10 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, ret = create_fixed_disk(fd, buf, total_size); } - fail: +fail: qemu_close(fd); +out: + g_free(disk_type_param); return ret; } @@ -841,20 +843,24 @@ static void vpc_close(BlockDriverState *bs) error_free(s->migration_blocker); } -static QEMUOptionParameter vpc_create_options[] = { - { - .name = BLOCK_OPT_SIZE, - .type = OPT_SIZE, - .help = "Virtual disk size" - }, - { - .name = BLOCK_OPT_SUBFMT, - .type = OPT_STRING, - .help = - "Type of virtual hard disk format. Supported formats are " - "{dynamic (default) | fixed} " - }, - { NULL } +static QemuOptsList vpc_create_opts = { + .name = "vpc-create-opts", + .head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.head), + .desc = { + { + .name = BLOCK_OPT_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Virtual disk size" + }, + { + .name = BLOCK_OPT_SUBFMT, + .type = QEMU_OPT_STRING, + .help = + "Type of virtual hard disk format. Supported formats are " + "{dynamic (default) | fixed} " + }, + { /* end of list */ } + } }; static BlockDriver bdrv_vpc = { @@ -865,14 +871,14 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare = vpc_reopen_prepare, - .bdrv_create = vpc_create, + .bdrv_create2 = vpc_create, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write, .bdrv_get_info = vpc_get_info, - .create_options = vpc_create_options, + .create_opts = &vpc_create_opts, .bdrv_has_zero_init = vpc_has_zero_init, };