[DTrace-devel] [PATCH] add dt_bpf_map_update()

Eugene Loh eugene.loh at oracle.com
Wed Mar 4 07:49:13 PST 2020


Add a convenience wrapper for updating elements in BPF maps.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_bpf.c | 16 ++++++++++++++++
 libdtrace/dt_bpf.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index ae742148..f72a5df9 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -138,6 +138,22 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp, uint_t probec)
 	/* FIXME: Need to put in the actual struct ref for probe info. */
 }
 
+/*
+ * Store the (key, value) pair in the map referenced by the given fd.
+ */
+int dt_bpf_map_update(int fd, const void *key, const void *val)
+{
+	union bpf_attr attr;
+
+	memset(&attr, 0, sizeof(attr));
+	attr.map_fd = fd;
+	attr.key = (uint64_t)(unsigned long)key;
+	attr.value = (uint64_t)(unsigned long)val;
+	attr.flags = 0;
+
+	return bpf(BPF_MAP_UPDATE_ELEM, &attr);
+}
+
 /*
  * Perform relocation processing on a program.
  */
diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
index cf852409..c258318f 100644
--- a/libdtrace/dt_bpf.h
+++ b/libdtrace/dt_bpf.h
@@ -15,6 +15,7 @@ extern "C" {
 #endif
 
 extern int dt_bpf_gmap_create(dtrace_hdl_t *, uint_t);
+extern int dt_bpf_map_update(int fd, const void *key, const void *val);
 extern int dt_bpf_prog(dtrace_hdl_t *, dtrace_prog_t *);
 
 #ifdef	__cplusplus
-- 
2.25.0




More information about the DTrace-devel mailing list