Message ID | 20200114224412.3028054-1-kafai@fb.com |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | bpftool: Support dumping a map with btf_vmlinux_value_type_id | expand |
On Tue, Jan 14, 2020 at 2:44 PM Martin KaFai Lau <kafai@fb.com> wrote: > > This patch exposes bpf_find_kernel_btf() to libbpf_internal.h. > It will be used in 'bpftool map dump' in a following patch > to dump a map with btf_vmlinux_value_type_id set. > > Signed-off-by: Martin KaFai Lau <kafai@fb.com> > --- This function comes up not a first time, I guess it makes sense to finally make it a public API. We should also try to minimize number of internal APIs used by bpftool. So if no one objects to expose it, should we call it a bit more precisely and according to libbpf naming guidelines: libbpf_load_kernel_btf? libbpf_find_kernel_btf is acceptable, but it does more than just finding, thus "load". It should also probably live in btf.c+btf.h? WDYT? > tools/lib/bpf/libbpf.c | 3 +-- > tools/lib/bpf/libbpf_internal.h | 1 + > 2 files changed, 2 insertions(+), 2 deletions(-) > [...]
On Tue, Jan 14, 2020 at 05:43:58PM -0800, Andrii Nakryiko wrote: > On Tue, Jan 14, 2020 at 2:44 PM Martin KaFai Lau <kafai@fb.com> wrote: > > > > This patch exposes bpf_find_kernel_btf() to libbpf_internal.h. > > It will be used in 'bpftool map dump' in a following patch > > to dump a map with btf_vmlinux_value_type_id set. > > > > Signed-off-by: Martin KaFai Lau <kafai@fb.com> > > --- > > This function comes up not a first time, I guess it makes sense to > finally make it a public API. We should also try to minimize number of > internal APIs used by bpftool. > > So if no one objects to expose it, should we call it a bit more > precisely and according to libbpf naming guidelines: > libbpf_load_kernel_btf? libbpf_find_kernel_btf is acceptable, but it > does more than just finding, thus "load". It should also probably live > in btf.c+btf.h? WDYT? Sure, I will add it as LIBBPF_API in btf.h > > > > tools/lib/bpf/libbpf.c | 3 +-- > > tools/lib/bpf/libbpf_internal.h | 1 + > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > [...]
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 0c229f00a67e..0666d6383285 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -73,7 +73,6 @@ #define __printf(a, b) __attribute__((format(printf, a, b))) -static struct btf *bpf_find_kernel_btf(void); static struct bpf_map *bpf_object__add_map(struct bpf_object *obj); static struct bpf_program *bpf_object__find_prog_by_idx(struct bpf_object *obj, int idx); @@ -4339,7 +4338,7 @@ static struct btf *btf_load_raw(const char *path) * Probe few well-known locations for vmlinux kernel image and try to load BTF * data out of it to use for target BTF. */ -static struct btf *bpf_find_kernel_btf(void) +struct btf *bpf_find_kernel_btf(void) { struct { const char *path_fmt; diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index 8c3afbd97747..8593954d8f81 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -95,6 +95,7 @@ static inline bool libbpf_validate_opts(const char *opts, #define OPTS_GET(opts, field, fallback_value) \ (OPTS_HAS(opts, field) ? (opts)->field : fallback_value) +struct btf *bpf_find_kernel_btf(void); int parse_cpu_mask_str(const char *s, bool **mask, int *mask_sz); int parse_cpu_mask_file(const char *fcpu, bool **mask, int *mask_sz); int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
This patch exposes bpf_find_kernel_btf() to libbpf_internal.h. It will be used in 'bpftool map dump' in a following patch to dump a map with btf_vmlinux_value_type_id set. Signed-off-by: Martin KaFai Lau <kafai@fb.com> --- tools/lib/bpf/libbpf.c | 3 +-- tools/lib/bpf/libbpf_internal.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)