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

Andrew Melnychenko posted 6 patches 6 months, 2 weeks ago
There is a newer version of this series
[RFC PATCH v3 1/6] qemu_monitor: Added QEMU's "request-ebpf" support.
Posted by Andrew Melnychenko 6 months, 2 weeks 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      | 13 +++++++++++++
 src/qemu/qemu_monitor.h      |  3 +++
 src/qemu/qemu_monitor_json.c | 26 ++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  3 +++
 4 files changed, 45 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 34e2ccab97..1dc2fa3fac 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4511,3 +4511,16 @@ qemuMonitorDisplayReload(qemuMonitor *mon,
 
     return qemuMonitorJSONDisplayReload(mon, type, tlsCerts);
 }
+
+const char *
+qemuMonitorGetEbpf(qemuMonitor *mon, const char *ebpfName)
+{
+    QEMU_CHECK_MONITOR_NULL(mon);
+
+    if (ebpfName == NULL) {
+        virReportInvalidNonNullArg(ebpfName);
+        return NULL;
+    }
+
+    return qemuMonitorJSONGetEbpf(mon, ebpfName);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 6e81945201..fe8853a2c4 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1586,3 +1586,6 @@ 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 eb84a3d938..585a645e66 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8896,3 +8896,29 @@ 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 9684660d86..4a6fc9324e 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -829,3 +829,6 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
 int qemuMonitorJSONDisplayReload(qemuMonitor *mon,
                                  const char *type,
                                  bool tlsCerts);
+
+const char *
+qemuMonitorJSONGetEbpf(qemuMonitor *mon, const char *ebpfName);
-- 
2.44.0
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [RFC PATCH v3 1/6] qemu_monitor: Added QEMU's "request-ebpf" support.
Posted by Michal Prívozník 6 months, 1 week ago
On 5/12/24 21:45, Andrew Melnychenko wrote:
> 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      | 13 +++++++++++++
>  src/qemu/qemu_monitor.h      |  3 +++
>  src/qemu/qemu_monitor_json.c | 26 ++++++++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h |  3 +++
>  4 files changed, 45 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 34e2ccab97..1dc2fa3fac 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -4511,3 +4511,16 @@ qemuMonitorDisplayReload(qemuMonitor *mon,
>  
>      return qemuMonitorJSONDisplayReload(mon, type, tlsCerts);
>  }
> +
> +const char *
> +qemuMonitorGetEbpf(qemuMonitor *mon, const char *ebpfName)

I'm going to mentioned it here, because this is the first occurrence and
then I'll stop pointing it out: libvirt's coding style is a bit
different. I think the pre-exiting code around may give you couple of
examples. Anyway, this is a nitpick.

> +{
> +    QEMU_CHECK_MONITOR_NULL(mon);
> +
> +    if (ebpfName == NULL) {
> +        virReportInvalidNonNullArg(ebpfName);
> +        return NULL;
> +    }

We don't usually do this kind of check here. Usually there's just one
(or very few) callers of these functions and they can verify arguments
passed).

> +
> +    return qemuMonitorJSONGetEbpf(mon, ebpfName);
> +}

Michal