forked from Minki/linux
d3e0ce3930
A series of bpf loader related error codes were introduced to help error reporting. Functions were improved to return these new error codes. Functions which return pointers were adjusted to encode error codes into return value using the ERR_PTR() interface. bpf_loader_strerror() was improved to convert these error messages to strings. It checks the error codes and calls libbpf_strerror() and strerror_r() accordingly, so caller don't need to consider checking the range of the error code. In bpf__strerror_load(), print kernel version of running kernel and the object's 'version' section to notify user how to fix his/her program. v1 -> v2: Use macro for error code. Fetch error message based on array index, eliminate for-loop. Print version strings. Before: # perf record -e ./test_kversion_nomatch_program.o sleep 1 event syntax error: './test_kversion_nomatch_program.o' \___ Failed to load program: Validate your program and check 'license'/'version' sections in your object SKIP After: # perf record -e ./test_kversion_nomatch_program.o ls event syntax error: './test_kversion_nomatch_program.o' \___ 'version' (4.4.0) doesn't match running kernel (4.3.0) SKIP Signed-off-by: Wang Nan <wangnan0@huawei.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1446818289-87444-1-git-send-email-wangnan0@huawei.com [ Add 'static inline' to bpf__strerror_prepare_load() when LIBBPF is disabled ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
109 lines
2.9 KiB
C
109 lines
2.9 KiB
C
/*
|
|
* Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
|
|
* Copyright (C) 2015, Huawei Inc.
|
|
*/
|
|
#ifndef __BPF_LOADER_H
|
|
#define __BPF_LOADER_H
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/err.h>
|
|
#include <string.h>
|
|
#include <bpf/libbpf.h>
|
|
#include "probe-event.h"
|
|
#include "debug.h"
|
|
|
|
enum bpf_loader_errno {
|
|
__BPF_LOADER_ERRNO__START = __LIBBPF_ERRNO__START - 100,
|
|
/* Invalid config string */
|
|
BPF_LOADER_ERRNO__CONFIG = __BPF_LOADER_ERRNO__START,
|
|
BPF_LOADER_ERRNO__GROUP, /* Invalid group name */
|
|
BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */
|
|
BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */
|
|
BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */
|
|
__BPF_LOADER_ERRNO__END,
|
|
};
|
|
|
|
struct bpf_object;
|
|
#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
|
|
|
|
typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
|
|
int fd, void *arg);
|
|
|
|
#ifdef HAVE_LIBBPF_SUPPORT
|
|
struct bpf_object *bpf__prepare_load(const char *filename, bool source);
|
|
int bpf__strerror_prepare_load(const char *filename, bool source,
|
|
int err, char *buf, size_t size);
|
|
|
|
void bpf__clear(void);
|
|
|
|
int bpf__probe(struct bpf_object *obj);
|
|
int bpf__unprobe(struct bpf_object *obj);
|
|
int bpf__strerror_probe(struct bpf_object *obj, int err,
|
|
char *buf, size_t size);
|
|
|
|
int bpf__load(struct bpf_object *obj);
|
|
int bpf__strerror_load(struct bpf_object *obj, int err,
|
|
char *buf, size_t size);
|
|
int bpf__foreach_tev(struct bpf_object *obj,
|
|
bpf_prog_iter_callback_t func, void *arg);
|
|
#else
|
|
static inline struct bpf_object *
|
|
bpf__prepare_load(const char *filename __maybe_unused,
|
|
bool source __maybe_unused)
|
|
{
|
|
pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
|
|
return ERR_PTR(-ENOTSUP);
|
|
}
|
|
|
|
static inline void bpf__clear(void) { }
|
|
|
|
static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
|
|
static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
|
|
static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
|
|
|
|
static inline int
|
|
bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
|
|
bpf_prog_iter_callback_t func __maybe_unused,
|
|
void *arg __maybe_unused)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int
|
|
__bpf_strerror(char *buf, size_t size)
|
|
{
|
|
if (!size)
|
|
return 0;
|
|
strncpy(buf,
|
|
"ERROR: eBPF object loading is disabled during compiling.\n",
|
|
size);
|
|
buf[size - 1] = '\0';
|
|
return 0;
|
|
}
|
|
|
|
static inline
|
|
int bpf__strerror_prepare_load(const char *filename __maybe_unused,
|
|
bool source __maybe_unused,
|
|
int err __maybe_unused,
|
|
char *buf, size_t size)
|
|
{
|
|
return __bpf_strerror(buf, size);
|
|
}
|
|
|
|
static inline int
|
|
bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
|
|
int err __maybe_unused,
|
|
char *buf, size_t size)
|
|
{
|
|
return __bpf_strerror(buf, size);
|
|
}
|
|
|
|
static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
|
|
int err __maybe_unused,
|
|
char *buf, size_t size)
|
|
{
|
|
return __bpf_strerror(buf, size);
|
|
}
|
|
#endif
|
|
#endif
|