libbpf: remove multi-instance and custom private data APIs
Remove all the public APIs that are related to creating multi-instance bpf_programs through custom preprocessing callback and generally working with them. Also remove all the bpf_{object,map,program}__[set_]priv() APIs. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20220627211527.2245459-10-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
146bf811f5
commit
b4bda502df
@ -366,6 +366,16 @@ struct bpf_sec_def {
|
||||
libbpf_prog_attach_fn_t prog_attach_fn;
|
||||
};
|
||||
|
||||
struct bpf_prog_prep_result {
|
||||
struct bpf_insn *new_insn_ptr;
|
||||
int new_insn_cnt;
|
||||
int *pfd;
|
||||
};
|
||||
|
||||
typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
|
||||
struct bpf_insn *insns, int insns_cnt,
|
||||
struct bpf_prog_prep_result *res);
|
||||
|
||||
/*
|
||||
* bpf_prog should be a better name but it has been used in
|
||||
* linux/filter.h.
|
||||
@ -426,8 +436,6 @@ struct bpf_program {
|
||||
bpf_program_prep_t preprocessor;
|
||||
|
||||
struct bpf_object *obj;
|
||||
void *priv;
|
||||
bpf_program_clear_priv_t clear_priv;
|
||||
|
||||
bool autoload;
|
||||
bool mark_btf_static;
|
||||
@ -511,8 +519,6 @@ struct bpf_map {
|
||||
__u32 btf_key_type_id;
|
||||
__u32 btf_value_type_id;
|
||||
__u32 btf_vmlinux_value_type_id;
|
||||
void *priv;
|
||||
bpf_map_clear_priv_t clear_priv;
|
||||
enum libbpf_map_type libbpf_type;
|
||||
void *mmaped;
|
||||
struct bpf_struct_ops *st_ops;
|
||||
@ -668,9 +674,6 @@ struct bpf_object {
|
||||
size_t log_size;
|
||||
__u32 log_level;
|
||||
|
||||
void *priv;
|
||||
bpf_object_clear_priv_t clear_priv;
|
||||
|
||||
int *fd_array;
|
||||
size_t fd_array_cap;
|
||||
size_t fd_array_cnt;
|
||||
@ -721,12 +724,6 @@ static void bpf_program__exit(struct bpf_program *prog)
|
||||
if (!prog)
|
||||
return;
|
||||
|
||||
if (prog->clear_priv)
|
||||
prog->clear_priv(prog, prog->priv);
|
||||
|
||||
prog->priv = NULL;
|
||||
prog->clear_priv = NULL;
|
||||
|
||||
bpf_program__unload(prog);
|
||||
zfree(&prog->name);
|
||||
zfree(&prog->sec_name);
|
||||
@ -8051,12 +8048,6 @@ static int bpf_program_unpin_instance(struct bpf_program *prog, const char *path
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((alias("bpf_program_pin_instance")))
|
||||
int bpf_object__pin_instance(struct bpf_program *prog, const char *path, int instance);
|
||||
|
||||
__attribute__((alias("bpf_program_unpin_instance")))
|
||||
int bpf_program__unpin_instance(struct bpf_program *prog, const char *path, int instance);
|
||||
|
||||
int bpf_program__pin(struct bpf_program *prog, const char *path)
|
||||
{
|
||||
int i, err;
|
||||
@ -8492,11 +8483,6 @@ int bpf_object__pin(struct bpf_object *obj, const char *path)
|
||||
|
||||
static void bpf_map__destroy(struct bpf_map *map)
|
||||
{
|
||||
if (map->clear_priv)
|
||||
map->clear_priv(map, map->priv);
|
||||
map->priv = NULL;
|
||||
map->clear_priv = NULL;
|
||||
|
||||
if (map->inner_map) {
|
||||
bpf_map__destroy(map->inner_map);
|
||||
zfree(&map->inner_map);
|
||||
@ -8532,9 +8518,6 @@ void bpf_object__close(struct bpf_object *obj)
|
||||
if (IS_ERR_OR_NULL(obj))
|
||||
return;
|
||||
|
||||
if (obj->clear_priv)
|
||||
obj->clear_priv(obj, obj->priv);
|
||||
|
||||
usdt_manager_free(obj->usdt_man);
|
||||
obj->usdt_man = NULL;
|
||||
|
||||
@ -8594,22 +8577,6 @@ int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bpf_object__set_priv(struct bpf_object *obj, void *priv,
|
||||
bpf_object_clear_priv_t clear_priv)
|
||||
{
|
||||
if (obj->priv && obj->clear_priv)
|
||||
obj->clear_priv(obj, obj->priv);
|
||||
|
||||
obj->priv = priv;
|
||||
obj->clear_priv = clear_priv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *bpf_object__priv(const struct bpf_object *obj)
|
||||
{
|
||||
return obj ? obj->priv : libbpf_err_ptr(-EINVAL);
|
||||
}
|
||||
|
||||
int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
|
||||
{
|
||||
struct bpf_gen *gen;
|
||||
@ -8676,22 +8643,6 @@ bpf_object__prev_program(const struct bpf_object *obj, struct bpf_program *next)
|
||||
return prog;
|
||||
}
|
||||
|
||||
int bpf_program__set_priv(struct bpf_program *prog, void *priv,
|
||||
bpf_program_clear_priv_t clear_priv)
|
||||
{
|
||||
if (prog->priv && prog->clear_priv)
|
||||
prog->clear_priv(prog, prog->priv);
|
||||
|
||||
prog->priv = priv;
|
||||
prog->clear_priv = clear_priv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *bpf_program__priv(const struct bpf_program *prog)
|
||||
{
|
||||
return prog ? prog->priv : libbpf_err_ptr(-EINVAL);
|
||||
}
|
||||
|
||||
void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex)
|
||||
{
|
||||
prog->prog_ifindex = ifindex;
|
||||
@ -8758,37 +8709,6 @@ int bpf_program__set_insns(struct bpf_program *prog,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bpf_program__set_prep(struct bpf_program *prog, int nr_instances,
|
||||
bpf_program_prep_t prep)
|
||||
{
|
||||
int *instances_fds;
|
||||
|
||||
if (nr_instances <= 0 || !prep)
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
if (prog->instances.nr > 0 || prog->instances.fds) {
|
||||
pr_warn("Can't set pre-processor after loading\n");
|
||||
return libbpf_err(-EINVAL);
|
||||
}
|
||||
|
||||
instances_fds = malloc(sizeof(int) * nr_instances);
|
||||
if (!instances_fds) {
|
||||
pr_warn("alloc memory failed for fds\n");
|
||||
return libbpf_err(-ENOMEM);
|
||||
}
|
||||
|
||||
/* fill all fd with -1 */
|
||||
memset(instances_fds, -1, sizeof(int) * nr_instances);
|
||||
|
||||
prog->instances.nr = nr_instances;
|
||||
prog->instances.fds = instances_fds;
|
||||
prog->preprocessor = prep;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((alias("bpf_program_nth_fd")))
|
||||
int bpf_program__nth_fd(const struct bpf_program *prog, int n);
|
||||
|
||||
static int bpf_program_nth_fd(const struct bpf_program *prog, int n)
|
||||
{
|
||||
int fd;
|
||||
@ -9716,27 +9636,6 @@ __u32 bpf_map__btf_value_type_id(const struct bpf_map *map)
|
||||
return map ? map->btf_value_type_id : 0;
|
||||
}
|
||||
|
||||
int bpf_map__set_priv(struct bpf_map *map, void *priv,
|
||||
bpf_map_clear_priv_t clear_priv)
|
||||
{
|
||||
if (!map)
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
if (map->priv) {
|
||||
if (map->clear_priv)
|
||||
map->clear_priv(map, map->priv);
|
||||
}
|
||||
|
||||
map->priv = priv;
|
||||
map->clear_priv = clear_priv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *bpf_map__priv(const struct bpf_map *map)
|
||||
{
|
||||
return map ? map->priv : libbpf_err_ptr(-EINVAL);
|
||||
}
|
||||
|
||||
int bpf_map__set_initial_value(struct bpf_map *map,
|
||||
const void *data, size_t size)
|
||||
{
|
||||
|
@ -231,13 +231,6 @@ LIBBPF_API struct bpf_program *
|
||||
bpf_object__find_program_by_name(const struct bpf_object *obj,
|
||||
const char *name);
|
||||
|
||||
typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "storage via set_priv/priv is deprecated")
|
||||
LIBBPF_API int bpf_object__set_priv(struct bpf_object *obj, void *priv,
|
||||
bpf_object_clear_priv_t clear_priv);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "storage via set_priv/priv is deprecated")
|
||||
LIBBPF_API void *bpf_object__priv(const struct bpf_object *prog);
|
||||
|
||||
LIBBPF_API int
|
||||
libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
|
||||
enum bpf_attach_type *expected_attach_type);
|
||||
@ -260,13 +253,6 @@ bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prog)
|
||||
LIBBPF_API struct bpf_program *
|
||||
bpf_object__prev_program(const struct bpf_object *obj, struct bpf_program *prog);
|
||||
|
||||
typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, void *);
|
||||
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "storage via set_priv/priv is deprecated")
|
||||
LIBBPF_API int bpf_program__set_priv(struct bpf_program *prog, void *priv,
|
||||
bpf_program_clear_priv_t clear_priv);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "storage via set_priv/priv is deprecated")
|
||||
LIBBPF_API void *bpf_program__priv(const struct bpf_program *prog);
|
||||
LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,
|
||||
__u32 ifindex);
|
||||
|
||||
@ -328,14 +314,6 @@ LIBBPF_API int bpf_program__set_insns(struct bpf_program *prog,
|
||||
LIBBPF_API size_t bpf_program__insn_cnt(const struct bpf_program *prog);
|
||||
|
||||
LIBBPF_API int bpf_program__fd(const struct bpf_program *prog);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "multi-instance bpf_program support is deprecated")
|
||||
LIBBPF_API int bpf_program__pin_instance(struct bpf_program *prog,
|
||||
const char *path,
|
||||
int instance);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "multi-instance bpf_program support is deprecated")
|
||||
LIBBPF_API int bpf_program__unpin_instance(struct bpf_program *prog,
|
||||
const char *path,
|
||||
int instance);
|
||||
|
||||
/**
|
||||
* @brief **bpf_program__pin()** pins the BPF program to a file
|
||||
@ -635,69 +613,6 @@ LIBBPF_API struct bpf_link *
|
||||
bpf_program__attach_iter(const struct bpf_program *prog,
|
||||
const struct bpf_iter_attach_opts *opts);
|
||||
|
||||
/*
|
||||
* Libbpf allows callers to adjust BPF programs before being loaded
|
||||
* into kernel. One program in an object file can be transformed into
|
||||
* multiple variants to be attached to different hooks.
|
||||
*
|
||||
* bpf_program_prep_t, bpf_program__set_prep and bpf_program__nth_fd
|
||||
* form an API for this purpose.
|
||||
*
|
||||
* - bpf_program_prep_t:
|
||||
* Defines a 'preprocessor', which is a caller defined function
|
||||
* passed to libbpf through bpf_program__set_prep(), and will be
|
||||
* called before program is loaded. The processor should adjust
|
||||
* the program one time for each instance according to the instance id
|
||||
* passed to it.
|
||||
*
|
||||
* - bpf_program__set_prep:
|
||||
* Attaches a preprocessor to a BPF program. The number of instances
|
||||
* that should be created is also passed through this function.
|
||||
*
|
||||
* - bpf_program__nth_fd:
|
||||
* After the program is loaded, get resulting FD of a given instance
|
||||
* of the BPF program.
|
||||
*
|
||||
* If bpf_program__set_prep() is not used, the program would be loaded
|
||||
* without adjustment during bpf_object__load(). The program has only
|
||||
* one instance. In this case bpf_program__fd(prog) is equal to
|
||||
* bpf_program__nth_fd(prog, 0).
|
||||
*/
|
||||
struct bpf_prog_prep_result {
|
||||
/*
|
||||
* If not NULL, load new instruction array.
|
||||
* If set to NULL, don't load this instance.
|
||||
*/
|
||||
struct bpf_insn *new_insn_ptr;
|
||||
int new_insn_cnt;
|
||||
|
||||
/* If not NULL, result FD is written to it. */
|
||||
int *pfd;
|
||||
};
|
||||
|
||||
/*
|
||||
* Parameters of bpf_program_prep_t:
|
||||
* - prog: The bpf_program being loaded.
|
||||
* - n: Index of instance being generated.
|
||||
* - insns: BPF instructions array.
|
||||
* - insns_cnt:Number of instructions in insns.
|
||||
* - res: Output parameter, result of transformation.
|
||||
*
|
||||
* Return value:
|
||||
* - Zero: pre-processing success.
|
||||
* - Non-zero: pre-processing error, stop loading.
|
||||
*/
|
||||
typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
|
||||
struct bpf_insn *insns, int insns_cnt,
|
||||
struct bpf_prog_prep_result *res);
|
||||
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_program__insns() for getting bpf_program instructions")
|
||||
LIBBPF_API int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
|
||||
bpf_program_prep_t prep);
|
||||
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "multi-instance bpf_program support is deprecated")
|
||||
LIBBPF_API int bpf_program__nth_fd(const struct bpf_program *prog, int n);
|
||||
|
||||
LIBBPF_API enum bpf_prog_type bpf_program__type(const struct bpf_program *prog);
|
||||
|
||||
/**
|
||||
@ -846,12 +761,6 @@ LIBBPF_API int bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex);
|
||||
LIBBPF_API __u64 bpf_map__map_extra(const struct bpf_map *map);
|
||||
LIBBPF_API int bpf_map__set_map_extra(struct bpf_map *map, __u64 map_extra);
|
||||
|
||||
typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "storage via set_priv/priv is deprecated")
|
||||
LIBBPF_API int bpf_map__set_priv(struct bpf_map *map, void *priv,
|
||||
bpf_map_clear_priv_t clear_priv);
|
||||
LIBBPF_DEPRECATED_SINCE(0, 7, "storage via set_priv/priv is deprecated")
|
||||
LIBBPF_API void *bpf_map__priv(const struct bpf_map *map);
|
||||
LIBBPF_API int bpf_map__set_initial_value(struct bpf_map *map,
|
||||
const void *data, size_t size);
|
||||
LIBBPF_API const void *bpf_map__initial_value(struct bpf_map *map, size_t *psize);
|
||||
|
@ -6,11 +6,9 @@ LIBBPF_0.0.1 {
|
||||
bpf_map__fd;
|
||||
bpf_map__name;
|
||||
bpf_map__pin;
|
||||
bpf_map__priv;
|
||||
bpf_map__reuse_fd;
|
||||
bpf_map__set_ifindex;
|
||||
bpf_map__set_inner_map_fd;
|
||||
bpf_map__set_priv;
|
||||
bpf_map__unpin;
|
||||
bpf_map_delete_elem;
|
||||
bpf_map_get_fd_by_id;
|
||||
@ -32,8 +30,6 @@ LIBBPF_0.0.1 {
|
||||
bpf_object__pin;
|
||||
bpf_object__pin_maps;
|
||||
bpf_object__pin_programs;
|
||||
bpf_object__priv;
|
||||
bpf_object__set_priv;
|
||||
bpf_object__unpin_maps;
|
||||
bpf_object__unpin_programs;
|
||||
bpf_prog_attach;
|
||||
@ -43,18 +39,12 @@ LIBBPF_0.0.1 {
|
||||
bpf_prog_get_next_id;
|
||||
bpf_prog_query;
|
||||
bpf_program__fd;
|
||||
bpf_program__nth_fd;
|
||||
bpf_program__pin;
|
||||
bpf_program__pin_instance;
|
||||
bpf_program__priv;
|
||||
bpf_program__set_expected_attach_type;
|
||||
bpf_program__set_ifindex;
|
||||
bpf_program__set_prep;
|
||||
bpf_program__set_priv;
|
||||
bpf_program__set_type;
|
||||
bpf_program__unload;
|
||||
bpf_program__unpin;
|
||||
bpf_program__unpin_instance;
|
||||
bpf_prog_linfo__free;
|
||||
bpf_prog_linfo__new;
|
||||
bpf_prog_linfo__lfind_addr_func;
|
||||
|
Loading…
Reference in New Issue
Block a user