libvirt/libvirt-qemu_agent-Add-qemuAgentGetLoadAvg.patch
Jiri Denemark 05ff4ee618 libvirt-10.10.0-11.el9
- Add load average information type into virDomainGetGuestInfo (RHEL-88447)
- qemu_agent: Add qemuAgentGetLoadAvg() (RHEL-88447)
- qemu: Add support for VIR_DOMAIN_GUEST_INFO_LOAD (RHEL-88447)
- virsh: Add support for VIR_DOMAIN_GUEST_INFO_LOAD (RHEL-88447)
- qemu_capabilities: Fetch caps for virtio-mem-ccw too (RHEL-87532)
- cpu_map: Add avx10* CPU features (RHEL-87796)
- cpu_map: Add GraniteRapids-v2 CPU model (RHEL-87796)
- cpu_map: Add sha512, sm3, and sm4 CPU features (RHEL-87796)
- virsh: Introduce new hypervisor-cpu-models command (RHEL-11435)
- qemu: remove nonsensical sanity check in processNetdevStreamDisconnectedEvent() (RHEL-80169)
- qemu: make processNetDevStreamDisconnectedEvent() reusable (RHEL-80169)
- qemu: respond to NETDEV_VHOST_USER_DISCONNECTED event (RHEL-80169)
- qemu: put vhost-user code that's special for passt in a helper function (RHEL-80169)
- qemu: make passt+vhostuser reconnect behave identically to passt+user (RHEL-80169)

Resolves: RHEL-11435, RHEL-80169, RHEL-87532, RHEL-87796, RHEL-88447
2025-05-22 12:11:58 +02:00

164 lines
4.8 KiB
Diff

From 8c10ceadcb2c32217b90277ee73f1eb990c67cbc Mon Sep 17 00:00:00 2001
Message-ID: <8c10ceadcb2c32217b90277ee73f1eb990c67cbc.1747908717.git.jdenemar@redhat.com>
From: Martin Kletzander <mkletzan@redhat.com>
Date: Tue, 25 Feb 2025 15:23:07 +0100
Subject: [PATCH] qemu_agent: Add qemuAgentGetLoadAvg()
With qemu guest agent 9.3 we are able to get the load averages with a
new command.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit 1669d91eade46b930ebb44e4b9d398ea8c2064e7)
https://issues.redhat.com/browse/RHEL-88447
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
src/qemu/qemu_agent.c | 46 +++++++++++++++++++++++++++++++++++++
src/qemu/qemu_agent.h | 6 +++++
tests/qemuagenttest.c | 53 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+)
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 43fca86f10..16a6eaa998 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -2568,3 +2568,49 @@ int qemuAgentGetDisks(qemuAgent *agent,
g_free(*disks);
return -1;
}
+
+
+int
+qemuAgentGetLoadAvg(qemuAgent *agent,
+ double *load1m,
+ double *load5m,
+ double *load15m,
+ bool report_unsupported)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ virJSONValue *data = NULL;
+ int rc;
+
+ if (!(cmd = qemuAgentMakeCommand("guest-get-load", NULL)))
+ return -1;
+
+ if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
+ report_unsupported)) < 0)
+ return rc;
+
+ if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("qemu agent didn't return an array of loads"));
+ return -1;
+ }
+
+#define GET_NUMBER_PARAM(param_) \
+ do { \
+ if (param_ && \
+ virJSONValueObjectGetNumberDouble(data, #param_, param_) < 0) { \
+ virReportError(VIR_ERR_INTERNAL_ERROR, \
+ _("parameter '%1$s' is missing in reply of guest-get-load"), \
+ #param_); \
+ return -1; \
+ } \
+ } while (0)
+
+ GET_NUMBER_PARAM(load1m);
+ GET_NUMBER_PARAM(load5m);
+ GET_NUMBER_PARAM(load15m);
+
+#undef GET_NUMBER_PARAM
+
+ return 0;
+}
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index f98586e8f8..cd17a98d39 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -195,3 +195,9 @@ int qemuAgentSSHRemoveAuthorizedKeys(qemuAgent *agent,
int qemuAgentGetDisks(qemuAgent *mon,
qemuAgentDiskInfo ***disks,
bool report_unsupported);
+
+int qemuAgentGetLoadAvg(qemuAgent *agent,
+ double *load1m,
+ double *load5m,
+ double *load15m,
+ bool report_unsupported);
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index 3287880241..566571cf11 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -1356,6 +1356,58 @@ testQemuAgentTimezone(const void *data)
virTypedParamsFree(params, nparams);
return ret;
}
+
+
+static const char testQemuAgentGetLoadAvgResponse[] =
+ "{"
+ " \"return\": {"
+ " \"load15m\": 0.03564453125,"
+ " \"load5m\": 0.064453125,"
+ " \"load1m\": 0.00390625"
+ " }"
+ "}";
+
+static int
+testQemuAgentGetLoadAvg(const void *data)
+{
+ virDomainXMLOption *xmlopt = (virDomainXMLOption *)data;
+ g_autoptr(qemuMonitorTest) test = qemuMonitorTestNewAgent(xmlopt);
+ double load1m = 0;
+ double load5m = 0;
+ double load15m = 0;
+
+ if (!test)
+ return -1;
+
+ if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+ return -1;
+
+ if (qemuMonitorTestAddItem(test, "guest-get-load",
+ testQemuAgentGetLoadAvgResponse) < 0)
+ return -1;
+
+ if (qemuAgentGetLoadAvg(qemuMonitorTestGetAgent(test),
+ &load1m, &load5m, &load15m, true) < 0)
+ return -1;
+
+#define VALIDATE_LOAD(value_, expected_) \
+ do { \
+ if (value_ != expected_) { \
+ virReportError(VIR_ERR_INTERNAL_ERROR, \
+ "Expected " #value_ " '%.11f', got '%.11f'", \
+ expected_, value_); \
+ return -1; \
+ } \
+ } while (0)
+
+ VALIDATE_LOAD(load1m, 0.00390625);
+ VALIDATE_LOAD(load5m, 0.064453125);
+ VALIDATE_LOAD(load15m, 0.03564453125);
+
+ return 0;
+}
+
+
static int
mymain(void)
{
@@ -1392,6 +1444,7 @@ mymain(void)
DO_TEST(Timezone);
DO_TEST(SSHKeys);
DO_TEST(GetDisks);
+ DO_TEST(GetLoadAvg);
DO_TEST(Timeout); /* Timeout should always be called last */
--
2.49.0