From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: ehabkost@redhat.com, mst@redhat.com, armbru@redhat.com,
lcapitulino@redhat.com, blauwirbel@gmail.com,
aliguori@amazon.com, imammedo@redhat.com, pbonzini@redhat.com,
afaerber@suse.de
Subject: [Qemu-devel] [PATCH v3 2/3] vl: use qemu machine QOM class instead of global machines list
Date: Wed, 5 Mar 2014 19:30:46 +0200 [thread overview]
Message-ID: <1394040647-20083-3-git-send-email-marcel.a@redhat.com> (raw)
In-Reply-To: <1394040647-20083-1-git-send-email-marcel.a@redhat.com>
The machine registration flow is refactored to use the QOM functionality.
Instead of linking the machines into a list, each machine has a type
and the types can be traversed in the QOM way.
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
include/hw/boards.h | 1 +
vl.c | 75 ++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 55 insertions(+), 21 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 15df78e..7c93384 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -49,6 +49,7 @@ struct QEMUMachine {
const char *hw_version;
};
+#define TYPE_MACHINE_SUFFIX "-machine"
int qemu_register_machine(QEMUMachine *m);
QEMUMachine *find_default_machine(void);
diff --git a/vl.c b/vl.c
index 685a7a9..9fff2eb 100644
--- a/vl.c
+++ b/vl.c
@@ -1525,54 +1525,81 @@ void pcmcia_info(Monitor *mon, const QDict *qdict)
/***********************************************************/
/* machine registration */
-static QEMUMachine *first_machine = NULL;
QEMUMachine *current_machine = NULL;
+static void machine_class_init(ObjectClass *oc, void *data)
+{
+ MachineClass *mc = MACHINE_CLASS(oc);
+
+ mc->qemu_machine = data;
+}
+
int qemu_register_machine(QEMUMachine *m)
{
- QEMUMachine **pm;
- pm = &first_machine;
- while (*pm != NULL)
- pm = &(*pm)->next;
- m->next = NULL;
- *pm = m;
+ TypeInfo ti = {
+ .name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL),
+ .parent = TYPE_MACHINE,
+ .class_init = machine_class_init,
+ .class_data = (void *)m,
+ };
+
+ type_register(&ti);
+
return 0;
}
static QEMUMachine *find_machine(const char *name)
{
- QEMUMachine *m;
+ GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
+ QEMUMachine *m = NULL;
+
+ for (el = machines; el; el = el->next) {
+ MachineClass *mc = el->data;
- for(m = first_machine; m != NULL; m = m->next) {
- if (!strcmp(m->name, name))
- return m;
- if (m->alias && !strcmp(m->alias, name))
- return m;
+ if (!strcmp(mc->qemu_machine->name, name)) {
+ m = mc->qemu_machine;
+ break;
+ }
+ if (mc->qemu_machine->alias && !strcmp(mc->qemu_machine->alias, name)) {
+ m = mc->qemu_machine;
+ break;
+ }
}
- return NULL;
+
+ g_slist_free(machines);
+ return m;
}
QEMUMachine *find_default_machine(void)
{
- QEMUMachine *m;
+ GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
+ QEMUMachine *m = NULL;
- for(m = first_machine; m != NULL; m = m->next) {
- if (m->is_default) {
- return m;
+ for (el = machines; el; el = el->next) {
+ MachineClass *mc = el->data;
+
+ if (mc->qemu_machine->is_default) {
+ m = mc->qemu_machine;
+ break;
}
}
- return NULL;
+
+ g_slist_free(machines);
+ return m;
}
MachineInfoList *qmp_query_machines(Error **errp)
{
+ GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
MachineInfoList *mach_list = NULL;
QEMUMachine *m;
- for (m = first_machine; m; m = m->next) {
+ for (el = machines; el; el = el->next) {
+ MachineClass *mc = el->data;
MachineInfoList *entry;
MachineInfo *info;
+ m = mc->qemu_machine;
info = g_malloc0(sizeof(*info));
if (m->is_default) {
info->has_is_default = true;
@@ -1593,6 +1620,7 @@ MachineInfoList *qmp_query_machines(Error **errp)
mach_list = entry;
}
+ g_slist_free(machines);
return mach_list;
}
@@ -2560,6 +2588,7 @@ static int debugcon_parse(const char *devname)
static QEMUMachine *machine_parse(const char *name)
{
QEMUMachine *m, *machine = NULL;
+ GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
if (name) {
machine = find_machine(name);
@@ -2568,13 +2597,17 @@ static QEMUMachine *machine_parse(const char *name)
return machine;
}
printf("Supported machines are:\n");
- for (m = first_machine; m != NULL; m = m->next) {
+ for (el = machines; el; el = el->next) {
+ MachineClass *mc = el->data;
+ m = mc->qemu_machine;
if (m->alias) {
printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
}
printf("%-20s %s%s\n", m->name, m->desc,
m->is_default ? " (default)" : "");
}
+
+ g_slist_free(machines);
exit(!name || !is_help_option(name));
}
--
1.8.3.1
next prev parent reply other threads:[~2014-03-05 17:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-05 17:30 [Qemu-devel] [PATCH v3 0/3] qemu-machine as a QOM object Marcel Apfelbaum
2014-03-05 17:30 ` [Qemu-devel] [PATCH v3 1/3] hw/core: introduced qemu machine as " Marcel Apfelbaum
2014-03-06 22:43 ` Andreas Färber
2014-03-07 11:31 ` Andreas Färber
2014-03-05 17:30 ` Marcel Apfelbaum [this message]
2014-03-06 22:55 ` [Qemu-devel] [PATCH v3 2/3] vl: use qemu machine QOM class instead of global machines list Andreas Färber
2014-03-05 17:30 ` [Qemu-devel] [PATCH v3 3/3] hw/boards: converted current_machine to be an instance of MachineCLass Marcel Apfelbaum
2014-03-05 17:36 ` Eric Blake
2014-03-05 17:59 ` Marcel Apfelbaum
2014-03-06 23:44 ` Andreas Färber
2014-03-07 1:16 ` Alexey Kardashevskiy
2014-03-07 5:40 ` Marcel Apfelbaum
2014-03-07 5:32 ` Marcel Apfelbaum
2014-03-07 11:27 ` Andreas Färber
2014-03-07 16:22 ` Marcel Apfelbaum
2014-03-07 16:27 ` Paolo Bonzini
2014-03-07 17:30 ` Andreas Färber
2014-03-07 20:41 ` Marcel Apfelbaum
2014-03-11 15:44 ` Marcel Apfelbaum
2014-03-11 16:48 ` Andreas Färber
2014-03-11 19:28 ` Marcel Apfelbaum
2014-03-07 8:36 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394040647-20083-3-git-send-email-marcel.a@redhat.com \
--to=marcel.a@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).