public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Use text error for btf_custom_path failures
@ 2023-02-28 14:25 Dmitrii Dolgov
  2023-03-01 19:02 ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitrii Dolgov @ 2023-02-28 14:25 UTC (permalink / raw)
  To: bpf; +Cc: andrii, ast, daniel, Dmitrii Dolgov

Use libbpf_strerror_r to expand the error when failed to parse the btf
file at btf_custom_path. It does not change a lot locally, but since the
error will bubble up through a few layers, it may become quite
confusing otherwise. As an example here is what happens when the file
indicated via btf_custom_path does not exist and the caller uses
strerror as well:

    libbpf: failed to parse target BTF: -2
    libbpf: failed to perform CO-RE relocations: -2
    libbpf: failed to load object 'bpf_probe'
    libbpf: failed to load BPF skeleton 'bpf_probe': -2
    [caller]: failed to load BPF object (errno: 2 | message: No such file or directory)

In this context "No such file or directory" could be easily
misinterpreted as belonging to some other part of loading process, e.g.
the BPF object itself. With this change it would look a bit better:

    libbpf: failed to parse target BTF: No such file or directory
    libbpf: failed to perform CO-RE relocations: -2
    libbpf: failed to load object 'bpf_probe'
    libbpf: failed to load BPF skeleton 'bpf_probe': -2
    [caller]: failed to load BPF object (errno: 2 | message: No such file or directory)

Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
---
 tools/lib/bpf/libbpf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 05c4db355f28..02a47552ad14 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5683,7 +5683,10 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
 		obj->btf_vmlinux_override = btf__parse(targ_btf_path, NULL);
 		err = libbpf_get_error(obj->btf_vmlinux_override);
 		if (err) {
-			pr_warn("failed to parse target BTF: %d\n", err);
+			char *cp, errmsg[STRERR_BUFSIZE];
+
+			cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
+			pr_warn("failed to parse target BTF: %s\n", cp);
 			return err;
 		}
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-06 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-28 14:25 [PATCH bpf-next] libbpf: Use text error for btf_custom_path failures Dmitrii Dolgov
2023-03-01 19:02 ` Andrii Nakryiko
2023-03-01 21:07   ` Dmitry Dolgov
2023-03-04 23:39     ` Andrii Nakryiko
2023-03-06 16:17       ` Quentin Monnet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox