From patchwork Thu Mar 27 13:04:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 334329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D6FAA14008A for ; Fri, 28 Mar 2014 00:05:48 +1100 (EST) Received: from localhost ([::1]:53445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTA09-00062a-U1 for incoming@patchwork.ozlabs.org; Thu, 27 Mar 2014 09:05:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WT9zO-0005ki-KG for qemu-devel@nongnu.org; Thu, 27 Mar 2014 09:05:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WT9zI-0000Rr-As for qemu-devel@nongnu.org; Thu, 27 Mar 2014 09:04:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57412) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WT9zI-0000Rh-1o for qemu-devel@nongnu.org; Thu, 27 Mar 2014 09:04:52 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2RD4oLj021255 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 27 Mar 2014 09:04:50 -0400 Received: from amosk.info.com (vpn1-112-135.nay.redhat.com [10.66.112.135]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2RD4ZFd029948; Thu, 27 Mar 2014 09:04:47 -0400 From: Amos Kong To: qemu-devel@nongnu.org Date: Thu, 27 Mar 2014 21:04:31 +0800 Message-Id: <1395925471-19841-4-git-send-email-akong@redhat.com> In-Reply-To: <1395925471-19841-1-git-send-email-akong@redhat.com> References: <1395925471-19841-1-git-send-email-akong@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, libvirt-list@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v5 for 2.0 3/3] abort QEMU if group name in option table doesn't match with defined option name 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 All the options are defined in qemu-options.hx. If we can't find a matched option definition by group name of option table, then the group name doesn't match with defined option name, it's not allowed from 2.0 Signed-off-by: Amos Kong Reviewed-by: Leandro Dorileo --- qemu-options.h | 12 ++++++++++++ util/qemu-config.c | 28 ++++++++++++++++++++++++++++ vl.c | 19 ++----------------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/qemu-options.h b/qemu-options.h index 89a009e..4024487 100644 --- a/qemu-options.h +++ b/qemu-options.h @@ -28,9 +28,21 @@ #ifndef _QEMU_OPTIONS_H_ #define _QEMU_OPTIONS_H_ +#include "sysemu/arch_init.h" + enum { #define QEMU_OPTIONS_GENERATE_ENUM #include "qemu-options-wrapper.h" }; +#define HAS_ARG 0x0001 + +typedef struct QEMUOption { + const char *name; + int flags; + int index; + uint32_t arch_mask; +} QEMUOption; + +extern const QEMUOption qemu_options[]; #endif diff --git a/util/qemu-config.c b/util/qemu-config.c index f610101..eba5428 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -6,6 +6,14 @@ #include "hw/qdev.h" #include "qapi/error.h" #include "qmp-commands.h" +#include "qemu-options.h" + +const QEMUOption qemu_options[] = { + { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, +#define QEMU_OPTIONS_GENERATE_OPTIONS +#include "qemu-options-wrapper.h" + { NULL }, +}; static QemuOptsList *vm_config_groups[32]; static QemuOptsList *drive_config_groups[4]; @@ -184,6 +192,20 @@ void qemu_add_drive_opts(QemuOptsList *list) abort(); } +/* check if the option is defined in qemu-options.hx */ +static bool opt_is_defined(const char *name) +{ + int i; + + for (i = 0; qemu_options[i].name; i++) { + if (!strcmp(qemu_options[i].name, name)) { + return true; + } + } + + return false; +} + void qemu_add_opts(QemuOptsList *list) { int entries, i; @@ -193,6 +215,12 @@ void qemu_add_opts(QemuOptsList *list) for (i = 0; i < entries; i++) { if (vm_config_groups[i] == NULL) { vm_config_groups[i] = list; + if (!opt_is_defined(list->name)) { + error_report("Didn't find a matched option definition, " + "group name (%s) of option table must match with " + "defined option name (Since 2.0)", list->name); + abort(); + } return; } } diff --git a/vl.c b/vl.c index 0464494..bd44c52 100644 --- a/vl.c +++ b/vl.c @@ -111,7 +111,6 @@ int main(int argc, char **argv) #include "trace/control.h" #include "qemu/queue.h" #include "sysemu/cpus.h" -#include "sysemu/arch_init.h" #include "qemu/osdep.h" #include "ui/qemu-spice.h" @@ -2082,22 +2081,6 @@ static void help(int exitcode) exit(exitcode); } -#define HAS_ARG 0x0001 - -typedef struct QEMUOption { - const char *name; - int flags; - int index; - uint32_t arch_mask; -} QEMUOption; - -static const QEMUOption qemu_options[] = { - { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, -#define QEMU_OPTIONS_GENERATE_OPTIONS -#include "qemu-options-wrapper.h" - { NULL }, -}; - static bool vga_available(void) { return object_class_by_name("VGA") || object_class_by_name("isa-vga"); @@ -2842,6 +2825,8 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +#undef HAS_ARG + static gpointer malloc_and_trace(gsize n_bytes) { void *ptr = malloc(n_bytes);