Skip to content

Commit aaa577e

Browse files
joannekoongNobody
authored and
Nobody
committed
selftests/bpf: Test for associating multiple elements with the local 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 <[email protected]>
1 parent 02fe28b commit aaa577e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tools/testing/selftests/bpf/progs/local_storage.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ struct {
3636
__type(value, struct local_storage);
3737
} sk_storage_map SEC(".maps");
3838

39+
struct {
40+
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
41+
__uint(map_flags, BPF_F_NO_PREALLOC | BPF_F_CLONE);
42+
__type(key, int);
43+
__type(value, struct local_storage);
44+
} sk_storage_map2 SEC(".maps");
45+
3946
struct {
4047
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
4148
__uint(map_flags, BPF_F_NO_PREALLOC);
@@ -115,7 +122,19 @@ int BPF_PROG(socket_bind, struct socket *sock, struct sockaddr *address,
115122
if (storage->value != DUMMY_STORAGE_VALUE)
116123
sk_storage_result = -1;
117124

125+
/* This tests that we can associate multiple elements
126+
* with the local storage.
127+
*/
128+
storage = bpf_sk_storage_get(&sk_storage_map2, sock->sk, 0,
129+
BPF_LOCAL_STORAGE_GET_F_CREATE);
130+
if (!storage)
131+
return 0;
132+
118133
err = bpf_sk_storage_delete(&sk_storage_map, sock->sk);
134+
if (err)
135+
return 0;
136+
137+
err = bpf_sk_storage_delete(&sk_storage_map2, sock->sk);
119138
if (!err)
120139
sk_storage_result = err;
121140

0 commit comments

Comments
 (0)