Skip to content

Commit

Permalink
selftests/bpf: Test for associating multiple elements with the local …
Browse files Browse the repository at this point in the history
…storage

This patch adds a few calls to the existing local storage selftest to
test that we can associate multiple elements with the local storage.

The sleepable program's call to bpf_sk_storage_get with sk_storage_map2
will lead to an allocation of a new selem under the GFP_KERNEL flag.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
  • Loading branch information
joannekoong authored and Nobody committed Mar 18, 2022
1 parent cf06812 commit 6ef3352
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/testing/selftests/bpf/progs/local_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ struct {
__type(value, struct local_storage);
} sk_storage_map SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC | BPF_F_CLONE);
__type(key, int);
__type(value, struct local_storage);
} sk_storage_map2 SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
Expand Down Expand Up @@ -115,7 +122,19 @@ int BPF_PROG(socket_bind, struct socket *sock, struct sockaddr *address,
if (storage->value != DUMMY_STORAGE_VALUE)
sk_storage_result = -1;

/* This tests that we can associate multiple elements
* with the local storage.
*/
storage = bpf_sk_storage_get(&sk_storage_map2, sock->sk, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!storage)
return 0;

err = bpf_sk_storage_delete(&sk_storage_map, sock->sk);
if (err)
return 0;

err = bpf_sk_storage_delete(&sk_storage_map2, sock->sk);
if (!err)
sk_storage_result = err;

Expand Down

0 comments on commit 6ef3352

Please sign in to comment.