Skip to contentSkip to conversation

remove QEMUMachine indirection from MachineClass

PATCH New Marcel Apfelbaum 1 participant 6 messages Apr 9, 2014

lore
Share & tools
lore
#0 lore raw

v3 cover remove QEMUMachine indirection from MachineClass

Cc Andreas Färber <[email protected]>

V2 -> V3:
- Addressed Andreas's comments:
- Dropped QEMUMachineInitArgs's 'next' obsoleted field in a separate patch
- Revision the separation into patches:
- Started using MachineClass for .machine early (3/5).
- Merged hw/ppc changes with QEMUMachine indirection removal
- Ensured that git bisect is not affected
- Rebased to master.

V1 -> V2:
- Addressed Paolo's comments:
- replaced commas by semicolons on patch 4/5.
- Rebased to master.

This is a continuation of 'QEMU Machine as QOM object' effort.
The scope of this series is to allow machine QOM-ification
of all machines gradually, by removing the need for QEMUMachine registration through vl.c .

Now we will have 2 paths:
1. Non QOM-ified machines will be converted to QOM on the fly in vl.c by qemu machine registration.
2. QOM-ified machines will behave as regular QOM classes setting MachineClass fields in class_init.
- Patch 4/5 demonstrates this.

Next steps:
- Replace QemuOpts queries by MachineState fields.
- Follow Paolo's suggestions to get rid of QEMUMachineInitArgs.

Comments are appreciated,

Thanks,
Marcel

Marcel Apfelbaum (5):
hw/boards.h: remove obsoleted field from QEMUMachine vl.c: copy QEMUMachine's fields to MachineClass
vl.c: Replace QEMUMachine with MachineClass in QEMUMachineInitArgs
machine: replace QEMUMachine by MachineClass in accelerator
configuration
machine: remove QEMUMachine indirection from MachineClass

 device-hotplug.c        |   2 +-
 hw/ppc/spapr.c          |  26 +++++------
 include/hw/boards.h     |  30 +++++++++++--
 include/hw/xen/xen.h    |   2 +-
 include/qemu/typedefs.h |   1 +
 include/sysemu/kvm.h    |   2 +-
 include/sysemu/qtest.h  |   2 +-
 kvm-all.c               |   6 +--
 kvm-stub.c              |   2 +-
 qmp.c                   |   4 +-
 qtest.c                 |   2 +-
 vl.c                    | 114 +++++++++++++++++++++++++++---------------------
 xen-all.c               |   2 +-
 xen-stub.c              |   2 +-
 14 files changed, 116 insertions(+), 81 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/5 hw/boards.h: remove obsoleted field from QEMUMachine

This field shouldn't be used any more since we
adopted the QOM way of iterating over the types.

The commit that obsoleted it is:
commit 261747f176f6f2d88f8268aaebfdd1a1afe887e2
vl: Use MachineClass instead of global QEMUMachine list

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.

---
 include/hw/boards.h | 1 -
 1 file changed, 1 deletion(-)
include/hw/boards.h +0 -1
index dd2c70d..aaaa871 100644
@@ -46,7 +46,6 @@ struct QEMUMachine {
     const char *default_machine_opts;
     const char *default_boot_order;
     GlobalProperty *compat_props;
-    struct QEMUMachine *next;
     const char *hw_version;
 };
 
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v3 2/5 vl.c: copy QEMUMachine's fields to MachineClass

In reply to Marcel Apfelbaum

In order to eliminate the QEMUMachine indirection, add its fields directly to MachineClass. Do not remove yet qemu_machine field because it is still in use by sparpr.

---
 include/hw/boards.h | 23 +++++++++++++++++++++++
 vl.c                | 23 +++++++++++++++++++++++
 2 files changed, 46 insertions(+)
include/hw/boards.h +23 -0
index aaaa871..138346d 100644
@@ -77,6 +77,29 @@ struct MachineClass {
     /*< public >*/
 
     QEMUMachine *qemu_machine;
+    const char *name;
+    const char *alias;
+    const char *desc;
+
+    void (*init)(QEMUMachineInitArgs *args);
+    void (*reset)(void);
+    void (*hot_add_cpu)(const int64_t id, Error **errp);
+    int (*kvm_type)(const char *arg);
+
+    BlockInterfaceType block_default_type;
+    int max_cpus;
+    unsigned int no_serial:1,
+        no_parallel:1,
+        use_virtcon:1,
+        use_sclp:1,
+        no_floppy:1,
+        no_cdrom:1,
+        no_sdcard:1;
+    int is_default;
+    const char *default_machine_opts;
+    const char *default_boot_order;
+    GlobalProperty *compat_props;
+    const char *hw_version;
 };
 
 /**
vl.c +23 -0
index 9975e5a..0b0202d 100644
@@ -1583,8 +1583,31 @@ MachineState *current_machine;
 static void machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    QEMUMachine *qm = data;
 
     mc->qemu_machine = data;
+
+    mc->name = qm->name;
+    mc->alias = qm->alias;
+    mc->desc = qm->desc;
+    mc->init = qm->init;
+    mc->reset = qm->reset;
+    mc->hot_add_cpu = qm->hot_add_cpu;
+    mc->kvm_type = qm->kvm_type;
+    mc->block_default_type = qm->block_default_type;
+    mc->max_cpus = qm->max_cpus;
+    mc->no_serial = qm->no_serial;
+    mc->no_parallel = qm->no_parallel;
+    mc->use_virtcon = qm->use_virtcon;
+    mc->use_sclp = qm->use_sclp;
+    mc->no_floppy = qm->no_floppy;
+    mc->no_cdrom = qm->no_cdrom;
+    mc->no_sdcard = qm->no_sdcard;
+    mc->is_default = qm->is_default;
+    mc->default_machine_opts = qm->default_machine_opts;
+    mc->default_boot_order = qm->default_boot_order;
+    mc->compat_props = qm->compat_props;
+    mc->hw_version = qm->hw_version;
 }
 
 int qemu_register_machine(QEMUMachine *m)
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v3 3/5 vl.c: Replace QEMUMachine with MachineClass in QEMUMachineInitArgs

In reply to Marcel Apfelbaum

QEMUMachine's fields are already in MachineClass. We can safely make the switch because we copy them in machine_class_init.

---
 include/hw/boards.h | 5 +++--
 vl.c                | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
include/hw/boards.h +3 -2
index 138346d..51211a6 100644
@@ -7,8 +7,10 @@
 #include "hw/qdev.h"
 #include "qom/object.h"
 
+typedef struct MachineClass MachineClass;
+
 typedef struct QEMUMachineInitArgs {
-    const QEMUMachine *machine;
+    const MachineClass *machine;
     ram_addr_t ram_size;
     const char *boot_order;
     const char *kernel_filename;
@@ -62,7 +64,6 @@ int qemu_register_machine(QEMUMachine *m);
     OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE)
 
 typedef struct MachineState MachineState;
-typedef struct MachineClass MachineClass;
 
 MachineClass *find_default_machine(void);
 extern MachineState *current_machine;
vl.c +1 -1
index 0b0202d..dc8d515 100644
@@ -4394,7 +4394,7 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
+    QEMUMachineInitArgs args = { .machine = machine_class,
                                  .ram_size = ram_size,
                                  .boot_order = boot_order,
                                  .kernel_filename = kernel_filename,
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v3 4/5 machine: replace QEMUMachine by MachineClass in accelerator configuration

In reply to Marcel Apfelbaum

This minimizes QEMUMachine usage, as part of machine QOM-ification.

---
 include/hw/xen/xen.h    |  2 +-
 include/qemu/typedefs.h |  1 +
 include/sysemu/kvm.h    |  2 +-
 include/sysemu/qtest.h  |  2 +-
 kvm-all.c               |  6 +++---
 kvm-stub.c              |  2 +-
 qtest.c                 |  2 +-
 vl.c                    | 10 +++++-----
 xen-all.c               |  2 +-
 xen-stub.c              |  2 +-
 10 files changed, 16 insertions(+), 15 deletions(-)
include/hw/xen/xen.h +1 -1
index 9d549fc..85fda3d 100644
@@ -36,7 +36,7 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
-int xen_init(QEMUMachine *machine);
+int xen_init(MachineClass *mc);
 int xen_hvm_init(MemoryRegion **ram_memory);
 void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
include/qemu/typedefs.h +1 -0
index bf8daac..86bab12 100644
@@ -31,6 +31,7 @@ typedef struct MemoryListener MemoryListener;
 typedef struct MemoryMappingList MemoryMappingList;
 
 typedef struct QEMUMachine QEMUMachine;
+typedef struct MachineClass MachineClass;
 typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
include/sysemu/kvm.h +1 -1
index 0bee1e8..518655c 100644
@@ -152,7 +152,7 @@ extern KVMState *kvm_state;
 
 /* external API */
 
-int kvm_init(QEMUMachine *machine);
+int kvm_init(MachineClass *mc);
 
 int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
include/sysemu/qtest.h +1 -1
index 224131f..95c9ade 100644
@@ -26,7 +26,7 @@ static inline bool qtest_enabled(void)
 
 bool qtest_driver(void);
 
-int qtest_init_accel(QEMUMachine *machine);
+int qtest_init_accel(MachineClass *mc);
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
 
 static inline int qtest_available(void)
kvm-all.c +3 -3
index cd4111d..1bb979d 100644
@@ -1341,7 +1341,7 @@ static int kvm_max_vcpus(KVMState *s)
     return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-int kvm_init(QEMUMachine *machine)
+int kvm_init(MachineClass *mc)
 {
     static const char upgrade_note[] =
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
@@ -1433,8 +1433,8 @@ int kvm_init(QEMUMachine *machine)
     }
 
     kvm_type = qemu_opt_get(qemu_get_machine_opts(), "kvm-type");
-    if (machine->kvm_type) {
-        type = machine->kvm_type(kvm_type);
+    if (mc->kvm_type) {
+        type = mc->kvm_type(kvm_type);
     } else if (kvm_type) {
         fprintf(stderr, "Invalid argument kvm-type=%s\n", kvm_type);
         goto err;
kvm-stub.c +1 -1
index ccdba62..8acda86 100644
@@ -34,7 +34,7 @@ int kvm_init_vcpu(CPUState *cpu)
     return -ENOSYS;
 }
 
-int kvm_init(QEMUMachine *machine)
+int kvm_init(MachineClass *mc)
 {
     return -ENOSYS;
 }
qtest.c +1 -1
index 0ac9f42..2aba20d 100644
@@ -500,7 +500,7 @@ static void qtest_event(void *opaque, int event)
     }
 }
 
-int qtest_init_accel(QEMUMachine *machine)
+int qtest_init_accel(MachineClass *mc)
 {
     configure_icount("0");
 
vl.c +5 -5
index dc8d515..5119937 100644
@@ -2720,7 +2720,7 @@ static MachineClass *machine_parse(const char *name)
     exit(!name || !is_help_option(name));
 }
 
-static int tcg_init(QEMUMachine *machine)
+static int tcg_init(MachineClass *mc)
 {
     tcg_exec_init(tcg_tb_size * 1024 * 1024);
     return 0;
@@ -2730,7 +2730,7 @@ static struct {
     const char *opt_name;
     const char *name;
     int (*available)(void);
-    int (*init)(QEMUMachine *);
+    int (*init)(MachineClass *mc);
     bool *allowed;
 } accel_list[] = {
     { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
@@ -2739,7 +2739,7 @@ static struct {
     { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
 };
 
-static int configure_accelerator(QEMUMachine *machine)
+static int configure_accelerator(MachineClass *mc)
 {
     const char *p;
     char buf[10];
@@ -2766,7 +2766,7 @@ static int configure_accelerator(QEMUMachine *machine)
                     continue;
                 }
                 *(accel_list[i].allowed) = true;
-                ret = accel_list[i].init(machine);
+                ret = accel_list[i].init(mc);
                 if (ret < 0) {
                     init_failed = true;
                     fprintf(stderr, "failed to initialize %s: %s\n",
@@ -4187,7 +4187,7 @@ int main(int argc, char **argv, char **envp)
         exit(0);
     }
 
-    configure_accelerator(machine);
+    configure_accelerator(machine_class);
 
     if (qtest_chrdev) {
         Error *local_err = NULL;
xen-all.c +1 -1
index ba34739..a63b531 100644
@@ -1001,7 +1001,7 @@ static void xen_exit_notifier(Notifier *n, void *data)
     xs_daemon_close(state->xenstore);
 }
 
-int xen_init(QEMUMachine *machine)
+int xen_init(MachineClass *mc)
 {
     xen_xc = xen_xc_interface_open(0, 0, 0);
     if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
xen-stub.c +1 -1
index 59927cb..de26583 100644
@@ -47,7 +47,7 @@ qemu_irq *xen_interrupt_controller_init(void)
     return NULL;
 }
 
-int xen_init(QEMUMachine *machine)
+int xen_init(MachineClass *mc)
 {
     return -ENOSYS;
 }
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v3 5/5 machine: remove QEMUMachine indirection from MachineClass

In reply to Marcel Apfelbaum

No need to go through qemu_machine field. Use
MachineClass fields directly.

---
 device-hotplug.c    |  2 +-
 hw/ppc/spapr.c      | 26 ++++++++----------
 include/hw/boards.h |  1 -
 qmp.c               |  4 +--
 vl.c                | 79 ++++++++++++++++++++++++-----------------------------
 5 files changed, 50 insertions(+), 62 deletions(-)
device-hotplug.c +1 -1
index ebfa6b1..eecb08e 100644
@@ -40,7 +40,7 @@ DriveInfo *add_init_drive(const char *optstr)
         return NULL;
 
     mc = MACHINE_GET_CLASS(current_machine);
-    dinfo = drive_init(opts, mc->qemu_machine->block_default_type);
+    dinfo = drive_init(opts, mc->block_default_type);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
hw/ppc/spapr.c +11 -15
index a11e121..b4ce950 100644
@@ -1419,19 +1419,6 @@ static int spapr_kvm_type(const char *vm_type)
     exit(1);
 }
 
-static QEMUMachine spapr_machine = {
-    .name = "pseries",
-    .desc = "pSeries Logical Partition (PAPR compliant)",
-    .is_default = 1,
-    .init = ppc_spapr_init,
-    .reset = ppc_spapr_reset,
-    .block_default_type = IF_SCSI,
-    .max_cpus = MAX_CPUS,
-    .no_parallel = 1,
-    .default_boot_order = NULL,
-    .kvm_type = spapr_kvm_type,
-};
-
 /*
  * Implementation of an interface to adjust firmware patch
  * for the bootindex property handling.
@@ -1494,7 +1481,17 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
     MachineClass *mc = MACHINE_CLASS(oc);
     FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
 
-    mc->qemu_machine = data;
+    mc->name = "pseries";
+    mc->desc = "pSeries Logical Partition (PAPR compliant)";
+    mc->is_default = 1;
+    mc->init = ppc_spapr_init;
+    mc->reset = ppc_spapr_reset;
+    mc->block_default_type = IF_SCSI;
+    mc->max_cpus = MAX_CPUS;
+    mc->no_parallel = 1;
+    mc->default_boot_order = NULL;
+    mc->kvm_type = spapr_kvm_type;
+
     fwc->get_dev_path = spapr_get_fw_dev_path;
 }
 
@@ -1502,7 +1499,6 @@ static const TypeInfo spapr_machine_info = {
     .name          = TYPE_SPAPR_MACHINE,
     .parent        = TYPE_MACHINE,
     .class_init    = spapr_machine_class_init,
-    .class_data    = &spapr_machine,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_FW_PATH_PROVIDER },
         { }
include/hw/boards.h +0 -1
index 51211a6..66ee98a 100644
@@ -77,7 +77,6 @@ struct MachineClass {
     ObjectClass parent_class;
     /*< public >*/
 
-    QEMUMachine *qemu_machine;
     const char *name;
     const char *alias;
     const char *desc;
qmp.c +2 -2
index 87a28f7..26eb589 100644
@@ -117,8 +117,8 @@ void qmp_cpu_add(int64_t id, Error **errp)
     MachineClass *mc;
 
     mc = MACHINE_GET_CLASS(current_machine);
-    if (mc->qemu_machine->hot_add_cpu) {
-        mc->qemu_machine->hot_add_cpu(id, errp);
+    if (mc->hot_add_cpu) {
+        mc->hot_add_cpu(id, errp);
     } else {
         error_setg(errp, "Not supported");
     }
vl.c +36 -43

204 lines not on this page · raw message

Signature · 1 line
1.8.3.1