diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-07-13 06:44:02 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-07-13 22:09:02 -0400 |
commit | 705fa2190dfb3d02f83adcd1abdb4e7dc3434597 (patch) | |
tree | 3ebba97ae06aa134af99ceb31ec365025d56a489 /tools/lib | |
parent | 5f44e4c810bf3ace5a97a84554d4eeccbb563ca5 (diff) |
tools lib bpf: Report error when kernel doesn't support program type
Now libbpf support tracepoint program type. Report meaningful error when kernel
version is less than 4.7.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1468406646-21642-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 27 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 1 |
2 files changed, 21 insertions, 7 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4751936831d7..32e6b6bc6f7d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -90,6 +90,7 @@ static const char *libbpf_strerror_table[NR_ERRNO] = { | |||
90 | [ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading", | 90 | [ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading", |
91 | [ERRCODE_OFFSET(PROG2BIG)] = "Program too big", | 91 | [ERRCODE_OFFSET(PROG2BIG)] = "Program too big", |
92 | [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version", | 92 | [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version", |
93 | [ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type", | ||
93 | }; | 94 | }; |
94 | 95 | ||
95 | int libbpf_strerror(int err, char *buf, size_t size) | 96 | int libbpf_strerror(int err, char *buf, size_t size) |
@@ -926,15 +927,27 @@ load_program(enum bpf_prog_type type, struct bpf_insn *insns, | |||
926 | pr_warning("-- BEGIN DUMP LOG ---\n"); | 927 | pr_warning("-- BEGIN DUMP LOG ---\n"); |
927 | pr_warning("\n%s\n", log_buf); | 928 | pr_warning("\n%s\n", log_buf); |
928 | pr_warning("-- END LOG --\n"); | 929 | pr_warning("-- END LOG --\n"); |
930 | } else if (insns_cnt >= BPF_MAXINSNS) { | ||
931 | pr_warning("Program too large (%d insns), at most %d insns\n", | ||
932 | insns_cnt, BPF_MAXINSNS); | ||
933 | ret = -LIBBPF_ERRNO__PROG2BIG; | ||
929 | } else { | 934 | } else { |
930 | if (insns_cnt >= BPF_MAXINSNS) { | 935 | /* Wrong program type? */ |
931 | pr_warning("Program too large (%d insns), at most %d insns\n", | 936 | if (type != BPF_PROG_TYPE_KPROBE) { |
932 | insns_cnt, BPF_MAXINSNS); | 937 | int fd; |
933 | ret = -LIBBPF_ERRNO__PROG2BIG; | 938 | |
934 | } else if (log_buf) { | 939 | fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns, |
935 | pr_warning("log buffer is empty\n"); | 940 | insns_cnt, license, kern_version, |
936 | ret = -LIBBPF_ERRNO__KVER; | 941 | NULL, 0); |
942 | if (fd >= 0) { | ||
943 | close(fd); | ||
944 | ret = -LIBBPF_ERRNO__PROGTYPE; | ||
945 | goto out; | ||
946 | } | ||
937 | } | 947 | } |
948 | |||
949 | if (log_buf) | ||
950 | ret = -LIBBPF_ERRNO__KVER; | ||
938 | } | 951 | } |
939 | 952 | ||
940 | out: | 953 | out: |
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index eb2a4c45f6b6..dd7a513efb10 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -39,6 +39,7 @@ enum libbpf_errno { | |||
39 | LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */ | 39 | LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */ |
40 | LIBBPF_ERRNO__PROG2BIG, /* Program too big */ | 40 | LIBBPF_ERRNO__PROG2BIG, /* Program too big */ |
41 | LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ | 41 | LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ |
42 | LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */ | ||
42 | __LIBBPF_ERRNO__END, | 43 | __LIBBPF_ERRNO__END, |
43 | }; | 44 | }; |
44 | 45 | ||