From patchwork Mon Aug 6 02:18:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 175235 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 19BA62C007C for ; Mon, 6 Aug 2012 12:19:29 +1000 (EST) Received: from localhost ([::1]:58722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyCul-0002v2-5s for incoming@patchwork.ozlabs.org; Sun, 05 Aug 2012 22:19:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyCuW-0002Qg-AR for qemu-devel@nongnu.org; Sun, 05 Aug 2012 22:19:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SyCuV-0001li-Bh for qemu-devel@nongnu.org; Sun, 05 Aug 2012 22:19:12 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:55339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyCuV-0001le-5Z for qemu-devel@nongnu.org; Sun, 05 Aug 2012 22:19:11 -0400 Received: by pbbro12 with SMTP id ro12so4516331pbb.4 for ; Sun, 05 Aug 2012 19:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=RavnaEnRfWWp0aYhy2G0cGfDS06FUdTcVMPfdpcGG5g=; b=wfRB61nVzOBkgnjp12olxofCR9Skb3aVlUUP60z7646QCOO91CUu8idlavizLUAHch Qf0WiTyB81WtAfP9Sxcxm79ahVyTUH4EmxjiWLisjStg/2XLch1zLqfKuzorhI0eo340 /Nhmrw/1zJc71mNhDefEi2KsuZEfHCXXCU2hqpY7vSHZmgA0zuQOXSqecxmRKSdC/ISd +Y0waaGYEy5nCcKX15sjJ63tx3BwPh9zs2nBZmwW18gqGq+qBZAwa0vK5KwdrrTirYds 3TQKs9W0+TtQgNQv/pEyjRjNx4nq1wQQNkDnVRR8QO/C/D4c6AnOb/DfYtMs5b17dWpV YkxQ== Received: by 10.68.195.197 with SMTP id ig5mr15251082pbc.137.1344219550529; Sun, 05 Aug 2012 19:19:10 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id qo8sm1291456pbb.19.2012.08.05.19.19.07 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 05 Aug 2012 19:19:09 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Mon, 6 Aug 2012 10:18:42 +0800 Message-Id: <1344219522-11873-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V2] qemu-img: use QemuOpts instead of QEMUOptionParameter in resize function 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 Signed-off-by: Dong Xu Wang Reviewed-by: Stefan Hajnoczi --- v1->v2: fix param leak. qemu-img.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 80cfb9b..36e1c77 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1567,14 +1567,19 @@ static int img_resize(int argc, char **argv) const char *filename, *fmt, *size; int64_t n, total_size; BlockDriverState *bs = NULL; - QEMUOptionParameter *param; - QEMUOptionParameter resize_options[] = { - { - .name = BLOCK_OPT_SIZE, - .type = OPT_SIZE, - .help = "Virtual disk size" + QemuOpts *param; + static QemuOptsList resize_options = { + .name = "resize_options", + .head = QTAILQ_HEAD_INITIALIZER(resize_options.head), + .desc = { + { + .name = BLOCK_OPT_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Virtual disk size" + }, { + /* end of list */ + } }, - { NULL } }; /* Remove size from argv manually so that negative numbers are not treated @@ -1624,14 +1629,15 @@ static int img_resize(int argc, char **argv) } /* Parse size */ - param = parse_option_parameters("", resize_options, NULL); - if (set_option_parameter(param, BLOCK_OPT_SIZE, size)) { + param = qemu_opts_create(&resize_options, NULL, 0, NULL); + if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) { /* Error message already printed when size parsing fails */ ret = -1; + qemu_opts_del(param); goto out; } - n = get_option_parameter(param, BLOCK_OPT_SIZE)->value.n; - free_option_parameters(param); + n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0); + qemu_opts_del(param); bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR); if (!bs) {