[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/7] machine: machine_find_class() function
From: |
Eduardo Habkost |
Subject: |
[PATCH v2 1/7] machine: machine_find_class() function |
Date: |
Tue, 13 Oct 2020 19:04:51 -0400 |
Move find_machine() from vl.c to core/machine.c and rename it to
machine_find_class(), so it can be reused by other code.
The function won't reuse the results of the previous
object_class_get_list() call like it did in vl.c, but this
shouldn't be a problem because the function is expected to be
called only once during regular QEMU usage.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/hw/boards.h | 2 ++
hw/core/machine.c | 16 ++++++++++++++++
softmmu/vl.c | 17 +----------------
3 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index bf53e8a16e..922b710be3 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -43,6 +43,8 @@ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc,
const char *type);
MemoryRegion *machine_consume_memdev(MachineState *machine,
HostMemoryBackend *backend);
+MachineClass *machine_find_class(const char *name);
+
/**
* CPUArchId:
* @arch_id - architecture-dependent CPU ID of present or possible CPU
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 7e2f4ec08e..879a596643 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1136,6 +1136,22 @@ void machine_run_board_init(MachineState *machine)
machine_class->init(machine);
}
+MachineClass *machine_find_class(const char *name)
+{
+ g_autoptr(GSList) machines = object_class_get_list(TYPE_MACHINE, false);
+ GSList *el;
+
+ for (el = machines; el; el = el->next) {
+ MachineClass *mc = el->data;
+
+ if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+ return mc;
+ }
+ }
+
+ return NULL;
+}
+
static const TypeInfo machine_info = {
.name = TYPE_MACHINE,
.parent = TYPE_OBJECT,
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 254ee5e525..b74f377a1c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -1159,21 +1159,6 @@ static int usb_parse(const char *cmdline)
MachineState *current_machine;
-static MachineClass *find_machine(const char *name, GSList *machines)
-{
- GSList *el;
-
- for (el = machines; el; el = el->next) {
- MachineClass *mc = el->data;
-
- if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
- return mc;
- }
- }
-
- return NULL;
-}
-
static MachineClass *find_default_machine(GSList *machines)
{
GSList *el;
@@ -2341,7 +2326,7 @@ static MachineClass *machine_parse(const char *name,
GSList *machines)
exit(0);
}
- mc = find_machine(name, machines);
+ mc = machine_find_class(name);
if (!mc) {
error_report("unsupported machine type");
error_printf("Use -machine help to list supported machines\n");
--
2.28.0
- [PATCH v2 0/7] i386: Add `machine` parameter to query-cpu-definitions, Eduardo Habkost, 2020/10/13
- [PATCH v2 1/7] machine: machine_find_class() function,
Eduardo Habkost <=
- [PATCH v2 2/7] i386: Add X86CPUModel.alias_of field, Eduardo Habkost, 2020/10/13
- [PATCH v2 3/7] i386: Replace x86_cpu_class_get_alias_of() with x86_cpu_model_resolve_alias(), Eduardo Habkost, 2020/10/13
- [PATCH v2 4/7] i386: Add default_version parameter to CPU version functions, Eduardo Habkost, 2020/10/13
- [PATCH v2 5/7] i386: Wrap QMP code in !CONFIG_USER_ONLY, Eduardo Habkost, 2020/10/13
- [PATCH v2 6/7] i386: Don't use default_cpu_version inside x86_cpu_definition_entry(), Eduardo Habkost, 2020/10/13
- [PATCH v2 7/7] cpu: Add `machine` parameter to query-cpu-definitions, Eduardo Habkost, 2020/10/13