libbpf: add map_get_fd_by_id and map_delete_elem in light skeleton
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>
Wed, 24 Aug 2022 13:40:37 +0000 (15:40 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 26 Aug 2022 01:52:29 +0000 (18:52 -0700)
This allows to have a better control over maps from the kernel when
preloading eBPF programs.

Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20220824134055.1328882-8-benjamin.tissoires@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/skel_internal.h

index 00c5f94..1e82ab0 100644 (file)
@@ -251,6 +251,29 @@ static inline int skel_map_update_elem(int fd, const void *key,
        return skel_sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, attr_sz);
 }
 
+static inline int skel_map_delete_elem(int fd, const void *key)
+{
+       const size_t attr_sz = offsetofend(union bpf_attr, flags);
+       union bpf_attr attr;
+
+       memset(&attr, 0, attr_sz);
+       attr.map_fd = fd;
+       attr.key = (long)key;
+
+       return skel_sys_bpf(BPF_MAP_DELETE_ELEM, &attr, attr_sz);
+}
+
+static inline int skel_map_get_fd_by_id(__u32 id)
+{
+       const size_t attr_sz = offsetofend(union bpf_attr, flags);
+       union bpf_attr attr;
+
+       memset(&attr, 0, attr_sz);
+       attr.map_id = id;
+
+       return skel_sys_bpf(BPF_MAP_GET_FD_BY_ID, &attr, attr_sz);
+}
+
 static inline int skel_raw_tracepoint_open(const char *name, int prog_fd)
 {
        const size_t attr_sz = offsetofend(union bpf_attr, raw_tracepoint.prog_fd);