Skip to content

Commit

Permalink
bpf, maps: add release callback
Browse files Browse the repository at this point in the history
Add a release callback for maps that is invoked when the last
reference to its struct file is gone and the struct file about
to be released by vfs. The handler will be used by fd array maps.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Daniel Borkmann authored and David S. Miller committed Jun 16, 2016
1 parent b478af0 commit 61d1b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ struct bpf_map;
struct bpf_map_ops {
/* funcs callable from userspace (via syscall) */
struct bpf_map *(*map_alloc)(union bpf_attr *attr);
void (*map_free)(struct bpf_map *);
void (*map_release)(struct bpf_map *map, struct file *map_file);
void (*map_free)(struct bpf_map *map);
int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);

/* funcs callable from userspace and from eBPF programs */
Expand Down
7 changes: 6 additions & 1 deletion kernel/bpf/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ void bpf_map_put_with_uref(struct bpf_map *map)

static int bpf_map_release(struct inode *inode, struct file *filp)
{
bpf_map_put_with_uref(filp->private_data);
struct bpf_map *map = filp->private_data;

if (map->ops->map_release)
map->ops->map_release(map, filp);

bpf_map_put_with_uref(map);
return 0;
}

Expand Down

0 comments on commit 61d1b6a

Please sign in to comment.