From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNqPm-00082u-9U for qemu-devel@nongnu.org; Wed, 12 Mar 2014 17:10:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNqPf-0008Uo-Al for qemu-devel@nongnu.org; Wed, 12 Mar 2014 17:10:14 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45524 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNqPe-0008SW-Tc for qemu-devel@nongnu.org; Wed, 12 Mar 2014 17:10:07 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 12 Mar 2014 22:09:47 +0100 Message-Id: <1394658603-13650-16-git-send-email-afaerber@suse.de> In-Reply-To: <1394658603-13650-1-git-send-email-afaerber@suse.de> References: <1394658603-13650-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0-rc0 15/31] vl: Use MachineClass instead of global QEMUMachine list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori , Marcel Apfelbaum From: Marcel Apfelbaum 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 Signed-off-by: Marcel Apfelbaum Signed-off-by: Andreas F=C3=A4rber --- 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 1259010..f9c035f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -51,6 +51,7 @@ struct QEMUMachine { const char *hw_version; }; =20 +#define TYPE_MACHINE_SUFFIX "-machine" int qemu_register_machine(QEMUMachine *m); QEMUMachine *find_default_machine(void); =20 diff --git a/vl.c b/vl.c index bca5c95..9e86be4 100644 --- a/vl.c +++ b/vl.c @@ -1571,54 +1571,81 @@ void pcmcia_info(Monitor *mon, const QDict *qdict= ) /***********************************************************/ /* machine registration */ =20 -static QEMUMachine *first_machine =3D NULL; QEMUMachine *current_machine =3D NULL; =20 +static void machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->qemu_machine =3D data; +} + int qemu_register_machine(QEMUMachine *m) { - QEMUMachine **pm; - pm =3D &first_machine; - while (*pm !=3D NULL) - pm =3D &(*pm)->next; - m->next =3D NULL; - *pm =3D m; + TypeInfo ti =3D { + .name =3D g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL), + .parent =3D TYPE_MACHINE, + .class_init =3D machine_class_init, + .class_data =3D (void *)m, + }; + + type_register(&ti); + return 0; } =20 static QEMUMachine *find_machine(const char *name) { - QEMUMachine *m; + GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false)= ; + QEMUMachine *m =3D NULL; + + for (el =3D machines; el; el =3D el->next) { + MachineClass *mc =3D el->data; =20 - for(m =3D first_machine; m !=3D NULL; m =3D 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 =3D mc->qemu_machine; + break; + } + if (mc->qemu_machine->alias && !strcmp(mc->qemu_machine->alias, = name)) { + m =3D mc->qemu_machine; + break; + } } - return NULL; + + g_slist_free(machines); + return m; } =20 QEMUMachine *find_default_machine(void) { - QEMUMachine *m; + GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false)= ; + QEMUMachine *m =3D NULL; =20 - for(m =3D first_machine; m !=3D NULL; m =3D m->next) { - if (m->is_default) { - return m; + for (el =3D machines; el; el =3D el->next) { + MachineClass *mc =3D el->data; + + if (mc->qemu_machine->is_default) { + m =3D mc->qemu_machine; + break; } } - return NULL; + + g_slist_free(machines); + return m; } =20 MachineInfoList *qmp_query_machines(Error **errp) { + GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false)= ; MachineInfoList *mach_list =3D NULL; QEMUMachine *m; =20 - for (m =3D first_machine; m; m =3D m->next) { + for (el =3D machines; el; el =3D el->next) { + MachineClass *mc =3D el->data; MachineInfoList *entry; MachineInfo *info; =20 + m =3D mc->qemu_machine; info =3D g_malloc0(sizeof(*info)); if (m->is_default) { info->has_is_default =3D true; @@ -1639,6 +1666,7 @@ MachineInfoList *qmp_query_machines(Error **errp) mach_list =3D entry; } =20 + g_slist_free(machines); return mach_list; } =20 @@ -2608,6 +2636,7 @@ static int debugcon_parse(const char *devname) static QEMUMachine *machine_parse(const char *name) { QEMUMachine *m, *machine =3D NULL; + GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false)= ; =20 if (name) { machine =3D find_machine(name); @@ -2616,13 +2645,17 @@ static QEMUMachine *machine_parse(const char *nam= e) return machine; } printf("Supported machines are:\n"); - for (m =3D first_machine; m !=3D NULL; m =3D m->next) { + for (el =3D machines; el; el =3D el->next) { + MachineClass *mc =3D el->data; + m =3D mc->qemu_machine; if (m->alias) { printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->nam= e); } printf("%-20s %s%s\n", m->name, m->desc, m->is_default ? " (default)" : ""); } + + g_slist_free(machines); exit(!name || !is_help_option(name)); } =20 --=20 1.8.4.5