bpf: introduce cgroup storage maps
This commit introduces BPF_MAP_TYPE_CGROUP_STORAGE maps: a special type of maps which are implementing the cgroup storage. >From the userspace point of view it's almost a generic hash map with the (cgroup inode id, attachment type) pair used as a key. The only difference is that some operations are restricted: 1) a user can't create new entries, 2) a user can't remove existing entries. The lookup from userspace is o(log(n)). Signed-off-by: Roman Gushchin <guro@fb.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
committed by
Daniel Borkmann
parent
0a4c58f570
commit
de9cbbaadb
@ -5154,6 +5154,14 @@ static int replace_map_fd_with_map_ptr(struct bpf_verifier_env *env)
|
||||
}
|
||||
env->used_maps[env->used_map_cnt++] = map;
|
||||
|
||||
if (map->map_type == BPF_MAP_TYPE_CGROUP_STORAGE &&
|
||||
bpf_cgroup_storage_assign(env->prog, map)) {
|
||||
verbose(env,
|
||||
"only one cgroup storage is allowed\n");
|
||||
fdput(f);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
fdput(f);
|
||||
next_insn:
|
||||
insn++;
|
||||
@ -5180,6 +5188,10 @@ static void release_maps(struct bpf_verifier_env *env)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (env->prog->aux->cgroup_storage)
|
||||
bpf_cgroup_storage_release(env->prog,
|
||||
env->prog->aux->cgroup_storage);
|
||||
|
||||
for (i = 0; i < env->used_map_cnt; i++)
|
||||
bpf_map_put(env->used_maps[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user