Follow-up cleanups to the manual loading series, just some extra documentation to the API headers, reject subprograms in bpf_program__set_load_strategy() for every strategy and a few more NITs. Suggested-by: Andrii Nakryiko Signed-off-by: Andrey Grodzovsky --- tools/lib/bpf/libbpf.c | 15 ++++++--------- tools/lib/bpf/libbpf.h | 14 +++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 02e75b183ed0..446b947c48f3 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9844,7 +9844,7 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch err = bpf_gen__finish(obj->gen_loader, obj->nr_programs, obj->nr_maps); } - bpf_object_post_load_cleanup(obj, false); + bpf_object_post_load_cleanup(obj, false /* !force */); obj->state = OBJ_LOADED; /* doesn't matter if successfully or not */ if (err) { @@ -16013,16 +16013,14 @@ int bpf_program__set_load_strategy(struct bpf_program *prog, enum bpf_prog_load_ if (obj->state >= OBJ_PREPARED) return libbpf_err(-EINVAL); + if (prog_is_subprog(obj, prog)) + return libbpf_err(-EINVAL); + switch (strategy) { case BPF_PROG_LOAD_STRATEGY_DISABLED: case BPF_PROG_LOAD_STRATEGY_AUTO: - prog->load_strategy = strategy; - break; case BPF_PROG_LOAD_STRATEGY_MANUAL: - if (prog_is_subprog(obj, prog)) - return libbpf_err(-EINVAL); - - prog->load_strategy = BPF_PROG_LOAD_STRATEGY_MANUAL; + prog->load_strategy = strategy; break; default: return libbpf_err(-EINVAL); @@ -16036,8 +16034,7 @@ enum bpf_prog_load_strategy bpf_program__load_strategy(const struct bpf_program return prog->load_strategy; } -int -bpf_program__load(struct bpf_program *prog) +int bpf_program__load(struct bpf_program *prog) { int err; struct bpf_object *obj = prog->obj; diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 22204a544b23..a8a23c135c17 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -390,6 +390,17 @@ LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog, LIBBPF_API const char *bpf_program__name(const struct bpf_program *prog); LIBBPF_API const char *bpf_program__section_name(const struct bpf_program *prog); LIBBPF_API bool bpf_program__autoload(const struct bpf_program *prog); + +/** + * @brief **bpf_program__set_autoload()** sets whether a BPF program is + * loaded automatically when its bpf_object is loaded. + * + * @param prog BPF program to update + * @param autoload true to load the program automatically, false to disable + * its loading + * @return 0 on success; -EINVAL if the object was already prepared or if the + * program is a subprogram + */ LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog, bool autoload); LIBBPF_API bool bpf_program__autoattach(const struct bpf_program *prog); LIBBPF_API void bpf_program__set_autoattach(struct bpf_program *prog, bool autoattach); @@ -2177,7 +2188,8 @@ enum bpf_prog_load_strategy { * * @param prog BPF program to update * @param strategy new load strategy for the program - * @return 0 on success; negative error code if the object was already prepared + * @return 0 on success; -EINVAL if the object was already prepared, if the + * strategy is not a valid one, or if the program is a subprogram */ LIBBPF_API int bpf_program__set_load_strategy(struct bpf_program *prog, enum bpf_prog_load_strategy strategy); -- 2.34.1