Libbpf userspace function bpf_map__update_elem
Allows to insert or update value in BPF map that corresponds to provided key.
Definition
int bpf_map__update_elem(const struct bpf_map *map, const void *key, size_t key_sz, const void *value, size_t value_sz, __u64 flags);
Parameters
map
: BPF map to insert to or update element inkey
: pointer to memory containing bytes of the keykey_sz
: size in bytes of key data, needs to match BPF map definition'skey_size
value
: pointer to memory containing bytes of the valuevalue_sz
: size in byte of value data memory; it has to match BPF map definition'svalue_size
. For per-CPU BPF maps value size has to be a product of BPF map value size and number of possible CPUs in the system (could be fetched withlibbpf_num_possible_cpus
). Note also that for per-CPU values value size has to be aligned up to closest 8 bytes for alignment reasons, so expected size is:round_up(value_size, 8) * libbpf_num_possible_cpus()
.flags
: flags passed to kernel for this operation
Return
0
, on success; negative error, otherwise
Usage
bpf_map__update_elem()
is high-level equivalent of bpf_map_update_elem()
API with added check for key and value size.
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome