From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKQQz-0005JM-B8 for qemu-devel@nongnu.org; Mon, 03 Mar 2014 05:49:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKQQq-00064s-R4 for qemu-devel@nongnu.org; Mon, 03 Mar 2014 05:49:21 -0500 Received: from mail-qg0-x22b.google.com ([2607:f8b0:400d:c04::22b]:35193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKQQq-00064j-K7 for qemu-devel@nongnu.org; Mon, 03 Mar 2014 05:49:12 -0500 Received: by mail-qg0-f43.google.com with SMTP id f51so10875091qge.2 for ; Mon, 03 Mar 2014 02:49:12 -0800 (PST) Sender: Paolo Bonzini Message-ID: <53145E21.3080803@redhat.com> Date: Mon, 03 Mar 2014 11:49:05 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1393765632-2753-1-git-send-email-marcel.a@redhat.com> <1393765632-2753-4-git-send-email-marcel.a@redhat.com> In-Reply-To: <1393765632-2753-4-git-send-email-marcel.a@redhat.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC V2 3/9] hw/boards: converted current_machine to be an instance of QemuMachineCLass List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum , 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, aliguori@amazon.com, imammedo@redhat.com, scottwood@freescale.com, edgar.iglesias@gmail.com, afaerber@suse.de, rth@twiddle.net Il 02/03/2014 14:07, Marcel Apfelbaum ha scritto: > 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. This is a relatively large change since current_machine is currently "class-like", while after your patch it is "object-like". Not a big problem, since I believe at the end of the conversion there shouldn't be a current_machine at all. Board initialization code will get it as an argument where they currently have the QEMUMachineInitArgs. The few that use current_machine before this patch can and should access the QOM tree to retrieve the current machine. ... which brings us to what is missing here: you are not adding current_machine as /machine in the QOM tree. :) Paolo > Signed-off-by: Marcel Apfelbaum > --- > 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) >