Generalize -machine command line option

-machine somehow suggests that it selects the machine, but it doesn't.
Fix that before this command is set in stone.

Actually, -machine should supersede -M and allow to introduce arbitrary
per-machine options to the command line. That will change the internal
realization again, but we will be able to keep the user interface
stable.

Tested-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Jan Kiszka 2011-07-23 12:38:37 +02:00 committed by Anthony Liguori
parent 7006b9cff3
commit 9052ea6bf4
3 changed files with 46 additions and 22 deletions

View File

@ -464,9 +464,14 @@ QemuOptsList qemu_option_rom_opts = {
static QemuOptsList qemu_machine_opts = { static QemuOptsList qemu_machine_opts = {
.name = "machine", .name = "machine",
.implied_opt_name = "type",
.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
.desc = { .desc = {
{ {
.name = "type",
.type = QEMU_OPT_STRING,
.help = "emulated machine"
}, {
.name = "accel", .name = "accel",
.type = QEMU_OPT_STRING, .type = QEMU_OPT_STRING,
.help = "accelerator list", .help = "accelerator list",

View File

@ -2075,13 +2075,23 @@ if KVM support is enabled when compiling.
ETEXI ETEXI
DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
"-machine accel=accel1[:accel2] use an accelerator (kvm,xen,tcg), default is tcg\n", QEMU_ARCH_ALL) "-machine [type=]name[,prop[=value][,...]]\n"
" selects emulated machine (-machine ? for list)\n"
" property accel=accel1[:accel2[:...]] selects accelerator\n"
" supported accelerators are kvm, xen, tcg (default: tcg)\n",
QEMU_ARCH_ALL)
STEXI STEXI
@item -machine accel=@var{accels} @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@findex -machine @findex -machine
This is use to enable an accelerator, in kvm,xen,tcg. Select the emulated machine by @var{name}. Use @code{-machine ?} to list
By default, it use only tcg. If there a more than one accelerator available machines. Supported machine properties are:
specified, the next one is used if the first don't work. @table @option
@item accel=@var{accels1}[:@var{accels2}[:...]]
This is used to enable an accelerator. Depending on the target architecture,
kvm, xen, or tcg can be available. By default, tcg is used. If there is more
than one accelerator specified, the next one is used if the previous one fails
to initialize.
@end table
ETEXI ETEXI
DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid, DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid,

43
vl.c
View File

@ -1899,6 +1899,27 @@ static int debugcon_parse(const char *devname)
return 0; return 0;
} }
static QEMUMachine *machine_parse(const char *name)
{
QEMUMachine *m, *machine = NULL;
if (name) {
machine = find_machine(name);
}
if (machine) {
return machine;
}
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(!name || *name != '?');
}
static int tcg_init(void) static int tcg_init(void)
{ {
return 0; return 0;
@ -2155,20 +2176,7 @@ int main(int argc, char **argv, char **envp)
} }
switch(popt->index) { switch(popt->index) {
case QEMU_OPTION_M: case QEMU_OPTION_M:
machine = find_machine(optarg); machine = machine_parse(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 != '?');
}
break; break;
case QEMU_OPTION_cpu: case QEMU_OPTION_cpu:
/* hw initialization will check this */ /* hw initialization will check this */
@ -2698,11 +2706,12 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_machine: case QEMU_OPTION_machine:
olist = qemu_find_opts("machine"); olist = qemu_find_opts("machine");
qemu_opts_reset(olist); qemu_opts_reset(olist);
opts = qemu_opts_parse(olist, optarg, 0); opts = qemu_opts_parse(olist, optarg, 1);
if (!opts) { if (!opts) {
fprintf(stderr, "parse error: %s\n", optarg); fprintf(stderr, "parse error: %s\n", optarg);
exit(1); exit(1);
} }
machine = machine_parse(qemu_opt_get(opts, "type"));
break; break;
case QEMU_OPTION_usb: case QEMU_OPTION_usb:
usb_enabled = 1; usb_enabled = 1;
@ -2976,8 +2985,8 @@ int main(int argc, char **argv, char **envp)
p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel"); p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
} }
if (p == NULL) { if (p == NULL) {
opts = qemu_opts_parse(qemu_find_opts("machine"), qemu_opts_reset(list);
machine->default_machine_opts, 0); opts = qemu_opts_parse(list, machine->default_machine_opts, 0);
if (!opts) { if (!opts) {
fprintf(stderr, "parse error for machine %s: %s\n", fprintf(stderr, "parse error for machine %s: %s\n",
machine->name, machine->default_machine_opts); machine->name, machine->default_machine_opts);