Skip to main content

bpf_map_lookup_and_delete_elem

Function bpf_map_lookup_and_delete_elem 

Source
pub fn bpf_map_lookup_and_delete_elem<F: KernelAuxiliaryOps>(
    arg: BpfMapUpdateArg,
) -> BpfResult<()>
Expand description

Look up an element with the given key in the map referred to by the file descriptor fd, and if found, delete the element.

For BPF_MAP_TYPE_QUEUE and BPF_MAP_TYPE_STACK map types, the flags argument needs to be set to 0, but for other map types, it may be specified as:

  • BPF_F_LOCK : If this flag is set, the command will acquire the spin-lock of the map value we are looking up.

If the map contains no spin-lock in its value, -EINVAL will be returned by the command.

The BPF_MAP_TYPE_QUEUE and BPF_MAP_TYPE_STACK map types implement this command as a “pop” operation, deleting the top element rather than one corresponding to key. The key and key_len parameters should be zeroed when issuing this operation for these map types.

This command is only valid for the following map types:

  • BPF_MAP_TYPE_QUEUE
  • BPF_MAP_TYPE_STACK
  • BPF_MAP_TYPE_HASH
  • BPF_MAP_TYPE_PERCPU_HASH
  • BPF_MAP_TYPE_LRU_HASH
  • BPF_MAP_TYPE_LRU_PERCPU_HASH

See https://ebpf-docs.dylanreimerink.nl/linux/syscall/BPF_MAP_LOOKUP_AND_DELETE_ELEM/