From patchwork Fri Jun 4 19:54:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 104314 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o54JskFd017790 for ; Fri, 4 Jun 2010 19:54:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753533Ab0FDTyo (ORCPT ); Fri, 4 Jun 2010 15:54:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34782 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752771Ab0FDTyo (ORCPT ); Fri, 4 Jun 2010 15:54:44 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o54JshvU019060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Jun 2010 15:54:43 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o54Jsgpv015615; Fri, 4 Jun 2010 15:54:42 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: mtosatti@redhat.com Subject: [PATCH] introduce -machine switch Date: Fri, 4 Jun 2010 16:54:41 -0300 Message-Id: <1275681281-14000-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 04 Jun 2010 19:54:46 +0000 (UTC) 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();