Commit ccc3f569 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

selftests/bpf: convert remaining legacy map definitions



Converted few remaining legacy BPF map definition to BTF-defined ones.
For the remaining two bpf_map_def-based legacy definitions that we want
to keep for testing purposes until libbpf 1.0 release, guard them in
pragma to suppres deprecation warnings which will be added in libbpf in
the next commit.

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220120060529.1890907-3-andrii@kernel.org


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 32b34294
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -7,12 +7,12 @@
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>

struct bpf_map_def SEC("maps") sock_map = {
	.type = BPF_MAP_TYPE_SOCKMAP,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 2,
};
struct {
	__uint(type, BPF_MAP_TYPE_SOCKMAP);
	__type(key, int);
	__type(value, int);
	__uint(max_entries, 2);
} sock_map SEC(".maps");

SEC("freplace/cls_redirect")
int freplace_cls_redirect_test(struct __sk_buff *skb)
+12 −12
Original line number Diff line number Diff line
@@ -2,19 +2,19 @@
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

struct bpf_map_def SEC("maps") htab = {
	.type = BPF_MAP_TYPE_HASH,
	.key_size = sizeof(__u32),
	.value_size = sizeof(long),
	.max_entries = 2,
};
struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__type(key, __u32);
	__type(value, long);
	__uint(max_entries, 2);
} htab SEC(".maps");

struct bpf_map_def SEC("maps") array = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(long),
	.max_entries = 2,
};
struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__type(key, __u32);
	__type(value, long);
	__uint(max_entries, 2);
} array SEC(".maps");

/* Sample program which should always load for testing control paths. */
SEC(".text") int func()
+3 −0
Original line number Diff line number Diff line
@@ -9,12 +9,15 @@ struct ipv_counts {
	unsigned int v6;
};

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
struct bpf_map_def SEC("maps") btf_map = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(struct ipv_counts),
	.max_entries = 4,
};
#pragma GCC diagnostic pop

BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);

+3 −0
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ struct ipv_counts {
	unsigned int v6;
};

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/* just to validate we can handle maps in multiple sections */
struct bpf_map_def SEC("maps") btf_map_legacy = {
	.type = BPF_MAP_TYPE_ARRAY,
@@ -16,6 +18,7 @@ struct bpf_map_def SEC("maps") btf_map_legacy = {
	.value_size = sizeof(long long),
	.max_entries = 4,
};
#pragma GCC diagnostic pop

BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);

+6 −6
Original line number Diff line number Diff line
@@ -8,12 +8,12 @@ struct ipv_counts {
	unsigned int v6;
};

struct bpf_map_def SEC("maps") btf_map = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(struct ipv_counts),
	.max_entries = 4,
};
struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(struct ipv_counts));
	__uint(max_entries, 4);
} btf_map SEC(".maps");

__attribute__((noinline))
int test_long_fname_2(void)
Loading