]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Add handlers for 'block-latency-histogram-set'
authorPeter Krempa <pkrempa@redhat.com>
Thu, 11 Dec 2025 17:38:12 +0000 (18:38 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Feb 2026 09:25:01 +0000 (10:25 +0100)
Add QMP monitor code for setting up latency histogram configuration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 24990372ddde9147c11cf2533b740daa04696439..958cd3a247ff4be0484a13c7b39200031a60d2aa 100644 (file)
@@ -4569,3 +4569,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);
+}
index 88a908c7822d52afd8a42691d5defc7f44446c0b..ddbf3371ca1083ecbce9afec2120ce087eb04a1e 100644 (file)
@@ -1985,3 +1985,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);
index 0bb1ca7957c535f6389e86a044555941daa6d617..f87636795911ac2350d50f49aa19e18df80e995d 100644 (file)
@@ -9167,3 +9167,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);
+}
index 8f5434d0dfa0b94cea25e6e3c8a87106fd71a695..cf9e341fe34259b093d0d38d63ff6fd6689ec65d 100644 (file)
@@ -818,3 +818,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);
index c10faa6a6f30e1babf90dedf46e89ff6b5530028..8911895c7ee6dbd850d1b55cea52b3ad143cd9c8 100644 (file)
@@ -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)
 {
@@ -2971,6 +2979,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);