From patchwork Mon Jun 25 10:04:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 167024 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 D66CAB6FA1 for ; Mon, 25 Jun 2012 20:10:42 +1000 (EST) Received: from localhost ([::1]:40516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sj6Fk-0002eq-CY for incoming@patchwork.ozlabs.org; Mon, 25 Jun 2012 06:10:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sj6FY-0002YO-Bx for qemu-devel@nongnu.org; Mon, 25 Jun 2012 06:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sj6FT-00031q-KF for qemu-devel@nongnu.org; Mon, 25 Jun 2012 06:10:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sj6FT-00031g-CJ for qemu-devel@nongnu.org; Mon, 25 Jun 2012 06:10:23 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5PAAEQD001279 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Jun 2012 06:10:14 -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-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q5PAA9U2003133; Mon, 25 Jun 2012 06:10:09 -0400 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 From: Jason Wang Date: Mon, 25 Jun 2012 18:04:14 +0800 Message-ID: <20120625100414.8096.38155.stgit@amd-6168-8-1.englab.nay.redhat.com> In-Reply-To: <20120625095059.8096.49429.stgit@amd-6168-8-1.englab.nay.redhat.com> References: <20120625095059.8096.49429.stgit@amd-6168-8-1.englab.nay.redhat.com> User-Agent: StGit/0.16-1-g60c4 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC V2 PATCH 1/4] 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);