* [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions
@ 2020-10-22 22:31 Eduardo Habkost
2020-10-22 22:31 ` [PATCH 1/4] qom: " Eduardo Habkost
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Eduardo Habkost @ 2020-10-22 22:31 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel P. Berrangé,
Eduardo Habkost, Michael S. Tsirkin, Philippe Mathieu-Daudé,
Markus Armbruster, Igor Mammedov, Paolo Bonzini, Aurelien Jarno
Based-on: 20201009160122.1662082-1-ehabkost@redhat.com
Git branch: https://github.com/ehabkost/qemu work/qom-bool-ptr-prop
This series introduces a helper to make it easier to register
simple boolan QOM properties. It will be useful for simplifying
existing property code in some types that can't use
QDEV_PROP_BOOL yet (because they are not TYPE_DEVICE subtypes).
As examples, some TYPE_MACHINE and TYPE_QAUTHZ_LIST_FILE
properties are converted to use the new functions.
This depends on the QOM property code cleanup that was also
submitted as part of:
https://lore.kernel.org/qemu-devel/20201009160122.1662082-1-ehabkost@redhat.com
Subject: [PATCH 00/12] qom: Make all -object types use only class properties<
Eduardo Habkost (4):
qom: object*_property_add_bool_ptr() functions
autz/listfile: Use object_class_property_add_bool_ptr()
machine: Use object_class_property_add_bool_ptr() when possible
pc: Use object_class_property_add_bool_ptr()
include/qom/object.h | 23 +++++++++++++
authz/listfile.c | 27 ++-------------
hw/core/machine.c | 78 ++++++++------------------------------------
hw/i386/pc.c | 57 +++++---------------------------
qom/object.c | 31 ++++++++++++++++++
5 files changed, 79 insertions(+), 137 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] qom: object*_property_add_bool_ptr() functions
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
@ 2020-10-22 22:31 ` Eduardo Habkost
2020-10-22 22:31 ` [PATCH 2/4] autz/listfile: Use object_class_property_add_bool_ptr() Eduardo Habkost
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2020-10-22 22:31 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel P. Berrangé,
Eduardo Habkost, Michael S. Tsirkin, Philippe Mathieu-Daudé,
Markus Armbruster, Igor Mammedov, Paolo Bonzini, Aurelien Jarno
Provide helpers for registering boolean properties that simply
read/write a struct field, to reduce the need to manually write
property getters and setters.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
include/qom/object.h | 23 +++++++++++++++++++++++
qom/object.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index a124cf897d..954a26c567 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1815,6 +1815,29 @@ ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
ptrdiff_t offset,
ObjectPropertyFlags flags);
+/**
+ * object_property_add_bool_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @flags: bitwise-or'd ObjectPropertyFlags
+ *
+ * Add an bool property in memory. This function will add a
+ * property of type 'bool'.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.
+ */
+ObjectProperty *
+object_property_add_bool_ptr(Object *obj, const char *name,
+ bool *v,
+ ObjectPropertyFlags flags);
+
+ObjectProperty *
+object_class_property_add_bool_ptr(ObjectClass *klass,
+ const char *name,
+ ptrdiff_t offset,
+ ObjectPropertyFlags flags);
+
/**
* object_property_add_alias:
* @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index 73f27b8b7e..2abc2bda33 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2713,6 +2713,37 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
flags, offset);
}
+static void property_visit_bool_ptr(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ PointerProperty *prop = opaque;
+ bool *field = pointer_property_get_ptr(obj, prop);
+ visit_type_bool(v, name, field, errp);
+}
+
+ObjectProperty *
+object_property_add_bool_ptr(Object *obj, const char *name,
+ bool *v,
+ ObjectPropertyFlags flags)
+{
+ return object_property_add_uint_ptr(obj, name, "bool",
+ property_visit_bool_ptr,
+ property_visit_bool_ptr,
+ flags,
+ (void *)v);
+}
+
+ObjectProperty *
+object_class_property_add_bool_ptr(ObjectClass *klass, const char *name,
+ ptrdiff_t offset,
+ ObjectPropertyFlags flags)
+{
+ return object_class_property_add_uint_ptr(klass, name, "bool",
+ property_visit_bool_ptr,
+ property_visit_bool_ptr,
+ flags, offset);
+}
+
typedef struct {
Object *target_obj;
char *target_name;
--
2.28.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] autz/listfile: Use object_class_property_add_bool_ptr()
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
2020-10-22 22:31 ` [PATCH 1/4] qom: " Eduardo Habkost
@ 2020-10-22 22:31 ` Eduardo Habkost
2020-10-22 22:31 ` [PATCH 3/4] machine: Use object_class_property_add_bool_ptr() when possible Eduardo Habkost
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2020-10-22 22:31 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel P. Berrangé,
Eduardo Habkost, Michael S. Tsirkin, Philippe Mathieu-Daudé,
Markus Armbruster, Igor Mammedov, Paolo Bonzini, Aurelien Jarno
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org
---
authz/listfile.c | 27 +++------------------------
1 file changed, 3 insertions(+), 24 deletions(-)
diff --git a/authz/listfile.c b/authz/listfile.c
index aaf930453d..911c4e45f2 100644
--- a/authz/listfile.c
+++ b/authz/listfile.c
@@ -184,27 +184,6 @@ qauthz_list_file_prop_get_filename(Object *obj,
}
-static void
-qauthz_list_file_prop_set_refresh(Object *obj,
- bool value,
- Error **errp G_GNUC_UNUSED)
-{
- QAuthZListFile *fauthz = QAUTHZ_LIST_FILE(obj);
-
- fauthz->refresh = value;
-}
-
-
-static bool
-qauthz_list_file_prop_get_refresh(Object *obj,
- Error **errp G_GNUC_UNUSED)
-{
- QAuthZListFile *fauthz = QAUTHZ_LIST_FILE(obj);
-
- return fauthz->refresh;
-}
-
-
static void
qauthz_list_file_finalize(Object *obj)
{
@@ -227,9 +206,9 @@ qauthz_list_file_class_init(ObjectClass *oc, void *data)
object_class_property_add_str(oc, "filename",
qauthz_list_file_prop_get_filename,
qauthz_list_file_prop_set_filename);
- object_class_property_add_bool(oc, "refresh",
- qauthz_list_file_prop_get_refresh,
- qauthz_list_file_prop_set_refresh);
+ object_class_property_add_bool_ptr(oc, "refresh",
+ offsetof(QAuthZListFile, refresh),
+ OBJ_PROP_FLAG_READWRITE);
authz->is_allowed = qauthz_list_file_is_allowed;
}
--
2.28.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] machine: Use object_class_property_add_bool_ptr() when possible
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
2020-10-22 22:31 ` [PATCH 1/4] qom: " Eduardo Habkost
2020-10-22 22:31 ` [PATCH 2/4] autz/listfile: Use object_class_property_add_bool_ptr() Eduardo Habkost
@ 2020-10-22 22:31 ` Eduardo Habkost
2020-10-22 22:31 ` [PATCH 4/4] pc: Use object_class_property_add_bool_ptr() Eduardo Habkost
2020-10-23 7:37 ` [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Philippe Mathieu-Daudé
4 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2020-10-22 22:31 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel P. Berrangé,
Eduardo Habkost, Michael S. Tsirkin, Philippe Mathieu-Daudé,
Markus Armbruster, Igor Mammedov, Paolo Bonzini, Aurelien Jarno
Get rid if some manually written properties getters/setters.
Not all properties could be converted because they have extra
logic in the property setter.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: qemu-devel@nongnu.org
---
hw/core/machine.c | 78 ++++++++---------------------------------------
1 file changed, 13 insertions(+), 65 deletions(-)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index d740a7e963..21cad22b9e 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -325,34 +325,6 @@ static void machine_set_dt_compatible(Object *obj, const char *value, Error **er
ms->dt_compatible = g_strdup(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 bool machine_get_usb(Object *obj, Error **errp)
{
MachineState *ms = MACHINE(obj);
@@ -368,20 +340,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 char *machine_get_firmware(Object *obj, Error **errp)
{
MachineState *ms = MACHINE(obj);
@@ -397,20 +355,6 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
ms->firmware = g_strdup(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 void machine_set_enforce_config_section(Object *obj, bool value,
Error **errp)
{
@@ -449,7 +393,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;
}
}
@@ -827,13 +771,15 @@ 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_add_bool_ptr(oc, "dump-guest-core",
+ offsetof(MachineState, dump_guest_core),
+ OBJ_PROP_FLAG_READWRITE);
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_add_bool_ptr(oc, "mem-merge",
+ offsetof(MachineState, mem_merge),
+ OBJ_PROP_FLAG_READWRITE);
object_class_property_set_description(oc, "mem-merge",
"Enable/disable memory merge support");
@@ -842,8 +788,9 @@ 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_add_bool_ptr(oc, "graphics",
+ offsetof(MachineState, enable_graphics),
+ OBJ_PROP_FLAG_READWRITE);
object_class_property_set_description(oc, "graphics",
"Set on/off to enable/disable graphics emulation");
@@ -852,8 +799,9 @@ static void machine_class_init(ObjectClass *oc, void *data)
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_add_bool_ptr(oc, "suppress-vmdesc",
+ offsetof(MachineState, suppress_vmdesc),
+ OBJ_PROP_FLAG_READWRITE);
object_class_property_set_description(oc, "suppress-vmdesc",
"Set on to disable self-describing migration");
--
2.28.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] pc: Use object_class_property_add_bool_ptr()
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
` (2 preceding siblings ...)
2020-10-22 22:31 ` [PATCH 3/4] machine: Use object_class_property_add_bool_ptr() when possible Eduardo Habkost
@ 2020-10-22 22:31 ` Eduardo Habkost
2020-10-23 7:37 ` [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Philippe Mathieu-Daudé
4 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2020-10-22 22:31 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel P. Berrangé,
Eduardo Habkost, Michael S. Tsirkin, Philippe Mathieu-Daudé,
Markus Armbruster, Igor Mammedov, Paolo Bonzini, Aurelien Jarno,
Richard Henderson
Get rid of manually written property getters/setters.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: qemu-devel@nongnu.org
---
hw/i386/pc.c | 57 +++++++++-------------------------------------------
1 file changed, 9 insertions(+), 48 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4e323755d0..d5a5b1b2ae 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1493,48 +1493,6 @@ static void pc_machine_set_vmport(Object *obj, Visitor *v, const char *name,
visit_type_OnOffAuto(v, name, &pcms->vmport, errp);
}
-static bool pc_machine_get_smbus(Object *obj, Error **errp)
-{
- PCMachineState *pcms = PC_MACHINE(obj);
-
- return pcms->smbus_enabled;
-}
-
-static void pc_machine_set_smbus(Object *obj, bool value, Error **errp)
-{
- PCMachineState *pcms = PC_MACHINE(obj);
-
- pcms->smbus_enabled = value;
-}
-
-static bool pc_machine_get_sata(Object *obj, Error **errp)
-{
- PCMachineState *pcms = PC_MACHINE(obj);
-
- return pcms->sata_enabled;
-}
-
-static void pc_machine_set_sata(Object *obj, bool value, Error **errp)
-{
- PCMachineState *pcms = PC_MACHINE(obj);
-
- pcms->sata_enabled = value;
-}
-
-static bool pc_machine_get_pit(Object *obj, Error **errp)
-{
- PCMachineState *pcms = PC_MACHINE(obj);
-
- return pcms->pit_enabled;
-}
-
-static void pc_machine_set_pit(Object *obj, bool value, Error **errp)
-{
- PCMachineState *pcms = PC_MACHINE(obj);
-
- pcms->pit_enabled = value;
-}
-
static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
@@ -1697,14 +1655,17 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
object_class_property_set_description(oc, PC_MACHINE_VMPORT,
"Enable vmport (pc & q35)");
- object_class_property_add_bool(oc, PC_MACHINE_SMBUS,
- pc_machine_get_smbus, pc_machine_set_smbus);
+ object_class_property_add_bool_ptr(oc, PC_MACHINE_SMBUS,
+ offsetof(PCMachineState, smbus_enabled),
+ OBJ_PROP_FLAG_READWRITE);
- object_class_property_add_bool(oc, PC_MACHINE_SATA,
- pc_machine_get_sata, pc_machine_set_sata);
+ object_class_property_add_bool_ptr(oc, PC_MACHINE_SATA,
+ offsetof(PCMachineState, sata_enabled),
+ OBJ_PROP_FLAG_READWRITE);
- object_class_property_add_bool(oc, PC_MACHINE_PIT,
- pc_machine_get_pit, pc_machine_set_pit);
+ object_class_property_add_bool_ptr(oc, PC_MACHINE_PIT,
+ offsetof(PCMachineState, pit_enabled),
+ OBJ_PROP_FLAG_READWRITE);
}
static const TypeInfo pc_machine_info = {
--
2.28.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
` (3 preceding siblings ...)
2020-10-22 22:31 ` [PATCH 4/4] pc: Use object_class_property_add_bool_ptr() Eduardo Habkost
@ 2020-10-23 7:37 ` Philippe Mathieu-Daudé
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 7:37 UTC (permalink / raw)
To: Eduardo Habkost, qemu-devel
Cc: Daniel P. Berrangé,
Michael S. Tsirkin, Markus Armbruster, Paolo Bonzini,
Igor Mammedov, Aurelien Jarno
On 10/23/20 12:31 AM, Eduardo Habkost wrote:
> Based-on: 20201009160122.1662082-1-ehabkost@redhat.com
> Git branch: https://github.com/ehabkost/qemu work/qom-bool-ptr-prop
>
> This series introduces a helper to make it easier to register
> simple boolan QOM properties. It will be useful for simplifying
> existing property code in some types that can't use
> QDEV_PROP_BOOL yet (because they are not TYPE_DEVICE subtypes).
> As examples, some TYPE_MACHINE and TYPE_QAUTHZ_LIST_FILE
> properties are converted to use the new functions.
>
> This depends on the QOM property code cleanup that was also
> submitted as part of:
>
> https://lore.kernel.org/qemu-devel/20201009160122.1662082-1-ehabkost@redhat.com
> Subject: [PATCH 00/12] qom: Make all -object types use only class properties<
>
> Eduardo Habkost (4):
> qom: object*_property_add_bool_ptr() functions
> autz/listfile: Use object_class_property_add_bool_ptr()
> machine: Use object_class_property_add_bool_ptr() when possible
> pc: Use object_class_property_add_bool_ptr()
>
> include/qom/object.h | 23 +++++++++++++
> authz/listfile.c | 27 ++-------------
> hw/core/machine.c | 78 ++++++++------------------------------------
> hw/i386/pc.c | 57 +++++---------------------------
> qom/object.c | 31 ++++++++++++++++++
> 5 files changed, 79 insertions(+), 137 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-10-23 7:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 22:31 [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Eduardo Habkost
2020-10-22 22:31 ` [PATCH 1/4] qom: " Eduardo Habkost
2020-10-22 22:31 ` [PATCH 2/4] autz/listfile: Use object_class_property_add_bool_ptr() Eduardo Habkost
2020-10-22 22:31 ` [PATCH 3/4] machine: Use object_class_property_add_bool_ptr() when possible Eduardo Habkost
2020-10-22 22:31 ` [PATCH 4/4] pc: Use object_class_property_add_bool_ptr() Eduardo Habkost
2020-10-23 7:37 ` [PATCH 0/4] qom: Introduce object*_property_add_bool_ptr() functions Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.