Skip to content

Commit 2e2a0c9

Browse files
author
Alexei Starovoitov
committed
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: Alexei Starovoitov <[email protected]>
2 parents f6f3bac + ad3338d commit 2e2a0c9

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

kernel/bpf/arraymap.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,29 @@ static void bpf_fd_array_map_clear(struct bpf_map *map)
553553
fd_array_map_delete_elem(map, &i);
554554
}
555555

556+
static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key,
557+
struct seq_file *m)
558+
{
559+
void **elem, *ptr;
560+
u32 prog_id;
561+
562+
rcu_read_lock();
563+
564+
elem = array_map_lookup_elem(map, key);
565+
if (elem) {
566+
ptr = READ_ONCE(*elem);
567+
if (ptr) {
568+
seq_printf(m, "%u: ", *(u32 *)key);
569+
prog_id = prog_fd_array_sys_lookup_elem(ptr);
570+
btf_type_seq_show(map->btf, map->btf_value_type_id,
571+
&prog_id, m);
572+
seq_puts(m, "\n");
573+
}
574+
}
575+
576+
rcu_read_unlock();
577+
}
578+
556579
const struct bpf_map_ops prog_array_map_ops = {
557580
.map_alloc_check = fd_array_map_alloc_check,
558581
.map_alloc = array_map_alloc,
@@ -564,7 +587,7 @@ const struct bpf_map_ops prog_array_map_ops = {
564587
.map_fd_put_ptr = prog_fd_array_put_ptr,
565588
.map_fd_sys_lookup_elem = prog_fd_array_sys_lookup_elem,
566589
.map_release_uref = bpf_fd_array_map_clear,
567-
.map_check_btf = map_check_no_btf,
590+
.map_seq_show_elem = prog_array_map_seq_show_elem,
568591
};
569592

570593
static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,

tools/bpf/bpftool/map.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,6 @@ static int do_dump(int argc, char **argv)
673673
if (fd < 0)
674674
return -1;
675675

676-
if (map_is_map_of_maps(info.type) || map_is_map_of_progs(info.type)) {
677-
p_err("Dumping maps of maps and program maps not supported");
678-
close(fd);
679-
return -1;
680-
}
681-
682676
key = malloc(info.key_size);
683677
value = alloc_value(&info);
684678
if (!key || !value) {
@@ -732,7 +726,9 @@ static int do_dump(int argc, char **argv)
732726
} else {
733727
print_entry_plain(&info, key, value);
734728
}
735-
} else {
729+
num_elems++;
730+
} else if (!map_is_map_of_maps(info.type) &&
731+
!map_is_map_of_progs(info.type)) {
736732
if (json_output) {
737733
jsonw_name(json_wtr, "key");
738734
print_hex_data_json(key, info.key_size);
@@ -749,7 +745,6 @@ static int do_dump(int argc, char **argv)
749745
}
750746

751747
prev_key = key;
752-
num_elems++;
753748
}
754749

755750
if (json_output)

0 commit comments

Comments
 (0)