mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-29 12:49:07 +08:00
libbpf: remove deprecated low-level APIs
Drop low-level APIs as well as high-level (and very confusingly named) BPF object loading bpf_prog_load_xattr() and bpf_prog_load_deprecated() APIs. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20220627211527.2245459-3-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
8ee1202ff4
commit
9476dce6fe
89
src/libbpf.c
89
src/libbpf.c
@@ -10205,95 +10205,6 @@ long libbpf_get_error(const void *ptr)
|
||||
return -errno;
|
||||
}
|
||||
|
||||
__attribute__((alias("bpf_prog_load_xattr2")))
|
||||
int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
|
||||
struct bpf_object **pobj, int *prog_fd);
|
||||
|
||||
static int bpf_prog_load_xattr2(const struct bpf_prog_load_attr *attr,
|
||||
struct bpf_object **pobj, int *prog_fd)
|
||||
{
|
||||
struct bpf_object_open_attr open_attr = {};
|
||||
struct bpf_program *prog, *first_prog = NULL;
|
||||
struct bpf_object *obj;
|
||||
struct bpf_map *map;
|
||||
int err;
|
||||
|
||||
if (!attr)
|
||||
return libbpf_err(-EINVAL);
|
||||
if (!attr->file)
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
open_attr.file = attr->file;
|
||||
open_attr.prog_type = attr->prog_type;
|
||||
|
||||
obj = __bpf_object__open_xattr(&open_attr, 0);
|
||||
err = libbpf_get_error(obj);
|
||||
if (err)
|
||||
return libbpf_err(-ENOENT);
|
||||
|
||||
bpf_object__for_each_program(prog, obj) {
|
||||
enum bpf_attach_type attach_type = attr->expected_attach_type;
|
||||
/*
|
||||
* to preserve backwards compatibility, bpf_prog_load treats
|
||||
* attr->prog_type, if specified, as an override to whatever
|
||||
* bpf_object__open guessed
|
||||
*/
|
||||
if (attr->prog_type != BPF_PROG_TYPE_UNSPEC) {
|
||||
prog->type = attr->prog_type;
|
||||
prog->expected_attach_type = attach_type;
|
||||
}
|
||||
if (bpf_program__type(prog) == BPF_PROG_TYPE_UNSPEC) {
|
||||
/*
|
||||
* we haven't guessed from section name and user
|
||||
* didn't provide a fallback type, too bad...
|
||||
*/
|
||||
bpf_object__close(obj);
|
||||
return libbpf_err(-EINVAL);
|
||||
}
|
||||
|
||||
prog->prog_ifindex = attr->ifindex;
|
||||
prog->log_level = attr->log_level;
|
||||
prog->prog_flags |= attr->prog_flags;
|
||||
if (!first_prog)
|
||||
first_prog = prog;
|
||||
}
|
||||
|
||||
bpf_object__for_each_map(map, obj) {
|
||||
if (map->def.type != BPF_MAP_TYPE_PERF_EVENT_ARRAY)
|
||||
map->map_ifindex = attr->ifindex;
|
||||
}
|
||||
|
||||
if (!first_prog) {
|
||||
pr_warn("object file doesn't contain bpf program\n");
|
||||
bpf_object__close(obj);
|
||||
return libbpf_err(-ENOENT);
|
||||
}
|
||||
|
||||
err = bpf_object__load(obj);
|
||||
if (err) {
|
||||
bpf_object__close(obj);
|
||||
return libbpf_err(err);
|
||||
}
|
||||
|
||||
*pobj = obj;
|
||||
*prog_fd = bpf_program__fd(first_prog);
|
||||
return 0;
|
||||
}
|
||||
|
||||
COMPAT_VERSION(bpf_prog_load_deprecated, bpf_prog_load, LIBBPF_0.0.1)
|
||||
int bpf_prog_load_deprecated(const char *file, enum bpf_prog_type type,
|
||||
struct bpf_object **pobj, int *prog_fd)
|
||||
{
|
||||
struct bpf_prog_load_attr attr;
|
||||
|
||||
memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
|
||||
attr.file = file;
|
||||
attr.prog_type = type;
|
||||
attr.expected_attach_type = 0;
|
||||
|
||||
return bpf_prog_load_xattr2(&attr, pobj, prog_fd);
|
||||
}
|
||||
|
||||
/* Replace link's underlying BPF program with the new one */
|
||||
int bpf_link__update_program(struct bpf_link *link, struct bpf_program *prog)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user