Skip to contentSkip to conversation

Hi

PATCH In review [email protected] 6 participants 105 messages Oct 20 – Nov 1 Page 2 of 2

Subsystems (10)
lore
Share & tools
lore
#85 lore raw

PATCH v7 60/65 qdev: simplify DEFINE_PROP_ARRAY and remove generic array PropertyInfo

In reply to [email protected]

Change DEFINE_PROP_ARRAY, the macro now uses _arrayprop##_list to resolve the typed list PropertyInfo (introduced in the previous patch) instead of the generic qdev_prop_array.

This means the element type and size information is carried by the PropertyInfo itself rather than duplicated at each callsite. Since the typed list PropertyInfos encode element_info and element_size, the .arrayinfo and .arrayfieldsize fields are no longer set by the macro (they will be removed from the Property struct in the next patch).

Remove qdev_prop_array, which is now unused.

---
 hw/core/qdev-properties.c         |  8 --------
 hw/display/apple-gfx-mmio.m       |  2 +-
 hw/display/apple-gfx-pci.m        |  2 +-
 hw/display/apple-gfx.h            |  1 +
 hw/display/apple-gfx.m            |  4 ++++
 hw/input/stellaris_gamepad.c      |  2 +-
 hw/intc/arm_gicv3_common.c        |  2 +-
 hw/intc/arm_gicv5_common.c        |  4 ++--
 hw/intc/rx_icu.c                  |  4 ++--
 hw/misc/arm_sysctl.c              |  4 ++--
 hw/misc/mps2-scc.c                |  2 +-
 hw/net/rocker/rocker.c            |  2 +-
 hw/net/virtio-net.c               |  2 +-
 hw/nvram/xlnx-efuse.c             |  2 +-
 hw/nvram/xlnx-versal-efuse-ctrl.c |  2 +-
 hw/riscv/riscv_hart.c             |  6 ++----
 hw/virtio/virtio-iommu-pci.c      |  2 +-
 include/hw/block/block.h          |  2 +-
 include/hw/core/qdev-properties.h | 27 ++++++++++-----------------
 tests/unit/test-qdev.c            |  2 +-
 20 files changed, 35 insertions(+), 47 deletions(-)
hw/core/qdev-properties.c +0 -8
index bace12b10e36..5c403cc2e57e 100644
@@ -875,14 +875,6 @@ void default_prop_array(ObjectProperty *op, const Property *prop)
     object_property_set_default_list(op);
 }
 
-const PropertyInfo qdev_prop_array = {
-    .type = "list",
-    .get = get_prop_array,
-    .set = set_prop_array,
-    .release = release_prop_array,
-    .set_default_value = default_prop_array,
-};
-
 const PropertyInfo qdev_prop_uint8_list =
     DEFINE_PROP_ARRAY_INFO(qdev_prop_uint8, uint8_t);
 const PropertyInfo qdev_prop_uint16_list =
hw/display/apple-gfx-mmio.m +1 -1
index 58beaadd1f10..dcd04617eb87 100644
@@ -258,7 +258,7 @@ static void apple_gfx_mmio_reset(Object *obj, ResetType type)
 static const Property apple_gfx_mmio_properties[] = {
     DEFINE_PROP_ARRAY("display-modes", AppleGFXMMIOState,
                       common.num_display_modes, common.display_modes,
-                      qdev_prop_apple_gfx_display_mode, AppleGFXDisplayMode),
+                      qdev_prop_apple_gfx_display_mode),
 };
 
 static void apple_gfx_mmio_class_init(ObjectClass *klass, const void *data)
hw/display/apple-gfx-pci.m +1 -1
index b0694f4cb855..74f79c8b157b 100644
@@ -118,7 +118,7 @@ static void apple_gfx_pci_reset(Object *obj, ResetType type)
 static const Property apple_gfx_pci_properties[] = {
     DEFINE_PROP_ARRAY("display-modes", AppleGFXPCIState,
                       common.num_display_modes, common.display_modes,
-                      qdev_prop_apple_gfx_display_mode, AppleGFXDisplayMode),
+                      qdev_prop_apple_gfx_display_mode),
 };
 
 static void apple_gfx_pci_class_init(ObjectClass *klass, const void *data)
hw/display/apple-gfx.h +1 -0
index 3197bd853dab..b7eef7b9b14a 100644
@@ -69,6 +69,7 @@ void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_physical,
                                        MemoryRegion **mapping_in_region);
 
 extern const PropertyInfo qdev_prop_apple_gfx_display_mode;
+extern const PropertyInfo qdev_prop_apple_gfx_display_mode_list;
 
 #endif
 
hw/display/apple-gfx.m +4 -0
index 77c420b30006..592d692d793d 100644
@@ -16,6 +16,7 @@
 #include "qemu/cutils.h"
 #include "qemu/log.h"
 #include "qapi/qapi-builtin-type-infos.h"
+#include "hw/core/qdev-prop-internal.h"
 #include "qapi/visitor.h"
 #include "qapi/error.h"
 #include "qemu/aio-wait.h"
@@ -879,3 +880,6 @@ static void apple_gfx_set_display_mode(Object *obj, Visitor *v,
     .get   = apple_gfx_get_display_mode,
     .set   = apple_gfx_set_display_mode,
 };
+
+const PropertyInfo qdev_prop_apple_gfx_display_mode_list =
+    DEFINE_PROP_ARRAY_INFO(qdev_prop_apple_gfx_display_mode, AppleGFXDisplayMode);
hw/input/stellaris_gamepad.c +1 -1
index 376d91abad70..20613f649977 100644
@@ -80,7 +80,7 @@ static void stellaris_gamepad_reset_enter(Object *obj, ResetType type)
 
 static const Property stellaris_gamepad_properties[] = {
     DEFINE_PROP_ARRAY("keycodes", StellarisGamepad, num_buttons,
-                      keycodes, qdev_prop_uint32, uint32_t),
+                      keycodes, qdev_prop_uint32),
 };
 
 static void stellaris_gamepad_class_init(ObjectClass *klass, const void *data)
hw/intc/arm_gicv3_common.c +1 -1
index f7ba74e6d52a..1298b6b735e9 100644
@@ -615,7 +615,7 @@ static const Property arm_gicv3_common_properties[] = {
      */
     DEFINE_PROP_BOOL("force-8-bit-prio", GICv3State, force_8bit_prio, 0),
     DEFINE_PROP_ARRAY("redist-region-count", GICv3State, nb_redist_regions,
-                      redist_region_count, qdev_prop_uint32, uint32_t),
+                      redist_region_count, qdev_prop_uint32),
     DEFINE_PROP_LINK("sysmem", GICv3State, dma, TYPE_MEMORY_REGION,
                      MemoryRegion *),
     DEFINE_PROP_UINT32("first-cpu-index", GICv3State, first_cpu_idx, 0),
hw/intc/arm_gicv5_common.c +2 -2
index b155486af65e..61c8ae493021 100644
@@ -191,9 +191,9 @@ static void gicv5_common_realize(DeviceState *dev, Error **errp)
 
 static const Property arm_gicv5_common_properties[] = {
     DEFINE_PROP_LINK_ARRAY("cpus", GICv5Common, num_cpus,
-                           cpus, TYPE_ARM_CPU, ARMCPU *),
+                           cpus, TYPE_ARM_CPU),
     DEFINE_PROP_ARRAY("cpu-iaffids", GICv5Common, num_cpu_iaffids,
-                      cpu_iaffids, qdev_prop_uint32, uint32_t),
+                      cpu_iaffids, qdev_prop_uint32),
     DEFINE_PROP_UINT32("irsid", GICv5Common, irsid, 0),
     DEFINE_PROP_UINT32("spi-range", GICv5Common, spi_range, 0),
     DEFINE_PROP_UINT32("spi-base", GICv5Common, spi_base, 0),
hw/intc/rx_icu.c +2 -2
index 992b069ae245..125a6dcb6804 100644
@@ -356,9 +356,9 @@ static const VMStateDescription vmstate_rxicu = {
 
 static const Property rxicu_properties[] = {
     DEFINE_PROP_ARRAY("ipr-map", RXICUState, nr_irqs, map,
-                      qdev_prop_uint8, uint8_t),
+                      qdev_prop_uint8),
     DEFINE_PROP_ARRAY("trigger-level", RXICUState, nr_sense, init_sense,
-                      qdev_prop_uint8, uint8_t),
+                      qdev_prop_uint8),
 };
 
 static void rxicu_class_init(ObjectClass *klass, const void *data)
hw/misc/arm_sysctl.c +2 -2
index ebc95b9bb54c..1df85593a5cb 100644
@@ -626,10 +626,10 @@ static const Property arm_sysctl_properties[] = {
     DEFINE_PROP_UINT32("proc_id", arm_sysctl_state, proc_id, 0),
     /* Daughterboard power supply voltages (as reported via SYS_CFG) */
     DEFINE_PROP_ARRAY("db-voltage", arm_sysctl_state, db_num_vsensors,
-                      db_voltage, qdev_prop_uint32, uint32_t),
+                      db_voltage, qdev_prop_uint32),
     /* Daughterboard clock reset values (as reported via SYS_CFG) */
     DEFINE_PROP_ARRAY("db-clock", arm_sysctl_state, db_num_clocks,
-                      db_clock_reset, qdev_prop_uint32, uint32_t),
+                      db_clock_reset, qdev_prop_uint32),
 };
 
 static void arm_sysctl_class_init(ObjectClass *klass, const void *data)
hw/misc/mps2-scc.c +1 -1
index 554b504c7203..32f9e166feed 100644
@@ -464,7 +464,7 @@ static const Property mps2_scc_properties[] = {
      * motherboard configuration controller to suit the FPGA image.
      */
     DEFINE_PROP_ARRAY("oscclk", MPS2SCC, num_oscclk, oscclk_reset,
-                      qdev_prop_uint32, uint32_t),
+                      qdev_prop_uint32),
 };
 
 static void mps2_scc_class_init(ObjectClass *klass, const void *data)
hw/net/rocker/rocker.c +1 -1
index 910dce901b67..afbc32e99d94 100644
@@ -1466,7 +1466,7 @@ static const Property rocker_properties[] = {
     DEFINE_PROP_UINT64("switch_id", Rocker,
                        switch_id, 0),
     DEFINE_PROP_ARRAY("ports", Rocker, fp_ports,
-                      fp_ports_peers, qdev_prop_netdev, NICPeers),
+                      fp_ports_peers, qdev_prop_netdev),
 };
 
 static const VMStateDescription rocker_vmsd = {
hw/net/virtio-net.c +1 -1
index 19f453fb7dfd..56194398742e 100644
@@ -4377,7 +4377,7 @@ static const Property virtio_net_properties[] = {
     DEFINE_PROP_BIT64("hash", VirtIONet, host_features,
                     VIRTIO_NET_F_HASH_REPORT, false),
     DEFINE_PROP_ARRAY("ebpf-rss-fds", VirtIONet, nr_ebpf_rss_fds,
-                      ebpf_rss_fds, qdev_prop_string, char*),
+                      ebpf_rss_fds, qdev_prop_string),
     DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features,
                     VIRTIO_NET_F_RSC_EXT, false),
     DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout,
hw/nvram/xlnx-efuse.c +1 -1
index b1c9ee4980a0..99c16ce76f15 100644
@@ -266,7 +266,7 @@ static const Property efuse_properties[] = {
     DEFINE_PROP_UINT32("efuse-size", XlnxEFuse, efuse_size, 64 * 32),
     DEFINE_PROP_BOOL("init-factory-tbits", XlnxEFuse, init_tbits, true),
     DEFINE_PROP_ARRAY("read-only", XlnxEFuse, ro_bits_cnt, ro_bits,
-                      qdev_prop_uint32, uint32_t),
+                      qdev_prop_uint32),
 };
 
 static void efuse_class_init(ObjectClass *klass, const void *data)
hw/nvram/xlnx-versal-efuse-ctrl.c +1 -1
index f5d5587cb657..101320b82fd9 100644
@@ -740,7 +740,7 @@ static const Property efuse_ctrl_props[] = {
                      TYPE_XLNX_EFUSE, XlnxEFuse *),
     DEFINE_PROP_ARRAY("pg0-lock",
                       XlnxVersalEFuseCtrl, extra_pg0_lock_n16,
-                      extra_pg0_lock_spec, qdev_prop_uint16, uint16_t),
+                      extra_pg0_lock_spec, qdev_prop_uint16),
 };
 
 static void efuse_ctrl_class_init(ObjectClass *klass, const void *data)
hw/riscv/riscv_hart.c +2 -4
index 32fd39737ff6..132cf8737001 100644
@@ -48,11 +48,9 @@ static const Property riscv_harts_props[] = {
      * defined by "rnmi-exception-vector".
      */
     DEFINE_PROP_ARRAY("rnmi-interrupt-vector", RISCVHartArrayState,
-                      num_rnmi_irqvec, rnmi_irqvec, qdev_prop_uint64,
-                      uint64_t),
+                      num_rnmi_irqvec, rnmi_irqvec, qdev_prop_uint64),
     DEFINE_PROP_ARRAY("rnmi-exception-vector", RISCVHartArrayState,
-                      num_rnmi_excpvec, rnmi_excpvec, qdev_prop_uint64,
-                      uint64_t),
+                      num_rnmi_excpvec, rnmi_excpvec, qdev_prop_uint64),
     DEFINE_PROP_LINK("memory", RISCVHartArrayState, memory,
                      TYPE_MEMORY_REGION, MemoryRegion *),
 };
hw/virtio/virtio-iommu-pci.c +1 -1
index 7b5ffddc1e97..1f3a07c5d119 100644
@@ -38,7 +38,7 @@ static const Property virtio_iommu_pci_properties[] = {
     DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
     DEFINE_PROP_ARRAY("reserved-regions", VirtIOIOMMUPCI,
                       vdev.nr_prop_resv_regions, vdev.prop_resv_regions,
-                      qdev_prop_reserved_region, ReservedRegion),
+                      qdev_prop_reserved_region),
 };
 
 static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
include/hw/block/block.h +1 -1
index df941df19f26..70bf03a8de73 100644
@@ -83,7 +83,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
                             _conf.account_failed, ON_OFF_AUTO_AUTO),    \
     DEFINE_PROP_ARRAY("stats-intervals", _state,                        \
                      _conf.num_stats_intervals, _conf.stats_intervals,  \
-                     qdev_prop_uint32, uint32_t)
+                     qdev_prop_uint32)
 
 #define DEFINE_BLOCK_PROPERTIES(_state, _conf)                          \
     DEFINE_PROP_DRIVE("drive", _state, _conf.blk),                      \
include/hw/core/qdev-properties.h +10 -17
index 0c067170079d..39f95ce7a3c6 100644
@@ -76,7 +76,6 @@ extern const PropertyInfo qdev_prop_size;
 extern const PropertyInfo qdev_prop_string;
 extern const PropertyInfo qdev_prop_on_off_auto;
 extern const PropertyInfo qdev_prop_size32;
-extern const PropertyInfo qdev_prop_array;
 extern const PropertyInfo qdev_prop_uint8_list;
 extern const PropertyInfo qdev_prop_uint16_list;
 extern const PropertyInfo qdev_prop_uint32_list;
@@ -148,15 +147,15 @@ extern const PropertyInfo qdev_prop_link_list;
  * @_name: name of the array
  * @_state: name of the device state structure type
  * @_field: uint32_t field in @_state to hold the array length
- * @_arrayfield: field in @_state (of type '@_arraytype *') which
- *               will point to the array
- * @_arrayprop: PropertyInfo defining what property the array elements have
- * @_arraytype: C type of the array elements
+ * @_arrayfield: field in @_state which will point to the array
+ * @_arrayprop: PropertyInfo for the array elements (e.g. qdev_prop_uint32);
+ *              a corresponding list PropertyInfo named @_arrayprop##_list
+ *              must exist
  *
  * Define device properties for a variable-length array _name.  The array is
  * represented as a list in the visitor interface.
  *
- * @_arraytype is required to be movable with memcpy().
+ * The element type must be movable with memcpy().
  *
  * When the array property is set, the @_field member of the device
  * struct is set to the array length, and @_arrayfield is set to point
@@ -166,12 +165,10 @@ extern const PropertyInfo qdev_prop_link_list;
  * @_arrayfield memory.
  */
 #define DEFINE_PROP_ARRAY(_name, _state, _field,                        \
-                          _arrayfield, _arrayprop, _arraytype)          \
-    DEFINE_PROP(_name, _state, _field, qdev_prop_array, uint32_t,       \
+                          _arrayfield, _arrayprop)                      \
+    DEFINE_PROP(_name, _state, _field, _arrayprop##_list, uint32_t,     \
                 .set_default = true,                                    \
                 .defval.u = 0,                                          \
-                .arrayinfo = &(_arrayprop),                             \
-                .arrayfieldsize = sizeof(_arraytype),                   \
                 .arrayoffset = offsetof(_state, _arrayfield))
 
 #define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type)     \
@@ -183,10 +180,8 @@ extern const PropertyInfo qdev_prop_link_list;
  * @_name: name of the array
  * @_state: name of the device state structure type
  * @_field: uint32_t field in @_state to hold the array length
- * @_arrayfield: field in @_state (of type '@_arraytype *') which
- *               will point to the array
+ * @_arrayfield: field in @_state which will point to the array
  * @_linktype: QOM type name of the link type
- * @_arraytype: C type of the array elements
  *
  * Define device properties for a variable-length array _name of links
  * (i.e. this is the array version of DEFINE_PROP_LINK).
@@ -195,12 +190,10 @@ extern const PropertyInfo qdev_prop_link_list;
  * where each string is the QOM path of the object to be linked.
  */
 #define DEFINE_PROP_LINK_ARRAY(_name, _state, _field, _arrayfield,      \
-                               _linktype, _arraytype)                   \
-    DEFINE_PROP(_name, _state, _field, qdev_prop_array, uint32_t,       \
+                               _linktype)                               \
+    DEFINE_PROP(_name, _state, _field, qdev_prop_link_list, uint32_t,   \
                 .set_default = true,                                    \
                 .defval.u = 0,                                          \
-                .arrayinfo = &qdev_prop_link,                           \
-                .arrayfieldsize = sizeof(_arraytype),                   \
                 .arrayoffset = offsetof(_state, _arrayfield),           \
                 .link_type = _linktype)
 
tests/unit/test-qdev.c +1 -1
index 77c3eee71713..8cd004b1efab 100644
@@ -23,7 +23,7 @@ static const Property my_dev_props[] = {
     DEFINE_PROP_UINT32("u32", MyDev, prop_u32, 100),
     DEFINE_PROP_STRING("string", MyDev, prop_string),
     DEFINE_PROP_ARRAY("array-u32", MyDev, prop_array_u32_nb, prop_array_u32,
-                     qdev_prop_uint32, uint32_t),
+                     qdev_prop_uint32),
 };
 
 static void my_dev_class_init(ObjectClass *oc, const void *data)
Signature · 1 line
2.56.0.116.g6de20f6092dc
#86 lore raw

Re: [PATCH v7 60/65] qdev: simplify DEFINE_PROP_ARRAY and remove generic array PropertyInfo

Quoted 10 lines · Marc-André Lureau

Change DEFINE_PROP_ARRAY, the macro now uses _arrayprop##_list to resolve the typed list PropertyInfo (introduced in the previous patch) instead of the generic qdev_prop_array.

This means the element type and size information is carried by the PropertyInfo itself rather than duplicated at each callsite. Since the typed list PropertyInfos encode element_info and element_size, the .arrayinfo and .arrayfieldsize fields are no longer set by the macro (they will be removed from the Property struct in the next patch).

Quoted 4 lines

Remove qdev_prop_array, which is now unused.

I see the type of "gicv5" property "cpus" change from "list", which lazy bad, to "link<arm-cpu>List, which is confused bad.

#87 lore raw

PATCH v7 61/65 qdev: remove deprecated PropertyInfo.type and .enum_table fields

In reply to [email protected]

Now that all PropertyInfo definitions use .qapi_type, remove the legacy .type (string) and .enum_table fields from PropertyInfo, and the .arrayinfo/.arrayfieldsize fields from Property.

Remove fallback branches in qdev_property_add_static() and qdev_class_add_property() that used object_property_add() with prop->info->type: these always use the QAPI-aware registration path now. Simplify qdev_propinfo_enum_lookup(), prop_array_info() and prop_array_elem_size() to use the new fields directly.

---
 hw/core/qdev-properties.c         | 58 ++++++++++++---------------------------
 include/hw/core/qdev-properties.h |  4 ---
 2 files changed, 17 insertions(+), 45 deletions(-)
hw/core/qdev-properties.c +17 -41
index 5c403cc2e57e..a121878467e1 100644
@@ -103,11 +103,8 @@ static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)
 
 const QEnumLookup *qdev_propinfo_enum_lookup(const PropertyInfo *info)
 {
-    if (info->qapi_type) {
-        assert(info->qapi_type->lookup);
-        return info->qapi_type->lookup;
-    }
-    return info->enum_table;
+    assert(info->qapi_type->lookup);
+    return info->qapi_type->lookup;
 }
 
 void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
@@ -668,18 +665,12 @@ struct ArrayElementList {
 
 static const PropertyInfo *prop_array_info(const Property *prop)
 {
-    if (prop->info->element_info) {
-        return prop->info->element_info;
-    }
-    return prop->arrayinfo;
+    return prop->info->element_info;
 }
 
 static int prop_array_elem_size(const Property *prop)
 {
-    if (prop->info->element_size) {
-        return prop->info->element_size;
-    }
-    return prop->arrayfieldsize;
+    return prop->info->element_size;
 }
 
 /*
@@ -1224,20 +1215,13 @@ void qdev_property_add_static(DeviceState *dev, const Property *prop)
     const QAPITypeInfo *qapi_type = qdev_prop_qapi_type(prop);
 
     assert(!prop->info->create);
+    assert(qapi_type);
 
-    if (qapi_type) {
-        op = object_property_add_qapi(obj, prop->name, qapi_type,
-                                      field_prop_getter(prop->info),
-                                      field_prop_setter(prop->info),
-                                      prop->info->release,
-                                      (Property *)prop);
-    } else {
-        op = object_property_add(obj, prop->name, prop->info->type,
-                                 field_prop_getter(prop->info),
-                                 field_prop_setter(prop->info),
-                                 prop->info->release,
-                                 (Property *)prop);
-    }
+    op = object_property_add_qapi(obj, prop->name, qapi_type,
+                                  field_prop_getter(prop->info),
+                                  field_prop_setter(prop->info),
+                                  prop->info->release,
+                                  (Property *)prop);
 
     object_property_set_description(obj, prop->name,
                                     prop->info->description);
@@ -1261,21 +1245,13 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,
     } else {
         const QAPITypeInfo *qapi_type = qdev_prop_qapi_type(prop);
 
-        if (qapi_type) {
-            op = object_class_property_add_qapi(oc,
-                                               name, qapi_type,
-                                               field_prop_getter(prop->info),
-                                               field_prop_setter(prop->info),
-                                               prop->info->release,
-                                               (Property *)prop);
-        } else {
-            op = object_class_property_add(oc,
-                                           name, prop->info->type,
-                                           field_prop_getter(prop->info),
-                                           field_prop_setter(prop->info),
-                                           prop->info->release,
-                                           (Property *)prop);
-        }
+        assert(qapi_type);
+        op = object_class_property_add_qapi(oc,
+                                            name, qapi_type,
+                                            field_prop_getter(prop->info),
+                                            field_prop_setter(prop->info),
+                                            prop->info->release,
+                                            (Property *)prop);
     }
     if (prop->set_default) {
         prop->info->set_default_value(op, prop);
include/hw/core/qdev-properties.h +0 -4
index 39f95ce7a3c6..2267e734d1fd 100644
@@ -23,17 +23,13 @@ struct Property {
         int64_t i;
         uint64_t u;
     } defval;
-    const PropertyInfo *arrayinfo;
     int          arrayoffset;
-    int          arrayfieldsize;
     uint8_t      bitnr;
     bool         set_default;
 };
 
 struct PropertyInfo {
-    const char *type;
     const char *description;
-    const QEnumLookup *enum_table;
     const QAPITypeInfo *qapi_type;
     const struct PropertyInfo *element_info;
     int element_size;
Signature · 1 line
2.56.0.116.g6de20f6092dc
#88 lore raw

Re: [PATCH v7 61/65] qdev: remove deprecated PropertyInfo.type and .enum_table fields

Re title: I think "deprecated" isn't the right word. Let's go with "unused", or maybe

qdev: PropertyInfo.type and .enum_table are no longer used, drop

Quoted 12 lines · Marc-André Lureau

Now that all PropertyInfo definitions use .qapi_type, remove the legacy .type (string) and .enum_table fields from PropertyInfo, and the .arrayinfo/.arrayfieldsize fields from Property.

Remove fallback branches in qdev_property_add_static() and qdev_class_add_property() that used object_property_add() with prop->info->type: these always use the QAPI-aware registration path now. Simplify qdev_propinfo_enum_lookup(), prop_array_info() and prop_array_elem_size() to use the new fields directly.

#89 lore raw

PATCH v7 62/65 hw/i386: convert PCSouthBridgeOption to QAPI enum

In reply to [email protected]

Move PCSouthBridgeOption from a hand-rolled C enum to a proper QAPI enum in qapi/machine.json.

This gives the x-south-bridge property a generated type_info with a valid masked_name, so it appears in query-qmp-schema introspection and the qapi-type field of qom-list-properties output.

The south_bridge/default_south_bridge fields change from const char * to PCSouthBridgeOption, with an explicit mapping table from enum value to QOM device type name.

Enum values are changed: "PIIX3"->"ppix3", "piix4-isa"->"piix4", this is under a x-property, so shouldn't be a breaking change.

---
 hw/i386/pc_piix.c    | 61 ++++++++++++++++------------------------------------
 include/hw/i386/pc.h |  4 ++--
 qapi/machine.json    | 14 ++++++++++++
 3 files changed, 34 insertions(+), 45 deletions(-)
hw/i386/pc_piix.c +18 -43
index 63c4667ea372..5a94a34166d8 100644
@@ -47,6 +47,7 @@
 #include "hw/acpi/acpi.h"
 #include "hw/vfio/types.h"
 #include "qapi/error.h"
+#include "qapi/qapi-type-infos-machine.h"
 #include "qemu/error-report.h"
 #include "system/xen.h"
 #ifdef CONFIG_XEN
@@ -75,6 +76,11 @@ static GlobalProperty pc_piix_compat_defaults[] = {
 static const size_t pc_piix_compat_defaults_len =
     G_N_ELEMENTS(pc_piix_compat_defaults);
 
+static const char *pc_south_bridge_type[] = {
+    [PC_SOUTH_BRIDGE_OPTION_PIIX3] = TYPE_PIIX3_DEVICE,
+    [PC_SOUTH_BRIDGE_OPTION_PIIX4] = TYPE_PIIX4_PCI_DEVICE,
+};
+
 /*
  * Return the global irq number corresponding to a given device irq
  * pin. We could also use the bus number to have a more precise mapping.
@@ -236,7 +242,8 @@ static void pc_init1(MachineState *machine, const char *pci_type)
 
     gsi_state = pc_gsi_create(&x86ms->gsi, true);
 
-    pci_dev = pci_new_multifunction(-1, pcms->south_bridge);
+    pci_dev = pci_new_multifunction(-1,
+                                    pc_south_bridge_type[pcms->south_bridge]);
     object_property_set_bool(OBJECT(pci_dev), "has-usb",
                              machine_usb(machine), &error_abort);
     object_property_set_bool(OBJECT(pci_dev), "has-acpi",
@@ -317,51 +324,18 @@ static void pc_init1(MachineState *machine, const char *pci_type)
     }
 }
 
-typedef enum PCSouthBridgeOption {
-    PC_SOUTH_BRIDGE_OPTION_PIIX3,
-    PC_SOUTH_BRIDGE_OPTION_PIIX4,
-    PC_SOUTH_BRIDGE_OPTION_MAX,
-} PCSouthBridgeOption;
-
-static const QEnumLookup PCSouthBridgeOption_lookup = {
-    .array = (const char *const[]) {
-        [PC_SOUTH_BRIDGE_OPTION_PIIX3] = TYPE_PIIX3_DEVICE,
-        [PC_SOUTH_BRIDGE_OPTION_PIIX4] = TYPE_PIIX4_PCI_DEVICE,
-    },
-    .size = PC_SOUTH_BRIDGE_OPTION_MAX
-};
-
 static int pc_get_south_bridge(Object *obj, Error **errp)
 {
     PCMachineState *pcms = PC_MACHINE(obj);
-    int i;
 
-    for (i = 0; i < PCSouthBridgeOption_lookup.size; i++) {
-        if (g_strcmp0(PCSouthBridgeOption_lookup.array[i],
-                      pcms->south_bridge) == 0) {
-            return i;
-        }
-    }
-
-    error_setg(errp, "Invalid south bridge value set");
-    return 0;
+    return pcms->south_bridge;
 }
 
 static void pc_set_south_bridge(Object *obj, int value, Error **errp)
 {
     PCMachineState *pcms = PC_MACHINE(obj);
 
-    if (value < 0) {
-        error_setg(errp, "Value can't be negative");
-        return;
-    }
-
-    if (value >= PCSouthBridgeOption_lookup.size) {
-        error_setg(errp, "Value too big");
-        return;
-    }
-
-    pcms->south_bridge = PCSouthBridgeOption_lookup.array[value];
+    pcms->south_bridge = value;
 }
 
 #ifdef CONFIG_XEN
@@ -398,7 +372,7 @@ static void pc_i440fx_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     ObjectClass *oc = OBJECT_CLASS(m);
-    pcmc->default_south_bridge = TYPE_PIIX3_DEVICE;
+    pcmc->default_south_bridge = PC_SOUTH_BRIDGE_OPTION_PIIX3;
     pcmc->pci_root_uid = 0;
     pcmc->default_cpu_version = 1;
 
@@ -413,12 +387,13 @@ static void pc_i440fx_machine_options(MachineClass *m)
     machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE);
     machine_class_allow_dynamic_sysbus_dev(m, TYPE_UEFI_VARS_X64);
 
-    object_class_property_add_enum(oc, "x-south-bridge", "PCSouthBridgeOption",
-                                   &PCSouthBridgeOption_lookup,
-                                   pc_get_south_bridge,
-                                   pc_set_south_bridge);
-    object_class_property_set_description(oc, "x-south-bridge",
-                                     "Use a different south bridge than PIIX3");
+    object_class_property_add_qapi_enum(oc, QAPI_ENUM_PROP(
+        .name = "x-south-bridge",
+        .description = "Use a different south bridge than PIIX3",
+        .qapi_type = &PCSouthBridgeOption_type_info,
+        .get = pc_get_south_bridge,
+        .set = pc_set_south_bridge,
+    ));
     compat_props_add(m->compat_props,
                      pc_piix_compat_defaults, pc_piix_compat_defaults_len);
 }
include/hw/i386/pc.h +2 -2
index 8edec62a1af2..3afd376116b1 100644
@@ -47,7 +47,7 @@ typedef struct PCMachineState {
     uint64_t max_ram_below_4g;
     OnOffAuto vmport;
     SmbiosEntryPointType smbios_entry_point_type;
-    const char *south_bridge;
+    PCSouthBridgeOption south_bridge;
 
     bool acpi_build_enabled;
     bool wdat_enabled;
@@ -94,7 +94,7 @@ struct PCMachineClass {
 
     /* Device configuration: */
     bool pci_enabled;
-    const char *default_south_bridge;
+    PCSouthBridgeOption default_south_bridge;
 
     /* Compat options: */
 
qapi/machine.json +14 -0
index 46b6935ab0b8..cc028e890ae5 100644
@@ -462,6 +462,20 @@
 { 'enum': 'Pca9554PinState',
   'data': ['low', 'high'] }
 
+##
+# @PCSouthBridgeOption:
+#
+# South bridge chipset option for PC i440FX machines.
+#
+# @piix3: Intel PIIX3 (default)
+#
+# @piix4: Intel PIIX4
+#
+# Since: 11.2
+##
+{ 'enum': 'PCSouthBridgeOption',
+  'data': ['piix3', 'piix4'] }
+
 ##
 # @inject-nmi:
 #     Injects a Non-Maskable Interrupt (machine specific: for example
Signature · 1 line
2.56.0.116.g6de20f6092dc
#90 lore raw

PATCH v7 63/65 qom: remove old enum property registration API

In reply to [email protected]

Now that all callers use object_class_property_add_qapi_enum(), remove the legacy object_property_add_enum() and object_class_property_add_enum() functions along with their EnumProperty struct and property_get_enum / property_set_enum helpers.

Simplify object_property_get_enum() to assert on qapi_type rather than falling back to the old EnumProperty opaque data.

---
 include/qom/object.h | 45 ++--------------------------
 qom/object.c         | 82 ++--------------------------------------------------
 2 files changed, 4 insertions(+), 123 deletions(-)
include/qom/object.h +2 -43
index 29cbd84b8d03..a9bbc44cfcc9 100644
@@ -1697,12 +1697,12 @@ char *object_get_canonical_path(const Object *obj);
  *   because it was ambiguous, or %NULL. Set to %false on success.
  *
  * There are two types of supported paths--absolute paths and partial paths.
- * 
+ *
  * Absolute paths are derived from the root object and can follow child<> or
  * link<> properties.  Since they can follow link<> properties, they can be
  * arbitrarily long.  Absolute paths look like absolute filenames and are
  * prefixed with a leading slash.
- * 
+ *
  * Partial paths look like relative filenames.  They do not begin with a
  * prefix.  The matching rules for partial paths are subtle but designed to make
  * specifying objects easy.  At each level of the composition tree, the partial
@@ -1986,47 +1986,6 @@ ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
                                     bool (*get)(Object *, Error **),
                                     void (*set)(Object *, bool, Error **));
 
-/**
- * object_property_add_enum:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @typename: the name of the enum data type
- * @lookup: enum value namelookup table
- * @get: the getter or %NULL if the property is write-only.
- * @set: the setter or %NULL if the property is read-only
- *
- * Add an enum property using getters/setters.  This function will add a
- * property of type '@typename'.
- *
- * Returns: The newly added property on success, or %NULL on failure.
- */
-ObjectProperty *object_property_add_enum(Object *obj, const char *name,
-                              const char *typename,
-                              const QEnumLookup *lookup,
-                              int (*get)(Object *, Error **),
-                              void (*set)(Object *, int, Error **));
-
-/**
- * object_class_property_add_enum:
- * @klass: the object class to add a property to
- * @name: the name of the property
- * @typename: the name of the enum data type
- * @lookup: enum value namelookup table
- * @get: the getter or %NULL if the property is write-only.
- * @set: the setter or %NULL if the property is read-only
- *
- * Add an enum property using getters/setters.  This function will add a
- * property of type '@typename'.
- *
- * Returns: The newly added property on success, or %NULL on failure.
- */
-ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
-                                    const char *name,
-                                    const char *typename,
-                                    const QEnumLookup *lookup,
-                                    int (*get)(Object *, Error **),
-                                    void (*set)(Object *, int, Error **));
-
 /**
  * struct QapiEnumProp: Descriptor for a property backed by a QAPI enum type
  *
qom/object.c +2 -80

100 lines not on this page · raw message

Signature · 1 line
2.56.0.116.g6de20f6092dc
#91 lore raw

PATCH v7 64/65 qom: use QAPITypeInfo in object_property_get_enum

In reply to [email protected]

The typename parameter becomes a QAPITypeInfo pointer, and the validation compares prop->qapi_type against it instead of matching prop->type strings.

---
 hw/core/machine-qmp-cmds.c      | 4 +++-
 include/qom/object.h            | 4 ++--
 qom/object.c                    | 8 ++++----
 tests/unit/check-qom-proplist.c | 6 +++---
 4 files changed, 12 insertions(+), 10 deletions(-)
hw/core/machine-qmp-cmds.c +3 -1
index 3fee45d568da..6b425baeb2da 100644
@@ -18,6 +18,7 @@
 #include "qapi/qapi-commands-accelerator.h"
 #include "qapi/qapi-commands-machine.h"
 #include "qobject/qobject.h"
+#include "qapi/qapi-type-infos-common.h"
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/type-helpers.h"
 #include "qemu/uuid.h"
@@ -252,7 +253,8 @@ static int query_memdev(Object *obj, void *opaque)
         } else {
             m->has_reserve = true;
         }
-        m->policy = object_property_get_enum(obj, "policy", "HostMemPolicy",
+        m->policy = object_property_get_enum(obj, "policy",
+                                             &HostMemPolicy_type_info,
                                              &error_abort);
         host_nodes = object_property_get_qobject(obj,
                                                  "host-nodes",
include/qom/object.h +2 -2
index a9bbc44cfcc9..9f937e30dae5 100644
@@ -1566,7 +1566,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
  * object_property_get_enum:
  * @obj: the object
  * @name: the name of the property
- * @typename: the name of the enum data type
+ * @type_info: the QAPITypeInfo of the enum
  * @errp: returns an error if this function fails
  *
  * Returns: the value of the property, converted to an integer (which
@@ -1574,7 +1574,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
  * value is not an enum).
  */
 int object_property_get_enum(Object *obj, const char *name,
-                             const char *typename, Error **errp);
+                             const QAPITypeInfo *type_info, Error **errp);
 
 /**
  * object_property_set:
qom/object.c +4 -4
index 791d981dc689..40b569d4d574 100644
@@ -1775,7 +1775,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
 }
 
 int object_property_get_enum(Object *obj, const char *name,
-                             const char *typename, Error **errp)
+                             const QAPITypeInfo *type_info, Error **errp)
 {
     char *str;
     int ret;
@@ -1785,10 +1785,10 @@ int object_property_get_enum(Object *obj, const char *name,
         return -1;
     }
 
-    if (!g_str_equal(prop->type, typename)) {
+    if (prop->qapi_type != type_info) {
         error_setg(errp, "Property %s on %s is not '%s' enum type",
-                   name, object_class_get_name(
-                       object_get_class(obj)), typename);
+                   name, object_class_get_name(object_get_class(obj)),
+                   type_info->name);
         return -1;
     }
 
tests/unit/check-qom-proplist.c +3 -3
index 69155e720751..1cb48c7490ef 100644
@@ -582,14 +582,14 @@ static void test_dummy_getenum(void)
 
     val = object_property_get_enum(OBJECT(dobj),
                                    "av",
-                                   "DummyAnimal",
+                                   &dummy_animal_qapi_type_info,
                                    &error_abort);
     g_assert(val == DUMMY_PLATYPUS);
 
     /* A bad enum type name */
     val = object_property_get_enum(OBJECT(dobj),
                                    "av",
-                                   "BadAnimal",
+                                   &dummy_str_qapi_type_info,
                                    &err);
     g_assert(val == -1);
     error_free_or_abort(&err);
@@ -597,7 +597,7 @@ static void test_dummy_getenum(void)
     /* A non-enum property name */
     val = object_property_get_enum(OBJECT(dobj),
                                    "iv",
-                                   "DummyAnimal",
+                                   &dummy_animal_qapi_type_info,
                                    &err);
     g_assert(val == -1);
     error_free_or_abort(&err);
Signature · 1 line
2.56.0.116.g6de20f6092dc
#92 lore raw

Re: [PATCH v7 64/65] qom: use QAPITypeInfo in object_property_get_enum

Quoted 6 lines · Marc-André Lureau

The typename parameter becomes a QAPITypeInfo pointer, and the validation compares prop->qapi_type against it instead of matching prop->type strings.

[...]

Quoted 14 lines
qom/object.c +1 -1
index 791d981dc689..40b569d4d574 100644
@@ -1775,7 +1775,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
 }
 
 int object_property_get_enum(Object *obj, const char *name,
-                             const char *typename, Error **errp)
+                             const QAPITypeInfo *type_info, Error **errp)
 {
     char *str;
     int ret;

qom/object.c int object_property_get_enum(Object *obj, const char *name, · line 1791

Quoted 10 lines
qom/object.c +3 -3
@@ -1785,10 +1785,10 @@ int object_property_get_enum(Object *obj, const char *name,
         return -1;
     }
 
-    if (!g_str_equal(prop->type, typename)) {
+    if (prop->qapi_type != type_info) {
         error_setg(errp, "Property %s on %s is not '%s' enum type",
-                   name, object_class_get_name(
-                       object_get_class(obj)), typename);
+                   name, object_class_get_name(object_get_class(obj)),
+                   type_info->name);

How can this happen? Or is it a programming error?

Quoted 3 lines
qom/object.c +0 -0
         return -1;
     }
 

[...]

#93 lore raw

PATCH v7 65/65 tests/qmp-cmd-test: assert qapi-type resolves in query-qmp-schema

In reply to [email protected]

For every QOM type returned by qom-list-types, call qom-list-properties and verify that each property's qapi-type value (when present) maps to a valid entry in the query-qmp-schema introspection output.

The test is gated behind g_test_slow() since it iterates all registered QOM types.

---
 tests/qtest/qmp-cmd-test.c | 55 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)
tests/qtest/qmp-cmd-test.c +54 -1
index 279a8f5614e9..acb7b0dd6a9f 100644
@@ -15,6 +15,7 @@
 #include "qapi/error.h"
 #include "qapi/qapi-visit-introspect.h"
 #include "qobject/qdict.h"
+#include "qobject/qlist.h"
 #include "qapi/qobject-input-visitor.h"
 
 const char common_args[] = "-nodefaults -machine none";
@@ -131,6 +132,8 @@ typedef struct {
     GHashTable *hash;
 } QmpSchema;
 
+static QmpSchema schema;
+
 static void qmp_schema_init(QmpSchema *schema)
 {
     QDict *resp;
@@ -343,9 +346,56 @@ static void test_object_add_failure_modes(void)
     qtest_quit(qts);
 }
 
+static void test_qapi_type(void)
+{
+    QTestState *qts;
+    g_autoptr(QDict) resp = NULL;
+    QList *types;
+    QListEntry *type_entry, *prop_entry;
+
+    qts = qtest_init(common_args);
+
+    resp = qtest_qmp(qts,
+                     "{ 'execute': 'qom-list-types',"
+                     "  'arguments': { 'abstract': true } }");
+    g_assert(qdict_haskey(resp, "return"));
+    types = qdict_get_qlist(resp, "return");
+
+    QLIST_FOREACH_ENTRY(types, type_entry) {
+        QDict *type = qobject_to(QDict, qlist_entry_obj(type_entry));
+        const char *name = qdict_get_str(type, "name");
+        g_autoptr(QDict) props_resp = NULL;
+        QList *props;
+
+        props_resp = qtest_qmp(qts,
+                               "{ 'execute': 'qom-list-properties',"
+                               "  'arguments': { 'typename': %s } }",
+                               name);
+        if (!qdict_haskey(props_resp, "return")) {
+            continue;
+        }
+        props = qdict_get_qlist(props_resp, "return");
+
+        QLIST_FOREACH_ENTRY(props, prop_entry) {
+            QDict *prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+            const char *qapi_type = qdict_get_try_str(prop, "qapi-type");
+            const char *propname = qdict_get_str(prop, "name");
+            const char *ty = qdict_get_str(prop, "type");
+
+            if (qapi_type) {
+                g_assert_nonnull(qmp_schema_lookup(&schema, qapi_type));
+            } else if (!g_str_has_prefix(ty, "child<") &&
+                       !g_str_has_prefix(ty, "link<")) {
+                g_test_message("%s.%s %s has no associated qapi-type",
+                               name, propname, ty);
+            }
+        }
+    }
+    qtest_quit(qts);
+}
+
 int main(int argc, char *argv[])
 {
-    QmpSchema schema;
     int ret;
 
     g_test_init(&argc, &argv, NULL);
@@ -355,6 +405,9 @@ int main(int argc, char *argv[])
 
     qtest_add_func("qmp/object-add-failure-modes",
                    test_object_add_failure_modes);
+    if (g_test_slow()) {
+        qtest_add_func("qmp/qapi-type", test_qapi_type);
+    }
 
     ret = g_test_run();
 
Signature · 1 line
2.56.0.116.g6de20f6092dc
#94 lore raw

Property types changed in this series (was: [PATCH v7 00/65] Hi)

In reply to [email protected]

I used qom-list-types and qom-list-properties to list all properties and their types, then looked for changes. This can miss changes in dynamically created properties; see the note on qom-list-properties in qapi/qom.json. Moreover, I ran into a few QOM types where qom-list-properties is broken.

1. Close misses of QAPI type names change to actual QAPI type names

old property type new property type
---------------------------------------------
string str
uint64_t uint64
uint64_t size
int32_t int32
int size
uint32_t uint32
[uint16] uint16List
NotifyVMexitOption NotifyVmexitOption
CXLFixedMemoryWindow CXLFixedMemoryWindowOptionsList

2. Incorrect QAPI type names change to correct ones

old property type new property type
---------------------------------------------
SgxEPC SgxEPCList
QAuthZListRule QAuthZListRuleList
X86CPUFeatureWordInfo X86CPUFeatureWordInfoList
bool Pca9552LedState

3. Less than useful QAPI type names change to more useful ones

old property type new property type
---------------------------------------------
str Pca9552PinState
str Pca9554PinState

4. Lazy crap

old property type new property type
---------------------------------------------
list link<arm-cpu>List
list strList
list uint16List
list uint32List
list uint64List
list uint8List
struct any

I'm not sure the first one is what it should be.

I need to have a closer look at the last one.

5. Inventive crap

old property type new property type
---------------------------------------------
busnr uint8
guest statistics VirtioBalloonGuestStats
loadparm str
on|off|split OnOffSplit
struct tm StructTm

6. An odd duck

old property type new property type
---------------------------------------------
str int32

This is pci-device property addr. See PATCH 54.

On the way, I noted properties with anti-social names:

QOM type name property name
---------------------------------
acpi-ged memhp container[0]
e500-spin e500 spin pv device[0]

#95 lore raw

Re: Property types changed in this series

Libvirt developers: does libvirt use member @type of the reply of qom-list, qom-list-properties, qom-list-get?

I'm asking because Marc-André's work changes many values to add a more useful replacement. I think we should deprecate @type. I'd like to find out whether we need to preserve the values for the deprecation grace period.

Quoted 5 lines · Markus Armbruster

I used qom-list-types and qom-list-properties to list all properties and their types, then looked for changes. This can miss changes in dynamically created properties; see the note on qom-list-properties in qapi/qom.json. Moreover, I ran into a few QOM types where qom-list-properties is broken.

These are ast2700-a1, ast2700-a2, and several riscv CPUs. A fix for the latter has been queued.

Quoted 70 lines

1. Close misses of QAPI type names change to actual QAPI type names

old property type new property type
---------------------------------------------
string str
uint64_t uint64
uint64_t size
int32_t int32
int size
uint32_t uint32
[uint16] uint16List
NotifyVMexitOption NotifyVmexitOption
CXLFixedMemoryWindow CXLFixedMemoryWindowOptionsList

2. Incorrect QAPI type names change to correct ones

old property type new property type
---------------------------------------------
SgxEPC SgxEPCList
QAuthZListRule QAuthZListRuleList
X86CPUFeatureWordInfo X86CPUFeatureWordInfoList
bool Pca9552LedState

3. Less than useful QAPI type names change to more useful ones

old property type new property type
---------------------------------------------
str Pca9552PinState
str Pca9554PinState

4. Lazy crap

old property type new property type
---------------------------------------------
list link<arm-cpu>List
list strList
list uint16List
list uint32List
list uint64List
list uint8List
struct any

I'm not sure the first one is what it should be.

I need to have a closer look at the last one.

5. Inventive crap

old property type new property type
---------------------------------------------
busnr uint8
guest statistics VirtioBalloonGuestStats
loadparm str
on|off|split OnOffSplit
struct tm StructTm

6. An odd duck

old property type new property type
---------------------------------------------
str int32

This is pci-device property addr. See PATCH 54.

On the way, I noted properties with anti-social names:

QOM type name property name
---------------------------------
acpi-ged memhp container[0]
e500-spin e500 spin pv device[0]

#96 lore raw

Re: Property types changed in this series

Quoted 3 lines · Markus Armbruster via Devel

Libvirt developers: does libvirt use member @type of the reply of qom-list, qom-list-properties, qom-list-get?

The code for getting CPU properties uses qom-list-get for new QEMUs, where it checks whether "type" is "bool".

I think that can be easily converted to just check for the JSON type.

Jano

Quoted 5 lines

I'm asking because Marc-André's work changes many values to add a more useful replacement. I think we should deprecate @type. I'd like to find out whether we need to preserve the values for the deprecation grace period.

#97 lore raw

ObjectPropertyInfo design (was: [PATCH v7 00/65] Hi)

In reply to [email protected]

Marc-André's series evolves ObjectPropertyInfo and ObjectPropertyValue:
it adds member @qapi-type and changes many values of member @type.

I'd like to take a step back and discuss design. I trimmed Cc:
accordingly.

= The current interface

qom-list returns information on an object's properties, one ObjectPropertyInfo per property.

qom-list-properties returns information on properties an instance of a type is known to have[*], one ObjectPropertyInfo per property.

qom-list-get returns information on the properties of several objects, one ObjectPropertyValue per property.

ObjectPropertyInfo and ObjectPropertyValue provide @name and @type.

ObjectPropertyInfo additionally provides @description and @default-value, both optional.

ObjectPropertyValue additionally provides optional @value, absent when the property cannot be read.

If ObjectPropertyValue was an extension of ObjectPropertyInfo, then qom-list-get would be a strictly more powerful version of qom-list. It isn't. However, I think the information lost when moving from qom-list to qom-list-get is not useful:

* @description is rarely present (I see under 15% in a quick test). The description text is commonly misleading for QMP. For instance, qdev bool properties have description "on/off". The possible values are actually JSON false and true.

* @default-value can be useful with qom-list-properties, which operates on types. I doubt it is with qom-list, which operates on objects.

Let's pretend @description doesn't exist, and @default-value exists only with qom-list-properties.

This makes qom-list-get strictly more powerful than qom-list, so let's further pretend qom-list doesn't exist.

= Simplified interface for the sake of discussion

qom-list-properties returns information on properties an instance of a type is known to have[*]: @name, @type, and maybe @default-value.

qom-list-get returns information on the properties of several objects:
@name, @type, and maybe @value.

= The meaning of @type

Three cases:

1. For a child property (created with object_property_add_child() etc.), @type is "child<T>", where T is the child's QOM type.

2. For a link property (created with object_class_property_add_link() etc.), @type is "link<T>", where T is the target's QOM type.

3. For other properties, @type can be anything. We commonly use QAPI type names (occasionally misspelled), and also "well-known" (but undocumented) non-QAPI names for primitive types. Every now and then, developers get lazy and use values like "list", or creative and use values like "guest statistics". Nobody has gotten sufficiently masochistic to use values starting with "child<" or "link<" so far, although nothing would stop that.

Cases 1 and 2 go against the QAPI/QMP design maxim "don't encode stuff in strings".

Case 3 is is hard to use for anything. You're forced into stupid and brittle hardcoding.

Marc-André's work adds a new optional member @qapi_type that refers to a QAPI type in the output of query-qmp-schema. It's present for a large subset of case 3. When it's present, @type should not be used.

It also cleans up many crap cases of 3, but without making it robust. I understand this isn't something the series tries to do, it's just something that's easier to do than not to do. If it creates compatibility problems, we have to not do it. I hope it doesn't.

= Can we do better?

What information are we trying to convey? Four cases:

1. Child property: the child's QOM type

2. Link property: the target's QOM type

3. QAPI-backed property: the property's QAPI type

4. Other property: we have nothing useful to offer

Case 4 should go away eventually.

How would we encode this in QAPI on a green field? With a union, of course:

    { 'enum': 'ObjectPropertyKind',
      'data': [ 'child', 'link', 'qapi', 'other'] }

    { 'struct': 'ObjectPropertyInfoLink',
      'data': { 'qom-type': 'str' } }

    { 'struct': 'ObjectPropertyInfoQAPI',
      'data': { 'qapi-type': 'str' } }

    { 'union': 'ObjectProperty...',
      'base': { 'kind': 'ObjectPropertyKind',
                ... more ... },
      'discriminator': 'kind',
      'data': {
          'child': 'ObjectPropertyInfoLink',
          'link': 'ObjectPropertyInfoLink',
          'qapi': 'ObjectPropertyInfoQAPI' } }

To make this a compatible evolution of ObjectPropertyInfo, we need ... more ... to be

                'type': 'str',
                '*description': 'str'
                '*default-value': 'any',

Sadly, we need to duplicate the union for ObjectPropertyValue. There, ... more ... needs to be

                'type': 'str',
                '*value': 'any'

We should deprecate @type. I'd also deprecate @description.

Thoughts?

[*] It may have more; see the note in the doc comment of qom-list-properties.

#98 lore raw

Re: ObjectPropertyInfo design (was: [PATCH v7 00/65] Hi)

Hi

Quoted 132 lines · Markus Armbruster

Marc-André's series evolves ObjectPropertyInfo and ObjectPropertyValue:
it adds member @qapi-type and changes many values of member @type.

I'd like to take a step back and discuss design. I trimmed Cc:
accordingly.

= The current interface

qom-list returns information on an object's properties, one ObjectPropertyInfo per property.

qom-list-properties returns information on properties an instance of a type is known to have[*], one ObjectPropertyInfo per property.

qom-list-get returns information on the properties of several objects, one ObjectPropertyValue per property.

ObjectPropertyInfo and ObjectPropertyValue provide @name and @type.

ObjectPropertyInfo additionally provides @description and @default-value, both optional.

ObjectPropertyValue additionally provides optional @value, absent when the property cannot be read.

If ObjectPropertyValue was an extension of ObjectPropertyInfo, then qom-list-get would be a strictly more powerful version of qom-list. It isn't. However, I think the information lost when moving from qom-list to qom-list-get is not useful:

* @description is rarely present (I see under 15% in a quick test). The description text is commonly misleading for QMP. For instance, qdev bool properties have description "on/off". The possible values are actually JSON false and true.

* @default-value can be useful with qom-list-properties, which operates on types. I doubt it is with qom-list, which operates on objects.

Let's pretend @description doesn't exist, and @default-value exists only with qom-list-properties.

This makes qom-list-get strictly more powerful than qom-list, so let's further pretend qom-list doesn't exist.

= Simplified interface for the sake of discussion

qom-list-properties returns information on properties an instance of a type is known to have[*]: @name, @type, and maybe @default-value.

qom-list-get returns information on the properties of several objects:
@name, @type, and maybe @value.

= The meaning of @type

Three cases:

1. For a child property (created with object_property_add_child() etc.), @type is "child<T>", where T is the child's QOM type.

2. For a link property (created with object_class_property_add_link() etc.), @type is "link<T>", where T is the target's QOM type.

3. For other properties, @type can be anything. We commonly use QAPI type names (occasionally misspelled), and also "well-known" (but undocumented) non-QAPI names for primitive types. Every now and then, developers get lazy and use values like "list", or creative and use values like "guest statistics". Nobody has gotten sufficiently masochistic to use values starting with "child<" or "link<" so far, although nothing would stop that.

Cases 1 and 2 go against the QAPI/QMP design maxim "don't encode stuff in strings".

Case 3 is is hard to use for anything. You're forced into stupid and brittle hardcoding.

Marc-André's work adds a new optional member @qapi_type that refers to a QAPI type in the output of query-qmp-schema. It's present for a large subset of case 3. When it's present, @type should not be used.

It also cleans up many crap cases of 3, but without making it robust. I understand this isn't something the series tries to do, it's just something that's easier to do than not to do. If it creates compatibility problems, we have to not do it. I hope it doesn't.

= Can we do better?

What information are we trying to convey? Four cases:

1. Child property: the child's QOM type

2. Link property: the target's QOM type

3. QAPI-backed property: the property's QAPI type

4. Other property: we have nothing useful to offer

Case 4 should go away eventually.

How would we encode this in QAPI on a green field? With a union, of course:

    { 'enum': 'ObjectPropertyKind',
      'data': [ 'child', 'link', 'qapi', 'other'] }

    { 'struct': 'ObjectPropertyInfoLink',
      'data': { 'qom-type': 'str' } }

    { 'struct': 'ObjectPropertyInfoQAPI',
      'data': { 'qapi-type': 'str' } }

    { 'union': 'ObjectProperty...',
      'base': { 'kind': 'ObjectPropertyKind',
                ... more ... },
      'discriminator': 'kind',
      'data': {
          'child': 'ObjectPropertyInfoLink',
          'link': 'ObjectPropertyInfoLink',
          'qapi': 'ObjectPropertyInfoQAPI' } }

To make this a compatible evolution of ObjectPropertyInfo, we need ... more ... to be

                'type': 'str',
                '*description': 'str'
                '*default-value': 'any',
Quoted 7 lines

Sadly, we need to duplicate the union for ObjectPropertyValue. There, ... more ... needs to be

                'type': 'str',
                '*value': 'any'

We should deprecate @type. I'd also deprecate @description.

It's optional, I don't think that hurts.

Quoted 1 line

Thoughts?

I like it overall.

But this goes beyond the intended scope of the series. Blending/merging QOM type & QAPI type would warrant more design research. So covering child<> & link<> are out of scope of the current qom-qapi series. I think the addition of qapi-type shouldn't be incompatible with a future proposal, after all all properties should have some 'wire' type (link/child are paths). But we can drop it for now or just rename it x-qapi-type until we agree on the new introspection.

my2c

#99 lore raw

Re: ObjectPropertyInfo design

Marc-André Lureau <[email protected]> writes:

[Possible improvement to the QAPI/QMP QOM introspection interface...]

Quoted 13 lines
Quoted 1 line

Thoughts?

I like it overall.

But this goes beyond the intended scope of the series. Blending/merging QOM type & QAPI type would warrant more design research. So covering child<> & link<> are out of scope of the current qom-qapi series. I think the addition of qapi-type shouldn't be incompatible with a future proposal, after all all properties should have some 'wire' type (link/child are paths). But we can drop it for now or just rename it x-qapi-type until we agree on the new introspection.

Quoted 1 line

my2c

Adding @qapi-type with feature unstable means we don't have to worry about the external interface now. One less hurdle for merging. I like it.

Whether changing the @type values is safe remains somewhat unclear. See

Subject: Property types changed in this series (was: [PATCH v7 00/65] Hi)
Date: Wed, 21 Oct 2026 18:29:40 +0200
Message-ID: <[email protected]>

#100 lore raw

Re: ObjectPropertyInfo design

Quoted 23 lines · Markus Armbruster

Marc-André Lureau <[email protected]> writes:

[Possible improvement to the QAPI/QMP QOM introspection interface...]

Quoted 13 lines
Quoted 1 line

Thoughts?

I like it overall.

But this goes beyond the intended scope of the series. Blending/merging QOM type & QAPI type would warrant more design research. So covering child<> & link<> are out of scope of the current qom-qapi series. I think the addition of qapi-type shouldn't be incompatible with a future proposal, after all all properties should have some 'wire' type (link/child are paths). But we can drop it for now or just rename it x-qapi-type until we agree on the new introspection.

Quoted 1 line

my2c

Adding @qapi-type with feature unstable means we don't have to worry about the external interface now. One less hurdle for merging. I like it.

Quoted 5 lines

Whether changing the @type values is safe remains somewhat unclear. See

Subject: Property types changed in this series (was: [PATCH v7 00/65] Hi)
Date: Wed, 21 Oct 2026 18:29:40 +0200
Message-ID: <[email protected]>

We're about to miss the soft freeze. Not your fault; I've been awfully slow reviewing this.

The series is quite big. If we can't get it merged, we'll have to rebase and update it. Not good.

Here's a possible way forward:

1. We tweak this series to retain the existing @type values.

As is, the series changes @type to the QAPI type where applicable. This is an improvement, and *probably* safe enough, but I'm reluctant to accept the risk this late in the development cycle.

I can do the tweaking. It'll be mildly icky, but should go away fairly soon.

2. We mark @qapi-type unstable for now.

3. Try hard to get it merged in time for 11.2.

We can then improve on top at our leisure:

* If we convince ourselves that changing @type values is worthwhile and safe enough, do so early in a development cycle.

* Hunt down the remaining properties that don't use a QAPI type.

* Explore more comprehensive improvements to QOM introspection.

* Settle on a new QOM introspection interface, deprecate the old crap.

What do you think, Marc-André?

#101 lore raw

Re: ObjectPropertyInfo design

Hi

Quoted 40 lines · Markus Armbruster
Quoted 23 lines · Markus Armbruster

Marc-André Lureau <[email protected]> writes:

[Possible improvement to the QAPI/QMP QOM introspection interface...]

Quoted 13 lines
Quoted 1 line

Thoughts?

I like it overall.

But this goes beyond the intended scope of the series. Blending/merging QOM type & QAPI type would warrant more design research. So covering child<> & link<> are out of scope of the current qom-qapi series. I think the addition of qapi-type shouldn't be incompatible with a future proposal, after all all properties should have some 'wire' type (link/child are paths). But we can drop it for now or just rename it x-qapi-type until we agree on the new introspection.

Quoted 1 line

my2c

Adding @qapi-type with feature unstable means we don't have to worry about the external interface now. One less hurdle for merging. I like it.

Quoted 5 lines

Whether changing the @type values is safe remains somewhat unclear. See

Subject: Property types changed in this series (was: [PATCH v7 00/65] Hi)
Date: Wed, 21 Oct 2026 18:29:40 +0200
Message-ID: <[email protected]>

We're about to miss the soft freeze. Not your fault; I've been awfully slow reviewing this.

The series is quite big. If we can't get it merged, we'll have to rebase and update it. Not good.

Here's a possible way forward:

Quoted 8 lines

1. We tweak this series to retain the existing @type values.

As is, the series changes @type to the QAPI type where applicable. This is an improvement, and *probably* safe enough, but I'm reluctant to accept the risk this late in the development cycle.

I can do the tweaking. It'll be mildly icky, but should go away fairly soon.

Tbh, I don't think changing @type is going to hurt, and if it effectively does, we still have the rc period or backports as necessary.

Quoted 2 lines

2. We mark @qapi-type unstable for now.

yes

Quoted 5 lines

3. Try hard to get it merged in time for 11.2.

We can then improve on top at our leisure:

Quoted 8 lines

* If we convince ourselves that changing @type values is worthwhile and safe enough, do so early in a development cycle.

* Hunt down the remaining properties that don't use a QAPI type.

* Explore more comprehensive improvements to QOM introspection.

* Settle on a new QOM introspection interface, deprecate the old crap.

I think we should flush the queue, because it's natural to stop working on a "topic" when it reaches >50 pending patches. And it prevents other people from joining the effort too. If it takes >6 months to get 50 patches accepted, the QOM-QAPI dilemna is going to stay for a long time :)

#102 lore raw

Re: ObjectPropertyInfo design

Quoted 49 lines · Marc-André Lureau

Hi

Quoted 46 lines · Markus Armbruster
Quoted 23 lines · Markus Armbruster

Marc-André Lureau <[email protected]> writes:

[Possible improvement to the QAPI/QMP QOM introspection interface...]

Quoted 13 lines
Quoted 1 line

Thoughts?

I like it overall.

But this goes beyond the intended scope of the series. Blending/merging QOM type & QAPI type would warrant more design research. So covering child<> & link<> are out of scope of the current qom-qapi series. I think the addition of qapi-type shouldn't be incompatible with a future proposal, after all all properties should have some 'wire' type (link/child are paths). But we can drop it for now or just rename it x-qapi-type until we agree on the new introspection.

Quoted 1 line

my2c

Adding @qapi-type with feature unstable means we don't have to worry about the external interface now. One less hurdle for merging. I like it.

Quoted 5 lines

Whether changing the @type values is safe remains somewhat unclear. See

Subject: Property types changed in this series (was: [PATCH v7 00/65] Hi)
Date: Wed, 21 Oct 2026 18:29:40 +0200
Message-ID: <[email protected]>

We're about to miss the soft freeze. Not your fault; I've been awfully slow reviewing this.

The series is quite big. If we can't get it merged, we'll have to rebase and update it. Not good.

Here's a possible way forward:

1. We tweak this series to retain the existing @type values.

As is, the series changes @type to the QAPI type where applicable. This is an improvement, and *probably* safe enough, but I'm reluctant to accept the risk this late in the development cycle.

Quoted 6 lines
Quoted 2 lines

I can do the tweaking. It'll be mildly icky, but should go away fairly soon.

Tbh, I don't think changing @type is going to hurt, and if it effectively does, we still have the rc period or backports as necessary.

I don't think the changed values are enough of an improvement to be worth the risk and the churn.

Retaining the existing values turned out to be much less icky than I thought.

Quoted 3 lines
Quoted 1 line

2. We mark @qapi-type unstable for now.

yes

Done.

Quoted 11 lines
Quoted 11 lines

3. Try hard to get it merged in time for 11.2.

We can then improve on top at our leisure:

* If we convince ourselves that changing @type values is worthwhile and safe enough, do so early in a development cycle.

* Hunt down the remaining properties that don't use a QAPI type.

* Explore more comprehensive improvements to QOM introspection.

Quoted 7 lines
Quoted 1 line

* Settle on a new QOM introspection interface, deprecate the old crap.

I think we should flush the queue, because it's natural to stop working on a "topic" when it reaches >50 pending patches. And it prevents other people from joining the effort too. If it takes >6 months to get 50 patches accepted, the QOM-QAPI dilemna is going to stay for a long time :)

Oh yes, we should flush the queue.

This series took me waaaay too long. Series as big as this one take big chunks of uninterrupted time to process, and these are hard for me to come by. I should've gone "I do this series now whatever it takes, and screw everything else" much earlier.

My sincere apologies.

#103 lore raw

Re: ObjectPropertyInfo design (was: [PATCH v7 00/65] Hi)

In reply to Markus Armbruster
Quoted 7 lines · Markus Armbruster

Marc-André's series evolves ObjectPropertyInfo and ObjectPropertyValue:
it adds member @qapi-type and changes many values of member @type.

I'd like to take a step back and discuss design. I trimmed Cc:
accordingly.

Quoted 7 lines

= The current interface

qom-list returns information on an object's properties, one ObjectPropertyInfo per property.

qom-list-properties returns information on properties an instance of a type is known to have[*], one ObjectPropertyInfo per property.

This is

Quoted 3 lines

qom-list-get returns information on the properties of several objects, one ObjectPropertyValue per property.

Since 'qom-list-properties' is really introspecting types, rather than instances, I'd add its companion:

query-qmp-schema returns information on properties from user creatable QOM objects, via the ObjectOptions union which handles data of arbitary complexity and nesting, with strictly QAPI types only. Obviously missing QDev and other internal only types.

Quoted 4 lines

* @description is rarely present (I see under 15% in a quick test). The description text is commonly misleading for QMP. For instance, qdev bool properties have description "on/off". The possible values are actually JSON false and true.

With query-qmp-schema we have a description for 100% of properties, enforced by the QAPI schema parser. Only applies to UserCreatable QOM objects though.

I see descriptions as primarily a documentation thing for humans, and perhaps for machines which are trying to generate code frmo QAPI schema and want to use descriptions for docs. These are both static querying tasks.

I don't see descriptions as useful for mgmt apps at runtime for deployed QEMus.

Quoted 2 lines

* @default-value can be useful with qom-list-properties, which operates on types. I doubt it is with qom-list, which operates on objects.

Likewise, IMHO this is useful info statically, but not at runtime.

Quoted 11 lines

Let's pretend @description doesn't exist, and @default-value exists only with qom-list-properties.

This makes qom-list-get strictly more powerful than qom-list, so let's further pretend qom-list doesn't exist.

= Simplified interface for the sake of discussion

qom-list-properties returns information on properties an instance of a type is known to have[*]: @name, @type, and maybe @default-value.

In the ideal world 'qom-list-properties' would not need to exist, but it has to for the forseeable future, since none of QDev is modelled in QAPI schema currently.

Quoted 22 lines

qom-list-get returns information on the properties of several objects:
@name, @type, and maybe @value.

= The meaning of @type

Three cases:

1. For a child property (created with object_property_add_child() etc.), @type is "child<T>", where T is the child's QOM type.

2. For a link property (created with object_class_property_add_link() etc.), @type is "link<T>", where T is the target's QOM type.

3. For other properties, @type can be anything. We commonly use QAPI type names (occasionally misspelled), and also "well-known" (but undocumented) non-QAPI names for primitive types. Every now and then, developers get lazy and use values like "list", or creative and use values like "guest statistics". Nobody has gotten sufficiently masochistic to use values starting with "child<" or "link<" so far, although nothing would stop that.

Quoted 2 lines

Cases 1 and 2 go against the QAPI/QMP design maxim "don't encode stuff in strings".

They're not particular nice internally either as part of QDev/QOM. ie this is gross as a design approach:

  static inline bool object_property_is_child(ObjectProperty *prop)
  {
    return strstart(prop->type, "child<", NULL);
  }
Quoted 58 lines

Case 3 is is hard to use for anything. You're forced into stupid and brittle hardcoding.

Marc-André's work adds a new optional member @qapi_type that refers to a QAPI type in the output of query-qmp-schema. It's present for a large subset of case 3. When it's present, @type should not be used.

It also cleans up many crap cases of 3, but without making it robust. I understand this isn't something the series tries to do, it's just something that's easier to do than not to do. If it creates compatibility problems, we have to not do it. I hope it doesn't.

= Can we do better?

What information are we trying to convey? Four cases:

1. Child property: the child's QOM type

2. Link property: the target's QOM type

3. QAPI-backed property: the property's QAPI type

4. Other property: we have nothing useful to offer

Case 4 should go away eventually.

How would we encode this in QAPI on a green field? With a union, of course:

    { 'enum': 'ObjectPropertyKind',
      'data': [ 'child', 'link', 'qapi', 'other'] }

    { 'struct': 'ObjectPropertyInfoLink',
      'data': { 'qom-type': 'str' } }

    { 'struct': 'ObjectPropertyInfoQAPI',
      'data': { 'qapi-type': 'str' } }

    { 'union': 'ObjectProperty...',
      'base': { 'kind': 'ObjectPropertyKind',
                ... more ... },
      'discriminator': 'kind',
      'data': {
          'child': 'ObjectPropertyInfoLink',
          'link': 'ObjectPropertyInfoLink',
          'qapi': 'ObjectPropertyInfoQAPI' } }

To make this a compatible evolution of ObjectPropertyInfo, we need ... more ... to be

                'type': 'str',
                '*description': 'str'
                '*default-value': 'any',

Sadly, we need to duplicate the union for ObjectPropertyValue. There, ... more ... needs to be

Quoted 6 lines
                'type': 'str',
                '*value': 'any'

We should deprecate @type. I'd also deprecate @description.

Thoughts?

We currently have

{ 'enum': 'ObjectType', .... }

which provides a name in QMP schema for every QOM type that implements UserCreatable.

We could relatively easily extend that to cover *all* QOM types in existance, with some judicous grepping of TypeInfo classes.

It would be nice if we could enforce at runtime though that anything passed to type_register() was listed in 'ObjectType' enum to catch omissions. Not sure if there are any unexpected dragons if we make type_register() check the type name against 'ObjectType_lookup' from qapi-types-qom.h ?

Then your

Quoted 2 lines

{ 'struct': 'ObjectPropertyInfoLink',
'data': { 'qom-type': 'str' } }

could at least reference 'ObjectType' instead of 'str' and be aligned more with query-qmp-schema.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#104 lore raw

Re: ObjectPropertyInfo design

Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Markus Armbruster

Marc-André's series evolves ObjectPropertyInfo and ObjectPropertyValue:
it adds member @qapi-type and changes many values of member @type.

I'd like to take a step back and discuss design. I trimmed Cc:
accordingly.

= The current interface

Quoted 7 lines
Quoted 5 lines

qom-list returns information on an object's properties, one ObjectPropertyInfo per property.

qom-list-properties returns information on properties an instance of a type is known to have[*], one ObjectPropertyInfo per property.

This is

Yes?

Quoted 11 lines
Quoted 2 lines

qom-list-get returns information on the properties of several objects, one ObjectPropertyValue per property.

Since 'qom-list-properties' is really introspecting types, rather than instances, I'd add its companion:

query-qmp-schema returns information on properties from user creatable QOM objects, via the ObjectOptions union which handles data of arbitary complexity and nesting, with strictly QAPI types only. Obviously missing QDev and other internal only types.

Yes. Ideally, it would cover everything, but QOM's design and the sheer amount of QOM types and properties has kept that well out of reach. QOM introspection filled the gap, but badly. Marc-André's work makes it less bad.

Quoted 8 lines
Quoted 4 lines

* @description is rarely present (I see under 15% in a quick test). The description text is commonly misleading for QMP. For instance, qdev bool properties have description "on/off". The possible values are actually JSON false and true.

With query-qmp-schema we have a description for 100% of properties, enforced by the QAPI schema parser. Only applies to UserCreatable QOM objects though.

Yes.

QAPI schema doc comments are mandatory, and they get validated against the schema code. They become the "QEMU QMP Reference Manual".

QOM property description strings are optional, and they are not checked in any way. They are used in help intended for humans.

Quoted 7 lines

I see descriptions as primarily a documentation thing for humans, and perhaps for machines which are trying to generate code frmo QAPI schema and want to use descriptions for docs. These are both static querying tasks.

I don't see descriptions as useful for mgmt apps at runtime for deployed QEMus.

Noted.

Quoted 4 lines
Quoted 2 lines

* @default-value can be useful with qom-list-properties, which operates on types. I doubt it is with qom-list, which operates on objects.

Likewise, IMHO this is useful info statically, but not at runtime.

Noted.

Quoted 7 lines
Quoted 7 lines

Let's pretend @description doesn't exist, and @default-value exists only with qom-list-properties.

This makes qom-list-get strictly more powerful than qom-list, so let's further pretend qom-list doesn't exist.

Quoted 8 lines
Quoted 4 lines

= Simplified interface for the sake of discussion

qom-list-properties returns information on properties an instance of a type is known to have[*]: @name, @type, and maybe @default-value.

In the ideal world 'qom-list-properties' would not need to exist, but it has to for the forseeable future, since none of QDev is modelled in QAPI schema currently.

Yes.

Quoted 25 lines
Quoted 22 lines

qom-list-get returns information on the properties of several objects:
@name, @type, and maybe @value.

= The meaning of @type

Three cases:

1. For a child property (created with object_property_add_child() etc.), @type is "child<T>", where T is the child's QOM type.

2. For a link property (created with object_class_property_add_link() etc.), @type is "link<T>", where T is the target's QOM type.

3. For other properties, @type can be anything. We commonly use QAPI type names (occasionally misspelled), and also "well-known" (but undocumented) non-QAPI names for primitive types. Every now and then, developers get lazy and use values like "list", or creative and use values like "guest statistics". Nobody has gotten sufficiently masochistic to use values starting with "child<" or "link<" so far, although nothing would stop that.

Quoted 2 lines

Cases 1 and 2 go against the QAPI/QMP design maxim "don't encode stuff in strings".

Quoted 7 lines

They're not particular nice internally either as part of QDev/QOM. ie this is gross as a design approach:

  static inline bool object_property_is_child(ObjectProperty *prop)
  {
    return strstart(prop->type, "child<", NULL);
  }

I can top that!

    /* Go from link<FOO> to FOO.  */
    type = object_property_get_type(obj, name, NULL);
    target_type = g_strndup(&type[5], strlen(type) - 6);
Quoted 76 lines
Quoted 58 lines

Case 3 is is hard to use for anything. You're forced into stupid and brittle hardcoding.

Marc-André's work adds a new optional member @qapi_type that refers to a QAPI type in the output of query-qmp-schema. It's present for a large subset of case 3. When it's present, @type should not be used.

It also cleans up many crap cases of 3, but without making it robust. I understand this isn't something the series tries to do, it's just something that's easier to do than not to do. If it creates compatibility problems, we have to not do it. I hope it doesn't.

= Can we do better?

What information are we trying to convey? Four cases:

1. Child property: the child's QOM type

2. Link property: the target's QOM type

3. QAPI-backed property: the property's QAPI type

4. Other property: we have nothing useful to offer

Case 4 should go away eventually.

How would we encode this in QAPI on a green field? With a union, of course:

    { 'enum': 'ObjectPropertyKind',
      'data': [ 'child', 'link', 'qapi', 'other'] }

    { 'struct': 'ObjectPropertyInfoLink',
      'data': { 'qom-type': 'str' } }

    { 'struct': 'ObjectPropertyInfoQAPI',
      'data': { 'qapi-type': 'str' } }

    { 'union': 'ObjectProperty...',
      'base': { 'kind': 'ObjectPropertyKind',
                ... more ... },
      'discriminator': 'kind',
      'data': {
          'child': 'ObjectPropertyInfoLink',
          'link': 'ObjectPropertyInfoLink',
          'qapi': 'ObjectPropertyInfoQAPI' } }

To make this a compatible evolution of ObjectPropertyInfo, we need ... more ... to be

                'type': 'str',
                '*description': 'str'
                '*default-value': 'any',

Sadly, we need to duplicate the union for ObjectPropertyValue. There, ... more ... needs to be

Quoted 6 lines
                'type': 'str',
                '*value': 'any'

We should deprecate @type. I'd also deprecate @description.

Thoughts?

We currently have

{ 'enum': 'ObjectType', .... }

which provides a name in QMP schema for every QOM type that implements UserCreatable.

We could relatively easily extend that to cover *all* QOM types in existance, with some judicous grepping of TypeInfo classes.

Quoted 5 lines

It would be nice if we could enforce at runtime though that anything passed to type_register() was listed in 'ObjectType' enum to catch omissions. Not sure if there are any unexpected dragons if we make type_register() check the type name against 'ObjectType_lookup' from qapi-types-qom.h ?

Can't see why that wouldn't work.

We use strings instead of a C enum for type names, because a C enum would be conflict magnet, and also a "recompile the world" header.

Strings weaken the type checker, and also risk typos. The #define TYPE_FOO "foo" reduce that risk. Since we don't always use them, we always have to grep both for TYPE_FOO and "foo".

If we enumerate all the type names in a QAPI enum, we generate such a C enum, but use it only to check the strings. Still a conflict magnet, but at least not a "recompile the world" header.

Quoted 6 lines

Then your

Quoted 2 lines

{ 'struct': 'ObjectPropertyInfoLink',
'data': { 'qom-type': 'str' } }

could at least reference 'ObjectType' instead of 'str'

Yes. There are a few more, e.g. CompatProperty member @qom-type.

Quoted 2 lines

and be
aligned more with query-qmp-schema.

What do you mean by that?