Thread (67 messages) 67 messages, 12 authors, 2019-11-12

Re: [PATCH v3 bpf-next 16/18] libbpf: Add support for attaching BPF programs to other BPF programs

From: Song Liu <hidden>
Date: 2019-11-08 19:14:51
Also in: bpf

On Nov 8, 2019, at 11:13 AM, Alexei Starovoitov [off-list ref] wrote:

On 11/8/19 10:57 AM, Song Liu wrote:
quoted
quoted
On Nov 7, 2019, at 10:40 PM, Alexei Starovoitov [off-list ref] wrote:

Extend libbpf api to pass attach_prog_fd into bpf_object__open.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
[...]
quoted
+static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd)
+{
+	struct bpf_prog_info_linear *info_linear;
+	struct bpf_prog_info *info;
+	struct btf *btf = NULL;
+	int err = -EINVAL;
+
+	info_linear = bpf_program__get_prog_info_linear(attach_prog_fd, 0);
+	if (IS_ERR_OR_NULL(info_linear)) {
+		pr_warn("failed get_prog_info_linear for FD %d\n",
+			attach_prog_fd);
+		return -EINVAL;
+	}
+	info = &info_linear->info;
+	if (!info->btf_id) {
+		pr_warn("The target program doesn't have BTF\n");
+		goto out;
+	}
+	if (btf__get_from_id(info->btf_id, &btf)) {
+		pr_warn("Failed to get BTF of the program\n");
+		goto out;
+	}
+	err = btf__find_by_name_kind(btf, name, BTF_KIND_FUNC);
+	btf__free(btf);
+	if (err <= 0) {
+		pr_warn("%s is not found in prog's BTF\n", name);
+		goto out;
		^^^ This goto doesn't really do much.
yeah. it does look a bit weird.
I wanted to keep uniform error handling, but can remove it
if you insist.
I think it is good as-is. 

Thanks,
Song
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help