提交 61d1b6a4 编写于 作者: D Daniel Borkmann 提交者: David S. Miller

bpf, maps: add release callback

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: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 b478af0c
...@@ -19,7 +19,8 @@ struct bpf_map; ...@@ -19,7 +19,8 @@ struct bpf_map;
struct bpf_map_ops { struct bpf_map_ops {
/* funcs callable from userspace (via syscall) */ /* funcs callable from userspace (via syscall) */
struct bpf_map *(*map_alloc)(union bpf_attr *attr); 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); int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
/* funcs callable from userspace and from eBPF programs */ /* funcs callable from userspace and from eBPF programs */
......
...@@ -124,7 +124,12 @@ void bpf_map_put_with_uref(struct bpf_map *map) ...@@ -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) 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; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册