From patchwork Fri Jul 6 09:31:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 169392 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 937BE2C0203 for ; Fri, 6 Jul 2012 19:38:01 +1000 (EST) Received: from localhost ([::1]:44656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn4z9-0004T6-DN for incoming@patchwork.ozlabs.org; Fri, 06 Jul 2012 05:37:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn4yr-0004Ou-3C for qemu-devel@nongnu.org; Fri, 06 Jul 2012 05:37:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sn4yn-00028H-Dh for qemu-devel@nongnu.org; Fri, 06 Jul 2012 05:37:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64721) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn4yn-00027m-6R for qemu-devel@nongnu.org; Fri, 06 Jul 2012 05:37:37 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q669bRDU026983 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Jul 2012 05:37:28 -0400 Received: from amd-6168-8-1.englab.nay.redhat.com (amd-6168-8-1.englab.nay.redhat.com [10.66.104.52]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q669bHTD022903; Fri, 6 Jul 2012 05:37:23 -0400 From: Jason Wang To: krkumar2@in.ibm.com, habanero@linux.vnet.ibm.com, aliguori@us.ibm.com, rusty@rustcorp.com.au, mst@redhat.com, mashirle@us.ibm.com, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, tahm@linux.vnet.ibm.com, jwhan@filewood.snu.ac.kr, akong@redhat.com Date: Fri, 6 Jul 2012 17:31:06 +0800 Message-Id: <1341567070-14136-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1341567070-14136-1-git-send-email-jasowang@redhat.com> References: <1341567070-14136-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Jason Wang , kvm@vger.kernel.org Subject: [Qemu-devel] [RFC V3 1/5] option: introduce qemu_get_opt_all() 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 Sometimes, we need to pass option like -netdev tap,fd=100,fd=101,fd=102 which can not be properly parsed by qemu_find_opt() because it only returns the first matched option. So qemu_get_opt_all() were introduced to return an array of pointers which contains all matched option. Signed-off-by: Jason Wang --- qemu-option.c | 19 +++++++++++++++++++ qemu-option.h | 2 ++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index bb3886c..9263125 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -545,6 +545,25 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) return NULL; } +int qemu_opt_get_all(QemuOpts *opts, const char *name, const char **optp, + int max) +{ + QemuOpt *opt; + int index = 0; + + QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) { + if (strcmp(opt->name, name) == 0) { + if (index < max) { + optp[index++] = opt->str; + } + if (index == max) { + break; + } + } + } + return index; +} + const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); diff --git a/qemu-option.h b/qemu-option.h index 951dec3..3c9a273 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -106,6 +106,8 @@ struct QemuOptsList { QemuOptDesc desc[]; }; +int qemu_opt_get_all(QemuOpts *opts, const char *name, const char **optp, + int max); const char *qemu_opt_get(QemuOpts *opts, const char *name); bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);