From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, blauwirbel@gmail.com,
mdroth@linux.vnet.ibm.com, mst@redhat.com, armbru@redhat.com,
mtosatti@redhat.com, agraf@suse.de, ehabkost@redhat.com,
lcapitulino@redhat.com, peter.crosthwaite@petalogix.com,
quintela@redhat.com, imammedo@redhat.com, aliguori@amazon.com,
pbonzini@redhat.com, scottwood@freescale.com,
edgar.iglesias@gmail.com, afaerber@suse.de, rth@twiddle.net
Subject: [Qemu-devel] [PATCH RFC V2 3/9] hw/boards: converted current_machine to be an instance of QemuMachineCLass
Date: Sun, 2 Mar 2014 15:07:06 +0200 [thread overview]
Message-ID: <1393765632-2753-4-git-send-email-marcel.a@redhat.com> (raw)
In-Reply-To: <1393765632-2753-1-git-send-email-marcel.a@redhat.com>
In order to allow attaching machine options to a machine instance,
current_machine is converted into QemuMachineState.
As a first step of deprecating QEMUMachine, some of the functions
were modified to return QemuMachineCLass.
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
device-hotplug.c | 4 +++-
include/hw/boards.h | 6 ++---
qmp.c | 7 ++++--
vl.c | 69 +++++++++++++++++++++++++++++++----------------------
4 files changed, 51 insertions(+), 35 deletions(-)
diff --git a/device-hotplug.c b/device-hotplug.c
index 103d34a..fb5eb01 100644
--- a/device-hotplug.c
+++ b/device-hotplug.c
@@ -33,12 +33,14 @@ DriveInfo *add_init_drive(const char *optstr)
{
DriveInfo *dinfo;
QemuOpts *opts;
+ QemuMachineClass *machine_class;
opts = drive_def(optstr);
if (!opts)
return NULL;
- dinfo = drive_init(opts, current_machine->block_default_type);
+ machine_class = QEMU_MACHINE_GET_CLASS(current_machine);
+ dinfo = drive_init(opts, machine_class->qemu_machine->block_default_type);
if (!dinfo) {
qemu_opts_del(opts);
return NULL;
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 65e1e03..053c113 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -51,9 +51,6 @@ struct QEMUMachine {
#define TYPE_QEMU_MACHINE_PREFIX "machine-"
int qemu_register_machine(QEMUMachine *m);
-QEMUMachine *find_default_machine(void);
-
-extern QEMUMachine *current_machine;
#define TYPE_QEMU_MACHINE "machine"
#define QEMU_MACHINE(obj) \
@@ -66,6 +63,9 @@ extern QEMUMachine *current_machine;
typedef struct QemuMachineState QemuMachineState;
typedef struct QemuMachineClass QemuMachineClass;
+QemuMachineClass *find_default_machine(void);
+extern QemuMachineState *current_machine;
+
/**
* @QemuMachineClass
*
diff --git a/qmp.c b/qmp.c
index d0d98e7..df5d8d9 100644
--- a/qmp.c
+++ b/qmp.c
@@ -114,8 +114,11 @@ void qmp_cpu(int64_t index, Error **errp)
void qmp_cpu_add(int64_t id, Error **errp)
{
- if (current_machine->hot_add_cpu) {
- current_machine->hot_add_cpu(id, errp);
+ QemuMachineClass *machine_class;
+
+ machine_class = QEMU_MACHINE_GET_CLASS(current_machine);
+ if (machine_class->qemu_machine->hot_add_cpu) {
+ machine_class->qemu_machine->hot_add_cpu(id, errp);
} else {
error_setg(errp, "Not supported");
}
diff --git a/vl.c b/vl.c
index 50c880f..c4939ef 100644
--- a/vl.c
+++ b/vl.c
@@ -1529,7 +1529,7 @@ void pcmcia_info(Monitor *mon, const QDict *qdict)
/***********************************************************/
/* machine registration */
-QEMUMachine *current_machine = NULL;
+QemuMachineState *current_machine;
static void qemu_machine_class_init(ObjectClass *klass, void *data)
{
@@ -1552,44 +1552,45 @@ int qemu_register_machine(QEMUMachine *m)
return 0;
}
-static QEMUMachine *find_machine(const char *name)
+static QemuMachineClass *find_machine(const char *name)
{
GSList *el, *machines = object_class_get_list(TYPE_QEMU_MACHINE, false);
- QEMUMachine *m = NULL;
+ QemuMachineClass *k = NULL;
for (el = machines; el; el = el->next) {
- QemuMachineClass *k = el->data;
+ QemuMachineClass *temp = el->data;
- if (!strcmp(k->qemu_machine->name, name)) {
- m = k->qemu_machine;
+ if (!strcmp(temp->qemu_machine->name, name)) {
+ k = temp;
break;
}
- if (k->qemu_machine->alias && !strcmp(k->qemu_machine->alias, name)) {
- m = k->qemu_machine;
+ if (temp->qemu_machine->alias &&
+ !strcmp(temp->qemu_machine->alias, name)) {
+ k = temp;
break;
}
}
g_slist_free(machines);
- return m;
+ return k;
}
-QEMUMachine *find_default_machine(void)
+QemuMachineClass *find_default_machine(void)
{
GSList *el, *machines = object_class_get_list(TYPE_QEMU_MACHINE, false);
- QEMUMachine *m = NULL;
+ QemuMachineClass *k = NULL;
for (el = machines; el; el = el->next) {
- QemuMachineClass *k = el->data;
+ QemuMachineClass *temp = el->data;
- if (k->qemu_machine->is_default) {
- m = k->qemu_machine;
+ if (temp->qemu_machine->is_default) {
+ k = temp;
break;
}
}
g_slist_free(machines);
- return m;
+ return k;
}
MachineInfoList *qmp_query_machines(Error **errp)
@@ -1818,8 +1819,13 @@ void qemu_devices_reset(void)
void qemu_system_reset(bool report)
{
- if (current_machine && current_machine->reset) {
- current_machine->reset();
+ QemuMachineClass *machine_class;
+
+ machine_class = current_machine ? QEMU_MACHINE_GET_CLASS(current_machine)
+ : NULL;
+
+ if (machine_class && machine_class->qemu_machine->reset) {
+ machine_class->qemu_machine->reset();
} else {
qemu_devices_reset();
}
@@ -2565,21 +2571,21 @@ static int debugcon_parse(const char *devname)
return 0;
}
-static QEMUMachine *machine_parse(const char *name)
+static QemuMachineClass *machine_parse(const char *name)
{
- QEMUMachine *m, *machine = NULL;
+ QemuMachineClass *machine_class = NULL;
GSList *el, *machines = object_class_get_list(TYPE_QEMU_MACHINE, false);
if (name) {
- machine = find_machine(name);
+ machine_class = find_machine(name);
}
- if (machine) {
- return machine;
+ if (machine_class) {
+ return machine_class;
}
printf("Supported machines are:\n");
for (el = machines; el; el = el->next) {
QemuMachineClass *k = el->data;
- m = k->qemu_machine;
+ QEMUMachine *m = k->qemu_machine;
if (m->alias) {
printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
}
@@ -2836,6 +2842,7 @@ int main(int argc, char **argv, char **envp)
int optind;
const char *optarg;
const char *loadvm = NULL;
+ QemuMachineClass *machine_class;
QEMUMachine *machine;
const char *cpu_model;
const char *vga_model = "none";
@@ -2908,7 +2915,7 @@ int main(int argc, char **argv, char **envp)
os_setup_early_signal_handling();
module_call_init(MODULE_INIT_MACHINE);
- machine = find_default_machine();
+ machine_class = find_default_machine();
cpu_model = NULL;
ram_size = 0;
snapshot = 0;
@@ -2974,7 +2981,7 @@ int main(int argc, char **argv, char **envp)
}
switch(popt->index) {
case QEMU_OPTION_M:
- machine = machine_parse(optarg);
+ machine_class = machine_parse(optarg);
break;
case QEMU_OPTION_no_kvm_irqchip: {
olist = qemu_find_opts("machine");
@@ -3530,7 +3537,7 @@ int main(int argc, char **argv, char **envp)
}
optarg = qemu_opt_get(opts, "type");
if (optarg) {
- machine = machine_parse(optarg);
+ machine_class = machine_parse(optarg);
}
break;
case QEMU_OPTION_no_kvm:
@@ -3844,11 +3851,15 @@ int main(int argc, char **argv, char **envp)
}
#endif
- if (machine == NULL) {
+ if (machine_class == NULL) {
fprintf(stderr, "No machine found.\n");
exit(1);
}
+ current_machine = QEMU_MACHINE(object_new(object_class_get_name(
+ OBJECT_CLASS(machine_class))));
+
+ machine = machine_class->qemu_machine;
if (machine->hw_version) {
qemu_set_version(machine->hw_version);
}
@@ -4277,6 +4288,8 @@ int main(int argc, char **argv, char **envp)
.kernel_cmdline = kernel_cmdline,
.initrd_filename = initrd_filename,
.cpu_model = cpu_model };
+
+ current_machine->init_args = args;
machine->init(&args);
audio_init();
@@ -4285,8 +4298,6 @@ int main(int argc, char **argv, char **envp)
set_numa_modes();
- current_machine = machine;
-
/* init USB devices */
if (usb_enabled(false)) {
if (foreach_device_config(DEV_USB, usb_parse) < 0)
--
1.8.3.1
next prev parent reply other threads:[~2014-03-02 13:08 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-02 13:07 [Qemu-devel] [PATCH RFC V2 0/9] qemu-machine as a QOM object Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 1/9] hw/core: introduced qemu machine as " Marcel Apfelbaum
2014-03-03 12:56 ` Michael S. Tsirkin
2014-03-03 17:49 ` Andreas Färber
2014-03-03 19:06 ` Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 2/9] vl: use qemu machine QOM class instead of global machines list Marcel Apfelbaum
2014-03-03 12:58 ` Michael S. Tsirkin
2014-03-03 12:57 ` Paolo Bonzini
2014-03-03 13:03 ` Marcel Apfelbaum
2014-03-03 14:52 ` Andreas Färber
2014-03-03 15:05 ` Marcel Apfelbaum
2014-03-03 18:12 ` Andreas Färber
2014-03-03 19:54 ` Marcel Apfelbaum
2014-03-02 13:07 ` Marcel Apfelbaum [this message]
2014-03-03 10:49 ` [Qemu-devel] [PATCH RFC V2 3/9] hw/boards: converted current_machine to be an instance of QemuMachineCLass Paolo Bonzini
2014-03-03 12:07 ` Marcel Apfelbaum
2014-03-03 12:46 ` Paolo Bonzini
2014-03-03 12:11 ` Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 4/9] hw/machine: add qemu machine opts as properties to QemuMachineState Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 5/9] qapi: output visitor crashes qemu if it encounters a NULL value Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 6/9] vl.c: do not set 'type' property in obj_set_property Marcel Apfelbaum
2014-03-03 10:11 ` Paolo Bonzini
2014-03-03 12:09 ` Marcel Apfelbaum
2014-03-03 12:47 ` Paolo Bonzini
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 7/9] qom: add object_property_is_set Marcel Apfelbaum
2014-03-03 10:13 ` Paolo Bonzini
2014-03-03 12:09 ` Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 8/9] machine-opts: replace qemu_opt_get by QOM QemuMachine queries Marcel Apfelbaum
2014-03-03 10:11 ` Paolo Bonzini
2014-03-03 12:10 ` Marcel Apfelbaum
2014-03-02 13:07 ` [Qemu-devel] [PATCH RFC V2 9/9] hw/core: mapped QemuOpts into QEMUMachineInitArgs fields to remove duplication Marcel Apfelbaum
2014-03-03 10:13 ` Paolo Bonzini
2014-03-03 12:10 ` Marcel Apfelbaum
2014-03-03 10:50 ` [Qemu-devel] [PATCH RFC V2 0/9] qemu-machine as a QOM object Paolo Bonzini
2014-03-03 12:07 ` Marcel Apfelbaum
2014-03-03 12:56 ` Paolo Bonzini
2014-03-03 13:17 ` Marcel Apfelbaum
2014-03-03 14:10 ` Andreas Färber
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=1393765632-2753-4-git-send-email-marcel.a@redhat.com \
--to=marcel.a@redhat.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=edgar.iglesias@gmail.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@petalogix.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
--cc=scottwood@freescale.com \
/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).