[RFC PATCH v4 1/5] qemu_monitor: Added QEMU's "request-ebpf" support.

Andrew Melnychenko posted 5 patches 3 months ago
[RFC PATCH v4 1/5] qemu_monitor: Added QEMU's "request-ebpf" support.
Posted by Andrew Melnychenko 3 months ago
Added code for monitor and monitor_json.
The "request-ebpf" return's eBPF binary object encoded in base64.

QEMU provides eBPF that can be loaded and passed to it from Libvirt.
QEMU requires exact eBPF program/maps, so it can be retrieved using
QAPI.
To load eBPF program - administrative capabilities are required,
so Libvirt may load it and pass it to the QEMU instance.
For now, there is only "RSS"(Receive Side Scaling) for virtio-net eBPF
program and maps.

Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 src/qemu/qemu_monitor.c      |  9 +++++++++
 src/qemu/qemu_monitor.h      |  4 ++++
 src/qemu/qemu_monitor_json.c | 27 +++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  4 ++++
 4 files changed, 44 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index b1c0c6a064..82729279ff 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4508,3 +4508,12 @@ qemuMonitorDisplayReload(qemuMonitor *mon,
 
     return qemuMonitorJSONDisplayReload(mon, type, tlsCerts);
 }
+
+const char *
+qemuMonitorGetEbpf(qemuMonitor *mon,
+                   const char *ebpfName)
+{
+    QEMU_CHECK_MONITOR_NULL(mon);
+
+    return qemuMonitorJSONGetEbpf(mon, ebpfName);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 76c859a888..720e9efbb8 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1617,3 +1617,7 @@ int
 qemuMonitorDisplayReload(qemuMonitor *mon,
                          const char *type,
                          bool tlsCerts);
+
+const char *
+qemuMonitorGetEbpf(qemuMonitor *mon,
+                   const char *ebpfName);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8a20ce57e6..92bc7bd062 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8955,3 +8955,30 @@ int qemuMonitorJSONDisplayReload(qemuMonitor *mon,
 
     return 0;
 }
+
+const char *
+qemuMonitorJSONGetEbpf(qemuMonitor *mon,
+                       const char *ebpfName)
+{
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
+    virJSONValue *ret = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("request-ebpf", "s:id", ebpfName, NULL)))
+        return NULL;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        return NULL;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        return NULL;
+
+    ret = virJSONValueObjectGet(reply, "return");
+    if (!ret) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("request-ebpf reply was missing 'return' data"));
+        return NULL;
+    }
+
+    return g_strdup(virJSONValueObjectGetString(ret, "object"));
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 921dd34ed2..161f6b909f 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -825,3 +825,7 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
 int qemuMonitorJSONDisplayReload(qemuMonitor *mon,
                                  const char *type,
                                  bool tlsCerts);
+
+const char *
+qemuMonitorJSONGetEbpf(qemuMonitor *mon,
+                       const char *ebpfName);
-- 
2.45.2