1acf61631SYonghong Song // SPDX-License-Identifier: GPL-2.0
2acf61631SYonghong Song /* Copyright (c) 2020 Facebook */
384544f56SYonghong Song #include "bpf_iter.h"
4acf61631SYonghong Song #include <bpf/bpf_helpers.h>
5acf61631SYonghong Song 
6acf61631SYonghong Song char _license[] SEC("license") = "GPL";
7acf61631SYonghong Song 
8acf61631SYonghong Song SEC("iter/bpf_map")
dump_bpf_map(struct bpf_iter__bpf_map * ctx)9acf61631SYonghong Song int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
10acf61631SYonghong Song {
11acf61631SYonghong Song 	struct seq_file *seq = ctx->meta->seq;
12acf61631SYonghong Song 	__u64 seq_num = ctx->meta->seq_num;
13acf61631SYonghong Song 	struct bpf_map *map = ctx->map;
14acf61631SYonghong Song 
15acf61631SYonghong Song 	if (map == (void *)0) {
16acf61631SYonghong Song 		BPF_SEQ_PRINTF(seq, "      %%%%%% END %%%%%%\n");
17acf61631SYonghong Song 		return 0;
18acf61631SYonghong Song 	}
19acf61631SYonghong Song 
20acf61631SYonghong Song 	if (seq_num == 0)
21acf61631SYonghong Song 		BPF_SEQ_PRINTF(seq, "      id   refcnt  usercnt  locked_vm\n");
22acf61631SYonghong Song 
23acf61631SYonghong Song 	BPF_SEQ_PRINTF(seq, "%8u %8ld %8ld %10lu\n", map->id, map->refcnt.counter,
24acf61631SYonghong Song 		       map->usercnt.counter,
25*80ee81e0SRoman Gushchin 		       0LLU);
26acf61631SYonghong Song 	return 0;
27acf61631SYonghong Song }
28