Commit 2fe256a4 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann

selftests/bpf: Migrate selftests to bpf_map_create()

Conversion is straightforward for most cases. In few cases tests are
using mutable map_flags and attribute structs, but bpf_map_create_opts
can be used in the similar fashion, so there were no problems. Just lots
of repetitive conversions.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211124193233.3115996-5-andrii@kernel.org
parent 99a12a32
...@@ -68,13 +68,6 @@ static void map_batch_verify(int *visited, __u32 max_entries, int *keys, ...@@ -68,13 +68,6 @@ static void map_batch_verify(int *visited, __u32 max_entries, int *keys,
static void __test_map_lookup_and_update_batch(bool is_pcpu) static void __test_map_lookup_and_update_batch(bool is_pcpu)
{ {
struct bpf_create_map_attr xattr = {
.name = "array_map",
.map_type = is_pcpu ? BPF_MAP_TYPE_PERCPU_ARRAY :
BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(__s64),
};
int map_fd, *keys, *visited; int map_fd, *keys, *visited;
__u32 count, total, total_success; __u32 count, total, total_success;
const __u32 max_entries = 10; const __u32 max_entries = 10;
...@@ -86,10 +79,10 @@ static void __test_map_lookup_and_update_batch(bool is_pcpu) ...@@ -86,10 +79,10 @@ static void __test_map_lookup_and_update_batch(bool is_pcpu)
.flags = 0, .flags = 0,
); );
xattr.max_entries = max_entries; map_fd = bpf_map_create(is_pcpu ? BPF_MAP_TYPE_PERCPU_ARRAY : BPF_MAP_TYPE_ARRAY,
map_fd = bpf_create_map_xattr(&xattr); "array_map", sizeof(int), sizeof(__s64), max_entries, NULL);
CHECK(map_fd == -1, CHECK(map_fd == -1,
"bpf_create_map_xattr()", "error:%s\n", strerror(errno)); "bpf_map_create()", "error:%s\n", strerror(errno));
value_size = sizeof(__s64); value_size = sizeof(__s64);
if (is_pcpu) if (is_pcpu)
......
...@@ -83,22 +83,15 @@ void __test_map_lookup_and_delete_batch(bool is_pcpu) ...@@ -83,22 +83,15 @@ void __test_map_lookup_and_delete_batch(bool is_pcpu)
int err, step, value_size; int err, step, value_size;
bool nospace_err; bool nospace_err;
void *values; void *values;
struct bpf_create_map_attr xattr = {
.name = "hash_map",
.map_type = is_pcpu ? BPF_MAP_TYPE_PERCPU_HASH :
BPF_MAP_TYPE_HASH,
.key_size = sizeof(int),
.value_size = sizeof(int),
};
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts,
.elem_flags = 0, .elem_flags = 0,
.flags = 0, .flags = 0,
); );
xattr.max_entries = max_entries; map_fd = bpf_map_create(is_pcpu ? BPF_MAP_TYPE_PERCPU_HASH : BPF_MAP_TYPE_HASH,
map_fd = bpf_create_map_xattr(&xattr); "hash_map", sizeof(int), sizeof(int), max_entries, NULL);
CHECK(map_fd == -1, CHECK(map_fd == -1,
"bpf_create_map_xattr()", "error:%s\n", strerror(errno)); "bpf_map_create()", "error:%s\n", strerror(errno));
value_size = is_pcpu ? sizeof(value) : sizeof(int); value_size = is_pcpu ? sizeof(value) : sizeof(int);
keys = malloc(max_entries * sizeof(int)); keys = malloc(max_entries * sizeof(int));
......
...@@ -64,13 +64,7 @@ static void map_batch_verify(int *visited, __u32 max_entries, ...@@ -64,13 +64,7 @@ static void map_batch_verify(int *visited, __u32 max_entries,
void test_lpm_trie_map_batch_ops(void) void test_lpm_trie_map_batch_ops(void)
{ {
struct bpf_create_map_attr xattr = { LIBBPF_OPTS(bpf_map_create_opts, create_opts, .map_flags = BPF_F_NO_PREALLOC);
.name = "lpm_trie_map",
.map_type = BPF_MAP_TYPE_LPM_TRIE,
.key_size = sizeof(struct test_lpm_key),
.value_size = sizeof(int),
.map_flags = BPF_F_NO_PREALLOC,
};
struct test_lpm_key *keys, key; struct test_lpm_key *keys, key;
int map_fd, *values, *visited; int map_fd, *values, *visited;
__u32 step, count, total, total_success; __u32 step, count, total, total_success;
...@@ -82,9 +76,10 @@ void test_lpm_trie_map_batch_ops(void) ...@@ -82,9 +76,10 @@ void test_lpm_trie_map_batch_ops(void)
.flags = 0, .flags = 0,
); );
xattr.max_entries = max_entries; map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, "lpm_trie_map",
map_fd = bpf_create_map_xattr(&xattr); sizeof(struct test_lpm_key), sizeof(int),
CHECK(map_fd == -1, "bpf_create_map_xattr()", "error:%s\n", max_entries, &create_opts);
CHECK(map_fd == -1, "bpf_map_create()", "error:%s\n",
strerror(errno)); strerror(errno));
keys = malloc(max_entries * sizeof(struct test_lpm_key)); keys = malloc(max_entries * sizeof(struct test_lpm_key));
......
...@@ -19,16 +19,12 @@ ...@@ -19,16 +19,12 @@
#include <test_btf.h> #include <test_btf.h>
#include <test_maps.h> #include <test_maps.h>
static struct bpf_create_map_attr xattr = { static struct bpf_map_create_opts map_opts = {
.name = "sk_storage_map", .sz = sizeof(map_opts),
.map_type = BPF_MAP_TYPE_SK_STORAGE,
.map_flags = BPF_F_NO_PREALLOC,
.max_entries = 0,
.key_size = 4,
.value_size = 8,
.btf_key_type_id = 1, .btf_key_type_id = 1,
.btf_value_type_id = 3, .btf_value_type_id = 3,
.btf_fd = -1, .btf_fd = -1,
.map_flags = BPF_F_NO_PREALLOC,
}; };
static unsigned int nr_sk_threads_done; static unsigned int nr_sk_threads_done;
...@@ -150,13 +146,13 @@ static int create_sk_storage_map(void) ...@@ -150,13 +146,13 @@ static int create_sk_storage_map(void)
btf_fd = load_btf(); btf_fd = load_btf();
CHECK(btf_fd == -1, "bpf_load_btf", "btf_fd:%d errno:%d\n", CHECK(btf_fd == -1, "bpf_load_btf", "btf_fd:%d errno:%d\n",
btf_fd, errno); btf_fd, errno);
xattr.btf_fd = btf_fd; map_opts.btf_fd = btf_fd;
map_fd = bpf_create_map_xattr(&xattr); map_fd = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 0, &map_opts);
xattr.btf_fd = -1; map_opts.btf_fd = -1;
close(btf_fd); close(btf_fd);
CHECK(map_fd == -1, CHECK(map_fd == -1,
"bpf_create_map_xattr()", "errno:%d\n", errno); "bpf_map_create()", "errno:%d\n", errno);
return map_fd; return map_fd;
} }
...@@ -463,20 +459,20 @@ static void test_sk_storage_map_basic(void) ...@@ -463,20 +459,20 @@ static void test_sk_storage_map_basic(void)
int cnt; int cnt;
int lock; int lock;
} value = { .cnt = 0xeB9f, .lock = 0, }, lookup_value; } value = { .cnt = 0xeB9f, .lock = 0, }, lookup_value;
struct bpf_create_map_attr bad_xattr; struct bpf_map_create_opts bad_xattr;
int btf_fd, map_fd, sk_fd, err; int btf_fd, map_fd, sk_fd, err;
btf_fd = load_btf(); btf_fd = load_btf();
CHECK(btf_fd == -1, "bpf_load_btf", "btf_fd:%d errno:%d\n", CHECK(btf_fd == -1, "bpf_load_btf", "btf_fd:%d errno:%d\n",
btf_fd, errno); btf_fd, errno);
xattr.btf_fd = btf_fd; map_opts.btf_fd = btf_fd;
sk_fd = socket(AF_INET6, SOCK_STREAM, 0); sk_fd = socket(AF_INET6, SOCK_STREAM, 0);
CHECK(sk_fd == -1, "socket()", "sk_fd:%d errno:%d\n", CHECK(sk_fd == -1, "socket()", "sk_fd:%d errno:%d\n",
sk_fd, errno); sk_fd, errno);
map_fd = bpf_create_map_xattr(&xattr); map_fd = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 0, &map_opts);
CHECK(map_fd == -1, "bpf_create_map_xattr(good_xattr)", CHECK(map_fd == -1, "bpf_map_create(good_xattr)",
"map_fd:%d errno:%d\n", map_fd, errno); "map_fd:%d errno:%d\n", map_fd, errno);
/* Add new elem */ /* Add new elem */
...@@ -560,31 +556,29 @@ static void test_sk_storage_map_basic(void) ...@@ -560,31 +556,29 @@ static void test_sk_storage_map_basic(void)
CHECK(!err || errno != ENOENT, "bpf_map_delete_elem()", CHECK(!err || errno != ENOENT, "bpf_map_delete_elem()",
"err:%d errno:%d\n", err, errno); "err:%d errno:%d\n", err, errno);
memcpy(&bad_xattr, &xattr, sizeof(xattr)); memcpy(&bad_xattr, &map_opts, sizeof(map_opts));
bad_xattr.btf_key_type_id = 0; bad_xattr.btf_key_type_id = 0;
err = bpf_create_map_xattr(&bad_xattr); err = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 0, &bad_xattr);
CHECK(!err || errno != EINVAL, "bap_create_map_xattr(bad_xattr)", CHECK(!err || errno != EINVAL, "bpf_map_create(bad_xattr)",
"err:%d errno:%d\n", err, errno); "err:%d errno:%d\n", err, errno);
memcpy(&bad_xattr, &xattr, sizeof(xattr)); memcpy(&bad_xattr, &map_opts, sizeof(map_opts));
bad_xattr.btf_key_type_id = 3; bad_xattr.btf_key_type_id = 3;
err = bpf_create_map_xattr(&bad_xattr); err = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 0, &bad_xattr);
CHECK(!err || errno != EINVAL, "bap_create_map_xattr(bad_xattr)", CHECK(!err || errno != EINVAL, "bpf_map_create(bad_xattr)",
"err:%d errno:%d\n", err, errno); "err:%d errno:%d\n", err, errno);
memcpy(&bad_xattr, &xattr, sizeof(xattr)); err = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 1, &map_opts);
bad_xattr.max_entries = 1; CHECK(!err || errno != EINVAL, "bpf_map_create(bad_xattr)",
err = bpf_create_map_xattr(&bad_xattr);
CHECK(!err || errno != EINVAL, "bap_create_map_xattr(bad_xattr)",
"err:%d errno:%d\n", err, errno); "err:%d errno:%d\n", err, errno);
memcpy(&bad_xattr, &xattr, sizeof(xattr)); memcpy(&bad_xattr, &map_opts, sizeof(map_opts));
bad_xattr.map_flags = 0; bad_xattr.map_flags = 0;
err = bpf_create_map_xattr(&bad_xattr); err = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 0, &bad_xattr);
CHECK(!err || errno != EINVAL, "bap_create_map_xattr(bad_xattr)", CHECK(!err || errno != EINVAL, "bap_create_map_xattr(bad_xattr)",
"err:%d errno:%d\n", err, errno); "err:%d errno:%d\n", err, errno);
xattr.btf_fd = -1; map_opts.btf_fd = -1;
close(btf_fd); close(btf_fd);
close(map_fd); close(map_fd);
close(sk_fd); close(sk_fd);
......
...@@ -7,32 +7,33 @@ ...@@ -7,32 +7,33 @@
static void test_fail_cases(void) static void test_fail_cases(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts);
__u32 value; __u32 value;
int fd, err; int fd, err;
/* Invalid key size */ /* Invalid key size */
fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 4, sizeof(value), 100, 0); fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 4, sizeof(value), 100, NULL);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid key size")) if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid key size"))
close(fd); close(fd);
/* Invalid value size */ /* Invalid value size */
fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, 0, 100, 0); fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, 0, 100, NULL);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid value size 0")) if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid value size 0"))
close(fd); close(fd);
/* Invalid max entries size */ /* Invalid max entries size */
fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 0, 0); fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 0, NULL);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid max entries size")) if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid max entries size"))
close(fd); close(fd);
/* Bloom filter maps do not support BPF_F_NO_PREALLOC */ /* Bloom filter maps do not support BPF_F_NO_PREALLOC */
fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 100, opts.map_flags = BPF_F_NO_PREALLOC;
BPF_F_NO_PREALLOC); fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 100, &opts);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid flags")) if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid flags"))
close(fd); close(fd);
fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 100, 0); fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 100, NULL);
if (!ASSERT_GE(fd, 0, "bpf_create_map bloom filter")) if (!ASSERT_GE(fd, 0, "bpf_map_create bloom filter"))
return; return;
/* Test invalid flags */ /* Test invalid flags */
...@@ -56,13 +57,14 @@ static void test_fail_cases(void) ...@@ -56,13 +57,14 @@ static void test_fail_cases(void)
static void test_success_cases(void) static void test_success_cases(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts);
char value[11]; char value[11];
int fd, err; int fd, err;
/* Create a map */ /* Create a map */
fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 100, opts.map_flags = BPF_F_ZERO_SEED | BPF_F_NUMA_NODE;
BPF_F_ZERO_SEED | BPF_F_NUMA_NODE); fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 100, &opts);
if (!ASSERT_GE(fd, 0, "bpf_create_map bloom filter success case")) if (!ASSERT_GE(fd, 0, "bpf_map_create bloom filter success case"))
return; return;
/* Add a value to the bloom filter */ /* Add a value to the bloom filter */
...@@ -100,9 +102,9 @@ static void test_inner_map(struct bloom_filter_map *skel, const __u32 *rand_vals ...@@ -100,9 +102,9 @@ static void test_inner_map(struct bloom_filter_map *skel, const __u32 *rand_vals
struct bpf_link *link; struct bpf_link *link;
/* Create a bloom filter map that will be used as the inner map */ /* Create a bloom filter map that will be used as the inner map */
inner_map_fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(*rand_vals), inner_map_fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(*rand_vals),
nr_rand_vals, 0); nr_rand_vals, NULL);
if (!ASSERT_GE(inner_map_fd, 0, "bpf_create_map bloom filter inner map")) if (!ASSERT_GE(inner_map_fd, 0, "bpf_map_create bloom filter inner map"))
return; return;
for (i = 0; i < nr_rand_vals; i++) { for (i = 0; i < nr_rand_vals; i++) {
......
...@@ -469,12 +469,12 @@ static void test_overflow(bool test_e2big_overflow, bool ret1) ...@@ -469,12 +469,12 @@ static void test_overflow(bool test_e2big_overflow, bool ret1)
* fills seq_file buffer and then the other will trigger * fills seq_file buffer and then the other will trigger
* overflow and needs restart. * overflow and needs restart.
*/ */
map1_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 8, 1, 0); map1_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 8, 1, NULL);
if (CHECK(map1_fd < 0, "bpf_create_map", if (CHECK(map1_fd < 0, "bpf_map_create",
"map_creation failed: %s\n", strerror(errno))) "map_creation failed: %s\n", strerror(errno)))
goto out; goto out;
map2_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 8, 1, 0); map2_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 8, 1, NULL);
if (CHECK(map2_fd < 0, "bpf_create_map", if (CHECK(map2_fd < 0, "bpf_map_create",
"map_creation failed: %s\n", strerror(errno))) "map_creation failed: %s\n", strerror(errno)))
goto free_map1; goto free_map1;
......
...@@ -4074,7 +4074,7 @@ static void *btf_raw_create(const struct btf_header *hdr, ...@@ -4074,7 +4074,7 @@ static void *btf_raw_create(const struct btf_header *hdr,
static void do_test_raw(unsigned int test_num) static void do_test_raw(unsigned int test_num)
{ {
struct btf_raw_test *test = &raw_tests[test_num - 1]; struct btf_raw_test *test = &raw_tests[test_num - 1];
struct bpf_create_map_attr create_attr = {}; LIBBPF_OPTS(bpf_map_create_opts, opts);
int map_fd = -1, btf_fd = -1; int map_fd = -1, btf_fd = -1;
unsigned int raw_btf_size; unsigned int raw_btf_size;
struct btf_header *hdr; struct btf_header *hdr;
...@@ -4117,16 +4117,11 @@ static void do_test_raw(unsigned int test_num) ...@@ -4117,16 +4117,11 @@ static void do_test_raw(unsigned int test_num)
if (err || btf_fd < 0) if (err || btf_fd < 0)
goto done; goto done;
create_attr.name = test->map_name; opts.btf_fd = btf_fd;
create_attr.map_type = test->map_type; opts.btf_key_type_id = test->key_type_id;
create_attr.key_size = test->key_size; opts.btf_value_type_id = test->value_type_id;
create_attr.value_size = test->value_size; map_fd = bpf_map_create(test->map_type, test->map_name,
create_attr.max_entries = test->max_entries; test->key_size, test->value_size, test->max_entries, &opts);
create_attr.btf_fd = btf_fd;
create_attr.btf_key_type_id = test->key_type_id;
create_attr.btf_value_type_id = test->value_type_id;
map_fd = bpf_create_map_xattr(&create_attr);
err = ((map_fd < 0) != test->map_create_err); err = ((map_fd < 0) != test->map_create_err);
CHECK(err, "map_fd:%d test->map_create_err:%u", CHECK(err, "map_fd:%d test->map_create_err:%u",
...@@ -4290,7 +4285,7 @@ static int test_big_btf_info(unsigned int test_num) ...@@ -4290,7 +4285,7 @@ static int test_big_btf_info(unsigned int test_num)
static int test_btf_id(unsigned int test_num) static int test_btf_id(unsigned int test_num)
{ {
const struct btf_get_info_test *test = &get_info_tests[test_num - 1]; const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
struct bpf_create_map_attr create_attr = {}; LIBBPF_OPTS(bpf_map_create_opts, opts);
uint8_t *raw_btf = NULL, *user_btf[2] = {}; uint8_t *raw_btf = NULL, *user_btf[2] = {};
int btf_fd[2] = {-1, -1}, map_fd = -1; int btf_fd[2] = {-1, -1}, map_fd = -1;
struct bpf_map_info map_info = {}; struct bpf_map_info map_info = {};
...@@ -4355,16 +4350,11 @@ static int test_btf_id(unsigned int test_num) ...@@ -4355,16 +4350,11 @@ static int test_btf_id(unsigned int test_num)
} }
/* Test btf members in struct bpf_map_info */ /* Test btf members in struct bpf_map_info */
create_attr.name = "test_btf_id"; opts.btf_fd = btf_fd[0];
create_attr.map_type = BPF_MAP_TYPE_ARRAY; opts.btf_key_type_id = 1;
create_attr.key_size = sizeof(int); opts.btf_value_type_id = 2;
create_attr.value_size = sizeof(unsigned int); map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "test_btf_id",
create_attr.max_entries = 4; sizeof(int), sizeof(int), 4, &opts);
create_attr.btf_fd = btf_fd[0];
create_attr.btf_key_type_id = 1;
create_attr.btf_value_type_id = 2;
map_fd = bpf_create_map_xattr(&create_attr);
if (CHECK(map_fd < 0, "errno:%d", errno)) { if (CHECK(map_fd < 0, "errno:%d", errno)) {
err = -1; err = -1;
goto done; goto done;
...@@ -5153,7 +5143,7 @@ static void do_test_pprint(int test_num) ...@@ -5153,7 +5143,7 @@ static void do_test_pprint(int test_num)
{ {
const struct btf_raw_test *test = &pprint_test_template[test_num]; const struct btf_raw_test *test = &pprint_test_template[test_num];
enum pprint_mapv_kind_t mapv_kind = test->mapv_kind; enum pprint_mapv_kind_t mapv_kind = test->mapv_kind;
struct bpf_create_map_attr create_attr = {}; LIBBPF_OPTS(bpf_map_create_opts, opts);
bool ordered_map, lossless_map, percpu_map; bool ordered_map, lossless_map, percpu_map;
int err, ret, num_cpus, rounded_value_size; int err, ret, num_cpus, rounded_value_size;
unsigned int key, nr_read_elems; unsigned int key, nr_read_elems;
...@@ -5189,16 +5179,11 @@ static void do_test_pprint(int test_num) ...@@ -5189,16 +5179,11 @@ static void do_test_pprint(int test_num)
goto done; goto done;
} }
create_attr.name = test->map_name; opts.btf_fd = btf_fd;
create_attr.map_type = test->map_type; opts.btf_key_type_id = test->key_type_id;
create_attr.key_size = test->key_size; opts.btf_value_type_id = test->value_type_id;
create_attr.value_size = test->value_size; map_fd = bpf_map_create(test->map_type, test->map_name,
create_attr.max_entries = test->max_entries; test->key_size, test->value_size, test->max_entries, &opts);
create_attr.btf_fd = btf_fd;
create_attr.btf_key_type_id = test->key_type_id;
create_attr.btf_value_type_id = test->value_type_id;
map_fd = bpf_create_map_xattr(&create_attr);
if (CHECK(map_fd < 0, "errno:%d", errno)) { if (CHECK(map_fd < 0, "errno:%d", errno)) {
err = -1; err = -1;
goto done; goto done;
......
...@@ -15,22 +15,22 @@ static int prog_load_cnt(int verdict, int val) ...@@ -15,22 +15,22 @@ static int prog_load_cnt(int verdict, int val)
int cgroup_storage_fd, percpu_cgroup_storage_fd; int cgroup_storage_fd, percpu_cgroup_storage_fd;
if (map_fd < 0) if (map_fd < 0)
map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 8, 1, 0); map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 8, 1, NULL);
if (map_fd < 0) { if (map_fd < 0) {
printf("failed to create map '%s'\n", strerror(errno)); printf("failed to create map '%s'\n", strerror(errno));
return -1; return -1;
} }
cgroup_storage_fd = bpf_create_map(BPF_MAP_TYPE_CGROUP_STORAGE, cgroup_storage_fd = bpf_map_create(BPF_MAP_TYPE_CGROUP_STORAGE, NULL,
sizeof(struct bpf_cgroup_storage_key), 8, 0, 0); sizeof(struct bpf_cgroup_storage_key), 8, 0, NULL);
if (cgroup_storage_fd < 0) { if (cgroup_storage_fd < 0) {
printf("failed to create map '%s'\n", strerror(errno)); printf("failed to create map '%s'\n", strerror(errno));
return -1; return -1;
} }
percpu_cgroup_storage_fd = bpf_create_map( percpu_cgroup_storage_fd = bpf_map_create(
BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, NULL,
sizeof(struct bpf_cgroup_storage_key), 8, 0, 0); sizeof(struct bpf_cgroup_storage_key), 8, 0, NULL);
if (percpu_cgroup_storage_fd < 0) { if (percpu_cgroup_storage_fd < 0) {
printf("failed to create map '%s'\n", strerror(errno)); printf("failed to create map '%s'\n", strerror(errno));
return -1; return -1;
......
...@@ -241,8 +241,8 @@ void test_pinning(void) ...@@ -241,8 +241,8 @@ void test_pinning(void)
goto out; goto out;
} }
map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(__u32), map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(__u32),
sizeof(__u64), 1, 0); sizeof(__u64), 1, NULL);
if (CHECK(map_fd < 0, "create pinmap manually", "fd %d\n", map_fd)) if (CHECK(map_fd < 0, "create pinmap manually", "fd %d\n", map_fd))
goto out; goto out;
......
...@@ -62,8 +62,8 @@ void test_ringbuf_multi(void) ...@@ -62,8 +62,8 @@ void test_ringbuf_multi(void)
if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
goto cleanup; goto cleanup;
proto_fd = bpf_create_map(BPF_MAP_TYPE_RINGBUF, 0, 0, page_size, 0); proto_fd = bpf_map_create(BPF_MAP_TYPE_RINGBUF, NULL, 0, 0, page_size, NULL);
if (CHECK(proto_fd < 0, "bpf_create_map", "bpf_create_map failed\n")) if (CHECK(proto_fd < 0, "bpf_map_create", "bpf_map_create failed\n"))
goto cleanup; goto cleanup;
err = bpf_map__set_inner_map_fd(skel->maps.ringbuf_hash, proto_fd); err = bpf_map__set_inner_map_fd(skel->maps.ringbuf_hash, proto_fd);
......
...@@ -66,29 +66,20 @@ static union sa46 { ...@@ -66,29 +66,20 @@ static union sa46 {
static int create_maps(enum bpf_map_type inner_type) static int create_maps(enum bpf_map_type inner_type)
{ {
struct bpf_create_map_attr attr = {}; LIBBPF_OPTS(bpf_map_create_opts, opts);
inner_map_type = inner_type; inner_map_type = inner_type;
/* Creating reuseport_array */ /* Creating reuseport_array */
attr.name = "reuseport_array"; reuseport_array = bpf_map_create(inner_type, "reuseport_array",
attr.map_type = inner_type; sizeof(__u32), sizeof(__u32), REUSEPORT_ARRAY_SIZE, NULL);
attr.key_size = sizeof(__u32);
attr.value_size = sizeof(__u32);
attr.max_entries = REUSEPORT_ARRAY_SIZE;
reuseport_array = bpf_create_map_xattr(&attr);
RET_ERR(reuseport_array < 0, "creating reuseport_array", RET_ERR(reuseport_array < 0, "creating reuseport_array",
"reuseport_array:%d errno:%d\n", reuseport_array, errno); "reuseport_array:%d errno:%d\n", reuseport_array, errno);
/* Creating outer_map */ /* Creating outer_map */
attr.name = "outer_map"; opts.inner_map_fd = reuseport_array;
attr.map_type = BPF_MAP_TYPE_ARRAY_OF_MAPS; outer_map = bpf_map_create(BPF_MAP_TYPE_ARRAY_OF_MAPS, "outer_map",
attr.key_size = sizeof(__u32); sizeof(__u32), sizeof(__u32), 1, &opts);
attr.value_size = sizeof(__u32);
attr.max_entries = 1;
attr.inner_map_fd = reuseport_array;
outer_map = bpf_create_map_xattr(&attr);
RET_ERR(outer_map < 0, "creating outer_map", RET_ERR(outer_map < 0, "creating outer_map",
"outer_map:%d errno:%d\n", outer_map, errno); "outer_map:%d errno:%d\n", outer_map, errno);
......
...@@ -91,9 +91,9 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type) ...@@ -91,9 +91,9 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type)
if (CHECK_FAIL(s < 0)) if (CHECK_FAIL(s < 0))
return; return;
map = bpf_create_map(map_type, sizeof(int), sizeof(int), 1, 0); map = bpf_map_create(map_type, NULL, sizeof(int), sizeof(int), 1, NULL);
if (CHECK_FAIL(map < 0)) { if (CHECK_FAIL(map < 0)) {
perror("bpf_create_map"); perror("bpf_cmap_create");
goto out; goto out;
} }
......
...@@ -97,7 +97,7 @@ static void run_tests(int family, enum bpf_map_type map_type) ...@@ -97,7 +97,7 @@ static void run_tests(int family, enum bpf_map_type map_type)
char test_name[MAX_TEST_NAME]; char test_name[MAX_TEST_NAME];
int map; int map;
map = bpf_create_map(map_type, sizeof(int), sizeof(int), 1, 0); map = bpf_map_create(map_type, NULL, sizeof(int), sizeof(int), 1, NULL);
if (CHECK_FAIL(map < 0)) { if (CHECK_FAIL(map < 0)) {
perror("bpf_map_create"); perror("bpf_map_create");
return; return;
......
...@@ -502,8 +502,8 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd) ...@@ -502,8 +502,8 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd)
if (s < 0) if (s < 0)
return; return;
mapfd = bpf_create_map(BPF_MAP_TYPE_SOCKMAP, sizeof(key), mapfd = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, sizeof(key),
sizeof(value32), 1, 0); sizeof(value32), 1, NULL);
if (mapfd < 0) { if (mapfd < 0) {
FAIL_ERRNO("map_create"); FAIL_ERRNO("map_create");
goto close; goto close;
......
...@@ -80,7 +80,7 @@ static int fn(void) ...@@ -80,7 +80,7 @@ static int fn(void)
if (!ASSERT_OK(err, "creating " TDIR "/fs1/b")) if (!ASSERT_OK(err, "creating " TDIR "/fs1/b"))
goto out; goto out;
map = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 4, 1, 0); map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 4, 1, NULL);
if (!ASSERT_GT(map, 0, "create_map(ARRAY)")) if (!ASSERT_GT(map, 0, "create_map(ARRAY)"))
goto out; goto out;
err = bpf_obj_pin(map, TDIR "/fs1/c"); err = bpf_obj_pin(map, TDIR "/fs1/c");
......
...@@ -51,15 +51,15 @@ int main(int argc, char **argv) ...@@ -51,15 +51,15 @@ int main(int argc, char **argv)
goto err; goto err;
} }
map_fd = bpf_create_map(BPF_MAP_TYPE_CGROUP_STORAGE, sizeof(key), map_fd = bpf_map_create(BPF_MAP_TYPE_CGROUP_STORAGE, NULL, sizeof(key),
sizeof(value), 0, 0); sizeof(value), 0, NULL);
if (map_fd < 0) { if (map_fd < 0) {
printf("Failed to create map: %s\n", strerror(errno)); printf("Failed to create map: %s\n", strerror(errno));
goto out; goto out;
} }
percpu_map_fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, percpu_map_fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, NULL,
sizeof(key), sizeof(value), 0, 0); sizeof(key), sizeof(value), 0, NULL);
if (percpu_map_fd < 0) { if (percpu_map_fd < 0) {
printf("Failed to create map: %s\n", strerror(errno)); printf("Failed to create map: %s\n", strerror(errno));
goto out; goto out;
......
...@@ -208,6 +208,7 @@ static void test_lpm_order(void) ...@@ -208,6 +208,7 @@ static void test_lpm_order(void)
static void test_lpm_map(int keysize) static void test_lpm_map(int keysize)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
size_t i, j, n_matches, n_matches_after_delete, n_nodes, n_lookups; size_t i, j, n_matches, n_matches_after_delete, n_nodes, n_lookups;
struct tlpm_node *t, *list = NULL; struct tlpm_node *t, *list = NULL;
struct bpf_lpm_trie_key *key; struct bpf_lpm_trie_key *key;
...@@ -233,11 +234,11 @@ static void test_lpm_map(int keysize) ...@@ -233,11 +234,11 @@ static void test_lpm_map(int keysize)
key = alloca(sizeof(*key) + keysize); key = alloca(sizeof(*key) + keysize);
memset(key, 0, sizeof(*key) + keysize); memset(key, 0, sizeof(*key) + keysize);
map = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE, map = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, NULL,
sizeof(*key) + keysize, sizeof(*key) + keysize,
keysize + 1, keysize + 1,
4096, 4096,
BPF_F_NO_PREALLOC); &opts);
assert(map >= 0); assert(map >= 0);
for (i = 0; i < n_nodes; ++i) { for (i = 0; i < n_nodes; ++i) {
...@@ -329,6 +330,7 @@ static void test_lpm_map(int keysize) ...@@ -329,6 +330,7 @@ static void test_lpm_map(int keysize)
static void test_lpm_ipaddr(void) static void test_lpm_ipaddr(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
struct bpf_lpm_trie_key *key_ipv4; struct bpf_lpm_trie_key *key_ipv4;
struct bpf_lpm_trie_key *key_ipv6; struct bpf_lpm_trie_key *key_ipv6;
size_t key_size_ipv4; size_t key_size_ipv4;
...@@ -342,14 +344,14 @@ static void test_lpm_ipaddr(void) ...@@ -342,14 +344,14 @@ static void test_lpm_ipaddr(void)
key_ipv4 = alloca(key_size_ipv4); key_ipv4 = alloca(key_size_ipv4);
key_ipv6 = alloca(key_size_ipv6); key_ipv6 = alloca(key_size_ipv6);
map_fd_ipv4 = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE, map_fd_ipv4 = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, NULL,
key_size_ipv4, sizeof(value), key_size_ipv4, sizeof(value),
100, BPF_F_NO_PREALLOC); 100, &opts);
assert(map_fd_ipv4 >= 0); assert(map_fd_ipv4 >= 0);
map_fd_ipv6 = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE, map_fd_ipv6 = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, NULL,
key_size_ipv6, sizeof(value), key_size_ipv6, sizeof(value),
100, BPF_F_NO_PREALLOC); 100, &opts);
assert(map_fd_ipv6 >= 0); assert(map_fd_ipv6 >= 0);
/* Fill data some IPv4 and IPv6 address ranges */ /* Fill data some IPv4 and IPv6 address ranges */
...@@ -423,6 +425,7 @@ static void test_lpm_ipaddr(void) ...@@ -423,6 +425,7 @@ static void test_lpm_ipaddr(void)
static void test_lpm_delete(void) static void test_lpm_delete(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
struct bpf_lpm_trie_key *key; struct bpf_lpm_trie_key *key;
size_t key_size; size_t key_size;
int map_fd; int map_fd;
...@@ -431,9 +434,9 @@ static void test_lpm_delete(void) ...@@ -431,9 +434,9 @@ static void test_lpm_delete(void)
key_size = sizeof(*key) + sizeof(__u32); key_size = sizeof(*key) + sizeof(__u32);
key = alloca(key_size); key = alloca(key_size);
map_fd = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE, map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, NULL,
key_size, sizeof(value), key_size, sizeof(value),
100, BPF_F_NO_PREALLOC); 100, &opts);
assert(map_fd >= 0); assert(map_fd >= 0);
/* Add nodes: /* Add nodes:
...@@ -535,6 +538,7 @@ static void test_lpm_delete(void) ...@@ -535,6 +538,7 @@ static void test_lpm_delete(void)
static void test_lpm_get_next_key(void) static void test_lpm_get_next_key(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
struct bpf_lpm_trie_key *key_p, *next_key_p; struct bpf_lpm_trie_key *key_p, *next_key_p;
size_t key_size; size_t key_size;
__u32 value = 0; __u32 value = 0;
...@@ -544,8 +548,7 @@ static void test_lpm_get_next_key(void) ...@@ -544,8 +548,7 @@ static void test_lpm_get_next_key(void)
key_p = alloca(key_size); key_p = alloca(key_size);
next_key_p = alloca(key_size); next_key_p = alloca(key_size);
map_fd = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE, key_size, sizeof(value), map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, NULL, key_size, sizeof(value), 100, &opts);
100, BPF_F_NO_PREALLOC);
assert(map_fd >= 0); assert(map_fd >= 0);
/* empty tree. get_next_key should return ENOENT */ /* empty tree. get_next_key should return ENOENT */
...@@ -753,6 +756,7 @@ static void setup_lpm_mt_test_info(struct lpm_mt_test_info *info, int map_fd) ...@@ -753,6 +756,7 @@ static void setup_lpm_mt_test_info(struct lpm_mt_test_info *info, int map_fd)
static void test_lpm_multi_thread(void) static void test_lpm_multi_thread(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
struct lpm_mt_test_info info[4]; struct lpm_mt_test_info info[4];
size_t key_size, value_size; size_t key_size, value_size;
pthread_t thread_id[4]; pthread_t thread_id[4];
...@@ -762,8 +766,7 @@ static void test_lpm_multi_thread(void) ...@@ -762,8 +766,7 @@ static void test_lpm_multi_thread(void)
/* create a trie */ /* create a trie */
value_size = sizeof(__u32); value_size = sizeof(__u32);
key_size = sizeof(struct bpf_lpm_trie_key) + value_size; key_size = sizeof(struct bpf_lpm_trie_key) + value_size;
map_fd = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE, key_size, value_size, map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, NULL, key_size, value_size, 100, &opts);
100, BPF_F_NO_PREALLOC);
/* create 4 threads to test update, delete, lookup and get_next_key */ /* create 4 threads to test update, delete, lookup and get_next_key */
setup_lpm_mt_test_info(&info[0], map_fd); setup_lpm_mt_test_info(&info[0], map_fd);
......
...@@ -28,13 +28,14 @@ static int nr_cpus; ...@@ -28,13 +28,14 @@ static int nr_cpus;
static int create_map(int map_type, int map_flags, unsigned int size) static int create_map(int map_type, int map_flags, unsigned int size)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = map_flags);
int map_fd; int map_fd;
map_fd = bpf_create_map(map_type, sizeof(unsigned long long), map_fd = bpf_map_create(map_type, NULL, sizeof(unsigned long long),
sizeof(unsigned long long), size, map_flags); sizeof(unsigned long long), size, &opts);
if (map_fd == -1) if (map_fd == -1)
perror("bpf_create_map"); perror("bpf_map_create");
return map_fd; return map_fd;
} }
...@@ -42,7 +43,6 @@ static int create_map(int map_type, int map_flags, unsigned int size) ...@@ -42,7 +43,6 @@ static int create_map(int map_type, int map_flags, unsigned int size)
static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key, static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key,
void *value) void *value)
{ {
struct bpf_create_map_attr map;
struct bpf_insn insns[] = { struct bpf_insn insns[] = {
BPF_LD_MAP_VALUE(BPF_REG_9, 0, 0), BPF_LD_MAP_VALUE(BPF_REG_9, 0, 0),
BPF_LD_MAP_FD(BPF_REG_1, fd), BPF_LD_MAP_FD(BPF_REG_1, fd),
...@@ -63,13 +63,7 @@ static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key, ...@@ -63,13 +63,7 @@ static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key,
int mfd, pfd, ret, zero = 0; int mfd, pfd, ret, zero = 0;
__u32 retval = 0; __u32 retval = 0;
memset(&map, 0, sizeof(map)); mfd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), sizeof(__u64), 1, NULL);
map.map_type = BPF_MAP_TYPE_ARRAY;
map.key_size = sizeof(int);
map.value_size = sizeof(unsigned long long);
map.max_entries = 1;
mfd = bpf_create_map_xattr(&map);
if (mfd < 0) if (mfd < 0)
return -1; return -1;
......
This diff is collapsed.
...@@ -185,11 +185,12 @@ static void do_test(uint32_t *tests, int start_insns, int fd_map, ...@@ -185,11 +185,12 @@ static void do_test(uint32_t *tests, int start_insns, int fd_map,
int main(void) int main(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
uint32_t tests = 0; uint32_t tests = 0;
int i, fd_map; int i, fd_map;
fd_map = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(int), fd_map = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(int),
sizeof(int), 1, BPF_F_NO_PREALLOC); sizeof(int), 1, &opts);
assert(fd_map > 0); assert(fd_map > 0);
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
......
...@@ -461,11 +461,11 @@ static int __create_map(uint32_t type, uint32_t size_key, ...@@ -461,11 +461,11 @@ static int __create_map(uint32_t type, uint32_t size_key,
uint32_t size_value, uint32_t max_elem, uint32_t size_value, uint32_t max_elem,
uint32_t extra_flags) uint32_t extra_flags)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts);
int fd; int fd;
fd = bpf_create_map(type, size_key, size_value, max_elem, opts.map_flags = (type == BPF_MAP_TYPE_HASH ? BPF_F_NO_PREALLOC : 0) | extra_flags;
(type == BPF_MAP_TYPE_HASH ? fd = bpf_map_create(type, NULL, size_key, size_value, max_elem, &opts);
BPF_F_NO_PREALLOC : 0) | extra_flags);
if (fd < 0) { if (fd < 0) {
if (skip_unsupported_map(type)) if (skip_unsupported_map(type))
return -1; return -1;
...@@ -521,8 +521,8 @@ static int create_prog_array(enum bpf_prog_type prog_type, uint32_t max_elem, ...@@ -521,8 +521,8 @@ static int create_prog_array(enum bpf_prog_type prog_type, uint32_t max_elem,
{ {
int mfd, p1fd, p2fd, p3fd; int mfd, p1fd, p2fd, p3fd;
mfd = bpf_create_map(BPF_MAP_TYPE_PROG_ARRAY, sizeof(int), mfd = bpf_map_create(BPF_MAP_TYPE_PROG_ARRAY, NULL, sizeof(int),
sizeof(int), max_elem, 0); sizeof(int), max_elem, NULL);
if (mfd < 0) { if (mfd < 0) {
if (skip_unsupported_map(BPF_MAP_TYPE_PROG_ARRAY)) if (skip_unsupported_map(BPF_MAP_TYPE_PROG_ARRAY))
return -1; return -1;
...@@ -552,10 +552,11 @@ static int create_prog_array(enum bpf_prog_type prog_type, uint32_t max_elem, ...@@ -552,10 +552,11 @@ static int create_prog_array(enum bpf_prog_type prog_type, uint32_t max_elem,
static int create_map_in_map(void) static int create_map_in_map(void)
{ {
LIBBPF_OPTS(bpf_map_create_opts, opts);
int inner_map_fd, outer_map_fd; int inner_map_fd, outer_map_fd;
inner_map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(int), inner_map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int),
sizeof(int), 1, 0); sizeof(int), 1, NULL);
if (inner_map_fd < 0) { if (inner_map_fd < 0) {
if (skip_unsupported_map(BPF_MAP_TYPE_ARRAY)) if (skip_unsupported_map(BPF_MAP_TYPE_ARRAY))
return -1; return -1;
...@@ -563,8 +564,9 @@ static int create_map_in_map(void) ...@@ -563,8 +564,9 @@ static int create_map_in_map(void)
return inner_map_fd; return inner_map_fd;
} }
outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL, opts.inner_map_fd = inner_map_fd;
sizeof(int), inner_map_fd, 1, 0); outer_map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL,
sizeof(int), sizeof(int), 1, &opts);
if (outer_map_fd < 0) { if (outer_map_fd < 0) {
if (skip_unsupported_map(BPF_MAP_TYPE_ARRAY_OF_MAPS)) if (skip_unsupported_map(BPF_MAP_TYPE_ARRAY_OF_MAPS))
return -1; return -1;
...@@ -583,8 +585,8 @@ static int create_cgroup_storage(bool percpu) ...@@ -583,8 +585,8 @@ static int create_cgroup_storage(bool percpu)
BPF_MAP_TYPE_CGROUP_STORAGE; BPF_MAP_TYPE_CGROUP_STORAGE;
int fd; int fd;
fd = bpf_create_map(type, sizeof(struct bpf_cgroup_storage_key), fd = bpf_map_create(type, NULL, sizeof(struct bpf_cgroup_storage_key),
TEST_DATA_LEN, 0, 0); TEST_DATA_LEN, 0, NULL);
if (fd < 0) { if (fd < 0) {
if (skip_unsupported_map(type)) if (skip_unsupported_map(type))
return -1; return -1;
...@@ -648,22 +650,17 @@ static int load_btf(void) ...@@ -648,22 +650,17 @@ static int load_btf(void)
static int create_map_spin_lock(void) static int create_map_spin_lock(void)
{ {
struct bpf_create_map_attr attr = { LIBBPF_OPTS(bpf_map_create_opts, opts,
.name = "test_map",
.map_type = BPF_MAP_TYPE_ARRAY,
.key_size = 4,
.value_size = 8,
.max_entries = 1,
.btf_key_type_id = 1, .btf_key_type_id = 1,
.btf_value_type_id = 3, .btf_value_type_id = 3,
}; );
int fd, btf_fd; int fd, btf_fd;
btf_fd = load_btf(); btf_fd = load_btf();
if (btf_fd < 0) if (btf_fd < 0)
return -1; return -1;
attr.btf_fd = btf_fd; opts.btf_fd = btf_fd;
fd = bpf_create_map_xattr(&attr); fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "test_map", 4, 8, 1, &opts);
if (fd < 0) if (fd < 0)
printf("Failed to create map with spin_lock\n"); printf("Failed to create map with spin_lock\n");
return fd; return fd;
...@@ -671,24 +668,19 @@ static int create_map_spin_lock(void) ...@@ -671,24 +668,19 @@ static int create_map_spin_lock(void)
static int create_sk_storage_map(void) static int create_sk_storage_map(void)
{ {
struct bpf_create_map_attr attr = { LIBBPF_OPTS(bpf_map_create_opts, opts,
.name = "test_map",
.map_type = BPF_MAP_TYPE_SK_STORAGE,
.key_size = 4,
.value_size = 8,
.max_entries = 0,
.map_flags = BPF_F_NO_PREALLOC, .map_flags = BPF_F_NO_PREALLOC,
.btf_key_type_id = 1, .btf_key_type_id = 1,
.btf_value_type_id = 3, .btf_value_type_id = 3,
}; );
int fd, btf_fd; int fd, btf_fd;
btf_fd = load_btf(); btf_fd = load_btf();
if (btf_fd < 0) if (btf_fd < 0)
return -1; return -1;
attr.btf_fd = btf_fd; opts.btf_fd = btf_fd;
fd = bpf_create_map_xattr(&attr); fd = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "test_map", 4, 8, 0, &opts);
close(attr.btf_fd); close(opts.btf_fd);
if (fd < 0) if (fd < 0)
printf("Failed to create sk_storage_map\n"); printf("Failed to create sk_storage_map\n");
return fd; return fd;
......
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