diff mbox

[1/4] machine: Register TYPE_MACHINE properties as class properties

Message ID 1476394002-8392-2-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost Oct. 13, 2016, 9:26 p.m. UTC
When doing the conversion, the NULL errp arguments on the
property registration calls were changed to &error_abort.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/machine.c | 206 ++++++++++++++++++++++++++----------------------------
 1 file changed, 98 insertions(+), 108 deletions(-)

Comments

Igor Mammedov Oct. 14, 2016, 1:08 p.m. UTC | #1
On Thu, 13 Oct 2016 18:26:39 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> When doing the conversion, the NULL errp arguments on the
> property registration calls were changed to &error_abort.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
So many property registrations look pretty ugly but still
better than doing it per instance, not that it matters
so far as there is only 1 instance of Machine at a time.

So
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

most of the properties below are dumb field setter/getter,
it would be much better to declare them statically and
make generic Object code to initialize them at type
initialization time.
i.e. make similar thing like static properties but for class
and probably extend it to have optional custom setter/getter.

> ---
>  hw/core/machine.c | 206 ++++++++++++++++++++++++++----------------------------
>  1 file changed, 98 insertions(+), 108 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index afd84ac..b0fd91f 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -364,6 +364,104 @@ static void machine_class_init(ObjectClass *oc, void *data)
>      /* Default 128 MB as guest ram size */
>      mc->default_ram_size = 128 * M_BYTE;
>      mc->rom_file_has_mr = true;
> +
> +    object_class_property_add_str(oc, "accel",
> +        machine_get_accel, machine_set_accel, &error_abort);
> +    object_class_property_set_description(oc, "accel",
> +        "Accelerator list", &error_abort);
> +
> +    object_class_property_add(oc, "kernel-irqchip", "OnOffSplit",
> +        NULL, machine_set_kernel_irqchip,
> +        NULL, NULL, &error_abort);
> +    object_class_property_set_description(oc, "kernel-irqchip",
> +        "Configure KVM in-kernel irqchip", &error_abort);
> +
> +    object_class_property_add(oc, "kvm-shadow-mem", "int",
> +        machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
> +        NULL, NULL, &error_abort);
> +    object_class_property_set_description(oc, "kvm-shadow-mem",
> +        "KVM shadow MMU size", &error_abort);
> +
> +    object_class_property_add_str(oc, "kernel",
> +        machine_get_kernel, machine_set_kernel, &error_abort);
> +    object_class_property_set_description(oc, "kernel",
> +        "Linux kernel image file", &error_abort);
> +
> +    object_class_property_add_str(oc, "initrd",
> +        machine_get_initrd, machine_set_initrd, &error_abort);
> +    object_class_property_set_description(oc, "initrd",
> +        "Linux initial ramdisk file", &error_abort);
> +
> +    object_class_property_add_str(oc, "append",
> +        machine_get_append, machine_set_append, &error_abort);
> +    object_class_property_set_description(oc, "append",
> +        "Linux kernel command line", &error_abort);
> +
> +    object_class_property_add_str(oc, "dtb",
> +        machine_get_dtb, machine_set_dtb, &error_abort);
> +    object_class_property_set_description(oc, "dtb",
> +        "Linux kernel device tree file", &error_abort);
> +
> +    object_class_property_add_str(oc, "dumpdtb",
> +        machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
> +    object_class_property_set_description(oc, "dumpdtb",
> +        "Dump current dtb to a file and quit", &error_abort);
> +
> +    object_class_property_add(oc, "phandle-start", "int",
> +        machine_get_phandle_start, machine_set_phandle_start,
> +        NULL, NULL, &error_abort);
> +    object_class_property_set_description(oc, "phandle-start",
> +            "The first phandle ID we may generate dynamically", &error_abort);
> +
> +    object_class_property_add_str(oc, "dt-compatible",
> +        machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
> +    object_class_property_set_description(oc, "dt-compatible",
> +        "Overrides the \"compatible\" property of the dt root node",
> +        &error_abort);
> +
> +    object_class_property_add_bool(oc, "dump-guest-core",
> +        machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
> +    object_class_property_set_description(oc, "dump-guest-core",
> +        "Include guest memory in  a core dump", &error_abort);
> +
> +    object_class_property_add_bool(oc, "mem-merge",
> +        machine_get_mem_merge, machine_set_mem_merge, &error_abort);
> +    object_class_property_set_description(oc, "mem-merge",
> +        "Enable/disable memory merge support", &error_abort);
> +
> +    object_class_property_add_bool(oc, "usb",
> +        machine_get_usb, machine_set_usb, &error_abort);
> +    object_class_property_set_description(oc, "usb",
> +        "Set on/off to enable/disable usb", &error_abort);
> +
> +    object_class_property_add_bool(oc, "graphics",
> +        machine_get_graphics, machine_set_graphics, &error_abort);
> +    object_class_property_set_description(oc, "graphics",
> +        "Set on/off to enable/disable graphics emulation", &error_abort);
> +
> +    object_class_property_add_bool(oc, "igd-passthru",
> +        machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
> +        &error_abort);
> +    object_class_property_set_description(oc, "igd-passthru",
> +        "Set on/off to enable/disable igd passthrou", &error_abort);
> +
> +    object_class_property_add_str(oc, "firmware",
> +        machine_get_firmware, machine_set_firmware,
> +        &error_abort);
> +    object_class_property_set_description(oc, "firmware",
> +        "Firmware image", &error_abort);
> +
> +    object_class_property_add_bool(oc, "suppress-vmdesc",
> +        machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
> +        &error_abort);
> +    object_class_property_set_description(oc, "suppress-vmdesc",
> +        "Set on to disable self-describing migration", &error_abort);
> +
> +    object_class_property_add_bool(oc, "enforce-config-section",
> +        machine_get_enforce_config_section, machine_set_enforce_config_section,
> +        &error_abort);
> +    object_class_property_set_description(oc, "enforce-config-section",
> +        "Set on to enforce configuration section migration", &error_abort);
>  }
>  
>  static void machine_class_base_init(ObjectClass *oc, void *data)
> @@ -387,114 +485,6 @@ static void machine_initfn(Object *obj)
>      ms->mem_merge = true;
>      ms->enable_graphics = true;
>  
> -    object_property_add_str(obj, "accel",
> -                            machine_get_accel, machine_set_accel, NULL);
> -    object_property_set_description(obj, "accel",
> -                                    "Accelerator list",
> -                                    NULL);
> -    object_property_add(obj, "kernel-irqchip", "OnOffSplit",
> -                        NULL,
> -                        machine_set_kernel_irqchip,
> -                        NULL, NULL, NULL);
> -    object_property_set_description(obj, "kernel-irqchip",
> -                                    "Configure KVM in-kernel irqchip",
> -                                    NULL);
> -    object_property_add(obj, "kvm-shadow-mem", "int",
> -                        machine_get_kvm_shadow_mem,
> -                        machine_set_kvm_shadow_mem,
> -                        NULL, NULL, NULL);
> -    object_property_set_description(obj, "kvm-shadow-mem",
> -                                    "KVM shadow MMU size",
> -                                    NULL);
> -    object_property_add_str(obj, "kernel",
> -                            machine_get_kernel, machine_set_kernel, NULL);
> -    object_property_set_description(obj, "kernel",
> -                                    "Linux kernel image file",
> -                                    NULL);
> -    object_property_add_str(obj, "initrd",
> -                            machine_get_initrd, machine_set_initrd, NULL);
> -    object_property_set_description(obj, "initrd",
> -                                    "Linux initial ramdisk file",
> -                                    NULL);
> -    object_property_add_str(obj, "append",
> -                            machine_get_append, machine_set_append, NULL);
> -    object_property_set_description(obj, "append",
> -                                    "Linux kernel command line",
> -                                    NULL);
> -    object_property_add_str(obj, "dtb",
> -                            machine_get_dtb, machine_set_dtb, NULL);
> -    object_property_set_description(obj, "dtb",
> -                                    "Linux kernel device tree file",
> -                                    NULL);
> -    object_property_add_str(obj, "dumpdtb",
> -                            machine_get_dumpdtb, machine_set_dumpdtb, NULL);
> -    object_property_set_description(obj, "dumpdtb",
> -                                    "Dump current dtb to a file and quit",
> -                                    NULL);
> -    object_property_add(obj, "phandle-start", "int",
> -                        machine_get_phandle_start,
> -                        machine_set_phandle_start,
> -                        NULL, NULL, NULL);
> -    object_property_set_description(obj, "phandle-start",
> -                                    "The first phandle ID we may generate dynamically",
> -                                    NULL);
> -    object_property_add_str(obj, "dt-compatible",
> -                            machine_get_dt_compatible,
> -                            machine_set_dt_compatible,
> -                            NULL);
> -    object_property_set_description(obj, "dt-compatible",
> -                                    "Overrides the \"compatible\" property of the dt root node",
> -                                    NULL);
> -    object_property_add_bool(obj, "dump-guest-core",
> -                             machine_get_dump_guest_core,
> -                             machine_set_dump_guest_core,
> -                             NULL);
> -    object_property_set_description(obj, "dump-guest-core",
> -                                    "Include guest memory in  a core dump",
> -                                    NULL);
> -    object_property_add_bool(obj, "mem-merge",
> -                             machine_get_mem_merge,
> -                             machine_set_mem_merge, NULL);
> -    object_property_set_description(obj, "mem-merge",
> -                                    "Enable/disable memory merge support",
> -                                    NULL);
> -    object_property_add_bool(obj, "usb",
> -                             machine_get_usb,
> -                             machine_set_usb, NULL);
> -    object_property_set_description(obj, "usb",
> -                                    "Set on/off to enable/disable usb",
> -                                    NULL);
> -    object_property_add_bool(obj, "graphics",
> -                             machine_get_graphics,
> -                             machine_set_graphics, NULL);
> -    object_property_set_description(obj, "graphics",
> -                                    "Set on/off to enable/disable graphics emulation",
> -                                    NULL);
> -    object_property_add_bool(obj, "igd-passthru",
> -                             machine_get_igd_gfx_passthru,
> -                             machine_set_igd_gfx_passthru, NULL);
> -    object_property_set_description(obj, "igd-passthru",
> -                                    "Set on/off to enable/disable igd passthrou",
> -                                    NULL);
> -    object_property_add_str(obj, "firmware",
> -                            machine_get_firmware,
> -                            machine_set_firmware, NULL);
> -    object_property_set_description(obj, "firmware",
> -                                    "Firmware image",
> -                                    NULL);
> -    object_property_add_bool(obj, "suppress-vmdesc",
> -                             machine_get_suppress_vmdesc,
> -                             machine_set_suppress_vmdesc, NULL);
> -    object_property_set_description(obj, "suppress-vmdesc",
> -                                    "Set on to disable self-describing migration",
> -                                    NULL);
> -    object_property_add_bool(obj, "enforce-config-section",
> -                             machine_get_enforce_config_section,
> -                             machine_set_enforce_config_section, NULL);
> -    object_property_set_description(obj, "enforce-config-section",
> -                                    "Set on to enforce configuration section migration",
> -                                    NULL);
> -
>      /* Register notifier when init is done for sysbus sanity checks */
>      ms->sysbus_notifier.notify = machine_init_notify;
>      qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
Eduardo Habkost Oct. 14, 2016, 1:24 p.m. UTC | #2
On Fri, Oct 14, 2016 at 03:08:30PM +0200, Igor Mammedov wrote:
> On Thu, 13 Oct 2016 18:26:39 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > When doing the conversion, the NULL errp arguments on the
> > property registration calls were changed to &error_abort.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> So many property registrations look pretty ugly but still
> better than doing it per instance, not that it matters
> so far as there is only 1 instance of Machine at a time.
> 
> So
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>

Thanks!

> 
> most of the properties below are dumb field setter/getter,
> it would be much better to declare them statically and
> make generic Object code to initialize them at type
> initialization time.
> i.e. make similar thing like static properties but for class
> and probably extend it to have optional custom setter/getter.

I've been considering doing that. It should be easier after the
"qdev class properties" series gets applied, but the existing
static-property code is still specific to DeviceState (probably
it's only because the static property getter/setters include a
dev->realized check).
diff mbox

Patch

diff --git a/hw/core/machine.c b/hw/core/machine.c
index afd84ac..b0fd91f 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -364,6 +364,104 @@  static void machine_class_init(ObjectClass *oc, void *data)
     /* Default 128 MB as guest ram size */
     mc->default_ram_size = 128 * M_BYTE;
     mc->rom_file_has_mr = true;
+
+    object_class_property_add_str(oc, "accel",
+        machine_get_accel, machine_set_accel, &error_abort);
+    object_class_property_set_description(oc, "accel",
+        "Accelerator list", &error_abort);
+
+    object_class_property_add(oc, "kernel-irqchip", "OnOffSplit",
+        NULL, machine_set_kernel_irqchip,
+        NULL, NULL, &error_abort);
+    object_class_property_set_description(oc, "kernel-irqchip",
+        "Configure KVM in-kernel irqchip", &error_abort);
+
+    object_class_property_add(oc, "kvm-shadow-mem", "int",
+        machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
+        NULL, NULL, &error_abort);
+    object_class_property_set_description(oc, "kvm-shadow-mem",
+        "KVM shadow MMU size", &error_abort);
+
+    object_class_property_add_str(oc, "kernel",
+        machine_get_kernel, machine_set_kernel, &error_abort);
+    object_class_property_set_description(oc, "kernel",
+        "Linux kernel image file", &error_abort);
+
+    object_class_property_add_str(oc, "initrd",
+        machine_get_initrd, machine_set_initrd, &error_abort);
+    object_class_property_set_description(oc, "initrd",
+        "Linux initial ramdisk file", &error_abort);
+
+    object_class_property_add_str(oc, "append",
+        machine_get_append, machine_set_append, &error_abort);
+    object_class_property_set_description(oc, "append",
+        "Linux kernel command line", &error_abort);
+
+    object_class_property_add_str(oc, "dtb",
+        machine_get_dtb, machine_set_dtb, &error_abort);
+    object_class_property_set_description(oc, "dtb",
+        "Linux kernel device tree file", &error_abort);
+
+    object_class_property_add_str(oc, "dumpdtb",
+        machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
+    object_class_property_set_description(oc, "dumpdtb",
+        "Dump current dtb to a file and quit", &error_abort);
+
+    object_class_property_add(oc, "phandle-start", "int",
+        machine_get_phandle_start, machine_set_phandle_start,
+        NULL, NULL, &error_abort);
+    object_class_property_set_description(oc, "phandle-start",
+            "The first phandle ID we may generate dynamically", &error_abort);
+
+    object_class_property_add_str(oc, "dt-compatible",
+        machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
+    object_class_property_set_description(oc, "dt-compatible",
+        "Overrides the \"compatible\" property of the dt root node",
+        &error_abort);
+
+    object_class_property_add_bool(oc, "dump-guest-core",
+        machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
+    object_class_property_set_description(oc, "dump-guest-core",
+        "Include guest memory in  a core dump", &error_abort);
+
+    object_class_property_add_bool(oc, "mem-merge",
+        machine_get_mem_merge, machine_set_mem_merge, &error_abort);
+    object_class_property_set_description(oc, "mem-merge",
+        "Enable/disable memory merge support", &error_abort);
+
+    object_class_property_add_bool(oc, "usb",
+        machine_get_usb, machine_set_usb, &error_abort);
+    object_class_property_set_description(oc, "usb",
+        "Set on/off to enable/disable usb", &error_abort);
+
+    object_class_property_add_bool(oc, "graphics",
+        machine_get_graphics, machine_set_graphics, &error_abort);
+    object_class_property_set_description(oc, "graphics",
+        "Set on/off to enable/disable graphics emulation", &error_abort);
+
+    object_class_property_add_bool(oc, "igd-passthru",
+        machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
+        &error_abort);
+    object_class_property_set_description(oc, "igd-passthru",
+        "Set on/off to enable/disable igd passthrou", &error_abort);
+
+    object_class_property_add_str(oc, "firmware",
+        machine_get_firmware, machine_set_firmware,
+        &error_abort);
+    object_class_property_set_description(oc, "firmware",
+        "Firmware image", &error_abort);
+
+    object_class_property_add_bool(oc, "suppress-vmdesc",
+        machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
+        &error_abort);
+    object_class_property_set_description(oc, "suppress-vmdesc",
+        "Set on to disable self-describing migration", &error_abort);
+
+    object_class_property_add_bool(oc, "enforce-config-section",
+        machine_get_enforce_config_section, machine_set_enforce_config_section,
+        &error_abort);
+    object_class_property_set_description(oc, "enforce-config-section",
+        "Set on to enforce configuration section migration", &error_abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data)
@@ -387,114 +485,6 @@  static void machine_initfn(Object *obj)
     ms->mem_merge = true;
     ms->enable_graphics = true;
 
-    object_property_add_str(obj, "accel",
-                            machine_get_accel, machine_set_accel, NULL);
-    object_property_set_description(obj, "accel",
-                                    "Accelerator list",
-                                    NULL);
-    object_property_add(obj, "kernel-irqchip", "OnOffSplit",
-                        NULL,
-                        machine_set_kernel_irqchip,
-                        NULL, NULL, NULL);
-    object_property_set_description(obj, "kernel-irqchip",
-                                    "Configure KVM in-kernel irqchip",
-                                    NULL);
-    object_property_add(obj, "kvm-shadow-mem", "int",
-                        machine_get_kvm_shadow_mem,
-                        machine_set_kvm_shadow_mem,
-                        NULL, NULL, NULL);
-    object_property_set_description(obj, "kvm-shadow-mem",
-                                    "KVM shadow MMU size",
-                                    NULL);
-    object_property_add_str(obj, "kernel",
-                            machine_get_kernel, machine_set_kernel, NULL);
-    object_property_set_description(obj, "kernel",
-                                    "Linux kernel image file",
-                                    NULL);
-    object_property_add_str(obj, "initrd",
-                            machine_get_initrd, machine_set_initrd, NULL);
-    object_property_set_description(obj, "initrd",
-                                    "Linux initial ramdisk file",
-                                    NULL);
-    object_property_add_str(obj, "append",
-                            machine_get_append, machine_set_append, NULL);
-    object_property_set_description(obj, "append",
-                                    "Linux kernel command line",
-                                    NULL);
-    object_property_add_str(obj, "dtb",
-                            machine_get_dtb, machine_set_dtb, NULL);
-    object_property_set_description(obj, "dtb",
-                                    "Linux kernel device tree file",
-                                    NULL);
-    object_property_add_str(obj, "dumpdtb",
-                            machine_get_dumpdtb, machine_set_dumpdtb, NULL);
-    object_property_set_description(obj, "dumpdtb",
-                                    "Dump current dtb to a file and quit",
-                                    NULL);
-    object_property_add(obj, "phandle-start", "int",
-                        machine_get_phandle_start,
-                        machine_set_phandle_start,
-                        NULL, NULL, NULL);
-    object_property_set_description(obj, "phandle-start",
-                                    "The first phandle ID we may generate dynamically",
-                                    NULL);
-    object_property_add_str(obj, "dt-compatible",
-                            machine_get_dt_compatible,
-                            machine_set_dt_compatible,
-                            NULL);
-    object_property_set_description(obj, "dt-compatible",
-                                    "Overrides the \"compatible\" property of the dt root node",
-                                    NULL);
-    object_property_add_bool(obj, "dump-guest-core",
-                             machine_get_dump_guest_core,
-                             machine_set_dump_guest_core,
-                             NULL);
-    object_property_set_description(obj, "dump-guest-core",
-                                    "Include guest memory in  a core dump",
-                                    NULL);
-    object_property_add_bool(obj, "mem-merge",
-                             machine_get_mem_merge,
-                             machine_set_mem_merge, NULL);
-    object_property_set_description(obj, "mem-merge",
-                                    "Enable/disable memory merge support",
-                                    NULL);
-    object_property_add_bool(obj, "usb",
-                             machine_get_usb,
-                             machine_set_usb, NULL);
-    object_property_set_description(obj, "usb",
-                                    "Set on/off to enable/disable usb",
-                                    NULL);
-    object_property_add_bool(obj, "graphics",
-                             machine_get_graphics,
-                             machine_set_graphics, NULL);
-    object_property_set_description(obj, "graphics",
-                                    "Set on/off to enable/disable graphics emulation",
-                                    NULL);
-    object_property_add_bool(obj, "igd-passthru",
-                             machine_get_igd_gfx_passthru,
-                             machine_set_igd_gfx_passthru, NULL);
-    object_property_set_description(obj, "igd-passthru",
-                                    "Set on/off to enable/disable igd passthrou",
-                                    NULL);
-    object_property_add_str(obj, "firmware",
-                            machine_get_firmware,
-                            machine_set_firmware, NULL);
-    object_property_set_description(obj, "firmware",
-                                    "Firmware image",
-                                    NULL);
-    object_property_add_bool(obj, "suppress-vmdesc",
-                             machine_get_suppress_vmdesc,
-                             machine_set_suppress_vmdesc, NULL);
-    object_property_set_description(obj, "suppress-vmdesc",
-                                    "Set on to disable self-describing migration",
-                                    NULL);
-    object_property_add_bool(obj, "enforce-config-section",
-                             machine_get_enforce_config_section,
-                             machine_set_enforce_config_section, NULL);
-    object_property_set_description(obj, "enforce-config-section",
-                                    "Set on to enforce configuration section migration",
-                                    NULL);
-
     /* Register notifier when init is done for sysbus sanity checks */
     ms->sysbus_notifier.notify = machine_init_notify;
     qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);