From patchwork Fri Jun 4 19:55:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 54703 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 29035B7D59 for ; Sat, 5 Jun 2010 06:48:18 +1000 (EST) Received: from localhost ([127.0.0.1]:60372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKdVh-0004Jd-LH for incoming@patchwork.ozlabs.org; Fri, 04 Jun 2010 16:28:57 -0400 Received: from [140.186.70.92] (port=36663 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKd5K-0003rm-BQ for qemu-devel@nongnu.org; Fri, 04 Jun 2010 16:01:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKcz7-0002zo-6n for qemu-devel@nongnu.org; Fri, 04 Jun 2010 15:55:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51032) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKcz6-0002za-Sd for qemu-devel@nongnu.org; Fri, 04 Jun 2010 15:55:17 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o54JtE66007849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Jun 2010 15:55:14 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o54JtCW7006436; Fri, 4 Jun 2010 15:55:13 -0400 From: Glauber Costa To: qemu-devel@nongnu.org Date: Fri, 4 Jun 2010 16:55:11 -0300 Message-Id: <1275681311-14033-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH] introduce -machine switch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds initial support for the -machine option, that allows command line specification of machine attributes. Besides its value per-se, it is the saner way we found to allow for enabling/disabling of kvm's in-kernel irqchip. machine-related options like kernel, initrd, etc, are now accepted under this switch. Note: This is against anthony's staging. --- hw/boards.h | 4 +++ hw/pc_piix.c | 3 ++ qemu-options.hx | 14 ++++++++++ vl.c | 72 +++++++++++++++++++++++++++++++++++-------------------- 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/hw/boards.h b/hw/boards.h index 18b6b8f..bac8583 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -35,6 +35,10 @@ extern QEMUMachine *current_machine; #define COMMON_MACHINE_OPTS() \ { \ + .name = "machine", \ + .type = QEMU_OPT_STRING, \ + }, \ + { \ .name = "ram_size", \ .type = QEMU_OPT_NUMBER, \ }, \ diff --git a/hw/pc_piix.c b/hw/pc_piix.c index f01194c..3ddb695 100644 --- a/hw/pc_piix.c +++ b/hw/pc_piix.c @@ -67,6 +67,9 @@ static void pc_init1(QemuOpts *opts, int pci_enabled) vmport_init(); + if (!kernel_cmdline) + kernel_cmdline = ""; + /* allocate ram and load rom/bios */ pc_memory_init(ram_size, kernel_filename, kernel_cmdline, initrd_filename, &below_4g_mem_size, &above_4g_mem_size); diff --git a/qemu-options.hx b/qemu-options.hx index a6928b7..76ca866 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -35,6 +35,20 @@ STEXI Select the emulated @var{machine} (@code{-M ?} for list) ETEXI +DEF("machine", HAS_ARG, QEMU_OPTION_machine, + "-machine [machine=m][,ram_size=ram][,boot_device=dev]\n" + " [,kernel=vmlinux][,cmdline=kernel_cmdline][,initrd=initrd]\n" + " [,cpu=cpu_type]\n" + " pc-specific options: [,acpi=on|off]\n" + " kvm-x86 specific options: [,apic_in_kernel=on|off]\n" + " select emulated machine (-machine ? for list)\n", + QEMU_ARCH_ALL) +STEXI +@item -machine @var{machine}[,@var{option}] +@findex -machine +Select the emulated @var{machine} (@code{-machine ?} for list) +ETEXI + DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, "-cpu cpu select CPU (-cpu ? for list)\n", QEMU_ARCH_ALL) STEXI diff --git a/vl.c b/vl.c index 96b8d35..177ffe2 100644 --- a/vl.c +++ b/vl.c @@ -1605,6 +1605,16 @@ static QEMUMachine *find_machine(const char *name) if (m->alias && !strcmp(m->alias, name)) return m; } + + printf("Supported machines are:\n"); + for(m = first_machine; m != NULL; m = m->next) { + if (m->alias) + printf("%-10s %s (alias of %s)\n", + m->alias, m->desc, m->name); + printf("%-10s %s%s\n", + m->name, m->desc, + m->is_default ? " (default)" : ""); + } return NULL; } @@ -2567,7 +2577,7 @@ int main(int argc, char **argv, char **envp) DisplayState *ds; DisplayChangeListener *dcl; int cyls, heads, secs, translation; - QemuOpts *hda_opts = NULL, *opts; + QemuOpts *hda_opts = NULL, *machine_opts = NULL, *opts = NULL; int optind; const char *optarg; const char *loadvm = NULL; @@ -2697,21 +2707,29 @@ int main(int argc, char **argv, char **envp) exit(1); } switch(popt->index) { + case QEMU_OPTION_machine: { + const char *mach; + + machine_opts = qemu_opts_parse(&qemu_machine_opts, optarg, 0); + if (!machine_opts) { + fprintf(stderr, "parse error: %s\n", optarg); + exit(1); + } + mach = qemu_opt_get(machine_opts, "machine"); + + if (!mach) + break; + + machine = find_machine(mach); + + if (!machine) + exit(*mach != '?'); + break; + } case QEMU_OPTION_M: machine = find_machine(optarg); - if (!machine) { - QEMUMachine *m; - printf("Supported machines are:\n"); - for(m = first_machine; m != NULL; m = m->next) { - if (m->alias) - printf("%-10s %s (alias of %s)\n", - m->alias, m->desc, m->name); - printf("%-10s %s%s\n", - m->name, m->desc, - m->is_default ? " (default)" : ""); - } - exit(*optarg != '?'); - } + if (!machine) + exit(*optarg != '?'); break; case QEMU_OPTION_cpu: /* hw initialization will check this */ @@ -3723,47 +3741,49 @@ int main(int argc, char **argv, char **envp) } qemu_add_globals(); - opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + if (!machine_opts) + machine_opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + if (kernel_filename) { - qemu_opt_set(opts, "kernel", kernel_filename); + qemu_opt_set(machine_opts, "kernel", kernel_filename); if (kernel_cmdline) { - qemu_opt_set(opts, "cmdline", kernel_cmdline); + qemu_opt_set(machine_opts, "cmdline", kernel_cmdline); } if (initrd_filename) { - qemu_opt_set(opts, "initrd", initrd_filename); + qemu_opt_set(machine_opts, "initrd", initrd_filename); } } - qemu_opt_set(opts, "boot_device", boot_devices); + qemu_opt_set(machine_opts, "boot_device", boot_devices); if (cpu_model) { - qemu_opt_set(opts, "cpu", cpu_model); + qemu_opt_set(machine_opts, "cpu", cpu_model); } if (ram_size) { char buffer[64]; snprintf(buffer, sizeof(buffer), "%" PRId64, ram_size); - qemu_opt_set(opts, "ram_size", buffer); + qemu_opt_set(machine_opts, "ram_size", buffer); } if (acpi_enabled == 0) { - qemu_opt_set(opts, "acpi", "off"); + qemu_opt_set(machine_opts, "acpi", "off"); } if (machine->opts_desc) { - if (qemu_opts_validate(opts, machine->opts_desc) < 0) { + if (qemu_opts_validate(machine_opts, machine->opts_desc) < 0) { exit(1); } } else { - if (qemu_opts_validate(opts, common_machine_opts) < 0) { + if (qemu_opts_validate(machine_opts, common_machine_opts) < 0) { exit(1); } } - machine->init(machine, opts); + machine->init(machine, machine_opts); - qemu_opts_del(opts); + qemu_opts_del(machine_opts); cpu_synchronize_all_post_init();