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>,
"Michael S. Tsirkin" <mst@redhat.com>,
"David Hildenbrand" <david@kernel.org>,
"Eric Blake" <eblake@redhat.com>,
"Zhao Liu" <zhao1.liu@intel.com>
Subject: [PATCH v3 49/74] virtio-balloon: convert guest-stats property to QAPI type
Date: Tue, 18 Aug 2026 15:11:16 +0400 [thread overview]
Message-ID: <20260818-qom-qapi-v3-49-24b8bbbe3d86@redhat.com> (raw)
In-Reply-To: <20260818-qom-qapi-v3-0-24b8bbbe3d86@redhat.com>
Define VirtioBalloonStats and VirtioBalloonGuestStats QAPI struct types
in the schema, replacing the hand-rolled visitor in balloon_stats_get_all()
with a generated visit_type_VirtioBalloonGuestStats() call.
The wire format is preserved: the JSON output from qom-get is identical
to the previous hand-rolled visitor output.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
docs/interop/virtio-balloon-stats.rst | 22 +--------
hw/virtio/virtio-balloon.c | 84 ++++++++++++--------------------
qapi/machine.json | 92 +++++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+), 75 deletions(-)
diff --git a/docs/interop/virtio-balloon-stats.rst b/docs/interop/virtio-balloon-stats.rst
index b9a6a6edb229..88d3271bbb02 100644
--- a/docs/interop/virtio-balloon-stats.rst
+++ b/docs/interop/virtio-balloon-stats.rst
@@ -22,27 +22,7 @@ polling the guest's balloon driver for new stats in the specified time
interval.
To retrieve those stats, clients have to query the guest-stats property,
-which will return a dictionary containing:
-
- * A key named 'stats', containing all available stats. If the guest
- doesn't support a particular stat, or if it couldn't be retrieved,
- its value will be -1. Currently, the following stats are supported:
-
- - stat-swap-in
- - stat-swap-out
- - stat-major-faults
- - stat-minor-faults
- - stat-free-memory
- - stat-total-memory
- - stat-available-memory
- - stat-disk-caches
- - stat-htlb-pgalloc
- - stat-htlb-pgfail
-
- * A key named last-update, which contains the last stats update
- timestamp in seconds. Since this timestamp is generated by the host,
- a buggy guest can't influence its value. The value is 0 if the guest
- has not updated the stats (yet).
+which will return a VirtioBalloonGuestStats (see QAPI documentation).
It's also important to note the following:
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 9e43948128f7..c9873f8cf0c2 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -29,6 +29,8 @@
#include "qapi/error.h"
#include "qapi/qapi-builtin-type-infos.h"
#include "qapi/qapi-events-machine.h"
+#include "qapi/qapi-type-infos-machine.h"
+#include "qapi/qapi-visit-machine.h"
#include "qapi/visitor.h"
#include "trace.h"
#include "qemu/error-report.h"
@@ -169,33 +171,8 @@ static void balloon_deflate_page(VirtIOBalloon *balloon,
}
}
-/*
- * All stats upto VIRTIO_BALLOON_S_NR /must/ have a
- * non-NULL name declared here, since these are used
- * as keys for populating the QDict with stats
- */
-static const char *balloon_stat_names[] = {
- [VIRTIO_BALLOON_S_SWAP_IN] = "stat-swap-in",
- [VIRTIO_BALLOON_S_SWAP_OUT] = "stat-swap-out",
- [VIRTIO_BALLOON_S_MAJFLT] = "stat-major-faults",
- [VIRTIO_BALLOON_S_MINFLT] = "stat-minor-faults",
- [VIRTIO_BALLOON_S_MEMFREE] = "stat-free-memory",
-
- [VIRTIO_BALLOON_S_MEMTOT] = "stat-total-memory",
- [VIRTIO_BALLOON_S_AVAIL] = "stat-available-memory",
- [VIRTIO_BALLOON_S_CACHES] = "stat-disk-caches",
- [VIRTIO_BALLOON_S_HTLB_PGALLOC] = "stat-htlb-pgalloc",
- [VIRTIO_BALLOON_S_HTLB_PGFAIL] = "stat-htlb-pgfail",
-
- [VIRTIO_BALLOON_S_OOM_KILL] = "stat-oom-kills",
- [VIRTIO_BALLOON_S_ALLOC_STALL] = "stat-alloc-stalls",
- [VIRTIO_BALLOON_S_ASYNC_SCAN] = "stat-async-scans",
- [VIRTIO_BALLOON_S_DIRECT_SCAN] = "stat-direct-scans",
- [VIRTIO_BALLOON_S_ASYNC_RECLAIM] = "stat-async-reclaims",
-
- [VIRTIO_BALLOON_S_DIRECT_RECLAIM] = "stat-direct-reclaims",
-};
-G_STATIC_ASSERT(G_N_ELEMENTS(balloon_stat_names) == VIRTIO_BALLOON_S_NR);
+/* Update VirtioBalloonStats QAPI type when new stats are added */
+G_STATIC_ASSERT(VIRTIO_BALLOON_S_NR == 16);
/*
* reset_stats - Mark all items in the stats array as unset
@@ -257,33 +234,31 @@ static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
VirtIOBalloon *s = VIRTIO_BALLOON(obj);
- bool ok = false;
- int i;
+ VirtioBalloonStats stats = {
+ .stat_swap_in = s->stats[VIRTIO_BALLOON_S_SWAP_IN],
+ .stat_swap_out = s->stats[VIRTIO_BALLOON_S_SWAP_OUT],
+ .stat_major_faults = s->stats[VIRTIO_BALLOON_S_MAJFLT],
+ .stat_minor_faults = s->stats[VIRTIO_BALLOON_S_MINFLT],
+ .stat_free_memory = s->stats[VIRTIO_BALLOON_S_MEMFREE],
+ .stat_total_memory = s->stats[VIRTIO_BALLOON_S_MEMTOT],
+ .stat_available_memory = s->stats[VIRTIO_BALLOON_S_AVAIL],
+ .stat_disk_caches = s->stats[VIRTIO_BALLOON_S_CACHES],
+ .stat_htlb_pgalloc = s->stats[VIRTIO_BALLOON_S_HTLB_PGALLOC],
+ .stat_htlb_pgfail = s->stats[VIRTIO_BALLOON_S_HTLB_PGFAIL],
+ .stat_oom_kills = s->stats[VIRTIO_BALLOON_S_OOM_KILL],
+ .stat_alloc_stalls = s->stats[VIRTIO_BALLOON_S_ALLOC_STALL],
+ .stat_async_scans = s->stats[VIRTIO_BALLOON_S_ASYNC_SCAN],
+ .stat_direct_scans = s->stats[VIRTIO_BALLOON_S_DIRECT_SCAN],
+ .stat_async_reclaims = s->stats[VIRTIO_BALLOON_S_ASYNC_RECLAIM],
+ .stat_direct_reclaims = s->stats[VIRTIO_BALLOON_S_DIRECT_RECLAIM],
+ };
+ VirtioBalloonGuestStats guest_stats = {
+ .last_update = s->stats_last_update,
+ .stats = &stats,
+ };
+ VirtioBalloonGuestStats *argp = &guest_stats;
- if (!visit_start_struct(v, name, NULL, 0, errp)) {
- return;
- }
- if (!visit_type_int(v, "last-update", &s->stats_last_update, errp)) {
- goto out_end;
- }
-
- if (!visit_start_struct(v, "stats", NULL, 0, errp)) {
- goto out_end;
- }
- for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) {
- if (!visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], errp)) {
- goto out_nested;
- }
- }
- ok = visit_check_struct(v, errp);
-out_nested:
- visit_end_struct(v, NULL);
-
- if (ok) {
- visit_check_struct(v, errp);
- }
-out_end:
- visit_end_struct(v, NULL);
+ visit_type_VirtioBalloonGuestStats(v, name, &argp, errp);
}
static void balloon_stats_get_poll_interval(Object *obj, Visitor *v,
@@ -1020,7 +995,8 @@ static void virtio_balloon_instance_init(Object *obj)
s->free_page_hint_cmd_id = VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
s->free_page_hint_notify.notify = virtio_balloon_free_page_hint_notify;
- object_property_add(obj, "guest-stats", "guest statistics",
+ object_property_add_qapi(obj, "guest-stats",
+ &VirtioBalloonGuestStats_type_info,
balloon_stats_get_all, NULL, NULL, NULL);
object_property_add_qapi(obj, "guest-stats-polling-interval", &int_type_info,
diff --git a/qapi/machine.json b/qapi/machine.json
index 2d63c1bac3b4..d418b34a8643 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -1132,6 +1132,98 @@
##
{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } }
+##
+# @VirtioBalloonStats:
+#
+# VirtIO balloon device guest memory statistics.
+#
+# If the guest doesn't support a particular stat, or if it couldn't
+# be retrieved, its value will be -1.
+#
+# @stat-swap-in: The amount of memory that has been
+# swapped in (in bytes).
+#
+# @stat-swap-out: The amount of memory that has been
+# swapped out to disk (in bytes).
+#
+# @stat-major-faults: The number of major page faults
+# that have occurred.
+#
+# @stat-minor-faults: The number of minor page faults
+# that have occurred.
+#
+# @stat-free-memory: The amount of memory not being used
+# for any purpose (in bytes).
+#
+# @stat-total-memory: The total amount of memory available
+# (in bytes).
+#
+# @stat-available-memory: An estimate of how much memory is available
+# (in bytes) for starting new applications, without pushing the
+# system to swap.
+#
+# @stat-disk-caches: The amount of memory, in bytes, that can be
+# quickly reclaimed without additional I/O. Typically these pages
+# are used for caching files from disk.
+#
+# @stat-htlb-pgalloc: The number of successful hugetlb page
+# allocations
+#
+# @stat-htlb-pgfail: The number of failed hugetlb page
+# allocations
+#
+# @stat-oom-kills: The number of OOM killer invocations
+#
+# @stat-alloc-stalls: The number of memory allocation stalls
+#
+# @stat-async-scans: The number of memory scanned asynchronously
+#
+# @stat-direct-scans: The number of memory scanned directly
+#
+# @stat-async-reclaims: The number of memory reclaimed asynchronously
+#
+# @stat-direct-reclaims: The number of memory reclaimed directly
+#
+# Since: 11.2
+##
+{ 'struct': 'VirtioBalloonStats',
+ 'data': {
+ 'stat-swap-in': 'uint64',
+ 'stat-swap-out': 'uint64',
+ 'stat-major-faults': 'uint64',
+ 'stat-minor-faults': 'uint64',
+ 'stat-free-memory': 'uint64',
+ 'stat-total-memory': 'uint64',
+ 'stat-available-memory': 'uint64',
+ 'stat-disk-caches': 'uint64',
+ 'stat-htlb-pgalloc': 'uint64',
+ 'stat-htlb-pgfail': 'uint64',
+ 'stat-oom-kills': 'uint64',
+ 'stat-alloc-stalls': 'uint64',
+ 'stat-async-scans': 'uint64',
+ 'stat-direct-scans': 'uint64',
+ 'stat-async-reclaims': 'uint64',
+ 'stat-direct-reclaims': 'uint64' } }
+
+##
+# @VirtioBalloonGuestStats:
+#
+# Guest statistics from the VirtIO balloon device.
+#
+# @last-update: timestamp in seconds of the last stats
+# update from the guest (since this timestamp is generated
+# by the host, a buggy guest can't influence its value),
+# or 0 if no update has been received yet.
+#
+# @stats: balloon memory statistics
+#
+# Since: 11.2
+##
+{ 'struct': 'VirtioBalloonGuestStats',
+ 'data': {
+ 'last-update': 'int',
+ 'stats': 'VirtioBalloonStats' } }
+
##
# @query-balloon:
#
--
2.55.0.543.g5ebe2ebe4ea8
next prev 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 ` Marc-André Lureau [this message]
2026-08-18 11:11 ` [PATCH v3 50/74] qom: replace object_property_add_tm with StructTm QAPI type Marc-André Lureau
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-49-24b8bbbe3d86@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=david@kernel.org \
--cc=eblake@redhat.com \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@mailo.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@intel.com \
/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.