WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / bpf_iter_test_kern4.c
blobee49493dc1251666a1a5462162a4bb5685fd328a
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include "bpf_iter.h"
4 #include <bpf/bpf_helpers.h>
6 char _license[] SEC("license") = "GPL";
8 __u32 map1_id = 0, map2_id = 0;
9 __u32 map1_accessed = 0, map2_accessed = 0;
10 __u64 map1_seqnum = 0, map2_seqnum1 = 0, map2_seqnum2 = 0;
12 static volatile const __u32 print_len;
13 static volatile const __u32 ret1;
15 SEC("iter/bpf_map")
16 int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
18 struct seq_file *seq = ctx->meta->seq;
19 struct bpf_map *map = ctx->map;
20 __u64 seq_num;
21 int i, ret = 0;
23 if (map == (void *)0)
24 return 0;
26 /* only dump map1_id and map2_id */
27 if (map->id != map1_id && map->id != map2_id)
28 return 0;
30 seq_num = ctx->meta->seq_num;
31 if (map->id == map1_id) {
32 map1_seqnum = seq_num;
33 map1_accessed++;
36 if (map->id == map2_id) {
37 if (map2_accessed == 0) {
38 map2_seqnum1 = seq_num;
39 if (ret1)
40 ret = 1;
41 } else {
42 map2_seqnum2 = seq_num;
44 map2_accessed++;
47 /* fill seq_file buffer */
48 for (i = 0; i < print_len; i++)
49 bpf_seq_write(seq, &seq_num, sizeof(seq_num));
51 return ret;