remove QEMUMachine indirection from MachineClass
cover remove QEMUMachine indirection from MachineClass
Note: this is a resend (I sent the series some time ago with no luck),
sorry if you get this series twice.
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 sugestions to get rid of QEMUMachineInitArgs.
Comments are appreciated,
Thanks,
Marcel
Marcel Apfelbaum (5):
hw/boards.h: add QEMUMachine's fields to MachineClass
machine: remove QEMUMachine indirection from MachineClass
machine: replace QEMUMachine by MachineClass in accelerator
configuration
hw/ppc: remove QEMUMachine indirection
vl.c: Remove QEMUMachine usage
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
PATCH 1/5 hw/boards.h: add QEMUMachine's fields to MachineClass
In order to eliminate the QEMUMachine indirection, add its fields directly to MachineClass. Do not remove yet qemu_machine field because it is in use already by sparpr.
--- include/hw/boards.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/hw/boards.h +23 -0
@@ -78,6 +78,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; };/**
Signature · 1 line
1.8.3.1
PATCH 2/5 machine: remove QEMUMachine indirection from MachineClass
In reply to Marcel ApfelbaumNo need to go through qemu_machine field. Use
MachineClass fields directly.
--- device-hotplug.c | 2 +- qmp.c | 4 +-- vl.c | 103 ++++++++++++++++++++++++++++++++----------------------- 3 files changed, 63 insertions(+), 46 deletions(-)
device-hotplug.c +1 -1
@@ -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 ;
qmp.c +2 -2
@@ -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 +60 -43
228 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/5 machine: replace QEMUMachine by MachineClass in accelerator configuration
In reply to Marcel ApfelbaumThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -2715,7 +2715,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 ;
@@ -2725,7 +2725,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 },
@@ -2734,7 +2734,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 ];
@@ -2761,7 +2761,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",
@@ -4188,7 +4188,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
@@ -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
@@ -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
PATCH 4/5 hw/ppc: remove QEMUMachine indirection
In reply to Marcel ApfelbaumNo need for QEMUMachine anymore because
its fields are passed to MachineClass.
--- hw/ppc/spapr.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
hw/ppc/spapr.c +11 -15
@@ -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 }, { }
Signature · 1 line
1.8.3.1
PATCH 5/5 vl.c: Remove QEMUMachine usage
In reply to Marcel ApfelbaumAll the references of QEMUMachine are already
replaced by MachineClass.
--- include/hw/boards.h | 7 +++---- vl.c | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-)
include/hw/boards.h +3 -4
@@ -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;
@@ -46,7 +48,6 @@ struct QEMUMachine {const char *default_machine_opts;const char *default_boot_order;GlobalProperty *compat_props; -struct QEMUMachine *next;const char *hw_version; };
@@ -63,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;
@@ -77,7 +77,6 @@ struct MachineClass {ObjectClass parent_class;/*< public >*/ -QEMUMachine *qemu_machine;const char *name;const char *alias;const char *desc;
vl.c +1 -2
@@ -2961,7 +2961,6 @@ int main(int argc, char **argv, char **envp)const char *optarg;const char *loadvm =NULL ;MachineClass *machine_class; -QEMUMachine *machine =NULL ;const char *cpu_model;const char *vga_model =NULL ;const char *qtest_chrdev =NULL ;
@@ -4395,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