Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+21 -29
+4 -7
tools/bpf/bpftool/gen.c
··· 486 486 487 487 static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard) 488 488 { 489 - struct bpf_object_load_attr load_attr = {}; 490 489 DECLARE_LIBBPF_OPTS(gen_loader_opts, opts); 491 490 struct bpf_map *map; 492 491 char ident[256]; ··· 495 496 if (err) 496 497 return err; 497 498 498 - load_attr.obj = obj; 499 - if (verifier_logs) 500 - /* log_level1 + log_level2 + stats, but not stable UAPI */ 501 - load_attr.log_level = 1 + 2 + 4; 502 - 503 - err = bpf_object__load_xattr(&load_attr); 499 + err = bpf_object__load(obj); 504 500 if (err) { 505 501 p_err("failed to load object file"); 506 502 goto out; ··· 713 719 if (obj_name[0] == '\0') 714 720 get_obj_name(obj_name, file); 715 721 opts.object_name = obj_name; 722 + if (verifier_logs) 723 + /* log_level1 + log_level2 + stats, but not stable UAPI */ 724 + opts.kernel_log_level = 1 + 2 + 4; 716 725 obj = bpf_object__open_mem(obj_data, file_sz, &opts); 717 726 err = libbpf_get_error(obj); 718 727 if (err) {
+10 -14
tools/bpf/bpftool/prog.c
··· 1464 1464 DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts, 1465 1465 .relaxed_maps = relaxed_maps, 1466 1466 ); 1467 - struct bpf_object_load_attr load_attr = { 0 }; 1468 1467 enum bpf_attach_type expected_attach_type; 1469 1468 struct map_replace *map_replace = NULL; 1470 1469 struct bpf_program *prog = NULL, *pos; ··· 1597 1598 1598 1599 set_max_rlimit(); 1599 1600 1601 + if (verifier_logs) 1602 + /* log_level1 + log_level2 + stats, but not stable UAPI */ 1603 + open_opts.kernel_log_level = 1 + 2 + 4; 1604 + 1600 1605 obj = bpf_object__open_file(file, &open_opts); 1601 1606 if (libbpf_get_error(obj)) { 1602 1607 p_err("failed to open object file"); ··· 1680 1677 goto err_close_obj; 1681 1678 } 1682 1679 1683 - load_attr.obj = obj; 1684 - if (verifier_logs) 1685 - /* log_level1 + log_level2 + stats, but not stable UAPI */ 1686 - load_attr.log_level = 1 + 2 + 4; 1687 - 1688 - err = bpf_object__load_xattr(&load_attr); 1680 + err = bpf_object__load(obj); 1689 1681 if (err) { 1690 1682 p_err("failed to load object file"); 1691 1683 goto err_close_obj; ··· 1807 1809 { 1808 1810 DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts); 1809 1811 DECLARE_LIBBPF_OPTS(gen_loader_opts, gen); 1810 - struct bpf_object_load_attr load_attr = {}; 1811 1812 struct bpf_object *obj; 1812 1813 const char *file; 1813 1814 int err = 0; ··· 1814 1817 if (!REQ_ARGS(1)) 1815 1818 return -1; 1816 1819 file = GET_ARG(); 1820 + 1821 + if (verifier_logs) 1822 + /* log_level1 + log_level2 + stats, but not stable UAPI */ 1823 + open_opts.kernel_log_level = 1 + 2 + 4; 1817 1824 1818 1825 obj = bpf_object__open_file(file, &open_opts); 1819 1826 if (libbpf_get_error(obj)) { ··· 1829 1828 if (err) 1830 1829 goto err_close_obj; 1831 1830 1832 - load_attr.obj = obj; 1833 - if (verifier_logs) 1834 - /* log_level1 + log_level2 + stats, but not stable UAPI */ 1835 - load_attr.log_level = 1 + 2 + 4; 1836 - 1837 - err = bpf_object__load_xattr(&load_attr); 1831 + err = bpf_object__load(obj); 1838 1832 if (err) { 1839 1833 p_err("failed to load object file"); 1840 1834 goto err_close_obj;
+7 -8
tools/bpf/bpftool/struct_ops.c
··· 479 479 480 480 static int do_register(int argc, char **argv) 481 481 { 482 - struct bpf_object_load_attr load_attr = {}; 482 + LIBBPF_OPTS(bpf_object_open_opts, open_opts); 483 483 const struct bpf_map_def *def; 484 484 struct bpf_map_info info = {}; 485 485 __u32 info_len = sizeof(info); ··· 494 494 495 495 file = GET_ARG(); 496 496 497 - obj = bpf_object__open(file); 497 + if (verifier_logs) 498 + /* log_level1 + log_level2 + stats, but not stable UAPI */ 499 + open_opts.kernel_log_level = 1 + 2 + 4; 500 + 501 + obj = bpf_object__open_file(file, &open_opts); 498 502 if (libbpf_get_error(obj)) 499 503 return -1; 500 504 501 505 set_max_rlimit(); 502 506 503 - load_attr.obj = obj; 504 - if (verifier_logs) 505 - /* log_level1 + log_level2 + stats, but not stable UAPI */ 506 - load_attr.log_level = 1 + 2 + 4; 507 - 508 - if (bpf_object__load_xattr(&load_attr)) { 507 + if (bpf_object__load(obj)) { 509 508 bpf_object__close(obj); 510 509 return -1; 511 510 }