tools/bpf: sync uapi/bpf.h
Subsystems (4)
Alexei Starovoitov
maintainerPATCH v5 7/9 tools/bpf: sync uapi/bpf.h
add BPF_F_LOCK definition to tools/include/uapi/linux/bpf.h
Signed-off-by Alexei Starovoitov <[email protected]>
--- tools/include/uapi/linux/bpf.h | 1 + 1 file changed, 1 insertion(+)
tools/include/uapi/linux/bpf.h +1 -0
@@ -267,6 +267,7 @@ enum bpf_attach_type {#define BPF_ANY 0/* create new element or update existing */ #define BPF_NOEXIST 1/* create new element if it didn't exist */ #define BPF_EXIST 2/* update existing element */ +#define BPF_F_LOCK 4/* spin_lock-ed map_lookup/map_update */ /* flags for BPF_MAP_CREATE command */ #define BPF_F_NO_PREALLOC (1U << 0)
Signature · 1 line
2.20.0
Alexei Starovoitov
maintainerPATCH v5 8/9 libbpf: introduce bpf_map_lookup_elem_flags()
Introduce
int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, __u64 flags) helper to lookup array/hash/cgroup_local_storage elements with BPF_F_LOCK flag.
Signed-off-by Alexei Starovoitov <[email protected]>
--- tools/lib/bpf/bpf.c | 13 +++++++++++++ tools/lib/bpf/bpf.h | 2 ++ tools/lib/bpf/libbpf.map | 1 + 3 files changed, 16 insertions(+)
tools/lib/bpf/bpf.c +13 -0
@@ -357,6 +357,19 @@ int bpf_map_lookup_elem(int fd, const void *key, void *value)return sys_bpf (BPF_MAP_LOOKUP_ELEM , &attr,sizeof (attr)); } +int bpf_map_lookup_elem_flags (int fd,const void *key,void *value,__u64 flags) +{ +union bpf_attr attr; + +bzero (&attr,sizeof (attr)); + attr.map_fd = fd; + attr.key =ptr_to_u64 (key); + attr.value =ptr_to_u64 (value); + attr.flags = flags; + +return sys_bpf (BPF_MAP_LOOKUP_ELEM , &attr,sizeof (attr)); +} +int bpf_map_lookup_and_delete_elem (int fd,const void *key,void *value) {union bpf_attr attr;
tools/lib/bpf/bpf.h +2 -0
@@ -110,6 +110,8 @@ LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value, __u64 flags); LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value); +LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, +__u64 flags); LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,void *value); LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
tools/lib/bpf/libbpf.map +1 -0
@@ -130,4 +130,5 @@ LIBBPF_0.0.2 { bpf_probe_helper; bpf_probe_map_type; bpf_probe_prog_type; + bpf_map_lookup_elem_flags; } LIBBPF_0.0.1;
Signature · 1 line
2.20.0