qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH RFC V2 3/9] hw/boards: converted current_machine


From: Marcel Apfelbaum
Subject: Re: [Qemu-devel] [PATCH RFC V2 3/9] hw/boards: converted current_machine to be an instance of QemuMachineCLass
Date: Mon, 03 Mar 2014 14:11:24 +0200

On Mon, 2014-03-03 at 11:49 +0100, Paolo Bonzini wrote:
> 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.
This is the main reason I changed from "class like" code to object,
because in the end the users will use the object returned from the query.

> 
> ... which brings us to what is missing here: you are not adding 
> current_machine as /machine in the QOM tree. :)
Is missing on purpose, I am not sure what are the consequences of changing the 
/machine
from container to an actual object. I am (almost) sure that this container has 
child
containers and I am looking for the rules: can an object act like a container?

So, I do intend of course to add it, once I have responded to the above issue.
Thanks,
Marcel
> 
> Paolo
> 
> > Signed-off-by: Marcel Apfelbaum <address@hidden>
> > ---
> >  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)
> >
> 







reply via email to

[Prev in Thread] Current Thread [Next in Thread]