Skip to contentSkip to conversation

qom/qdev: associate properties with QAPI schema types

PATCH RESEND In review Markus Armbruster 2 participants 66 messages Nov 1 – Nov 2 Page 2 of 2

Subsystems (8)
lore
Share & tools
lore
#55 lore raw

PATCH v8 1/1 hw/ufs: Convert PropertyInfo to QAPITypeInfo

In reply to Markus Armbruster

This gives properties "x-fault-inject-tag" and "x-fault-inject-mode" 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 conversion is trivial for ufs_prop_get_fault_inject_tag. For ufs_prop_get_fault_inject_tag, we need to conver UfsFaultInjectMode to a QAPI enum.

---
Fixup needed for commit c821f2f69f1 (hw/ufs: Add experimental fault injection properties for holding requests)

 qapi/common.json | 30 ++++++++++++++++++++++++++++++
 hw/ufs/ufs.h     | 34 ----------------------------------
 hw/ufs/ufs.c     | 15 +++------------
 3 files changed, 33 insertions(+), 46 deletions(-)
qapi/common.json +30 -0
index 68b649ecf2..84f12c133a 100644
@@ -245,3 +245,33 @@
     'tm_hour': 'int32',
     'tm_min': 'int32',
     'tm_sec': 'int32' } }
+
+##
+# @UfsFaultInjectMode:
+#     Fault injection modes for x-fault-inject-mode property.
+#     Controls how the held transfer request and subsequent Task
+#     Management Request (TMR) are resolved by the controller:
+#
+# @abort-success: TMR ABORT_TASK aborts the held request, clears its
+#     state, and returns SUCCESS (COMPL).
+#
+# @abort-failed: TMR ABORT_TASK returns TASK_MANAGEMENT_FUNC_FAILED,
+#     forcing host driver to escalate to Host Reset.
+#
+# @in-transition: TMR QUERY_TASK releases the held request to execute
+#     normally through the SCSI layer and returns the real task status
+#     (SUCCEEDED while the command is still in flight); ABORT_TASK
+#     cancels the held request and returns FUNCTION_COMPLETE.
+#
+# @timeout: TMR ABORT_TASK does not complete or clear doorbell,
+#     triggering hardware-level TMR timeout.
+#
+# @ssu-timeout: Intercepts SCSI START_STOP (0x1B) commands targeting
+#     the UFS Device WLUN when x-fault-inject-tag is armed.
+#
+# Since: 11.2
+##
+{ 'enum': 'UfsFaultInjectMode',
+  'prefix': 'UFS_FAULT_INJECT',
+  'data': [ 'abort-success', 'abort-failed', 'in-transition', 'timeout',
+            'ssu-timeout' ] }
hw/ufs/ufs.h +0 -34
index 7ddc540546..0014978322 100644
@@ -90,39 +90,6 @@ typedef struct UfsLu {
     UfsScsiOp scsi_op;
 } UfsLu;
 
-/*
- * Fault injection modes for x-fault-inject-mode property.
- * Controls how the held transfer request and subsequent Task Management
- * Request (TMR) are resolved by the controller:
- *
- * UFS_FAULT_INJECT_ABORT_SUCCESS: TMR ABORT_TASK aborts the held request,
- *                                 clears its state, and returns SUCCESS
- *                                 (COMPL).
- * UFS_FAULT_INJECT_ABORT_FAILED:  TMR ABORT_TASK returns
- *                                 TASK_MANAGEMENT_FUNC_FAILED, forcing host
- *                                 driver to escalate to Host Reset.
- * UFS_FAULT_INJECT_IN_TRANSITION: TMR QUERY_TASK releases the held request to
- *                                 execute normally through the SCSI layer and
- *                                 returns the real task status (SUCCEEDED while
- *                                 the command is still in flight);
- *                                 ABORT_TASK cancels the held request and
- *                                 returns FUNCTION_COMPLETE.
- * UFS_FAULT_INJECT_TIMEOUT:       TMR ABORT_TASK does not complete or clear
- *                                 doorbell, triggering hardware-level TMR
- *                                 timeout.
- * UFS_FAULT_INJECT_SSU_TIMEOUT:   Intercepts SCSI START_STOP (0x1B) commands
- *                                 targeting the UFS Device WLUN when
- *                                 x-fault-inject-tag is armed.
- */
-typedef enum UfsFaultInjectMode {
-    UFS_FAULT_INJECT_ABORT_SUCCESS = 0,
-    UFS_FAULT_INJECT_ABORT_FAILED,
-    UFS_FAULT_INJECT_IN_TRANSITION,
-    UFS_FAULT_INJECT_TIMEOUT,
-    UFS_FAULT_INJECT_SSU_TIMEOUT,
-    UFS_FAULT_INJECT_MODE_MAX,
-} UfsFaultInjectMode;
-
 /*
  * Sentinel values for x-fault-inject-tag property.
  * Task Tags in UFS are 8-bit (0..255). Values >= 256 are reserved as
@@ -375,6 +342,5 @@ void ufs_unrealize(UfsHc *u);
 
 extern const PropertyInfo ufs_prop_fault_inject_tag;
 extern const PropertyInfo ufs_prop_fault_inject_mode;
-extern const QEnumLookup UfsFaultInjectMode_lookup;
 
 #endif /* HW_UFS_UFS_H */
hw/ufs/ufs.c +3 -12
index f8da7c9554..3de67831ea 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-type-infos-common.h"
 #include "qapi/visitor.h"
 #include "scsi/constants.h"
 #include "hw/core/irq.h"
@@ -3234,17 +3235,6 @@ static void ufs_init_hc(UfsHc *u)
     ufs_fault_inject_init(u);
 }
 
-const QEnumLookup UfsFaultInjectMode_lookup = {
-    .array = (const char *const[]) {
-        [UFS_FAULT_INJECT_ABORT_SUCCESS] = "abort-success",
-        [UFS_FAULT_INJECT_ABORT_FAILED] = "abort-failed",
-        [UFS_FAULT_INJECT_IN_TRANSITION] = "in-transition",
-        [UFS_FAULT_INJECT_TIMEOUT] = "timeout",
-        [UFS_FAULT_INJECT_SSU_TIMEOUT] = "ssu-timeout",
-    },
-    .size = UFS_FAULT_INJECT_MODE_MAX,
-};
-
 static void ufs_prop_get_fault_inject_tag(Object *obj, Visitor *v,
                                           const char *name, void *opaque,
                                           Error **errp)
@@ -3300,6 +3290,7 @@ static void ufs_prop_set_default_fault_inject_tag(ObjectProperty *op,
 
 const PropertyInfo ufs_prop_fault_inject_tag = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "Task tag to hold for fault injection",
     .get = ufs_prop_get_fault_inject_tag,
     .set = ufs_prop_set_fault_inject_tag,
@@ -3309,9 +3300,9 @@ const PropertyInfo ufs_prop_fault_inject_tag = {
 
 const PropertyInfo ufs_prop_fault_inject_mode = {
     .type = "UfsFaultInjectMode",
+    .qapi_type = &UfsFaultInjectMode_type_info,
     .description = "Fault injection mode: abort-success, abort-failed, "
                    "in-transition, timeout, ssu-timeout",
-    .enum_table = &UfsFaultInjectMode_lookup,
     .get = qdev_propinfo_get_enum,
     .set = qdev_propinfo_set_enum,
     .set_default_value = qdev_propinfo_set_default_value_enum,
Signature · 1 line
2.55.0
Reviewed-by on v8 1/1
#56 lore raw

Re: [PATCH v8 48.5/56] hw/ufs: Convert PropertyInfo to QAPITypeInfo

Quoted 11 lines · Markus Armbruster

This gives properties "x-fault-inject-tag" and "x-fault-inject-mode" 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 conversion is trivial for ufs_prop_get_fault_inject_tag. For ufs_prop_get_fault_inject_tag, we need to conver UfsFaultInjectMode to a QAPI enum.

Quoted 150 lines

---
Fixup needed for commit c821f2f69f1 (hw/ufs: Add experimental fault injection properties for holding requests)

 qapi/common.json | 30 ++++++++++++++++++++++++++++++
 hw/ufs/ufs.h     | 34 ----------------------------------
 hw/ufs/ufs.c     | 15 +++------------
 3 files changed, 33 insertions(+), 46 deletions(-)
qapi/common.json +30 -0
index 68b649ecf2..84f12c133a 100644
@@ -245,3 +245,33 @@
     'tm_hour': 'int32',
     'tm_min': 'int32',
     'tm_sec': 'int32' } }
+
+##
+# @UfsFaultInjectMode:
+#     Fault injection modes for x-fault-inject-mode property.
+#     Controls how the held transfer request and subsequent Task
+#     Management Request (TMR) are resolved by the controller:
+#
+# @abort-success: TMR ABORT_TASK aborts the held request, clears its
+#     state, and returns SUCCESS (COMPL).
+#
+# @abort-failed: TMR ABORT_TASK returns TASK_MANAGEMENT_FUNC_FAILED,
+#     forcing host driver to escalate to Host Reset.
+#
+# @in-transition: TMR QUERY_TASK releases the held request to execute
+#     normally through the SCSI layer and returns the real task status
+#     (SUCCEEDED while the command is still in flight); ABORT_TASK
+#     cancels the held request and returns FUNCTION_COMPLETE.
+#
+# @timeout: TMR ABORT_TASK does not complete or clear doorbell,
+#     triggering hardware-level TMR timeout.
+#
+# @ssu-timeout: Intercepts SCSI START_STOP (0x1B) commands targeting
+#     the UFS Device WLUN when x-fault-inject-tag is armed.
+#
+# Since: 11.2
+##
+{ 'enum': 'UfsFaultInjectMode',
+  'prefix': 'UFS_FAULT_INJECT',
+  'data': [ 'abort-success', 'abort-failed', 'in-transition', 'timeout',
+            'ssu-timeout' ] }
hw/ufs/ufs.h +0 -34
index 7ddc540546..0014978322 100644
@@ -90,39 +90,6 @@ typedef struct UfsLu {
     UfsScsiOp scsi_op;
 } UfsLu;
 
-/*
- * Fault injection modes for x-fault-inject-mode property.
- * Controls how the held transfer request and subsequent Task Management
- * Request (TMR) are resolved by the controller:
- *
- * UFS_FAULT_INJECT_ABORT_SUCCESS: TMR ABORT_TASK aborts the held request,
- *                                 clears its state, and returns SUCCESS
- *                                 (COMPL).
- * UFS_FAULT_INJECT_ABORT_FAILED:  TMR ABORT_TASK returns
- *                                 TASK_MANAGEMENT_FUNC_FAILED, forcing host
- *                                 driver to escalate to Host Reset.
- * UFS_FAULT_INJECT_IN_TRANSITION: TMR QUERY_TASK releases the held request to
- *                                 execute normally through the SCSI layer and
- *                                 returns the real task status (SUCCEEDED while
- *                                 the command is still in flight);
- *                                 ABORT_TASK cancels the held request and
- *                                 returns FUNCTION_COMPLETE.
- * UFS_FAULT_INJECT_TIMEOUT:       TMR ABORT_TASK does not complete or clear
- *                                 doorbell, triggering hardware-level TMR
- *                                 timeout.
- * UFS_FAULT_INJECT_SSU_TIMEOUT:   Intercepts SCSI START_STOP (0x1B) commands
- *                                 targeting the UFS Device WLUN when
- *                                 x-fault-inject-tag is armed.
- */
-typedef enum UfsFaultInjectMode {
-    UFS_FAULT_INJECT_ABORT_SUCCESS = 0,
-    UFS_FAULT_INJECT_ABORT_FAILED,
-    UFS_FAULT_INJECT_IN_TRANSITION,
-    UFS_FAULT_INJECT_TIMEOUT,
-    UFS_FAULT_INJECT_SSU_TIMEOUT,
-    UFS_FAULT_INJECT_MODE_MAX,
-} UfsFaultInjectMode;
-
 /*
  * Sentinel values for x-fault-inject-tag property.
  * Task Tags in UFS are 8-bit (0..255). Values >= 256 are reserved as
@@ -375,6 +342,5 @@ void ufs_unrealize(UfsHc *u);
 
 extern const PropertyInfo ufs_prop_fault_inject_tag;
 extern const PropertyInfo ufs_prop_fault_inject_mode;
-extern const QEnumLookup UfsFaultInjectMode_lookup;
 
 #endif /* HW_UFS_UFS_H */
hw/ufs/ufs.c +3 -13
index f8da7c9554..3de67831ea 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-type-infos-common.h"
 #include "qapi/visitor.h"
 #include "scsi/constants.h"
 #include "hw/core/irq.h"
@@ -3234,17 +3235,6 @@ static void ufs_init_hc(UfsHc *u)
     ufs_fault_inject_init(u);
 }
 
-const QEnumLookup UfsFaultInjectMode_lookup = {
-    .array = (const char *const[]) {
-        [UFS_FAULT_INJECT_ABORT_SUCCESS] = "abort-success",
-        [UFS_FAULT_INJECT_ABORT_FAILED] = "abort-failed",
-        [UFS_FAULT_INJECT_IN_TRANSITION] = "in-transition",
-        [UFS_FAULT_INJECT_TIMEOUT] = "timeout",
-        [UFS_FAULT_INJECT_SSU_TIMEOUT] = "ssu-timeout",
-    },
-    .size = UFS_FAULT_INJECT_MODE_MAX,
-};
-
 static void ufs_prop_get_fault_inject_tag(Object *obj, Visitor *v,
                                           const char *name, void *opaque,
                                           Error **errp)
@@ -3300,6 +3290,7 @@ static void ufs_prop_set_default_fault_inject_tag(ObjectProperty *op,
 
 const PropertyInfo ufs_prop_fault_inject_tag = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "Task tag to hold for fault injection",
     .get = ufs_prop_get_fault_inject_tag,
     .set = ufs_prop_set_fault_inject_tag,
@@ -3309,9 +3300,9 @@ const PropertyInfo ufs_prop_fault_inject_tag = {
 
 const PropertyInfo ufs_prop_fault_inject_mode = {
     .type = "UfsFaultInjectMode",
+    .qapi_type = &UfsFaultInjectMode_type_info,
     .description = "Fault injection mode: abort-success, abort-failed, "
                    "in-transition, timeout, ssu-timeout",
-    .enum_table = &UfsFaultInjectMode_lookup,
     .get = qdev_propinfo_get_enum,
     .set = qdev_propinfo_set_enum,
     .set_default_value = qdev_propinfo_set_default_value_enum,
--

2.55.0

#57 lore raw

PATCH v8 49/56 hw: convert device-local PropertyInfo definitions to use qapi_type

In reply to Markus Armbruster

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

Add a .qapi_type pointer to PropertyInfo definitions in device-specific files. Mechanical, except for "display_mode" in apple-gfx.m, which is a string of a specific format.

---
 hw/block/xen-block.c       | 2 ++
 hw/misc/xlnx-versal-trng.c | 2 ++
 hw/nvme/nguid.c            | 2 ++
 hw/nvram/xlnx-bbram.c      | 2 ++
 hw/nvram/xlnx-efuse.c      | 2 ++
 hw/pci/pci.c               | 2 ++
 hw/s390x/ccw-device.c      | 2 ++
 hw/s390x/css.c             | 3 +++
 hw/s390x/s390-pci-bus.c    | 2 ++
 hw/vfio/pci-quirks.c       | 2 ++
 hw/display/apple-gfx.m     | 2 ++
 11 files changed, 23 insertions(+)
hw/block/xen-block.c +2 -0
index 474c12fe4a..ffdb080657 100644
@@ -29,6 +29,7 @@
 #include "dataplane/xen-block.h"
 #include "hw/xen/interface/io/xs_wire.h"
 #include "trace.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 #define XVDA_MAJOR 202
 #define XVDQ_MAJOR (1 << 20)
@@ -664,6 +665,7 @@ invalid:
  */
 static const PropertyInfo xen_block_prop_vdev = {
     .type  = "str",
+    .qapi_type = &str_type_info,
     .description = "Virtual Disk specifier (d*p*/xvd*/hd*/sd*)",
     .get = xen_block_get_vdev,
     .set = xen_block_set_vdev,
hw/misc/xlnx-versal-trng.c +2 -0
index 0584ee089e..3204e083ea 100644
@@ -36,6 +36,7 @@
 #include "qapi/visitor.h"
 #include "migration/vmstate.h"
 #include "hw/core/qdev-properties.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 #ifndef XLNX_VERSAL_TRNG_ERR_DEBUG
 #define XLNX_VERSAL_TRNG_ERR_DEBUG 0
@@ -663,6 +664,7 @@ static void trng_prop_fault_event_get(Object *obj, Visitor *v,
 
 static const PropertyInfo trng_prop_fault_events = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "Set to trigger TRNG fault events",
     .set = trng_prop_fault_event_set,
     .get = trng_prop_fault_event_get,
hw/nvme/nguid.c +2 -0
index 4cd6fad6ac..ccc12ac9f9 100644
@@ -18,6 +18,7 @@
 #include "qapi/visitor.h"
 #include "qemu/ctype.h"
 #include "nvme.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 #define NGUID_SEPARATOR '-'
 
@@ -180,6 +181,7 @@ static void set_nguid(Object *obj, Visitor *v, const char *name, void *opaque,
 
 const PropertyInfo qdev_prop_nguid = {
     .type  = "str",
+    .qapi_type = &str_type_info,
     .description =
         "NGUID or \"" NGUID_VALUE_AUTO "\" for random value",
     .get   = get_nguid,
hw/nvram/xlnx-bbram.c +2 -0
index e336874bde..8e7597621d 100644
@@ -34,6 +34,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/qdev-properties-system.h"
 #include "hw/nvram/xlnx-efuse.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 #ifndef XLNX_BBRAM_ERR_DEBUG
 #define XLNX_BBRAM_ERR_DEBUG 0
@@ -487,6 +488,7 @@ static void bbram_prop_release_drive(Object *obj, const char *name,
 
 static const PropertyInfo bbram_prop_drive = {
     .type  = "str",
+    .qapi_type = &str_type_info,
     .description = "Node name or ID of a block device to use as BBRAM backend",
     .realized_set_allowed = true,
     .get = bbram_prop_get_drive,
hw/nvram/xlnx-efuse.c +2 -0
index 03c9fbc0d0..7d2030f7aa 100644
@@ -34,6 +34,7 @@
 #include "system/blockdev.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/core/qdev-properties-system.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 #define TBIT0_OFFSET     28
 #define TBIT1_OFFSET     29
@@ -252,6 +253,7 @@ static void efuse_prop_release_drive(Object *obj, const char *name,
 
 static const PropertyInfo efuse_prop_drive = {
     .type  = "str",
+    .qapi_type = &str_type_info,
     .description = "Node name or ID of a block device to use as eFUSE backend",
     .realized_set_allowed = true,
     .get = efuse_prop_get_drive,
hw/pci/pci.c +2 -0
index 0efb4eb4bb..0f4c900991 100644
@@ -53,6 +53,7 @@
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "pci-internal.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 #include "hw/xen/xen.h"
 #include "hw/i386/kvm/xen_evtchn.h"
@@ -81,6 +82,7 @@ static void prop_pci_busnr_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_pci_busnr = {
     .type = "busnr",
+    .qapi_type = &uint8_type_info,
     .get = prop_pci_busnr_get,
 };
 
hw/s390x/ccw-device.c +2 -0
index 25c4273279..54766f53e1 100644
@@ -17,6 +17,7 @@
 #include "qapi/visitor.h"
 #include "qemu/ctype.h"
 #include "qapi/error.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 static void ccw_device_refill_ids(CcwDevice *dev)
 {
@@ -75,6 +76,7 @@ static void ccw_device_set_loadparm(Object *obj, Visitor *v,
 
 const PropertyInfo ccw_loadparm = {
     .type  = "str",
+    .qapi_type = &str_type_info,
     .description = "Up to 8 chars in set of [A-Za-z0-9. ] to select"
             " a guest kernel",
     .get = ccw_device_get_loadparm,
hw/s390x/css.c +3 -0
index 65341c68c3..44805ceb49 100644
@@ -24,6 +24,7 @@
 #include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/s390-ccw.h"
 #include "exec/cpu-common.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 typedef struct CrwContainer {
     CRW crw;
@@ -2531,6 +2532,7 @@ out:
 
 const PropertyInfo css_devid_propinfo = {
     .type = "str",
+    .qapi_type = &str_type_info,
     .description = "Identifier of an I/O device in the channel "
                    "subsystem, example: fe.1.23ab",
     .get = get_css_devid,
@@ -2539,6 +2541,7 @@ const PropertyInfo css_devid_propinfo = {
 
 const PropertyInfo css_devid_ro_propinfo = {
     .type = "str",
+    .qapi_type = &str_type_info,
     .description = "Read-only identifier of an I/O device in the channel "
                    "subsystem, example: fe.1.23ab",
     .get = get_css_devid,
hw/s390x/s390-pci-bus.c +2 -0
index cdd75cdfd2..6703d4c1cb 100644
@@ -35,6 +35,7 @@
 #include "system/runstate.h"
 
 #include "trace.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 S390pciState *s390_get_phb(void)
 {
@@ -1852,6 +1853,7 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo s390_pci_fid_propinfo = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "zpci_fid",
     .get = s390_pci_get_fid,
     .set = s390_pci_set_fid,
hw/vfio/pci-quirks.c +2 -0
index c5b4f9091d..a38a0e7a3a 100644
@@ -26,6 +26,7 @@
 #include "pci.h"
 #include "pci-quirks.h"
 #include "trace.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 /*
  * List of device ids/vendor ids for which to disable
@@ -1437,6 +1438,7 @@ static void set_nv_gpudirect_clique_id(Object *obj, Visitor *v,
 
 const PropertyInfo qdev_prop_nv_gpudirect_clique = {
     .type = "uint8",
+    .qapi_type = &uint8_type_info,
     .description = "NVIDIA GPUDirect Clique ID (0 - 15)",
     .get = get_nv_gpudirect_clique_id,
     .set = set_nv_gpudirect_clique_id,
hw/display/apple-gfx.m +2 -0
index be0061b9db..4db80f0b10 100644
@@ -15,6 +15,7 @@
 #include "qemu/lockable.h"
 #include "qemu/cutils.h"
 #include "qemu/log.h"
+#include "qapi/qapi-builtin-type-infos.h"
 #include "qapi/visitor.h"
 #include "qapi/error.h"
 #include "qemu/aio-wait.h"
@@ -872,6 +873,7 @@ static void apple_gfx_set_display_mode(Object *obj, Visitor *v,
 
 const PropertyInfo qdev_prop_apple_gfx_display_mode = {
     .type  = "display_mode",
+    .qapi_type = &str_type_info,
     .description =
         "Display mode in pixels and Hertz, as <width>x<height>@<refresh-rate> "
         "Example: 3840x2160@60",
Signature · 1 line
2.55.0
#58 lore raw

PATCH v8 50/56 target/riscv: convert PropertyInfo definitions to use qapi_type

In reply to Markus Armbruster

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

Mechanically add a .qapi_type pointer to PropertyInfo definitions in target/riscv/cpu.c.

---
 target/riscv/cpu.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
target/riscv/cpu.c +15 -0
index adb53aad96..362e561809 100644
@@ -1730,6 +1730,7 @@ static void prop_pmu_num_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_pmu_num = {
     .type = "uint8",
+    .qapi_type = &uint8_type_info,
     .description = "pmu-num",
     .get = prop_pmu_num_get,
     .set = prop_pmu_num_set,
@@ -1772,6 +1773,7 @@ static void prop_pmu_mask_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_pmu_mask = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "pmu-mask",
     .get = prop_pmu_mask_get,
     .set = prop_pmu_mask_set,
@@ -1804,6 +1806,7 @@ static void prop_mmu_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_mmu = {
     .type = "bool",
+    .qapi_type = &bool_type_info,
     .description = "mmu",
     .get = prop_mmu_get,
     .set = prop_mmu_set,
@@ -1837,6 +1840,7 @@ static void prop_pmp_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_pmp = {
     .type = "bool",
+    .qapi_type = &bool_type_info,
     .description = "pmp",
     .get = prop_pmp_get,
     .set = prop_pmp_set,
@@ -1877,6 +1881,7 @@ static void prop_num_pmp_regions_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_num_pmp_regions = {
     .type = "uint8",
+    .qapi_type = &uint8_type_info,
     .description = "num-pmp-regions",
     .get = prop_num_pmp_regions_get,
     .set = prop_num_pmp_regions_set,
@@ -1915,6 +1920,7 @@ static void prop_pmp_granularity_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_pmp_granularity = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "pmp-granularity",
     .get = prop_pmp_granularity_get,
     .set = prop_pmp_granularity_set,
@@ -1991,6 +1997,7 @@ static void prop_priv_spec_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_priv_spec = {
     .type = "str",
+    .qapi_type = &str_type_info,
     .description = "priv_spec",
     /* FIXME enum? */
     .get = prop_priv_spec_get,
@@ -2024,6 +2031,7 @@ static void prop_vext_spec_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_vext_spec = {
     .type = "str",
+    .qapi_type = &str_type_info,
     .description = "vext_spec",
     /* FIXME enum? */
     .get = prop_vext_spec_get,
@@ -2108,6 +2116,7 @@ static void prop_elen_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_elen = {
     .type = "uint16",
+    .qapi_type = &uint16_type_info,
     .description = "elen",
     .get = prop_elen_get,
     .set = prop_elen_set,
@@ -2144,6 +2153,7 @@ static void prop_cbom_blksize_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_cbom_blksize = {
     .type = "uint16",
+    .qapi_type = &uint16_type_info,
     .description = "cbom_blocksize",
     .get = prop_cbom_blksize_get,
     .set = prop_cbom_blksize_set,
@@ -2180,6 +2190,7 @@ static void prop_cbop_blksize_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_cbop_blksize = {
     .type = "uint16",
+    .qapi_type = &uint16_type_info,
     .description = "cbop_blocksize",
     .get = prop_cbop_blksize_get,
     .set = prop_cbop_blksize_set,
@@ -2216,6 +2227,7 @@ static void prop_cboz_blksize_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_cboz_blksize = {
     .type = "uint16",
+    .qapi_type = &uint16_type_info,
     .description = "cboz_blocksize",
     .get = prop_cboz_blksize_get,
     .set = prop_cboz_blksize_set,
@@ -2252,6 +2264,7 @@ static void prop_mvendorid_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_mvendorid = {
     .type = "uint32",
+    .qapi_type = &uint32_type_info,
     .description = "mvendorid",
     .get = prop_mvendorid_get,
     .set = prop_mvendorid_set,
@@ -2288,6 +2301,7 @@ static void prop_mimpid_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_mimpid = {
     .type = "uint64",
+    .qapi_type = &uint64_type_info,
     .description = "mimpid",
     .get = prop_mimpid_get,
     .set = prop_mimpid_set,
@@ -2345,6 +2359,7 @@ static void prop_marchid_get(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo prop_marchid = {
     .type = "uint64",
+    .qapi_type = &uint64_type_info,
     .description = "marchid",
     .get = prop_marchid_get,
     .set = prop_marchid_set,
Signature · 1 line
2.55.0
#59 lore raw

PATCH v8 51/56 qdev: convert PropertyInfo definitions to use qapi_type

In reply to Markus Armbruster

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

Add a .qapi_type pointer to the remaining PropertyInfo definitions outside hw/.

After this patch, all PropertyInfo definitions have .qapi_type set, except qdev_prop_link (uses .create) and qdev_prop_array (left for later).

---
 backends/spdm-socket.c  | 3 ++-
 backends/tpm/tpm_util.c | 2 ++
 migration/options.c     | 3 +++
 target/sparc/cpu.c      | 2 ++
 4 files changed, 9 insertions(+), 1 deletion(-)
backends/spdm-socket.c +2 -1
index 826efc276d..e1d5626062 100644
@@ -17,6 +17,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/qdev-properties-system.h"
 #include "hw/core/qdev-prop-internal.h"
+#include "qapi/qapi-type-infos-sockets.h"
 
 static bool read_bytes(const int socket, uint8_t *buffer,
                        size_t number_of_bytes)
@@ -254,8 +255,8 @@ void spdm_socket_close(const int socket, SpdmTransportType transport_type)
 
 const PropertyInfo qdev_prop_spdm_trans = {
     .type = "SpdmTransportType",
+    .qapi_type = &SpdmTransportType_type_info,
     .description = "Spdm Transport, doe/nvme/mctp/scsi/unspecified",
-    .enum_table = &SpdmTransportType_lookup,
     .get = qdev_propinfo_get_enum,
     .set = qdev_propinfo_set_enum,
     .set_default_value = qdev_propinfo_set_default_value_enum,
backends/tpm/tpm_util.c +2 -0
index 7019f7fd3e..e52f342933 100644
@@ -30,6 +30,7 @@
 #include "system/tpm_backend.h"
 #include "system/tpm_util.h"
 #include "trace.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 /* tpm backend property */
 
@@ -78,6 +79,7 @@ static void release_tpm(Object *obj, const char *name, void *opaque)
 
 const PropertyInfo qdev_prop_tpm = {
     .type  = "str",
+    .qapi_type = &str_type_info,
     .description = "ID of a tpm to use as a backend",
     .get   = get_tpm,
     .set   = set_tpm,
migration/options.c +3 -0
index 46d040fc3f..1be4151ea7 100644
@@ -37,6 +37,8 @@
 #include "ram.h"
 #include "options.h"
 #include "system/kvm.h"
+#include "qapi/qapi-builtin-type-infos.h"
+#include "qapi/qapi-type-infos-common.h"
 
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -295,6 +297,7 @@ static void set_default_value_tls_opt(ObjectProperty *op, const Property *prop)
  */
 const PropertyInfo qdev_prop_StrOrNull = {
     .type  = "StrOrNull",
+    .qapi_type = &StrOrNull_type_info,
     .get = get_StrOrNull,
     .set = set_StrOrNull,
     .release = release_StrOrNull,
target/sparc/cpu.c +2 -0
index 28ae629d50..7729413698 100644
@@ -30,6 +30,7 @@
 #include "tcg/tcg.h"
 #include "fpu/softfloat.h"
 #include "target/sparc/translate.h"
+#include "qapi/qapi-builtin-type-infos.h"
 
 //#define DEBUG_FEATURES
 
@@ -950,6 +951,7 @@ static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
 
 static const PropertyInfo qdev_prop_nwindows = {
     .type  = "int",
+    .qapi_type = &int_type_info,
     .description = "Number of register windows",
     .get   = sparc_get_nwindows,
     .set   = sparc_set_nwindows,
Signature · 1 line
2.55.0
#60 lore raw

PATCH v8 52/56 qdev: PropertyInfo.enum_table is no longer used, drop

In reply to Markus Armbruster

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

Now that all PropertyInfo for enums definitions use .qapi_type, remove the legacy .enum_table field from PropertyInfo, along with the qdev_propinfo_enum_lookup() helper.

---
 hw/core/qdev-prop-internal.h      |  2 --
 include/hw/core/qdev-properties.h |  1 -
 hw/core/qdev-properties-system.c  | 12 +++++-------
 hw/core/qdev-properties.c         | 17 ++++-------------
 4 files changed, 9 insertions(+), 23 deletions(-)
hw/core/qdev-prop-internal.h +0 -2
index c190b7b88c..d7b77844fe 100644
@@ -8,8 +8,6 @@
 #ifndef HW_CORE_QDEV_PROP_INTERNAL_H
 #define HW_CORE_QDEV_PROP_INTERNAL_H
 
-const QEnumLookup *qdev_propinfo_enum_lookup(const PropertyInfo *info);
-
 void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
                             void *opaque, Error **errp);
 void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
include/hw/core/qdev-properties.h +0 -1
index 1ea2ba66bb..a57291a5a1 100644
@@ -33,7 +33,6 @@ struct Property {
 struct PropertyInfo {
     const char *type;
     const char *description;
-    const QEnumLookup *enum_table;
     const QAPITypeInfo *qapi_type;
     bool realized_set_allowed; /* allow setting property on realized device */
     char *(*print)(Object *obj, const Property *prop);
hw/core/qdev-properties-system.c +5 -7
index 8924f84806..4d605c2056 100644
@@ -592,7 +592,7 @@ static void qdev_propinfo_set_losttickpolicy(Object *obj, Visitor *v,
     int value;
 
     if (!visit_type_enum(v, name, &value,
-                         qdev_propinfo_enum_lookup(prop->info), errp)) {
+                         prop->info->qapi_type->lookup, errp)) {
         return;
     }
 
@@ -1081,8 +1081,7 @@ static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
         abort();
     }
 
-    visit_type_enum(v, name, &speed,
-                    qdev_propinfo_enum_lookup(prop->info), errp);
+    visit_type_enum(v, name, &speed, prop->info->qapi_type->lookup, errp);
 }
 
 static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
@@ -1093,7 +1092,7 @@ static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
     int speed;
 
     if (!visit_type_enum(v, name, &speed,
-                         qdev_propinfo_enum_lookup(prop->info), errp)) {
+                         prop->info->qapi_type->lookup, errp)) {
         return;
     }
 
@@ -1167,8 +1166,7 @@ static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
         abort();
     }
 
-    visit_type_enum(v, name, &width,
-                    qdev_propinfo_enum_lookup(prop->info), errp);
+    visit_type_enum(v, name, &width, prop->info->qapi_type->lookup, errp);
 }
 
 static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
@@ -1179,7 +1177,7 @@ static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
     int width;
 
     if (!visit_type_enum(v, name, &width,
-                         qdev_propinfo_enum_lookup(prop->info), errp)) {
+                         prop->info->qapi_type->lookup, errp)) {
         return;
     }
 
hw/core/qdev-properties.c +4 -13
index fb11eb1f1c..e2ea894595 100644
@@ -101,22 +101,13 @@ static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)
     return info->set ? field_prop_set : NULL;
 }
 
-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;
-}
-
 void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
                             void *opaque, Error **errp)
 {
     const Property *prop = opaque;
     int *ptr = object_field_prop_ptr(obj, prop);
 
-    visit_type_enum(v, name, ptr, qdev_propinfo_enum_lookup(prop->info), errp);
+    visit_type_enum(v, name, ptr, prop->info->qapi_type->lookup, errp);
 }
 
 void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
@@ -125,14 +116,14 @@ void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
     const Property *prop = opaque;
     int *ptr = object_field_prop_ptr(obj, prop);
 
-    visit_type_enum(v, name, ptr, qdev_propinfo_enum_lookup(prop->info), errp);
+    visit_type_enum(v, name, ptr, prop->info->qapi_type->lookup, errp);
 }
 
 void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
                                           const Property *prop)
 {
     object_property_set_default_str(op,
-        qapi_enum_lookup(qdev_propinfo_enum_lookup(prop->info),
+        qapi_enum_lookup(prop->info->qapi_type->lookup,
                          prop->defval.i));
 }
 
@@ -970,7 +961,7 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
 
     prop = qdev_prop_find(dev, name);
     object_property_set_str(OBJECT(dev), name,
-        qapi_enum_lookup(qdev_propinfo_enum_lookup(prop->info), value),
+        qapi_enum_lookup(prop->info->qapi_type->lookup, value),
         &error_abort);
 }
 
Signature · 1 line
2.55.0
#61 lore raw

PATCH v8 53/56 hw/i386: convert PCSouthBridgeOption to QAPI enum

In reply to Markus Armbruster

From: Marc-André Lureau <[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.

---
 qapi/machine.json    | 13 +++++++++++
 include/hw/i386/pc.h |  4 ++--
 hw/i386/pc_piix.c    | 52 +++++++++++---------------------------------
 3 files changed, 28 insertions(+), 41 deletions(-)
qapi/machine.json +13 -0
index 80348b5350..c19eea2b4b 100644
@@ -416,6 +416,19 @@
 { 'enum': 'LostTickPolicy',
   'data': ['discard', 'delay', 'slew' ] }
 
+##
+# @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
include/hw/i386/pc.h +2 -2
index 8edec62a1a..3afd376116 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: */
 
hw/i386/pc_piix.c +13 -39

98 lines not on this page · raw message

Signature · 1 line
2.55.0
#62 lore raw

PATCH v8 54/56 qom: Drop object_property_add_enum() parameter @lookup

In reply to Markus Armbruster

All callers now pass non-null @qapi_type and null @lookup. Drop @lookup and simplify the code accordingly.

---
 include/chardev/char.h                   |  3 +--
 include/qom/object.h                     |  4 ----
 accel/hvf/hvf-all.c                      |  2 +-
 accel/kvm/kvm-all.c                      |  2 +-
 accel/whpx/whpx-common.c                 |  4 ++--
 authz/list.c                             |  1 -
 backends/hostmem-file.c                  |  2 +-
 backends/hostmem-memfd.c                 |  4 ++--
 backends/hostmem.c                       |  2 +-
 crypto/secret_common.c                   |  2 +-
 crypto/tlscreds.c                        |  2 +-
 hw/arm/virt.c                            |  4 ++--
 hw/i386/microvm.c                        | 15 ++++++---------
 hw/i386/pc.c                             |  5 ++---
 hw/i386/pc_piix.c                        |  5 ++---
 hw/i386/x86.c                            | 12 ++++--------
 hw/loongarch/virt.c                      | 14 +++++++-------
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/riscv/virt.c                          | 10 +++++-----
 monitor/qmp.c                            |  2 +-
 net/filter.c                             |  5 +++--
 qom/object.c                             | 15 ++++-----------
 target/i386/kvm/kvm.c                    |  4 ++--
 target/i386/sev.c                        |  2 +-
 target/i386/whpx/whpx-all.c              |  7 +++----
 tests/unit/check-qom-proplist.c          |  3 +--
 ui/dbus.c                                |  4 ++--
 ui/input-linux.c                         |  2 +-
 28 files changed, 58 insertions(+), 81 deletions(-)
include/chardev/char.h +1 -2
index 61e6957118..45fc3edb5e 100644
@@ -358,8 +358,7 @@ static inline void chardev_vc_add_encoding_prop(ObjectClass *oc,
     void (*set)(Object *, int, Error **))
 {
     object_class_property_add_enum(oc, "encoding", "ChardevVCEncoding",
-                                   &ChardevVCEncoding_type_info, NULL,
-                                   get, set);
+                                   &ChardevVCEncoding_type_info, get, set);
 }
 
 #endif
include/qom/object.h +0 -4
index d1699964fa..a90cd30675 100644
@@ -1988,7 +1988,6 @@ ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
  * @name: the name of the property
  * @typename: the name of the enum data type
  * @qapi_type: QAPI type info descriptor
- * @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
  *
@@ -2000,7 +1999,6 @@ ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
 ObjectProperty *object_property_add_enum(Object *obj, const char *name,
                               const char *typename,
                               const QAPITypeInfo *qapi_type,
-                              const QEnumLookup *lookup,
                               int (*get)(Object *, Error **),
                               void (*set)(Object *, int, Error **));
 
@@ -2010,7 +2008,6 @@ ObjectProperty *object_property_add_enum(Object *obj, const char *name,
  * @name: the name of the property
  * @typename: the name of the enum data type
  * @qapi_type: QAPI type info descriptor
- * @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
  *
@@ -2023,7 +2020,6 @@ ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
                                     const char *name,
                                     const char *typename,
                                     const QAPITypeInfo *qapi_type,
-                                    const QEnumLookup *lookup,
                                     int (*get)(Object *, Error **),
                                     void (*set)(Object *, int, Error **));
 
accel/hvf/hvf-all.c +1 -1
index 938379b9f2..f233d86c06 100644
@@ -271,7 +271,7 @@ static void hvf_accel_class_init(ObjectClass *oc, const void *data)
 
     object_class_property_add_enum(oc, "kernel-irqchip", "on|off|split",
                                    &OnOffSplit_type_info, NULL,
-                                   NULL, hvf_set_kernel_irqchip);
+                                   hvf_set_kernel_irqchip);
     object_class_property_set_description(oc, "kernel-irqchip",
         "Configure HVF irqchip");
 }
accel/kvm/kvm-all.c +1 -1
index dcb1db139d..313c41c4a2 100644
@@ -4299,7 +4299,7 @@ static void kvm_accel_class_init(ObjectClass *oc, const void *data)
 
     object_class_property_add_enum(oc, "kernel-irqchip", "on|off|split",
                                    &OnOffSplit_type_info, NULL,
-                                   NULL, kvm_set_kernel_irqchip);
+                                   kvm_set_kernel_irqchip);
     object_class_property_set_description(oc, "kernel-irqchip",
         "Configure KVM in-kernel irqchip");
 
accel/whpx/whpx-common.c +2 -2
index 068258bf6c..78d2827809 100644
@@ -510,12 +510,12 @@ static void whpx_accel_class_init(ObjectClass *oc, const void *data)
 
     object_class_property_add_enum(oc, "kernel-irqchip", "on|off|split",
                                    &OnOffSplit_type_info, NULL,
-                                   NULL, whpx_set_kernel_irqchip);
+                                   whpx_set_kernel_irqchip);
     object_class_property_set_description(oc, "kernel-irqchip",
         "Configure WHPX in-kernel irqchip");
     object_class_property_add_enum(oc, "hyperv", "OnOffAuto",
                                    &OnOffAuto_type_info, NULL,
-                                   NULL, whpx_set_hyperv);
+                                   whpx_set_hyperv);
     object_class_property_set_description(oc, "hyperv",
         "Configure Hyper-V enlightenments");
 
authz/list.c +0 -1
index 75155cf077..c3dd9d7b68 100644
@@ -123,7 +123,6 @@ qauthz_list_class_init(ObjectClass *oc, const void *data)
 
     object_class_property_add_enum(oc, "policy", "QAuthZListPolicy",
                                    &QAuthZListPolicy_type_info,
-                                   NULL,
                                    qauthz_list_prop_get_policy,
                                    qauthz_list_prop_set_policy);
 
backends/hostmem-file.c +1 -1
index 2f65ca3678..6ad9cad032 100644
@@ -293,7 +293,7 @@ file_backend_class_init(ObjectClass *oc, const void *data)
         file_memory_backend_get_readonly,
         file_memory_backend_set_readonly);
     object_class_property_add_enum(oc, "rom", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+                                   &OnOffAuto_type_info,
                                    file_memory_backend_get_rom,
                                    file_memory_backend_set_rom);
     object_class_property_set_description(oc, "rom",
backends/hostmem-memfd.c +2 -2
index 19a9a5b409..496455f7aa 100644
@@ -201,8 +201,8 @@ memfd_backend_class_init(ObjectClass *oc, const void *data)
                                               "Huge pages size (ex: 2M, 1G)");
     }
 
-    object_class_property_add_enum(oc, "guest-memfd",  "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+    object_class_property_add_enum(oc, "guest-memfd", "OnOffAuto",
+                                   &OnOffAuto_type_info,
                                    memfd_backend_get_guest_memfd,
                                    memfd_backend_set_guest_memfd);
     object_class_property_set_description(oc, "guest-memfd",
backends/hostmem.c +1 -1
index 0f39f4d1b7..173d042be3 100644
@@ -554,7 +554,7 @@ host_memory_backend_class_init(ObjectClass *oc, const void *data)
     object_class_property_set_description(oc, "host-nodes",
         "Binds memory to the list of NUMA host nodes");
     object_class_property_add_enum(oc, "policy", "HostMemPolicy",
-                                   &HostMemPolicy_type_info, NULL,
+                                   &HostMemPolicy_type_info,
                                    host_memory_backend_get_policy,
                                    host_memory_backend_set_policy);
     object_class_property_set_description(oc, "policy",
crypto/secret_common.c +1 -1
index 8e05f1365e..98898aa885 100644
@@ -271,7 +271,7 @@ qcrypto_secret_class_init(ObjectClass *oc, const void *data)
     ucc->complete = qcrypto_secret_complete;
 
     object_class_property_add_enum(oc, "format", "QCryptoSecretFormat",
-                                   &QCryptoSecretFormat_type_info, NULL,
+                                   &QCryptoSecretFormat_type_info,
                                    qcrypto_secret_prop_get_format,
                                    qcrypto_secret_prop_set_format);
     object_class_property_add_str(oc, "keyid",
crypto/tlscreds.c +1 -1
index 021e4bf111..74d8d4fe00 100644
@@ -223,7 +223,7 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, const void *data)
                                   qcrypto_tls_creds_prop_get_dir,
                                   qcrypto_tls_creds_prop_set_dir);
     object_class_property_add_enum(oc, "endpoint", "QCryptoTLSCredsEndpoint",
-                                   &QCryptoTLSCredsEndpoint_type_info, NULL,
+                                   &QCryptoTLSCredsEndpoint_type_info,
                                    qcrypto_tls_creds_prop_get_endpoint,
                                    qcrypto_tls_creds_prop_set_endpoint);
     object_class_property_add_str(oc, "priority",
hw/arm/virt.c +2 -2
index 2f03679afd..57bd78479f 100644
@@ -4202,8 +4202,8 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
     mc->default_nic = "virtio-net-pci";
 
     object_class_property_add_enum(oc, "acpi", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   virt_get_acpi, virt_set_acpi);
+                                   &OnOffAuto_type_info, virt_get_acpi,
+                                   virt_set_acpi);
     object_class_property_set_description(oc, "acpi",
         "Enable ACPI");
     object_class_property_add_bool(oc, "secure", virt_get_secure,
hw/i386/microvm.c +6 -9
index 7f010cb2f2..ed391c0596 100644
@@ -658,25 +658,22 @@ static void microvm_class_init(ObjectClass *oc, const void *data)
     hc->unplug_request = microvm_device_unplug_request_cb;
     hc->unplug = microvm_device_unplug_cb;
 
-    object_class_property_add_enum(oc, MICROVM_MACHINE_RTC,
-                                   "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+    object_class_property_add_enum(oc, MICROVM_MACHINE_RTC, "OnOffAuto",
+                                   &OnOffAuto_type_info,
                                    microvm_machine_get_rtc,
                                    microvm_machine_set_rtc);
     object_class_property_set_description(oc, MICROVM_MACHINE_RTC,
         "Enable MC146818 RTC");
 
-    object_class_property_add_enum(oc, MICROVM_MACHINE_PCIE,
-                                   "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+    object_class_property_add_enum(oc, MICROVM_MACHINE_PCIE, "OnOffAuto",
+                                   &OnOffAuto_type_info,
                                    microvm_machine_get_pcie,
                                    microvm_machine_set_pcie);
     object_class_property_set_description(oc, MICROVM_MACHINE_PCIE,
         "Enable PCIe");
 
-    object_class_property_add_enum(oc, MICROVM_MACHINE_IOAPIC2,
-                                   "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+    object_class_property_add_enum(oc, MICROVM_MACHINE_IOAPIC2, "OnOffAuto",
+                                   &OnOffAuto_type_info,
                                    microvm_machine_get_ioapic2,
                                    microvm_machine_set_ioapic2);
     object_class_property_set_description(oc, MICROVM_MACHINE_IOAPIC2,
hw/i386/pc.c +2 -3
index 80940e81e5..4737eb471c 100644
@@ -1726,9 +1726,8 @@ static void pc_machine_class_init(ObjectClass *oc, const void *data)
     object_class_property_set_description(oc, PC_MACHINE_MAX_RAM_BELOW_4G,
         "Maximum ram below the 4G boundary (32bit boundary)");
 
-    object_class_property_add_enum(oc, PC_MACHINE_VMPORT,
-                                   "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+    object_class_property_add_enum(oc, PC_MACHINE_VMPORT, "OnOffAuto",
+                                   &OnOffAuto_type_info,
                                    pc_machine_get_vmport,
                                    pc_machine_set_vmport);
     object_class_property_set_description(oc, PC_MACHINE_VMPORT,
hw/i386/pc_piix.c +2 -3
index 20bd4231c1..211e3c5f9e 100644
@@ -389,9 +389,8 @@ static void pc_i440fx_machine_options(MachineClass *m)
 
     object_class_property_add_enum(oc, "x-south-bridge",
                                    "PCSouthBridgeOption",
-                                   &PCSouthBridgeOption_type_info, NULL,
-                                   pc_get_south_bridge,
-                                   pc_set_south_bridge);
+                                   &PCSouthBridgeOption_type_info,
+                                   pc_get_south_bridge, pc_set_south_bridge);
     object_class_property_set_description(oc, "x-south-bridge",
                                      "Use a different south bridge than PIIX3");
     compat_props_add(m->compat_props,
hw/i386/x86.c +4 -8
index 4e5a7cf270..4b75b7406a 100644
@@ -373,29 +373,25 @@ static void x86_machine_class_init(ObjectClass *oc, const void *data)
     nc->raise_nmi = x86_nmi;
 
     object_class_property_add_enum(oc, X86_MACHINE_SMM, "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   x86_machine_get_smm,
+                                   &OnOffAuto_type_info, x86_machine_get_smm,
                                    x86_machine_set_smm);
     object_class_property_set_description(oc, X86_MACHINE_SMM,
         "Enable SMM");
 
     object_class_property_add_enum(oc, X86_MACHINE_ACPI, "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   x86_machine_get_acpi,
+                                   &OnOffAuto_type_info, x86_machine_get_acpi,
                                    x86_machine_set_acpi);
     object_class_property_set_description(oc, X86_MACHINE_ACPI,
         "Enable ACPI");
 
     object_class_property_add_enum(oc, X86_MACHINE_PIT, "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   x86_machine_get_pit,
+                                   &OnOffAuto_type_info, x86_machine_get_pit,
                                    x86_machine_set_pit);
     object_class_property_set_description(oc, X86_MACHINE_PIT,
         "Enable i8254 PIT");
 
     object_class_property_add_enum(oc, X86_MACHINE_PIC, "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   x86_machine_get_pic,
+                                   &OnOffAuto_type_info, x86_machine_get_pic,
                                    x86_machine_set_pic);
     object_class_property_set_description(oc, X86_MACHINE_PIC,
         "Enable i8259 PIC");
hw/loongarch/virt.c +7 -7
index 1eae2bffe6..598898e0fb 100644
@@ -1470,18 +1470,18 @@ static void virt_class_init(ObjectClass *oc, const void *data)
     hc->unplug = virt_device_unplug;
 
     object_class_property_add_enum(oc, "acpi", "OnOffAuto",
-                                        &OnOffAuto_type_info, NULL,
-                                        virt_get_acpi, virt_set_acpi);
+                                   &OnOffAuto_type_info, virt_get_acpi,
+                                   virt_set_acpi);
     object_class_property_set_description(oc, "acpi",
         "Enable ACPI");
     object_class_property_add_enum(oc, "v-eiointc", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   virt_get_veiointc, virt_set_veiointc);
+                                   &OnOffAuto_type_info, virt_get_veiointc,
+                                   virt_set_veiointc);
     object_class_property_set_description(oc, "v-eiointc",
                             "Enable Virt Extend I/O Interrupt Controller.");
-    object_class_property_add_enum(oc,  "dmsi", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   virt_get_dmsi, virt_set_dmsi);
+    object_class_property_add_enum(oc, "dmsi", "OnOffAuto",
+                                   &OnOffAuto_type_info, virt_get_dmsi,
+                                   virt_set_dmsi);
     object_class_property_set_description(oc, "dmsi",
                             "Enable direct Message-interrupts Controller.");
     machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -1
index b52f12924d..4ad04801ce 100644
@@ -176,7 +176,7 @@ static void petalogix_s3adsp1800_machine_class_init(ObjectClass *oc,
     mc->is_default = true;
 
     prop = object_class_property_add_enum(oc, "endianness", "EndianMode",
-                                          &EndianMode_type_info, NULL,
+                                          &EndianMode_type_info,
                                           machine_get_endianness,
                                           machine_set_endianness);
     object_property_set_default_str(prop, target_big_endian() ? "big"
hw/riscv/virt.c +5 -5
index 31fecdc964..0cb731482a 100644
@@ -1175,14 +1175,14 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
     }
 
     object_class_property_add_enum(oc, "acpi", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   virt_get_acpi, virt_set_acpi);
+                                   &OnOffAuto_type_info, virt_get_acpi,
+                                   virt_set_acpi);
     object_class_property_set_description(oc, "acpi",
                                           "Enable ACPI");
 
-    object_class_property_add_enum(oc,  "iommu-sys", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   virt_get_iommu_sys, virt_set_iommu_sys);
+    object_class_property_add_enum(oc, "iommu-sys", "OnOffAuto",
+                                   &OnOffAuto_type_info, virt_get_iommu_sys,
+                                   virt_set_iommu_sys);
     object_class_property_set_description(oc, "iommu-sys",
                                           "Enable IOMMU platform device");
 }
monitor/qmp.c +1 -1
index c6341f1a20..d2e45d3993 100644
@@ -136,7 +136,7 @@ static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
                                    monitor_qmp_set_pretty);
     object_class_property_add_enum(cls, "close-action",
                                    "MonitorQMPCloseAction",
-                                   &MonitorQMPCloseAction_type_info, NULL,
+                                   &MonitorQMPCloseAction_type_info,
                                    monitor_qmp_get_close_action,
                                    monitor_qmp_set_close_action);
 
net/filter.c +3 -2
index 9013d872ea..145c72107a 100644
@@ -344,8 +344,9 @@ static void netfilter_class_init(ObjectClass *oc, const void *data)
     object_class_property_add_str(oc, "netdev",
                                   netfilter_get_netdev_id, netfilter_set_netdev_id);
     object_class_property_add_enum(oc, "queue", "NetFilterDirection",
-                                   &NetFilterDirection_type_info, NULL,
-                                   netfilter_get_direction, netfilter_set_direction);
+                                   &NetFilterDirection_type_info,
+                                   netfilter_get_direction,
+                                   netfilter_set_direction);
     object_class_property_add_str(oc, "status",
                                   netfilter_get_status, netfilter_set_status);
     object_class_property_add_str(oc, "position",
qom/object.c +4 -11
index 637459c2b1..c285eb849f 100644
@@ -2501,8 +2501,7 @@ object_class_property_add_bool(ObjectClass *klass, const char *name,
 }
 
 typedef struct EnumProperty {
-    const QAPITypeInfo *qapi_type; /* non-null for QAPI enums */
-    const QEnumLookup *lookup;
+    const QAPITypeInfo *qapi_type;
     int (*get)(Object *, Error **);
     void (*set)(Object *, int, Error **);
 } EnumProperty;
@@ -2520,7 +2519,7 @@ static void property_get_enum(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    visit_type_enum(v, name, &value, prop->lookup, errp);
+    visit_type_enum(v, name, &value, prop->qapi_type->lookup, errp);
 }
 
 static void property_set_enum(Object *obj, Visitor *v, const char *name,
@@ -2529,7 +2528,7 @@ static void property_set_enum(Object *obj, Visitor *v, const char *name,
     EnumProperty *prop = opaque;
     int value;
 
-    if (!visit_type_enum(v, name, &value, prop->lookup, errp)) {
+    if (!visit_type_enum(v, name, &value, prop->qapi_type->lookup, errp)) {
         return;
     }
     prop->set(obj, value, errp);
@@ -2539,15 +2538,12 @@ ObjectProperty *
 object_property_add_enum(Object *obj, const char *name,
                          const char *typename,
                          const QAPITypeInfo *qapi_type,
-                         const QEnumLookup *lookup,
                          int (*get)(Object *, Error **),
                          void (*set)(Object *, int, Error **))
 {
     EnumProperty *prop = g_malloc(sizeof(*prop));
 
-    assert(!qapi_type != !lookup);
     prop->qapi_type = qapi_type;
-    prop->lookup = lookup ?: qapi_type->lookup;
     prop->get = get;
     prop->set = set;
 
@@ -2562,15 +2558,12 @@ ObjectProperty *
 object_class_property_add_enum(ObjectClass *klass, const char *name,
                                     const char *typename,
                                     const QAPITypeInfo *qapi_type,
-                                    const QEnumLookup *lookup,
                                     int (*get)(Object *, Error **),
                                     void (*set)(Object *, int, Error **))
 {
     EnumProperty *prop = g_malloc(sizeof(*prop));
 
-    assert(!qapi_type != !lookup);
     prop->qapi_type = qapi_type;
-    prop->lookup = lookup ?: qapi_type->lookup;
     prop->get = get;
     prop->set = set;
 
@@ -2607,7 +2600,7 @@ int object_property_get_enum(Object *obj, const char *name,
         return -1;
     }
 
-    ret = qapi_enum_parse(enumprop->lookup, str, -1, errp);
+    ret = qapi_enum_parse(enumprop->qapi_type->lookup, str, -1, errp);
     g_free(str);
 
     return ret;
target/i386/kvm/kvm.c +2 -2
index e003e47c5b..64c9e2e379 100644
@@ -7092,7 +7092,7 @@ static void kvm_arch_set_honor_guest_pat(Object *obj, int value, Error **errp)
 void kvm_arch_accel_class_init(ObjectClass *oc)
 {
     object_class_property_add_enum(oc, "notify-vmexit", "NotifyVMexitOption",
-                                   &NotifyVmexitOption_type_info, NULL,
+                                   &NotifyVmexitOption_type_info,
                                    kvm_arch_get_notify_vmexit,
                                    kvm_arch_set_notify_vmexit);
     object_class_property_set_description(oc, "notify-vmexit",
@@ -7132,7 +7132,7 @@ void kvm_arch_accel_class_init(ObjectClass *oc)
                                           "Maximum number of Xen PIRQs");
 
     object_class_property_add_enum(oc, "honor-guest-pat", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+                                   &OnOffAuto_type_info,
                                    kvm_arch_get_honor_guest_pat,
                                    kvm_arch_set_honor_guest_pat);
     object_class_property_set_description(oc, "honor-guest-pat",
target/i386/sev.c +1 -1
index c1c12d1125..604c2255ac 100644
@@ -3019,7 +3019,7 @@ sev_guest_class_init(ObjectClass *oc, const void *data)
     object_class_property_set_description(oc, "session-file",
             "guest owners session parameters (encoded with base64)");
     object_class_property_add_enum(oc, "legacy-vm-type", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
+                                   &OnOffAuto_type_info,
                                    sev_guest_get_legacy_vm_type,
                                    sev_guest_set_legacy_vm_type);
     object_class_property_set_description(oc, "legacy-vm-type",
target/i386/whpx/whpx-all.c +3 -4
index c459138c7e..e3e672dcd1 100644
@@ -2974,17 +2974,16 @@ void whpx_arch_accel_class_init(ObjectClass *oc)
 {
     object_class_property_add_enum(oc, "ignore-unknown-msr", "OnOffAuto",
                                    &OnOffAuto_type_info, NULL,
-                                   NULL, whpx_set_unknown_msr);
+                                   whpx_set_unknown_msr);
     object_class_property_set_description(oc, "ignore-unknown-msr",
         "Configure unknown MSR behavior");
     object_class_property_add_enum(oc, "intercept-msr-gp", "OnOffAuto",
                                    &OnOffAuto_type_info, NULL,
-                                   NULL, whpx_set_intercept_msr_gp);
+                                   whpx_set_intercept_msr_gp);
     object_class_property_set_description(oc, "intercept-msr-gp",
         "Intercept #GP to log erroring MSR accesses.");
     object_class_property_add_enum(oc, "ssd", "OnOffAuto",
-                                   &OnOffAuto_type_info, NULL,
-                                   NULL, whpx_set_ssd);
+                                   &OnOffAuto_type_info, NULL, whpx_set_ssd);
     object_class_property_set_description(oc, "ssd",
         "Separate security domain");
 }
tests/unit/check-qom-proplist.c +1 -2
index 246935d714..381a868a80 100644
@@ -152,8 +152,7 @@ static void dummy_class_init(ObjectClass *cls, const void *data)
                               dummy_get_sv, dummy_set_sv,
                               NULL, NULL);
     object_class_property_add_enum(cls, "av", "DummyAnimal",
-                                   &dummy_animal_qapi_type_info, NULL,
-                                   dummy_get_av,
+                                   &dummy_animal_qapi_type_info, dummy_get_av,
                                    dummy_set_av);
 }
 
ui/dbus.c +2 -2
index 9c21204771..f473a66889 100644
@@ -511,8 +511,8 @@ dbus_display_class_init(ObjectClass *oc, const void *data)
     object_class_property_add_str(oc, "addr", get_dbus_addr, set_dbus_addr);
     object_class_property_add_str(oc, "audiodev", get_audiodev, set_audiodev);
     object_class_property_add_enum(oc, "gl-mode", "DisplayGLMode",
-                                   &DisplayGLMode_type_info, NULL,
-                                   get_gl_mode, set_gl_mode);
+                                   &DisplayGLMode_type_info, get_gl_mode,
+                                   set_gl_mode);
 }
 
 #define TYPE_CHARDEV_VC "chardev-vc"
ui/input-linux.c +1 -1
index 127be74450..c7f9114036 100644
@@ -508,7 +508,7 @@ static void input_linux_class_init(ObjectClass *oc, const void *data)
                                    input_linux_get_repeat,
                                    input_linux_set_repeat);
     object_class_property_add_enum(oc, "grab-toggle", "GrabToggleKeys",
-                                   &GrabToggleKeys_type_info, NULL,
+                                   &GrabToggleKeys_type_info,
                                    input_linux_get_grab_toggle,
                                    input_linux_set_grab_toggle);
 }
Signature · 1 line
2.55.0
#64 lore raw

PATCH v8 55/56 qom: use QAPITypeInfo in object_property_get_enum

In reply to Markus Armbruster

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

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

---
 include/qom/object.h            |  4 ++--
 hw/core/machine-qmp-cmds.c      |  4 +++-
 qom/object.c                    | 14 ++++++--------
 tests/unit/check-qom-proplist.c |  6 +++---
 4 files changed, 14 insertions(+), 14 deletions(-)
include/qom/object.h +2 -2
index a90cd30675..9338f0b986 100644
@@ -1562,7 +1562,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
@@ -1570,7 +1570,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:
hw/core/machine-qmp-cmds.c +3 -1
index 07a048d0a9..0558d6d703 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"
@@ -278,7 +279,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",
qom/object.c +6 -8
index c285eb849f..0858c4a214 100644
@@ -2575,32 +2575,30 @@ object_class_property_add_enum(ObjectClass *klass, 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;
     ObjectProperty *prop = object_property_find_err(obj, name, errp);
-    EnumProperty *enumprop;
 
     if (prop == NULL) {
         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;
     }
 
-    enumprop = prop->opaque;
-
     str = object_property_get_str(obj, name, errp);
     if (!str) {
         return -1;
     }
 
-    ret = qapi_enum_parse(enumprop->qapi_type->lookup, str, -1, errp);
+    assert(prop->qapi_type);
+    ret = qapi_enum_parse(prop->qapi_type->lookup, str, -1, errp);
     g_free(str);
 
     return ret;
tests/unit/check-qom-proplist.c +3 -3
index 381a868a80..bf7c1386be 100644
@@ -580,14 +580,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);
@@ -595,7 +595,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.55.0
#65 lore raw

PATCH v8 56/56 tests/qmp-cmd-test: assert qapi-type resolves in query-qmp-schema

In reply to Markus Armbruster

From: Marc-André Lureau <[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 279a8f5614..acb7b0dd6a 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.55.0