diff mbox

[RFC,V2,1/9] hw/core: introduced qemu machine as QOM object

Message ID 1393765632-2753-2-git-send-email-marcel.a@redhat.com
State New
Headers show

Commit Message

Marcel Apfelbaum March 2, 2014, 1:07 p.m. UTC
The main functionality change is to convert QEMUMachine into QemuMachineClass
and QEMUMachineInitArgs into QemuMachineState, instance of QemuMachineClass.

As a first step, in order to make possible an incremental developement,
both QEMUMachine and QEMUMachineInitArgs are being embeded into the
new types.

Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 hw/core/Makefile.objs |  2 +-
 hw/core/machine.c     | 38 +++++++++++++++++++++++++++++++++++++
 include/hw/boards.h   | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 hw/core/machine.c

Comments

Michael S. Tsirkin March 3, 2014, 12:56 p.m. UTC | #1
On Sun, Mar 02, 2014 at 03:07:04PM +0200, Marcel Apfelbaum wrote:
> The main functionality change is to convert QEMUMachine into QemuMachineClass
> and QEMUMachineInitArgs into QemuMachineState, instance of QemuMachineClass.
> 
> As a first step, in order to make possible an incremental developement,
> both QEMUMachine and QEMUMachineInitArgs are being embeded into the
> new types.
> 
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  hw/core/Makefile.objs |  2 +-
>  hw/core/machine.c     | 38 +++++++++++++++++++++++++++++++++++++
>  include/hw/boards.h   | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 91 insertions(+), 1 deletion(-)
>  create mode 100644 hw/core/machine.c
> 
> diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
> index 9e324be..f80c13c 100644
> --- a/hw/core/Makefile.objs
> +++ b/hw/core/Makefile.objs
> @@ -11,4 +11,4 @@ common-obj-$(CONFIG_SOFTMMU) += sysbus.o
>  common-obj-$(CONFIG_SOFTMMU) += null-machine.o
>  common-obj-$(CONFIG_SOFTMMU) += loader.o
>  common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
> -
> +common-obj-$(CONFIG_SOFTMMU) += machine.o
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> new file mode 100644
> index 0000000..2c6e1a3
> --- /dev/null
> +++ b/hw/core/machine.c
> @@ -0,0 +1,38 @@
> +/*
> + * QEMU Machine
> + *
> + * Copyright (C) 2013 Red Hat Inc
> + *
> + * Authors:
> + *   Marcel Apfelbaum <marcel.a@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "hw/boards.h"
> +
> +static void qemu_machine_initfn(Object *obj)
> +{
> +}
> +
> +static void qemu_machine_class_init(ObjectClass *oc, void *data)
> +{
> +}
> +
> +static const TypeInfo qemu_machine_info = {
> +    .name = TYPE_QEMU_MACHINE,
> +    .parent = TYPE_OBJECT,
> +    .abstract = true,
> +    .class_size = sizeof(QemuMachineClass),
> +    .class_init = qemu_machine_class_init,
> +    .instance_size = sizeof(QemuMachineState),
> +    .instance_init = qemu_machine_initfn,
> +};
> +
> +static void register_types(void)
> +{
> +    type_register_static(&qemu_machine_info);
> +}
> +
> +type_init(register_types);
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index 2151460..7b4708d 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -5,6 +5,7 @@
>  
>  #include "sysemu/blockdev.h"
>  #include "hw/qdev.h"
> +#include "qom/object.h"
>  
>  typedef struct QEMUMachine QEMUMachine;
>  
> @@ -53,4 +54,55 @@ QEMUMachine *find_default_machine(void);
>  
>  extern QEMUMachine *current_machine;
>  
> +#define TYPE_QEMU_MACHINE "machine"
> +#define QEMU_MACHINE(obj) \
> +    OBJECT_CHECK(QemuMachineState, (obj), TYPE_QEMU_MACHINE)
> +#define QEMU_MACHINE_GET_CLASS(obj) \
> +    OBJECT_GET_CLASS(QemuMachineClass, (obj), TYPE_QEMU_MACHINE)
> +#define QEMU_MACHINE_CLASS(klass) \
> +    OBJECT_CLASS_CHECK(QemuMachineClass, (klass), TYPE_QEMU_MACHINE)
> +
> +typedef struct QemuMachineState QemuMachineState;
> +typedef struct QemuMachineClass QemuMachineClass;
> +
> +/**
> + * @QemuMachineClass
> + *
> + * @parent_class: opaque parent class container
> + */
> +struct QemuMachineClass {
> +    ObjectClass parent_class;
> +
> +    QEMUMachine *qemu_machine;
> +};
> +
> +/**
> + * @QemuMachineState
> + *
> + * @parent: opaque parent object container
> + */
> +struct QemuMachineState {
> +    /* private */
> +    Object parent;
> +    /* public */
> +
> +
> +    char *accel;
> +    bool kernel_irqchip;
> +    int kvm_shadow_mem;
> +    char *kernel;
> +    char *initrd;
> +    char *append;
> +    char *dtb;
> +    char *dumpdtb;
> +    int phandle_start;
> +    char *dt_compatible;
> +    bool dump_guest_core;
> +    bool mem_merge;
> +    bool usb;
> +    char *firmware;
> +
> +    QEMUMachineInitArgs init_args;
> +};
> +
>  #endif
> -- 
> 1.8.3.1
Andreas Färber March 3, 2014, 5:49 p.m. UTC | #2
Am 02.03.2014 14:07, schrieb Marcel Apfelbaum:
> The main functionality change is to convert QEMUMachine into QemuMachineClass
> and QEMUMachineInitArgs into QemuMachineState, instance of QemuMachineClass.

I wonder why go from QEMUMachine* to QemuMachine*? I don't spot a name
clash, and keeping QEMU like we use PCI or USB would make the correct
spelling clearer.

> 
> As a first step, in order to make possible an incremental developement,

"development"

> both QEMUMachine and QEMUMachineInitArgs are being embeded into the

"embedded"

> new types.
> 
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> ---
>  hw/core/Makefile.objs |  2 +-
>  hw/core/machine.c     | 38 +++++++++++++++++++++++++++++++++++++
>  include/hw/boards.h   | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 91 insertions(+), 1 deletion(-)
>  create mode 100644 hw/core/machine.c
> 
> diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
> index 9e324be..f80c13c 100644
> --- a/hw/core/Makefile.objs
> +++ b/hw/core/Makefile.objs
> @@ -11,4 +11,4 @@ common-obj-$(CONFIG_SOFTMMU) += sysbus.o
>  common-obj-$(CONFIG_SOFTMMU) += null-machine.o
>  common-obj-$(CONFIG_SOFTMMU) += loader.o
>  common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
> -
> +common-obj-$(CONFIG_SOFTMMU) += machine.o

Cleaning up that trailing white line is good. Might it make sense to
move the new line to above null-machine.o though?

> diff --git a/hw/core/machine.c b/hw/core/machine.c
> new file mode 100644
> index 0000000..2c6e1a3
> --- /dev/null
> +++ b/hw/core/machine.c
> @@ -0,0 +1,38 @@
> +/*
> + * QEMU Machine
> + *
> + * Copyright (C) 2013 Red Hat Inc

2014?

> + *
> + * Authors:
> + *   Marcel Apfelbaum <marcel.a@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "hw/boards.h"
> +
> +static void qemu_machine_initfn(Object *obj)

My preference would be to just use machine_ prefix.

> +{
> +}
> +
> +static void qemu_machine_class_init(ObjectClass *oc, void *data)
> +{
> +}

No-op functions could be left out here and added once needed.

> +
> +static const TypeInfo qemu_machine_info = {
> +    .name = TYPE_QEMU_MACHINE,

TYPE_MACHINE?

> +    .parent = TYPE_OBJECT,
> +    .abstract = true,
> +    .class_size = sizeof(QemuMachineClass),
> +    .class_init = qemu_machine_class_init,
> +    .instance_size = sizeof(QemuMachineState),
> +    .instance_init = qemu_machine_initfn,
> +};
> +
> +static void register_types(void)

machine_register_types?

> +{
> +    type_register_static(&qemu_machine_info);
> +}
> +
> +type_init(register_types);

No semicolon needed.

> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index 2151460..7b4708d 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -5,6 +5,7 @@
>  
>  #include "sysemu/blockdev.h"
>  #include "hw/qdev.h"
> +#include "qom/object.h"
>  
>  typedef struct QEMUMachine QEMUMachine;
>  
> @@ -53,4 +54,55 @@ QEMUMachine *find_default_machine(void);
>  
>  extern QEMUMachine *current_machine;
>  
> +#define TYPE_QEMU_MACHINE "machine"
> +#define QEMU_MACHINE(obj) \
> +    OBJECT_CHECK(QemuMachineState, (obj), TYPE_QEMU_MACHINE)
> +#define QEMU_MACHINE_GET_CLASS(obj) \
> +    OBJECT_GET_CLASS(QemuMachineClass, (obj), TYPE_QEMU_MACHINE)
> +#define QEMU_MACHINE_CLASS(klass) \
> +    OBJECT_CLASS_CHECK(QemuMachineClass, (klass), TYPE_QEMU_MACHINE)
> +
> +typedef struct QemuMachineState QemuMachineState;
> +typedef struct QemuMachineClass QemuMachineClass;
> +
> +/**
> + * @QemuMachineClass
> + *
> + * @parent_class: opaque parent class container
> + */
> +struct QemuMachineClass {

/*< private >*/

> +    ObjectClass parent_class;

/*< public >*/

> +
> +    QEMUMachine *qemu_machine;
> +};
> +
> +/**
> + * @QemuMachineState
> + *
> + * @parent: opaque parent object container
> + */
> +struct QemuMachineState {
> +    /* private */
> +    Object parent;
> +    /* public */

/*< ... >*/ is the gtk-doc syntax, and parent_obj please.

> +
> +

Double white line intentional?

> +    char *accel;
> +    bool kernel_irqchip;
> +    int kvm_shadow_mem;
> +    char *kernel;
> +    char *initrd;
> +    char *append;
> +    char *dtb;
> +    char *dumpdtb;
> +    int phandle_start;
> +    char *dt_compatible;
> +    bool dump_guest_core;
> +    bool mem_merge;
> +    bool usb;
> +    char *firmware;
> +
> +    QEMUMachineInitArgs init_args;
> +};
> +
>  #endif
> 

Regards,
Andreas
Marcel Apfelbaum March 3, 2014, 7:06 p.m. UTC | #3
On Mon, 2014-03-03 at 18:49 +0100, Andreas Färber wrote:
> Am 02.03.2014 14:07, schrieb Marcel Apfelbaum:
> > The main functionality change is to convert QEMUMachine into QemuMachineClass
> > and QEMUMachineInitArgs into QemuMachineState, instance of QemuMachineClass.
> 
> I wonder why go from QEMUMachine* to QemuMachine*? I don't spot a name
> clash, and keeping QEMU like we use PCI or USB would make the correct
> spelling clearer.
Well, it was mostly a "conservative" choice, but MachineClass/MachineState
sounds great to me, I am going to replace them, thanks!
> 
> > 
> > As a first step, in order to make possible an incremental developement,
> 
> "development"
Oops
> 
> > both QEMUMachine and QEMUMachineInitArgs are being embeded into the
> 
> "embedded"
Another oops, I usually run a spelling cycle before sending,
I'll be more careful, thanks.
 
> 
> > new types.
> > 
> > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> > ---
> >  hw/core/Makefile.objs |  2 +-
> >  hw/core/machine.c     | 38 +++++++++++++++++++++++++++++++++++++
> >  include/hw/boards.h   | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 91 insertions(+), 1 deletion(-)
> >  create mode 100644 hw/core/machine.c
> > 
> > diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
> > index 9e324be..f80c13c 100644
> > --- a/hw/core/Makefile.objs
> > +++ b/hw/core/Makefile.objs
> > @@ -11,4 +11,4 @@ common-obj-$(CONFIG_SOFTMMU) += sysbus.o
> >  common-obj-$(CONFIG_SOFTMMU) += null-machine.o
> >  common-obj-$(CONFIG_SOFTMMU) += loader.o
> >  common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
> > -
> > +common-obj-$(CONFIG_SOFTMMU) += machine.o
> 
> Cleaning up that trailing white line is good. Might it make sense to
> move the new line to above null-machine.o though?
> 
> > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > new file mode 100644
> > index 0000000..2c6e1a3
> > --- /dev/null
> > +++ b/hw/core/machine.c
> > @@ -0,0 +1,38 @@
> > +/*
> > + * QEMU Machine
> > + *
> > + * Copyright (C) 2013 Red Hat Inc
> 
> 2014?
Yes it is :) , maybe I started a draft on December? I'll update, of course.

> 
> > + *
> > + * Authors:
> > + *   Marcel Apfelbaum <marcel.a@redhat.com>
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> > + * See the COPYING file in the top-level directory.
> > + */
> > +
> > +#include "hw/boards.h"
> > +
> > +static void qemu_machine_initfn(Object *obj)
> 
> My preference would be to just use machine_ prefix.
Removing the "qemu" when not necessary, sure.

> 
> > +{
> > +}
> > +
> > +static void qemu_machine_class_init(ObjectClass *oc, void *data)
> > +{
> > +}
> 
> No-op functions could be left out here and added once needed.
Go it.
> 
> > +
> > +static const TypeInfo qemu_machine_info = {
> > +    .name = TYPE_QEMU_MACHINE,
> 
> TYPE_MACHINE?
Sure, I'll replace.

> 
> > +    .parent = TYPE_OBJECT,
> > +    .abstract = true,
> > +    .class_size = sizeof(QemuMachineClass),
> > +    .class_init = qemu_machine_class_init,
> > +    .instance_size = sizeof(QemuMachineState),
> > +    .instance_init = qemu_machine_initfn,
> > +};
> > +
> > +static void register_types(void)
> 
> machine_register_types?
OK
> 
> > +{
> > +    type_register_static(&qemu_machine_info);
> > +}
> > +
> > +type_init(register_types);
> 
> No semicolon needed.
OK

> 
> > diff --git a/include/hw/boards.h b/include/hw/boards.h
> > index 2151460..7b4708d 100644
> > --- a/include/hw/boards.h
> > +++ b/include/hw/boards.h
> > @@ -5,6 +5,7 @@
> >  
> >  #include "sysemu/blockdev.h"
> >  #include "hw/qdev.h"
> > +#include "qom/object.h"
> >  
> >  typedef struct QEMUMachine QEMUMachine;
> >  
> > @@ -53,4 +54,55 @@ QEMUMachine *find_default_machine(void);
> >  
> >  extern QEMUMachine *current_machine;
> >  
> > +#define TYPE_QEMU_MACHINE "machine"
> > +#define QEMU_MACHINE(obj) \
> > +    OBJECT_CHECK(QemuMachineState, (obj), TYPE_QEMU_MACHINE)
> > +#define QEMU_MACHINE_GET_CLASS(obj) \
> > +    OBJECT_GET_CLASS(QemuMachineClass, (obj), TYPE_QEMU_MACHINE)
> > +#define QEMU_MACHINE_CLASS(klass) \
> > +    OBJECT_CLASS_CHECK(QemuMachineClass, (klass), TYPE_QEMU_MACHINE)
> > +
> > +typedef struct QemuMachineState QemuMachineState;
> > +typedef struct QemuMachineClass QemuMachineClass;
> > +
> > +/**
> > + * @QemuMachineClass
> > + *
> > + * @parent_class: opaque parent class container
> > + */
> > +struct QemuMachineClass {
> 
> /*< private >*/
> 
> > +    ObjectClass parent_class;
> 
> /*< public >*/
OK

> 
> > +
> > +    QEMUMachine *qemu_machine;
> > +};
> > +
> > +/**
> > + * @QemuMachineState
> > + *
> > + * @parent: opaque parent object container
> > + */
> > +struct QemuMachineState {
> > +    /* private */
> > +    Object parent;
> > +    /* public */
> 
> /*< ... >*/ is the gtk-doc syntax, and parent_obj please.
Sure, I've kind of took this from another QOM object, picked 
the wrong one to follow, I'll change, thanks for the tip.
> 
> > +
> > +
> 
> Double white line intentional?
Yes, prefer one? I saw this double line in a few places.

> 
> > +    char *accel;
> > +    bool kernel_irqchip;
> > +    int kvm_shadow_mem;
> > +    char *kernel;
> > +    char *initrd;
> > +    char *append;
> > +    char *dtb;
> > +    char *dumpdtb;
> > +    int phandle_start;
> > +    char *dt_compatible;
> > +    bool dump_guest_core;
> > +    bool mem_merge;
> > +    bool usb;
> > +    char *firmware;
> > +
> > +    QEMUMachineInitArgs init_args;
> > +};
> > +
> >  #endif
> > 
> 
Thanks for the thorough review!
Marcel

> Regards,
> Andreas
>
diff mbox

Patch

diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index 9e324be..f80c13c 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -11,4 +11,4 @@  common-obj-$(CONFIG_SOFTMMU) += sysbus.o
 common-obj-$(CONFIG_SOFTMMU) += null-machine.o
 common-obj-$(CONFIG_SOFTMMU) += loader.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
-
+common-obj-$(CONFIG_SOFTMMU) += machine.o
diff --git a/hw/core/machine.c b/hw/core/machine.c
new file mode 100644
index 0000000..2c6e1a3
--- /dev/null
+++ b/hw/core/machine.c
@@ -0,0 +1,38 @@ 
+/*
+ * QEMU Machine
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ *   Marcel Apfelbaum <marcel.a@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "hw/boards.h"
+
+static void qemu_machine_initfn(Object *obj)
+{
+}
+
+static void qemu_machine_class_init(ObjectClass *oc, void *data)
+{
+}
+
+static const TypeInfo qemu_machine_info = {
+    .name = TYPE_QEMU_MACHINE,
+    .parent = TYPE_OBJECT,
+    .abstract = true,
+    .class_size = sizeof(QemuMachineClass),
+    .class_init = qemu_machine_class_init,
+    .instance_size = sizeof(QemuMachineState),
+    .instance_init = qemu_machine_initfn,
+};
+
+static void register_types(void)
+{
+    type_register_static(&qemu_machine_info);
+}
+
+type_init(register_types);
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 2151460..7b4708d 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -5,6 +5,7 @@ 
 
 #include "sysemu/blockdev.h"
 #include "hw/qdev.h"
+#include "qom/object.h"
 
 typedef struct QEMUMachine QEMUMachine;
 
@@ -53,4 +54,55 @@  QEMUMachine *find_default_machine(void);
 
 extern QEMUMachine *current_machine;
 
+#define TYPE_QEMU_MACHINE "machine"
+#define QEMU_MACHINE(obj) \
+    OBJECT_CHECK(QemuMachineState, (obj), TYPE_QEMU_MACHINE)
+#define QEMU_MACHINE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(QemuMachineClass, (obj), TYPE_QEMU_MACHINE)
+#define QEMU_MACHINE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(QemuMachineClass, (klass), TYPE_QEMU_MACHINE)
+
+typedef struct QemuMachineState QemuMachineState;
+typedef struct QemuMachineClass QemuMachineClass;
+
+/**
+ * @QemuMachineClass
+ *
+ * @parent_class: opaque parent class container
+ */
+struct QemuMachineClass {
+    ObjectClass parent_class;
+
+    QEMUMachine *qemu_machine;
+};
+
+/**
+ * @QemuMachineState
+ *
+ * @parent: opaque parent object container
+ */
+struct QemuMachineState {
+    /* private */
+    Object parent;
+    /* public */
+
+
+    char *accel;
+    bool kernel_irqchip;
+    int kvm_shadow_mem;
+    char *kernel;
+    char *initrd;
+    char *append;
+    char *dtb;
+    char *dumpdtb;
+    int phandle_start;
+    char *dt_compatible;
+    bool dump_guest_core;
+    bool mem_merge;
+    bool usb;
+    char *firmware;
+
+    QEMUMachineInitArgs init_args;
+};
+
 #endif