Commit 5f155c25 authored by Mickaël Salaün's avatar Mickaël Salaün Committed by David S. Miller

bpf: Use bpf_map_get_next_key() from the library

Replace bpf_map_next_key() with bpf_map_get_next_key() calls.
Signed-off-by: default avatarMickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e58383b8
...@@ -135,7 +135,7 @@ int bpf_map_delete_elem(int fd, const void *key) ...@@ -135,7 +135,7 @@ int bpf_map_delete_elem(int fd, const void *key)
return sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); return sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
} }
int bpf_map_get_next_key(int fd, void *key, void *next_key) int bpf_map_get_next_key(int fd, const void *key, void *next_key)
{ {
union bpf_attr attr; union bpf_attr attr;
......
...@@ -38,7 +38,7 @@ int bpf_map_update_elem(int fd, const void *key, const void *value, ...@@ -38,7 +38,7 @@ int bpf_map_update_elem(int fd, const void *key, const void *value,
int bpf_map_lookup_elem(int fd, const void *key, void *value); int bpf_map_lookup_elem(int fd, const void *key, void *value);
int bpf_map_delete_elem(int fd, const void *key); int bpf_map_delete_elem(int fd, const void *key);
int bpf_map_get_next_key(int fd, void *key, void *next_key); int bpf_map_get_next_key(int fd, const void *key, void *next_key);
int bpf_obj_pin(int fd, const char *pathname); int bpf_obj_pin(int fd, const char *pathname);
int bpf_obj_get(const char *pathname); int bpf_obj_get(const char *pathname);
int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type); int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type);
......
...@@ -24,17 +24,6 @@ static inline int bpf(int cmd, union bpf_attr *attr, unsigned int size) ...@@ -24,17 +24,6 @@ static inline int bpf(int cmd, union bpf_attr *attr, unsigned int size)
#endif #endif
} }
static inline int bpf_map_next_key(int fd, const void *key, void *next_key)
{
union bpf_attr attr = {};
attr.map_fd = fd;
attr.key = bpf_ptr_to_u64(key);
attr.next_key = bpf_ptr_to_u64(next_key);
return bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr));
}
static inline int bpf_map_create(enum bpf_map_type type, uint32_t size_key, static inline int bpf_map_create(enum bpf_map_type type, uint32_t size_key,
uint32_t size_value, uint32_t max_elem, uint32_t size_value, uint32_t max_elem,
uint32_t flags) uint32_t flags)
......
...@@ -46,7 +46,7 @@ static int map_subset(int map0, int map1) ...@@ -46,7 +46,7 @@ static int map_subset(int map0, int map1)
unsigned long long value0[nr_cpus], value1[nr_cpus]; unsigned long long value0[nr_cpus], value1[nr_cpus];
int ret; int ret;
while (!bpf_map_next_key(map1, &next_key, &next_key)) { while (!bpf_map_get_next_key(map1, &next_key, &next_key)) {
assert(!bpf_map_lookup_elem(map1, &next_key, value1)); assert(!bpf_map_lookup_elem(map1, &next_key, value1));
ret = bpf_map_lookup_elem(map0, &next_key, value0); ret = bpf_map_lookup_elem(map0, &next_key, value0);
if (ret) { if (ret) {
......
...@@ -89,11 +89,11 @@ static void test_hashmap(int task, void *data) ...@@ -89,11 +89,11 @@ static void test_hashmap(int task, void *data)
assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT); assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT);
/* Iterate over two elements. */ /* Iterate over two elements. */
assert(bpf_map_next_key(fd, &key, &next_key) == 0 && assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 &&
(next_key == 1 || next_key == 2)); (next_key == 1 || next_key == 2));
assert(bpf_map_next_key(fd, &next_key, &next_key) == 0 && assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 &&
(next_key == 1 || next_key == 2)); (next_key == 1 || next_key == 2));
assert(bpf_map_next_key(fd, &next_key, &next_key) == -1 && assert(bpf_map_get_next_key(fd, &next_key, &next_key) == -1 &&
errno == ENOENT); errno == ENOENT);
/* Delete both elements. */ /* Delete both elements. */
...@@ -105,7 +105,7 @@ static void test_hashmap(int task, void *data) ...@@ -105,7 +105,7 @@ static void test_hashmap(int task, void *data)
key = 0; key = 0;
/* Check that map is empty. */ /* Check that map is empty. */
assert(bpf_map_next_key(fd, &key, &next_key) == -1 && assert(bpf_map_get_next_key(fd, &key, &next_key) == -1 &&
errno == ENOENT); errno == ENOENT);
close(fd); close(fd);
...@@ -175,7 +175,7 @@ static void test_hashmap_percpu(int task, void *data) ...@@ -175,7 +175,7 @@ static void test_hashmap_percpu(int task, void *data)
assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT); assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT);
/* Iterate over two elements. */ /* Iterate over two elements. */
while (!bpf_map_next_key(fd, &key, &next_key)) { while (!bpf_map_get_next_key(fd, &key, &next_key)) {
assert((expected_key_mask & next_key) == next_key); assert((expected_key_mask & next_key) == next_key);
expected_key_mask &= ~next_key; expected_key_mask &= ~next_key;
...@@ -201,7 +201,7 @@ static void test_hashmap_percpu(int task, void *data) ...@@ -201,7 +201,7 @@ static void test_hashmap_percpu(int task, void *data)
key = 0; key = 0;
/* Check that map is empty. */ /* Check that map is empty. */
assert(bpf_map_next_key(fd, &key, &next_key) == -1 && assert(bpf_map_get_next_key(fd, &key, &next_key) == -1 &&
errno == ENOENT); errno == ENOENT);
close(fd); close(fd);
...@@ -246,11 +246,11 @@ static void test_arraymap(int task, void *data) ...@@ -246,11 +246,11 @@ static void test_arraymap(int task, void *data)
assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT);
/* Iterate over two elements. */ /* Iterate over two elements. */
assert(bpf_map_next_key(fd, &key, &next_key) == 0 && assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 &&
next_key == 0); next_key == 0);
assert(bpf_map_next_key(fd, &next_key, &next_key) == 0 && assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 &&
next_key == 1); next_key == 1);
assert(bpf_map_next_key(fd, &next_key, &next_key) == -1 && assert(bpf_map_get_next_key(fd, &next_key, &next_key) == -1 &&
errno == ENOENT); errno == ENOENT);
/* Delete shouldn't succeed. */ /* Delete shouldn't succeed. */
...@@ -301,11 +301,11 @@ static void test_arraymap_percpu(int task, void *data) ...@@ -301,11 +301,11 @@ static void test_arraymap_percpu(int task, void *data)
assert(bpf_map_lookup_elem(fd, &key, values) == -1 && errno == ENOENT); assert(bpf_map_lookup_elem(fd, &key, values) == -1 && errno == ENOENT);
/* Iterate over two elements. */ /* Iterate over two elements. */
assert(bpf_map_next_key(fd, &key, &next_key) == 0 && assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 &&
next_key == 0); next_key == 0);
assert(bpf_map_next_key(fd, &next_key, &next_key) == 0 && assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 &&
next_key == 1); next_key == 1);
assert(bpf_map_next_key(fd, &next_key, &next_key) == -1 && assert(bpf_map_get_next_key(fd, &next_key, &next_key) == -1 &&
errno == ENOENT); errno == ENOENT);
/* Delete shouldn't succeed. */ /* Delete shouldn't succeed. */
...@@ -380,8 +380,8 @@ static void test_map_large(void) ...@@ -380,8 +380,8 @@ static void test_map_large(void)
/* Iterate through all elements. */ /* Iterate through all elements. */
for (i = 0; i < MAP_SIZE; i++) for (i = 0; i < MAP_SIZE; i++)
assert(bpf_map_next_key(fd, &key, &key) == 0); assert(bpf_map_get_next_key(fd, &key, &key) == 0);
assert(bpf_map_next_key(fd, &key, &key) == -1 && errno == ENOENT); assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT);
key.c = 0; key.c = 0;
assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0);
...@@ -479,8 +479,8 @@ static void test_map_parallel(void) ...@@ -479,8 +479,8 @@ static void test_map_parallel(void)
/* Check that all elements were inserted. */ /* Check that all elements were inserted. */
key = -1; key = -1;
for (i = 0; i < MAP_SIZE; i++) for (i = 0; i < MAP_SIZE; i++)
assert(bpf_map_next_key(fd, &key, &key) == 0); assert(bpf_map_get_next_key(fd, &key, &key) == 0);
assert(bpf_map_next_key(fd, &key, &key) == -1 && errno == ENOENT); assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT);
/* Another check for all elements */ /* Another check for all elements */
for (i = 0; i < MAP_SIZE; i++) { for (i = 0; i < MAP_SIZE; i++) {
...@@ -496,7 +496,7 @@ static void test_map_parallel(void) ...@@ -496,7 +496,7 @@ static void test_map_parallel(void)
/* Nothing should be left. */ /* Nothing should be left. */
key = -1; key = -1;
assert(bpf_map_next_key(fd, &key, &key) == -1 && errno == ENOENT); assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT);
} }
static void run_all_tests(void) static void run_all_tests(void)
......
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