From patchwork Wed May 7 09:54:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 346484 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 62782140216 for ; Wed, 7 May 2014 20:07:52 +1000 (EST) Received: from localhost ([::1]:39904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhylR-0006M2-U1 for incoming@patchwork.ozlabs.org; Wed, 07 May 2014 06:07:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhyZX-0003LD-Ly for qemu-devel@nongnu.org; Wed, 07 May 2014 05:55:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhyZR-0002Xf-DI for qemu-devel@nongnu.org; Wed, 07 May 2014 05:55:31 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:36256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhyZR-0002XT-29 for qemu-devel@nongnu.org; Wed, 07 May 2014 05:55:25 -0400 Received: from linux-cyliu.lab.bej.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (NOT encrypted); Wed, 07 May 2014 03:55:11 -0600 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Wed, 7 May 2014 17:54:16 +0800 Message-Id: <1399456476-10786-14-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1399456476-10786-1-git-send-email-cyliu@suse.com> References: <1399456476-10786-1-git-send-email-cyliu@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.26 Cc: l@dorileo.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v27 13/33] vvfat.c: handle cross_driver's create_options and create_opts 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 vvfat shares create options of qcow driver. To avoid vvfat breaking when qcow driver changes from QEMUOptionParameter to QemuOpts, let it able to handle both cases. Signed-off-by: Chunyan Liu --- Change: * Fix memory free: - qemu_opts_free(create_opts); + if (bdrv_qcow->create_options) { + qemu_opts_free(create_opts); + } block/vvfat.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 155fc9b..41fe623 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2906,8 +2906,9 @@ static BlockDriver vvfat_write_target = { static int enable_write_target(BDRVVVFATState *s) { - BlockDriver *bdrv_qcow; - QEMUOptionParameter *options; + BlockDriver *bdrv_qcow = NULL; + QemuOptsList *create_opts = NULL; + QemuOpts *opts = NULL; Error *local_err = NULL; int ret; int size = sector2cluster(s, s->sector_count); @@ -2922,11 +2923,17 @@ static int enable_write_target(BDRVVVFATState *s) } bdrv_qcow = bdrv_find_format("qcow"); - options = parse_option_parameters("", bdrv_qcow->create_options, NULL); - set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512); - set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:"); + assert(!(bdrv_qcow->create_opts && bdrv_qcow->create_options)); + if (bdrv_qcow->create_options) { + create_opts = params_to_opts(bdrv_qcow->create_options); + } else { + create_opts = bdrv_qcow->create_opts; + } + opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512); + qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:"); - ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err); + ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err); if (ret < 0) { qerror_report_err(local_err); error_free(local_err); @@ -2955,6 +2962,10 @@ static int enable_write_target(BDRVVVFATState *s) return 0; err: + qemu_opts_del(opts); + if (bdrv_qcow->create_options) { + qemu_opts_free(create_opts); + } g_free(s->qcow_filename); s->qcow_filename = NULL; return ret;