From patchwork Mon Mar 19 15:09:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 147547 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 E3C4BB6EE7 for ; Tue, 20 Mar 2012 02:10:08 +1100 (EST) Received: from localhost ([::1]:45183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9eDm-0003oo-Gs for incoming@patchwork.ozlabs.org; Mon, 19 Mar 2012 11:10:06 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9eDX-0003mP-If for qemu-devel@nongnu.org; Mon, 19 Mar 2012 11:09:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9eDD-0000Jd-F6 for qemu-devel@nongnu.org; Mon, 19 Mar 2012 11:09:51 -0400 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:47524 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9eDD-0000JL-76 for qemu-devel@nongnu.org; Mon, 19 Mar 2012 11:09:31 -0400 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id q2JF9TII030942; Mon, 19 Mar 2012 10:09:29 -0500 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q2JF9Tas030941; Mon, 19 Mar 2012 10:09:29 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2012 10:09:19 -0500 Message-Id: <1332169763-30665-6-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1332169763-30665-1-git-send-email-aliguori@us.ibm.com> References: <1332169763-30665-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Anthony Liguori , Eric Blake , Eduardo Habkost , Gerd Hoffman Subject: [Qemu-devel] [PATCH 5/9] vl: enable system configuration to be used 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 Now that we have options grouped, allow the [system] section to be used to set these options. Signed-off-by: Anthony Liguori --- vl.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 53 insertions(+), 9 deletions(-) diff --git a/vl.c b/vl.c index 9a7ad40..5e86311 100644 --- a/vl.c +++ b/vl.c @@ -2187,6 +2187,24 @@ static void qemu_run_machine_init_done_notifiers(void) notifier_list_notify(&machine_init_done_notifiers, NULL); } +static const QEMUOption *find_opt_by_name(const char *name) +{ + const QEMUOption *popt; + + popt = qemu_options; + for(;;) { + if (!popt->name) { + break; + } + if (!strcmp(popt->name, name)) { + return popt; + } + popt++; + } + + return NULL; +} + static const QEMUOption *lookup_opt(int argc, char **argv, const char **poptarg, int *poptind) { @@ -2200,15 +2218,10 @@ static const QEMUOption *lookup_opt(int argc, char **argv, /* Treat --foo the same as -foo. */ if (r[1] == '-') r++; - popt = qemu_options; - for(;;) { - if (!popt->name) { - error_report("invalid option"); - exit(1); - } - if (!strcmp(popt->name, r + 1)) - break; - popt++; + popt = find_opt_by_name(r + 1); + if (popt == NULL) { + error_report("invalid option"); + exit(1); } if (popt->flags & HAS_ARG) { if (optind >= argc) { @@ -2273,6 +2286,35 @@ typedef struct QemuOptions int defconfig; } QemuOptions; +static void qemu_parse_option(int index, const char *optarg, QemuOptions *options); + +static int qemu_parse_system_option(const char *name, const char *value, void *opaque) +{ + QemuOptions *options = opaque; + const QEMUOption *popt; + + popt = find_opt_by_name(name); + if (popt == NULL) { + return -1; + } + + qemu_parse_option(popt->index, value, options); + + return 0; +} + +static int qemu_parse_system_section(QemuOpts *opts, void *opaque) +{ + QemuOptions *options = opaque; + + return qemu_opt_foreach(opts, qemu_parse_system_option, options, 0); +} + +static void qemu_parse_system_sections(QemuOptions *options) +{ + qemu_opts_foreach(qemu_find_opts("system"), qemu_parse_system_section, options, 1); +} + static void qemu_parse_option(int index, const char *optarg, QemuOptions *options) { QemuOpts *opts; @@ -3143,6 +3185,8 @@ static void qemu_parse_options(int argc, char **argv, QemuOptions *options) qemu_parse_option(popt->index, optarg, options); } } + + qemu_parse_system_sections(options); } int main(int argc, char **argv, char **envp)