From 7c2aba744258dff59bfe10ff806d8e47567ff66f Mon Sep 17 00:00:00 2001 From: chendexi Date: Sat, 1 Jul 2023 14:48:22 +0800 Subject: [PATCH] Add an interface to get the keys and values in the hash table in batches --- src/libs/map_helpers.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/libs/map_helpers.c b/src/libs/map_helpers.c index 54700f7c..f33878f9 100644 --- a/src/libs/map_helpers.c +++ b/src/libs/map_helpers.c @@ -43,3 +43,28 @@ dump_hash_iter(int map_fd, void *keys, __u32 key_size, return 0; } +static int +dump_hash_batch(int map_fd, void *keys, __u32 key_size, + void *values, __u32 value_size, __u32 *count) +{ + void *in = NULL, *out; + __u32 n, n_read = 0; + int err = 0; + + while (n_read < *count && !err) { + n = *count - n_read; + err = bpf_map_lookup_batch(map_fd, &in, &out, + keys + n_read * key_size, + values + n_read * value_size, + &n, NULL); + if (err && errno != ENOENT) { + return -1; + } + n_read += n; + in = out; + } + + *count = n_read; + return 0; +} + -- Gitee