All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	qemu-ppc@nongnu.org
Subject: [PATCH v3 50/74] qom: replace object_property_add_tm with StructTm QAPI type
Date: Tue, 18 Aug 2026 15:11:17 +0400	[thread overview]
Message-ID: <20260818-qom-qapi-v3-50-24b8bbbe3d86@redhat.com> (raw)
In-Reply-To: <20260818-qom-qapi-v3-0-24b8bbbe3d86@redhat.com>

Define a StructTm QAPI struct in common.json matching the existing
"struct tm" property wire format (tm_year, tm_mon, tm_mday, tm_hour,
tm_min, tm_sec as int32).

Convert the two callers (mc146818rtc and spapr_rtc) to use
object_property_add_qapi() with a standard ObjectPropertyAccessor
that populates a StructTm and calls the generated visitor.

Remove object_property_add_tm(), object_class_property_add_tm(),
the TMProperty type, and the property_get_tm() helper from
qom/object.c, along with their declarations in object.h.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/ppc/spapr_rtc.c   | 18 +++++++++++---
 hw/rtc/mc146818rtc.c | 16 +++++++++---
 include/qom/object.h | 29 ----------------------
 qapi/common.json     | 28 +++++++++++++++++++++
 qapi/pragma.json     |  1 +
 qom/object.c         | 69 ----------------------------------------------------
 6 files changed, 57 insertions(+), 104 deletions(-)

diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c
index 1f7d2d8f898b..a4a2b3237e26 100644
--- a/hw/ppc/spapr_rtc.c
+++ b/hw/ppc/spapr_rtc.c
@@ -33,6 +33,9 @@
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-misc.h"
+#include "qapi/qapi-type-infos-common.h"
+#include "qapi/qapi-visit-common.h"
+#include "qapi/visitor.h"
 #include "qemu/cutils.h"
 #include "qemu/module.h"
 
@@ -131,9 +134,17 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, SpaprMachineState *spapr,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
-static void spapr_rtc_qom_date(Object *obj, struct tm *current_tm, Error **errp)
+static void spapr_rtc_qom_date(Object *obj, Visitor *v, const char *name,
+                               void *opaque, Error **errp)
 {
-    spapr_rtc_read(SPAPR_RTC(obj), current_tm, NULL);
+    struct tm value;
+    StructTm tm, *tmp = &tm;
+
+    spapr_rtc_read(SPAPR_RTC(obj), &value, NULL);
+
+    tm = (StructTm) { value.tm_year, value.tm_mon, value.tm_mday,
+                      value.tm_hour, value.tm_min, value.tm_sec };
+    visit_type_StructTm(v, name, &tmp, errp);
 }
 
 static void spapr_rtc_realize(DeviceState *dev, Error **errp)
@@ -150,7 +161,8 @@ static void spapr_rtc_realize(DeviceState *dev, Error **errp)
     rtc_ns = qemu_clock_get_ns(rtc_clock);
     rtc->ns_offset = host_s * NANOSECONDS_PER_SECOND - rtc_ns;
 
-    object_property_add_tm(OBJECT(rtc), "date", spapr_rtc_qom_date);
+    object_property_add_qapi(OBJECT(rtc), "date", &StructTm_type_info,
+                             spapr_rtc_qom_date, NULL, NULL, NULL);
 }
 
 static const VMStateDescription vmstate_spapr_rtc = {
diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c
index ba396435d1af..328dd038f167 100644
--- a/hw/rtc/mc146818rtc.c
+++ b/hw/rtc/mc146818rtc.c
@@ -42,6 +42,8 @@
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-misc.h"
+#include "qapi/qapi-type-infos-common.h"
+#include "qapi/qapi-visit-common.h"
 #include "qapi/visitor.h"
 #include "trace.h"
 
@@ -854,12 +856,19 @@ static const MemoryRegionOps cmos_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void rtc_get_date(Object *obj, struct tm *current_tm, Error **errp)
+static void rtc_get_date(Object *obj, Visitor *v, const char *name,
+                         void *opaque, Error **errp)
 {
     MC146818RtcState *s = MC146818_RTC(obj);
+    struct tm value;
+    StructTm tm, *tmp = &tm;
 
     rtc_update_time(s);
-    rtc_get_time(s, current_tm);
+    rtc_get_time(s, &value);
+
+    tm = (StructTm) { value.tm_year, value.tm_mon, value.tm_mday,
+                      value.tm_hour, value.tm_min, value.tm_sec };
+    visit_type_StructTm(v, name, &tmp, errp);
 }
 
 static void rtc_realizefn(DeviceState *dev, Error **errp)
@@ -1019,7 +1028,8 @@ static void rtc_class_initfn(ObjectClass *klass, const void *data)
     device_class_set_props(dc, mc146818rtc_properties);
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 
-    object_class_property_add_tm(klass, "date", rtc_get_date);
+    object_class_property_add_qapi(klass, "date", &StructTm_type_info,
+                                   rtc_get_date, NULL, NULL, NULL);
 }
 
 static const TypeInfo mc146818rtc_info = {
diff --git a/include/qom/object.h b/include/qom/object.h
index 70217eba1473..db4972294e39 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -2049,35 +2049,6 @@ object_class_property_add_qapi(ObjectClass *klass,
                                ObjectPropertyRelease *release,
                                void *opaque);
 
-/**
- * object_property_add_tm:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @get: the getter or NULL if the property is write-only.
- *
- * Add a read-only struct tm valued property using a getter function.
- * This function will add a property of type 'struct tm'.
- *
- * Returns: The newly added property on success, or %NULL on failure.
- */
-ObjectProperty *object_property_add_tm(Object *obj, const char *name,
-                            void (*get)(Object *, struct tm *, Error **));
-
-/**
- * object_class_property_add_tm:
- * @klass: the object class to add a property to
- * @name: the name of the property
- * @get: the getter or NULL if the property is write-only.
- *
- * Add a read-only struct tm valued property using a getter function.
- * This function will add a property of type 'struct tm'.
- *
- * Returns: The newly added property on success, or %NULL on failure.
- */
-ObjectProperty *object_class_property_add_tm(ObjectClass *klass,
-                            const char *name,
-                            void (*get)(Object *, struct tm *, Error **));
-
 typedef enum {
     /* Automatically add a getter to the property */
     OBJ_PROP_FLAG_READ = 1 << 0,
diff --git a/qapi/common.json b/qapi/common.json
index af7e3d618a7c..928ba0ba2c63 100644
--- a/qapi/common.json
+++ b/qapi/common.json
@@ -228,3 +228,31 @@
 ##
 { 'enum': 'EndianMode',
   'data': [ 'unspecified', 'little', 'big' ] }
+
+##
+# @StructTm:
+#
+# Broken-down time.  Field semantics match C ``struct tm``.
+#
+# @tm_year: years since 1900
+#
+# @tm_mon: months since January (0-11)
+#
+# @tm_mday: day of the month (1-31)
+#
+# @tm_hour: hours since midnight (0-23)
+#
+# @tm_min: minutes after the hour (0-59)
+#
+# @tm_sec: seconds after the minute (0-59, 60-61 for leap seconds)
+#
+# Since: 11.2
+##
+{ 'struct': 'StructTm',
+  'data': {
+    'tm_year': 'int32',
+    'tm_mon': 'int32',
+    'tm_mday': 'int32',
+    'tm_hour': 'int32',
+    'tm_min': 'int32',
+    'tm_sec': 'int32' } }
diff --git a/qapi/pragma.json b/qapi/pragma.json
index 24aebbe8f5fc..8283149693d8 100644
--- a/qapi/pragma.json
+++ b/qapi/pragma.json
@@ -108,6 +108,7 @@
         'QKeyCode',                 # send-key, input-sent-event
         'QapiErrorClass',           # QMP error replies
         'SshHostKeyCheckMode',      # blockdev-add, -blockdev
+        'StructTm',                 # qom-get of RTC date property
         'SysEmuTarget',             # query-cpu-fast, query-target
         'UuidInfo',                 # query-uuid
         'VncClientInfo',            # query-vnc, query-vnc-servers, ...
diff --git a/qom/object.c b/qom/object.c
index 65e640d1b7d1..4d7c9181fb6e 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2628,75 +2628,6 @@ object_class_property_add_qapi(ObjectClass *klass, const char *name,
     return prop;
 }
 
-typedef struct TMProperty {
-    void (*get)(Object *, struct tm *, Error **);
-} TMProperty;
-
-static void property_get_tm(Object *obj, Visitor *v, const char *name,
-                            void *opaque, Error **errp)
-{
-    TMProperty *prop = opaque;
-    Error *err = NULL;
-    struct tm value;
-
-    prop->get(obj, &value, &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
-
-    if (!visit_start_struct(v, name, NULL, 0, errp)) {
-        return;
-    }
-    if (!visit_type_int32(v, "tm_year", &value.tm_year, errp)) {
-        goto out_end;
-    }
-    if (!visit_type_int32(v, "tm_mon", &value.tm_mon, errp)) {
-        goto out_end;
-    }
-    if (!visit_type_int32(v, "tm_mday", &value.tm_mday, errp)) {
-        goto out_end;
-    }
-    if (!visit_type_int32(v, "tm_hour", &value.tm_hour, errp)) {
-        goto out_end;
-    }
-    if (!visit_type_int32(v, "tm_min", &value.tm_min, errp)) {
-        goto out_end;
-    }
-    if (!visit_type_int32(v, "tm_sec", &value.tm_sec, errp)) {
-        goto out_end;
-    }
-    visit_check_struct(v, errp);
-out_end:
-    visit_end_struct(v, NULL);
-}
-
-ObjectProperty *
-object_property_add_tm(Object *obj, const char *name,
-                       void (*get)(Object *, struct tm *, Error **))
-{
-    TMProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-
-    return object_property_add(obj, name, "struct tm",
-                               get ? property_get_tm : NULL, NULL,
-                               property_release_data,
-                               prop);
-}
-
-ObjectProperty *
-object_class_property_add_tm(ObjectClass *klass, const char *name,
-                             void (*get)(Object *, struct tm *, Error **))
-{
-    TMProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-
-    return object_class_property_add(klass, name, "struct tm",
-                                     get ? property_get_tm : NULL,
-                                     NULL, NULL, prop);
-}
 
 static char *object_get_type(Object *obj, Error **errp)
 {

-- 
2.55.0.543.g5ebe2ebe4ea8



  parent reply	other threads:[~2026-08-18 11:25 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 11:10 [PATCH v3 00/74] qom/qdev: associate properties with QAPI schema types Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 01/74] qapi: add QAPITypeInfo struct definition Marc-André Lureau
2026-08-21 13:40   ` Markus Armbruster
2026-08-21 15:33     ` Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 02/74] qapi/gen: fix _module_basename for multi-dash 'what' parameters Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 03/74] qapi: factor out QAPISchemaUsedTypes from introspect visitor Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 04/74] qapi: register all introspectable types, not just QMP-reachable ones Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 05/74] qapi: add type-infos generator Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 06/74] meson: add qapi-type-infos-*.c/h to build Marc-André Lureau
2026-08-18 11:41   ` Kostiantyn Kostiuk
2026-08-18 11:10 ` [PATCH v3 07/74] qom: add qapi_type field to ObjectProperty Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 08/74] qapi/qom: add qapi-type field to ObjectPropertyInfo Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 09/74] qom/qmp: populate qapi-type in QMP handlers Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 10/74] qom: add object_property_set_default_enum() Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 11/74] qom: add object_{class_}property_add_qapi Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 12/74] qom: add object_{class_}property_add_qapi_enum Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 13/74] tests: update check-qom-proplist for QAPI-aware property registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 14/74] qom: convert enum properties to QAPI-aware registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 15/74] qom: remove old enum property registration API Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 16/74] qom: convert struct properties to QAPI-aware registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 17/74] x86: convert OnOffAuto " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 18/74] microvm: " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 19/74] pc: convert OnOffAuto vmport property " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 20/74] arm/virt: convert OnOffAuto acpi " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 21/74] riscv/virt: convert OnOffAuto properties " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 22/74] loongarch/virt: " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 23/74] hostmem-file: convert OnOffAuto rom property " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 24/74] sev: convert OnOffAuto legacy-vm-type " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 25/74] whpx: convert OnOffAuto hyperv " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 26/74] whpx: convert OnOffAuto arch properties " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 27/74] accel/kvm: convert OnOffSplit property " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 28/74] whpx: " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 29/74] ppc/spapr-caps: convert to QAPI-aware property registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 30/74] system/memory: fix "priority" property typename Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 31/74] backends/hostmem: fix property typenames Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 32/74] backends/hostmem-file: fix "align" property typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 33/74] accel/tcg: fix "tb-size" " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 34/74] block/throttle-groups: fix throttle properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 35/74] event-loop-base: fix property typenames Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 36/74] iothread: fix poll properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 37/74] util/thread-context: fix property typenames Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 38/74] target/i386: fix CPUID version properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 39/74] ppc/pnv: fix phb-id and chip-id " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 40/74] backends/hostmem-memfd: fix "hugetlbsize" property typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 41/74] hw/acpi: fix "node" properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 42/74] net/colo-compare: fix compare_timeout setter visitor type Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 43/74] net/colo-compare: fix max_queue_size " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 44/74] hw/misc/xlnx-versal-trng: add missing getter for fips-fault-events Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 45/74] qom: convert scalar properties to QAPI-aware registration Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 46/74] i386/cpu: convert strList property " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 47/74] accel/hvf: convert OnOffSplit " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 48/74] i386/x86: convert SgxEPCList " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 49/74] virtio-balloon: convert guest-stats property to QAPI type Marc-André Lureau
2026-08-18 11:11 ` Marc-André Lureau [this message]
2026-08-18 11:11 ` [PATCH v3 51/74] hw/nvdimm: convert UUID property to QAPI-aware registration Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 52/74] hw/s390-virtio-ccw: convert loadparm " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 53/74] hw/ppc/spapr_drc: convert fdt " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 54/74] spdm-socket: convert SpdmTransportType to QAPI enum Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 55/74] hw/gpio/pca955x: use QAPI enums for led and pin properties Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 56/74] include: add QEMU_REPEAT helper macro Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 57/74] hw/gpio/pca955x: convert pin/led property to QAPI-aware enum Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 58/74] hw/pci: change the busnr type to uint8 Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 59/74] qdev: add qapi_type field to PropertyInfo with fallback registration Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 60/74] qdev: convert core PropertyInfo definitions to use qapi_type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 61/74] qdev: adjust PciDevfn declared type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 62/74] qdev: convert system PropertyInfo definitions to use qapi_type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 63/74] hw: convert device-local " Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 64/74] target/riscv: fix incorrect QAPI types and u8 casting Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 65/74] target/riscv: convert PropertyInfo definitions to use qapi_type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 66/74] qdev: " Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 67/74] qdev: introduce typed array PropertyInfos Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 68/74] qdev: simplify DEFINE_PROP_ARRAY and remove generic array PropertyInfo Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 69/74] qdev: remove deprecated PropertyInfo.type and .enum_table fields Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 70/74] memory: use object_property_add_link for container property Marc-André Lureau
2026-08-20 18:17   ` Peter Xu
2026-08-18 13:29 ` [PATCH v3 71/74] hw/i386: convert PCSouthBridgeOption to QAPI enum Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 72/74] qom: use QAPITypeInfo in object_property_get_enum Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 73/74] qapi: expose integer signedness and width in introspection Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 74/74] tests/qmp-cmd-test: assert qapi-type resolves in query-qmp-schema Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260818-qom-qapi-v3-50-24b8bbbe3d86@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=harshpb@linux.ibm.com \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@mailo.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.