Commit 2e2a0c96 authored by Alexei Starovoitov's avatar Alexei Starovoitov

Merge branch 'progarray_mapinmap_dump'

Yonghong Song says:

====================
The support to dump program array and map_in_map maps
for bpffs and bpftool is added. Patch #1 added bpffs support
and Patch #2 added bpftool support. Please see
individual patches for example output.
====================
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents f6f3bac0 ad3338d2
...@@ -553,6 +553,29 @@ static void bpf_fd_array_map_clear(struct bpf_map *map) ...@@ -553,6 +553,29 @@ static void bpf_fd_array_map_clear(struct bpf_map *map)
fd_array_map_delete_elem(map, &i); fd_array_map_delete_elem(map, &i);
} }
static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key,
struct seq_file *m)
{
void **elem, *ptr;
u32 prog_id;
rcu_read_lock();
elem = array_map_lookup_elem(map, key);
if (elem) {
ptr = READ_ONCE(*elem);
if (ptr) {
seq_printf(m, "%u: ", *(u32 *)key);
prog_id = prog_fd_array_sys_lookup_elem(ptr);
btf_type_seq_show(map->btf, map->btf_value_type_id,
&prog_id, m);
seq_puts(m, "\n");
}
}
rcu_read_unlock();
}
const struct bpf_map_ops prog_array_map_ops = { const struct bpf_map_ops prog_array_map_ops = {
.map_alloc_check = fd_array_map_alloc_check, .map_alloc_check = fd_array_map_alloc_check,
.map_alloc = array_map_alloc, .map_alloc = array_map_alloc,
...@@ -564,7 +587,7 @@ const struct bpf_map_ops prog_array_map_ops = { ...@@ -564,7 +587,7 @@ const struct bpf_map_ops prog_array_map_ops = {
.map_fd_put_ptr = prog_fd_array_put_ptr, .map_fd_put_ptr = prog_fd_array_put_ptr,
.map_fd_sys_lookup_elem = prog_fd_array_sys_lookup_elem, .map_fd_sys_lookup_elem = prog_fd_array_sys_lookup_elem,
.map_release_uref = bpf_fd_array_map_clear, .map_release_uref = bpf_fd_array_map_clear,
.map_check_btf = map_check_no_btf, .map_seq_show_elem = prog_array_map_seq_show_elem,
}; };
static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file, static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,
......
...@@ -673,12 +673,6 @@ static int do_dump(int argc, char **argv) ...@@ -673,12 +673,6 @@ static int do_dump(int argc, char **argv)
if (fd < 0) if (fd < 0)
return -1; return -1;
if (map_is_map_of_maps(info.type) || map_is_map_of_progs(info.type)) {
p_err("Dumping maps of maps and program maps not supported");
close(fd);
return -1;
}
key = malloc(info.key_size); key = malloc(info.key_size);
value = alloc_value(&info); value = alloc_value(&info);
if (!key || !value) { if (!key || !value) {
...@@ -732,7 +726,9 @@ static int do_dump(int argc, char **argv) ...@@ -732,7 +726,9 @@ static int do_dump(int argc, char **argv)
} else { } else {
print_entry_plain(&info, key, value); print_entry_plain(&info, key, value);
} }
} else { num_elems++;
} else if (!map_is_map_of_maps(info.type) &&
!map_is_map_of_progs(info.type)) {
if (json_output) { if (json_output) {
jsonw_name(json_wtr, "key"); jsonw_name(json_wtr, "key");
print_hex_data_json(key, info.key_size); print_hex_data_json(key, info.key_size);
...@@ -749,7 +745,6 @@ static int do_dump(int argc, char **argv) ...@@ -749,7 +745,6 @@ static int do_dump(int argc, char **argv)
} }
prev_key = key; prev_key = key;
num_elems++;
} }
if (json_output) if (json_output)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment