mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-23 05:56:14 -04:00
bpf: Use bpf_map_lookup_elem() from the library
Replace bpf_map_lookup() with bpf_map_lookup_elem() calls. Signed-off-by: Mickaë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: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
10ecc728fe
commit
e5ff7c4019
@@ -55,11 +55,11 @@ static void test_hashmap(int task, void *data)
|
||||
errno == EINVAL);
|
||||
|
||||
/* Check that key=1 can be found. */
|
||||
assert(bpf_map_lookup(fd, &key, &value) == 0 && value == 1234);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234);
|
||||
|
||||
key = 2;
|
||||
/* Check that key=2 is not found. */
|
||||
assert(bpf_map_lookup(fd, &key, &value) == -1 && errno == ENOENT);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT);
|
||||
|
||||
/* BPF_EXIST means update existing element. */
|
||||
assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == -1 &&
|
||||
@@ -148,11 +148,11 @@ static void test_hashmap_percpu(int task, void *data)
|
||||
* was run from a different CPU.
|
||||
*/
|
||||
value[0] = 1;
|
||||
assert(bpf_map_lookup(fd, &key, value) == 0 && value[0] == 100);
|
||||
assert(bpf_map_lookup_elem(fd, &key, value) == 0 && value[0] == 100);
|
||||
|
||||
key = 2;
|
||||
/* Check that key=2 is not found. */
|
||||
assert(bpf_map_lookup(fd, &key, value) == -1 && errno == ENOENT);
|
||||
assert(bpf_map_lookup_elem(fd, &key, value) == -1 && errno == ENOENT);
|
||||
|
||||
/* BPF_EXIST means update existing element. */
|
||||
assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == -1 &&
|
||||
@@ -179,7 +179,7 @@ static void test_hashmap_percpu(int task, void *data)
|
||||
assert((expected_key_mask & next_key) == next_key);
|
||||
expected_key_mask &= ~next_key;
|
||||
|
||||
assert(bpf_map_lookup(fd, &next_key, value) == 0);
|
||||
assert(bpf_map_lookup_elem(fd, &next_key, value) == 0);
|
||||
|
||||
for (i = 0; i < nr_cpus; i++)
|
||||
assert(value[i] == i + 100);
|
||||
@@ -229,11 +229,11 @@ static void test_arraymap(int task, void *data)
|
||||
errno == EEXIST);
|
||||
|
||||
/* Check that key=1 can be found. */
|
||||
assert(bpf_map_lookup(fd, &key, &value) == 0 && value == 1234);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234);
|
||||
|
||||
key = 0;
|
||||
/* Check that key=0 is also found and zero initialized. */
|
||||
assert(bpf_map_lookup(fd, &key, &value) == 0 && value == 0);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0);
|
||||
|
||||
/* key=0 and key=1 were inserted, check that key=2 cannot be inserted
|
||||
* due to max_entries limit.
|
||||
@@ -243,7 +243,7 @@ static void test_arraymap(int task, void *data)
|
||||
errno == E2BIG);
|
||||
|
||||
/* Check that key = 2 doesn't exist. */
|
||||
assert(bpf_map_lookup(fd, &key, &value) == -1 && errno == ENOENT);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT);
|
||||
|
||||
/* Iterate over two elements. */
|
||||
assert(bpf_map_next_key(fd, &key, &next_key) == 0 &&
|
||||
@@ -285,11 +285,11 @@ static void test_arraymap_percpu(int task, void *data)
|
||||
errno == EEXIST);
|
||||
|
||||
/* Check that key=1 can be found. */
|
||||
assert(bpf_map_lookup(fd, &key, values) == 0 && values[0] == 100);
|
||||
assert(bpf_map_lookup_elem(fd, &key, values) == 0 && values[0] == 100);
|
||||
|
||||
key = 0;
|
||||
/* Check that key=0 is also found and zero initialized. */
|
||||
assert(bpf_map_lookup(fd, &key, values) == 0 &&
|
||||
assert(bpf_map_lookup_elem(fd, &key, values) == 0 &&
|
||||
values[0] == 0 && values[nr_cpus - 1] == 0);
|
||||
|
||||
/* Check that key=2 cannot be inserted due to max_entries limit. */
|
||||
@@ -298,7 +298,7 @@ static void test_arraymap_percpu(int task, void *data)
|
||||
errno == E2BIG);
|
||||
|
||||
/* Check that key = 2 doesn't exist. */
|
||||
assert(bpf_map_lookup(fd, &key, values) == -1 && errno == ENOENT);
|
||||
assert(bpf_map_lookup_elem(fd, &key, values) == -1 && errno == ENOENT);
|
||||
|
||||
/* Iterate over two elements. */
|
||||
assert(bpf_map_next_key(fd, &key, &next_key) == 0 &&
|
||||
@@ -340,7 +340,7 @@ static void test_arraymap_percpu_many_keys(void)
|
||||
for (i = 0; i < nr_cpus; i++)
|
||||
values[i] = 0;
|
||||
|
||||
assert(bpf_map_lookup(fd, &key, values) == 0);
|
||||
assert(bpf_map_lookup_elem(fd, &key, values) == 0);
|
||||
|
||||
for (i = 0; i < nr_cpus; i++)
|
||||
assert(values[i] == i + 10);
|
||||
@@ -384,9 +384,9 @@ static void test_map_large(void)
|
||||
assert(bpf_map_next_key(fd, &key, &key) == -1 && errno == ENOENT);
|
||||
|
||||
key.c = 0;
|
||||
assert(bpf_map_lookup(fd, &key, &value) == 0 && value == 0);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0);
|
||||
key.a = 1;
|
||||
assert(bpf_map_lookup(fd, &key, &value) == -1 && errno == ENOENT);
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
@@ -486,7 +486,7 @@ static void test_map_parallel(void)
|
||||
for (i = 0; i < MAP_SIZE; i++) {
|
||||
key = MAP_SIZE - i - 1;
|
||||
|
||||
assert(bpf_map_lookup(fd, &key, &value) == 0 &&
|
||||
assert(bpf_map_lookup_elem(fd, &key, &value) == 0 &&
|
||||
value == key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user