hw/boards: Convert current_machine to MachineState
In order to allow attaching machine options to a machine instance, current_machine is converted into MachineState. As a first step of deprecating QEMUMachine, some of the functions were modified to return MachineClass. Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
261747f176
commit
0056ae24bc
@ -33,12 +33,14 @@ DriveInfo *add_init_drive(const char *optstr)
|
|||||||
{
|
{
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
|
MachineClass *mc;
|
||||||
|
|
||||||
opts = drive_def(optstr);
|
opts = drive_def(optstr);
|
||||||
if (!opts)
|
if (!opts)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dinfo = drive_init(opts, current_machine->block_default_type);
|
mc = MACHINE_GET_CLASS(current_machine);
|
||||||
|
dinfo = drive_init(opts, mc->qemu_machine->block_default_type);
|
||||||
if (!dinfo) {
|
if (!dinfo) {
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -53,9 +53,6 @@ struct QEMUMachine {
|
|||||||
|
|
||||||
#define TYPE_MACHINE_SUFFIX "-machine"
|
#define TYPE_MACHINE_SUFFIX "-machine"
|
||||||
int qemu_register_machine(QEMUMachine *m);
|
int qemu_register_machine(QEMUMachine *m);
|
||||||
QEMUMachine *find_default_machine(void);
|
|
||||||
|
|
||||||
extern QEMUMachine *current_machine;
|
|
||||||
|
|
||||||
#define TYPE_MACHINE "machine"
|
#define TYPE_MACHINE "machine"
|
||||||
#define MACHINE(obj) \
|
#define MACHINE(obj) \
|
||||||
@ -68,6 +65,9 @@ extern QEMUMachine *current_machine;
|
|||||||
typedef struct MachineState MachineState;
|
typedef struct MachineState MachineState;
|
||||||
typedef struct MachineClass MachineClass;
|
typedef struct MachineClass MachineClass;
|
||||||
|
|
||||||
|
MachineClass *find_default_machine(void);
|
||||||
|
extern MachineState *current_machine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MachineClass:
|
* MachineClass:
|
||||||
* @qemu_machine: #QEMUMachine
|
* @qemu_machine: #QEMUMachine
|
||||||
|
7
qmp.c
7
qmp.c
@ -114,8 +114,11 @@ void qmp_cpu(int64_t index, Error **errp)
|
|||||||
|
|
||||||
void qmp_cpu_add(int64_t id, Error **errp)
|
void qmp_cpu_add(int64_t id, Error **errp)
|
||||||
{
|
{
|
||||||
if (current_machine->hot_add_cpu) {
|
MachineClass *mc;
|
||||||
current_machine->hot_add_cpu(id, errp);
|
|
||||||
|
mc = MACHINE_GET_CLASS(current_machine);
|
||||||
|
if (mc->qemu_machine->hot_add_cpu) {
|
||||||
|
mc->qemu_machine->hot_add_cpu(id, errp);
|
||||||
} else {
|
} else {
|
||||||
error_setg(errp, "Not supported");
|
error_setg(errp, "Not supported");
|
||||||
}
|
}
|
||||||
|
72
vl.c
72
vl.c
@ -1571,7 +1571,7 @@ void pcmcia_info(Monitor *mon, const QDict *qdict)
|
|||||||
/***********************************************************/
|
/***********************************************************/
|
||||||
/* machine registration */
|
/* machine registration */
|
||||||
|
|
||||||
QEMUMachine *current_machine = NULL;
|
MachineState *current_machine;
|
||||||
|
|
||||||
static void machine_class_init(ObjectClass *oc, void *data)
|
static void machine_class_init(ObjectClass *oc, void *data)
|
||||||
{
|
{
|
||||||
@ -1594,44 +1594,45 @@ int qemu_register_machine(QEMUMachine *m)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QEMUMachine *find_machine(const char *name)
|
static MachineClass *find_machine(const char *name)
|
||||||
{
|
{
|
||||||
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
|
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
|
||||||
QEMUMachine *m = NULL;
|
MachineClass *mc = NULL;
|
||||||
|
|
||||||
for (el = machines; el; el = el->next) {
|
for (el = machines; el; el = el->next) {
|
||||||
MachineClass *mc = el->data;
|
MachineClass *temp = el->data;
|
||||||
|
|
||||||
if (!strcmp(mc->qemu_machine->name, name)) {
|
if (!strcmp(temp->qemu_machine->name, name)) {
|
||||||
m = mc->qemu_machine;
|
mc = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mc->qemu_machine->alias && !strcmp(mc->qemu_machine->alias, name)) {
|
if (temp->qemu_machine->alias &&
|
||||||
m = mc->qemu_machine;
|
!strcmp(temp->qemu_machine->alias, name)) {
|
||||||
|
mc = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free(machines);
|
g_slist_free(machines);
|
||||||
return m;
|
return mc;
|
||||||
}
|
}
|
||||||
|
|
||||||
QEMUMachine *find_default_machine(void)
|
MachineClass *find_default_machine(void)
|
||||||
{
|
{
|
||||||
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
|
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
|
||||||
QEMUMachine *m = NULL;
|
MachineClass *mc = NULL;
|
||||||
|
|
||||||
for (el = machines; el; el = el->next) {
|
for (el = machines; el; el = el->next) {
|
||||||
MachineClass *mc = el->data;
|
MachineClass *temp = el->data;
|
||||||
|
|
||||||
if (mc->qemu_machine->is_default) {
|
if (temp->qemu_machine->is_default) {
|
||||||
m = mc->qemu_machine;
|
mc = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free(machines);
|
g_slist_free(machines);
|
||||||
return m;
|
return mc;
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineInfoList *qmp_query_machines(Error **errp)
|
MachineInfoList *qmp_query_machines(Error **errp)
|
||||||
@ -1860,8 +1861,12 @@ void qemu_devices_reset(void)
|
|||||||
|
|
||||||
void qemu_system_reset(bool report)
|
void qemu_system_reset(bool report)
|
||||||
{
|
{
|
||||||
if (current_machine && current_machine->reset) {
|
MachineClass *mc;
|
||||||
current_machine->reset();
|
|
||||||
|
mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
|
||||||
|
|
||||||
|
if (mc && mc->qemu_machine->reset) {
|
||||||
|
mc->qemu_machine->reset();
|
||||||
} else {
|
} else {
|
||||||
qemu_devices_reset();
|
qemu_devices_reset();
|
||||||
}
|
}
|
||||||
@ -2633,21 +2638,21 @@ static int debugcon_parse(const char *devname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QEMUMachine *machine_parse(const char *name)
|
static MachineClass *machine_parse(const char *name)
|
||||||
{
|
{
|
||||||
QEMUMachine *m, *machine = NULL;
|
MachineClass *mc = NULL;
|
||||||
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
|
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
machine = find_machine(name);
|
mc = find_machine(name);
|
||||||
}
|
}
|
||||||
if (machine) {
|
if (mc) {
|
||||||
return machine;
|
return mc;
|
||||||
}
|
}
|
||||||
printf("Supported machines are:\n");
|
printf("Supported machines are:\n");
|
||||||
for (el = machines; el; el = el->next) {
|
for (el = machines; el; el = el->next) {
|
||||||
MachineClass *mc = el->data;
|
MachineClass *mc = el->data;
|
||||||
m = mc->qemu_machine;
|
QEMUMachine *m = mc->qemu_machine;
|
||||||
if (m->alias) {
|
if (m->alias) {
|
||||||
printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
|
printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
|
||||||
}
|
}
|
||||||
@ -2904,6 +2909,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
int optind;
|
int optind;
|
||||||
const char *optarg;
|
const char *optarg;
|
||||||
const char *loadvm = NULL;
|
const char *loadvm = NULL;
|
||||||
|
MachineClass *machine_class;
|
||||||
QEMUMachine *machine;
|
QEMUMachine *machine;
|
||||||
const char *cpu_model;
|
const char *cpu_model;
|
||||||
const char *vga_model = "none";
|
const char *vga_model = "none";
|
||||||
@ -2978,7 +2984,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
os_setup_early_signal_handling();
|
os_setup_early_signal_handling();
|
||||||
|
|
||||||
module_call_init(MODULE_INIT_MACHINE);
|
module_call_init(MODULE_INIT_MACHINE);
|
||||||
machine = find_default_machine();
|
machine_class = find_default_machine();
|
||||||
cpu_model = NULL;
|
cpu_model = NULL;
|
||||||
ram_size = 0;
|
ram_size = 0;
|
||||||
snapshot = 0;
|
snapshot = 0;
|
||||||
@ -3044,7 +3050,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
}
|
}
|
||||||
switch(popt->index) {
|
switch(popt->index) {
|
||||||
case QEMU_OPTION_M:
|
case QEMU_OPTION_M:
|
||||||
machine = machine_parse(optarg);
|
machine_class = machine_parse(optarg);
|
||||||
break;
|
break;
|
||||||
case QEMU_OPTION_no_kvm_irqchip: {
|
case QEMU_OPTION_no_kvm_irqchip: {
|
||||||
olist = qemu_find_opts("machine");
|
olist = qemu_find_opts("machine");
|
||||||
@ -3600,7 +3606,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
}
|
}
|
||||||
optarg = qemu_opt_get(opts, "type");
|
optarg = qemu_opt_get(opts, "type");
|
||||||
if (optarg) {
|
if (optarg) {
|
||||||
machine = machine_parse(optarg);
|
machine_class = machine_parse(optarg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEMU_OPTION_no_kvm:
|
case QEMU_OPTION_no_kvm:
|
||||||
@ -3906,11 +3912,17 @@ int main(int argc, char **argv, char **envp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (machine == NULL) {
|
if (machine_class == NULL) {
|
||||||
fprintf(stderr, "No machine found.\n");
|
fprintf(stderr, "No machine found.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_machine = MACHINE(object_new(object_class_get_name(
|
||||||
|
OBJECT_CLASS(machine_class))));
|
||||||
|
object_property_add_child(object_get_root(), "machine",
|
||||||
|
OBJECT(current_machine), &error_abort);
|
||||||
|
|
||||||
|
machine = machine_class->qemu_machine;
|
||||||
if (machine->hw_version) {
|
if (machine->hw_version) {
|
||||||
qemu_set_version(machine->hw_version);
|
qemu_set_version(machine->hw_version);
|
||||||
}
|
}
|
||||||
@ -4339,7 +4351,9 @@ int main(int argc, char **argv, char **envp)
|
|||||||
.kernel_cmdline = kernel_cmdline,
|
.kernel_cmdline = kernel_cmdline,
|
||||||
.initrd_filename = initrd_filename,
|
.initrd_filename = initrd_filename,
|
||||||
.cpu_model = cpu_model };
|
.cpu_model = cpu_model };
|
||||||
machine->init(&args);
|
|
||||||
|
current_machine->init_args = args;
|
||||||
|
machine->init(¤t_machine->init_args);
|
||||||
|
|
||||||
audio_init();
|
audio_init();
|
||||||
|
|
||||||
@ -4347,8 +4361,6 @@ int main(int argc, char **argv, char **envp)
|
|||||||
|
|
||||||
set_numa_modes();
|
set_numa_modes();
|
||||||
|
|
||||||
current_machine = machine;
|
|
||||||
|
|
||||||
/* init USB devices */
|
/* init USB devices */
|
||||||
if (usb_enabled(false)) {
|
if (usb_enabled(false)) {
|
||||||
if (foreach_device_config(DEV_USB, usb_parse) < 0)
|
if (foreach_device_config(DEV_USB, usb_parse) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user