[PATCH 35/36] machine: Use DEFINE_PROP_BOOL for boolean properties

Eduardo Habkost posted 36 patches 5 years, 3 months ago
Maintainers: Antony Pavlov <antonynpavlov@gmail.com>, Halil Pasic <pasic@linux.ibm.com>, Juan Quintela <quintela@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Cédric Le Goater" <clg@kaod.org>, Paolo Bonzini <pbonzini@redhat.com>, Jason Wang <jasowang@redhat.com>, Richard Henderson <rth@twiddle.net>, John Snow <jsnow@redhat.com>, Magnus Damm <magnus.damm@gmail.com>, Max Reitz <mreitz@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Alberto Garcia <berto@igalia.com>, Fabien Chouteau <chouteau@adacore.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Laurent Vivier <lvivier@redhat.com>, Sarah Harris <S.E.Harris@kent.ac.uk>, Eric Auger <eric.auger@redhat.com>, Thomas Huth <huth@tuxfamily.org>, Anthony Perard <anthony.perard@citrix.com>, Raphael Norwitz <raphael.norwitz@nutanix.com>, Jiri Pirko <jiri@resnulli.us>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Gerd Hoffmann <kraxel@redhat.com>, Christian Borntraeger <borntraeger@de.ibm.com>, Eduardo Habkost <ehabkost@redhat.com>, Artyom Tarasenko <atar4qemu@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Amit Shah <amit@kernel.org>, Andrew Baumann <Andrew.Baumann@microsoft.com>, Corey Minyard <minyard@acm.org>, Joel Stanley <joel@jms.id.au>, Igor Mitsyanko <i.mitsyanko@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Alex Williamson <alex.williamson@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Peter Chubb <peter.chubb@nicta.com.au>, Andrzej Zaborowski <balrogg@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Michael Rolnik <mrolnik@gmail.com>, Paul Durrant <paul@xen.org>, KONRAD Frederic <frederic.konrad@adacore.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Michael Walle <michael@walle.cc>, Yoshinori Sato <ysato@users.sourceforge.jp>, Stefan Hajnoczi <stefanha@redhat.com>, Yuval Shaia <yuval.shaia.ml@gmail.com>
There is a newer version of this series
[PATCH 35/36] machine: Use DEFINE_PROP_BOOL for boolean properties
Posted by Eduardo Habkost 5 years, 3 months ago
Unfortunately, the "usb" property is not trivial because it
actually represents a pair of booleans.  It probably should be
replaced by a OnOffAuto property instead.

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

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 97e102911a..e62097526a 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -236,34 +236,6 @@ static void machine_set_phandle_start(Object *obj, Visitor *v,
     ms->phandle_start = value;
 }
 
-static bool machine_get_dump_guest_core(Object *obj, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    return ms->dump_guest_core;
-}
-
-static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    ms->dump_guest_core = value;
-}
-
-static bool machine_get_mem_merge(Object *obj, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    return ms->mem_merge;
-}
-
-static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    ms->mem_merge = value;
-}
-
 static Property machine_props[] = {
     DEFINE_PROP_STRING("kernel", MachineState, kernel_filename),
     DEFINE_PROP_STRING("initrd", MachineState, initrd_filename),
@@ -273,6 +245,10 @@ static Property machine_props[] = {
     DEFINE_PROP_STRING("dt-compatible", MachineState, dt_compatible),
     DEFINE_PROP_STRING("firmware", MachineState, firmware),
     DEFINE_PROP_STRING("memory-backend", MachineState, ram_memdev_id),
+    DEFINE_PROP_BOOL("dump-guest-core", MachineState, dump_guest_core, true),
+    DEFINE_PROP_BOOL("mem-merge", MachineState, mem_merge, true),
+    DEFINE_PROP_BOOL("graphics", MachineState, enable_graphics, true),
+    DEFINE_PROP_BOOL("suppress-vmdesc", MachineState, suppress_vmdesc, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -291,34 +267,6 @@ static void machine_set_usb(Object *obj, bool value, Error **errp)
     ms->usb_disabled = !value;
 }
 
-static bool machine_get_graphics(Object *obj, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    return ms->enable_graphics;
-}
-
-static void machine_set_graphics(Object *obj, bool value, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    ms->enable_graphics = value;
-}
-
-static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    ms->suppress_vmdesc = value;
-}
-
-static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
-{
-    MachineState *ms = MACHINE(obj);
-
-    return ms->suppress_vmdesc;
-}
-
 static char *machine_get_memory_encryption(Object *obj, Error **errp)
 {
     MachineState *ms = MACHINE(obj);
@@ -339,7 +287,7 @@ static void machine_set_memory_encryption(Object *obj, const char *value,
      * so there's no point in it trying to merge areas.
      */
     if (value) {
-        machine_set_mem_merge(obj, false, errp);
+        ms->mem_merge = false;
     }
 }
 
@@ -692,13 +640,8 @@ static void machine_class_init(ObjectClass *oc, void *data)
     object_class_property_set_description(oc, "dt-compatible",
         "Overrides the \"compatible\" property of the dt root node");
 
-    object_class_property_add_bool(oc, "dump-guest-core",
-        machine_get_dump_guest_core, machine_set_dump_guest_core);
     object_class_property_set_description(oc, "dump-guest-core",
         "Include guest memory in a core dump");
-
-    object_class_property_add_bool(oc, "mem-merge",
-        machine_get_mem_merge, machine_set_mem_merge);
     object_class_property_set_description(oc, "mem-merge",
         "Enable/disable memory merge support");
 
@@ -707,16 +650,10 @@ static void machine_class_init(ObjectClass *oc, void *data)
     object_class_property_set_description(oc, "usb",
         "Set on/off to enable/disable usb");
 
-    object_class_property_add_bool(oc, "graphics",
-        machine_get_graphics, machine_set_graphics);
     object_class_property_set_description(oc, "graphics",
         "Set on/off to enable/disable graphics emulation");
-
     object_class_property_set_description(oc, "firmware",
         "Firmware image");
-
-    object_class_property_add_bool(oc, "suppress-vmdesc",
-        machine_get_suppress_vmdesc, machine_set_suppress_vmdesc);
     object_class_property_set_description(oc, "suppress-vmdesc",
         "Set on to disable self-describing migration");
 
@@ -751,10 +688,6 @@ static void machine_initfn(Object *obj)
     MachineState *ms = MACHINE(obj);
     MachineClass *mc = MACHINE_GET_CLASS(obj);
 
-    ms->dump_guest_core = true;
-    ms->mem_merge = true;
-    ms->enable_graphics = true;
-
     if (mc->nvdimm_supported) {
         Object *obj = OBJECT(ms);
 
-- 
2.28.0