From patchwork Sun Feb 7 16:24:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 8244721 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BAE2D9F1C0 for ; Sun, 7 Feb 2016 16:24:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E10F20173 for ; Sun, 7 Feb 2016 16:24:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3541420121 for ; Sun, 7 Feb 2016 16:24:33 +0000 (UTC) Received: from localhost ([::1]:36039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSS8W-0005Lh-AT for patchwork-qemu-devel@patchwork.kernel.org; Sun, 07 Feb 2016 11:24:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSS8O-0005LX-Ks for qemu-devel@nongnu.org; Sun, 07 Feb 2016 11:24:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSS8L-000757-EH for qemu-devel@nongnu.org; Sun, 07 Feb 2016 11:24:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSS8L-000753-8d; Sun, 07 Feb 2016 11:24:21 -0500 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 (Postfix) with ESMTPS id 485A48535A; Sun, 7 Feb 2016 16:24:20 +0000 (UTC) Received: from work.redhat.com (vpn1-6-221.ams2.redhat.com [10.36.6.221]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u17GOFse022655; Sun, 7 Feb 2016 11:24:16 -0500 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Sun, 7 Feb 2016 18:24:14 +0200 Message-Id: <1454862254-9089-1-git-send-email-marcel@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: marcel@redhat.com, pbonzini@redhat.com, qemu-stable@nongnu.org, armbru@redhat.com, ehabkost@redhat.com Subject: [Qemu-devel] [PATCH] vl.c: fixed regression of machine error message 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit e1ce0c3cb(vl.c: fix regression when reading machine type from config file) fixed the error message when the machine type was supplied inside the config file. However now the option name is not displayed correctly if the error happens when the machine is specified at command line. Running ./x86_64-softmmu/qemu-system-x86_64 -M q35-1.5 -redir tcp:8022::22 will result in the error message: qemu-system-x86_64: -redir tcp:8022::22: unsupported machine type Use -machine help to list supported machines Fixed it by saving the error location and also extracted the code dealing with machine options into a separate function. Reported-by: Michael S. Tsirkin Signed-off-by: Marcel Apfelbaum --- Hi, I hope I used "location" correctly, if anyone is aware of a simpler approach please advice. Thanks, Marcel vl.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/vl.c b/vl.c index f043009..f8a9213 100644 --- a/vl.c +++ b/vl.c @@ -2751,6 +2751,26 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +static void machine_set_options(Location *machine_opt_loc, + MachineClass **machine_class) +{ + const char *optarg; + Location *curr = loc_push_restore(machine_opt_loc); + + optarg = qemu_opt_get(qemu_get_machine_opts(), "type"); + if (optarg) { + *machine_class = machine_parse(optarg); + } + + if (*machine_class == NULL) { + error_report("No machine specified, and there is no default"); + error_printf("Use -machine help to list supported machines\n"); + exit(1); + } + + loc_pop(curr); +} + static int machine_set_property(void *opaque, const char *name, const char *value, Error **errp) @@ -2975,6 +2995,7 @@ int main(int argc, char **argv, char **envp) const char *optarg; const char *loadvm = NULL; MachineClass *machine_class; + Location machine_opt_loc = {0}; const char *cpu_model; const char *vga_model = NULL; const char *qtest_chrdev = NULL; @@ -3671,6 +3692,7 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_M: case QEMU_OPTION_machine: + loc_save(&machine_opt_loc); olist = qemu_find_opts("machine"); opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { @@ -4019,17 +4041,7 @@ int main(int argc, char **argv, char **envp) replay_configure(icount_opts); - opts = qemu_get_machine_opts(); - optarg = qemu_opt_get(opts, "type"); - if (optarg) { - machine_class = machine_parse(optarg); - } - - if (machine_class == NULL) { - error_report("No machine specified, and there is no default"); - error_printf("Use -machine help to list supported machines\n"); - exit(1); - } + machine_set_options(&machine_opt_loc, &machine_class); set_memory_options(&ram_slots, &maxram_size, machine_class);