bpf tools: Add helper function for updating bpf maps elements
Add bpf_map_update_elem() helper function which calls the sys_bpf syscall to update elements in bpf maps. Upcoming patches will use it to adjust data in map through the perf command line. Signed-off-by: He Kuang <hekuang@huawei.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1448372181-151723-4-git-send-email-wangnan0@huawei.com Signed-off-by: Wang Nan <wangnan0@huawei.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
dcdd184b60
commit
43798bf372
@ -83,3 +83,17 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
|
|||||||
log_buf[0] = 0;
|
log_buf[0] = 0;
|
||||||
return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bpf_map_update_elem(int fd, 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_UPDATE_ELEM, &attr, sizeof(attr));
|
||||||
|
}
|
||||||
|
@ -20,4 +20,6 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
|
|||||||
u32 kern_version, char *log_buf,
|
u32 kern_version, char *log_buf,
|
||||||
size_t log_buf_sz);
|
size_t log_buf_sz);
|
||||||
|
|
||||||
|
int bpf_map_update_elem(int fd, void *key, void *value,
|
||||||
|
u64 flags);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user