[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190201214230.1441-2-maciej.fijalkowski@intel.com>
Date: Fri, 1 Feb 2019 22:42:23 +0100
From: Maciej Fijalkowski <maciejromanfijalkowski@...il.com>
To: daniel@...earbox.net, ast@...nel.org
Cc: netdev@...r.kernel.org, jakub.kicinski@...ronome.com,
brouer@...hat.com, john.fastabend@...il.com
Subject: [PATCH bpf-next v6 1/8] libbpf: Add a helper for retrieving a map fd for a given name
XDP samples are mostly cooperating with eBPF maps through their file
descriptors. In case of a eBPF program that contains multiple maps it
might be tiresome to iterate through them and call bpf_map__fd for each
one. Add a helper mostly based on bpf_object__find_map_by_name, but
instead of returning the struct bpf_map pointer, return map fd.
Suggested-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
Acked-by: John Fastabend <john.fastabend@...il.com>
---
tools/lib/bpf/libbpf.c | 6 ++++++
tools/lib/bpf/libbpf.h | 3 +++
tools/lib/bpf/libbpf.map | 1 +
3 files changed, 10 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2ccde17957e6..03bc01ca2577 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2884,6 +2884,12 @@ bpf_object__find_map_by_name(struct bpf_object *obj, const char *name)
return NULL;
}
+int
+bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name)
+{
+ return bpf_map__fd(bpf_object__find_map_by_name(obj, name));
+}
+
struct bpf_map *
bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
{
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 62ae6cb93da1..931be6f3408c 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -264,6 +264,9 @@ struct bpf_map;
LIBBPF_API struct bpf_map *
bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
+LIBBPF_API int
+bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name);
+
/*
* Get bpf_map through the offset of corresponding struct bpf_map_def
* in the BPF object file.
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index f6f96fc38c50..43ba9bb8d24b 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -131,4 +131,5 @@ LIBBPF_0.0.2 {
bpf_probe_map_type;
bpf_probe_prog_type;
bpf_map_lookup_elem_flags;
+ bpf_object__find_map_fd_by_name;
} LIBBPF_0.0.1;
--
2.16.1
Powered by blists - more mailing lists