Added code for monitor and monitor_json.
The "request-ebpf" return's eBPF binary object encoded in base64.
The function qemuMonitorGetEbpf() returns a decoded blob.
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(a)daynix.com>
---
src/qemu/qemu_monitor.c | 23 +++++++++++++++++++++++
src/qemu/qemu_monitor.h | 3 +++
src/qemu/qemu_monitor_json.c | 21 +++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 3 +++
4 files changed, 50 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 320729f067..07596c78ee 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4512,3 +4512,26 @@ qemuMonitorGetStatsByQOMPath(virJSONValue *arr,
return NULL;
}
+
+void *
+qemuMonitorGetEbpf(qemuMonitor *mon, const char *ebpfName, size_t *size)
+{
+ QEMU_CHECK_MONITOR_NULL(mon);
+ g_autoptr(virJSONValue) reply = NULL;
+ const char *ebpfBase64 = NULL;
+ void *ebpfObject = NULL;
+
+ if (ebpfName == NULL || size == NULL)
+ return NULL;
+
+ reply = qemuMonitorJSONGetEbpf(mon, ebpfName);
+
+ if (reply == NULL)
+ return NULL;
+
+ ebpfBase64 = virJSONValueObjectGetString(reply, "object");
+
+ ebpfObject = g_base64_decode(ebpfBase64, size);
+
+ return ebpfObject;
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 6c590933aa..15f32f105c 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1579,3 +1579,6 @@ qemuMonitorExtractQueryStats(virJSONValue *info);
virJSONValue *
qemuMonitorGetStatsByQOMPath(virJSONValue *arr,
char *qom_path);
+
+void *
+qemuMonitorGetEbpf(qemuMonitor *mon, const char *ebpfName, size_t *size);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8152eea9a0..a7d0865ddc 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8851,3 +8851,24 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
return virJSONValueObjectStealArray(reply, "return");
}
+
+
+virJSONValue *
+qemuMonitorJSONGetEbpf(qemuMonitor *mon, const char *ebpfName)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("request-ebpf",
+ "s:id", ebpfName, NULL)))
+ return NULL;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return NULL;
+
+ /* return empty hash */
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
+ return NULL;
+
+ return virJSONValueObjectStealObject(reply, "return");
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 06023b98ea..6a2fc963ba 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -825,3 +825,6 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
qemuMonitorQueryStatsTargetType target,
char **vcpus,
GPtrArray *providers);
+
+virJSONValue *
+qemuMonitorJSONGetEbpf(qemuMonitor *mon, const char *ebpfName);
--
2.42.0