From 99b1b6fda9b4e098a7bbbbb44e02064c57bff558 Mon Sep 17 00:00:00 2001 Message-ID: <99b1b6fda9b4e098a7bbbbb44e02064c57bff558.1771336681.git.jdenemar@redhat.com> From: Peter Krempa Date: Thu, 11 Dec 2025 18:38:12 +0100 Subject: [PATCH] qemu: monitor: Add handlers for 'block-latency-histogram-set' Add QMP monitor code for setting up latency histogram configuration. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik (cherry picked from commit ad4830ce6844b75800685ea85b15a53b8dbc5ac6) https://issues.redhat.com/browse/RHEL-147866 [rhel-9.8] https://issues.redhat.com/browse/RHEL-131335 [rhel-10.2] --- src/qemu/qemu_monitor.c | 21 +++++++++++++ src/qemu/qemu_monitor.h | 9 ++++++ src/qemu/qemu_monitor_json.c | 60 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 9 ++++++ tests/qemumonitorjsontest.c | 9 ++++++ 5 files changed, 108 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index cdd08004fb..3d7477c01c 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4612,3 +4612,24 @@ qemuMonitorBlockdevSetActive(qemuMonitor *mon, return qemuMonitorJSONBlockdevSetActive(mon, nodename, active); } + + +int +qemuMonitorBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush) +{ + QEMU_CHECK_MONITOR(mon); + VIR_DEBUG("id='%s'", id); + + return qemuMonitorJSONBlockLatencyHistogramSet(mon, id, + boundaries, + boundaries_read, + boundaries_write, + boundaries_zone, + boundaries_flush); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 238f7be875..bbe400003a 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1988,3 +1988,12 @@ int qemuMonitorBlockdevSetActive(qemuMonitor *mon, const char *nodename, bool active); + +int +qemuMonitorBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index edeea22ee0..45f690d9e2 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9130,3 +9130,63 @@ qemuMonitorJSONBlockdevSetActive(qemuMonitor *mon, return qemuMonitorJSONCheckError(cmd, reply); } + + +static virJSONValue * +qemuMonitorJSONBlockLatencyHistogramBoundary(unsigned int *bound) +{ + g_autoptr(virJSONValue) ret = virJSONValueNewArray(); + + if (!bound) + return NULL; + + for (; *bound > 0; bound++) { + g_autoptr(virJSONValue) val = virJSONValueNewNumberUint(*bound); + + /* the only error is if the first argument is not an array */ + ignore_value(virJSONValueArrayAppend(ret, &val)); + } + + return g_steal_pointer(&ret); +} + + +int +qemuMonitorJSONBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush) +{ + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + + g_autoptr(virJSONValue) bound = NULL; + g_autoptr(virJSONValue) bound_read = NULL; + g_autoptr(virJSONValue) bound_write = NULL; + g_autoptr(virJSONValue) bound_zone = NULL; + g_autoptr(virJSONValue) bound_flush = NULL; + + bound = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries); + bound_read = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_read); + bound_write = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_write); + bound_zone = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_zone); + bound_flush = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_flush); + + if (!(cmd = qemuMonitorJSONMakeCommand("block-latency-histogram-set", + "s:id", id, + "A:boundaries", &bound, + "A:boundaries-read", &bound_read, + "A:boundaries-write", &bound_write, + "A:boundaries-zap", &bound_zone, + "A:boundaries-flush", &bound_flush, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + return qemuMonitorJSONCheckError(cmd, reply); +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index db9160eb68..b418f70048 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -815,3 +815,12 @@ int qemuMonitorJSONBlockdevSetActive(qemuMonitor *mon, const char *nodename, bool active); + +int +qemuMonitorJSONBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index bfe81739a7..1c1aaaa586 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1130,6 +1130,14 @@ GEN_TEST_FUNC(qemuMonitorJSONSetAction, GEN_TEST_FUNC(qemuMonitorJSONSetLaunchSecurityState, "sev_secret_header", "sev_secret", 0, true) +unsigned int testHistogramBoundaries[] = {10, 30, 50, 0}; +GEN_TEST_FUNC(qemuMonitorJSONBlockLatencyHistogramSet, "devid", + testHistogramBoundaries, + testHistogramBoundaries, + testHistogramBoundaries, + testHistogramBoundaries, + testHistogramBoundaries) + static int testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque) { @@ -2958,6 +2966,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONBlockJobCancel); DO_TEST_GEN(qemuMonitorJSONSetAction); DO_TEST_GEN(qemuMonitorJSONSetLaunchSecurityState); + DO_TEST_GEN(qemuMonitorJSONBlockLatencyHistogramSet); DO_TEST(qemuMonitorJSONGetBalloonInfo); DO_TEST(qemuMonitorJSONGetBlockInfo); DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo); -- 2.53.0