mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
bpftool: Switch bpf_object__load_xattr() to bpf_object__load()
Switch all the uses of to-be-deprecated bpf_object__load_xattr() into a simple bpf_object__load() calls with optional log_level passed through open_opts.kernel_log_level, if -d option is specified. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211209193840.1248570-13-andrii@kernel.org
This commit is contained in:
parent
3fc5fdcca1
commit
b59e4ce8bc
3 changed files with 21 additions and 29 deletions
|
@ -486,7 +486,6 @@ static void codegen_destroy(struct bpf_object *obj, const char *obj_name)
|
||||||
|
|
||||||
static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard)
|
static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard)
|
||||||
{
|
{
|
||||||
struct bpf_object_load_attr load_attr = {};
|
|
||||||
DECLARE_LIBBPF_OPTS(gen_loader_opts, opts);
|
DECLARE_LIBBPF_OPTS(gen_loader_opts, opts);
|
||||||
struct bpf_map *map;
|
struct bpf_map *map;
|
||||||
char ident[256];
|
char ident[256];
|
||||||
|
@ -496,12 +495,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
load_attr.obj = obj;
|
err = bpf_object__load(obj);
|
||||||
if (verifier_logs)
|
|
||||||
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
|
||||||
load_attr.log_level = 1 + 2 + 4;
|
|
||||||
|
|
||||||
err = bpf_object__load_xattr(&load_attr);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
p_err("failed to load object file");
|
p_err("failed to load object file");
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -719,6 +713,9 @@ static int do_skeleton(int argc, char **argv)
|
||||||
if (obj_name[0] == '\0')
|
if (obj_name[0] == '\0')
|
||||||
get_obj_name(obj_name, file);
|
get_obj_name(obj_name, file);
|
||||||
opts.object_name = obj_name;
|
opts.object_name = obj_name;
|
||||||
|
if (verifier_logs)
|
||||||
|
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
||||||
|
opts.kernel_log_level = 1 + 2 + 4;
|
||||||
obj = bpf_object__open_mem(obj_data, file_sz, &opts);
|
obj = bpf_object__open_mem(obj_data, file_sz, &opts);
|
||||||
err = libbpf_get_error(obj);
|
err = libbpf_get_error(obj);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -1464,7 +1464,6 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
|
||||||
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
|
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
|
||||||
.relaxed_maps = relaxed_maps,
|
.relaxed_maps = relaxed_maps,
|
||||||
);
|
);
|
||||||
struct bpf_object_load_attr load_attr = { 0 };
|
|
||||||
enum bpf_attach_type expected_attach_type;
|
enum bpf_attach_type expected_attach_type;
|
||||||
struct map_replace *map_replace = NULL;
|
struct map_replace *map_replace = NULL;
|
||||||
struct bpf_program *prog = NULL, *pos;
|
struct bpf_program *prog = NULL, *pos;
|
||||||
|
@ -1598,6 +1597,10 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
|
||||||
|
|
||||||
set_max_rlimit();
|
set_max_rlimit();
|
||||||
|
|
||||||
|
if (verifier_logs)
|
||||||
|
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
||||||
|
open_opts.kernel_log_level = 1 + 2 + 4;
|
||||||
|
|
||||||
obj = bpf_object__open_file(file, &open_opts);
|
obj = bpf_object__open_file(file, &open_opts);
|
||||||
if (libbpf_get_error(obj)) {
|
if (libbpf_get_error(obj)) {
|
||||||
p_err("failed to open object file");
|
p_err("failed to open object file");
|
||||||
|
@ -1677,12 +1680,7 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
|
||||||
goto err_close_obj;
|
goto err_close_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
load_attr.obj = obj;
|
err = bpf_object__load(obj);
|
||||||
if (verifier_logs)
|
|
||||||
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
|
||||||
load_attr.log_level = 1 + 2 + 4;
|
|
||||||
|
|
||||||
err = bpf_object__load_xattr(&load_attr);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
p_err("failed to load object file");
|
p_err("failed to load object file");
|
||||||
goto err_close_obj;
|
goto err_close_obj;
|
||||||
|
@ -1809,7 +1807,6 @@ static int do_loader(int argc, char **argv)
|
||||||
{
|
{
|
||||||
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts);
|
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts);
|
||||||
DECLARE_LIBBPF_OPTS(gen_loader_opts, gen);
|
DECLARE_LIBBPF_OPTS(gen_loader_opts, gen);
|
||||||
struct bpf_object_load_attr load_attr = {};
|
|
||||||
struct bpf_object *obj;
|
struct bpf_object *obj;
|
||||||
const char *file;
|
const char *file;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -1818,6 +1815,10 @@ static int do_loader(int argc, char **argv)
|
||||||
return -1;
|
return -1;
|
||||||
file = GET_ARG();
|
file = GET_ARG();
|
||||||
|
|
||||||
|
if (verifier_logs)
|
||||||
|
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
||||||
|
open_opts.kernel_log_level = 1 + 2 + 4;
|
||||||
|
|
||||||
obj = bpf_object__open_file(file, &open_opts);
|
obj = bpf_object__open_file(file, &open_opts);
|
||||||
if (libbpf_get_error(obj)) {
|
if (libbpf_get_error(obj)) {
|
||||||
p_err("failed to open object file");
|
p_err("failed to open object file");
|
||||||
|
@ -1828,12 +1829,7 @@ static int do_loader(int argc, char **argv)
|
||||||
if (err)
|
if (err)
|
||||||
goto err_close_obj;
|
goto err_close_obj;
|
||||||
|
|
||||||
load_attr.obj = obj;
|
err = bpf_object__load(obj);
|
||||||
if (verifier_logs)
|
|
||||||
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
|
||||||
load_attr.log_level = 1 + 2 + 4;
|
|
||||||
|
|
||||||
err = bpf_object__load_xattr(&load_attr);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
p_err("failed to load object file");
|
p_err("failed to load object file");
|
||||||
goto err_close_obj;
|
goto err_close_obj;
|
||||||
|
|
|
@ -479,7 +479,7 @@ static int do_unregister(int argc, char **argv)
|
||||||
|
|
||||||
static int do_register(int argc, char **argv)
|
static int do_register(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct bpf_object_load_attr load_attr = {};
|
LIBBPF_OPTS(bpf_object_open_opts, open_opts);
|
||||||
const struct bpf_map_def *def;
|
const struct bpf_map_def *def;
|
||||||
struct bpf_map_info info = {};
|
struct bpf_map_info info = {};
|
||||||
__u32 info_len = sizeof(info);
|
__u32 info_len = sizeof(info);
|
||||||
|
@ -494,18 +494,17 @@ static int do_register(int argc, char **argv)
|
||||||
|
|
||||||
file = GET_ARG();
|
file = GET_ARG();
|
||||||
|
|
||||||
obj = bpf_object__open(file);
|
if (verifier_logs)
|
||||||
|
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
||||||
|
open_opts.kernel_log_level = 1 + 2 + 4;
|
||||||
|
|
||||||
|
obj = bpf_object__open_file(file, &open_opts);
|
||||||
if (libbpf_get_error(obj))
|
if (libbpf_get_error(obj))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
set_max_rlimit();
|
set_max_rlimit();
|
||||||
|
|
||||||
load_attr.obj = obj;
|
if (bpf_object__load(obj)) {
|
||||||
if (verifier_logs)
|
|
||||||
/* log_level1 + log_level2 + stats, but not stable UAPI */
|
|
||||||
load_attr.log_level = 1 + 2 + 4;
|
|
||||||
|
|
||||||
if (bpf_object__load_xattr(&load_attr)) {
|
|
||||||
bpf_object__close(obj);
|
bpf_object__close(obj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue